LibreOffice Module lotuswordpro (master) 1
lwpfont.cxx
Go to the documentation of this file.
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 <lwpbasetype.hxx>
60#include <xfilter/xfdefs.hxx>
61#include <xfilter/xfcolor.hxx>
62#include <sal/log.hxx>
63
65{
71 m_nCase = pStrm->QuickReaduInt8();
72 m_nUnder = pStrm->QuickReaduInt8();
73 pStrm->SkipExtra();
74}
75
77{
78 if (IsBoldOverridden())
79 pFont->SetBold(Is(BOLD));
80
82 pFont->SetItalic(Is(ITALIC));
83
85 {
86 if(Is(STRIKETHRU))
87 {
88 pFont->SetCrossout(enumXFCrossoutSignel);
89 }
90 else
91 {
92 pFont->SetCrossout(enumXFCrossoutNone);
93 }
94 }
95
97 {
98 if(Is(SUPERSCRIPT))
99 pFont->SetPosition();
100 }
101
102 if (IsSubOverridden())
103 {
104 if(Is(SUBSCRIPT))
105 pFont->SetPosition(false);
106 }
107
109 {
110 switch(m_nUnder)
111 {
112 case UNDER_SINGLE:
113 pFont->SetUnderline(enumXFUnderlineSingle);
114 break;
115 case UNDER_DOUBLE:
116 pFont->SetUnderline(enumXFUnderlineDouble);
117 break;
119 pFont->SetUnderline(enumXFUnderlineSingle, true);
120 break;
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;
130 }
131 }
132
133 if (IsCaseOverridden())
134 {
135 switch(m_nCase)
136 {
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
153 ;
154 }
155 }
156
157 //Please note that, put the SmallCaps setting after the case setting,
158 //for SmallCaps has higher priority than LowerCase but low
160 {
161 if( pFont->GetTransform()!=enumXFTransformUpper ) //SmallCaps should not override upper case
162 {
163 if(Is(SMALLCAPS))
164 pFont->SetTransform(enumXFTransformSmallCaps);
165 }
166 }
167
168 // TODO: tightness
169 //if (IsTightnessOverridden())
170 // pFont->SetTightness(cTightness);*/
171}
172
174{
175 return (0 != (m_nAttrBits & Attr));
176}
177
179{
180 return (0 != (m_nAttrOverrideBits & BOLD));
181}
182
184{
185 return (0 != (m_nAttrOverrideBits & ITALIC));
186}
188{
189 return (0 != (m_nAttrOverrideBits & STRIKETHRU));
190}
192{
193 return (0 != (m_nAttrOverrideBits & SMALLCAPS));
194}
196{
197 return (0 != (m_nAttrOverrideBits & SUPERSCRIPT));
198
199}
201{
202 return (0 != (m_nAttrOverrideBits & SUBSCRIPT));
203
204}
205
207{
208 return (0 != (m_nAttrOverrideBits2 & UNDER));
209}
211{
212 return (0 != (m_nAttrOverrideBits2 & CASE));
213}
214
216{
217 m_WindowsFaceName.Read(pStrm);
218
219 // use the m_WindowsFaceName to set the m_FaceName temporarily
221
222 //Skip the panoseNumber
223 //m_PanoseNumber.Read(pStrm);
224 LwpPanoseNumber thePanoseToSkip;
225 thePanoseToSkip.Read(pStrm);
226
227 pStrm->SkipExtra();
228
230}
231
232OUString const & LwpFontTableEntry::GetFaceName() const
233{
234 return m_WindowsFaceName.str();
235}
236
238{
239 if(m_FaceName.str().isEmpty()) return;
241 XFFontDecl aFontDecl1( m_FaceName.str(), m_FaceName.str() );
242 pXFStyleManager->AddFontDecl(aFontDecl1);
243}
244
246 : m_nCount(0)
247{}
248
250{
251 m_pFontEntries = nullptr;
252 m_nCount = pStrm->QuickReaduInt16();
253 if(m_nCount>0)
254 {
256 for(sal_uInt16 i=0; i<m_nCount; i++)
257 {
258 m_pFontEntries[i].Read(pStrm);
259 }
260 }
261 pStrm->SkipExtra();
262}
263
264OUString LwpFontTable::GetFaceName(sal_uInt16 index) //index: start from 1
265{
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();
268}
269
271{
272}
273
275{
276 //Read CFontDescriptionOverrideBase
278 m_nApplyBits = pStrm->QuickReaduInt8();
279 m_nPointSize = pStrm->QuickReaduInt32();
281 m_nTightness = pStrm->QuickReaduInt16();
282 m_Color.Read(pStrm);
283 m_BackColor.Read(pStrm);
284 pStrm->SkipExtra();
285
286 //Read data of LwpFontNameEntry
287 m_nFaceName = pStrm->QuickReaduInt16();
289 pStrm->SkipExtra();
290}
291
293{
295 pFont->SetFontSize(static_cast<sal_uInt8>(m_nPointSize/65536L));
296
298 {
299 XFColor aColor(m_Color.To24Color());
300 pFont->SetColor(aColor);
301 }
302
304 {
306 {
307 XFColor aColor(m_BackColor.To24Color());
308 pFont->SetBackColor( aColor );
309 }
310 else if (m_BackColor.IsTransparent())
311 {
312 pFont->SetBackColorTransparent();
313 }
314 }
315
316 // TODO: tightness
317 //if (IsTightnessOverridden())
318 // pFont->SetTightness(cTightness);
319}
320
322{
323 return (0 != (m_nOverrideBits & FACENAME));
324}
325
327{
328 return (0 != (m_nOverrideBits & ALTFACENAME));
329}
330
332{
333 return (0 != (m_nOverrideBits & POINTSIZE));
334}
335
337{
338 return (0 != (m_nOverrideBits & COLOR));
339}
340
342{
343 return (0 != (m_nOverrideBits & BKCOLOR));
344}
345
346//TODO
347//sal_Bool LwpFontNameEntry::IsTightnessOverridden()
348//{
349// return (0 != (m_nOverrideBits & TIGHTNESS));
350//}
351
352//sal_Bool LwpFontNameEntry::IsAnythingOverridden()
353//{
354// return (0 != (m_nOverrideBits & ALL_BITS));
355//}
356
358 : m_nCount(0)
359{}
360
362{
363}
364
366{
367 m_nCount = pStrm->QuickReaduInt16();
368 if(m_nCount>0)
369 {
371 for(sal_uInt16 i=0; i<m_nCount; i++)
372 {
373 m_pFontNames[i].Read(pStrm);
374 }
375 }
376 m_FontTbl.Read(pStrm);
377 pStrm->SkipExtra();
378}
379
380void LwpFontNameManager::Override(sal_uInt16 index, rtl::Reference<XFFont> const & pFont)
381 //index: start from 1
382{
383 if (index > m_nCount || index < 1)
384 return ;
385
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()));
391}
392
393OUString LwpFontNameManager::GetNameByIndex(sal_uInt16 index)
394 //index: start from 1
395{
396 if (index > m_nCount || index < 1)
397 return OUString();
398
399 sal_uInt16 nameindex = m_pFontNames[index-1].GetFaceID();
400 return m_FontTbl.GetFaceName(nameindex);
401}
402
404{
405 m_nCount = pStrm->QuickReaduInt16();
407
408 for(sal_uInt16 i=0; i<m_nCount; i++)
409 {
410 m_pFontAttrs[i].Read(pStrm);
411 }
412 pStrm->SkipExtra();
413}
414
415void LwpFontAttrManager::Override(sal_uInt16 index, rtl::Reference<XFFont> const & pFont)
416 //index: start from 1
417{
418 if (index > m_nCount || index < 1)
419 return ;
420
421 m_pFontAttrs[index-1].Override(pFont);
422}
423
425{
426}
427
429{
430 m_FNMgr.Read(pStrm);
431 m_AttrMgr.Read(pStrm);
432 pStrm->SkipExtra();
433
434}
435
436/*
437VO_PARASTYLE call this method to add its style to XFStyleManager based on the fontID
4381. Construct the text style based on the fontID
4392. Add the style to XFStyleManager, and return the <office:styles> style name
4403. Add it to LwpParaStyleMap.
441Note: 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()
443*/
444/*void LwpFontManager::AddStyle(LwpObjectID styleObjID, sal_uInt32 fontID, OUString styleName)
445{
446 XFTextStyle* pStyle = new XFTextStyle(); //to be deleted by XFStyleManager
447 AddStyle(styleObjID, fontID, styleName, pStyle);
448}*/
449
450/*
451VO_PARASTYLE/VO_CHARACTERSTYLE call this method to add its style to XFStyleManager based on the fontID
4521. Construct the text style based on the fontID
4532. Add the style to XFStyleManager, and return the <office:styles> style name
4543. Add it to LwpParaStyleMap.
455Prerequisite: pStyle has been created and the paragraph properties has been set to it.
456//To be replaced by LwpStyleManager::AddStyle() and the following CreateFont()
457*/
458/*void LwpFontManager::AddStyle(LwpObjectID styleObjID, sal_uInt32 fontID, OUString styleName, XFTextStyle* pStyle)
459{
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));
466}*/
467
468/*
469Create XFFont based on the fotID
470*/
472{
473 rtl::Reference<XFFont> pFont = new XFFont();
476 return pFont;
477}
478
479/*
480Called XFFont based on the override result of two font ids.
481Refer to CFontManager::OverrideID
482*/
483//OUString LwpFontManager::GetOverrideStyle(sal_uInt32 fontID, sal_uInt32 overID)
485{
486 rtl::Reference<XFFont> pFont = new XFFont(); //To be deleted by XFFontFactory
487 if(fontID)
488 {
489 Override(fontID, pFont);
490 }
491 if(overID)
492 {
493 Override(overID, pFont);
494 }
495 return pFont;
496}
497
499{
502}
503
505{
506 return m_FNMgr.GetNameByIndex(GetFontNameIndex(fontID));//use font id for bullet?
507}
508
509/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void Read(LwpObjectStream *pStrm)
@descr read atomholder from object stream the default encoding used in Word Pro is 1252
const OUString & str() const
bool IsValidColor() const
Definition: lwpcolor.hxx:114
void Read(LwpObjectStream *pStrm)
@descr read color and then resolve the RGB values
Definition: lwpcolor.cxx:74
bool IsTransparent() const
Definition: lwpcolor.hxx:118
sal_uInt32 To24Color()
@descr return the BGR format
Definition: lwpcolor.cxx:66
sal_uInt8 m_nAttrOverrideBits2
Definition: lwpfont.hxx:192
void Override(rtl::Reference< XFFont > const &pFont)
Definition: lwpfont.cxx:76
bool IsSubOverridden() const
Definition: lwpfont.cxx:200
sal_uInt16 m_nAttrBits
Definition: lwpfont.hxx:189
bool IsBoldOverridden() const
Definition: lwpfont.cxx:178
bool IsSmallCapsOverridden() const
Definition: lwpfont.cxx:191
sal_uInt16 m_nAttrOverrideBits
Definition: lwpfont.hxx:190
bool IsCaseOverridden() const
Definition: lwpfont.cxx:210
void Read(LwpObjectStream *pStrm)
Definition: lwpfont.cxx:64
bool IsStrikeThruOverridden() const
Definition: lwpfont.cxx:187
bool IsSuperOverridden() const
Definition: lwpfont.cxx:195
sal_uInt8 m_nAttrApplyBits2
Definition: lwpfont.hxx:193
bool IsItalicOverridden() const
Definition: lwpfont.cxx:183
sal_uInt16 m_nAttrApplyBits
Definition: lwpfont.hxx:191
sal_uInt8 m_nCase
Definition: lwpfont.hxx:194
sal_uInt8 m_nUnder
Definition: lwpfont.hxx:195
bool IsUnderlineOverridden() const
Definition: lwpfont.cxx:206
bool Is(sal_uInt16 Attr)
Definition: lwpfont.cxx:173
sal_uInt16 m_nCount
Definition: lwpfont.hxx:253
std::unique_ptr< LwpFontAttrEntry[]> m_pFontAttrs
Definition: lwpfont.hxx:254
void Read(LwpObjectStream *pStrm)
Definition: lwpfont.cxx:403
void Override(sal_uInt16 index, rtl::Reference< XFFont > const &pFont)
Definition: lwpfont.cxx:415
rtl::Reference< XFFont > CreateOverrideFont(sal_uInt32 fontID, sal_uInt32 overID)
Definition: lwpfont.cxx:484
void Read(LwpObjectStream *pStrm)
Definition: lwpfont.cxx:428
LwpFontAttrManager m_AttrMgr
Definition: lwpfont.hxx:263
static sal_uInt16 GetFontAttrIndex(sal_uInt32 fontID)
Definition: lwpfont.hxx:282
LwpFontNameManager m_FNMgr
Definition: lwpfont.hxx:262
rtl::Reference< XFFont > CreateFont(sal_uInt32 fontID)
Definition: lwpfont.cxx:471
void Override(sal_uInt32 fontID, rtl::Reference< XFFont > const &pFont)
Definition: lwpfont.cxx:498
static sal_uInt16 GetFontNameIndex(sal_uInt32 fontID)
Definition: lwpfont.hxx:277
OUString GetNameByID(sal_uInt32 fontID)
Definition: lwpfont.cxx:504
sal_uInt16 m_nAltFaceName
Definition: lwpfont.hxx:134
void Override(rtl::Reference< XFFont > const &pFont)
Definition: lwpfont.cxx:292
sal_uInt8 m_nApplyBits
Definition: lwpfont.hxx:126
void Read(LwpObjectStream *pStrm)
Definition: lwpfont.cxx:274
bool IsColorOverridden() const
Definition: lwpfont.cxx:336
LwpColor m_Color
Definition: lwpfont.hxx:130
sal_uInt8 m_nOverrideBits
Definition: lwpfont.hxx:125
LwpColor m_BackColor
Definition: lwpfont.hxx:131
bool IsPointSizeOverridden() const
Definition: lwpfont.cxx:331
sal_uInt32 m_nPointSize
Definition: lwpfont.hxx:127
sal_uInt16 m_nTightness
Definition: lwpfont.hxx:129
sal_uInt16 m_nFaceName
Definition: lwpfont.hxx:133
sal_uInt16 m_nOverstrike
Definition: lwpfont.hxx:128
bool IsAltFaceNameOverridden() const
Definition: lwpfont.cxx:326
bool IsFaceNameOverridden() const
Definition: lwpfont.cxx:321
bool IsBackgroundColorOverridden() const
Definition: lwpfont.cxx:341
LwpFontTable m_FontTbl
Definition: lwpfont.hxx:166
sal_uInt16 m_nCount
Definition: lwpfont.hxx:164
void Read(LwpObjectStream *pStrm)
Definition: lwpfont.cxx:365
void Override(sal_uInt16 index, rtl::Reference< XFFont > const &pFont)
Definition: lwpfont.cxx:380
OUString GetNameByIndex(sal_uInt16 index)
Definition: lwpfont.cxx:393
std::unique_ptr< LwpFontNameEntry[]> m_pFontNames
Definition: lwpfont.hxx:165
OUString const & GetFaceName() const
Definition: lwpfont.cxx:232
void Read(LwpObjectStream *pStrm)
Definition: lwpfont.cxx:215
void RegisterFontDecl()
Definition: lwpfont.cxx:237
LwpAtomHolder m_WindowsFaceName
Definition: lwpfont.hxx:83
LwpAtomHolder m_FaceName
Definition: lwpfont.hxx:84
sal_uInt16 m_nCount
Definition: lwpfont.hxx:100
std::unique_ptr< LwpFontTableEntry[]> m_pFontEntries
Definition: lwpfont.hxx:101
OUString GetFaceName(sal_uInt16 index)
Definition: lwpfont.cxx:264
void Read(LwpObjectStream *pStrm)
Definition: lwpfont.cxx:249
XFStyleManager * GetXFStyleManager()
static LwpGlobalMgr * GetInstance(LwpSvStream *pSvStream=nullptr)
stream class for LwpObject body data provide stream like interface to read object data
Definition: lwpobjstrm.hxx:77
sal_uInt16 QuickReaduInt16(bool *pFailure=nullptr)
@descr Quick read sal_uInt32
Definition: lwpobjstrm.cxx:200
void SkipExtra()
@descr skip extra bytes
Definition: lwpobjstrm.cxx:258
sal_uInt8 QuickReaduInt8(bool *pFailure=nullptr)
@descr Quick read sal_uInt8
Definition: lwpobjstrm.cxx:230
sal_uInt32 QuickReaduInt32(bool *pFailure=nullptr)
@descr Quick read sal_uInt32
Definition: lwpobjstrm.cxx:189
used for lwpfont for font description
Definition: lwpbasetype.hxx:71
void Read(LwpObjectStream *pStrm)
@descr read PonoseNumber from object stream
Definition: lwpbasetype.cxx:60
Color object.
Definition: xfcolor.hxx:70
Font declaration in OOo xml file.
Definition: xffontdecl.hxx:72
@descr The font struct of openoffice xml filter.
Definition: xffont.hxx:120
Style manager for the filter.
void AddFontDecl(XFFontDecl const &aFontDecl)
sal_Int16 m_nCount
#define SAL_WARN_IF(condition, area, stream)
int i
index
int fontID
unsigned char sal_uInt8
@ enumXFCrossoutSignel
Definition: xfdefs.hxx:146
@ enumXFCrossoutNone
Definition: xfdefs.hxx:145
@ enumXFUnderlineSingle
Definition: xfdefs.hxx:117
@ enumXFUnderlineDouble
Definition: xfdefs.hxx:118
@ enumXFTransformSmallCaps
Definition: xfdefs.hxx:159
@ enumXFTransformNone
Definition: xfdefs.hxx:155
@ enumXFTransformLower
Definition: xfdefs.hxx:157
@ enumXFTransformUpper
Definition: xfdefs.hxx:156
@ enumXFTransformCapitalize
Definition: xfdefs.hxx:158