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 ************************************************************************/
62 #include <lwpglobalmgr.hxx>
63 #include "lwpsilverbullet.hxx"
65 #include "lwpdivinfo.hxx"
66 #include "lwpfribheader.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
const & objHdr
, LwpSvStream
* pStrm
)
74 : LwpDLNFVList(objHdr
, pStrm
)
78 memset(m_pHideLevels
, 0, sizeof(m_pHideLevels
));
81 LwpSilverBullet::~LwpSilverBullet()
85 void LwpSilverBullet::Read()
89 m_nFlags
= m_pObjStrm
->QuickReaduInt16();
90 m_aStory
.ReadIndexed(m_pObjStrm
.get());
92 sal_uInt16 nNumPos
= m_pObjStrm
->QuickReaduInt16();
94 if (nNumPos
> SAL_N_ELEMENTS(m_pResetPositionFlags
))
95 throw std::range_error("corrupt SilverBullet");
97 for (sal_uInt16 nC
= 0; nC
< nNumPos
; nC
++)
98 m_pResetPositionFlags
[nC
] = m_pObjStrm
->QuickReaduInt8();
100 if (nNumPos
< SAL_N_ELEMENTS(m_pResetPositionFlags
))
101 std::fill(m_pResetPositionFlags
+ nNumPos
, m_pResetPositionFlags
+ SAL_N_ELEMENTS(m_pResetPositionFlags
), 0);
103 m_nUseCount
= m_pObjStrm
->QuickReaduInt32();
105 m_aAtomHolder
.Read(m_pObjStrm
.get());
109 * @short: Register bullet or numbering style-list and store the returned
110 * name from XFStyleManager.
113 void LwpSilverBullet::RegisterStyle()
115 std::unique_ptr
<XFListStyle
> xListStyle(new XFListStyle());
116 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
120 if (IsBulletOrdered() && HasName())
122 //todo: find the flag in the file
123 bool bCumulative
= false;
125 for (sal_uInt8 nPos
= 1; nPos
< 10; nPos
++)
127 ParaNumbering aParaNumbering
;
128 //get numbering format according to the position.
129 m_xBulletPara
->GetParaNumber(nPos
, &aParaNumbering
);
130 LwpFribParaNumber
* pParaNumber
= aParaNumbering
.pParaNumber
;
133 if (pParaNumber
->GetStyleID() != NUMCHAR_other
)
135 m_pHideLevels
[nPos
] = aParaNumbering
.nNumLevel
;
136 sal_uInt16 nDisplayLevel
= GetDisplayLevel(nPos
);
137 bCumulative
= (nDisplayLevel
> 1);
138 OUString aPrefix
= GetAdditionalName(nPos
);
141 if (!bCumulative
&& aParaNumbering
.pPrefix
)
143 aFmt
.SetPrefix(aPrefix
+ aParaNumbering
.pPrefix
->GetText());
146 aFmt
.SetFormat(GetNumCharByStyleID(pParaNumber
));
148 if (aParaNumbering
.pSuffix
)
150 aFmt
.SetSuffix(aParaNumbering
.pSuffix
->GetText());
153 //set numbering format into the style-list.
154 xListStyle
->SetListNumber(nPos
, aFmt
, pParaNumber
->GetStart()+1);
156 if (bCumulative
&& nPos
> 1)
158 xListStyle
->SetDisplayLevel(nPos
, nDisplayLevel
);
164 OUString aPrefix
, aSuffix
;
165 if (aParaNumbering
.pPrefix
)
167 aPrefix
= aParaNumbering
.pPrefix
->GetText();
169 if (aParaNumbering
.pSuffix
)
171 aSuffix
= aParaNumbering
.pSuffix
->GetText();
174 xListStyle
->SetListBullet(nPos
, GetNumCharByStyleID(pParaNumber
),
175 "Times New Roman", aPrefix
, aSuffix
);
178 xListStyle
->SetListPosition(nPos
, 0.0, 0.635, 0.0);
179 aParaNumbering
.clear();
184 //add style-list to style manager.
185 m_strStyleName
= pXFStyleManager
->AddStyle(std::move(xListStyle
)).m_pStyle
->GetStyleName();
189 * @short: Get the font name of the bullet.
191 * @return: Font name of the bullet.
193 OUString
LwpSilverBullet::GetBulletFontName()
195 //foundry has been set?
201 LwpFontManager
& rFontMgr
= m_pFoundry
->GetFontManager();
203 sal_uInt32 nBulletFontID
= m_xBulletPara
->GetBulletFontID();
204 sal_uInt16 nFinalFont
= static_cast<sal_uInt16
>((nBulletFontID
>> 16) & 0xFFFF);
206 //final fontid is valid?
207 if (nFinalFont
> 255 || nFinalFont
== 0)
212 //get font name from font manager.
213 OUString aFontName
= rFontMgr
.GetNameByID(nBulletFontID
);
218 * @short: Get bullet character of the bullet vo_para.
220 * @return: An UChar32 bullet character.
222 OUString
const & LwpSilverBullet::GetBulletChar() const
224 return m_xBulletPara
->GetBulletChar();
228 * @short: Get the LwpPara object through story id.
230 LwpPara
* LwpSilverBullet::GetBulletPara()
232 if (!m_xBulletPara
.is())
234 LwpStory
* pStory
= dynamic_cast<LwpStory
*>(m_aStory
.obj(VO_STORY
).get());
240 m_xBulletPara
.set(dynamic_cast<LwpPara
*>(pStory
->GetFirstPara().obj(VO_PARA
).get()));
243 return m_xBulletPara
.get();
247 * @short: Get numbering character of the bullet vo_para.
249 * @param: pParaNumber a pointer to the structure LwpFribParaNumber which
250 * includes numbering prefix, format and suffix.
251 * @return: An OUString object which store the numbering character.
253 OUString
LwpSilverBullet::GetNumCharByStyleID(LwpFribParaNumber
const * pParaNumber
)
261 OUString
strNumChar("1");
262 sal_uInt16 nStyleID
= pParaNumber
->GetStyleID();
268 case NUMCHAR_Chinese4
:
284 strNumChar
= OUString(sal_Unicode(pParaNumber
->GetNumberChar()));
286 case NUMCHAR_Chinese1
:
288 static constexpr OUStringLiteral sBuf
= u
"\u58f9\u002c\u0020\u8d30, \u53c1, ...";
289 strNumChar
= OUString(sBuf
);
292 case NUMCHAR_Chinese2
:
294 static constexpr OUStringLiteral sBuf
= u
"\u4e00, \u4e8c, \u4e09, ...";
295 strNumChar
= OUString(sBuf
);
298 case NUMCHAR_Chinese3
:
300 static constexpr OUStringLiteral sBuf
= u
"\u7532, \u4e59, \u4e19, ...";
301 strNumChar
= OUString(sBuf
);
314 * @short: To judge the silverbullet list is ordered or not.
316 * @return: sal_True if list is ordered, sal_False if list is unordered.
318 bool LwpSilverBullet::IsBulletOrdered()
320 if (!m_xBulletPara
.is())
323 LwpFribPtr
& rFribs
= m_xBulletPara
->GetFribs();
325 return (rFribs
.HasFrib(FRIB_TAG_PARANUMBER
) != nullptr);
329 * @short: Calculate the displaylevel according to the position and hidelevels.
331 * @param: nPos position of the numbering.
332 * @return: displaylevel of the position passed in.
334 sal_uInt16
LwpSilverBullet::GetDisplayLevel(sal_uInt8 nPos
)
338 sal_uInt16 nHideBit
= (1 << nPos
);
339 for (sal_uInt8 nC
= nPos
-1; nC
> 0; nC
--)
341 sal_uInt16 nAttrMask
= ~m_pHideLevels
[nC
];
342 if (!(nAttrMask
& nHideBit
))
344 return static_cast<sal_uInt16
>(nPos
- nC
);
349 return static_cast<sal_uInt16
>(nPos
);
353 * @descr: Get the additional information, "Division name" or "Section Name" from document
354 * variable frib according to numbering position. Whether we should add a
355 * Division/Section name or not is determined by the hidelevels of the frib.
356 * @param: nPos position of the numbering.
357 * @return: Division or Section name.
359 OUString
LwpSilverBullet::GetAdditionalName(sal_uInt8 nPos
)
362 sal_uInt16 nHideBit
= (1 << nPos
);
363 bool bDivisionName
= false;
364 bool bSectionName
= false;
366 LwpFrib
* pParaFrib
= m_xBulletPara
->GetFribs().GetFribs();
374 if (pParaFrib
->GetType() == FRIB_TAG_DOCVAR
)
376 ModifierInfo
* pMoInfo
= pParaFrib
->GetModifiers();
381 sal_uInt16 nHideLevels
= pMoInfo
->aTxtAttrOverride
.GetHideLevels();
382 sal_uInt16 nType
= static_cast<LwpFribDocVar
*>(pParaFrib
)->GetType();
384 if (~nHideLevels
& nHideBit
)
388 bDivisionName
= true;
390 else if (nType
== 0x000E)
396 pParaFrib
= pParaFrib
->GetNext();
401 aRet
+= GetDivisionName();
405 aRet
+= GetSectionName();
411 OUString
LwpSilverBullet::GetDivisionName()
420 LwpDocument
* pDoc
= m_pFoundry
->GetDocument();
423 LwpObjectID
& rID
= pDoc
->GetDivInfoID();
426 LwpDivInfo
*pInfo
= dynamic_cast<LwpDivInfo
*>(rID
.obj(VO_DIVISIONINFO
).get());
428 aRet
= pInfo
->GetDivName();
435 OUString
LwpSilverBullet::GetSectionName() const
437 LwpStory
* pStory
= dynamic_cast<LwpStory
*>(m_aStory
.obj(VO_STORY
).get());
443 return pStory
->GetSectionName();
446 bool LwpSilverBullet::HasName()
448 LwpAtomHolder
& rName
= GetName();
449 return (!rName
.str().isEmpty());
451 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */