fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / lotuswordpro / source / filter / lwppara1.cxx
blobc6eb252fa047cd93e3e6aa13b45d92d4f1948dcf
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 ************************************************************************/
60 /*************************************************************************
61 * Change History
62 Jan 2005 Created
63 ************************************************************************/
65 #include <memory>
67 #include <boost/cast.hpp>
69 #include "lwppara.hxx"
70 #include "lwpglobalmgr.hxx"
71 #include "lwpfilehdr.hxx"
72 #include "lwpparaproperty.hxx"
73 #include "lwptools.hxx"
74 #include "lwpparastyle.hxx"
75 #include "xfilter/xffont.hxx"
76 #include "xfilter/xftextstyle.hxx"
77 #include "xfilter/xfstylemanager.hxx"
78 #include "xfilter/xfparagraph.hxx"
79 #include "xfilter/xftextcontent.hxx"
80 #include "xfilter/xftextspan.hxx"
81 #include "xfilter/xfmargins.hxx"
82 #include "xfilter/xftabstop.hxx"
83 #include "xfilter/xflinebreak.hxx"
84 #include "xfilter/xfsection.hxx"
85 #include "xfilter/xfsectionstyle.hxx"
86 #include "xfilter/xfcolor.hxx"
87 #include "xfilter/xfhyperlink.hxx"
88 #include "lwpcharsetmgr.hxx"
89 #include "lwpsection.hxx"
90 #include "lwplayout.hxx"
91 #include "lwpusewhen.hxx"
93 #include "lwpbulletstylemgr.hxx"
94 #include "lwpstory.hxx"
95 #include "lwpsilverbullet.hxx"
96 #include "xfilter/xflist.hxx"
97 #include "xfilter/xfframe.hxx"
99 #include "lwpdivinfo.hxx"
100 #include "lwpdoc.hxx"
101 #include "lwpholder.hxx"
102 #include "lwppagehint.hxx"
104 #include "lwpdropcapmgr.hxx"
105 #include "lwptable.hxx"
106 #include "lwpcelllayout.hxx"
108 // boost::polymorphic_downcast checks and reports (using assert), if the
109 // cast is incorrect. We want this in debug builds.
110 #if OSL_DEBUG_LEVEL > 0
111 # undef NDEBUG
112 #elif !defined(NDEBUG)
113 # define NDEBUG 1
114 #endif
116 using boost::polymorphic_downcast;
119 * @short get text of paragraph
121 OUString LwpPara::GetContentText(bool bAllText)
123 // rFont = m_FontID;
124 if (bAllText)
126 m_Fribs.SetPara(this);
127 m_Fribs.GatherAllText();
128 return m_AllText;
130 else
131 return m_Content;
135 * @short set text of paragraph
137 void LwpPara::SetAllText(const OUString& sText)
139 m_AllText+=sText;
143 * @short set first frib content
145 void LwpPara::SetFirstFrib(const OUString& Content,sal_uInt32 FontID)
147 m_FontID= FontID;
148 m_Content=Content;
151 * @short get paragraph xfstyle
153 XFParaStyle* LwpPara::GetXFParaStyle()
155 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
156 return pXFStyleManager->FindParaStyle(m_StyleName);
159 * @short get drop cap info
161 #include "lwpframelayout.hxx"
162 void LwpPara::GatherDropcapInfo()
164 SetDropcapLines(m_pDropcapLayout->GetLines());
165 SetDropcapChars(m_pDropcapLayout->GetChars());
168 * @short get parent paragraph
170 LwpPara* LwpPara::GetParent()
172 LwpPara* pPara;
173 sal_uInt16 otherlevel;
174 sal_uInt16 level = GetLevel();
176 if (level != 1)
178 pPara = dynamic_cast<LwpPara*>(GetPrevious().obj().get());
179 while (pPara)
181 otherlevel = pPara->GetLevel();
182 if ((otherlevel < level) || (otherlevel && (level == 0)))
183 return pPara;
184 pPara = dynamic_cast<LwpPara*>(pPara->GetPrevious().obj().get());
187 return NULL;
191 * @short: Offer prefix, paranumber and suffix according to position.
192 * @param: nPosition index of wanted paranumbering in the style-list.
193 * @param: pParaNumbering a pointer to the structure which contains prefix, paranumber and
194 * suffix.
196 void LwpPara::GetParaNumber(sal_uInt16 nPosition, ParaNumbering* pParaNumbering)
198 if (nPosition > 9)
200 return;
202 sal_uInt16 nCurrentPos = 0;
204 LwpFrib* pPreFrib = NULL;
205 LwpFrib* pFrib = m_Fribs.GetFribs();
206 if (!pFrib)
208 return;
211 while (pFrib)
213 sal_uInt8 nFribType = pFrib->GetType();
214 if (nFribType == FRIB_TAG_PARANUMBER)
216 nCurrentPos++;
217 ModifierInfo* pModInfo = pFrib->GetModifiers();
218 if (pModInfo)
220 sal_uInt16 nHideLevels = pModInfo->aTxtAttrOverride.GetHideLevels();
221 if (nCurrentPos == nPosition)
223 //get prefix text frib
224 if (pPreFrib)
226 if ((pPreFrib->GetType() == FRIB_TAG_TEXT) &&
227 (pPreFrib->GetModifiers()->aTxtAttrOverride.GetHideLevels() == nHideLevels))
229 pParaNumbering->pPrefix = static_cast<LwpFribText*>(pPreFrib);
233 //get para numbering
234 pParaNumbering->pParaNumber = static_cast<LwpFribParaNumber*>(pFrib);
235 pParaNumbering->nNumLevel = nHideLevels;
237 //get suffix text frib
238 if ( (pFrib = pFrib->GetNext()) )
240 if( pFrib->GetType() == FRIB_TAG_TEXT )
242 if (
243 (pFrib->GetNext() && pFrib->GetNext()->GetType() == FRIB_TAG_TEXT) ||
244 (pFrib->GetModifiers()->aTxtAttrOverride.GetHideLevels() == nHideLevels)
247 pParaNumbering->pSuffix = static_cast<LwpFribText*>(pFrib);
252 break;
255 else
257 if (nCurrentPos == nPosition)
259 //get prefix text frib
260 if (pPreFrib)
262 if (pPreFrib->GetType() == FRIB_TAG_TEXT)
264 pParaNumbering->pPrefix = static_cast<LwpFribText*>(pPreFrib);
268 //get para numbering
269 pParaNumbering->pParaNumber = static_cast<LwpFribParaNumber*>(pFrib);
271 //get suffix text frib
272 if ( (pFrib = pFrib->GetNext()) )
274 if (pFrib->GetType() == FRIB_TAG_TEXT)
276 pParaNumbering->pSuffix = static_cast<LwpFribText*>(pFrib);
283 pPreFrib = pFrib;
284 if (pFrib)
286 pFrib = pFrib->GetNext();
291 * @short override alignment
293 void LwpPara::OverrideAlignment(LwpAlignmentOverride* base,LwpAlignmentOverride* over,XFParaStyle* pOverStyle)
295 if (base)//the latter two parameter never be null
297 over->Override(base);
298 LwpParaStyle::ApplyAlignment(pOverStyle,base);
300 else
301 LwpParaStyle::ApplyAlignment(pOverStyle,over);
304 * @short override indent attribute
306 void LwpPara::OverrideIndent(LwpIndentOverride* base,LwpIndentOverride* over,XFParaStyle* pOverStyle)
308 if (base)//the latter two parameter never be null
310 over->Override(base);
311 LwpParaStyle::ApplyIndent(this,pOverStyle,base);
313 else
315 LwpParaStyle::ApplyIndent(this,pOverStyle,over);
319 * @short override spacing
321 void LwpPara::OverrideSpacing(LwpSpacingOverride* base,LwpSpacingOverride* over,XFParaStyle* pOverStyle)
323 if (base)//the latter two parameter never be null
325 if (over)
326 over->Override(base);
327 LwpParaStyle::ApplySpacing(this,pOverStyle,base);
329 else
330 LwpParaStyle::ApplySpacing(this,pOverStyle,over);
334 * @short: Get parastyle object according to the objID.
335 * @return: pointer to the parastyle.
337 LwpParaStyle* LwpPara::GetParaStyle()
339 return dynamic_cast<LwpParaStyle*>(m_ParaStyle.obj(VO_PARASTYLE).get());
343 * @short: Override paraborder style.
344 * @param: pProps pointer to the LwpParaProperty and we can get local breaks through it.
345 * @param: pOverStyle pointer to XFParaStyle which contains the parastyle for XFilter.
347 void LwpPara::OverrideParaBorder(LwpParaProperty* pProps, XFParaStyle* pOverStyle)
349 // get paraborder in parastyle
350 LwpParaStyle* pParaStyle = this->GetParaStyle();
351 if (!pParaStyle)
353 return;
356 LwpOverride* pBorder = pParaStyle->GetParaBorder();
357 boost::scoped_ptr<LwpParaBorderOverride> pFinalBorder(
358 pBorder
359 ? polymorphic_downcast<LwpParaBorderOverride*>(pBorder->clone())
360 : new LwpParaBorderOverride)
363 // get local border
364 pBorder = static_cast<LwpParaBorderProperty*>(pProps)->GetLocalParaBorder();
365 if (pBorder)
367 boost::scoped_ptr<LwpParaBorderOverride> pLocalBorder(
368 polymorphic_downcast<LwpParaBorderOverride*>(pBorder->clone()));
369 pLocalBorder->Override(pFinalBorder.get());
372 LwpParaStyle::ApplyParaBorder(pOverStyle, pFinalBorder.get());
375 * @short: Override parabreaks style.
376 * @param: pProps pointer to the LwpParaProperty and we can get local breaks through it.
377 * @param: pOverStyle pointer to XFParaStyle which contains the parastyle for XFilter.
379 void LwpPara::OverrideParaBreaks(LwpParaProperty* pProps, XFParaStyle* pOverStyle)
381 // get breaks in parastyle
382 LwpParaStyle* pParaStyle = this->GetParaStyle();
383 if (!pParaStyle)
385 return;
388 LwpOverride* pBreaks = pParaStyle->GetBreaks();
389 std::unique_ptr<LwpBreaksOverride> pFinalBreaks(
390 pBreaks
391 ? polymorphic_downcast<LwpBreaksOverride*>(pBreaks->clone())
392 : new LwpBreaksOverride)
395 // get local breaks
396 pBreaks = static_cast<LwpParaBreaksProperty*>(pProps)->GetLocalParaBreaks();
397 if (pBreaks)
399 boost::scoped_ptr<LwpBreaksOverride> const pLocalBreaks(
400 polymorphic_downcast<LwpBreaksOverride*>(pBreaks->clone()));
401 pLocalBreaks->Override(pFinalBreaks.get());
404 // save the breaks
405 delete m_pBreaks;
406 m_pBreaks = pFinalBreaks.release();
408 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
409 if (m_pBreaks->IsKeepWithNext())
411 pOverStyle->SetBreaks(enumXFBreakKeepWithNext);
413 if (m_pBreaks->IsPageBreakBefore())
415 XFParaStyle* pStyle = new XFParaStyle();
416 pStyle->SetBreaks(enumXFBreakAftPage);
417 m_BefPageBreakName = pXFStyleManager->AddStyle(pStyle).m_pStyle->GetStyleName();
419 if (m_pBreaks->IsPageBreakAfter())
421 XFParaStyle* pStyle = new XFParaStyle();
422 pStyle->SetBreaks(enumXFBreakAftPage);
423 m_AftPageBreakName = pXFStyleManager->AddStyle(pStyle).m_pStyle->GetStyleName();
425 if (m_pBreaks->IsColumnBreakBefore())
427 XFParaStyle* pStyle = new XFParaStyle();
428 pStyle->SetBreaks(enumXFBreakAftColumn);//tmp after, should change when layout read
429 m_BefColumnBreakName = pXFStyleManager->AddStyle(pStyle).m_pStyle->GetStyleName();
431 if (m_pBreaks->IsColumnBreakAfter())
433 XFParaStyle* pStyle = new XFParaStyle();
434 pStyle->SetBreaks(enumXFBreakAftColumn);
435 m_AftColumnBreakName = pXFStyleManager->AddStyle(pStyle).m_pStyle->GetStyleName();
438 // pParaStyle->ApplyBreaks(pOverStyle, &aFinalBreaks);
442 * @short: Override bullet styles.
443 * @param: pProps pointer to the LwpParaProperty and we can get local bullet through it.
445 void LwpPara::OverrideParaBullet(LwpParaProperty* pProps)
447 // get bulletoverride in parastyle
448 LwpParaStyle* pParaStyle = this->GetParaStyle();
449 if (!pParaStyle)
451 return;
454 if (pProps)
456 m_pBullOver = new LwpBulletOverride();
457 // get local bulletoverride
458 LwpBulletOverride* pLocalBullet = static_cast<LwpParaBulletProperty*>(pProps)->GetLocalParaBullet();
459 if (!pLocalBullet)
461 return;
464 LwpObjectID aSilverBulletID = pLocalBullet->GetSilverBullet();
465 if (aSilverBulletID.IsNull())
467 return;
469 else
471 m_bHasBullet = true;
473 LwpOverride* pBullet= pParaStyle->GetBulletOverride();
474 std::unique_ptr<LwpBulletOverride> pFinalBullet(
475 pBullet
476 ? polymorphic_downcast<LwpBulletOverride*>(pBullet->clone())
477 : new LwpBulletOverride)
480 boost::scoped_ptr<LwpBulletOverride> const pLocalBullet2(pLocalBullet->clone());
481 pLocalBullet2->Override(pFinalBullet.get());
483 aSilverBulletID = pFinalBullet->GetSilverBullet();
484 delete m_pBullOver;
485 m_pBullOver = pFinalBullet.release();
486 if (!aSilverBulletID.IsNull())
488 m_pSilverBullet = dynamic_cast<LwpSilverBullet*>(aSilverBulletID.obj(VO_SILVERBULLET).get());
489 if (m_pSilverBullet)
490 m_pSilverBullet->SetFoundry(m_pFoundry);
493 m_aSilverBulletID = aSilverBulletID;
496 else
498 // m_pBullOver = pParaStyle->GetBulletOverride();
499 LwpBulletOverride* pBullOver = pParaStyle->GetBulletOverride();
500 if (pBullOver)
502 m_aSilverBulletID = pBullOver->GetSilverBullet();
503 if (!m_aSilverBulletID.IsNull())
505 m_bHasBullet = true;
507 m_pSilverBullet = dynamic_cast<LwpSilverBullet*>(m_aSilverBulletID.obj(VO_SILVERBULLET).get());
508 if (m_pSilverBullet)
509 m_pSilverBullet->SetFoundry(m_pFoundry);
512 std::unique_ptr<LwpBulletOverride> pBulletOverride(pBullOver->clone());
513 delete m_pBullOver;
514 m_pBullOver = pBulletOverride.release();
519 * @short: Override paranumbering properties.
520 * @param: pProps pointer to the LwpParaProperty and we can get local paranumbering through it.
522 void LwpPara::OverrideParaNumbering(LwpParaProperty* pProps)
524 // get numbering override in parastyle
525 LwpParaStyle* pParaStyle = this->GetParaStyle();
526 if (!pParaStyle)
528 return;
531 LwpNumberingOverride* pParaNumbering = pParaStyle->GetNumberingOverride();
532 std::unique_ptr<LwpNumberingOverride> pOver(new LwpNumberingOverride);
533 //Override with the local numbering, if any
534 if (pProps)
536 LwpNumberingOverride* pPropNumbering = static_cast<LwpParaNumberingProperty*>(pProps)->GetLocalNumbering();
537 if (pPropNumbering)
539 pOver.reset(pPropNumbering->clone());
542 else
544 if (pParaNumbering)
546 pOver.reset(pParaNumbering->clone());
550 if (m_nFlags & VALID_LEVEL)
552 pOver->OverrideLevel(m_nLevel);
555 m_pParaNumbering.reset(pOver.release());
558 void LwpPara::FindLayouts()
560 m_Fribs.SetPara(this);
561 m_Fribs.FindLayouts();
562 LwpPara* pNextPara = dynamic_cast<LwpPara*>(GetNext().obj().get());
563 if(pNextPara)
565 pNextPara->FindLayouts();
569 /**************************************************************************
570 * @descr: Get property according to the property type
571 * @param:
572 * @param:
573 * @return:
574 **************************************************************************/
575 LwpParaProperty* LwpPara::GetProperty(sal_uInt32 nPropType)
577 LwpParaProperty* pProps = m_pProps;
578 while(pProps)
580 if(pProps->GetType() == nPropType)
582 return pProps;
584 pProps = pProps->GetNext();
587 return NULL;
590 /**************************************************************************
591 * @descr: Get local tab rack
592 * @param:
593 * @param:
594 * @return:
595 **************************************************************************/
596 LwpTabOverride* LwpPara::GetLocalTabOverride()
598 LwpParaProperty* pProp = GetProperty(PP_LOCAL_TABRACK);
599 if(pProp)
601 return static_cast<LwpParaTabRackProperty*>(pProp)->GetTab();
603 return NULL;
607 * @descr: Determined which para is earlier in position
610 bool LwpPara::operator< (LwpPara& Other)
612 return m_nOrdinal < Other.GetOrdinal();
616 * @descr: If the two layouts in the same para, compare which layout is earlied according to frib order
619 bool LwpPara::ComparePagePosition(LwpVirtualLayout * pPreLayout, LwpVirtualLayout * pNextLayout)
621 m_Fribs.SetPara(this);
622 return m_Fribs.ComparePagePosition(pPreLayout, pNextLayout);
626 * @short check paragraph in cell or not
628 bool LwpPara::IsInCell()
630 LwpStory *pStory = GetStory();
631 LwpVirtualLayout* pLayout = pStory ? pStory->GetLayout(NULL) : NULL;
632 if(pLayout && pLayout->IsCell())
633 return true;
634 return false;
637 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */