build fix
[LibreOffice.git] / lotuswordpro / source / filter / lwpfont.cxx
blob98772071362a7cdfaa6b0106faa59b36c088086f
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"
60 #include "xfilter/xftextstyle.hxx"
61 #include "xfilter/xfdefs.hxx"
62 #include "xfilter/xfcolor.hxx"
64 void LwpFontAttrEntry::Read(LwpObjectStream *pStrm)
66 m_nAttrBits = pStrm->QuickReaduInt16();
67 m_nAttrOverrideBits = pStrm->QuickReaduInt16();
68 m_nAttrApplyBits = pStrm->QuickReaduInt16();
69 m_nAttrOverrideBits2 = pStrm->QuickReaduInt8();
70 m_nAttrApplyBits2 = pStrm->QuickReaduInt8();
71 m_nCase = pStrm->QuickReaduInt8();
72 m_nUnder = pStrm->QuickReaduInt8();
73 pStrm->SkipExtra();
76 void LwpFontAttrEntry::Override( rtl::Reference<XFFont> const & pFont )
78 if (IsBoldOverridden())
79 pFont->SetBold(Is(BOLD));
81 if (IsItalicOverridden())
82 pFont->SetItalic(Is(ITALIC));
84 if (IsStrikeThruOverridden())
86 if(Is(STRIKETHRU))
88 pFont->SetCrossout(enumXFCrossoutSignel);
90 else
92 pFont->SetCrossout(enumXFCrossoutNone);
96 if (IsSuperOverridden())
98 if(Is(SUPERSCRIPT))
99 pFont->SetPosition();
102 if (IsSubOverridden())
104 if(Is(SUBSCRIPT))
105 pFont->SetPosition(false);
108 if (IsUnderlineOverridden())
110 switch(m_nUnder)
112 case UNDER_SINGLE:
113 pFont->SetUnderline(enumXFUnderlineSingle);
114 break;
115 case UNDER_DOUBLE:
116 pFont->SetUnderline(enumXFUnderlineDouble);
117 break;
118 case UNDER_WORD_SINGLE:
119 pFont->SetUnderline(enumXFUnderlineSingle, true);
120 break;
121 case UNDER_WORD_DOUBLE:
122 pFont->SetUnderline(enumXFUnderlineSingle, true);
123 break;
124 case UNDER_DONTCARE: //fall through
125 case UNDER_OFF: //fall through
126 case UNDER_STYLE: //fall through
127 default:
128 break;
129 //do nothing;
133 if (IsCaseOverridden())
135 switch(m_nCase)
137 case CASE_UPPER:
138 pFont->SetTransform(enumXFTransformUpper);
139 break;
140 case CASE_LOWER:
141 pFont->SetTransform(enumXFTransformLower);
142 break;
143 case CASE_NORMAL:
144 pFont->SetTransform(enumXFTransformNone);
145 break;
146 case CASE_INITCAPS:
147 pFont->SetTransform(enumXFTransformCapitalize);
148 break;
149 case CASE_STYLE: //fall through
150 case CASE_DONTCARE: //fall through
151 default:
152 //do nothing
157 //Please note that, put the SmallCaps setting after the case setting,
158 //for SmallCaps has higher priority than LowerCase but low
159 if (IsSmallCapsOverridden())
161 if( pFont->GetTransform()!=enumXFTransformUpper ) //SmallCaps should not override upper case
163 if(Is(SMALLCAPS))
164 pFont->SetTransform(enumXFTransformSmallCaps);
168 // TODO: tightness
169 //if (IsTightnessOverridden())
170 // pFont->SetTightness(cTightness);*/
173 bool LwpFontAttrEntry::Is(sal_uInt16 Attr)
175 return (0 != (m_nAttrBits & Attr));
178 bool LwpFontAttrEntry::IsBoldOverridden()
180 return (0 != (m_nAttrOverrideBits & BOLD));
183 bool LwpFontAttrEntry::IsItalicOverridden()
185 return (0 != (m_nAttrOverrideBits & ITALIC));
187 bool LwpFontAttrEntry::IsStrikeThruOverridden()
189 return (0 != (m_nAttrOverrideBits & STRIKETHRU));
191 bool LwpFontAttrEntry::IsSmallCapsOverridden()
193 return (0 != (m_nAttrOverrideBits & SMALLCAPS));
195 bool LwpFontAttrEntry::IsSuperOverridden()
197 return (0 != (m_nAttrOverrideBits & SUPERSCRIPT));
200 bool LwpFontAttrEntry::IsSubOverridden()
202 return (0 != (m_nAttrOverrideBits & SUBSCRIPT));
206 bool LwpFontAttrEntry::IsUnderlineOverridden()
208 return (0 != (m_nAttrOverrideBits2 & UNDER));
210 bool LwpFontAttrEntry::IsCaseOverridden()
212 return (0 != (m_nAttrOverrideBits2 & CASE));
215 void LwpFontTableEntry::Read(LwpObjectStream *pStrm)
217 m_WindowsFaceName.Read(pStrm);
219 // use the m_WindowsFaceName to set the m_FaceName temporarily
220 m_FaceName = m_WindowsFaceName;
222 //Skip the panoseNumber
223 //m_PanoseNumber.Read(pStrm);
224 LwpPanoseNumber thePanoseToSkip;
225 thePanoseToSkip.Read(pStrm);
227 pStrm->SkipExtra();
229 RegisterFontDecl();
232 OUString LwpFontTableEntry::GetFaceName()
234 return (m_WindowsFaceName.str());
237 void LwpFontTableEntry::RegisterFontDecl()
239 if(m_FaceName.str().isEmpty()) return;
240 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
241 XFFontDecl aFontDecl1( m_FaceName.str(), m_FaceName.str() );
242 pXFStyleManager->AddFontDecl(aFontDecl1);
245 LwpFontTable::LwpFontTable()
246 : m_nCount(0)
247 , m_pFontEntries(nullptr)
250 void LwpFontTable::Read(LwpObjectStream *pStrm)
252 m_pFontEntries = nullptr;
253 m_nCount = pStrm->QuickReaduInt16();
254 if(m_nCount>0)
256 m_pFontEntries = new LwpFontTableEntry[m_nCount];
257 for(sal_uInt16 i=0; i<m_nCount; i++)
259 m_pFontEntries[i].Read(pStrm);
262 pStrm->SkipExtra();
265 OUString LwpFontTable::GetFaceName(sal_uInt16 index) //index: start from 1
267 SAL_WARN_IF(index > m_nCount || index <= 0, "lwp", "bad font index");
268 return (index <= m_nCount && index > 0) ? m_pFontEntries[index-1].GetFaceName() : OUString();
271 LwpFontTable::~LwpFontTable()
273 if(m_pFontEntries)
275 delete [] m_pFontEntries;
276 m_pFontEntries = nullptr;
280 void LwpFontNameEntry::Read(LwpObjectStream *pStrm)
282 //Read CFontDescriptionOverrideBase
283 m_nOverrideBits = pStrm->QuickReaduInt8();
284 m_nApplyBits = pStrm->QuickReaduInt8();
285 m_nPointSize = pStrm->QuickReaduInt32();
286 m_nOverstrike = pStrm->QuickReaduInt16();
287 m_nTightness = pStrm->QuickReaduInt16();
288 m_Color.Read(pStrm);
289 m_BackColor.Read(pStrm);
290 pStrm->SkipExtra();
292 //Read data of LwpFontNameEntry
293 m_nFaceName = pStrm->QuickReaduInt16();
294 m_nAltFaceName = pStrm->QuickReaduInt16();
295 pStrm->SkipExtra();
298 void LwpFontNameEntry::Override(rtl::Reference<XFFont> const & pFont)
300 if (IsPointSizeOverridden())
301 pFont->SetFontSize(static_cast<sal_uInt8>(m_nPointSize/65536L));
303 if (IsColorOverridden() && m_Color.IsValidColor())
305 XFColor aColor(m_Color.To24Color());
306 pFont->SetColor(aColor);
309 if (IsBackgroundColorOverridden() )
311 if (m_BackColor.IsValidColor())
313 XFColor aColor(m_BackColor.To24Color());
314 pFont->SetBackColor( aColor );
316 else if (m_BackColor.IsTransparent())
318 pFont->SetBackColorTransparent();
322 // TODO: tightness
323 //if (IsTightnessOverridden())
324 // pFont->SetTightness(cTightness);
327 bool LwpFontNameEntry::IsFaceNameOverridden()
329 return (0 != (m_nOverrideBits & FACENAME));
332 bool LwpFontNameEntry::IsAltFaceNameOverridden()
334 return (0 != (m_nOverrideBits & ALTFACENAME));
337 bool LwpFontNameEntry::IsPointSizeOverridden()
339 return (0 != (m_nOverrideBits & POINTSIZE));
342 bool LwpFontNameEntry::IsColorOverridden()
344 return (0 != (m_nOverrideBits & COLOR));
347 bool LwpFontNameEntry::IsBackgroundColorOverridden()
349 return (0 != (m_nOverrideBits & BKCOLOR));
352 //TODO
353 //sal_Bool LwpFontNameEntry::IsTightnessOverridden()
355 // return (0 != (m_nOverrideBits & TIGHTNESS));
358 //sal_Bool LwpFontNameEntry::IsAnythingOverridden()
360 // return (0 != (m_nOverrideBits & ALL_BITS));
363 LwpFontNameManager::LwpFontNameManager()
364 : m_nCount(0)
365 , m_pFontNames(nullptr)
368 LwpFontNameManager::~LwpFontNameManager()
370 if(m_pFontNames)
372 delete [] m_pFontNames;
373 m_pFontNames = nullptr;
377 void LwpFontNameManager::Read(LwpObjectStream *pStrm)
379 m_nCount = pStrm->QuickReaduInt16();
380 if(m_nCount>0)
382 m_pFontNames = new LwpFontNameEntry[m_nCount];
383 for(sal_uInt16 i=0; i<m_nCount; i++)
385 m_pFontNames[i].Read(pStrm);
388 m_FontTbl.Read(pStrm);
389 pStrm->SkipExtra();
392 void LwpFontNameManager::Override(sal_uInt16 index, rtl::Reference<XFFont> const & pFont)
393 //index: start from 1
395 if (index > m_nCount || index < 1)
396 return ;
398 m_pFontNames[index-1].Override(pFont);
399 if(m_pFontNames[index-1].IsFaceNameOverridden())
400 pFont->SetFontName(m_FontTbl.GetFaceName(m_pFontNames[index-1].GetFaceID()));
401 if(m_pFontNames[index-1].IsAltFaceNameOverridden())
402 pFont->SetFontNameAsia(m_FontTbl.GetFaceName(m_pFontNames[index-1].GetAltFaceID()));
405 OUString LwpFontNameManager::GetNameByIndex(sal_uInt16 index)
406 //index: start from 1
408 if (index > m_nCount || index < 1)
409 return OUString();
411 sal_uInt16 nameindex = m_pFontNames[index-1].GetFaceID();
412 return (m_FontTbl.GetFaceName(nameindex));
415 void LwpFontAttrManager::Read(LwpObjectStream *pStrm)
417 m_nCount = pStrm->QuickReaduInt16();
418 m_pFontAttrs = new LwpFontAttrEntry[m_nCount];
420 for(sal_uInt16 i=0; i<m_nCount; i++)
422 m_pFontAttrs[i].Read(pStrm);
424 pStrm->SkipExtra();
427 void LwpFontAttrManager::Override(sal_uInt16 index, rtl::Reference<XFFont> const & pFont)
428 //index: start from 1
430 if (index > m_nCount || index < 1)
431 return ;
433 m_pFontAttrs[index-1].Override(pFont);
436 LwpFontAttrManager::~LwpFontAttrManager()
438 if(m_pFontAttrs)
439 delete []m_pFontAttrs;
442 void LwpFontManager::Read(LwpObjectStream *pStrm)
444 m_FNMgr.Read(pStrm);
445 m_AttrMgr.Read(pStrm);
446 pStrm->SkipExtra();
451 VO_PARASTYLE call this method to add its style to XFStyleManager based on the fontID
452 1. Construct the text style based on the fontID
453 2. Add the style to XFStyleManager, and return the <office:styles> style name
454 3. Add it to LwpParaStyleMap.
455 Note: A temporary method for only font support phase. The next AddStyle should be used later.
456 // To be replaced by LwpStyleManager::AddStyle() and the following CreateFont()
458 /*void LwpFontManager::AddStyle(LwpObjectID styleObjID, sal_uInt32 fontID, OUString styleName)
460 XFTextStyle* pStyle = new XFTextStyle(); //to be deleted by XFStyleManager
461 AddStyle(styleObjID, fontID, styleName, pStyle);
465 VO_PARASTYLE/VO_CHARACTERSTYLE call this method to add its style to XFStyleManager based on the fontID
466 1. Construct the text style based on the fontID
467 2. Add the style to XFStyleManager, and return the <office:styles> style name
468 3. Add it to LwpParaStyleMap.
469 Prerequisite: pStyle has been created and the paragraph properties has been set to it.
470 //To be replaced by LwpStyleManager::AddStyle() and the following CreateFont()
472 /*void LwpFontManager::AddStyle(LwpObjectID styleObjID, sal_uInt32 fontID, OUString styleName, XFTextStyle* pStyle)
474 assert(pStyle);
475 XFFont* pFont = CreateFont(fontID);
476 pStyle->SetFont(pFont);
477 pStyle->SetStyleName(styleName);
478 XFStyleManager::AddStyle(pStyle);
479 m_StyleList.insert(LwpParaStyleMap::value_type(styleObjID, styleName));
483 Create XFFont based on the fotID
485 rtl::Reference<XFFont> LwpFontManager::CreateFont(sal_uInt32 fontID)
487 rtl::Reference<XFFont> pFont = new XFFont();
488 m_FNMgr.Override(GetFontNameIndex(fontID), pFont);
489 m_AttrMgr.Override(GetFontAttrIndex(fontID), pFont);
490 return pFont;
494 Called XFFont based on the override result of two font ids.
495 Refer to CFontManager::OverrideID
497 //OUString LwpFontManager::GetOverrideStyle(sal_uInt32 fontID, sal_uInt32 overID)
498 rtl::Reference<XFFont> LwpFontManager::CreateOverrideFont(sal_uInt32 fontID, sal_uInt32 overID)
500 rtl::Reference<XFFont> pFont = new XFFont(); //To be deleted by XFFontFactory
501 if(fontID)
503 Override(fontID, pFont);
505 if(overID)
507 Override(overID, pFont);
509 return pFont;
512 void LwpFontManager::Override(sal_uInt32 fontID, rtl::Reference<XFFont> const & pFont)
514 m_FNMgr.Override(GetFontNameIndex(fontID), pFont);
515 m_AttrMgr.Override(GetFontAttrIndex(fontID), pFont);
518 OUString LwpFontManager::GetNameByID(sal_uInt32 fontID)
520 return ( m_FNMgr.GetNameByIndex(GetFontNameIndex(fontID)) );//use font id for bullet?
523 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */