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,
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 /*************************************************************************
58 * For LWP filter architecture prototype
59 ************************************************************************/
60 /*************************************************************************
63 ************************************************************************/
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
112 #elif !defined(NDEBUG)
116 using boost::polymorphic_downcast
;
119 * @short get text of paragraph
121 OUString
LwpPara::GetContentText(bool bAllText
)
126 m_Fribs
.SetPara(this);
127 m_Fribs
.GatherAllText();
135 * @short set text of paragraph
137 void LwpPara::SetAllText(const OUString
& sText
)
143 * @short set first frib content
145 void LwpPara::SetFirstFrib(const OUString
& Content
,sal_uInt32 FontID
)
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()
173 sal_uInt16 otherlevel
;
174 sal_uInt16 level
= GetLevel();
178 pPara
= dynamic_cast<LwpPara
*>(GetPrevious().obj().get());
181 otherlevel
= pPara
->GetLevel();
182 if ((otherlevel
< level
) || (otherlevel
&& (level
== 0)))
184 pPara
= dynamic_cast<LwpPara
*>(pPara
->GetPrevious().obj().get());
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
196 void LwpPara::GetParaNumber(sal_uInt16 nPosition
, ParaNumbering
* pParaNumbering
)
202 sal_uInt16 nCurrentPos
= 0;
204 LwpFrib
* pPreFrib
= NULL
;
205 LwpFrib
* pFrib
= m_Fribs
.GetFribs();
213 sal_uInt8 nFribType
= pFrib
->GetType();
214 if (nFribType
== FRIB_TAG_PARANUMBER
)
217 ModifierInfo
* pModInfo
= pFrib
->GetModifiers();
220 sal_uInt16 nHideLevels
= pModInfo
->aTxtAttrOverride
.GetHideLevels();
221 if (nCurrentPos
== nPosition
)
223 //get prefix text frib
226 if ((pPreFrib
->GetType() == FRIB_TAG_TEXT
) &&
227 (pPreFrib
->GetModifiers()->aTxtAttrOverride
.GetHideLevels() == nHideLevels
))
229 pParaNumbering
->pPrefix
= static_cast<LwpFribText
*>(pPreFrib
);
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
)
243 (pFrib
->GetNext() && pFrib
->GetNext()->GetType() == FRIB_TAG_TEXT
) ||
244 (pFrib
->GetModifiers()->aTxtAttrOverride
.GetHideLevels() == nHideLevels
)
247 pParaNumbering
->pSuffix
= static_cast<LwpFribText
*>(pFrib
);
257 if (nCurrentPos
== nPosition
)
259 //get prefix text frib
262 if (pPreFrib
->GetType() == FRIB_TAG_TEXT
)
264 pParaNumbering
->pPrefix
= static_cast<LwpFribText
*>(pPreFrib
);
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
);
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
);
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
);
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
326 over
->Override(base
);
327 LwpParaStyle::ApplySpacing(this,pOverStyle
,base
);
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();
356 LwpOverride
* pBorder
= pParaStyle
->GetParaBorder();
357 boost::scoped_ptr
<LwpParaBorderOverride
> pFinalBorder(
359 ? polymorphic_downcast
<LwpParaBorderOverride
*>(pBorder
->clone())
360 : new LwpParaBorderOverride
)
364 pBorder
= static_cast<LwpParaBorderProperty
*>(pProps
)->GetLocalParaBorder();
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();
388 LwpOverride
* pBreaks
= pParaStyle
->GetBreaks();
389 std::unique_ptr
<LwpBreaksOverride
> pFinalBreaks(
391 ? polymorphic_downcast
<LwpBreaksOverride
*>(pBreaks
->clone())
392 : new LwpBreaksOverride
)
396 pBreaks
= static_cast<LwpParaBreaksProperty
*>(pProps
)->GetLocalParaBreaks();
399 boost::scoped_ptr
<LwpBreaksOverride
> const pLocalBreaks(
400 polymorphic_downcast
<LwpBreaksOverride
*>(pBreaks
->clone()));
401 pLocalBreaks
->Override(pFinalBreaks
.get());
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();
456 m_pBullOver
= new LwpBulletOverride();
457 // get local bulletoverride
458 LwpBulletOverride
* pLocalBullet
= static_cast<LwpParaBulletProperty
*>(pProps
)->GetLocalParaBullet();
464 LwpObjectID aSilverBulletID
= pLocalBullet
->GetSilverBullet();
465 if (aSilverBulletID
.IsNull())
473 LwpOverride
* pBullet
= pParaStyle
->GetBulletOverride();
474 std::unique_ptr
<LwpBulletOverride
> pFinalBullet(
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();
485 m_pBullOver
= pFinalBullet
.release();
486 if (!aSilverBulletID
.IsNull())
488 m_pSilverBullet
= dynamic_cast<LwpSilverBullet
*>(aSilverBulletID
.obj(VO_SILVERBULLET
).get());
490 m_pSilverBullet
->SetFoundry(m_pFoundry
);
493 m_aSilverBulletID
= aSilverBulletID
;
498 // m_pBullOver = pParaStyle->GetBulletOverride();
499 LwpBulletOverride
* pBullOver
= pParaStyle
->GetBulletOverride();
502 m_aSilverBulletID
= pBullOver
->GetSilverBullet();
503 if (!m_aSilverBulletID
.IsNull())
507 m_pSilverBullet
= dynamic_cast<LwpSilverBullet
*>(m_aSilverBulletID
.obj(VO_SILVERBULLET
).get());
509 m_pSilverBullet
->SetFoundry(m_pFoundry
);
512 std::unique_ptr
<LwpBulletOverride
> pBulletOverride(pBullOver
->clone());
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();
531 LwpNumberingOverride
* pParaNumbering
= pParaStyle
->GetNumberingOverride();
532 std::unique_ptr
<LwpNumberingOverride
> pOver(new LwpNumberingOverride
);
533 //Override with the local numbering, if any
536 LwpNumberingOverride
* pPropNumbering
= static_cast<LwpParaNumberingProperty
*>(pProps
)->GetLocalNumbering();
539 pOver
.reset(pPropNumbering
->clone());
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());
565 pNextPara
->FindLayouts();
569 /**************************************************************************
570 * @descr: Get property according to the property type
574 **************************************************************************/
575 LwpParaProperty
* LwpPara::GetProperty(sal_uInt32 nPropType
)
577 LwpParaProperty
* pProps
= m_pProps
;
580 if(pProps
->GetType() == nPropType
)
584 pProps
= pProps
->GetNext();
590 /**************************************************************************
591 * @descr: Get local tab rack
595 **************************************************************************/
596 LwpTabOverride
* LwpPara::GetLocalTabOverride()
598 LwpParaProperty
* pProp
= GetProperty(PP_LOCAL_TABRACK
);
601 return static_cast<LwpParaTabRackProperty
*>(pProp
)->GetTab();
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())
637 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */