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 ************************************************************************/
63 #include <boost/cast.hpp>
65 #include "lwppara.hxx"
66 #include "lwpglobalmgr.hxx"
67 #include "lwpfilehdr.hxx"
68 #include "lwpparaproperty.hxx"
69 #include "lwptools.hxx"
70 #include "lwpparastyle.hxx"
71 #include "xfilter/xffont.hxx"
72 #include "xfilter/xftextstyle.hxx"
73 #include "xfilter/xfstylemanager.hxx"
74 #include "xfilter/xfparagraph.hxx"
75 #include "xfilter/xftextcontent.hxx"
76 #include "xfilter/xftextspan.hxx"
77 #include "xfilter/xfmargins.hxx"
78 #include "xfilter/xftabstop.hxx"
79 #include "xfilter/xflinebreak.hxx"
80 #include "xfilter/xfsection.hxx"
81 #include "xfilter/xfsectionstyle.hxx"
82 #include "xfilter/xfcolor.hxx"
83 #include "xfilter/xfhyperlink.hxx"
84 #include "lwpcharsetmgr.hxx"
85 #include "lwpsection.hxx"
86 #include "lwplayout.hxx"
87 #include "lwpusewhen.hxx"
89 #include "lwpbulletstylemgr.hxx"
90 #include "lwpstory.hxx"
91 #include "lwpsilverbullet.hxx"
92 #include "xfilter/xflist.hxx"
93 #include "xfilter/xfframe.hxx"
95 #include "lwpdivinfo.hxx"
97 #include "lwpholder.hxx"
98 #include "lwppagehint.hxx"
100 #include "lwpdropcapmgr.hxx"
101 #include "lwptable.hxx"
102 #include "lwpcelllayout.hxx"
104 // boost::polymorphic_downcast checks and reports (using assert), if the
105 // cast is incorrect (in debug builds).
106 using boost::polymorphic_downcast
;
109 * @short get text of paragraph
111 OUString
LwpPara::GetContentText(bool bAllText
)
116 m_Fribs
.SetPara(this);
117 m_Fribs
.GatherAllText();
125 * @short set text of paragraph
127 void LwpPara::SetAllText(const OUString
& sText
)
133 * @short set first frib content
135 void LwpPara::SetFirstFrib(const OUString
& Content
,sal_uInt32 FontID
)
141 * @short get paragraph xfstyle
143 XFParaStyle
* LwpPara::GetXFParaStyle()
145 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
146 return pXFStyleManager
->FindParaStyle(m_StyleName
);
149 * @short get drop cap info
151 #include "lwpframelayout.hxx"
152 void LwpPara::GatherDropcapInfo()
154 SetDropcapLines(m_pDropcapLayout
->GetLines());
155 SetDropcapChars(m_pDropcapLayout
->GetChars());
158 * @short get parent paragraph
160 LwpPara
* LwpPara::GetParent()
163 sal_uInt16 otherlevel
;
164 sal_uInt16 level
= GetLevel();
168 pPara
= dynamic_cast<LwpPara
*>(GetPrevious().obj().get());
171 otherlevel
= pPara
->GetLevel();
172 if ((otherlevel
< level
) || (otherlevel
&& (level
== 0)))
174 pPara
= dynamic_cast<LwpPara
*>(pPara
->GetPrevious().obj().get());
181 * @short: Offer prefix, paranumber and suffix according to position.
182 * @param: nPosition index of wanted paranumbering in the style-list.
183 * @param: pParaNumbering a pointer to the structure which contains prefix, paranumber and
186 void LwpPara::GetParaNumber(sal_uInt16 nPosition
, ParaNumbering
* pParaNumbering
)
192 sal_uInt16 nCurrentPos
= 0;
194 LwpFrib
* pPreFrib
= nullptr;
195 LwpFrib
* pFrib
= m_Fribs
.GetFribs();
203 sal_uInt8 nFribType
= pFrib
->GetType();
204 if (nFribType
== FRIB_TAG_PARANUMBER
)
207 ModifierInfo
* pModInfo
= pFrib
->GetModifiers();
210 sal_uInt16 nHideLevels
= pModInfo
->aTxtAttrOverride
.GetHideLevels();
211 if (nCurrentPos
== nPosition
)
213 //get prefix text frib
216 if ((pPreFrib
->GetType() == FRIB_TAG_TEXT
) &&
217 (pPreFrib
->GetModifiers() && pPreFrib
->GetModifiers()->aTxtAttrOverride
.GetHideLevels() == nHideLevels
))
219 pParaNumbering
->pPrefix
= static_cast<LwpFribText
*>(pPreFrib
);
224 pParaNumbering
->pParaNumber
= static_cast<LwpFribParaNumber
*>(pFrib
);
225 pParaNumbering
->nNumLevel
= nHideLevels
;
227 //get suffix text frib
228 if ( (pFrib
= pFrib
->GetNext()) )
230 if( pFrib
->GetType() == FRIB_TAG_TEXT
)
233 (pFrib
->GetNext() && pFrib
->GetNext()->GetType() == FRIB_TAG_TEXT
) ||
234 (pFrib
->GetModifiers() && pFrib
->GetModifiers()->aTxtAttrOverride
.GetHideLevels() == nHideLevels
)
237 pParaNumbering
->pSuffix
= static_cast<LwpFribText
*>(pFrib
);
247 if (nCurrentPos
== nPosition
)
249 //get prefix text frib
252 if (pPreFrib
->GetType() == FRIB_TAG_TEXT
)
254 pParaNumbering
->pPrefix
= static_cast<LwpFribText
*>(pPreFrib
);
259 pParaNumbering
->pParaNumber
= static_cast<LwpFribParaNumber
*>(pFrib
);
261 //get suffix text frib
262 if ( (pFrib
= pFrib
->GetNext()) )
264 if (pFrib
->GetType() == FRIB_TAG_TEXT
)
266 pParaNumbering
->pSuffix
= static_cast<LwpFribText
*>(pFrib
);
276 pFrib
= pFrib
->GetNext();
281 * @short override alignment
283 void LwpPara::OverrideAlignment(LwpAlignmentOverride
* base
,LwpAlignmentOverride
* over
,XFParaStyle
* pOverStyle
)
285 if (base
)//the latter two parameter never be null
287 over
->Override(base
);
288 LwpParaStyle::ApplyAlignment(pOverStyle
,base
);
291 LwpParaStyle::ApplyAlignment(pOverStyle
,over
);
294 * @short override indent attribute
296 void LwpPara::OverrideIndent(LwpIndentOverride
* base
,LwpIndentOverride
* over
,XFParaStyle
* pOverStyle
)
298 if (base
)//the latter two parameter never be null
300 over
->Override(base
);
301 LwpParaStyle::ApplyIndent(this,pOverStyle
,base
);
305 LwpParaStyle::ApplyIndent(this,pOverStyle
,over
);
309 * @short override spacing
311 void LwpPara::OverrideSpacing(LwpSpacingOverride
* base
,LwpSpacingOverride
* over
,XFParaStyle
* pOverStyle
)
313 if (base
)//the latter two parameter never be null
316 over
->Override(base
);
317 LwpParaStyle::ApplySpacing(this,pOverStyle
,base
);
320 LwpParaStyle::ApplySpacing(this,pOverStyle
,over
);
324 * @short: Get parastyle object according to the objID.
325 * @return: pointer to the parastyle.
327 LwpParaStyle
* LwpPara::GetParaStyle()
329 return dynamic_cast<LwpParaStyle
*>(m_ParaStyle
.obj(VO_PARASTYLE
).get());
333 * @short: Override paraborder style.
334 * @param: pProps pointer to the LwpParaProperty and we can get local breaks through it.
335 * @param: pOverStyle pointer to XFParaStyle which contains the parastyle for XFilter.
337 void LwpPara::OverrideParaBorder(LwpParaProperty
* pProps
, XFParaStyle
* pOverStyle
)
339 // get paraborder in parastyle
340 LwpParaStyle
* pParaStyle
= GetParaStyle();
346 LwpOverride
* pBorder
= pParaStyle
->GetParaBorder();
347 std::unique_ptr
<LwpParaBorderOverride
> pFinalBorder(
349 ? polymorphic_downcast
<LwpParaBorderOverride
*>(pBorder
->clone())
350 : new LwpParaBorderOverride
)
354 pBorder
= static_cast<LwpParaBorderProperty
*>(pProps
)->GetLocalParaBorder();
357 std::unique_ptr
<LwpParaBorderOverride
> pLocalBorder(
358 polymorphic_downcast
<LwpParaBorderOverride
*>(pBorder
->clone()));
359 pLocalBorder
->Override(pFinalBorder
.get());
362 LwpParaStyle::ApplyParaBorder(pOverStyle
, pFinalBorder
.get());
365 * @short: Override parabreaks style.
366 * @param: pProps pointer to the LwpParaProperty and we can get local breaks through it.
367 * @param: pOverStyle pointer to XFParaStyle which contains the parastyle for XFilter.
369 void LwpPara::OverrideParaBreaks(LwpParaProperty
* pProps
, XFParaStyle
* pOverStyle
)
371 // get breaks in parastyle
372 LwpParaStyle
* pParaStyle
= GetParaStyle();
378 LwpOverride
* pBreaks
= pParaStyle
->GetBreaks();
379 std::unique_ptr
<LwpBreaksOverride
> pFinalBreaks(
381 ? polymorphic_downcast
<LwpBreaksOverride
*>(pBreaks
->clone())
382 : new LwpBreaksOverride
)
386 pBreaks
= static_cast<LwpParaBreaksProperty
*>(pProps
)->GetLocalParaBreaks();
389 std::unique_ptr
<LwpBreaksOverride
> const pLocalBreaks(
390 polymorphic_downcast
<LwpBreaksOverride
*>(pBreaks
->clone()));
391 pLocalBreaks
->Override(pFinalBreaks
.get());
396 m_pBreaks
= pFinalBreaks
.release();
398 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
399 if (m_pBreaks
->IsKeepWithNext())
401 pOverStyle
->SetBreaks(enumXFBreakKeepWithNext
);
403 if (m_pBreaks
->IsPageBreakBefore())
405 XFParaStyle
* pStyle
= new XFParaStyle();
406 pStyle
->SetBreaks(enumXFBreakAftPage
);
407 m_BefPageBreakName
= pXFStyleManager
->AddStyle(pStyle
).m_pStyle
->GetStyleName();
409 if (m_pBreaks
->IsPageBreakAfter())
411 XFParaStyle
* pStyle
= new XFParaStyle();
412 pStyle
->SetBreaks(enumXFBreakAftPage
);
413 m_AftPageBreakName
= pXFStyleManager
->AddStyle(pStyle
).m_pStyle
->GetStyleName();
415 if (m_pBreaks
->IsColumnBreakBefore())
417 XFParaStyle
* pStyle
= new XFParaStyle();
418 pStyle
->SetBreaks(enumXFBreakAftColumn
);//tmp after, should change when layout read
419 m_BefColumnBreakName
= pXFStyleManager
->AddStyle(pStyle
).m_pStyle
->GetStyleName();
421 if (m_pBreaks
->IsColumnBreakAfter())
423 XFParaStyle
* pStyle
= new XFParaStyle();
424 pStyle
->SetBreaks(enumXFBreakAftColumn
);
425 m_AftColumnBreakName
= pXFStyleManager
->AddStyle(pStyle
).m_pStyle
->GetStyleName();
428 // pParaStyle->ApplyBreaks(pOverStyle, &aFinalBreaks);
432 * @short: Override bullet styles.
433 * @param: pProps pointer to the LwpParaProperty and we can get local bullet through it.
435 void LwpPara::OverrideParaBullet(LwpParaProperty
* pProps
)
437 // get bulletoverride in parastyle
438 LwpParaStyle
* pParaStyle
= GetParaStyle();
446 m_pBullOver
= new LwpBulletOverride();
447 // get local bulletoverride
448 LwpBulletOverride
* pLocalBullet
= static_cast<LwpParaBulletProperty
*>(pProps
)->GetLocalParaBullet();
454 LwpObjectID aSilverBulletID
= pLocalBullet
->GetSilverBullet();
455 if (aSilverBulletID
.IsNull())
463 LwpOverride
* pBullet
= pParaStyle
->GetBulletOverride();
464 std::unique_ptr
<LwpBulletOverride
> pFinalBullet(
466 ? polymorphic_downcast
<LwpBulletOverride
*>(pBullet
->clone())
467 : new LwpBulletOverride
)
470 std::unique_ptr
<LwpBulletOverride
> const pLocalBullet2(pLocalBullet
->clone());
471 pLocalBullet2
->Override(pFinalBullet
.get());
473 aSilverBulletID
= pFinalBullet
->GetSilverBullet();
475 m_pBullOver
= pFinalBullet
.release();
476 if (!aSilverBulletID
.IsNull())
478 m_pSilverBullet
= dynamic_cast<LwpSilverBullet
*>(aSilverBulletID
.obj(VO_SILVERBULLET
).get());
480 m_pSilverBullet
->SetFoundry(m_pFoundry
);
483 m_aSilverBulletID
= aSilverBulletID
;
488 // m_pBullOver = pParaStyle->GetBulletOverride();
489 LwpBulletOverride
* pBullOver
= pParaStyle
->GetBulletOverride();
492 m_aSilverBulletID
= pBullOver
->GetSilverBullet();
493 if (!m_aSilverBulletID
.IsNull())
497 m_pSilverBullet
= dynamic_cast<LwpSilverBullet
*>(m_aSilverBulletID
.obj(VO_SILVERBULLET
).get());
499 m_pSilverBullet
->SetFoundry(m_pFoundry
);
502 std::unique_ptr
<LwpBulletOverride
> pBulletOverride(pBullOver
->clone());
504 m_pBullOver
= pBulletOverride
.release();
509 * @short: Override paranumbering properties.
510 * @param: pProps pointer to the LwpParaProperty and we can get local paranumbering through it.
512 void LwpPara::OverrideParaNumbering(LwpParaProperty
* pProps
)
514 // get numbering override in parastyle
515 LwpParaStyle
* pParaStyle
= GetParaStyle();
521 LwpNumberingOverride
* pParaNumbering
= pParaStyle
->GetNumberingOverride();
522 std::unique_ptr
<LwpNumberingOverride
> pOver(new LwpNumberingOverride
);
523 //Override with the local numbering, if any
526 LwpNumberingOverride
* pPropNumbering
= static_cast<LwpParaNumberingProperty
*>(pProps
)->GetLocalNumbering();
529 pOver
.reset(pPropNumbering
->clone());
536 pOver
.reset(pParaNumbering
->clone());
540 if (m_nFlags
& VALID_LEVEL
)
542 pOver
->OverrideLevel(m_nLevel
);
545 m_pParaNumbering
.reset(pOver
.release());
548 void LwpPara::FindLayouts()
550 m_Fribs
.SetPara(this);
551 m_Fribs
.FindLayouts();
552 LwpPara
* pNextPara
= dynamic_cast<LwpPara
*>(GetNext().obj().get());
555 pNextPara
->FindLayouts();
559 /**************************************************************************
560 * @descr: Get property according to the property type
561 **************************************************************************/
562 LwpParaProperty
* LwpPara::GetProperty(sal_uInt32 nPropType
)
564 LwpParaProperty
* pProps
= m_pProps
;
567 if(pProps
->GetType() == nPropType
)
571 pProps
= pProps
->GetNext();
577 /**************************************************************************
578 * @descr: Get local tab rack
579 **************************************************************************/
580 LwpTabOverride
* LwpPara::GetLocalTabOverride()
582 LwpParaProperty
* pProp
= GetProperty(PP_LOCAL_TABRACK
);
585 return static_cast<LwpParaTabRackProperty
*>(pProp
)->GetTab();
591 * @descr: Determined which para is earlier in position
594 bool LwpPara::operator< (LwpPara
& Other
)
596 return m_nOrdinal
< Other
.GetOrdinal();
600 * @descr: If the two layouts in the same para, compare which layout is earlied according to frib order
603 bool LwpPara::ComparePagePosition(LwpVirtualLayout
* pPreLayout
, LwpVirtualLayout
* pNextLayout
)
605 m_Fribs
.SetPara(this);
606 return m_Fribs
.ComparePagePosition(pPreLayout
, pNextLayout
);
610 * @short check paragraph in cell or not
612 bool LwpPara::IsInCell()
614 LwpStory
*pStory
= GetStory();
617 rtl::Reference
<LwpVirtualLayout
> xLayout(pStory
->GetLayout(nullptr));
618 if (xLayout
.is() && xLayout
->IsCell())
623 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */