fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / lotuswordpro / source / filter / lwpfont.cxx
blobf0809f0a8b6de470b0f4b86dd0ff6760c46c013d
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( XFFont*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(sal_True);
100 if (IsSubOverridden())
102 if(Is(SUBSCRIPT))
103 pFont->SetPosition(sal_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 sal_Bool LwpFontAttrEntry::Is(sal_uInt16 Attr)
173 return (0 != (m_nAttrBits & Attr));
176 sal_Bool LwpFontAttrEntry::IsBoldOverridden()
178 return (0 != (m_nAttrOverrideBits & BOLD));
181 sal_Bool LwpFontAttrEntry::IsItalicOverridden()
183 return (0 != (m_nAttrOverrideBits & ITALIC));
185 sal_Bool LwpFontAttrEntry::IsStrikeThruOverridden()
187 return (0 != (m_nAttrOverrideBits & STRIKETHRU));
189 sal_Bool LwpFontAttrEntry::IsSmallCapsOverridden()
191 return (0 != (m_nAttrOverrideBits & SMALLCAPS));
193 sal_Bool LwpFontAttrEntry::IsSuperOverridden()
195 return (0 != (m_nAttrOverrideBits & SUPERSCRIPT));
198 sal_Bool LwpFontAttrEntry::IsSubOverridden()
200 return (0 != (m_nAttrOverrideBits & SUBSCRIPT));
204 sal_Bool LwpFontAttrEntry::IsUnderlineOverridden()
206 return (0 != (m_nAttrOverrideBits2 & UNDER));
208 sal_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(XFFont* 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);
308 if (IsBackgroundColorOverridden() )
310 if (m_BackColor.IsValidColor())
312 XFColor aColor(m_BackColor.To24Color());
313 pFont->SetBackColor( aColor );
315 else if (m_BackColor.IsTransparent())
317 pFont->SetBackColorTransparent();
321 // TODO: tightness
322 //if (IsTightnessOverridden())
323 // pFont->SetTightness(cTightness);
326 sal_Bool LwpFontNameEntry::IsFaceNameOverridden()
328 return (0 != (m_nOverrideBits & FACENAME));
331 sal_Bool LwpFontNameEntry::IsAltFaceNameOverridden()
333 return (0 != (m_nOverrideBits & ALTFACENAME));
336 sal_Bool LwpFontNameEntry::IsPointSizeOverridden()
338 return (0 != (m_nOverrideBits & POINTSIZE));
341 sal_Bool LwpFontNameEntry::IsColorOverridden()
343 return (0 != (m_nOverrideBits & COLOR));
346 sal_Bool LwpFontNameEntry::IsBackgroundColorOverridden()
348 return (0 != (m_nOverrideBits & BKCOLOR));
351 //TODO
352 //sal_Bool LwpFontNameEntry::IsTightnessOverridden()
354 // return (0 != (m_nOverrideBits & TIGHTNESS));
357 //sal_Bool LwpFontNameEntry::IsAnythingOverridden()
359 // return (0 != (m_nOverrideBits & ALL_BITS));
363 LwpFontNameManager::LwpFontNameManager()
364 :m_pFontNames(NULL)
367 LwpFontNameManager::~LwpFontNameManager()
369 if(m_pFontNames)
371 delete [] m_pFontNames;
372 m_pFontNames = NULL;
376 void LwpFontNameManager::Read(LwpObjectStream *pStrm)
378 m_nCount = pStrm->QuickReaduInt16();
379 if(m_nCount>0)
381 m_pFontNames = new LwpFontNameEntry[m_nCount];
382 for(sal_uInt16 i=0; i<m_nCount; i++)
384 m_pFontNames[i].Read(pStrm);
387 m_FontTbl.Read(pStrm);
388 pStrm->SkipExtra();
391 void LwpFontNameManager::Override(sal_uInt16 index, XFFont* pFont)
392 //index: start from 1
394 if (index > m_nCount || index < 1)
395 return ;
397 m_pFontNames[index-1].Override(pFont);
398 if(m_pFontNames[index-1].IsFaceNameOverridden())
399 pFont->SetFontName(m_FontTbl.GetFaceName(m_pFontNames[index-1].GetFaceID()));
400 if(m_pFontNames[index-1].IsAltFaceNameOverridden())
401 pFont->SetFontNameAsia(m_FontTbl.GetFaceName(m_pFontNames[index-1].GetAltFaceID()));
403 OUString LwpFontNameManager::GetNameByIndex(sal_uInt16 index)
405 sal_uInt16 nameindex = m_pFontNames[index-1].GetFaceID();
406 return (m_FontTbl.GetFaceName(nameindex));
409 void LwpFontAttrManager::Read(LwpObjectStream *pStrm)
411 m_nCount = pStrm->QuickReaduInt16();
412 m_pFontAttrs = new LwpFontAttrEntry[m_nCount];
414 for(sal_uInt16 i=0; i<m_nCount; i++)
416 m_pFontAttrs[i].Read(pStrm);
418 pStrm->SkipExtra();
421 void LwpFontAttrManager::Override(sal_uInt16 index, XFFont* pFont)
422 //index: start from 1
424 if (index > m_nCount || index < 1)
425 return ;
427 m_pFontAttrs[index-1].Override(pFont);
430 LwpFontAttrManager::~LwpFontAttrManager()
432 if(m_pFontAttrs)
433 delete []m_pFontAttrs;
436 void LwpFontManager::Read(LwpObjectStream *pStrm)
438 m_FNMgr.Read(pStrm);
439 m_AttrMgr.Read(pStrm);
440 pStrm->SkipExtra();
444 #include "xfilter/xftextstyle.hxx"
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()
454 /*void LwpFontManager::AddStyle(LwpObjectID styleObjID, sal_uInt32 fontID, OUString styleName)
456 XFTextStyle* pStyle = new XFTextStyle(); //to be deleted by XFStyleManager
457 AddStyle(styleObjID, fontID, styleName, pStyle);
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()
468 /*void LwpFontManager::AddStyle(LwpObjectID styleObjID, sal_uInt32 fontID, OUString styleName, XFTextStyle* pStyle)
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));
479 Create XFFont based on the fotID
481 XFFont* LwpFontManager::CreateFont(sal_uInt32 fontID)
483 XFFont* pFont = new XFFont();
484 m_FNMgr.Override(GetFontNameIndex(fontID), pFont);
485 m_AttrMgr.Override(GetFontAttrIndex(fontID), pFont);
486 return pFont;
490 Called XFFont based on the override result of two font ids.
491 Refer to CFontManager::OverrideID
493 //OUString LwpFontManager::GetOverrideStyle(sal_uInt32 fontID, sal_uInt32 overID)
494 XFFont* LwpFontManager::CreateOverrideFont(sal_uInt32 fontID, sal_uInt32 overID)
496 XFFont* pFont = new XFFont(); //To be deleted by XFFontFactory
497 if(fontID)
499 Override(fontID, pFont);
501 if(overID)
503 Override(overID, pFont);
505 return pFont;
508 void LwpFontManager::Override(sal_uInt32 fontID, XFFont* pFont)
510 m_FNMgr.Override(GetFontNameIndex(fontID), pFont);
511 m_AttrMgr.Override(GetFontAttrIndex(fontID), pFont);
514 OUString LwpFontManager::GetNameByID(sal_uInt32 fontID)
516 return ( m_FNMgr.GetNameByIndex(GetFontNameIndex(fontID)) );//use font id for bullet?
519 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */