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 258 : XFFont::XFFont()
63 : {
64 258 : m_nFontSize = 0;
65 258 : m_nFontSizeAsia = 0;
66 258 : m_nFontSizeComplex = 0;
67 258 : m_bItalic = sal_False;
68 258 : m_bItalicAsia = sal_False;
69 258 : m_bItalicComplex = sal_False;
70 258 : m_bBold = sal_False;
71 258 : m_bBoldAsia = sal_False;
72 258 : m_bBoldComplex = sal_False;
73 258 : m_eUnderline = enumXFUnderlineNone;
74 258 : m_eCrossout = enumXFCrossoutNone;
75 258 : m_eRelief = enumXFReliefNone;
76 258 : m_eTransform = enumXFTransformNone;
77 258 : m_eEmphasize = enumXFEmphasizeNone;
78 258 : m_bEmphasizeTop = sal_True;
79 258 : m_bOutline = sal_False;
80 258 : m_bShadow = sal_False;
81 258 : m_bBlink = sal_False;
82 258 : m_nPosition = 33;
83 258 : m_nScale = 58;
84 258 : m_fCharSpace = 0;
85 258 : m_nWidthScale = 100;
86 258 : m_bWordByWord = sal_False;
87 258 : m_nFlag = 0;
88 258 : }
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 3896 : bool operator==(XFFont& f1, XFFont& f2)
109 : {
110 : //The most possible entry be first:
111 3896 : if( f1.m_nFlag != f2.m_nFlag )
112 2788 : return false;
113 :
114 3208 : if( f1.m_strFontName != f2.m_strFontName ||
115 1050 : f1.m_strFontNameAsia != f2.m_strFontNameAsia ||
116 1050 : f1.m_strFontNameComplex != f2.m_strFontNameComplex
117 : )
118 58 : return false;
119 :
120 1050 : if( f1.m_nFontSize != f2.m_nFontSize ||
121 : f1.m_nFontSizeAsia != f2.m_nFontSizeAsia ||
122 : f1.m_nFontSizeComplex != f2.m_nFontSizeComplex
123 : )
124 368 : return false;
125 :
126 682 : 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 682 : if( f1.m_bBold != f2.m_bBold ||
133 : f1.m_bBoldAsia != f2.m_bBoldAsia ||
134 : f1.m_bBoldComplex != f2.m_bBoldComplex
135 : )
136 4 : return false;
137 :
138 678 : if( f1.m_nFlag&XFFONT_FLAG_UNDERLINE )
139 : {
140 0 : if( f1.m_eUnderline != f2.m_eUnderline )
141 0 : return false;
142 : }
143 :
144 678 : if( f1.m_nFlag&XFFONT_FLAG_UNDERLINECOLOR )
145 : {
146 0 : if( f1.m_aUnderlineColor != f2.m_aUnderlineColor )
147 0 : return false;
148 : }
149 :
150 678 : if( f1.m_nFlag&XFFONT_FLAG_CROSSOUT )
151 : {
152 380 : if( f1.m_eCrossout != f2.m_eCrossout )
153 0 : return false;
154 : }
155 :
156 678 : if( f1.m_nFlag&XFFONT_FLAG_RELIEF )
157 : {
158 0 : if( f1.m_eRelief != f2.m_eRelief )
159 0 : return false;
160 : }
161 :
162 678 : if( f1.m_nFlag&XFFONT_FLAG_TRANSFORM )
163 : {
164 380 : if( f1.m_eTransform != f2.m_eTransform )
165 0 : return false;
166 : }
167 :
168 678 : 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 678 : if( f1.m_bWordByWord != f2.m_bWordByWord )
177 0 : return false;
178 :
179 678 : if( f1.m_nFlag&XFFONT_FLAG_OUTLINE )
180 : {
181 0 : if( f1.m_bOutline != f2.m_bOutline )
182 0 : return false;
183 : }
184 :
185 678 : if( f1.m_nFlag&XFFONT_FLAG_SHADOW )
186 : {
187 0 : if( f1.m_bShadow != f2.m_bShadow )
188 0 : return false;
189 : }
190 :
191 678 : if( f1.m_nFlag&XFFONT_FLAG_BLINK )
192 : {
193 0 : if( f1.m_bBlink != f2.m_bBlink )
194 0 : return false;
195 : }
196 :
197 678 : if( f1.m_nFlag&XFFONT_FLAG_POSITION )
198 : {
199 2 : if( f1.m_nPosition != f2.m_nPosition )
200 2 : return false;
201 : }
202 :
203 676 : if( f1.m_nFlag&XFFONT_FLAG_SCALE )
204 : {
205 0 : if( f1.m_nScale != f2.m_nScale )
206 0 : return false;
207 : }
208 :
209 676 : if( f1.m_nFlag&XFFONT_FLAG_CHARSPACE )
210 : {
211 0 : if( f1.m_fCharSpace != f2.m_fCharSpace )
212 0 : return false;
213 : }
214 :
215 676 : if( f1.m_nFlag&XFFONT_FLAG_WIDTHSCALE )
216 : {
217 0 : if( f1.m_nWidthScale != f2.m_nWidthScale )
218 0 : return false;
219 : }
220 :
221 676 : if( f1.m_nFlag&XFFONT_FLAG_COLOR )
222 : {
223 404 : if( f1.m_aColor != f2.m_aColor )
224 0 : return false;
225 : }
226 :
227 676 : if( f1.m_nFlag&XFFONT_FLAG_BGCOLOR )
228 : {
229 380 : if( f1.m_aBackColor != f2.m_aBackColor )
230 0 : return false;
231 : }
232 :
233 676 : return true;
234 : }
235 :
236 888 : bool operator!=(XFFont& f1, XFFont& f2)
237 : {
238 888 : return !(f1==f2);
239 : }
240 :
241 :
242 101 : void XFFont::ToXml(IXFStream *pStrm)
243 : {
244 101 : IXFAttrList *pAttrList = pStrm->GetAttrList();
245 :
246 101 : if( m_nFlag & XFFONT_FLAG_NAME )
247 : {
248 89 : pAttrList->AddAttribute(A2OUSTR("style:font-name"),m_strFontName );
249 : }
250 :
251 101 : if( m_nFlag & XFFONT_FLAG_NAME_ASIA )
252 : {
253 89 : pAttrList->AddAttribute(A2OUSTR("style:font-name-asian"),m_strFontNameAsia );
254 : }
255 :
256 101 : if( m_nFlag & XFFONT_FLAG_NAME_COMPLEX )
257 : {
258 89 : pAttrList->AddAttribute(A2OUSTR("style:font-name-complex"), m_strFontNameComplex);
259 : }
260 :
261 : //font size:
262 101 : if( (m_nFlag & XFFONT_FLAG_SIZE) && m_nFontSize != 0 )
263 : {
264 87 : rtl::OUString strSize = Int32ToOUString(m_nFontSize);
265 87 : strSize += A2OUSTR("pt");
266 87 : pAttrList->AddAttribute(A2OUSTR("fo:font-size"),strSize);
267 : }
268 101 : if( (m_nFlag & XFFONT_FLAG_SIZE_ASIA) && m_nFontSizeAsia )
269 : {
270 87 : rtl::OUString strSize = Int32ToOUString(m_nFontSizeAsia);
271 87 : strSize += A2OUSTR("pt");
272 87 : pAttrList->AddAttribute(A2OUSTR("style:font-size-asian"),strSize);
273 : }
274 101 : if( (m_nFlag & XFFONT_FLAG_SIZE_COMPLEX) && m_nFontSizeComplex )
275 : {
276 87 : rtl::OUString strSize = Int32ToOUString(m_nFontSizeComplex);
277 87 : strSize += A2OUSTR("pt");
278 87 : pAttrList->AddAttribute(A2OUSTR("style:font-size-complex"),strSize);
279 : }
280 :
281 : //italic flag:
282 101 : if( ( m_nFlag & XFFONT_FLAG_ITALIC) && m_bItalic )
283 : {
284 3 : pAttrList->AddAttribute(A2OUSTR("fo:font-style"), A2OUSTR("italic"));
285 : }
286 101 : if( (m_nFlag & XFFONT_FLAG_ITALIC_ASIA) && m_bItalicAsia )
287 : {
288 3 : pAttrList->AddAttribute(A2OUSTR("style:font-style-asian"), A2OUSTR("italic"));
289 : }
290 101 : if( (m_nFlag & XFFONT_FLAG_ITALIC_COMPLEX) && m_bItalicComplex )
291 : {
292 3 : pAttrList->AddAttribute(A2OUSTR("style:font-style-complex"), A2OUSTR("italic"));
293 : }
294 :
295 : //Bold flag:
296 101 : if( (m_nFlag & XFFONT_FLAG_BOLD) && m_bBold )
297 : {
298 13 : pAttrList->AddAttribute(A2OUSTR("fo:font-weight"), A2OUSTR("bold"));
299 : }
300 101 : if( (m_nFlag & XFFONT_FLAG_BOLD_ASIA) && m_bBoldAsia )
301 : {
302 13 : pAttrList->AddAttribute(A2OUSTR("style:font-weight-asian"), A2OUSTR("bold"));
303 : }
304 101 : if( (m_nFlag & XFFONT_FLAG_BOLD_ASIA) && m_bBoldComplex )
305 : {
306 13 : pAttrList->AddAttribute(A2OUSTR("style:font-weight-complex"), A2OUSTR("bold"));
307 : }
308 : //underline:
309 101 : if( (m_nFlag & XFFONT_FLAG_UNDERLINE) && m_eUnderline )
310 : {
311 1 : pAttrList->AddAttribute(A2OUSTR("style:text-underline"), GetUnderlineName(m_eUnderline) );
312 1 : if( (m_nFlag & XFFONT_FLAG_UNDERLINECOLOR) )
313 : {
314 0 : pAttrList->AddAttribute( A2OUSTR("style:text-underline-color"), m_aUnderlineColor.ToString() );
315 : }
316 : else
317 1 : pAttrList->AddAttribute( A2OUSTR("style:text-underline-color"), A2OUSTR("font-color") );
318 : }
319 :
320 : //enumCrossoutType m_eCrossout;
321 101 : if( (m_nFlag & XFFONT_FLAG_CROSSOUT) && m_eCrossout )
322 : {
323 1 : pAttrList->AddAttribute(A2OUSTR("style:text-crossing-out"), GetCrossoutName(m_eCrossout) );
324 : }
325 :
326 101 : if( m_nFlag & XFFONT_FLAG_UNDERLINE || m_nFlag & XFFONT_FLAG_CROSSOUT )
327 : {
328 74 : if( m_bWordByWord )
329 0 : pAttrList->AddAttribute(A2OUSTR("fo:score-spaces"), A2OUSTR("false") );
330 : else
331 74 : pAttrList->AddAttribute(A2OUSTR("fo:score-spaces"), A2OUSTR("true") );
332 : }
333 :
334 101 : if( (m_nFlag & XFFONT_FLAG_RELIEF) && m_eRelief )
335 : {
336 0 : pAttrList->AddAttribute(A2OUSTR("style:font-relief"), GetReliefName(m_eRelief) );
337 : }
338 :
339 101 : 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 101 : 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 101 : if( (m_nFlag & XFFONT_FLAG_OUTLINE) && m_bOutline )
358 : {
359 0 : pAttrList->AddAttribute(A2OUSTR("style:text-outline"), A2OUSTR("true") );
360 : }
361 :
362 101 : if( (m_nFlag & XFFONT_FLAG_SHADOW) && m_bShadow )
363 : {
364 0 : pAttrList->AddAttribute(A2OUSTR("fo:text-shadow"), A2OUSTR("1pt 1pt") );
365 : }
366 :
367 101 : 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 101 : if( ((m_nFlag & XFFONT_FLAG_SCALE) && m_nScale>0 ) ||
375 : ((m_nFlag & XFFONT_FLAG_POSITION) && m_nPosition != 0)
376 : )
377 : {
378 2 : rtl::OUString tmp;
379 2 : tmp = Int32ToOUString(m_nPosition) + A2OUSTR("% ");
380 2 : tmp += Int32ToOUString(m_nScale) + A2OUSTR("%");
381 2 : pAttrList->AddAttribute(A2OUSTR("style:text-position"), tmp );
382 : }
383 :
384 : //char space:
385 101 : 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 101 : 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 101 : if( (m_nFlag & XFFONT_FLAG_COLOR) )
397 : {
398 84 : pAttrList->AddAttribute( A2OUSTR("fo:color"), m_aColor.ToString() );
399 : }
400 :
401 101 : if( (m_nFlag & XFFONT_FLAG_BGCOLOR) )
402 : {
403 72 : if (m_bTransparent)
404 72 : 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 101 : }
409 :
410 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|