1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_starmath.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include <tools/stream.hxx> 33*cdf0e10cSrcweir #include <vcl/svapp.hxx> 34*cdf0e10cSrcweir #include <editeng/scripttypeitem.hxx> 35*cdf0e10cSrcweir #include "format.hxx" 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////// 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir // Latin default-fonts 40*cdf0e10cSrcweir static const sal_uInt16 aLatinDefFnts[FNT_END] = 41*cdf0e10cSrcweir { 42*cdf0e10cSrcweir DEFAULTFONT_SERIF, // FNT_VARIABLE 43*cdf0e10cSrcweir DEFAULTFONT_SERIF, // FNT_FUNCTION 44*cdf0e10cSrcweir DEFAULTFONT_SERIF, // FNT_NUMBER 45*cdf0e10cSrcweir DEFAULTFONT_SERIF, // FNT_TEXT 46*cdf0e10cSrcweir DEFAULTFONT_SERIF, // FNT_SERIF 47*cdf0e10cSrcweir DEFAULTFONT_SANS, // FNT_SANS 48*cdf0e10cSrcweir DEFAULTFONT_FIXED // FNT_FIXED 49*cdf0e10cSrcweir //OpenSymbol, // FNT_MATH 50*cdf0e10cSrcweir }; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir // CJK default-fonts 53*cdf0e10cSrcweir //! we use non-asian fonts for variables, functions and numbers since they 54*cdf0e10cSrcweir //! look better and even in asia only latin letters will be used for those. 55*cdf0e10cSrcweir //! At least that's what I was told... 56*cdf0e10cSrcweir static const sal_uInt16 aCJKDefFnts[FNT_END] = 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir DEFAULTFONT_SERIF, // FNT_VARIABLE 59*cdf0e10cSrcweir DEFAULTFONT_SERIF, // FNT_FUNCTION 60*cdf0e10cSrcweir DEFAULTFONT_SERIF, // FNT_NUMBER 61*cdf0e10cSrcweir DEFAULTFONT_CJK_TEXT, // FNT_TEXT 62*cdf0e10cSrcweir DEFAULTFONT_CJK_TEXT, // FNT_SERIF 63*cdf0e10cSrcweir DEFAULTFONT_CJK_DISPLAY, // FNT_SANS 64*cdf0e10cSrcweir DEFAULTFONT_CJK_TEXT // FNT_FIXED 65*cdf0e10cSrcweir //OpenSymbol, // FNT_MATH 66*cdf0e10cSrcweir }; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir // CTL default-fonts 69*cdf0e10cSrcweir static const sal_uInt16 aCTLDefFnts[FNT_END] = 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir DEFAULTFONT_CTL_TEXT, // FNT_VARIABLE 72*cdf0e10cSrcweir DEFAULTFONT_CTL_TEXT, // FNT_FUNCTION 73*cdf0e10cSrcweir DEFAULTFONT_CTL_TEXT, // FNT_NUMBER 74*cdf0e10cSrcweir DEFAULTFONT_CTL_TEXT, // FNT_TEXT 75*cdf0e10cSrcweir DEFAULTFONT_CTL_TEXT, // FNT_SERIF 76*cdf0e10cSrcweir DEFAULTFONT_CTL_TEXT, // FNT_SANS 77*cdf0e10cSrcweir DEFAULTFONT_CTL_TEXT // FNT_FIXED 78*cdf0e10cSrcweir //OpenSymbol, // FNT_MATH 79*cdf0e10cSrcweir }; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir String GetDefaultFontName( LanguageType nLang, sal_uInt16 nIdent ) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir DBG_ASSERT( /*FNT_BEGIN <= nIdent &&*/ nIdent <= FNT_END, 85*cdf0e10cSrcweir "index out opd range" ); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir if (FNT_MATH == nIdent) 88*cdf0e10cSrcweir return String::CreateFromAscii( FNTNAME_MATH ); 89*cdf0e10cSrcweir else 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir const sal_uInt16 *pTable; 92*cdf0e10cSrcweir switch ( SvtLanguageOptions::GetScriptTypeOfLanguage( nLang ) ) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir case SCRIPTTYPE_LATIN : pTable = aLatinDefFnts; break; 95*cdf0e10cSrcweir case SCRIPTTYPE_ASIAN : pTable = aCJKDefFnts; break; 96*cdf0e10cSrcweir case SCRIPTTYPE_COMPLEX : pTable = aCTLDefFnts; break; 97*cdf0e10cSrcweir default : 98*cdf0e10cSrcweir pTable = aLatinDefFnts; 99*cdf0e10cSrcweir DBG_ERROR( "unknown script-type" ); 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir return Application::GetDefaultDevice()->GetDefaultFont( 103*cdf0e10cSrcweir pTable[ nIdent ], nLang, 104*cdf0e10cSrcweir DEFAULTFONT_FLAGS_ONLYONE ).GetName(); 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////// 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir SmFormat::SmFormat() 111*cdf0e10cSrcweir : aBaseSize(0, SmPtsTo100th_mm(12)) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir nVersion = SM_FMT_VERSION_NOW; 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir eHorAlign = AlignCenter; 116*cdf0e10cSrcweir nGreekCharStyle = 0; 117*cdf0e10cSrcweir bIsTextmode = bScaleNormalBrackets = sal_False; 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir vSize[SIZ_TEXT] = 100; 120*cdf0e10cSrcweir vSize[SIZ_INDEX] = 60; 121*cdf0e10cSrcweir vSize[SIZ_FUNCTION] = 122*cdf0e10cSrcweir vSize[SIZ_OPERATOR] = 100; 123*cdf0e10cSrcweir vSize[SIZ_LIMITS] = 60; 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir vDist[DIS_HORIZONTAL] = 10; 126*cdf0e10cSrcweir vDist[DIS_VERTICAL] = 5; 127*cdf0e10cSrcweir vDist[DIS_ROOT] = 0; 128*cdf0e10cSrcweir vDist[DIS_SUPERSCRIPT] = 129*cdf0e10cSrcweir vDist[DIS_SUBSCRIPT] = 20; 130*cdf0e10cSrcweir vDist[DIS_NUMERATOR] = 131*cdf0e10cSrcweir vDist[DIS_DENOMINATOR] = 0; 132*cdf0e10cSrcweir vDist[DIS_FRACTION] = 10; 133*cdf0e10cSrcweir vDist[DIS_STROKEWIDTH] = 5; 134*cdf0e10cSrcweir vDist[DIS_UPPERLIMIT] = 135*cdf0e10cSrcweir vDist[DIS_LOWERLIMIT] = 0; 136*cdf0e10cSrcweir vDist[DIS_BRACKETSIZE] = 137*cdf0e10cSrcweir vDist[DIS_BRACKETSPACE] = 5; 138*cdf0e10cSrcweir vDist[DIS_MATRIXROW] = 3; 139*cdf0e10cSrcweir vDist[DIS_MATRIXCOL] = 30; 140*cdf0e10cSrcweir vDist[DIS_ORNAMENTSIZE] = 141*cdf0e10cSrcweir vDist[DIS_ORNAMENTSPACE] = 0; 142*cdf0e10cSrcweir vDist[DIS_OPERATORSIZE] = 50; 143*cdf0e10cSrcweir vDist[DIS_OPERATORSPACE] = 20; 144*cdf0e10cSrcweir vDist[DIS_LEFTSPACE] = 145*cdf0e10cSrcweir vDist[DIS_RIGHTSPACE] = 100; 146*cdf0e10cSrcweir vDist[DIS_TOPSPACE] = 147*cdf0e10cSrcweir vDist[DIS_BOTTOMSPACE] = 148*cdf0e10cSrcweir vDist[DIS_NORMALBRACKETSIZE] = 0; 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir vFont[FNT_VARIABLE] = 151*cdf0e10cSrcweir vFont[FNT_FUNCTION] = 152*cdf0e10cSrcweir vFont[FNT_NUMBER] = 153*cdf0e10cSrcweir vFont[FNT_TEXT] = 154*cdf0e10cSrcweir vFont[FNT_SERIF] = SmFace(C2S(FNTNAME_TIMES), aBaseSize); 155*cdf0e10cSrcweir vFont[FNT_SANS] = SmFace(C2S(FNTNAME_HELV), aBaseSize); 156*cdf0e10cSrcweir vFont[FNT_FIXED] = SmFace(C2S(FNTNAME_COUR), aBaseSize); 157*cdf0e10cSrcweir vFont[FNT_MATH] = SmFace(C2S(FNTNAME_MATH), aBaseSize); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir vFont[FNT_MATH].SetCharSet( RTL_TEXTENCODING_UNICODE ); 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir vFont[FNT_VARIABLE].SetItalic(ITALIC_NORMAL); 162*cdf0e10cSrcweir vFont[FNT_FUNCTION].SetItalic(ITALIC_NONE); 163*cdf0e10cSrcweir vFont[FNT_NUMBER] .SetItalic(ITALIC_NONE); 164*cdf0e10cSrcweir vFont[FNT_TEXT] .SetItalic(ITALIC_NONE); 165*cdf0e10cSrcweir vFont[FNT_SERIF] .SetItalic(ITALIC_NONE); 166*cdf0e10cSrcweir vFont[FNT_SANS] .SetItalic(ITALIC_NONE); 167*cdf0e10cSrcweir vFont[FNT_FIXED] .SetItalic(ITALIC_NONE); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir for ( sal_uInt16 i = FNT_BEGIN; i <= FNT_END; i++ ) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir SmFace &rFace = vFont[i]; 172*cdf0e10cSrcweir rFace.SetTransparent( sal_True ); 173*cdf0e10cSrcweir rFace.SetAlign( ALIGN_BASELINE ); 174*cdf0e10cSrcweir rFace.SetColor( COL_AUTO ); 175*cdf0e10cSrcweir bDefaultFont[i] = sal_False; 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir void SmFormat::SetFont(sal_uInt16 nIdent, const SmFace &rFont, sal_Bool bDefault ) 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir vFont[nIdent] = rFont; 183*cdf0e10cSrcweir vFont[nIdent].SetTransparent( sal_True ); 184*cdf0e10cSrcweir vFont[nIdent].SetAlign( ALIGN_BASELINE ); 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir bDefaultFont[nIdent] = bDefault; 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir SmFormat & SmFormat::operator = (const SmFormat &rFormat) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir SetBaseSize(rFormat.GetBaseSize()); 192*cdf0e10cSrcweir SetVersion (rFormat.GetVersion()); 193*cdf0e10cSrcweir SetHorAlign(rFormat.GetHorAlign()); 194*cdf0e10cSrcweir SetTextmode(rFormat.IsTextmode()); 195*cdf0e10cSrcweir SetGreekCharStyle(rFormat.GetGreekCharStyle()); 196*cdf0e10cSrcweir SetScaleNormalBrackets(rFormat.IsScaleNormalBrackets()); 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir sal_uInt16 i; 199*cdf0e10cSrcweir for (i = FNT_BEGIN; i <= FNT_END; i++) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir SetFont(i, rFormat.GetFont(i)); 202*cdf0e10cSrcweir SetDefaultFont(i, rFormat.IsDefaultFont(i)); 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir for (i = SIZ_BEGIN; i <= SIZ_END; i++) 205*cdf0e10cSrcweir SetRelSize(i, rFormat.GetRelSize(i)); 206*cdf0e10cSrcweir for (i = DIS_BEGIN; i <= DIS_END; i++) 207*cdf0e10cSrcweir SetDistance(i, rFormat.GetDistance(i)); 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir return *this; 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir sal_Bool SmFormat::operator == (const SmFormat &rFormat) const 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir sal_Bool bRes = aBaseSize == rFormat.aBaseSize && 216*cdf0e10cSrcweir eHorAlign == rFormat.eHorAlign && 217*cdf0e10cSrcweir nGreekCharStyle == rFormat.nGreekCharStyle && 218*cdf0e10cSrcweir bIsTextmode == rFormat.bIsTextmode && 219*cdf0e10cSrcweir bScaleNormalBrackets == rFormat.bScaleNormalBrackets; 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir sal_uInt16 i; 222*cdf0e10cSrcweir for (i = 0; i <= SIZ_END && bRes; ++i) 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir if (vSize[i] != rFormat.vSize[i]) 225*cdf0e10cSrcweir bRes = sal_False; 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir for (i = 0; i <= DIS_END && bRes; ++i) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir if (vDist[i] != rFormat.vDist[i]) 230*cdf0e10cSrcweir bRes = sal_False; 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir for (i = 0; i <= FNT_END && bRes; ++i) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir if (vFont[i] != rFormat.vFont[i] || 235*cdf0e10cSrcweir bDefaultFont[i] != rFormat.bDefaultFont[i]) 236*cdf0e10cSrcweir bRes = sal_False; 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir return bRes; 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir 243