LibreOffice Module lotuswordpro (master) 1
lwpsilverbullet.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 <memory>
62#include <lwpglobalmgr.hxx>
63#include "lwpsilverbullet.hxx"
64#include "lwpdoc.hxx"
65#include "lwpdivinfo.hxx"
66#include "lwpfribheader.hxx"
67#include <lwpfoundry.hxx>
68#include "lwpstory.hxx"
69#include "lwppara.hxx"
72
74 : LwpDLNFVList(objHdr, pStrm)
75 , m_nFlags(0)
76 , m_nUseCount(0)
77{
78 memset(m_pHideLevels, 0, sizeof(m_pHideLevels));
79}
80
82{
83}
84
86{
88
89 m_nFlags = m_pObjStrm->QuickReaduInt16();
91
92 sal_uInt16 nNumPos = m_pObjStrm->QuickReaduInt16();
93
95 throw std::range_error("corrupt SilverBullet");
96
97 for (sal_uInt16 nC = 0; nC < nNumPos; nC++)
98 m_pResetPositionFlags[nC] = m_pObjStrm->QuickReaduInt8();
99
102
103 m_nUseCount = m_pObjStrm->QuickReaduInt32();
104
106}
107
114{
115 std::unique_ptr<XFListStyle> xListStyle(new XFListStyle());
117
119
120 if (IsBulletOrdered() && HasName())
121 {
122 //todo: find the flag in the file
123 bool bCumulative = false;
124
125 for (sal_uInt8 nPos = 1; nPos < 10; nPos++)
126 {
127 ParaNumbering aParaNumbering;
128 //get numbering format according to the position.
129 m_xBulletPara->GetParaNumber(nPos, &aParaNumbering);
130 LwpFribParaNumber* pParaNumber = aParaNumbering.pParaNumber;
131 if (pParaNumber)
132 {
133 if (pParaNumber->GetStyleID() != NUMCHAR_other)
134 {
135 m_pHideLevels[nPos] = aParaNumbering.nNumLevel;
136 sal_uInt16 nDisplayLevel = GetDisplayLevel(nPos);
137 bCumulative = (nDisplayLevel > 1);
138 OUString aPrefix = GetAdditionalName(nPos);
139
140 XFNumFmt aFmt;
141 if (!bCumulative && aParaNumbering.pPrefix)
142 {
143 aFmt.SetPrefix(aPrefix + aParaNumbering.pPrefix->GetText());
144 }
145
146 aFmt.SetFormat(GetNumCharByStyleID(pParaNumber));
147
148 if (aParaNumbering.pSuffix)
149 {
150 aFmt.SetSuffix(aParaNumbering.pSuffix->GetText());
151 }
152
153 //set numbering format into the style-list.
154 xListStyle->SetListNumber(nPos, aFmt, pParaNumber->GetStart()+1);
155
156 if (bCumulative && nPos > 1)
157 {
158 xListStyle->SetDisplayLevel(nPos, nDisplayLevel);
159 }
160
161 }
162 else
163 {
164 OUString aPrefix, aSuffix;
165 if (aParaNumbering.pPrefix)
166 {
167 aPrefix = aParaNumbering.pPrefix->GetText();
168 }
169 if (aParaNumbering.pSuffix)
170 {
171 aSuffix = aParaNumbering.pSuffix->GetText();
172 }
173
174 xListStyle->SetListBullet(nPos, GetNumCharByStyleID(pParaNumber),
175 "Times New Roman", aPrefix, aSuffix);
176 }
177
178 xListStyle->SetListPosition(nPos, 0.0, 0.635, 0.0);
179 aParaNumbering.clear();
180 }
181 }
182 }
183
184 //add style-list to style manager.
185 m_strStyleName = pXFStyleManager->AddStyle(std::move(xListStyle)).m_pStyle->GetStyleName();
186}
187
194{
195 //foundry has been set?
196 if (!m_pFoundry)
197 {
198 return OUString();
199 }
200
202
203 sal_uInt32 nBulletFontID = m_xBulletPara->GetBulletFontID();
204 sal_uInt16 nFinalFont = static_cast<sal_uInt16>((nBulletFontID >> 16) & 0xFFFF);
205
206 //final fontid is valid?
207 if (nFinalFont > 255 || nFinalFont == 0)
208 {
209 return OUString();
210 }
211
212 //get font name from font manager.
213 OUString aFontName = rFontMgr.GetNameByID(nBulletFontID);
214
215 return aFontName;
216}
222OUString const & LwpSilverBullet::GetBulletChar() const
223{
224 return m_xBulletPara->GetBulletChar();
225}
226
231{
232 if (!m_xBulletPara.is())
233 {
234 LwpStory* pStory = dynamic_cast<LwpStory*>(m_aStory.obj(VO_STORY).get());
235 if (!pStory)
236 {
237 return nullptr;
238 }
239
240 m_xBulletPara.set(dynamic_cast<LwpPara*>(pStory->GetFirstPara().obj(VO_PARA).get()));
241 }
242
243 return m_xBulletPara.get();
244}
245
254{
255 if (!pParaNumber)
256 {
257 assert(false);
258 return OUString();
259 }
260
261 OUString strNumChar("1");
262 sal_uInt16 nStyleID = pParaNumber->GetStyleID();
263
264 switch (nStyleID)
265 {
266 case NUMCHAR_1:
267 case NUMCHAR_01:
268 case NUMCHAR_Chinese4:
269 strNumChar = "1";
270 break;
271 case NUMCHAR_A :
272 strNumChar = "A";
273 break;
274 case NUMCHAR_a:
275 strNumChar = "a";
276 break;
277 case NUMCHAR_I:
278 strNumChar = "I";
279 break;
280 case NUMCHAR_i:
281 strNumChar = "i";
282 break;
283 case NUMCHAR_other:
284 strNumChar = OUString(sal_Unicode(pParaNumber->GetNumberChar()));
285 break;
286 case NUMCHAR_Chinese1:
287 {
288 static constexpr OUStringLiteral sBuf = u"\u58f9\u002c\u0020\u8d30, \u53c1, ...";
289 strNumChar = OUString(sBuf);
290 }
291 break;
292 case NUMCHAR_Chinese2:
293 {
294 static constexpr OUStringLiteral sBuf = u"\u4e00, \u4e8c, \u4e09, ...";
295 strNumChar = OUString(sBuf);
296 }
297 break;
298 case NUMCHAR_Chinese3:
299 {
300 static constexpr OUStringLiteral sBuf = u"\u7532, \u4e59, \u4e19, ...";
301 strNumChar = OUString(sBuf);
302 }
303 break;
304 case NUMCHAR_none:
305 strNumChar.clear();
306 break;
307 default:
308 break;
309 }//mod end
310 return strNumChar;
311}
312
319{
320 if (!m_xBulletPara.is())
321 return false;
322
323 LwpFribPtr& rFribs = m_xBulletPara->GetFribs();
324
325 return (rFribs.HasFrib(FRIB_TAG_PARANUMBER) != nullptr);
326}
327
335{
336 if (nPos > 1)
337 {
338 sal_uInt16 nHideBit = (1 << nPos);
339 for (sal_uInt8 nC = nPos-1; nC > 0; nC--)
340 {
341 sal_uInt16 nAttrMask = ~m_pHideLevels[nC];
342 if (!(nAttrMask & nHideBit))
343 {
344 return static_cast<sal_uInt16>(nPos - nC);
345 }
346 }
347 }
348
349 return static_cast<sal_uInt16>(nPos);
350}
351
360{
361 OUString aRet;
362 sal_uInt16 nHideBit = (1 << nPos);
363 bool bDivisionName = false;
364 bool bSectionName = false;
365
366 LwpFrib* pParaFrib = m_xBulletPara->GetFribs().GetFribs();
367 if (!pParaFrib)
368 {
369 return OUString();
370 }
371
372 while (pParaFrib)
373 {
374 if (pParaFrib->GetType() == FRIB_TAG_DOCVAR)
375 {
376 ModifierInfo* pMoInfo = pParaFrib->GetModifiers();
377 if (!pMoInfo)
378 {
379 return OUString();
380 }
381 sal_uInt16 nHideLevels = pMoInfo->aTxtAttrOverride.GetHideLevels();
382 sal_uInt16 nType = static_cast<LwpFribDocVar*>(pParaFrib)->GetType();
383
384 if (~nHideLevels & nHideBit)
385 {
386 if (nType == 0x000D)
387 {
388 bDivisionName = true;
389 }
390 else if (nType == 0x000E)
391 {
392 bSectionName= true;
393 }
394 }
395 }
396 pParaFrib = pParaFrib->GetNext();
397 }
398
399 if (bDivisionName)
400 {
401 aRet += GetDivisionName();
402 }
403 if (bSectionName)
404 {
405 aRet += GetSectionName();
406 }
407
408 return aRet;
409}
410
412{
413 OUString aRet;
414
415 if (!m_pFoundry)
416 {
417 return aRet;
418 }
419
421 if (pDoc)
422 {
423 LwpObjectID& rID = pDoc->GetDivInfoID();
424 if (!rID.IsNull())
425 {
426 LwpDivInfo *pInfo = dynamic_cast<LwpDivInfo*>(rID.obj(VO_DIVISIONINFO).get());
427 if (pInfo)
428 aRet = pInfo->GetDivName();
429 }
430 }
431
432 return aRet;
433}
434
436{
437 LwpStory* pStory = dynamic_cast<LwpStory*>(m_aStory.obj(VO_STORY).get());
438 if (!pStory)
439 {
440 return OUString();
441 }
442
443 return pStory->GetSectionName();
444}
445
447{
448 LwpAtomHolder& rName = GetName();
449 return (!rName.str().isEmpty());
450}
451/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual OUString GetStyleName()=0
@descr: return the style name.
AtomHolder class of Word Pro to hold a string.
void Read(LwpObjectStream *pStrm)
@descr read atomholder from object stream the default encoding used in Word Pro is 1252
const OUString & str() const
Double Linked Named Family Virtual List.
Definition: lwpdlvlist.hxx:91
void Read() override
@descr Read LwpDLNFVList data from object stream
Definition: lwpdlvlist.cxx:90
LwpAtomHolder & GetName()
Definition: lwpdlvlist.hxx:108
OUString const & GetDivName() const
Definition: lwpdivinfo.hxx:79
Document object, represent document and division.
Definition: lwpdoc.hxx:76
LwpObjectID & GetDivInfoID()
Definition: lwpdoc.hxx:183
OUString GetNameByID(sal_uInt32 fontID)
Definition: lwpfont.cxx:504
LwpFontManager & GetFontManager()
Definition: lwpfoundry.hxx:250
LwpDocument * GetDocument()
Definition: lwpfoundry.hxx:254
sal_uInt16 GetNumberChar() const
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
LwpFrib * GetNext()
Definition: lwpfrib.hxx:96
sal_uInt8 GetType() const
Definition: lwpfrib.hxx:98
ModifierInfo * GetModifiers()
Definition: lwpfrib.hxx:114
XFStyleManager * GetXFStyleManager()
static LwpGlobalMgr * GetInstance(LwpSvStream *pSvStream=nullptr)
Base class of all Lwp VO objects.
Definition: lwpobjhdr.hxx:71
object id class
Definition: lwpobjid.hxx:79
void ReadIndexed(LwpSvStream *pStrm)
@descr Read object id with indexed format from stream if index>0, lowid is get from time table per th...
Definition: lwpobjid.cxx:96
rtl::Reference< LwpObject > obj(VO_TYPE tag=VO_INVALID) const
@descr get object from object factory per the object id
Definition: lwpobjid.cxx:183
bool IsNull() const
Definition: lwpobjid.hxx:110
LwpFoundry * m_pFoundry
Definition: lwpobj.hxx:91
std::unique_ptr< LwpObjectStream > m_pObjStrm
Definition: lwpobj.hxx:90
rtl::Reference< LwpPara > m_xBulletPara
OUString const & GetBulletChar() const
: Get bullet character of the bullet vo_para.
void Read() override
@descr Read LwpDLNFVList data from object stream
virtual void RegisterStyle() override
: Register bullet or numbering style-list and store the returned name from XFStyleManager.
virtual ~LwpSilverBullet() override
LwpPara * GetBulletPara()
: Get the LwpPara object through story id.
sal_uInt8 m_pResetPositionFlags[MAXNUMBERPOSITIONS]
OUString GetBulletFontName()
: Get the font name of the bullet.
LwpObjectID m_aStory
sal_uInt16 m_pHideLevels[10]
sal_uInt32 m_nUseCount
static OUString GetNumCharByStyleID(LwpFribParaNumber const *pParaNumber)
: Get numbering character of the bullet vo_para.
OUString GetDivisionName()
LwpSilverBullet(LwpObjectHeader const &objHdr, LwpSvStream *pStrm)
LwpAtomHolder m_aAtomHolder
sal_uInt16 GetDisplayLevel(sal_uInt8 nPos)
: Calculate the displaylevel according to the position and hidelevels.
bool IsBulletOrdered()
: To judge the silverbullet list is ordered or not.
OUString GetAdditionalName(sal_uInt8 nPos)
@descr: Get the additional information, "Division name" or "Section Name" from document variable frib...
OUString GetSectionName() const
const OUString & GetSectionName() const
Definition: lwpstory.hxx:116
LwpObjectID & GetFirstPara()
Definition: lwpstory.hxx:139
encapsulate XInputStream to provide SvStream like interfaces
Definition: lwpsvstream.hxx:69
sal_uInt16 GetHideLevels() const
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)
float u
sal_Int32 m_nFlags
sal_uInt16 nPos
@ VO_PARA
Definition: lwpdefs.hxx:70
@ VO_STORY
Definition: lwpdefs.hxx:72
@ VO_DIVISIONINFO
Definition: lwpdefs.hxx:78
@ FRIB_TAG_DOCVAR
@ FRIB_TAG_PARANUMBER
const sal_uInt16 NUMCHAR_A
const sal_uInt16 NUMCHAR_i
const sal_uInt16 NUMCHAR_Chinese1
const sal_uInt16 NUMCHAR_Chinese4
const sal_uInt16 NUMCHAR_a
const sal_uInt16 NUMCHAR_Chinese3
const sal_uInt16 NUMCHAR_none
const sal_uInt16 NUMCHAR_01
const sal_uInt16 NUMCHAR_I
const sal_uInt16 NUMCHAR_Chinese2
const sal_uInt16 NUMCHAR_1
const sal_uInt16 NUMCHAR_other
#define SAL_N_ELEMENTS(arr)
QPRO_FUNC_TYPE nType
IXFStyle * m_pStyle
Definition: xfstylecont.hxx:71
LwpTextAttributeOverride aTxtAttrOverride
Definition: lwpfrib.hxx:77
sal_uInt16 nNumLevel
Definition: lwppara.hxx:119
void clear()
Definition: lwppara.hxx:126
LwpFribParaNumber * pParaNumber
Definition: lwppara.hxx:116
LwpFribText * pPrefix
Definition: lwppara.hxx:115
LwpFribText * pSuffix
Definition: lwppara.hxx:117
unsigned char sal_uInt8
sal_uInt16 sal_Unicode