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