1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
55 #include "lwpglobalmgr.hxx"
56 #include "lwpfont.hxx"
57 #include "xfilter/xfstylemanager.hxx"
58 #include "xfilter/xffontfactory.hxx"
60 void LwpFontAttrEntry::Read(LwpObjectStream
*pStrm
)
62 pStrm
->QuickRead(&m_nAttrBits
, sizeof(m_nAttrBits
));
63 pStrm
->QuickRead(&m_nAttrOverrideBits
, sizeof(m_nAttrOverrideBits
));
64 pStrm
->QuickRead(&m_nAttrApplyBits
, sizeof(m_nAttrApplyBits
));
65 pStrm
->QuickRead(&m_nAttrOverrideBits2
, sizeof(m_nAttrOverrideBits2
));
66 pStrm
->QuickRead(&m_nAttrApplyBits2
, sizeof(m_nAttrApplyBits2
));
67 pStrm
->QuickRead(&m_nCase
, sizeof(m_nCase
));
68 pStrm
->QuickRead(&m_nUnder
, sizeof(m_nUnder
));
72 #include "xfilter/xfdefs.hxx"
73 void LwpFontAttrEntry::Override( XFFont
*pFont
)
75 if (IsBoldOverridden())
76 pFont
->SetBold(Is(BOLD
));
78 if (IsItalicOverridden())
79 pFont
->SetItalic(Is(ITALIC
));
81 if (IsStrikeThruOverridden())
85 pFont
->SetCrossout(enumXFCrossoutSignel
);
89 pFont
->SetCrossout(enumXFCrossoutNone
);
93 if (IsSuperOverridden())
96 pFont
->SetPosition(TRUE
);
99 if (IsSubOverridden())
102 pFont
->SetPosition(FALSE
);
105 if (IsUnderlineOverridden())
110 pFont
->SetUnderline(enumXFUnderlineSingle
);
113 pFont
->SetUnderline(enumXFUnderlineDouble
);
115 case UNDER_WORD_SINGLE
:
116 pFont
->SetUnderline(enumXFUnderlineSingle
, true);
118 case UNDER_WORD_DOUBLE
:
119 pFont
->SetUnderline(enumXFUnderlineSingle
, true);
121 case UNDER_DONTCARE
: //fall through
122 case UNDER_OFF
: //fall through
123 case UNDER_STYLE
: //fall through
130 if (IsCaseOverridden())
135 pFont
->SetTransform(enumXFTransformUpper
);
138 pFont
->SetTransform(enumXFTransformLower
);
141 pFont
->SetTransform(enumXFTransformNone
);
144 pFont
->SetTransform(enumXFTransformCapitalize
);
146 case CASE_STYLE
: //fall through
147 case CASE_DONTCARE
: //fall through
154 //Please note that, put the SmallCaps setting after the case setting,
155 //for SmallCaps has higher priority than LowerCase but low
156 if (IsSmallCapsOverridden())
158 if( pFont
->GetTransform()!=enumXFTransformUpper
) //SmallCaps should not override upper case
161 pFont
->SetTransform(enumXFTransformSmallCaps
);
166 //if (IsTightnessOverridden())
167 // pFont->SetTightness(cTightness);*/
170 BOOL
LwpFontAttrEntry::Is(sal_uInt16 Attr
)
172 return (0 != (m_nAttrBits
& Attr
));
175 BOOL
LwpFontAttrEntry::IsBoldOverridden()
177 return (0 != (m_nAttrOverrideBits
& BOLD
));
180 BOOL
LwpFontAttrEntry::IsItalicOverridden()
182 return (0 != (m_nAttrOverrideBits
& ITALIC
));
184 BOOL
LwpFontAttrEntry::IsStrikeThruOverridden()
186 return (0 != (m_nAttrOverrideBits
& STRIKETHRU
));
188 BOOL
LwpFontAttrEntry::IsSmallCapsOverridden()
190 return (0 != (m_nAttrOverrideBits
& SMALLCAPS
));
192 BOOL
LwpFontAttrEntry::IsSuperOverridden()
194 return (0 != (m_nAttrOverrideBits
& SUPERSCRIPT
));
197 BOOL
LwpFontAttrEntry::IsSubOverridden()
199 return (0 != (m_nAttrOverrideBits
& SUBSCRIPT
));
203 BOOL
LwpFontAttrEntry::IsSuperSubOverridden()
205 return (0 != (m_nAttrOverrideBits
206 & (SUPERSCRIPT
| SUBSCRIPT
)));
209 BOOL
LwpFontAttrEntry::IsUnderlineOverridden()
211 return (0 != (m_nAttrOverrideBits2
& UNDER
));
213 BOOL
LwpFontAttrEntry::IsCaseOverridden()
215 return (0 != (m_nAttrOverrideBits2
& CASE
));
218 void LwpFontTableEntry::Read(LwpObjectStream
*pStrm
)
220 m_WindowsFaceName
.Read(pStrm
);
222 // use the m_WindowsFaceName to set the m_FaceName temporarily
223 m_FaceName
= m_WindowsFaceName
;
225 //Skip the panoseNumber
226 //m_PanoseNumber.Read(pStrm);
227 LwpPanoseNumber thePanoseToSkip
;
228 thePanoseToSkip
.Read(pStrm
);
235 OUString
LwpFontTableEntry::GetFaceName()
237 return (m_WindowsFaceName
.str());
240 void LwpFontTableEntry::RegisterFontDecl()
242 if(m_FaceName
.str().getLength()==0) return;
243 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
244 XFFontDecl
aFontDecl1( m_FaceName
.str(), m_FaceName
.str(), false );
245 pXFStyleManager
->AddFontDecl(aFontDecl1
);
248 LwpFontTable::LwpFontTable()
249 : m_pFontEntries(NULL
)
252 void LwpFontTable::Read(LwpObjectStream
*pStrm
)
254 m_pFontEntries
= NULL
;
255 pStrm
->QuickRead(&m_nCount
, sizeof(m_nCount
));
258 m_pFontEntries
= new LwpFontTableEntry
[m_nCount
];
259 for(sal_uInt16 i
=0; i
<m_nCount
; i
++)
261 m_pFontEntries
[i
].Read(pStrm
);
267 OUString
LwpFontTable::GetFaceName(sal_uInt16 index
) //index: start from 1
270 if (index
< 1)//add by , for fix crash,2005/12/20
271 return OUString::createFromAscii("");//add end
272 return m_pFontEntries
[index
-1].GetFaceName();
275 LwpFontTable::~LwpFontTable()
279 delete [] m_pFontEntries
;
280 m_pFontEntries
= NULL
;
284 void LwpFontNameEntry::Read(LwpObjectStream
*pStrm
)
286 //Read CFontDescriptionOverrideBase
287 pStrm
->QuickRead(&m_nOverrideBits
, sizeof(m_nOverrideBits
));
288 pStrm
->QuickRead(&m_nApplyBits
, sizeof(m_nApplyBits
));
289 pStrm
->QuickRead(&m_nPointSize
, sizeof(m_nPointSize
));
290 pStrm
->QuickRead(&m_nOverstrike
, sizeof(m_nOverstrike
));
291 pStrm
->QuickRead(&m_nTightness
, sizeof(m_nTightness
));
293 m_BackColor
.Read(pStrm
);
296 //Read data of LwpFontNameEntry
297 pStrm
->QuickRead(&m_nFaceName
, sizeof(m_nFaceName
));
298 pStrm
->QuickRead(&m_nAltFaceName
, sizeof(m_nAltFaceName
));
301 #include "xfilter/xfcolor.hxx"
302 void LwpFontNameEntry::Override(XFFont
* pFont
)
304 if (IsPointSizeOverridden())
305 pFont
->SetFontSize(static_cast<sal_uInt8
>(m_nPointSize
/65536L));
307 if (IsColorOverridden() && m_Color
.IsValidColor())
309 XFColor
aColor(m_Color
.To24Color());
310 pFont
->SetColor(aColor
);
314 if (IsBackgroundColorOverridden() )
316 if (m_BackColor
.IsValidColor())
318 XFColor
aColor(m_BackColor
.To24Color());
319 pFont
->SetBackColor( aColor
);
321 else if (m_BackColor
.IsTransparent())
323 pFont
->SetBackColorTransparent();
328 //if (IsTightnessOverridden())
329 // pFont->SetTightness(cTightness);
332 BOOL
LwpFontNameEntry::IsFaceNameOverridden()
334 return (0 != (m_nOverrideBits
& FACENAME
));
337 BOOL
LwpFontNameEntry::IsAltFaceNameOverridden()
339 return (0 != (m_nOverrideBits
& ALTFACENAME
));
342 BOOL
LwpFontNameEntry::IsPointSizeOverridden()
344 return (0 != (m_nOverrideBits
& POINTSIZE
));
347 BOOL
LwpFontNameEntry::IsColorOverridden()
349 return (0 != (m_nOverrideBits
& COLOR
));
352 BOOL
LwpFontNameEntry::IsBackgroundColorOverridden()
354 return (0 != (m_nOverrideBits
& BKCOLOR
));
357 BOOL
LwpFontNameEntry::IsTightnessOverridden()
359 return (0 != (m_nOverrideBits
& TIGHTNESS
));
362 BOOL
LwpFontNameEntry::IsAnythingOverridden()
364 return (0 != (m_nOverrideBits
& ALL_BITS
));
368 LwpFontNameManager::LwpFontNameManager()
372 LwpFontNameManager::~LwpFontNameManager()
376 delete [] m_pFontNames
;
381 void LwpFontNameManager::Read(LwpObjectStream
*pStrm
)
383 pStrm
->QuickRead(&m_nCount
, sizeof(m_nCount
));
386 m_pFontNames
= new LwpFontNameEntry
[m_nCount
];
387 for(sal_uInt16 i
=0; i
<m_nCount
; i
++)
389 m_pFontNames
[i
].Read(pStrm
);
392 m_FontTbl
.Read(pStrm
);
396 void LwpFontNameManager::Override(sal_uInt16 index
, XFFont
* pFont
)
397 //index: start from 1
400 m_pFontNames
[index
-1].Override(pFont
);
401 if(m_pFontNames
[index
-1].IsFaceNameOverridden())
402 pFont
->SetFontName(m_FontTbl
.GetFaceName(m_pFontNames
[index
-1].GetFaceID()));
403 if(m_pFontNames
[index
-1].IsAltFaceNameOverridden())
404 pFont
->SetFontNameAsia(m_FontTbl
.GetFaceName(m_pFontNames
[index
-1].GetAltFaceID()));
406 OUString
LwpFontNameManager::GetNameByIndex(sal_uInt16 index
)
408 sal_uInt16 nameindex
= m_pFontNames
[index
-1].GetFaceID();
409 return (m_FontTbl
.GetFaceName(nameindex
));
412 /*void LwpFontNameManager::Override(sal_uInt16 baseID, sal_uInt16 overID, XFFont* pFont)
415 m_pFontNames[overID-1]. Override(&m_pFontNames[baseID-1], pFont);
418 void LwpFontAttrManager::Override(sal_uInt16 baseID, sal_uInt16 overID, XFFont*pFont)
420 m_pFontAttrs[overID-1]. Override(&m_pFontAttrs[baseID-1], pFont);
423 void LwpFontAttrManager::Read(LwpObjectStream
*pStrm
) {
424 pStrm
->QuickRead(&m_nCount
, sizeof(m_nCount
));
425 m_pFontAttrs
= new LwpFontAttrEntry
[m_nCount
];
427 for(sal_uInt16 i
=0; i
<m_nCount
; i
++)
429 m_pFontAttrs
[i
].Read(pStrm
);
434 void LwpFontAttrManager::Override(sal_uInt16 index
, XFFont
* pFont
)
435 //index: start from 1
438 m_pFontAttrs
[index
-1].Override(pFont
);
441 LwpFontAttrManager::~LwpFontAttrManager()
444 delete []m_pFontAttrs
;
447 void LwpFontManager::Read(LwpObjectStream
*pStrm
)
450 m_AttrMgr
.Read(pStrm
);
455 #include "xfilter/xftextstyle.hxx"
458 VO_PARASTYLE call this method to add its style to XFStyleManager based on the fontID
459 1. Construct the text style based on the fontID
460 2. Add the style to XFStyleManager, and return the <office:styles> style name
461 3. Add it to LwpParaStyleMap.
462 Note: A temporary method for only font support phase. The next AddStyle should be used later.
463 // To be replaced by LwpStyleManager::AddStyle() and the following CreateFont()
465 /*void LwpFontManager::AddStyle(LwpObjectID styleObjID, sal_uInt32 fontID, OUString styleName)
467 XFTextStyle* pStyle = new XFTextStyle(); //to be deleted by XFStyleManager
468 AddStyle(styleObjID, fontID, styleName, pStyle);
472 VO_PARASTYLE/VO_CHARACTERSTYLE call this method to add its style to XFStyleManager based on the fontID
473 1. Construct the text style based on the fontID
474 2. Add the style to XFStyleManager, and return the <office:styles> style name
475 3. Add it to LwpParaStyleMap.
476 Prerequisite: pStyle has been created and the paragraph properties has been set to it.
477 //To be replaced by LwpStyleManager::AddStyle() and the following CreateFont()
479 /*void LwpFontManager::AddStyle(LwpObjectID styleObjID, sal_uInt32 fontID, OUString styleName, XFTextStyle* pStyle)
482 XFFont* pFont = CreateFont(fontID);
483 pStyle->SetFont(pFont);
484 pStyle->SetStyleName(styleName);
485 XFStyleManager::AddStyle(pStyle);
486 m_StyleList.insert(LwpParaStyleMap::value_type(styleObjID, styleName));
490 Create XFFont based on the fotID
492 XFFont
* LwpFontManager::CreateFont(sal_uInt32 fontID
)
494 XFFont
* pFont
= new XFFont();
496 m_FNMgr
.Override(GetFontNameIndex(fontID
), pFont
);
497 m_AttrMgr
.Override(GetFontAttrIndex(fontID
), pFont
);
502 Called XFFont based on the override result of two font ids.
503 Refer to CFontManager::OverrideID
505 //OUString LwpFontManager::GetOverrideStyle(sal_uInt32 fontID, sal_uInt32 overID)
506 XFFont
* LwpFontManager::CreateOverrideFont(sal_uInt32 fontID
, sal_uInt32 overID
)
508 XFFont
* pFont
= new XFFont(); //To be deleted by XFFontFactory
512 Override(fontID
, pFont
);
516 Override(overID
, pFont
);
521 void LwpFontManager::Override(sal_uInt32 fontID
, XFFont
* pFont
)
523 m_FNMgr
.Override(GetFontNameIndex(fontID
), pFont
);
524 m_AttrMgr
.Override(GetFontAttrIndex(fontID
), pFont
);
529 Called by VO_PARA to get style name based on the Para Style ID
530 1) Get style from LwpParaStyleMap based on the LwpObjectID of VO_PARASTYLE.
531 2) Prerequisite: VO_PARASTYLE should call AddStyle first.
532 3) Return empty string if no style found.
533 //To be replaced by OUString LwpStyleManager::GetStyle(const LwpObjectID &styleID)
535 /*OUString LwpFontManager::GetParaStyle(const LwpObjectID &styleID)
537 LwpParaStyleMap::const_iterator it = m_StyleList.find(styleID);
538 if (it != m_StyleList.end()) {
539 return((*it).second);
544 void LwpFontManager::SetDfltFont(XFFont
* pFont
)
546 // TODO: Set default XFFont values in lwp filter
547 //color:black, background color: transparent, Orientation: left to right, top to bottom, others: 0
548 //Refer to CFontDescription::CFontDescription(void)
549 //Did not find anything special
550 //pFont->SetColor(XFColor(0,0,0));
553 OUString
LwpFontManager::GetNameByID(sal_uInt32 fontID
)
555 return ( m_FNMgr
.GetNameByIndex(GetFontNameIndex(fontID
)) );//use font id for bullet? note by ,2005/7/5