fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / lotuswordpro / source / filter / lwpfont.cxx
blob3ee7e1b5ecb1ba11a99571750d02cbe06feb6324
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
10 * Sun Microsystems Inc., October, 2000
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
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.
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.
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
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.
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.
46 * The Initial Developer of the Original Code is: IBM Corporation
48 * Copyright: 2008 by IBM Corporation
50 * All Rights Reserved.
52 * Contributor(s): _______________________________________
55 ************************************************************************/
56 #include "lwpglobalmgr.hxx"
57 #include "lwpfont.hxx"
58 #include "xfilter/xfstylemanager.hxx"
59 #include "xfilter/xffontfactory.hxx"
61 void LwpFontAttrEntry::Read(LwpObjectStream *pStrm)
63 m_nAttrBits = pStrm->QuickReaduInt16();
64 m_nAttrOverrideBits = pStrm->QuickReaduInt16();
65 m_nAttrApplyBits = pStrm->QuickReaduInt16();
66 m_nAttrOverrideBits2 = pStrm->QuickReaduInt8();
67 m_nAttrApplyBits2 = pStrm->QuickReaduInt8();
68 m_nCase = pStrm->QuickReaduInt8();
69 m_nUnder = pStrm->QuickReaduInt8();
70 pStrm->SkipExtra();
73 #include "xfilter/xfdefs.hxx"
74 void LwpFontAttrEntry::Override( rtl::Reference<XFFont> const & pFont )
76 if (IsBoldOverridden())
77 pFont->SetBold(Is(BOLD));
79 if (IsItalicOverridden())
80 pFont->SetItalic(Is(ITALIC));
82 if (IsStrikeThruOverridden())
84 if(Is(STRIKETHRU))
86 pFont->SetCrossout(enumXFCrossoutSignel);
88 else
90 pFont->SetCrossout(enumXFCrossoutNone);
94 if (IsSuperOverridden())
96 if(Is(SUPERSCRIPT))
97 pFont->SetPosition(true);
100 if (IsSubOverridden())
102 if(Is(SUBSCRIPT))
103 pFont->SetPosition(false);
106 if (IsUnderlineOverridden())
108 switch(m_nUnder)
110 case UNDER_SINGLE:
111 pFont->SetUnderline(enumXFUnderlineSingle);
112 break;
113 case UNDER_DOUBLE:
114 pFont->SetUnderline(enumXFUnderlineDouble);
115 break;
116 case UNDER_WORD_SINGLE:
117 pFont->SetUnderline(enumXFUnderlineSingle, true);
118 break;
119 case UNDER_WORD_DOUBLE:
120 pFont->SetUnderline(enumXFUnderlineSingle, true);
121 break;
122 case UNDER_DONTCARE: //fall through
123 case UNDER_OFF: //fall through
124 case UNDER_STYLE: //fall through
125 default:
126 break;
127 //do nothing;
131 if (IsCaseOverridden())
133 switch(m_nCase)
135 case CASE_UPPER:
136 pFont->SetTransform(enumXFTransformUpper);
137 break;
138 case CASE_LOWER:
139 pFont->SetTransform(enumXFTransformLower);
140 break;
141 case CASE_NORMAL:
142 pFont->SetTransform(enumXFTransformNone);
143 break;
144 case CASE_INITCAPS:
145 pFont->SetTransform(enumXFTransformCapitalize);
146 break;
147 case CASE_STYLE: //fall through
148 case CASE_DONTCARE: //fall through
149 default:
150 //do nothing
155 //Please note that, put the SmallCaps setting after the case setting,
156 //for SmallCaps has higher priority than LowerCase but low
157 if (IsSmallCapsOverridden())
159 if( pFont->GetTransform()!=enumXFTransformUpper ) //SmallCaps should not override upper case
161 if(Is(SMALLCAPS))
162 pFont->SetTransform(enumXFTransformSmallCaps);
166 // TODO: tightness
167 //if (IsTightnessOverridden())
168 // pFont->SetTightness(cTightness);*/
171 bool LwpFontAttrEntry::Is(sal_uInt16 Attr)
173 return (0 != (m_nAttrBits & Attr));
176 bool LwpFontAttrEntry::IsBoldOverridden()
178 return (0 != (m_nAttrOverrideBits & BOLD));
181 bool LwpFontAttrEntry::IsItalicOverridden()
183 return (0 != (m_nAttrOverrideBits & ITALIC));
185 bool LwpFontAttrEntry::IsStrikeThruOverridden()
187 return (0 != (m_nAttrOverrideBits & STRIKETHRU));
189 bool LwpFontAttrEntry::IsSmallCapsOverridden()
191 return (0 != (m_nAttrOverrideBits & SMALLCAPS));
193 bool LwpFontAttrEntry::IsSuperOverridden()
195 return (0 != (m_nAttrOverrideBits & SUPERSCRIPT));
198 bool LwpFontAttrEntry::IsSubOverridden()
200 return (0 != (m_nAttrOverrideBits & SUBSCRIPT));
204 bool LwpFontAttrEntry::IsUnderlineOverridden()
206 return (0 != (m_nAttrOverrideBits2 & UNDER));
208 bool LwpFontAttrEntry::IsCaseOverridden()
210 return (0 != (m_nAttrOverrideBits2 & CASE));
213 void LwpFontTableEntry::Read(LwpObjectStream *pStrm)
215 m_WindowsFaceName.Read(pStrm);
217 // use the m_WindowsFaceName to set the m_FaceName temporarily
218 m_FaceName = m_WindowsFaceName;
220 //Skip the panoseNumber
221 //m_PanoseNumber.Read(pStrm);
222 LwpPanoseNumber thePanoseToSkip;
223 thePanoseToSkip.Read(pStrm);
225 pStrm->SkipExtra();
227 RegisterFontDecl();
230 OUString LwpFontTableEntry::GetFaceName()
232 return (m_WindowsFaceName.str());
235 void LwpFontTableEntry::RegisterFontDecl()
237 if(m_FaceName.str().isEmpty()) return;
238 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
239 XFFontDecl aFontDecl1( m_FaceName.str(), m_FaceName.str(), false );
240 pXFStyleManager->AddFontDecl(aFontDecl1);
243 LwpFontTable::LwpFontTable()
244 : m_nCount(0)
245 , m_pFontEntries(NULL)
248 void LwpFontTable::Read(LwpObjectStream *pStrm)
250 m_pFontEntries = NULL;
251 m_nCount = pStrm->QuickReaduInt16();
252 if(m_nCount>0)
254 m_pFontEntries = new LwpFontTableEntry[m_nCount];
255 for(sal_uInt16 i=0; i<m_nCount; i++)
257 m_pFontEntries[i].Read(pStrm);
260 pStrm->SkipExtra();
263 OUString LwpFontTable::GetFaceName(sal_uInt16 index) //index: start from 1
265 assert(index <= m_nCount && index > 0);
266 return (index <= m_nCount && index > 0) ? m_pFontEntries[index-1].GetFaceName() : OUString();
269 LwpFontTable::~LwpFontTable()
271 if(m_pFontEntries)
273 delete [] m_pFontEntries;
274 m_pFontEntries = NULL;
278 void LwpFontNameEntry::Read(LwpObjectStream *pStrm)
280 //Read CFontDescriptionOverrideBase
281 m_nOverrideBits = pStrm->QuickReaduInt8();
282 m_nApplyBits = pStrm->QuickReaduInt8();
283 m_nPointSize = pStrm->QuickReaduInt32();
284 m_nOverstrike = pStrm->QuickReaduInt16();
285 m_nTightness = pStrm->QuickReaduInt16();
286 m_Color.Read(pStrm);
287 m_BackColor.Read(pStrm);
288 pStrm->SkipExtra();
290 //Read data of LwpFontNameEntry
291 m_nFaceName = pStrm->QuickReaduInt16();
292 m_nAltFaceName = pStrm->QuickReaduInt16();
293 pStrm->SkipExtra();
295 #include "xfilter/xfcolor.hxx"
296 void LwpFontNameEntry::Override(rtl::Reference<XFFont> const & pFont)
298 if (IsPointSizeOverridden())
299 pFont->SetFontSize(static_cast<sal_uInt8>(m_nPointSize/65536L));
301 if (IsColorOverridden() && m_Color.IsValidColor())
303 XFColor aColor(m_Color.To24Color());
304 pFont->SetColor(aColor);
307 if (IsBackgroundColorOverridden() )
309 if (m_BackColor.IsValidColor())
311 XFColor aColor(m_BackColor.To24Color());
312 pFont->SetBackColor( aColor );
314 else if (m_BackColor.IsTransparent())
316 pFont->SetBackColorTransparent();
320 // TODO: tightness
321 //if (IsTightnessOverridden())
322 // pFont->SetTightness(cTightness);
325 bool LwpFontNameEntry::IsFaceNameOverridden()
327 return (0 != (m_nOverrideBits & FACENAME));
330 bool LwpFontNameEntry::IsAltFaceNameOverridden()
332 return (0 != (m_nOverrideBits & ALTFACENAME));
335 bool LwpFontNameEntry::IsPointSizeOverridden()
337 return (0 != (m_nOverrideBits & POINTSIZE));
340 bool LwpFontNameEntry::IsColorOverridden()
342 return (0 != (m_nOverrideBits & COLOR));
345 bool LwpFontNameEntry::IsBackgroundColorOverridden()
347 return (0 != (m_nOverrideBits & BKCOLOR));
350 //TODO
351 //sal_Bool LwpFontNameEntry::IsTightnessOverridden()
353 // return (0 != (m_nOverrideBits & TIGHTNESS));
356 //sal_Bool LwpFontNameEntry::IsAnythingOverridden()
358 // return (0 != (m_nOverrideBits & ALL_BITS));
361 LwpFontNameManager::LwpFontNameManager()
362 : m_nCount(0)
363 , m_pFontNames(NULL)
366 LwpFontNameManager::~LwpFontNameManager()
368 if(m_pFontNames)
370 delete [] m_pFontNames;
371 m_pFontNames = NULL;
375 void LwpFontNameManager::Read(LwpObjectStream *pStrm)
377 m_nCount = pStrm->QuickReaduInt16();
378 if(m_nCount>0)
380 m_pFontNames = new LwpFontNameEntry[m_nCount];
381 for(sal_uInt16 i=0; i<m_nCount; i++)
383 m_pFontNames[i].Read(pStrm);
386 m_FontTbl.Read(pStrm);
387 pStrm->SkipExtra();
390 void LwpFontNameManager::Override(sal_uInt16 index, rtl::Reference<XFFont> const & pFont)
391 //index: start from 1
393 if (index > m_nCount || index < 1)
394 return ;
396 m_pFontNames[index-1].Override(pFont);
397 if(m_pFontNames[index-1].IsFaceNameOverridden())
398 pFont->SetFontName(m_FontTbl.GetFaceName(m_pFontNames[index-1].GetFaceID()));
399 if(m_pFontNames[index-1].IsAltFaceNameOverridden())
400 pFont->SetFontNameAsia(m_FontTbl.GetFaceName(m_pFontNames[index-1].GetAltFaceID()));
402 OUString LwpFontNameManager::GetNameByIndex(sal_uInt16 index)
404 sal_uInt16 nameindex = m_pFontNames[index-1].GetFaceID();
405 return (m_FontTbl.GetFaceName(nameindex));
408 void LwpFontAttrManager::Read(LwpObjectStream *pStrm)
410 m_nCount = pStrm->QuickReaduInt16();
411 m_pFontAttrs = new LwpFontAttrEntry[m_nCount];
413 for(sal_uInt16 i=0; i<m_nCount; i++)
415 m_pFontAttrs[i].Read(pStrm);
417 pStrm->SkipExtra();
420 void LwpFontAttrManager::Override(sal_uInt16 index, rtl::Reference<XFFont> const & pFont)
421 //index: start from 1
423 if (index > m_nCount || index < 1)
424 return ;
426 m_pFontAttrs[index-1].Override(pFont);
429 LwpFontAttrManager::~LwpFontAttrManager()
431 if(m_pFontAttrs)
432 delete []m_pFontAttrs;
435 void LwpFontManager::Read(LwpObjectStream *pStrm)
437 m_FNMgr.Read(pStrm);
438 m_AttrMgr.Read(pStrm);
439 pStrm->SkipExtra();
443 #include "xfilter/xftextstyle.hxx"
446 VO_PARASTYLE call this method to add its style to XFStyleManager based on the fontID
447 1. Construct the text style based on the fontID
448 2. Add the style to XFStyleManager, and return the <office:styles> style name
449 3. Add it to LwpParaStyleMap.
450 Note: A temporary method for only font support phase. The next AddStyle should be used later.
451 // To be replaced by LwpStyleManager::AddStyle() and the following CreateFont()
453 /*void LwpFontManager::AddStyle(LwpObjectID styleObjID, sal_uInt32 fontID, OUString styleName)
455 XFTextStyle* pStyle = new XFTextStyle(); //to be deleted by XFStyleManager
456 AddStyle(styleObjID, fontID, styleName, pStyle);
460 VO_PARASTYLE/VO_CHARACTERSTYLE call this method to add its style to XFStyleManager based on the fontID
461 1. Construct the text style based on the fontID
462 2. Add the style to XFStyleManager, and return the <office:styles> style name
463 3. Add it to LwpParaStyleMap.
464 Prerequisite: pStyle has been created and the paragraph properties has been set to it.
465 //To be replaced by LwpStyleManager::AddStyle() and the following CreateFont()
467 /*void LwpFontManager::AddStyle(LwpObjectID styleObjID, sal_uInt32 fontID, OUString styleName, XFTextStyle* pStyle)
469 assert(pStyle);
470 XFFont* pFont = CreateFont(fontID);
471 pStyle->SetFont(pFont);
472 pStyle->SetStyleName(styleName);
473 XFStyleManager::AddStyle(pStyle);
474 m_StyleList.insert(LwpParaStyleMap::value_type(styleObjID, styleName));
478 Create XFFont based on the fotID
480 rtl::Reference<XFFont> LwpFontManager::CreateFont(sal_uInt32 fontID)
482 rtl::Reference<XFFont> pFont = new XFFont();
483 m_FNMgr.Override(GetFontNameIndex(fontID), pFont);
484 m_AttrMgr.Override(GetFontAttrIndex(fontID), pFont);
485 return pFont;
489 Called XFFont based on the override result of two font ids.
490 Refer to CFontManager::OverrideID
492 //OUString LwpFontManager::GetOverrideStyle(sal_uInt32 fontID, sal_uInt32 overID)
493 rtl::Reference<XFFont> LwpFontManager::CreateOverrideFont(sal_uInt32 fontID, sal_uInt32 overID)
495 rtl::Reference<XFFont> pFont = new XFFont(); //To be deleted by XFFontFactory
496 if(fontID)
498 Override(fontID, pFont);
500 if(overID)
502 Override(overID, pFont);
504 return pFont;
507 void LwpFontManager::Override(sal_uInt32 fontID, rtl::Reference<XFFont> const & pFont)
509 m_FNMgr.Override(GetFontNameIndex(fontID), pFont);
510 m_AttrMgr.Override(GetFontAttrIndex(fontID), pFont);
513 OUString LwpFontManager::GetNameByID(sal_uInt32 fontID)
515 return ( m_FNMgr.GetNameByIndex(GetFontNameIndex(fontID)) );//use font id for bullet?
518 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */