cURL: follow redirects
[LibreOffice.git] / lotuswordpro / source / filter / lwpsilverbullet.cxx
blob4446aedb685283a0a2ca8175724c1e4c050aae16
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()
83 void LwpSilverBullet::Read()
85 LwpDLNFVList::Read();
87 m_nFlags = m_pObjStrm->QuickReaduInt16();
88 m_aStory.ReadIndexed(m_pObjStrm.get());
90 sal_uInt16 nNumPos = m_pObjStrm->QuickReaduInt16();
92 if (nNumPos > SAL_N_ELEMENTS(m_pResetPositionFlags))
93 throw std::range_error("corrupt SilverBullet");
95 for (sal_uInt16 nC = 0; nC < nNumPos; nC++)
96 m_pResetPositionFlags[nC] = m_pObjStrm->QuickReaduInt8();
98 m_nUseCount = m_pObjStrm->QuickReaduInt32();
100 m_pAtomHolder->Read(m_pObjStrm.get());
104 * @short: Register bullet or numbering style-list and store the returned
105 * name from XFStyleManager.
106 * @descr:
108 void LwpSilverBullet::RegisterStyle()
110 XFListStyle* pListStyle = new XFListStyle();
111 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
113 GetBulletPara();
115 if (IsBulletOrdered() && HasName())
117 //todo: find the flag in the file
118 bool bCumulative = false;
120 for (sal_uInt8 nPos = 1; nPos < 10; nPos++)
122 ParaNumbering aParaNumbering;
123 //get numbering format according to the position.
124 m_xBulletPara->GetParaNumber(nPos, &aParaNumbering);
125 LwpFribParaNumber* pParaNumber = aParaNumbering.pParaNumber;
126 if (pParaNumber)
128 if (pParaNumber->GetStyleID() != NUMCHAR_other)
130 m_pHideLevels[nPos] = aParaNumbering.nNumLevel;
131 sal_uInt16 nDisplayLevel = GetDisplayLevel(nPos);
132 bCumulative = (nDisplayLevel > 1);
133 OUString aPrefix = GetAdditionalName(nPos);
135 XFNumFmt aFmt;
136 if (!bCumulative && aParaNumbering.pPrefix)
138 aFmt.SetPrefix(aPrefix + aParaNumbering.pPrefix->GetText());
141 aFmt.SetFormat(GetNumCharByStyleID(pParaNumber));
143 if (aParaNumbering.pSuffix)
145 aFmt.SetSuffix(aParaNumbering.pSuffix->GetText());
148 //set numbering format into the style-list.
149 pListStyle->SetListNumber(nPos, aFmt, pParaNumber->GetStart()+1);
151 if (bCumulative && nPos > 1)
153 pListStyle->SetDisplayLevel(nPos, nDisplayLevel);
157 else
159 OUString aPrefix, aSuffix;
160 if (aParaNumbering.pPrefix)
162 aPrefix = aParaNumbering.pPrefix->GetText();
164 if (aParaNumbering.pSuffix)
166 aSuffix = aParaNumbering.pSuffix->GetText();
169 pListStyle->SetListBullet(nPos, GetNumCharByStyleID(pParaNumber),
170 "Times New Roman", aPrefix, aSuffix);
173 pListStyle->SetListPosition(nPos, 0.0, 0.635, 0.0);
174 aParaNumbering.clear();
179 //add style-list to style manager.
180 m_strStyleName = pXFStyleManager->AddStyle(pListStyle).m_pStyle->GetStyleName();
184 * @short: Get the font name of the bullet.
185 * @descr:
186 * @return: Font name of the bullet.
188 OUString LwpSilverBullet::GetBulletFontName()
190 //foundry has been set?
191 if (!m_pFoundry)
193 return OUString();
196 LwpFontManager& rFontMgr = m_pFoundry->GetFontManger();
198 sal_uInt32 nBulletFontID = m_xBulletPara->GetBulletFontID();
199 sal_uInt16 nFinalFont = static_cast<sal_uInt16>((nBulletFontID >> 16) & 0xFFFF);
201 //final fontid is valid?
202 if (nFinalFont > 255 || nFinalFont == 0)
204 return OUString();
207 //get font name from font manager.
208 OUString aFontName = rFontMgr.GetNameByID(nBulletFontID);
210 return aFontName;
213 * @short: Get bullet character of the bullet vo_para.
214 * @descr:
215 * @return: An UChar32 bulle character.
217 OUString LwpSilverBullet::GetBulletChar()
219 return m_xBulletPara->GetBulletChar();
223 * @short: Get the LwpPara object through story id.
225 LwpPara* LwpSilverBullet::GetBulletPara()
227 if (!m_xBulletPara.is())
229 LwpStory* pStory = dynamic_cast<LwpStory*>(m_aStory.obj(VO_STORY).get());
230 if (!pStory)
232 return nullptr;
235 m_xBulletPara.set(dynamic_cast<LwpPara*>(pStory->GetFirstPara().obj(VO_PARA).get()));
238 return m_xBulletPara.get();
242 * @short: Get numbering character of the bullet vo_para.
243 * @descr:
244 * @param: pParaNumber a pointer to the structure LwpFribParaNumber which
245 * includes numbering prefix, format and suffix.
246 * @return: An OUString object which store the numbering character.
248 OUString LwpSilverBullet::GetNumCharByStyleID(LwpFribParaNumber* pParaNumber)
250 if (!pParaNumber)
252 assert(false);
253 return OUString();
256 OUString strNumChar("1");
257 sal_uInt16 nStyleID = pParaNumber->GetStyleID();
259 switch (nStyleID)
261 case NUMCHAR_1:
262 case NUMCHAR_01:
263 case NUMCHAR_Chinese4:
264 strNumChar = "1";
265 break;
266 case NUMCHAR_A :
267 strNumChar = "A";
268 break;
269 case NUMCHAR_a:
270 strNumChar = "a";
271 break;
272 case NUMCHAR_I:
273 strNumChar = "I";
274 break;
275 case NUMCHAR_i:
276 strNumChar = "i";
277 break;
278 case NUMCHAR_other:
279 strNumChar = OUString(sal_Unicode(pParaNumber->GetNumberChar()));
280 break;
281 case NUMCHAR_Chinese1:
283 sal_Unicode sBuf[13] = {0x58f9,0x002c,0x0020,0x8d30,0x002c,0x0020,0x53c1,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
284 strNumChar = OUString(sBuf);
286 break;
287 case NUMCHAR_Chinese2:
289 sal_Unicode sBuf[13] = {0x4e00,0x002c,0x0020,0x4e8c,0x002c,0x0020,0x4e09,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
290 strNumChar = OUString(sBuf);
292 break;
293 case NUMCHAR_Chinese3:
295 sal_Unicode sBuf[13] = {0x7532,0x002c,0x0020,0x4e59,0x002c,0x0020,0x4e19,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
296 strNumChar = OUString(sBuf);
298 break;
299 case NUMCHAR_none:
300 strNumChar.clear();
301 break;
302 default:
303 break;
304 }//mod end
305 return strNumChar;
309 * @short: To judge the silverbullet list is ordered or not.
310 * @descr:
311 * @return: sal_True if list is ordered, sal_False if list is unordered.
313 bool LwpSilverBullet::IsBulletOrdered()
315 if (!m_xBulletPara.is())
316 return false;
318 LwpFribPtr& rFribs = m_xBulletPara->GetFribs();
320 return (rFribs.HasFrib(FRIB_TAG_PARANUMBER) != nullptr);
324 * @short: Calculate the displaylevel according to the position and hidelevels.
325 * @descr:
326 * @param: nPos position of the numbering.
327 * @return: displaylevel of the position passed in.
329 sal_uInt16 LwpSilverBullet::GetDisplayLevel(sal_uInt8 nPos)
331 if (nPos > 1)
333 sal_uInt16 nHideBit = (1 << nPos);
334 for (sal_uInt8 nC = nPos-1; nC > 0; nC--)
336 sal_uInt16 nAttrMask = ~m_pHideLevels[nC];
337 if (!(nAttrMask & nHideBit))
339 return static_cast<sal_uInt16>(nPos - nC);
344 return static_cast<sal_uInt16>(nPos);
348 * @descr: Get the additional information, "Division name" or "Section Name" from document
349 * variable frib according to numbering position. Whether we should add a
350 * Division/Section name or not is determined by the hidelevels of the frib.
351 * @param: nPos position of the numbering.
352 * @return: Division or Section name.
354 OUString LwpSilverBullet::GetAdditionalName(sal_uInt8 nPos)
356 OUString aRet;
357 sal_uInt16 nHideBit = (1 << nPos);
358 bool bDivisionName = false;
359 bool bSectionName = false;
361 LwpFrib* pParaFrib = m_xBulletPara->GetFribs().GetFribs();
362 if (!pParaFrib)
364 return OUString();
367 while (pParaFrib)
369 if (pParaFrib->GetType() == FRIB_TAG_DOCVAR)
371 ModifierInfo* pMoInfo = pParaFrib->GetModifiers();
372 if (!pMoInfo)
374 return OUString();
376 sal_uInt16 nHideLevels = pMoInfo->aTxtAttrOverride.GetHideLevels();
377 sal_uInt16 nType = static_cast<LwpFribDocVar*>(pParaFrib)->GetType();
379 if (~nHideLevels & nHideBit)
381 if (nType == 0x000D)
383 bDivisionName = true;
385 else if (nType == 0x000E)
387 bSectionName= true;
391 pParaFrib = pParaFrib->GetNext();
394 if (bDivisionName)
396 aRet += GetDivisionName();
398 if (bSectionName)
400 aRet += GetSectionName();
403 return aRet;
406 OUString LwpSilverBullet::GetDivisionName()
408 OUString aRet;
410 if (!m_pFoundry)
412 return aRet;
415 LwpDocument* pDoc = m_pFoundry->GetDocument();
416 if (pDoc)
418 LwpObjectID& rID = pDoc->GetDivInfoID();
419 if (!rID.IsNull())
421 LwpDivInfo *pInfo = dynamic_cast<LwpDivInfo*>(rID.obj(VO_DIVISIONINFO).get());
422 if (pInfo)
423 aRet = pInfo->GetDivName();
427 return aRet;
430 OUString LwpSilverBullet::GetSectionName()
432 LwpStory* pStory = dynamic_cast<LwpStory*>(m_aStory.obj(VO_STORY).get());
433 if (!pStory)
435 return OUString();
438 return pStory->GetSectionName();
441 bool LwpSilverBullet::HasName()
443 LwpAtomHolder& rName = GetName();
444 return (!rName.str().isEmpty());
446 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */