Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * The Contents of this file are made available subject to the terms of
5 : : * either of the following licenses
6 : : *
7 : : * - GNU Lesser General Public License Version 2.1
8 : : * - Sun Industry Standards Source License Version 1.1
9 : : *
10 : : * Sun Microsystems Inc., October, 2000
11 : : *
12 : : * GNU Lesser General Public License Version 2.1
13 : : * =============================================
14 : : * Copyright 2000 by Sun Microsystems, Inc.
15 : : * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 : : *
17 : : * This library is free software; you can redistribute it and/or
18 : : * modify it under the terms of the GNU Lesser General Public
19 : : * License version 2.1, as published by the Free Software Foundation.
20 : : *
21 : : * This library is distributed in the hope that it will be useful,
22 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 : : * Lesser General Public License for more details.
25 : : *
26 : : * You should have received a copy of the GNU Lesser General Public
27 : : * License along with this library; if not, write to the Free Software
28 : : * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 : : * MA 02111-1307 USA
30 : : *
31 : : *
32 : : * Sun Industry Standards Source License Version 1.1
33 : : * =================================================
34 : : * The contents of this file are subject to the Sun Industry Standards
35 : : * Source License Version 1.1 (the "License"); You may not use this file
36 : : * except in compliance with the License. You may obtain a copy of the
37 : : * License at http://www.openoffice.org/license.html.
38 : : *
39 : : * Software provided under this License is provided on an "AS IS" basis,
40 : : * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 : : * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 : : * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 : : * See the License for the specific provisions governing your rights and
44 : : * obligations concerning the Software.
45 : : *
46 : : * The Initial Developer of the Original Code is: IBM Corporation
47 : : *
48 : : * Copyright: 2008 by IBM Corporation
49 : : *
50 : : * All Rights Reserved.
51 : : *
52 : : * Contributor(s): _______________________________________
53 : : *
54 : : *
55 : : ************************************************************************/
56 : : /*************************************************************************
57 : : * @file
58 : : * Font object to serial to xml filter.
59 : : ************************************************************************/
60 : : #include "xffont.hxx"
61 : :
62 : 1290 : XFFont::XFFont()
63 : : {
64 : 1290 : m_nFontSize = 0;
65 : 1290 : m_nFontSizeAsia = 0;
66 : 1290 : m_nFontSizeComplex = 0;
67 : 1290 : m_bItalic = sal_False;
68 : 1290 : m_bItalicAsia = sal_False;
69 : 1290 : m_bItalicComplex = sal_False;
70 : 1290 : m_bBold = sal_False;
71 : 1290 : m_bBoldAsia = sal_False;
72 : 1290 : m_bBoldComplex = sal_False;
73 : 1290 : m_eUnderline = enumXFUnderlineNone;
74 : 1290 : m_eCrossout = enumXFCrossoutNone;
75 : 1290 : m_eRelief = enumXFReliefNone;
76 : 1290 : m_eTransform = enumXFTransformNone;
77 : 1290 : m_eEmphasize = enumXFEmphasizeNone;
78 : 1290 : m_bEmphasizeTop = sal_True;
79 : 1290 : m_bOutline = sal_False;
80 : 1290 : m_bShadow = sal_False;
81 : 1290 : m_bBlink = sal_False;
82 : 1290 : m_nPosition = 33;
83 : 1290 : m_nScale = 58;
84 : 1290 : m_fCharSpace = 0;
85 : 1290 : m_nWidthScale = 100;
86 : 1290 : m_bWordByWord = sal_False;
87 : 1290 : m_nFlag = 0;
88 : 1290 : }
89 : : /*
90 : : The Following variable are to be compared:
91 : : rtl::OUString m_strFontName;
92 : : rtl::OUString m_strFontNameAsia;
93 : : rtl::OUString m_strFontNameComplex;
94 : : sal_Int16 m_nFontSize;
95 : : sal_Int16 m_nFontSizeAsia;
96 : : sal_Int16 m_nFontSizeComplex;
97 : : sal_Bool m_bItalic;
98 : : sal_Bool m_bItalicAsia;
99 : : sal_Bool m_bItalicComplex;
100 : : sal_Bool m_bBold;
101 : : sal_Bool m_bBoldAsia;
102 : : sal_Bool m_bBoldComplex;
103 : : sal_Int16 m_nUnderline;
104 : : sal_uInt32 m_nUnderlineColor;
105 : :
106 : : sal_uInt32 m_nFlag;
107 : : */
108 : 19480 : bool operator==(XFFont& f1, XFFont& f2)
109 : : {
110 : : //The most possible entry be first:
111 [ + + ]: 19480 : if( f1.m_nFlag != f2.m_nFlag )
112 : 13940 : return false;
113 : :
114 [ + + + - : 16040 : if( f1.m_strFontName != f2.m_strFontName ||
- + ][ + + ]
115 : 5250 : f1.m_strFontNameAsia != f2.m_strFontNameAsia ||
116 : 5250 : f1.m_strFontNameComplex != f2.m_strFontNameComplex
117 : : )
118 : 290 : return false;
119 : :
120 [ + + ][ + - ]: 5250 : if( f1.m_nFontSize != f2.m_nFontSize ||
[ - + ]
121 : : f1.m_nFontSizeAsia != f2.m_nFontSizeAsia ||
122 : : f1.m_nFontSizeComplex != f2.m_nFontSizeComplex
123 : : )
124 : 1840 : return false;
125 : :
126 [ + - ][ + - ]: 3410 : if( f1.m_bItalic != f2.m_bItalic ||
[ - + ]
127 : : f1.m_bItalicAsia != f2.m_bItalicAsia ||
128 : : f1.m_bItalicComplex != f2.m_bItalicComplex
129 : : )
130 : 0 : return false;
131 : :
132 [ + + ][ + - ]: 3410 : if( f1.m_bBold != f2.m_bBold ||
[ - + ]
133 : : f1.m_bBoldAsia != f2.m_bBoldAsia ||
134 : : f1.m_bBoldComplex != f2.m_bBoldComplex
135 : : )
136 : 20 : return false;
137 : :
138 [ - + ]: 3390 : if( f1.m_nFlag&XFFONT_FLAG_UNDERLINE )
139 : : {
140 [ # # ]: 0 : if( f1.m_eUnderline != f2.m_eUnderline )
141 : 0 : return false;
142 : : }
143 : :
144 [ - + ]: 3390 : if( f1.m_nFlag&XFFONT_FLAG_UNDERLINECOLOR )
145 : : {
146 [ # # ]: 0 : if( f1.m_aUnderlineColor != f2.m_aUnderlineColor )
147 : 0 : return false;
148 : : }
149 : :
150 [ + + ]: 3390 : if( f1.m_nFlag&XFFONT_FLAG_CROSSOUT )
151 : : {
152 [ - + ]: 1900 : if( f1.m_eCrossout != f2.m_eCrossout )
153 : 0 : return false;
154 : : }
155 : :
156 [ - + ]: 3390 : if( f1.m_nFlag&XFFONT_FLAG_RELIEF )
157 : : {
158 [ # # ]: 0 : if( f1.m_eRelief != f2.m_eRelief )
159 : 0 : return false;
160 : : }
161 : :
162 [ + + ]: 3390 : if( f1.m_nFlag&XFFONT_FLAG_TRANSFORM )
163 : : {
164 [ - + ]: 1900 : if( f1.m_eTransform != f2.m_eTransform )
165 : 0 : return false;
166 : : }
167 : :
168 [ - + ]: 3390 : if( f1.m_nFlag&XFFONT_FLAG_EMPHASIZE )
169 : : {
170 [ # # ]: 0 : if( f1.m_eEmphasize != f2.m_eEmphasize )
171 : 0 : return false;
172 [ # # ]: 0 : if( f1.m_bEmphasizeTop != f2.m_bEmphasizeTop )
173 : 0 : return false;
174 : : }
175 : :
176 [ - + ]: 3390 : if( f1.m_bWordByWord != f2.m_bWordByWord )
177 : 0 : return false;
178 : :
179 [ - + ]: 3390 : if( f1.m_nFlag&XFFONT_FLAG_OUTLINE )
180 : : {
181 [ # # ]: 0 : if( f1.m_bOutline != f2.m_bOutline )
182 : 0 : return false;
183 : : }
184 : :
185 [ - + ]: 3390 : if( f1.m_nFlag&XFFONT_FLAG_SHADOW )
186 : : {
187 [ # # ]: 0 : if( f1.m_bShadow != f2.m_bShadow )
188 : 0 : return false;
189 : : }
190 : :
191 [ - + ]: 3390 : if( f1.m_nFlag&XFFONT_FLAG_BLINK )
192 : : {
193 [ # # ]: 0 : if( f1.m_bBlink != f2.m_bBlink )
194 : 0 : return false;
195 : : }
196 : :
197 [ + + ]: 3390 : if( f1.m_nFlag&XFFONT_FLAG_POSITION )
198 : : {
199 [ + - ]: 10 : if( f1.m_nPosition != f2.m_nPosition )
200 : 10 : return false;
201 : : }
202 : :
203 [ - + ]: 3380 : if( f1.m_nFlag&XFFONT_FLAG_SCALE )
204 : : {
205 [ # # ]: 0 : if( f1.m_nScale != f2.m_nScale )
206 : 0 : return false;
207 : : }
208 : :
209 [ - + ]: 3380 : if( f1.m_nFlag&XFFONT_FLAG_CHARSPACE )
210 : : {
211 [ # # ]: 0 : if( f1.m_fCharSpace != f2.m_fCharSpace )
212 : 0 : return false;
213 : : }
214 : :
215 [ - + ]: 3380 : if( f1.m_nFlag&XFFONT_FLAG_WIDTHSCALE )
216 : : {
217 [ # # ]: 0 : if( f1.m_nWidthScale != f2.m_nWidthScale )
218 : 0 : return false;
219 : : }
220 : :
221 [ + + ]: 3380 : if( f1.m_nFlag&XFFONT_FLAG_COLOR )
222 : : {
223 [ - + ]: 2020 : if( f1.m_aColor != f2.m_aColor )
224 : 0 : return false;
225 : : }
226 : :
227 [ + + ]: 3380 : if( f1.m_nFlag&XFFONT_FLAG_BGCOLOR )
228 : : {
229 [ - + ]: 1900 : if( f1.m_aBackColor != f2.m_aBackColor )
230 : 0 : return false;
231 : : }
232 : :
233 : 19480 : return true;
234 : : }
235 : :
236 : 4440 : bool operator!=(XFFont& f1, XFFont& f2)
237 : : {
238 : 4440 : return !(f1==f2);
239 : : }
240 : :
241 : :
242 : 505 : void XFFont::ToXml(IXFStream *pStrm)
243 : : {
244 : 505 : IXFAttrList *pAttrList = pStrm->GetAttrList();
245 : :
246 [ + + ]: 505 : if( m_nFlag & XFFONT_FLAG_NAME )
247 : : {
248 [ + - ]: 445 : pAttrList->AddAttribute(A2OUSTR("style:font-name"),m_strFontName );
249 : : }
250 : :
251 [ + + ]: 505 : if( m_nFlag & XFFONT_FLAG_NAME_ASIA )
252 : : {
253 [ + - ]: 445 : pAttrList->AddAttribute(A2OUSTR("style:font-name-asian"),m_strFontNameAsia );
254 : : }
255 : :
256 [ + + ]: 505 : if( m_nFlag & XFFONT_FLAG_NAME_COMPLEX )
257 : : {
258 [ + - ]: 445 : pAttrList->AddAttribute(A2OUSTR("style:font-name-complex"), m_strFontNameComplex);
259 : : }
260 : :
261 : : //font size:
262 [ + + ][ + - ]: 505 : if( (m_nFlag & XFFONT_FLAG_SIZE) && m_nFontSize != 0 )
263 : : {
264 [ + - ]: 435 : rtl::OUString strSize = Int32ToOUString(m_nFontSize);
265 : 435 : strSize += A2OUSTR("pt");
266 [ + - ]: 435 : pAttrList->AddAttribute(A2OUSTR("fo:font-size"),strSize);
267 : : }
268 [ + + ][ + - ]: 505 : if( (m_nFlag & XFFONT_FLAG_SIZE_ASIA) && m_nFontSizeAsia )
269 : : {
270 [ + - ]: 435 : rtl::OUString strSize = Int32ToOUString(m_nFontSizeAsia);
271 : 435 : strSize += A2OUSTR("pt");
272 [ + - ]: 435 : pAttrList->AddAttribute(A2OUSTR("style:font-size-asian"),strSize);
273 : : }
274 [ + + ][ + - ]: 505 : if( (m_nFlag & XFFONT_FLAG_SIZE_COMPLEX) && m_nFontSizeComplex )
275 : : {
276 [ + - ]: 435 : rtl::OUString strSize = Int32ToOUString(m_nFontSizeComplex);
277 : 435 : strSize += A2OUSTR("pt");
278 [ + - ]: 435 : pAttrList->AddAttribute(A2OUSTR("style:font-size-complex"),strSize);
279 : : }
280 : :
281 : : //italic flag:
282 [ + + ][ + + ]: 505 : if( ( m_nFlag & XFFONT_FLAG_ITALIC) && m_bItalic )
283 : : {
284 [ + - ]: 15 : pAttrList->AddAttribute(A2OUSTR("fo:font-style"), A2OUSTR("italic"));
285 : : }
286 [ + + ][ + + ]: 505 : if( (m_nFlag & XFFONT_FLAG_ITALIC_ASIA) && m_bItalicAsia )
287 : : {
288 [ + - ]: 15 : pAttrList->AddAttribute(A2OUSTR("style:font-style-asian"), A2OUSTR("italic"));
289 : : }
290 [ + + ][ + + ]: 505 : if( (m_nFlag & XFFONT_FLAG_ITALIC_COMPLEX) && m_bItalicComplex )
291 : : {
292 [ + - ]: 15 : pAttrList->AddAttribute(A2OUSTR("style:font-style-complex"), A2OUSTR("italic"));
293 : : }
294 : :
295 : : //Bold flag:
296 [ + + ][ + + ]: 505 : if( (m_nFlag & XFFONT_FLAG_BOLD) && m_bBold )
297 : : {
298 [ + - ]: 65 : pAttrList->AddAttribute(A2OUSTR("fo:font-weight"), A2OUSTR("bold"));
299 : : }
300 [ + + ][ + + ]: 505 : if( (m_nFlag & XFFONT_FLAG_BOLD_ASIA) && m_bBoldAsia )
301 : : {
302 [ + - ]: 65 : pAttrList->AddAttribute(A2OUSTR("style:font-weight-asian"), A2OUSTR("bold"));
303 : : }
304 [ + + ][ + + ]: 505 : if( (m_nFlag & XFFONT_FLAG_BOLD_ASIA) && m_bBoldComplex )
305 : : {
306 [ + - ]: 65 : pAttrList->AddAttribute(A2OUSTR("style:font-weight-complex"), A2OUSTR("bold"));
307 : : }
308 : : //underline:
309 [ + + ][ + - ]: 505 : if( (m_nFlag & XFFONT_FLAG_UNDERLINE) && m_eUnderline )
310 : : {
311 [ + - ]: 5 : pAttrList->AddAttribute(A2OUSTR("style:text-underline"), GetUnderlineName(m_eUnderline) );
312 [ - + ]: 5 : if( (m_nFlag & XFFONT_FLAG_UNDERLINECOLOR) )
313 : : {
314 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("style:text-underline-color"), m_aUnderlineColor.ToString() );
315 : : }
316 : : else
317 [ + - ]: 5 : pAttrList->AddAttribute( A2OUSTR("style:text-underline-color"), A2OUSTR("font-color") );
318 : : }
319 : :
320 : : //enumCrossoutType m_eCrossout;
321 [ + + ][ + + ]: 505 : if( (m_nFlag & XFFONT_FLAG_CROSSOUT) && m_eCrossout )
322 : : {
323 [ + - ]: 5 : pAttrList->AddAttribute(A2OUSTR("style:text-crossing-out"), GetCrossoutName(m_eCrossout) );
324 : : }
325 : :
326 [ + + ][ + + ]: 505 : if( m_nFlag & XFFONT_FLAG_UNDERLINE || m_nFlag & XFFONT_FLAG_CROSSOUT )
327 : : {
328 [ - + ]: 370 : if( m_bWordByWord )
329 [ # # ]: 0 : pAttrList->AddAttribute(A2OUSTR("fo:score-spaces"), A2OUSTR("false") );
330 : : else
331 [ + - ]: 370 : pAttrList->AddAttribute(A2OUSTR("fo:score-spaces"), A2OUSTR("true") );
332 : : }
333 : :
334 [ - + ][ # # ]: 505 : if( (m_nFlag & XFFONT_FLAG_RELIEF) && m_eRelief )
335 : : {
336 [ # # ]: 0 : pAttrList->AddAttribute(A2OUSTR("style:font-relief"), GetReliefName(m_eRelief) );
337 : : }
338 : :
339 [ + + ][ - + ]: 505 : if( (m_nFlag & XFFONT_FLAG_TRANSFORM) && m_eTransform )
340 : : {
341 : : //enumTransformSmallCap is different:
342 [ # # ]: 0 : if( m_eTransform == enumXFTransformSmallCaps )
343 [ # # ]: 0 : pAttrList->AddAttribute(A2OUSTR("fo:font-variant"), GetTransformName(m_eTransform) );
344 : : else
345 [ # # ]: 0 : pAttrList->AddAttribute(A2OUSTR("fo:text-transform"), GetTransformName(m_eTransform) );
346 : : }
347 : :
348 [ - + ][ # # ]: 505 : if( (m_nFlag & XFFONT_FLAG_EMPHASIZE) && m_eEmphasize )
349 : : {
350 [ # # ]: 0 : rtl::OUString empha = GetEmphasizeName(m_eEmphasize);
351 : 0 : empha += A2OUSTR(" ");
352 [ # # ]: 0 : if( m_bEmphasizeTop )
353 : 0 : empha += A2OUSTR("above");
354 [ # # ]: 0 : pAttrList->AddAttribute(A2OUSTR("style:text-emphasize"), empha );
355 : : }
356 : :
357 [ - + ][ # # ]: 505 : if( (m_nFlag & XFFONT_FLAG_OUTLINE) && m_bOutline )
358 : : {
359 [ # # ]: 0 : pAttrList->AddAttribute(A2OUSTR("style:text-outline"), A2OUSTR("true") );
360 : : }
361 : :
362 [ - + ][ # # ]: 505 : if( (m_nFlag & XFFONT_FLAG_SHADOW) && m_bShadow )
363 : : {
364 [ # # ]: 0 : pAttrList->AddAttribute(A2OUSTR("fo:text-shadow"), A2OUSTR("1pt 1pt") );
365 : : }
366 : :
367 [ - + ][ # # ]: 505 : if( (m_nFlag & XFFONT_FLAG_BLINK) && m_bBlink )
368 : : {
369 [ # # ]: 0 : pAttrList->AddAttribute(A2OUSTR("style:text-blinking"), A2OUSTR("true") );
370 : : }
371 : :
372 : :
373 : : //position & sacle:
374 [ - + ][ # # ]: 505 : if( ((m_nFlag & XFFONT_FLAG_SCALE) && m_nScale>0 ) ||
[ + + ][ + - ]
375 : : ((m_nFlag & XFFONT_FLAG_POSITION) && m_nPosition != 0)
376 : : )
377 : : {
378 : 10 : rtl::OUString tmp;
379 [ + - ]: 10 : tmp = Int32ToOUString(m_nPosition) + A2OUSTR("% ");
380 [ + - ]: 10 : tmp += Int32ToOUString(m_nScale) + A2OUSTR("%");
381 [ + - ]: 10 : pAttrList->AddAttribute(A2OUSTR("style:text-position"), tmp );
382 : : }
383 : :
384 : : //char space:
385 [ - + ][ # # ]: 505 : if( (m_nFlag & XFFONT_FLAG_CHARSPACE) && m_fCharSpace != 0 )
386 : : {
387 [ # # ][ # # ]: 0 : pAttrList->AddAttribute(A2OUSTR("fo:letter-spacing"), DoubleToOUString(m_fCharSpace)+A2OUSTR("cm") );
388 : : }
389 : :
390 [ - + ][ # # ]: 505 : if( (m_nFlag&XFFONT_FLAG_WIDTHSCALE) && m_nWidthScale != 100 )
391 : : {
392 [ # # ][ # # ]: 0 : pAttrList->AddAttribute(A2OUSTR("style:text-scale"), DoubleToOUString(m_nWidthScale)+A2OUSTR("%") );
393 : : }
394 : :
395 : : //Color:
396 [ + + ]: 505 : if( (m_nFlag & XFFONT_FLAG_COLOR) )
397 : : {
398 [ + - ]: 420 : pAttrList->AddAttribute( A2OUSTR("fo:color"), m_aColor.ToString() );
399 : : }
400 : :
401 [ + + ]: 505 : if( (m_nFlag & XFFONT_FLAG_BGCOLOR) )
402 : : {
403 [ + - ]: 360 : if (m_bTransparent)
404 [ + - ]: 360 : pAttrList->AddAttribute( A2OUSTR("style:text-background-color"), A2OUSTR("transparent"));
405 : : else
406 [ # # ]: 0 : pAttrList->AddAttribute( A2OUSTR("style:text-background-color"), m_aBackColor.ToString() );
407 : : }
408 : 505 : }
409 : :
410 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|