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,
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 /*************************************************************************
58 * For LWP filter architecture prototype
59 ************************************************************************/
61 #include "lwpglobalmgr.hxx"
62 #include "lwpsilverbullet.hxx"
64 #include "lwpdivinfo.hxx"
65 #include "lwpfoundry.hxx"
66 #include "lwpstory.hxx"
67 #include "lwppara.hxx"
68 #include "xfilter/xfliststyle.hxx"
69 #include "xfilter/xfstylemanager.hxx"
71 LwpSilverBullet::LwpSilverBullet(LwpObjectHeader
& objHdr
, LwpSvStream
* pStrm
)
72 : LwpDLNFVList(objHdr
, pStrm
)
75 , m_pAtomHolder(new LwpAtomHolder
)
79 LwpSilverBullet::~LwpSilverBullet()
83 void LwpSilverBullet::Read()
87 m_nFlags
= m_pObjStrm
->QuickReaduInt16();
88 m_aStory
.ReadIndexed(m_pObjStrm
.get());
90 sal_uInt16 nNumPos
= m_pObjStrm
->QuickReaduInt16();
92 if (nNumPos
> SAL_N_ELEMENTS(m_pResetPositionFlags
))
93 throw std::range_error("corrupt SilverBullet");
95 for (sal_uInt16 nC
= 0; nC
< nNumPos
; nC
++)
96 m_pResetPositionFlags
[nC
] = m_pObjStrm
->QuickReaduInt8();
98 m_nUseCount
= m_pObjStrm
->QuickReaduInt32();
100 m_pAtomHolder
->Read(m_pObjStrm
.get());
104 * @short: Register bullet or numbering style-list and store the returned
105 * name from XFStyleManager.
108 void LwpSilverBullet::RegisterStyle()
110 XFListStyle
* pListStyle
= new XFListStyle();
111 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
115 if (IsBulletOrdered() && HasName())
117 //todo: find the flag in the file
118 bool bCumulative
= false;
120 for (sal_uInt8 nPos
= 1; nPos
< 10; nPos
++)
122 ParaNumbering aParaNumbering
;
123 //get numbering format according to the position.
124 m_xBulletPara
->GetParaNumber(nPos
, &aParaNumbering
);
125 LwpFribParaNumber
* pParaNumber
= aParaNumbering
.pParaNumber
;
128 if (pParaNumber
->GetStyleID() != NUMCHAR_other
)
130 m_pHideLevels
[nPos
] = aParaNumbering
.nNumLevel
;
131 sal_uInt16 nDisplayLevel
= GetDisplayLevel(nPos
);
132 bCumulative
= (nDisplayLevel
> 1);
133 OUString aPrefix
= GetAdditionalName(nPos
);
136 if (!bCumulative
&& aParaNumbering
.pPrefix
)
138 aFmt
.SetPrefix(aPrefix
+ aParaNumbering
.pPrefix
->GetText());
141 aFmt
.SetFormat(GetNumCharByStyleID(pParaNumber
));
143 if (aParaNumbering
.pSuffix
)
145 aFmt
.SetSuffix(aParaNumbering
.pSuffix
->GetText());
148 //set numbering format into the style-list.
149 pListStyle
->SetListNumber(nPos
, aFmt
, pParaNumber
->GetStart()+1);
151 if (bCumulative
&& nPos
> 1)
153 pListStyle
->SetDisplayLevel(nPos
, nDisplayLevel
);
159 OUString aPrefix
, aSuffix
;
160 if (aParaNumbering
.pPrefix
)
162 aPrefix
= aParaNumbering
.pPrefix
->GetText();
164 if (aParaNumbering
.pSuffix
)
166 aSuffix
= aParaNumbering
.pSuffix
->GetText();
169 pListStyle
->SetListBullet(nPos
, GetNumCharByStyleID(pParaNumber
),
170 "Times New Roman", aPrefix
, aSuffix
);
173 pListStyle
->SetListPosition(nPos
, 0.0, 0.635, 0.0);
174 aParaNumbering
.clear();
179 //add style-list to style manager.
180 m_strStyleName
= pXFStyleManager
->AddStyle(pListStyle
).m_pStyle
->GetStyleName();
184 * @short: Get the font name of the bullet.
186 * @return: Font name of the bullet.
188 OUString
LwpSilverBullet::GetBulletFontName()
190 //foundry has been set?
196 LwpFontManager
& rFontMgr
= m_pFoundry
->GetFontManger();
198 sal_uInt32 nBulletFontID
= m_xBulletPara
->GetBulletFontID();
199 sal_uInt16 nFinalFont
= static_cast<sal_uInt16
>((nBulletFontID
>> 16) & 0xFFFF);
201 //final fontid is valid?
202 if (nFinalFont
> 255 || nFinalFont
== 0)
207 //get font name from font manager.
208 OUString aFontName
= rFontMgr
.GetNameByID(nBulletFontID
);
213 * @short: Get bullet character of the bullet vo_para.
215 * @return: An UChar32 bulle character.
217 OUString
LwpSilverBullet::GetBulletChar()
219 return m_xBulletPara
->GetBulletChar();
223 * @short: Get the LwpPara object through story id.
225 LwpPara
* LwpSilverBullet::GetBulletPara()
227 if (!m_xBulletPara
.is())
229 LwpStory
* pStory
= dynamic_cast<LwpStory
*>(m_aStory
.obj(VO_STORY
).get());
235 m_xBulletPara
.set(dynamic_cast<LwpPara
*>(pStory
->GetFirstPara().obj(VO_PARA
).get()));
238 return m_xBulletPara
.get();
242 * @short: Get numbering character of the bullet vo_para.
244 * @param: pParaNumber a pointer to the structure LwpFribParaNumber which
245 * includes numbering prefix, format and suffix.
246 * @return: An OUString object which store the numbering character.
248 OUString
LwpSilverBullet::GetNumCharByStyleID(LwpFribParaNumber
* pParaNumber
)
256 OUString
strNumChar("1");
257 sal_uInt16 nStyleID
= pParaNumber
->GetStyleID();
263 case NUMCHAR_Chinese4
:
279 strNumChar
= OUString(sal_Unicode(pParaNumber
->GetNumberChar()));
281 case NUMCHAR_Chinese1
:
283 sal_Unicode sBuf
[13] = {0x58f9,0x002c,0x0020,0x8d30,0x002c,0x0020,0x53c1,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
284 strNumChar
= OUString(sBuf
);
287 case NUMCHAR_Chinese2
:
289 sal_Unicode sBuf
[13] = {0x4e00,0x002c,0x0020,0x4e8c,0x002c,0x0020,0x4e09,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
290 strNumChar
= OUString(sBuf
);
293 case NUMCHAR_Chinese3
:
295 sal_Unicode sBuf
[13] = {0x7532,0x002c,0x0020,0x4e59,0x002c,0x0020,0x4e19,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
296 strNumChar
= OUString(sBuf
);
309 * @short: To judge the silverbullet list is ordered or not.
311 * @return: sal_True if list is ordered, sal_False if list is unordered.
313 bool LwpSilverBullet::IsBulletOrdered()
315 if (!m_xBulletPara
.is())
318 LwpFribPtr
& rFribs
= m_xBulletPara
->GetFribs();
320 return (rFribs
.HasFrib(FRIB_TAG_PARANUMBER
) != nullptr);
324 * @short: Calculate the displaylevel according to the position and hidelevels.
326 * @param: nPos position of the numbering.
327 * @return: displaylevel of the position passed in.
329 sal_uInt16
LwpSilverBullet::GetDisplayLevel(sal_uInt8 nPos
)
333 sal_uInt16 nHideBit
= (1 << nPos
);
334 for (sal_uInt8 nC
= nPos
-1; nC
> 0; nC
--)
336 sal_uInt16 nAttrMask
= ~m_pHideLevels
[nC
];
337 if (!(nAttrMask
& nHideBit
))
339 return static_cast<sal_uInt16
>(nPos
- nC
);
344 return static_cast<sal_uInt16
>(nPos
);
348 * @descr: Get the additional information, "Division name" or "Section Name" from document
349 * variable frib according to numbering position. Whether we should add a
350 * Division/Section name or not is determined by the hidelevels of the frib.
351 * @param: nPos position of the numbering.
352 * @return: Division or Section name.
354 OUString
LwpSilverBullet::GetAdditionalName(sal_uInt8 nPos
)
357 sal_uInt16 nHideBit
= (1 << nPos
);
358 bool bDivisionName
= false;
359 bool bSectionName
= false;
361 LwpFrib
* pParaFrib
= m_xBulletPara
->GetFribs().GetFribs();
369 if (pParaFrib
->GetType() == FRIB_TAG_DOCVAR
)
371 ModifierInfo
* pMoInfo
= pParaFrib
->GetModifiers();
376 sal_uInt16 nHideLevels
= pMoInfo
->aTxtAttrOverride
.GetHideLevels();
377 sal_uInt16 nType
= static_cast<LwpFribDocVar
*>(pParaFrib
)->GetType();
379 if (~nHideLevels
& nHideBit
)
383 bDivisionName
= true;
385 else if (nType
== 0x000E)
391 pParaFrib
= pParaFrib
->GetNext();
396 aRet
+= GetDivisionName();
400 aRet
+= GetSectionName();
406 OUString
LwpSilverBullet::GetDivisionName()
415 LwpDocument
* pDoc
= m_pFoundry
->GetDocument();
418 LwpObjectID
& rID
= pDoc
->GetDivInfoID();
421 LwpDivInfo
*pInfo
= dynamic_cast<LwpDivInfo
*>(rID
.obj(VO_DIVISIONINFO
).get());
423 aRet
= pInfo
->GetDivName();
430 OUString
LwpSilverBullet::GetSectionName()
432 LwpStory
* pStory
= dynamic_cast<LwpStory
*>(m_aStory
.obj(VO_STORY
).get());
438 return pStory
->GetSectionName();
441 bool LwpSilverBullet::HasName()
443 LwpAtomHolder
& rName
= GetName();
444 return (!rName
.str().isEmpty());
446 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */