Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / lotuswordpro / source / filter / lwpsilverbullet.cxx
blob497330460ea8bb047b50e1d4342eced361e0e26c
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,
29 * MA 02111-1307 USA
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 /*************************************************************************
57 * @file
58 * For LWP filter architecture prototype
59 ************************************************************************/
61 #include "lwpglobalmgr.hxx"
62 #include "lwpsilverbullet.hxx"
63 #include "lwpdoc.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)
73 , m_nFlags(0)
74 , m_nUseCount(0)
75 , m_pAtomHolder(new LwpAtomHolder)
79 LwpSilverBullet::~LwpSilverBullet()
81 delete m_pAtomHolder;
84 void LwpSilverBullet::Read()
86 LwpDLNFVList::Read();
88 m_nFlags = m_pObjStrm->QuickReaduInt16();
89 m_aStory.ReadIndexed(m_pObjStrm);
91 sal_uInt16 nNumPos = m_pObjStrm->QuickReaduInt16();
93 if (nNumPos > SAL_N_ELEMENTS(m_pResetPositionFlags))
94 throw std::range_error("corrupt SilverBullet");
96 for (sal_uInt16 nC = 0; nC < nNumPos; nC++)
97 m_pResetPositionFlags[nC] = m_pObjStrm->QuickReaduInt8();
99 m_nUseCount = m_pObjStrm->QuickReaduInt32();
101 m_pAtomHolder->Read(m_pObjStrm);
105 * @short: Register bullet or numbering style-list and store the returned
106 * name from XFStyleManager.
107 * @descr:
109 void LwpSilverBullet::RegisterStyle()
111 XFListStyle* pListStyle = new XFListStyle();
112 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
114 GetBulletPara();
116 if (IsBulletOrdered() && HasName())
118 //todo: find the flag in the file
119 bool bCumulative = false;
121 for (sal_uInt8 nPos = 1; nPos < 10; nPos++)
123 ParaNumbering aParaNumbering;
124 //get numbering format according to the position.
125 m_xBulletPara->GetParaNumber(nPos, &aParaNumbering);
126 LwpFribParaNumber* pParaNumber = aParaNumbering.pParaNumber;
127 if (pParaNumber)
129 if (pParaNumber->GetStyleID() != NUMCHAR_other)
131 m_pHideLevels[nPos] = aParaNumbering.nNumLevel;
132 sal_uInt16 nDisplayLevel = GetDisplayLevel(nPos);
133 bCumulative = (nDisplayLevel > 1);
134 OUString aPrefix = GetAdditionalName(nPos);
136 XFNumFmt aFmt;
137 if (!bCumulative && aParaNumbering.pPrefix)
139 aFmt.SetPrefix(aPrefix + aParaNumbering.pPrefix->GetText());
142 aFmt.SetFormat(GetNumCharByStyleID(pParaNumber));
144 if (aParaNumbering.pSuffix)
146 aFmt.SetSuffix(aParaNumbering.pSuffix->GetText());
149 //set numbering format into the style-list.
150 pListStyle->SetListNumber(nPos, aFmt, pParaNumber->GetStart()+1);
152 if (bCumulative && nPos > 1)
154 pListStyle->SetDisplayLevel(nPos, nDisplayLevel);
158 else
160 OUString aPrefix, aSuffix;
161 if (aParaNumbering.pPrefix)
163 aPrefix = aParaNumbering.pPrefix->GetText();
165 if (aParaNumbering.pSuffix)
167 aSuffix = aParaNumbering.pSuffix->GetText();
170 pListStyle->SetListBullet(nPos, GetNumCharByStyleID(pParaNumber),
171 "Times New Roman", aPrefix, aSuffix);
174 pListStyle->SetListPosition(nPos, 0.0, 0.635, 0.0);
175 aParaNumbering.clear();
180 //add style-list to style manager.
181 m_strStyleName = pXFStyleManager->AddStyle(pListStyle).m_pStyle->GetStyleName();
185 * @short: Get the font name of the bullet.
186 * @descr:
187 * @return: Font name of the bullet.
189 OUString LwpSilverBullet::GetBulletFontName()
191 //foundry has been set?
192 if (!m_pFoundry)
194 return OUString();
197 LwpFontManager& rFontMgr = m_pFoundry->GetFontManger();
199 sal_uInt32 nBulletFontID = m_xBulletPara->GetBulletFontID();
200 sal_uInt16 nFinalFont = static_cast<sal_uInt16>((nBulletFontID >> 16) & 0xFFFF);
202 //final fontid is valid?
203 if (nFinalFont > 255 || nFinalFont == 0)
205 return OUString();
208 //get font name from font manager.
209 OUString aFontName = rFontMgr.GetNameByID(nBulletFontID);
211 return aFontName;
214 * @short: Get bullet character of the bullet vo_para.
215 * @descr:
216 * @return: An UChar32 bulle character.
218 OUString LwpSilverBullet::GetBulletChar()
220 return m_xBulletPara->GetBulletChar();
224 * @short: Get the LwpPara object through story id.
226 LwpPara* LwpSilverBullet::GetBulletPara()
228 if (!m_xBulletPara.is())
230 LwpStory* pStory = dynamic_cast<LwpStory*>(m_aStory.obj(VO_STORY).get());
231 if (!pStory)
233 return nullptr;
236 m_xBulletPara.set(dynamic_cast<LwpPara*>(pStory->GetFirstPara().obj(VO_PARA).get()));
239 return m_xBulletPara.get();
243 * @short: Get numbering character of the bullet vo_para.
244 * @descr:
245 * @param: pParaNumber a pointer to the structure LwpFribParaNumber which
246 * includes numbering prefix, format and suffix.
247 * @return: An OUString object which store the numbering character.
249 OUString LwpSilverBullet::GetNumCharByStyleID(LwpFribParaNumber* pParaNumber)
251 if (!pParaNumber)
253 assert(false);
254 return OUString();
257 OUString strNumChar("1");
258 sal_uInt16 nStyleID = pParaNumber->GetStyleID();
260 switch (nStyleID)
262 case NUMCHAR_1:
263 case NUMCHAR_01:
264 case NUMCHAR_Chinese4:
265 strNumChar = "1";
266 break;
267 case NUMCHAR_A :
268 strNumChar = "A";
269 break;
270 case NUMCHAR_a:
271 strNumChar = "a";
272 break;
273 case NUMCHAR_I:
274 strNumChar = "I";
275 break;
276 case NUMCHAR_i:
277 strNumChar = "i";
278 break;
279 case NUMCHAR_other:
280 strNumChar = OUString(sal_Unicode(pParaNumber->GetNumberChar()));
281 break;
282 case NUMCHAR_Chinese1:
284 sal_Unicode sBuf[13] = {0x58f9,0x002c,0x0020,0x8d30,0x002c,0x0020,0x53c1,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
285 strNumChar = OUString(sBuf);
287 break;
288 case NUMCHAR_Chinese2:
290 sal_Unicode sBuf[13] = {0x4e00,0x002c,0x0020,0x4e8c,0x002c,0x0020,0x4e09,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
291 strNumChar = OUString(sBuf);
293 break;
294 case NUMCHAR_Chinese3:
296 sal_Unicode sBuf[13] = {0x7532,0x002c,0x0020,0x4e59,0x002c,0x0020,0x4e19,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
297 strNumChar = OUString(sBuf);
299 break;
300 case NUMCHAR_none:
301 strNumChar.clear();
302 break;
303 default:
304 break;
305 }//mod end
306 return strNumChar;
310 * @short: To judge the silverbullet list is ordered or not.
311 * @descr:
312 * @return: sal_True if list is ordered, sal_False if list is unordered.
314 bool LwpSilverBullet::IsBulletOrdered()
316 if (!m_xBulletPara.is())
317 return false;
319 LwpFribPtr& rFribs = m_xBulletPara->GetFribs();
321 return (rFribs.HasFrib(FRIB_TAG_PARANUMBER) != nullptr);
325 * @short: Calculate the displaylevel according to the position and hidelevels.
326 * @descr:
327 * @param: nPos position of the numbering.
328 * @return: displaylevel of the position passed in.
330 sal_uInt16 LwpSilverBullet::GetDisplayLevel(sal_uInt8 nPos)
332 if (nPos > 1)
334 sal_uInt16 nHideBit = (1 << nPos);
335 for (sal_uInt8 nC = nPos-1; nC > 0; nC--)
337 sal_uInt16 nAttrMask = ~m_pHideLevels[nC];
338 if (!(nAttrMask & nHideBit))
340 return static_cast<sal_uInt16>(nPos - nC);
345 return static_cast<sal_uInt16>(nPos);
349 * @descr: Get the additional information, "Division name" or "Section Name" from document
350 * variable frib according to numbering position. Whether we should add a
351 * Division/Section name or not is determined by the hidelevels of the frib.
352 * @param: nPos position of the numbering.
353 * @return: Division or Section name.
355 OUString LwpSilverBullet::GetAdditionalName(sal_uInt8 nPos)
357 OUString aRet;
358 sal_uInt16 nHideBit = (1 << nPos);
359 bool bDivisionName = false;
360 bool bSectionName = false;
362 LwpFrib* pParaFrib = m_xBulletPara->GetFribs().GetFribs();
363 if (!pParaFrib)
365 return OUString();
368 while (pParaFrib)
370 if (pParaFrib->GetType() == FRIB_TAG_DOCVAR)
372 ModifierInfo* pMoInfo = pParaFrib->GetModifiers();
373 if (!pMoInfo)
375 return OUString();
377 sal_uInt16 nHideLevels = pMoInfo->aTxtAttrOverride.GetHideLevels();
378 sal_uInt16 nType = static_cast<LwpFribDocVar*>(pParaFrib)->GetType();
380 if (~nHideLevels & nHideBit)
382 if (nType == 0x000D)
384 bDivisionName = true;
386 else if (nType == 0x000E)
388 bSectionName= true;
392 pParaFrib = pParaFrib->GetNext();
395 if (bDivisionName)
397 aRet += GetDivisionName();
399 if (bSectionName)
401 aRet += GetSectionName();
404 return aRet;
407 OUString LwpSilverBullet::GetDivisionName()
409 OUString aRet;
411 if (!m_pFoundry)
413 return aRet;
416 LwpDocument* pDoc = m_pFoundry->GetDocument();
417 if (pDoc)
419 LwpObjectID& rID = pDoc->GetDivInfoID();
420 if (!rID.IsNull())
422 LwpDivInfo *pInfo = dynamic_cast<LwpDivInfo*>(rID.obj(VO_DIVISIONINFO).get());
423 if (pInfo)
424 aRet = pInfo->GetDivName();
428 return aRet;
431 OUString LwpSilverBullet::GetSectionName()
433 LwpStory* pStory = dynamic_cast<LwpStory*>(m_aStory.obj(VO_STORY).get());
434 if (!pStory)
436 return OUString();
439 return pStory->GetSectionName();
442 bool LwpSilverBullet::HasName()
444 LwpAtomHolder& rName = GetName();
445 return (!rName.str().isEmpty());
447 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */