LibreOffice Module lotuswordpro (master) 1
lwpbulletstylemgr.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/*************************************************************************
57 * @file
58 * For LWP filter architecture prototype
59 ************************************************************************/
60
61#include "lwpbulletstylemgr.hxx"
62#include "lwpfribheader.hxx"
63#include "lwppara.hxx"
64#include "lwpsilverbullet.hxx"
65#include <lwptools.hxx>
66#include "lwpparaproperty.hxx"
69#include <xfilter/xflist.hxx>
70#include <lwpglobalmgr.hxx>
72#include <sal/log.hxx>
73
75 : m_pFoundry(nullptr)
76 , m_bContinue(true)
77 , m_bIsBulletSkipped(false)
78{
79}
80
82{
83 m_vIDsPairList.clear();
84 m_vStyleNameList.clear();
85}
86
95 LwpIndentOverride const * pIndent)
96{
97 if(!pPara || !pIndent || !pBullOver)
98 {
99 return OUString();
100 }
101
102 LwpSilverBullet* pSilverBullet = pPara->GetSilverBullet();
103 if (!pSilverBullet)
104 {
105 assert(false);
106 return OUString();
107 }
108
109 LwpPara* pBulletPara = pSilverBullet->GetBulletPara();
110 if (!pBulletPara)
111 {
112 SAL_WARN("lwp", "missing bullet para");
113 return OUString();
114 }
115
117 LwpObjectID aIndentID;
118 if (pProp)
119 {
120 LwpParaIndentProperty* pIndentProp = static_cast<LwpParaIndentProperty*>(pProp);
121 aIndentID = pIndentProp->GetIndentID();
122 }
123
124 LwpObjectID aBulletID = pBullOver->GetSilverBullet();
125 std::unique_ptr<LwpBulletOverride> pBulletOver(pBullOver->clone());
126
127 sal_uInt16 nNameIndex = 0;
128 for (auto const& vIDsPair : m_vIDsPairList)
129 {
130 if (vIDsPair.first->GetSilverBullet() == aBulletID && vIDsPair.second == aIndentID
131 && vIDsPair.first->IsRightAligned() == pBullOver->IsRightAligned())
132 {
133 return m_vStyleNameList[nNameIndex];
134 }
135 else
136 {
137 nNameIndex++;
138 }
139 }
140
141 m_vIDsPairList.emplace_back(std::move(pBulletOver), aIndentID);
142 OUString aStyleName;
143
144 LwpFribPtr& rBulletParaFribs = pBulletPara->GetFribs();
145 bool bIsNumbering = (rBulletParaFribs.HasFrib(FRIB_TAG_PARANUMBER) != nullptr);
146
148 if (pBullOver->IsRightAligned())
149 {
150 eAlign = enumXFAlignEnd;
151 }
152
153 std::unique_ptr<XFListStyle> pListStyle(new XFListStyle());
155
156 if (!bIsNumbering)
157 {
158 for (sal_uInt8 nC = 1; nC < 11; nC++)
159 {
160 pListStyle->SetListBullet(nC, pSilverBullet->GetBulletChar(), pSilverBullet->GetBulletFontName(),
162
163 if (pIndent->GetMRest() > 0) /* note: used to be 0.001, no idea why */
164 {
165 pListStyle->SetListPosition(nC, 0.0,
167 }
168 else
169 {
170 pListStyle->SetListPosition(nC, 0.0,
172 }
173 }
174
175 aStyleName = pXFStyleMgr->AddStyle(std::move(pListStyle)).m_pStyle->GetStyleName();
176 }
177 else
178 {
179 ParaNumbering aParaNumbering;
180 pBulletPara->GetParaNumber(1, &aParaNumbering);
181 LwpFribParaNumber* pParaNumber = aParaNumbering.pParaNumber;
182 if (pParaNumber)
183 {
184 for (sal_uInt8 nPos = 1; nPos < 10; nPos++)
185 {
186 if (pParaNumber->GetStyleID() != NUMCHAR_other)
187 {
188 OUString aPrefix;
189 XFNumFmt aFmt;
190 if (aParaNumbering.pPrefix)
191 {
192 aPrefix += aParaNumbering.pPrefix->GetText();
193 }
194
195 OUString aNumber = LwpSilverBullet::GetNumCharByStyleID(pParaNumber);
196 if (pParaNumber->GetStyleID() == NUMCHAR_01 || pParaNumber->GetStyleID() == NUMCHAR_Chinese4)
197 {
198 aPrefix += "0";
199 }
200 aFmt.SetPrefix(aPrefix);
201
202 aFmt.SetFormat(aNumber);
203
204 if (aParaNumbering.pSuffix)
205 {
206 aFmt.SetSuffix(aParaNumbering.pSuffix->GetText());
207 }
208
209 //set numbering format into the style-list.
210 pListStyle->SetListNumber(nPos, aFmt, pParaNumber->GetStart()+1);
211
212 }
213 else
214 {
215 OUString aPrefix, aSuffix;
216 if (aParaNumbering.pPrefix)
217 {
218 aPrefix = aParaNumbering.pPrefix->GetText();
219 }
220 if (aParaNumbering.pSuffix)
221 {
222 aSuffix = aParaNumbering.pSuffix->GetText();
223 }
224
225 pListStyle->SetListBullet(nPos, LwpSilverBullet::GetNumCharByStyleID(pParaNumber),
226 "Times New Roman", aPrefix, aSuffix);
227 }
228
229 pListStyle->SetListPosition(nPos, 0.0, 0.635, 0.0);
230 }
231 aStyleName = pXFStyleMgr->AddStyle(std::move(pListStyle)).m_pStyle->GetStyleName();
232 }
233 }
234
235 m_vStyleNameList.push_back(aStyleName);
236 return aStyleName;
237
238}
239
240//Create nested XFList and XFItems and then add it to XFContentContainer(pCont)
241//Return the inner XFItem created.
243 XFContentContainer* pCont, bool bIsOrdered,
244 const OUString& rStyleName, sal_Int16 nLevel, bool bIsBulletSkiped)
245{
246 assert(nLevel > 0);
247
248 m_bIsBulletSkipped = bIsBulletSkiped;
249
250 //todo: need judge here.
251 bool bContinue = m_bContinue;
252
253 rtl::Reference<XFList> prevList;
254 XFListItem* theItem;
255 XFListItem* InnerItem = nullptr;
256 for (sal_Int8 nC = nLevel - 1; nC >= 0; nC--)
257 {
258 rtl::Reference<XFList> theList(new XFList);
259 theItem = new XFListItem();
260 theList->Add(theItem);
261
262 if (bIsOrdered)
263 {
264 theList->SetOrdered(true);
265 }
266 else
267 {
268 bContinue = false;
269 theList->SetOrdered(false);
270 }
271
272 if (nC == nLevel - 1)
273 {
274 theList->SetContinueNumber(bContinue);
275 }
276 //Add the outer list to pCont
277 if (nC == 0 && pCont)
278 {
279 theList->SetStyleName(rStyleName);
280 theList->SetContinueNumber(bContinue);
281 pCont->Add(theList.get());
282 }
283
284 if ((nC == 0) && bIsBulletSkiped)
285 {
286 theList->SetContinueNumber(true);
287 }
288
289 if ((nC == nLevel - 1) && bIsBulletSkiped)
290 {
291 theItem->SetIsHeader();
292 }
293
294 if (nC == nLevel - 1)
295 {
296 InnerItem = theItem;
297 }
298
299 if (prevList)
300 {
301 theItem->Add(prevList.get());
302 }
303 prevList = theList;
304 }
305 return InnerItem;
306}
307
308/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual OUString GetStyleName()=0
@descr: return the style name.
virtual LwpBulletOverride * clone() const override
const LwpObjectID & GetSilverBullet() const
bool IsRightAligned() const
std::vector< OverridePair > m_vIDsPairList
rtl::Reference< XFContentContainer > AddBulletList(XFContentContainer *pCont, bool bIsOrdered, const OUString &rStyleName, sal_Int16 nLevel, bool bIsBulletSkiped)
OUString RegisterBulletStyle(LwpPara *pPara, const LwpBulletOverride *pBullOver, LwpIndentOverride const *pIndent)
Register bullet style to style-list.
std::vector< OUString > m_vStyleNameList
sal_uInt16 GetStyleID() const
sal_uInt16 GetStart() const
LwpFrib * HasFrib(sal_uInt8 nType)
Definition: lwpfribptr.cxx:366
const OUString & GetText() const
Definition: lwpfribtext.hxx:76
XFStyleManager * GetXFStyleManager()
static LwpGlobalMgr * GetInstance(LwpSvStream *pSvStream=nullptr)
sal_Int32 GetMFirst() const
sal_Int32 GetMRest() const
object id class
Definition: lwpobjid.hxx:79
const LwpObjectID & GetIndentID() const
LwpFribPtr & GetFribs()
Definition: lwppara.hxx:303
LwpSilverBullet * GetSilverBullet()
Definition: lwppara.hxx:279
LwpParaProperty * GetProperty(sal_uInt32 nPropType)
Definition: lwppara1.cxx:519
void GetParaNumber(sal_uInt16 nPosition, ParaNumbering *pParaNumbering)
: Offer prefix, paranumber and suffix according to position.
Definition: lwppara1.cxx:164
OUString const & GetBulletChar() const
: Get bullet character of the bullet vo_para.
LwpPara * GetBulletPara()
: Get the LwpPara object through story id.
OUString GetBulletFontName()
: Get the font name of the bullet.
static OUString GetSuffix()
static OUString GetNumCharByStyleID(LwpFribParaNumber const *pParaNumber)
: Get numbering character of the bullet vo_para.
static OUString GetPrefix()
static double ConvertToMetric(double fInch)
Definition: lwptools.hxx:113
static double ConvertFromUnits(sal_Int32 nUnits)
Definition: lwptools.hxx:109
A container for content.
virtual void Add(XFContent *pContent)
@descr Add content.
void SetIsHeader()
Definition: xflistitem.hxx:82
list object for order-list and unordered-list.
Definition: xflist.hxx:72
Bullet number format.
Definition: xfnumfmt.hxx:71
void SetFormat(const OUString &format)
Definition: xfnumfmt.hxx:120
void SetPrefix(const OUString &prefix)
Definition: xfnumfmt.hxx:85
void SetSuffix(const OUString &suffix)
Definition: xfnumfmt.hxx:96
Style manager for the filter.
IXFStyleRet AddStyle(std::unique_ptr< IXFStyle > pStyle)
sal_uInt16 nPos
#define SAL_WARN(area, stream)
@ FRIB_TAG_PARANUMBER
#define PP_LOCAL_INDENT
const sal_uInt16 NUMCHAR_Chinese4
const sal_uInt16 NUMCHAR_01
const sal_uInt16 NUMCHAR_other
IXFStyle * m_pStyle
Definition: xfstylecont.hxx:71
LwpFribParaNumber * pParaNumber
Definition: lwppara.hxx:116
LwpFribText * pPrefix
Definition: lwppara.hxx:115
LwpFribText * pSuffix
Definition: lwppara.hxx:117
unsigned char sal_uInt8
signed char sal_Int8
enumXFAlignType
Definition: xfdefs.hxx:172
@ enumXFAlignStart
Definition: xfdefs.hxx:174
@ enumXFAlignEnd
Definition: xfdefs.hxx:176