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 : #include "lwpglobalmgr.hxx"
57 : #include "lwpfont.hxx"
58 : #include "xfilter/xfstylemanager.hxx"
59 : #include "xfilter/xffontfactory.hxx"
60 :
61 25 : void LwpFontAttrEntry::Read(LwpObjectStream *pStrm)
62 : {
63 25 : m_nAttrBits = pStrm->QuickReaduInt16();
64 25 : m_nAttrOverrideBits = pStrm->QuickReaduInt16();
65 25 : m_nAttrApplyBits = pStrm->QuickReaduInt16();
66 25 : m_nAttrOverrideBits2 = pStrm->QuickReaduInt8();
67 25 : m_nAttrApplyBits2 = pStrm->QuickReaduInt8();
68 25 : m_nCase = pStrm->QuickReaduInt8();
69 25 : m_nUnder = pStrm->QuickReaduInt8();
70 25 : pStrm->SkipExtra();
71 25 : }
72 :
73 : #include "xfilter/xfdefs.hxx"
74 104 : void LwpFontAttrEntry::Override( XFFont*pFont )
75 : {
76 104 : if (IsBoldOverridden())
77 89 : pFont->SetBold(Is(BOLD));
78 :
79 104 : if (IsItalicOverridden())
80 73 : pFont->SetItalic(Is(ITALIC));
81 :
82 104 : if (IsStrikeThruOverridden())
83 : {
84 61 : if(Is(STRIKETHRU))
85 : {
86 1 : pFont->SetCrossout(enumXFCrossoutSignel);
87 : }
88 : else
89 : {
90 60 : pFont->SetCrossout(enumXFCrossoutNone);
91 : }
92 : }
93 :
94 104 : if (IsSuperOverridden())
95 : {
96 62 : if(Is(SUPERSCRIPT))
97 1 : pFont->SetPosition(sal_True);
98 : }
99 :
100 104 : if (IsSubOverridden())
101 : {
102 62 : if(Is(SUBSCRIPT))
103 1 : pFont->SetPosition(sal_False);
104 : }
105 :
106 104 : if (IsUnderlineOverridden())
107 : {
108 61 : switch(m_nUnder)
109 : {
110 : case UNDER_SINGLE:
111 1 : pFont->SetUnderline(enumXFUnderlineSingle);
112 1 : break;
113 : case UNDER_DOUBLE:
114 0 : pFont->SetUnderline(enumXFUnderlineDouble);
115 0 : break;
116 : case UNDER_WORD_SINGLE:
117 0 : pFont->SetUnderline(enumXFUnderlineSingle, true);
118 0 : break;
119 : case UNDER_WORD_DOUBLE:
120 0 : pFont->SetUnderline(enumXFUnderlineSingle, true);
121 0 : break;
122 : case UNDER_DONTCARE: //fall through
123 : case UNDER_OFF: //fall through
124 : case UNDER_STYLE: //fall through
125 : default:
126 60 : break;
127 : //do nothing;
128 : }
129 : }
130 :
131 104 : if (IsCaseOverridden())
132 : {
133 60 : switch(m_nCase)
134 : {
135 : case CASE_UPPER:
136 0 : pFont->SetTransform(enumXFTransformUpper);
137 0 : break;
138 : case CASE_LOWER:
139 0 : pFont->SetTransform(enumXFTransformLower);
140 0 : break;
141 : case CASE_NORMAL:
142 60 : pFont->SetTransform(enumXFTransformNone);
143 60 : break;
144 : case CASE_INITCAPS:
145 0 : pFont->SetTransform(enumXFTransformCapitalize);
146 0 : break;
147 : case CASE_STYLE: //fall through
148 : case CASE_DONTCARE: //fall through
149 : default:
150 : //do nothing
151 : ;
152 : }
153 : }
154 :
155 : //Please note that, put the SmallCaps setting after the case setting,
156 : //for SmallCaps has higher priority than LowerCase but low
157 104 : if (IsSmallCapsOverridden())
158 : {
159 60 : if( pFont->GetTransform()!=enumXFTransformUpper ) //SmallCaps should not override upper case
160 : {
161 60 : if(Is(SMALLCAPS))
162 0 : pFont->SetTransform(enumXFTransformSmallCaps);
163 : }
164 : }
165 :
166 : // TODO: tightness
167 : //if (IsTightnessOverridden())
168 : // pFont->SetTightness(cTightness);*/
169 104 : }
170 :
171 407 : sal_Bool LwpFontAttrEntry::Is(sal_uInt16 Attr)
172 : {
173 407 : return (0 != (m_nAttrBits & Attr));
174 : }
175 :
176 104 : sal_Bool LwpFontAttrEntry::IsBoldOverridden()
177 : {
178 104 : return (0 != (m_nAttrOverrideBits & BOLD));
179 : }
180 :
181 104 : sal_Bool LwpFontAttrEntry::IsItalicOverridden()
182 : {
183 104 : return (0 != (m_nAttrOverrideBits & ITALIC));
184 : }
185 104 : sal_Bool LwpFontAttrEntry::IsStrikeThruOverridden()
186 : {
187 104 : return (0 != (m_nAttrOverrideBits & STRIKETHRU));
188 : }
189 104 : sal_Bool LwpFontAttrEntry::IsSmallCapsOverridden()
190 : {
191 104 : return (0 != (m_nAttrOverrideBits & SMALLCAPS));
192 : }
193 104 : sal_Bool LwpFontAttrEntry::IsSuperOverridden()
194 : {
195 104 : return (0 != (m_nAttrOverrideBits & SUPERSCRIPT));
196 :
197 : }
198 104 : sal_Bool LwpFontAttrEntry::IsSubOverridden()
199 : {
200 104 : return (0 != (m_nAttrOverrideBits & SUBSCRIPT));
201 :
202 : }
203 :
204 104 : sal_Bool LwpFontAttrEntry::IsUnderlineOverridden()
205 : {
206 104 : return (0 != (m_nAttrOverrideBits2 & UNDER));
207 : }
208 104 : sal_Bool LwpFontAttrEntry::IsCaseOverridden()
209 : {
210 104 : return (0 != (m_nAttrOverrideBits2 & CASE));
211 : }
212 :
213 26 : void LwpFontTableEntry::Read(LwpObjectStream *pStrm)
214 : {
215 26 : m_WindowsFaceName.Read(pStrm);
216 :
217 : // use the m_WindowsFaceName to set the m_FaceName temporarily
218 26 : m_FaceName = m_WindowsFaceName;
219 :
220 : //Skip the panoseNumber
221 : //m_PanoseNumber.Read(pStrm);
222 26 : LwpPanoseNumber thePanoseToSkip;
223 26 : thePanoseToSkip.Read(pStrm);
224 :
225 26 : pStrm->SkipExtra();
226 :
227 26 : RegisterFontDecl();
228 26 : }
229 :
230 288 : OUString LwpFontTableEntry::GetFaceName()
231 : {
232 288 : return (m_WindowsFaceName.str());
233 : }
234 :
235 26 : void LwpFontTableEntry::RegisterFontDecl()
236 : {
237 52 : if(m_FaceName.str().isEmpty()) return;
238 22 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
239 22 : XFFontDecl aFontDecl1( m_FaceName.str(), m_FaceName.str(), false );
240 22 : pXFStyleManager->AddFontDecl(aFontDecl1);
241 : }
242 :
243 9 : LwpFontTable::LwpFontTable()
244 : : m_nCount(0)
245 9 : , m_pFontEntries(NULL)
246 9 : {}
247 :
248 9 : void LwpFontTable::Read(LwpObjectStream *pStrm)
249 : {
250 9 : m_pFontEntries = NULL;
251 9 : m_nCount = pStrm->QuickReaduInt16();
252 9 : if(m_nCount>0)
253 : {
254 4 : m_pFontEntries = new LwpFontTableEntry[m_nCount];
255 30 : for(sal_uInt16 i=0; i<m_nCount; i++)
256 : {
257 26 : m_pFontEntries[i].Read(pStrm);
258 : }
259 : }
260 9 : pStrm->SkipExtra();
261 9 : }
262 :
263 288 : OUString LwpFontTable::GetFaceName(sal_uInt16 index) //index: start from 1
264 : {
265 : assert(index <= m_nCount && index > 0);
266 288 : return (index <= m_nCount && index > 0) ? m_pFontEntries[index-1].GetFaceName() : OUString();
267 : }
268 :
269 8 : LwpFontTable::~LwpFontTable()
270 : {
271 8 : if(m_pFontEntries)
272 : {
273 4 : delete [] m_pFontEntries;
274 4 : m_pFontEntries = NULL;
275 : }
276 8 : }
277 :
278 81 : void LwpFontNameEntry::Read(LwpObjectStream *pStrm)
279 : {
280 : //Read CFontDescriptionOverrideBase
281 81 : m_nOverrideBits = pStrm->QuickReaduInt8();
282 81 : m_nApplyBits = pStrm->QuickReaduInt8();
283 81 : m_nPointSize = pStrm->QuickReaduInt32();
284 81 : m_nOverstrike = pStrm->QuickReaduInt16();
285 81 : m_nTightness = pStrm->QuickReaduInt16();
286 81 : m_Color.Read(pStrm);
287 81 : m_BackColor.Read(pStrm);
288 81 : pStrm->SkipExtra();
289 :
290 : //Read data of LwpFontNameEntry
291 81 : m_nFaceName = pStrm->QuickReaduInt16();
292 81 : m_nAltFaceName = pStrm->QuickReaduInt16();
293 81 : pStrm->SkipExtra();
294 81 : }
295 : #include "xfilter/xfcolor.hxx"
296 250 : void LwpFontNameEntry::Override(XFFont* pFont)
297 : {
298 250 : if (IsPointSizeOverridden())
299 236 : pFont->SetFontSize(static_cast<sal_uInt8>(m_nPointSize/65536L));
300 :
301 250 : if (IsColorOverridden() && m_Color.IsValidColor())
302 : {
303 95 : XFColor aColor(m_Color.To24Color());
304 95 : pFont->SetColor(aColor);
305 : }
306 :
307 :
308 250 : if (IsBackgroundColorOverridden() )
309 : {
310 60 : if (m_BackColor.IsValidColor())
311 : {
312 0 : XFColor aColor(m_BackColor.To24Color());
313 0 : pFont->SetBackColor( aColor );
314 : }
315 60 : else if (m_BackColor.IsTransparent())
316 : {
317 60 : pFont->SetBackColorTransparent();
318 : }
319 : }
320 :
321 : // TODO: tightness
322 : //if (IsTightnessOverridden())
323 : // pFont->SetTightness(cTightness);
324 250 : }
325 :
326 250 : sal_Bool LwpFontNameEntry::IsFaceNameOverridden()
327 : {
328 250 : return (0 != (m_nOverrideBits & FACENAME));
329 : }
330 :
331 250 : sal_Bool LwpFontNameEntry::IsAltFaceNameOverridden()
332 : {
333 250 : return (0 != (m_nOverrideBits & ALTFACENAME));
334 : }
335 :
336 250 : sal_Bool LwpFontNameEntry::IsPointSizeOverridden()
337 : {
338 250 : return (0 != (m_nOverrideBits & POINTSIZE));
339 : }
340 :
341 250 : sal_Bool LwpFontNameEntry::IsColorOverridden()
342 : {
343 250 : return (0 != (m_nOverrideBits & COLOR));
344 : }
345 :
346 250 : sal_Bool LwpFontNameEntry::IsBackgroundColorOverridden()
347 : {
348 250 : return (0 != (m_nOverrideBits & BKCOLOR));
349 : }
350 :
351 : //TODO
352 : //sal_Bool LwpFontNameEntry::IsTightnessOverridden()
353 : //{
354 : // return (0 != (m_nOverrideBits & TIGHTNESS));
355 : //}
356 :
357 : //sal_Bool LwpFontNameEntry::IsAnythingOverridden()
358 : //{
359 : // return (0 != (m_nOverrideBits & ALL_BITS));
360 : //}
361 :
362 :
363 9 : LwpFontNameManager::LwpFontNameManager()
364 9 : :m_pFontNames(NULL)
365 9 : {}
366 :
367 16 : LwpFontNameManager::~LwpFontNameManager()
368 : {
369 8 : if(m_pFontNames)
370 : {
371 4 : delete [] m_pFontNames;
372 4 : m_pFontNames = NULL;
373 : }
374 8 : }
375 :
376 9 : void LwpFontNameManager::Read(LwpObjectStream *pStrm)
377 : {
378 9 : m_nCount = pStrm->QuickReaduInt16();
379 9 : if(m_nCount>0)
380 : {
381 4 : m_pFontNames = new LwpFontNameEntry[m_nCount];
382 85 : for(sal_uInt16 i=0; i<m_nCount; i++)
383 : {
384 81 : m_pFontNames[i].Read(pStrm);
385 : }
386 : }
387 9 : m_FontTbl.Read(pStrm);
388 9 : pStrm->SkipExtra();
389 9 : }
390 :
391 258 : void LwpFontNameManager::Override(sal_uInt16 index, XFFont* pFont)
392 : //index: start from 1
393 : {
394 258 : if (index > m_nCount || index < 1)
395 266 : return ;
396 :
397 250 : m_pFontNames[index-1].Override(pFont);
398 250 : if(m_pFontNames[index-1].IsFaceNameOverridden())
399 228 : pFont->SetFontName(m_FontTbl.GetFaceName(m_pFontNames[index-1].GetFaceID()));
400 250 : if(m_pFontNames[index-1].IsAltFaceNameOverridden())
401 60 : pFont->SetFontNameAsia(m_FontTbl.GetFaceName(m_pFontNames[index-1].GetAltFaceID()));
402 : }
403 0 : OUString LwpFontNameManager::GetNameByIndex(sal_uInt16 index)
404 : {
405 0 : sal_uInt16 nameindex = m_pFontNames[index-1].GetFaceID();
406 0 : return (m_FontTbl.GetFaceName(nameindex));
407 : }
408 :
409 9 : void LwpFontAttrManager::Read(LwpObjectStream *pStrm)
410 : {
411 9 : m_nCount = pStrm->QuickReaduInt16();
412 9 : m_pFontAttrs = new LwpFontAttrEntry[m_nCount];
413 :
414 34 : for(sal_uInt16 i=0; i<m_nCount; i++)
415 : {
416 25 : m_pFontAttrs[i].Read(pStrm);
417 : }
418 9 : pStrm->SkipExtra();
419 9 : }
420 :
421 258 : void LwpFontAttrManager::Override(sal_uInt16 index, XFFont* pFont)
422 : //index: start from 1
423 : {
424 258 : if (index > m_nCount || index < 1)
425 412 : return ;
426 :
427 104 : m_pFontAttrs[index-1].Override(pFont);
428 : }
429 :
430 8 : LwpFontAttrManager::~LwpFontAttrManager()
431 : {
432 8 : if(m_pFontAttrs)
433 8 : delete []m_pFontAttrs;
434 8 : }
435 :
436 9 : void LwpFontManager::Read(LwpObjectStream *pStrm)
437 : {
438 9 : m_FNMgr.Read(pStrm);
439 9 : m_AttrMgr.Read(pStrm);
440 9 : pStrm->SkipExtra();
441 :
442 9 : }
443 :
444 : #include "xfilter/xftextstyle.hxx"
445 :
446 : /*
447 : VO_PARASTYLE call this method to add its style to XFStyleManager based on the fontID
448 : 1. Construct the text style based on the fontID
449 : 2. Add the style to XFStyleManager, and return the <office:styles> style name
450 : 3. Add it to LwpParaStyleMap.
451 : Note: A temporary method for only font support phase. The next AddStyle should be used later.
452 : // To be replaced by LwpStyleManager::AddStyle() and the following CreateFont()
453 : */
454 : /*void LwpFontManager::AddStyle(LwpObjectID styleObjID, sal_uInt32 fontID, OUString styleName)
455 : {
456 : XFTextStyle* pStyle = new XFTextStyle(); //to be deleted by XFStyleManager
457 : AddStyle(styleObjID, fontID, styleName, pStyle);
458 : }*/
459 :
460 : /*
461 : VO_PARASTYLE/VO_CHARACTERSTYLE call this method to add its style to XFStyleManager based on the fontID
462 : 1. Construct the text style based on the fontID
463 : 2. Add the style to XFStyleManager, and return the <office:styles> style name
464 : 3. Add it to LwpParaStyleMap.
465 : Prerequisite: pStyle has been created and the paragraph properties has been set to it.
466 : //To be replaced by LwpStyleManager::AddStyle() and the following CreateFont()
467 : */
468 : /*void LwpFontManager::AddStyle(LwpObjectID styleObjID, sal_uInt32 fontID, OUString styleName, XFTextStyle* pStyle)
469 : {
470 : assert(pStyle);
471 : XFFont* pFont = CreateFont(fontID);
472 : pStyle->SetFont(pFont);
473 : pStyle->SetStyleName(styleName);
474 : XFStyleManager::AddStyle(pStyle);
475 : m_StyleList.insert(LwpParaStyleMap::value_type(styleObjID, styleName));
476 : }*/
477 :
478 : /*
479 : Create XFFont based on the fotID
480 : */
481 258 : XFFont* LwpFontManager::CreateFont(sal_uInt32 fontID)
482 : {
483 258 : XFFont* pFont = new XFFont();
484 258 : m_FNMgr.Override(GetFontNameIndex(fontID), pFont);
485 258 : m_AttrMgr.Override(GetFontAttrIndex(fontID), pFont);
486 258 : return pFont;
487 : }
488 :
489 : /*
490 : Called XFFont based on the override result of two font ids.
491 : Refer to CFontManager::OverrideID
492 : */
493 : //OUString LwpFontManager::GetOverrideStyle(sal_uInt32 fontID, sal_uInt32 overID)
494 0 : XFFont* LwpFontManager::CreateOverrideFont(sal_uInt32 fontID, sal_uInt32 overID)
495 : {
496 0 : XFFont* pFont = new XFFont(); //To be deleted by XFFontFactory
497 0 : if(fontID)
498 : {
499 0 : Override(fontID, pFont);
500 : }
501 0 : if(overID)
502 : {
503 0 : Override(overID, pFont);
504 : }
505 0 : return pFont;
506 : }
507 :
508 0 : void LwpFontManager::Override(sal_uInt32 fontID, XFFont* pFont)
509 : {
510 0 : m_FNMgr.Override(GetFontNameIndex(fontID), pFont);
511 0 : m_AttrMgr.Override(GetFontAttrIndex(fontID), pFont);
512 0 : }
513 :
514 0 : OUString LwpFontManager::GetNameByID(sal_uInt32 fontID)
515 : {
516 0 : return ( m_FNMgr.GetNameByIndex(GetFontNameIndex(fontID)) );//use font id for bullet?
517 : }
518 :
519 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|