tdf#131098 docx export: write fill property of graphic
[LibreOffice.git] / lotuswordpro / source / filter / lwpfont.cxx
blob92a4d76dc28f066163738e2ef26d53d9de9c602a
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 <lwpbasetype.hxx>
59 #include <xfilter/xfstylemanager.hxx>
60 #include <xfilter/xfdefs.hxx>
61 #include <xfilter/xfcolor.hxx>
62 #include <sal/log.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() const
180 return (0 != (m_nAttrOverrideBits & BOLD));
183 bool LwpFontAttrEntry::IsItalicOverridden() const
185 return (0 != (m_nAttrOverrideBits & ITALIC));
187 bool LwpFontAttrEntry::IsStrikeThruOverridden() const
189 return (0 != (m_nAttrOverrideBits & STRIKETHRU));
191 bool LwpFontAttrEntry::IsSmallCapsOverridden() const
193 return (0 != (m_nAttrOverrideBits & SMALLCAPS));
195 bool LwpFontAttrEntry::IsSuperOverridden() const
197 return (0 != (m_nAttrOverrideBits & SUPERSCRIPT));
200 bool LwpFontAttrEntry::IsSubOverridden() const
202 return (0 != (m_nAttrOverrideBits & SUBSCRIPT));
206 bool LwpFontAttrEntry::IsUnderlineOverridden() const
208 return (0 != (m_nAttrOverrideBits2 & UNDER));
210 bool LwpFontAttrEntry::IsCaseOverridden() const
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 const & LwpFontTableEntry::GetFaceName() const
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)
249 void LwpFontTable::Read(LwpObjectStream *pStrm)
251 m_pFontEntries = nullptr;
252 m_nCount = pStrm->QuickReaduInt16();
253 if(m_nCount>0)
255 m_pFontEntries.reset( new LwpFontTableEntry[m_nCount] );
256 for(sal_uInt16 i=0; i<m_nCount; i++)
258 m_pFontEntries[i].Read(pStrm);
261 pStrm->SkipExtra();
264 OUString LwpFontTable::GetFaceName(sal_uInt16 index) //index: start from 1
266 SAL_WARN_IF(index > m_nCount || index <= 0, "lwp", "bad font index");
267 return (index <= m_nCount && index > 0) ? m_pFontEntries[index-1].GetFaceName() : OUString();
270 LwpFontTable::~LwpFontTable()
274 void LwpFontNameEntry::Read(LwpObjectStream *pStrm)
276 //Read CFontDescriptionOverrideBase
277 m_nOverrideBits = pStrm->QuickReaduInt8();
278 m_nApplyBits = pStrm->QuickReaduInt8();
279 m_nPointSize = pStrm->QuickReaduInt32();
280 m_nOverstrike = pStrm->QuickReaduInt16();
281 m_nTightness = pStrm->QuickReaduInt16();
282 m_Color.Read(pStrm);
283 m_BackColor.Read(pStrm);
284 pStrm->SkipExtra();
286 //Read data of LwpFontNameEntry
287 m_nFaceName = pStrm->QuickReaduInt16();
288 m_nAltFaceName = pStrm->QuickReaduInt16();
289 pStrm->SkipExtra();
292 void LwpFontNameEntry::Override(rtl::Reference<XFFont> const & pFont)
294 if (IsPointSizeOverridden())
295 pFont->SetFontSize(static_cast<sal_uInt8>(m_nPointSize/65536L));
297 if (IsColorOverridden() && m_Color.IsValidColor())
299 XFColor aColor(m_Color.To24Color());
300 pFont->SetColor(aColor);
303 if (IsBackgroundColorOverridden() )
305 if (m_BackColor.IsValidColor())
307 XFColor aColor(m_BackColor.To24Color());
308 pFont->SetBackColor( aColor );
310 else if (m_BackColor.IsTransparent())
312 pFont->SetBackColorTransparent();
316 // TODO: tightness
317 //if (IsTightnessOverridden())
318 // pFont->SetTightness(cTightness);
321 bool LwpFontNameEntry::IsFaceNameOverridden() const
323 return (0 != (m_nOverrideBits & FACENAME));
326 bool LwpFontNameEntry::IsAltFaceNameOverridden() const
328 return (0 != (m_nOverrideBits & ALTFACENAME));
331 bool LwpFontNameEntry::IsPointSizeOverridden() const
333 return (0 != (m_nOverrideBits & POINTSIZE));
336 bool LwpFontNameEntry::IsColorOverridden() const
338 return (0 != (m_nOverrideBits & COLOR));
341 bool LwpFontNameEntry::IsBackgroundColorOverridden() const
343 return (0 != (m_nOverrideBits & BKCOLOR));
346 //TODO
347 //sal_Bool LwpFontNameEntry::IsTightnessOverridden()
349 // return (0 != (m_nOverrideBits & TIGHTNESS));
352 //sal_Bool LwpFontNameEntry::IsAnythingOverridden()
354 // return (0 != (m_nOverrideBits & ALL_BITS));
357 LwpFontNameManager::LwpFontNameManager()
358 : m_nCount(0)
361 LwpFontNameManager::~LwpFontNameManager()
365 void LwpFontNameManager::Read(LwpObjectStream *pStrm)
367 m_nCount = pStrm->QuickReaduInt16();
368 if(m_nCount>0)
370 m_pFontNames.reset( new LwpFontNameEntry[m_nCount] );
371 for(sal_uInt16 i=0; i<m_nCount; i++)
373 m_pFontNames[i].Read(pStrm);
376 m_FontTbl.Read(pStrm);
377 pStrm->SkipExtra();
380 void LwpFontNameManager::Override(sal_uInt16 index, rtl::Reference<XFFont> const & pFont)
381 //index: start from 1
383 if (index > m_nCount || index < 1)
384 return ;
386 m_pFontNames[index-1].Override(pFont);
387 if(m_pFontNames[index-1].IsFaceNameOverridden())
388 pFont->SetFontName(m_FontTbl.GetFaceName(m_pFontNames[index-1].GetFaceID()));
389 if(m_pFontNames[index-1].IsAltFaceNameOverridden())
390 pFont->SetFontNameAsia(m_FontTbl.GetFaceName(m_pFontNames[index-1].GetAltFaceID()));
393 OUString LwpFontNameManager::GetNameByIndex(sal_uInt16 index)
394 //index: start from 1
396 if (index > m_nCount || index < 1)
397 return OUString();
399 sal_uInt16 nameindex = m_pFontNames[index-1].GetFaceID();
400 return m_FontTbl.GetFaceName(nameindex);
403 void LwpFontAttrManager::Read(LwpObjectStream *pStrm)
405 m_nCount = pStrm->QuickReaduInt16();
406 m_pFontAttrs.reset( new LwpFontAttrEntry[m_nCount] );
408 for(sal_uInt16 i=0; i<m_nCount; i++)
410 m_pFontAttrs[i].Read(pStrm);
412 pStrm->SkipExtra();
415 void LwpFontAttrManager::Override(sal_uInt16 index, rtl::Reference<XFFont> const & pFont)
416 //index: start from 1
418 if (index > m_nCount || index < 1)
419 return ;
421 m_pFontAttrs[index-1].Override(pFont);
424 LwpFontAttrManager::~LwpFontAttrManager()
428 void LwpFontManager::Read(LwpObjectStream *pStrm)
430 m_FNMgr.Read(pStrm);
431 m_AttrMgr.Read(pStrm);
432 pStrm->SkipExtra();
437 VO_PARASTYLE call this method to add its style to XFStyleManager based on the fontID
438 1. Construct the text style based on the fontID
439 2. Add the style to XFStyleManager, and return the <office:styles> style name
440 3. Add it to LwpParaStyleMap.
441 Note: A temporary method for only font support phase. The next AddStyle should be used later.
442 // To be replaced by LwpStyleManager::AddStyle() and the following CreateFont()
444 /*void LwpFontManager::AddStyle(LwpObjectID styleObjID, sal_uInt32 fontID, OUString styleName)
446 XFTextStyle* pStyle = new XFTextStyle(); //to be deleted by XFStyleManager
447 AddStyle(styleObjID, fontID, styleName, pStyle);
451 VO_PARASTYLE/VO_CHARACTERSTYLE 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 Prerequisite: pStyle has been created and the paragraph properties has been set to it.
456 //To be replaced by LwpStyleManager::AddStyle() and the following CreateFont()
458 /*void LwpFontManager::AddStyle(LwpObjectID styleObjID, sal_uInt32 fontID, OUString styleName, XFTextStyle* pStyle)
460 assert(pStyle);
461 XFFont* pFont = CreateFont(fontID);
462 pStyle->SetFont(pFont);
463 pStyle->SetStyleName(styleName);
464 XFStyleManager::AddStyle(pStyle);
465 m_StyleList.emplace( styleObjID, styleName));
469 Create XFFont based on the fotID
471 rtl::Reference<XFFont> LwpFontManager::CreateFont(sal_uInt32 fontID)
473 rtl::Reference<XFFont> pFont = new XFFont();
474 m_FNMgr.Override(GetFontNameIndex(fontID), pFont);
475 m_AttrMgr.Override(GetFontAttrIndex(fontID), pFont);
476 return pFont;
480 Called XFFont based on the override result of two font ids.
481 Refer to CFontManager::OverrideID
483 //OUString LwpFontManager::GetOverrideStyle(sal_uInt32 fontID, sal_uInt32 overID)
484 rtl::Reference<XFFont> LwpFontManager::CreateOverrideFont(sal_uInt32 fontID, sal_uInt32 overID)
486 rtl::Reference<XFFont> pFont = new XFFont(); //To be deleted by XFFontFactory
487 if(fontID)
489 Override(fontID, pFont);
491 if(overID)
493 Override(overID, pFont);
495 return pFont;
498 void LwpFontManager::Override(sal_uInt32 fontID, rtl::Reference<XFFont> const & pFont)
500 m_FNMgr.Override(GetFontNameIndex(fontID), pFont);
501 m_AttrMgr.Override(GetFontAttrIndex(fontID), pFont);
504 OUString LwpFontManager::GetNameByID(sal_uInt32 fontID)
506 return m_FNMgr.GetNameByIndex(GetFontNameIndex(fontID));//use font id for bullet?
509 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */