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 /*************************************************************************
57 * For LWP filter architecture prototype
58 ************************************************************************/
59 /*************************************************************************
62 ************************************************************************/
63 #include "lwpglobalmgr.hxx"
64 #include "lwpsilverbullet.hxx"
66 #include "lwpdivinfo.hxx"
67 #include "lwpfoundry.hxx"
68 #include "lwpstory.hxx"
69 #include "lwppara.hxx"
70 #include "xfilter/xfliststyle.hxx"
71 #include "xfilter/xfstylemanager.hxx"
73 LwpSilverBullet::LwpSilverBullet(LwpObjectHeader
& objHdr
, LwpSvStream
* pStrm
)
74 : LwpDLNFVList(objHdr
, pStrm
), m_pAtomHolder(new LwpAtomHolder
), m_pBulletPara(NULL
)
78 LwpSilverBullet::~LwpSilverBullet()
86 void LwpSilverBullet::Read()
90 m_pObjStrm
->QuickRead(&m_nFlags
, 2);
91 m_aStory
.ReadIndexed(m_pObjStrm
);
94 m_pObjStrm
->QuickRead(&nNumPos
, 2);
96 for (sal_uInt8 nC
= 0; nC
< nNumPos
; nC
++)
98 m_pObjStrm
->QuickRead(&m_pResetPositionFlags
[nC
], 1);
101 m_pObjStrm
->QuickRead(&m_nUseCount
, 4);
103 m_pAtomHolder
->Read(m_pObjStrm
);
107 * @short: Register bullet or numbering style-list and store the returned
108 * name from XFStyleManager.
111 void LwpSilverBullet::RegisterStyle()
113 XFListStyle
* pListStyle
= new XFListStyle();
114 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
116 this->GetBulletPara();
118 if (this->IsBulletOrdered() && this->HasName())
120 ParaNumbering aParaNumbering
;
123 //todo: find the flag in the file
124 sal_Bool bCumulative
= sal_False
;
126 //get the numbeing format of level-1
127 m_pBulletPara
->GetParaNumber(1, &aParaNumbering
);
128 if (aParaNumbering
.pPrefix
)
130 aFmt
.SetPrefix(aParaNumbering
.pPrefix
->GetText());
134 for (sal_uInt8 nPos
= 1; nPos
< 10; nPos
++)
136 //get numbering format according to the position.
137 m_pBulletPara
->GetParaNumber(nPos
, &aParaNumbering
);
138 LwpFribParaNumber
* pParaNumber
= aParaNumbering
.pParaNumber
;
141 if (pParaNumber
->GetStyleID() != NUMCHAR_other
)
143 m_pHideLevels
[nPos
] = aParaNumbering
.nNumLevel
;
144 sal_uInt16 nDisplayLevel
= this->GetDisplayLevel(nPos
);
145 bCumulative
= (sal_Bool
)(nDisplayLevel
> 1);
146 rtl::OUString aPrefix
= this->GetAdditionalName(nPos
);
149 if (!bCumulative
&& aParaNumbering
.pPrefix
)
151 aFmt
.SetPrefix(aPrefix
+ aParaNumbering
.pPrefix
->GetText());
154 aFmt
.SetFormat(this->GetNumCharByStyleID(pParaNumber
));
156 if (aParaNumbering
.pSuffix
)
158 aFmt
.SetSuffix(aParaNumbering
.pSuffix
->GetText());
161 //set numbering format into the style-list.
162 pListStyle
->SetListNumber(nPos
, aFmt
, pParaNumber
->GetStart()+1);
164 if (bCumulative
&& nPos
> 1)
166 pListStyle
->SetDisplayLevel(nPos
, nDisplayLevel
);
172 rtl::OUString aPrefix
, aSuffix
;
173 if (aParaNumbering
.pPrefix
)
175 aPrefix
= aParaNumbering
.pPrefix
->GetText();
177 if (aParaNumbering
.pSuffix
)
179 aSuffix
= aParaNumbering
.pSuffix
->GetText();
182 pListStyle
->SetListBullet(nPos
, this->GetNumCharByStyleID(pParaNumber
).toChar(),
183 rtl::OUString::createFromAscii("Times New Roman"), aPrefix
, aSuffix
);
186 pListStyle
->SetListPosition(nPos
, 0.0, 0.635, 0.0);
187 aParaNumbering
.clear();
193 //register bullet style-list
194 /* for (sal_uInt8 nC = 1; nC < 11; nC++)
196 pListStyle->SetListBullet(nC, this->GetBulletChar(), this->GetBulletFontName(),
197 this->GetPrefix(), this->GetSuffix());
198 pListStyle->SetListPosition(nC, 0.0, 0.635, 0.0);
203 //add style-list to style manager.
204 m_strStyleName
= pXFStyleManager
->AddStyle(pListStyle
)->GetStyleName();
208 * @short: Get the font name of the bullet.
210 * @return: Font name of the bullet.
212 rtl::OUString
LwpSilverBullet::GetBulletFontName()
214 //foundry has been set?
217 return rtl::OUString::createFromAscii("");
220 LwpFontManager
* pFontMgr
= m_pFoundry
->GetFontManger();
223 return rtl::OUString::createFromAscii("");
226 sal_uInt32 nBulletFontID
= m_pBulletPara
->GetBulletFontID();
227 sal_uInt16 nFinalFont
= static_cast<sal_uInt16
>((nBulletFontID
>> 16) & 0xFFFF);
229 //final fontid is valid?
230 if (nFinalFont
> 255 || nFinalFont
== 0)
232 return rtl::OUString::createFromAscii("");
235 //get font name from font manager.
236 rtl::OUString aFontName
= pFontMgr
->GetNameByID(nBulletFontID
);
241 * @short: Get bullet character of the bullet vo_para.
243 * @return: An UChar32 bulle character.
245 UChar32
LwpSilverBullet::GetBulletChar()
247 rtl::OUString aBulletChar
= m_pBulletPara
->GetBulletChar();
249 return aBulletChar
.toChar();
252 rtl::OUString
LwpSilverBullet::GetPrefix()
254 return rtl::OUString::createFromAscii("");
257 rtl::OUString
LwpSilverBullet::GetSuffix()
259 return rtl::OUString::createFromAscii("");
262 * @short: Get the LwpPara object through story id.
264 LwpPara
* LwpSilverBullet::GetBulletPara()
268 LwpStory
* pStory
= static_cast<LwpStory
*>(m_aStory
.obj(VO_STORY
));
274 m_pBulletPara
= static_cast<LwpPara
*>(pStory
->GetFirstPara()->obj(VO_PARA
));
277 return m_pBulletPara
;
281 * @short: Get numbering character of the bullet vo_para.
283 * @param: pParaNumber a pionter to the structure LwpFribParaNumber which
284 * includes numbering prefix, format and suffix.
285 * @return: An OUString object which store the numbering character.
287 rtl::OUString
LwpSilverBullet::GetNumCharByStyleID(LwpFribParaNumber
* pParaNumber
)
292 return rtl::OUString::createFromAscii("");
295 rtl::OUString strNumChar
= rtl::OUString::createFromAscii("1");
296 sal_uInt16 nStyleID
= pParaNumber
->GetStyleID();
303 case NUMCHAR_Chinese4
:
304 strNumChar
= rtl::OUString::createFromAscii("1");
307 strNumChar
= rtl::OUString::createFromAscii("A");
310 strNumChar
= rtl::OUString::createFromAscii("a");
313 strNumChar
= rtl::OUString::createFromAscii("I");
316 strNumChar
= rtl::OUString::createFromAscii("i");
319 uC
= static_cast<UChar32
>(pParaNumber
->GetNumberChar());
320 strNumChar
= rtl::OUString(uC
);
322 case NUMCHAR_Chinese1
:
324 sal_Unicode sBuf
[13] = {0x58f9,0x002c,0x0020,0x8d30,0x002c,0x0020,0x53c1,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
325 strNumChar
= rtl::OUString(sBuf
);
328 case NUMCHAR_Chinese2
:
330 sal_Unicode sBuf
[13] = {0x4e00,0x002c,0x0020,0x4e8c,0x002c,0x0020,0x4e09,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
331 strNumChar
= rtl::OUString(sBuf
);
334 case NUMCHAR_Chinese3
:
336 sal_Unicode sBuf
[13] = {0x7532,0x002c,0x0020,0x4e59,0x002c,0x0020,0x4e19,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
337 strNumChar
= rtl::OUString(sBuf
);
341 strNumChar
= rtl::OUString::createFromAscii("");
350 * @short: To judge the silverbullet list is ordered or not.
352 * @return: sal_True if list is ordered, sal_False if list is unordered.
354 sal_Bool
LwpSilverBullet::IsBulletOrdered()
356 return (sal_Bool
)(m_pBulletPara
->GetFribs()->HasFrib(FRIB_TAG_PARANUMBER
) != NULL
);
360 * @short: Calculate the displaylevel according to the position and hidelevels.
362 * @param: nPos position of the numbering.
363 * @return: displaylevel of the position passed in.
365 sal_uInt16
LwpSilverBullet::GetDisplayLevel(sal_uInt8 nPos
)
369 sal_uInt16 nHideBit
= (1 << nPos
);
370 for (sal_uInt8 nC
= nPos
-1; nC
> 0; nC
--)
372 sal_uInt16 nAttrMask
= ~m_pHideLevels
[nC
];
373 if (!(nAttrMask
& nHideBit
))
375 return static_cast<sal_uInt16
>(nPos
- nC
);
380 return static_cast<sal_uInt16
>(nPos
);
384 * @descr: Get the additional information, "Division name" or "Section Name" from document
385 * variable frib according to numbering position. Whether we should add a
386 * Division/Section name or not is determined by the hidelevels of the frib.
387 * @param: nPos position of the numbering.
388 * @return: Division or Section name.
390 rtl::OUString
LwpSilverBullet::GetAdditionalName(sal_uInt8 nPos
)
392 rtl::OUString aRet
= rtl::OUString::createFromAscii("");
393 sal_uInt16 nHideBit
= (1 << nPos
);
394 sal_Bool bDivisionName
= sal_False
;
395 sal_Bool bSectionName
= sal_False
;
397 LwpFrib
* pParaFrib
= m_pBulletPara
->GetFribs()->GetFribs();
400 return rtl::OUString::createFromAscii("");
405 if (pParaFrib
->GetType() == FRIB_TAG_DOCVAR
)
407 ModifierInfo
* pMoInfo
= pParaFrib
->GetModifiers();
410 return rtl::OUString::createFromAscii("");
412 sal_uInt16 nHideLevels
= pMoInfo
->aTxtAttrOverride
.GetHideLevels();
413 sal_uInt16 nType
= static_cast<LwpFribDocVar
*>(pParaFrib
)->GetType();
415 if (~nHideLevels
& nHideBit
)
419 bDivisionName
= sal_True
;
421 else if (nType
== 0x000E)
423 bSectionName
= sal_True
;
427 pParaFrib
= pParaFrib
->GetNext();
432 aRet
+= this->GetDivisionName();
436 aRet
+= this->GetSectionName();
442 rtl::OUString
LwpSilverBullet::GetDivisionName()
446 return rtl::OUString::createFromAscii("");
449 rtl::OUString aRet
= rtl::OUString::createFromAscii("");
451 LwpDocument
* pDoc
= m_pFoundry
->GetDocument();
454 LwpObjectID
* pID
= pDoc
->GetDivInfoID();
457 aRet
= static_cast<LwpDivInfo
*>(pID
->obj(VO_DIVISIONINFO
))->GetDivName();
464 rtl::OUString
LwpSilverBullet::GetSectionName()
466 LwpStory
* pStory
= static_cast<LwpStory
*>(m_aStory
.obj(VO_STORY
));
469 return rtl::OUString::createFromAscii("");
472 return pStory
->GetSectionName();
475 sal_Bool
LwpSilverBullet::HasName()
477 LwpAtomHolder
* pName
= this->GetName();
480 return (sal_Bool
)(pName
->str().getLength() != 0);