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