Branch data Line data Source code
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 : : * Change History
62 : : Jan 2005 Created
63 : : ************************************************************************/
64 : : #include "lwpglobalmgr.hxx"
65 : : #include "lwpsilverbullet.hxx"
66 : : #include "lwpdoc.hxx"
67 : : #include "lwpdivinfo.hxx"
68 : : #include "lwpfoundry.hxx"
69 : : #include "lwpstory.hxx"
70 : : #include "lwppara.hxx"
71 : : #include "xfilter/xfliststyle.hxx"
72 : : #include "xfilter/xfstylemanager.hxx"
73 : :
74 : 39 : LwpSilverBullet::LwpSilverBullet(LwpObjectHeader& objHdr, LwpSvStream* pStrm)
75 [ + - ][ + - ]: 39 : : LwpDLNFVList(objHdr, pStrm), m_pAtomHolder(new LwpAtomHolder), m_pBulletPara(NULL)
[ + - ]
76 : : {
77 : 39 : }
78 : :
79 : 39 : LwpSilverBullet::~LwpSilverBullet()
80 : : {
81 [ + - ]: 39 : if (m_pAtomHolder)
82 : : {
83 [ + - ][ + - ]: 39 : delete m_pAtomHolder;
84 : : }
85 [ - + ]: 78 : }
86 : :
87 : 39 : void LwpSilverBullet::Read()
88 : : {
89 : 39 : LwpDLNFVList::Read();
90 : :
91 : 39 : m_nFlags = m_pObjStrm->QuickReaduInt16();
92 : 39 : m_aStory.ReadIndexed(m_pObjStrm);
93 : :
94 : 39 : sal_uInt16 nNumPos = m_pObjStrm->QuickReaduInt16();
95 : :
96 [ + + ]: 429 : for (sal_uInt8 nC = 0; nC < nNumPos; nC++)
97 : 390 : m_pResetPositionFlags[nC] = m_pObjStrm->QuickReaduInt8();
98 : :
99 : 39 : m_nUseCount = m_pObjStrm->QuickReaduInt32();
100 : :
101 : 39 : m_pAtomHolder->Read(m_pObjStrm);
102 : 39 : }
103 : :
104 : : /**
105 : : * @short: Register bullet or numbering style-list and store the returned
106 : : * name from XFStyleManager.
107 : : * @descr:
108 : : */
109 : 39 : void LwpSilverBullet::RegisterStyle()
110 : : {
111 [ + - ]: 39 : XFListStyle* pListStyle = new XFListStyle();
112 : 39 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
113 : :
114 : 39 : this->GetBulletPara();
115 : :
116 [ + + ][ + + ]: 39 : if (this->IsBulletOrdered() && this->HasName())
[ + - ]
117 : : {
118 : : //todo: find the flag in the file
119 : 36 : sal_Bool bCumulative = sal_False;
120 : :
121 [ + + ]: 360 : for (sal_uInt8 nPos = 1; nPos < 10; nPos++)
122 : : {
123 [ + - ]: 324 : ParaNumbering aParaNumbering;
124 : : //get numbering format according to the position.
125 [ + - ]: 324 : m_pBulletPara->GetParaNumber(nPos, &aParaNumbering);
126 : 324 : LwpFribParaNumber* pParaNumber = aParaNumbering.pParaNumber;
127 [ + - ]: 324 : if (pParaNumber)
128 : : {
129 [ + - ]: 324 : if (pParaNumber->GetStyleID() != NUMCHAR_other)
130 : : {
131 : 324 : m_pHideLevels[nPos] = aParaNumbering.nNumLevel;
132 : 324 : sal_uInt16 nDisplayLevel = this->GetDisplayLevel(nPos);
133 : 324 : bCumulative = (sal_Bool)(nDisplayLevel > 1);
134 [ + - ]: 324 : rtl::OUString aPrefix = this->GetAdditionalName(nPos);
135 : :
136 : 324 : XFNumFmt aFmt;
137 [ + + ][ + + ]: 324 : if (!bCumulative && aParaNumbering.pPrefix)
138 : : {
139 : 12 : aFmt.SetPrefix(aPrefix + aParaNumbering.pPrefix->GetText());
140 : : }
141 : :
142 [ + - ]: 324 : aFmt.SetFormat(this->GetNumCharByStyleID(pParaNumber));
143 : :
144 [ + + ]: 324 : if (aParaNumbering.pSuffix)
145 : : {
146 : 120 : aFmt.SetSuffix(aParaNumbering.pSuffix->GetText());
147 : : }
148 : :
149 : : //set numbering format into the style-list.
150 [ + - ]: 324 : pListStyle->SetListNumber(nPos, aFmt, pParaNumber->GetStart()+1);
151 : :
152 [ + + ][ + - ]: 324 : if (bCumulative && nPos > 1)
153 : : {
154 [ + - ]: 192 : pListStyle->SetDisplayLevel(nPos, nDisplayLevel);
155 : 324 : }
156 : :
157 : : }
158 : : else
159 : : {
160 : 0 : rtl::OUString aPrefix, aSuffix;
161 [ # # ]: 0 : if (aParaNumbering.pPrefix)
162 : : {
163 : 0 : aPrefix = aParaNumbering.pPrefix->GetText();
164 : : }
165 [ # # ]: 0 : if (aParaNumbering.pSuffix)
166 : : {
167 : 0 : aSuffix = aParaNumbering.pSuffix->GetText();
168 : : }
169 : :
170 [ # # ]: 0 : pListStyle->SetListBullet(nPos, this->GetNumCharByStyleID(pParaNumber).toChar(),
171 [ # # ]: 0 : rtl::OUString("Times New Roman"), aPrefix, aSuffix);
172 : : }
173 : :
174 [ + - ]: 324 : pListStyle->SetListPosition(nPos, 0.0, 0.635, 0.0);
175 : 324 : aParaNumbering.clear();
176 : : }
177 : : }
178 : : }
179 : :
180 : : //add style-list to style manager.
181 : 39 : m_strStyleName = pXFStyleManager->AddStyle(pListStyle)->GetStyleName();
182 : 39 : }
183 : :
184 : : /**
185 : : * @short: Get the font name of the bullet.
186 : : * @descr:
187 : : * @return: Font name of the bullet.
188 : : */
189 : 0 : rtl::OUString LwpSilverBullet::GetBulletFontName()
190 : : {
191 : 0 : rtl::OUString aEmpty;
192 : :
193 : : //foundry has been set?
194 [ # # ]: 0 : if (!m_pFoundry)
195 : : {
196 : 0 : return aEmpty;
197 : : }
198 : :
199 : 0 : LwpFontManager* pFontMgr = m_pFoundry->GetFontManger();
200 [ # # ]: 0 : if (!pFontMgr)
201 : : {
202 : 0 : return aEmpty;
203 : : }
204 : :
205 : 0 : sal_uInt32 nBulletFontID = m_pBulletPara->GetBulletFontID();
206 : 0 : sal_uInt16 nFinalFont = static_cast<sal_uInt16>((nBulletFontID >> 16) & 0xFFFF);
207 : :
208 : : //final fontid is valid?
209 [ # # ][ # # ]: 0 : if (nFinalFont > 255 || nFinalFont == 0)
210 : : {
211 : 0 : return aEmpty;
212 : : }
213 : :
214 : : //get font name from font manager.
215 [ # # ]: 0 : rtl::OUString aFontName = pFontMgr->GetNameByID(nBulletFontID);
216 : :
217 : 0 : return aFontName;
218 : : }
219 : : /**
220 : : * @short: Get bullet character of the bullet vo_para.
221 : : * @descr:
222 : : * @return: An UChar32 bulle character.
223 : : */
224 : 0 : UChar32 LwpSilverBullet::GetBulletChar()
225 : : {
226 : 0 : rtl::OUString aBulletChar = m_pBulletPara->GetBulletChar();
227 : :
228 : 0 : return aBulletChar.toChar();
229 : : }
230 : :
231 : : /**
232 : : * @short: Get the LwpPara object through story id.
233 : : */
234 : 45 : LwpPara* LwpSilverBullet::GetBulletPara()
235 : : {
236 [ + + ]: 45 : if (!m_pBulletPara)
237 : : {
238 [ - + ]: 39 : LwpStory* pStory = dynamic_cast<LwpStory*>(m_aStory.obj(VO_STORY));
239 [ - + ]: 39 : if (!pStory)
240 : : {
241 : 0 : return NULL;
242 : : }
243 : :
244 [ - + ]: 39 : m_pBulletPara = dynamic_cast<LwpPara*>(pStory->GetFirstPara()->obj(VO_PARA));
245 : : }
246 : :
247 : 45 : return m_pBulletPara;
248 : : }
249 : :
250 : : /**
251 : : * @short: Get numbering character of the bullet vo_para.
252 : : * @descr:
253 : : * @param: pParaNumber a pionter to the structure LwpFribParaNumber which
254 : : * includes numbering prefix, format and suffix.
255 : : * @return: An OUString object which store the numbering character.
256 : : */
257 : 351 : rtl::OUString LwpSilverBullet::GetNumCharByStyleID(LwpFribParaNumber* pParaNumber)
258 : : {
259 : 351 : rtl::OUString aEmpty;
260 : :
261 [ - + ]: 351 : if (!pParaNumber)
262 : : {
263 : : assert(false);
264 : 0 : return aEmpty;
265 : : }
266 : :
267 : 351 : rtl::OUString strNumChar("1");
268 : 351 : sal_uInt16 nStyleID = pParaNumber->GetStyleID();
269 : 351 : UChar32 uC = 0x0000;
270 : :
271 [ + + + + : 351 : switch (nStyleID)
+ - - - -
- - ]
272 : : {
273 : : case NUMCHAR_1:
274 : : case NUMCHAR_01:
275 : : case NUMCHAR_Chinese4:
276 : 279 : strNumChar = rtl::OUString("1");
277 : 279 : break;
278 : : case NUMCHAR_A :
279 : 12 : strNumChar = rtl::OUString("A");
280 : 12 : break;
281 : : case NUMCHAR_a:
282 : 24 : strNumChar = rtl::OUString("a");
283 : 24 : break;
284 : : case NUMCHAR_I:
285 : 12 : strNumChar = rtl::OUString("I");
286 : 12 : break;
287 : : case NUMCHAR_i:
288 : 24 : strNumChar = rtl::OUString("i");
289 : 24 : break;
290 : : case NUMCHAR_other:
291 : 0 : uC = static_cast<UChar32>(pParaNumber->GetNumberChar());
292 : 0 : strNumChar = rtl::OUString(uC);
293 : 0 : break;
294 : : case NUMCHAR_Chinese1:
295 : : {
296 : 0 : sal_Unicode sBuf[13] = {0x58f9,0x002c,0x0020,0x8d30,0x002c,0x0020,0x53c1,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
297 : 0 : strNumChar = rtl::OUString(sBuf);
298 : : }
299 : 0 : break;
300 : : case NUMCHAR_Chinese2:
301 : : {
302 : 0 : sal_Unicode sBuf[13] = {0x4e00,0x002c,0x0020,0x4e8c,0x002c,0x0020,0x4e09,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
303 : 0 : strNumChar = rtl::OUString(sBuf);
304 : : }
305 : 0 : break;
306 : : case NUMCHAR_Chinese3:
307 : : {
308 : 0 : sal_Unicode sBuf[13] = {0x7532,0x002c,0x0020,0x4e59,0x002c,0x0020,0x4e19,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
309 : 0 : strNumChar = rtl::OUString(sBuf);
310 : : }
311 : 0 : break;
312 : : case NUMCHAR_none:
313 : 0 : strNumChar = aEmpty;
314 : 0 : break;
315 : : default:
316 : 0 : break;
317 : : }//mod end
318 : 351 : return strNumChar;
319 : : }
320 : :
321 : : /**
322 : : * @short: To judge the silverbullet list is ordered or not.
323 : : * @descr:
324 : : * @return: sal_True if list is ordered, sal_False if list is unordered.
325 : : */
326 : 72 : sal_Bool LwpSilverBullet::IsBulletOrdered()
327 : : {
328 [ - + ]: 72 : if (!m_pBulletPara)
329 : 0 : return sal_False;
330 : :
331 : 72 : LwpFribPtr* pFribs = m_pBulletPara->GetFribs();
332 : :
333 [ - + ]: 72 : if (!pFribs)
334 : 0 : return sal_False;
335 : :
336 : 72 : return (sal_Bool)(pFribs->HasFrib(FRIB_TAG_PARANUMBER) != NULL);
337 : : }
338 : :
339 : : /**
340 : : * @short: Calculate the displaylevel according to the position and hidelevels.
341 : : * @descr:
342 : : * @param: nPos position of the numbering.
343 : : * @return: displaylevel of the position passed in.
344 : : */
345 : 324 : sal_uInt16 LwpSilverBullet::GetDisplayLevel(sal_uInt8 nPos)
346 : : {
347 [ + + ]: 324 : if (nPos > 1)
348 : : {
349 : 288 : sal_uInt16 nHideBit = (1 << nPos);
350 [ + + ]: 1152 : for (sal_uInt8 nC = nPos-1; nC > 0; nC--)
351 : : {
352 : 960 : sal_uInt16 nAttrMask = ~m_pHideLevels[nC];
353 [ + + ]: 960 : if (!(nAttrMask & nHideBit))
354 : : {
355 : 96 : return static_cast<sal_uInt16>(nPos - nC);
356 : : }
357 : : }
358 : : }
359 : :
360 : 324 : return static_cast<sal_uInt16>(nPos);
361 : : }
362 : :
363 : : /**
364 : : * @descr: Get the additional information, "Division name" or "Section Name" from document
365 : : * variable frib according to numbering position. Whether we should add a
366 : : * Division/Section name or not is determined by the hidelevels of the frib.
367 : : * @param: nPos position of the numbering.
368 : : * @return: Division or Section name.
369 : : */
370 : 324 : rtl::OUString LwpSilverBullet::GetAdditionalName(sal_uInt8 nPos)
371 : : {
372 : 324 : rtl::OUString aRet, aEmpty;
373 : 324 : sal_uInt16 nHideBit = (1 << nPos);
374 : 324 : sal_Bool bDivisionName = sal_False;
375 : 324 : sal_Bool bSectionName = sal_False;
376 : :
377 : 324 : LwpFrib* pParaFrib = m_pBulletPara->GetFribs()->GetFribs();
378 [ - + ]: 324 : if (!pParaFrib)
379 : : {
380 : 0 : return aEmpty;
381 : : }
382 : :
383 [ + + ]: 6480 : while (pParaFrib)
384 : : {
385 [ - + ]: 6156 : if (pParaFrib->GetType() == FRIB_TAG_DOCVAR)
386 : : {
387 : 0 : ModifierInfo* pMoInfo = pParaFrib->GetModifiers();
388 [ # # ]: 0 : if (!pMoInfo)
389 : : {
390 : 0 : return aEmpty;
391 : : }
392 : 0 : sal_uInt16 nHideLevels = pMoInfo->aTxtAttrOverride.GetHideLevels();
393 : 0 : sal_uInt16 nType = static_cast<LwpFribDocVar*>(pParaFrib)->GetType();
394 : :
395 [ # # ]: 0 : if (~nHideLevels & nHideBit)
396 : : {
397 [ # # ]: 0 : if (nType == 0x000D)
398 : : {
399 : 0 : bDivisionName = sal_True;
400 : : }
401 [ # # ]: 0 : else if (nType == 0x000E)
402 : : {
403 : 0 : bSectionName= sal_True;
404 : : }
405 : : }
406 : : }
407 : 6156 : pParaFrib = pParaFrib->GetNext();
408 : : }
409 : :
410 [ - + ]: 324 : if (bDivisionName)
411 : : {
412 [ # # ]: 0 : aRet += this->GetDivisionName();
413 : : }
414 [ - + ]: 324 : if (bSectionName)
415 : : {
416 [ # # ]: 0 : aRet += this->GetSectionName();
417 : : }
418 : :
419 : 324 : return aRet;
420 : : }
421 : :
422 : 0 : rtl::OUString LwpSilverBullet::GetDivisionName()
423 : : {
424 : 0 : rtl::OUString aRet;
425 : :
426 [ # # ]: 0 : if (!m_pFoundry)
427 : : {
428 : 0 : return aRet;
429 : : }
430 : :
431 : 0 : LwpDocument* pDoc = m_pFoundry->GetDocument();
432 [ # # ]: 0 : if (pDoc)
433 : : {
434 : 0 : LwpObjectID* pID = pDoc->GetDivInfoID();
435 [ # # ]: 0 : if (!pID->IsNull())
436 : : {
437 [ # # ][ # # ]: 0 : LwpDivInfo *pInfo = dynamic_cast<LwpDivInfo*>(pID->obj(VO_DIVISIONINFO));
438 [ # # ]: 0 : if (pInfo)
439 : 0 : aRet = pInfo->GetDivName();
440 : : }
441 : : }
442 : :
443 : 0 : return aRet;
444 : : }
445 : :
446 : 0 : rtl::OUString LwpSilverBullet::GetSectionName()
447 : : {
448 : 0 : rtl::OUString aEmpty;
449 [ # # ][ # # ]: 0 : LwpStory* pStory = dynamic_cast<LwpStory*>(m_aStory.obj(VO_STORY));
450 [ # # ]: 0 : if (!pStory)
451 : : {
452 : 0 : return aEmpty;
453 : : }
454 : :
455 : 0 : return pStory->GetSectionName();
456 : : }
457 : :
458 : 72 : sal_Bool LwpSilverBullet::HasName()
459 : : {
460 : 72 : LwpAtomHolder* pName = this->GetName();
461 [ + - ]: 72 : if (pName)
462 : : {
463 : 72 : return (sal_Bool)(!pName->str().isEmpty());
464 : : }
465 : : else
466 : : {
467 : 72 : return sal_False;
468 : : }
469 : : }
470 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|