1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: format.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_starmath.hxx"
35 #include <tools/stream.hxx>
36 #include <vcl/svapp.hxx>
37 #include <svx/scripttypeitem.hxx>
40 /////////////////////////////////////////////////////////////////
42 // Latin default-fonts
43 static const USHORT aLatinDefFnts
[FNT_END
] =
45 DEFAULTFONT_SERIF
, // FNT_VARIABLE
46 DEFAULTFONT_SERIF
, // FNT_FUNCTION
47 DEFAULTFONT_SERIF
, // FNT_NUMBER
48 DEFAULTFONT_SERIF
, // FNT_TEXT
49 DEFAULTFONT_SERIF
, // FNT_SERIF
50 DEFAULTFONT_SANS
, // FNT_SANS
51 DEFAULTFONT_FIXED
// FNT_FIXED
52 //StarSymbol, // FNT_MATH
56 //! we use non-asian fonts for variables, functions and numbers since they
57 //! look better and even in asia only latin letters will be used for those.
58 //! At least that's what I was told...
59 static const USHORT aCJKDefFnts
[FNT_END
] =
61 DEFAULTFONT_SERIF
, // FNT_VARIABLE
62 DEFAULTFONT_SERIF
, // FNT_FUNCTION
63 DEFAULTFONT_SERIF
, // FNT_NUMBER
64 DEFAULTFONT_CJK_TEXT
, // FNT_TEXT
65 DEFAULTFONT_CJK_TEXT
, // FNT_SERIF
66 DEFAULTFONT_CJK_DISPLAY
, // FNT_SANS
67 DEFAULTFONT_CJK_TEXT
// FNT_FIXED
68 //StarSymbol, // FNT_MATH
72 static const USHORT aCTLDefFnts
[FNT_END
] =
74 DEFAULTFONT_CTL_TEXT
, // FNT_VARIABLE
75 DEFAULTFONT_CTL_TEXT
, // FNT_FUNCTION
76 DEFAULTFONT_CTL_TEXT
, // FNT_NUMBER
77 DEFAULTFONT_CTL_TEXT
, // FNT_TEXT
78 DEFAULTFONT_CTL_TEXT
, // FNT_SERIF
79 DEFAULTFONT_CTL_TEXT
, // FNT_SANS
80 DEFAULTFONT_CTL_TEXT
// FNT_FIXED
81 //StarSymbol, // FNT_MATH
85 String
GetDefaultFontName( LanguageType nLang
, USHORT nIdent
)
87 DBG_ASSERT( /*FNT_BEGIN <= nIdent &&*/ nIdent
<= FNT_END
,
88 "index out opd range" );
90 if (FNT_MATH
== nIdent
)
91 return String::CreateFromAscii( FNTNAME_MATH
);
95 switch ( SvtLanguageOptions::GetScriptTypeOfLanguage( nLang
) )
97 case SCRIPTTYPE_LATIN
: pTable
= aLatinDefFnts
; break;
98 case SCRIPTTYPE_ASIAN
: pTable
= aCJKDefFnts
; break;
99 case SCRIPTTYPE_COMPLEX
: pTable
= aCTLDefFnts
; break;
101 pTable
= aLatinDefFnts
;
102 DBG_ERROR( "unknown script-type" );
105 return Application::GetDefaultDevice()->GetDefaultFont(
106 pTable
[ nIdent
], nLang
,
107 DEFAULTFONT_FLAGS_ONLYONE
).GetName();
111 /////////////////////////////////////////////////////////////////
114 : aBaseSize(0, SmPtsTo100th_mm(12))
116 nVersion
= SM_FMT_VERSION_NOW
;
118 eHorAlign
= AlignCenter
;
119 bIsTextmode
= bScaleNormalBrackets
= FALSE
;
121 vSize
[SIZ_TEXT
] = 100;
122 vSize
[SIZ_INDEX
] = 60;
123 vSize
[SIZ_FUNCTION
] =
124 vSize
[SIZ_OPERATOR
] = 100;
125 vSize
[SIZ_LIMITS
] = 60;
127 vDist
[DIS_HORIZONTAL
] = 10;
128 vDist
[DIS_VERTICAL
] = 5;
130 vDist
[DIS_SUPERSCRIPT
] =
131 vDist
[DIS_SUBSCRIPT
] = 20;
132 vDist
[DIS_NUMERATOR
] =
133 vDist
[DIS_DENOMINATOR
] = 0;
134 vDist
[DIS_FRACTION
] = 10;
135 vDist
[DIS_STROKEWIDTH
] = 5;
136 vDist
[DIS_UPPERLIMIT
] =
137 vDist
[DIS_LOWERLIMIT
] = 0;
138 vDist
[DIS_BRACKETSIZE
] =
139 vDist
[DIS_BRACKETSPACE
] = 5;
140 vDist
[DIS_MATRIXROW
] = 3;
141 vDist
[DIS_MATRIXCOL
] = 30;
142 vDist
[DIS_ORNAMENTSIZE
] =
143 vDist
[DIS_ORNAMENTSPACE
] = 0;
144 vDist
[DIS_OPERATORSIZE
] = 50;
145 vDist
[DIS_OPERATORSPACE
] = 20;
146 vDist
[DIS_LEFTSPACE
] =
147 vDist
[DIS_RIGHTSPACE
] = 100;
148 vDist
[DIS_TOPSPACE
] =
149 vDist
[DIS_BOTTOMSPACE
] =
150 vDist
[DIS_NORMALBRACKETSIZE
] = 0;
152 vFont
[FNT_VARIABLE
] =
153 vFont
[FNT_FUNCTION
] =
156 vFont
[FNT_SERIF
] = SmFace(C2S(FNTNAME_TIMES
), aBaseSize
);
157 vFont
[FNT_SANS
] = SmFace(C2S(FNTNAME_HELV
), aBaseSize
);
158 vFont
[FNT_FIXED
] = SmFace(C2S(FNTNAME_COUR
), aBaseSize
);
159 vFont
[FNT_MATH
] = SmFace(C2S(FNTNAME_MATH
), aBaseSize
);
161 vFont
[FNT_MATH
].SetCharSet( RTL_TEXTENCODING_UNICODE
);
163 vFont
[FNT_VARIABLE
].SetItalic(ITALIC_NORMAL
);
164 vFont
[FNT_FUNCTION
].SetItalic(ITALIC_NONE
);
165 vFont
[FNT_NUMBER
] .SetItalic(ITALIC_NONE
);
166 vFont
[FNT_TEXT
] .SetItalic(ITALIC_NONE
);
167 vFont
[FNT_SERIF
] .SetItalic(ITALIC_NONE
);
168 vFont
[FNT_SANS
] .SetItalic(ITALIC_NONE
);
169 vFont
[FNT_FIXED
] .SetItalic(ITALIC_NONE
);
171 for ( USHORT i
= FNT_BEGIN
; i
<= FNT_END
; i
++ )
173 SmFace
&rFace
= vFont
[i
];
174 rFace
.SetTransparent( TRUE
);
175 rFace
.SetAlign( ALIGN_BASELINE
);
176 rFace
.SetColor( COL_AUTO
);
177 bDefaultFont
[i
] = FALSE
;
182 void SmFormat::SetFont(USHORT nIdent
, const SmFace
&rFont
, BOOL bDefault
)
184 vFont
[nIdent
] = rFont
;
185 vFont
[nIdent
].SetTransparent( TRUE
);
186 vFont
[nIdent
].SetAlign( ALIGN_BASELINE
);
188 bDefaultFont
[nIdent
] = bDefault
;
191 SmFormat
& SmFormat::operator = (const SmFormat
&rFormat
)
193 SetBaseSize(rFormat
.GetBaseSize());
194 SetVersion (rFormat
.GetVersion());
195 SetHorAlign(rFormat
.GetHorAlign());
196 SetTextmode(rFormat
.IsTextmode());
197 SetScaleNormalBrackets(rFormat
.IsScaleNormalBrackets());
200 for (i
= FNT_BEGIN
; i
<= FNT_END
; i
++)
202 SetFont(i
, rFormat
.GetFont(i
));
203 SetDefaultFont(i
, rFormat
.IsDefaultFont(i
));
205 for (i
= SIZ_BEGIN
; i
<= SIZ_END
; i
++)
206 SetRelSize(i
, rFormat
.GetRelSize(i
));
207 for (i
= DIS_BEGIN
; i
<= DIS_END
; i
++)
208 SetDistance(i
, rFormat
.GetDistance(i
));
214 BOOL
SmFormat::operator == (const SmFormat
&rFormat
) const
216 BOOL bRes
= aBaseSize
== rFormat
.aBaseSize
&&
217 eHorAlign
== rFormat
.eHorAlign
&&
218 bIsTextmode
== rFormat
.bIsTextmode
&&
219 bScaleNormalBrackets
== rFormat
.bScaleNormalBrackets
;
222 for (i
= 0; i
<= SIZ_END
&& bRes
; ++i
)
224 if (vSize
[i
] != rFormat
.vSize
[i
])
227 for (i
= 0; i
<= DIS_END
&& bRes
; ++i
)
229 if (vDist
[i
] != rFormat
.vDist
[i
])
232 for (i
= 0; i
<= FNT_END
&& bRes
; ++i
)
234 if (vFont
[i
] != rFormat
.vFont
[i
] ||
235 bDefaultFont
[i
] != rFormat
.bDefaultFont
[i
])