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 ************************************************************************/
62 #include "lwplayout.hxx"
63 #include "lwpusewhen.hxx"
64 #include <lwptools.hxx>
65 #include "lwplaypiece.hxx"
66 #include <xfilter/xfcolumns.hxx>
67 #include "lwpstory.hxx"
68 #include "lwpparastyle.hxx"
69 #include "lwpholder.hxx"
71 #include "lwpgrfobj.hxx"
72 #include <lwpfilehdr.hxx>
73 #include <osl/thread.h>
74 #include <sal/log.hxx>
75 #include <o3tl/sorted_vector.hxx>
77 LwpVirtualLayout::LwpVirtualLayout(LwpObjectHeader
const& objHdr
, LwpSvStream
* pStrm
)
78 : LwpDLNFPVList(objHdr
, pStrm
)
79 , m_bGettingHonorProtection(false)
80 , m_bGettingMarginsSameAsParent(false)
81 , m_bGettingHasProtection(false)
82 , m_bGettingIsProtected(false)
83 , m_bGettingIsAutoGrowDown(false)
84 , m_bGettingMarginsValue(false)
85 , m_bGettingExtMarginsValue(false)
86 , m_bGettingUsePrinterSettings(false)
87 , m_bGettingScaleCenter(false)
88 , m_bGettingBorderStuff(false)
89 , m_bGettingUseWhen(false)
90 , m_bGettingStyleLayout(false)
91 , m_bGettingAutoGrowUp(false)
101 void LwpVirtualLayout::Read()
103 LwpDLNFPVList::Read();
105 LwpObjectStream
* pStrm
= m_pObjStrm
.get();
106 m_nAttributes
= pStrm
->QuickReaduInt32();
107 m_nAttributes2
= pStrm
->QuickReaduInt32();
108 m_nAttributes3
= pStrm
->QuickReaduInt32();
109 m_nOverrideFlag
= pStrm
->QuickReaduInt32();
110 m_nDirection
= pStrm
->QuickReaduInt16();
112 //Note that two bytes is read into m_nEditorID instead of one byte.
113 m_nEditorID
= pStrm
->QuickReaduInt16();
115 m_NextEnumerated
.ReadIndexed(pStrm
);
116 m_PreviousEnumerated
.ReadIndexed(pStrm
);
121 bool LwpVirtualLayout::MarginsSameAsParent()
123 return (m_nAttributes2
& STYLE2_MARGINSSAMEASPARENT
) != 0;
127 * @descr: Get the gap between columns
130 double LwpVirtualLayout::GetColGap(sal_uInt16
/*nIndex*/)
132 //return DEFAULTGAPSIZE;
133 //return LwpTools::ConvertToMetric(0.17);//DEFAULTGAPSIZE=0.17
134 return LwpTools::ConvertToMetric(0.17);
138 * @descr: Whether it is honoring protection
141 bool LwpVirtualLayout::HonorProtection()
143 if (!(m_nAttributes2
& STYLE2_HONORPROTECTION
))
146 rtl::Reference
<LwpVirtualLayout
> xParent(
147 dynamic_cast<LwpVirtualLayout
*>(GetParent().obj().get()));
148 if (xParent
.is() && !xParent
->IsHeader())
150 return xParent
->GetHonorProtection();
153 if (m_pFoundry
) //is null now
155 LwpDocument
* pDoc
= m_pFoundry
->GetDocument();
156 if (pDoc
&& pDoc
->GetRootDocument())
157 return pDoc
->GetRootDocument()->GetHonorProtection();
164 * @descr: Whether it is protected
167 bool LwpVirtualLayout::IsProtected()
169 bool bProtected
= (m_nAttributes
& STYLE_PROTECTED
) != 0;
171 rtl::Reference
<LwpVirtualLayout
> xParent(
172 dynamic_cast<LwpVirtualLayout
*>(GetParent().obj().get()));
173 if (xParent
.is() && !xParent
->IsHeader())
175 if (xParent
->GetHonorProtection() && (xParent
->GetHasProtection() || bProtected
))
180 else if (m_pFoundry
) //is null now
182 LwpDocument
* pDoc
= m_pFoundry
->GetDocument();
185 if (pDoc
->GetHonorProtection() && bProtected
)
196 * @descr: Whether it has protection
199 bool LwpVirtualLayout::HasProtection()
201 if (m_nAttributes
& STYLE_PROTECTED
)
204 rtl::Reference
<LwpVirtualLayout
> xParent(
205 dynamic_cast<LwpVirtualLayout
*>(GetParent().obj().get()));
206 if (xParent
.is() && !xParent
->IsHeader())
208 return xParent
->GetHasProtection();
215 * @descr: Whether it is a mirror layout
218 bool LwpVirtualLayout::IsComplex() const { return (m_nAttributes
& STYLE_COMPLEX
) != 0; }
221 * @descr: Get usewhen pointer
224 LwpUseWhen
* LwpVirtualLayout::GetUseWhen()
226 if (m_bGettingUseWhen
)
227 throw std::runtime_error("recursion in layout");
228 m_bGettingUseWhen
= true;
230 LwpUseWhen
* pRet
= nullptr;
233 If we have a parent, and I'm not a page layout,
234 use my parents information.
236 if (GetLayoutType() != LWP_PAGE_LAYOUT
)
239 rtl::Reference
<LwpVirtualLayout
> xParent(
240 dynamic_cast<LwpVirtualLayout
*>(GetParent().obj().get()));
241 if (xParent
.is() && !xParent
->IsHeader() && (xParent
->GetLayoutType() != LWP_PAGE_LAYOUT
))
242 pRet
= xParent
->GetUseWhen();
246 pRet
= VirtualGetUseWhen();
248 m_bGettingUseWhen
= false;
253 * @descr: Whether this layout is page layout or not
255 bool LwpVirtualLayout::IsPage() { return (GetLayoutType() == LWP_PAGE_LAYOUT
); }
257 * @descr: Whether this layout is header layout or not
259 bool LwpVirtualLayout::IsHeader() { return (GetLayoutType() == LWP_HEADER_LAYOUT
); }
261 * @descr: Whether this layout is footer layout or not
263 bool LwpVirtualLayout::IsFooter() { return (GetLayoutType() == LWP_FOOTER_LAYOUT
); }
265 * @descr: Whether this layout is frame layout or not
267 bool LwpVirtualLayout::IsFrame() { return (GetLayoutType() == LWP_FRAME_LAYOUT
); }
270 * @descr: Whether this layout is cell layout or not
272 bool LwpVirtualLayout::IsCell()
274 return (GetLayoutType() == LWP_CELL_LAYOUT
|| GetLayoutType() == LWP_CONNECTED_CELL_LAYOUT
275 || GetLayoutType() == LWP_HIDDEN_CELL_LAYOUT
);
278 * @descr: Whether this layout is supertable layout or not
280 bool LwpVirtualLayout::IsSuperTable() { return (GetLayoutType() == LWP_SUPERTABLE_LAYOUT
); }
282 * @descr: Whether this layout is group layout or not
284 bool LwpVirtualLayout::IsGroupHead() { return (GetLayoutType() == LWP_GROUP_LAYOUT
); }
286 * @descr: get the relative type
288 sal_uInt8
LwpVirtualLayout::GetRelativeType()
290 return LwpLayoutRelativityGuts::LAY_PARENT_RELATIVE
;
293 * @descr: whether it is relative anchored layout
295 bool LwpVirtualLayout::IsRelativeAnchored()
299 nType
= GetRelativeType();
300 return (nType
== LwpLayoutRelativityGuts::LAY_PARA_RELATIVE
)
301 || (nType
== LwpLayoutRelativityGuts::LAY_INLINE
)
302 || (nType
== LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE
)
303 || (nType
== LwpLayoutRelativityGuts::LAY_INLINE_VERTICAL
);
306 * @descr: whether it is MinimumHeight layout
308 bool LwpVirtualLayout::IsMinimumHeight() const
310 return ((m_nAttributes3
& STYLE3_MINHEIGHTVALID
) != 0);
314 * @descr: Get parent layout
317 rtl::Reference
<LwpVirtualLayout
> LwpVirtualLayout::GetParentLayout()
319 return rtl::Reference
<LwpVirtualLayout
>(
320 dynamic_cast<LwpVirtualLayout
*>(GetParent().obj().get()));
324 * @descr: Register child layout style
327 void LwpVirtualLayout::RegisterChildStyle()
329 //Register all children styles
330 rtl::Reference
<LwpVirtualLayout
> xLayout(
331 dynamic_cast<LwpVirtualLayout
*>(GetChildHead().obj().get()));
334 xLayout
->SetFoundry(m_pFoundry
);
335 xLayout
->DoRegisterStyle();
336 xLayout
.set(dynamic_cast<LwpVirtualLayout
*>(xLayout
->GetNext().obj().get()));
340 bool LwpVirtualLayout::NoContentReference()
342 return (m_nAttributes2
& STYLE2_NOCONTENTREFERENCE
) != 0;
345 bool LwpVirtualLayout::IsStyleLayout()
347 if (m_bGettingStyleLayout
)
348 throw std::runtime_error("recursion in layout");
349 m_bGettingStyleLayout
= true;
352 if (m_nAttributes3
& STYLE3_STYLELAYOUT
)
356 rtl::Reference
<LwpVirtualLayout
> xParent(
357 dynamic_cast<LwpVirtualLayout
*>(GetParent().obj().get()));
359 bRet
= xParent
->IsStyleLayout();
362 m_bGettingStyleLayout
= false;
367 * @descr: Find child layout by layout type
370 LwpVirtualLayout
* LwpVirtualLayout::FindChildByType(LWP_LAYOUT_TYPE eType
)
372 LwpObjectID
* pID
= &GetChildHead();
373 o3tl::sorted_vector
<LwpVirtualLayout
*> aSeen
;
375 while (pID
&& !pID
->IsNull())
377 LwpVirtualLayout
* pLayout
= dynamic_cast<LwpVirtualLayout
*>(pID
->obj().get());
381 bool bAlreadySeen
= !aSeen
.insert(pLayout
).second
;
384 SAL_WARN("lwp", "loop in layout");
388 if (pLayout
->GetLayoutType() == eType
)
391 pID
= &pLayout
->GetNext();
398 * @descr: Whether the size of layout is fit the graphic
401 bool LwpVirtualLayout::IsFitGraphic()
403 return IsAutoGrowRight() && !IsAutoGrowLeft() && GetIsAutoGrowDown();
407 * @descr: Whether the width of layout is auto grow
410 bool LwpVirtualLayout::IsAutoGrowWidth() { return IsAutoGrowLeft() || IsAutoGrowRight(); }
413 * @descr: Determine whether the layout width is to margin
416 bool LwpVirtualLayout::IsInlineToMargin() const
418 return (m_nAttributes3
& STYLE3_INLINETOMARGIN
) != 0;
421 void LwpAssociatedLayouts::Read(LwpObjectStream
* pStrm
)
423 m_OnlyLayout
.ReadIndexed(pStrm
);
424 m_Layouts
.Read(pStrm
);
429 * @descr: Looking for the layout which follows the pStartLayout
430 * @param: pStartLayout - the layout which is used for looking for its following layout
432 rtl::Reference
<LwpVirtualLayout
>
433 LwpAssociatedLayouts::GetLayout(LwpVirtualLayout
const* pStartLayout
)
435 if (!pStartLayout
&& !m_OnlyLayout
.IsNull())
436 /* Looking for the first layout and there's only one layout in the list.*/
437 return rtl::Reference
<LwpVirtualLayout
>(
438 dynamic_cast<LwpVirtualLayout
*>(m_OnlyLayout
.obj().get()));
440 rtl::Reference
<LwpObjectHolder
> xObjHolder(
441 dynamic_cast<LwpObjectHolder
*>(m_Layouts
.GetHead().obj().get()));
444 rtl::Reference
<LwpVirtualLayout
> xLayout(
445 dynamic_cast<LwpVirtualLayout
*>(xObjHolder
->GetObject().obj().get()));
449 while (xObjHolder
.is() && pStartLayout
!= xLayout
.get())
451 xObjHolder
.set(dynamic_cast<LwpObjectHolder
*>(xObjHolder
->GetNext().obj().get()));
454 xLayout
.set(dynamic_cast<LwpVirtualLayout
*>(xObjHolder
->GetObject().obj().get()));
460 xObjHolder
.set(dynamic_cast<LwpObjectHolder
*>(xObjHolder
->GetNext().obj().get()));
463 xLayout
.set(dynamic_cast<LwpVirtualLayout
*>(xObjHolder
->GetObject().obj().get()));
469 return rtl::Reference
<LwpVirtualLayout
>();
472 LwpHeadLayout::LwpHeadLayout(LwpObjectHeader
const& objHdr
, LwpSvStream
* pStrm
)
473 : LwpVirtualLayout(objHdr
, pStrm
)
477 void LwpHeadLayout::Read()
479 LwpVirtualLayout::Read();
480 //For PermissiveLayout
481 m_pObjStrm
->SkipExtra();
483 m_pObjStrm
->SkipExtra();
486 void LwpHeadLayout::RegisterStyle()
488 //Register all children styles
489 rtl::Reference
<LwpVirtualLayout
> xLayout(
490 dynamic_cast<LwpVirtualLayout
*>(GetChildHead().obj().get()));
491 o3tl::sorted_vector
<LwpVirtualLayout
*> aSeen
;
494 bool bAlreadySeen
= !aSeen
.insert(xLayout
.get()).second
;
496 throw std::runtime_error("loop in conversion");
497 xLayout
->SetFoundry(m_pFoundry
);
498 //if the layout is relative to para, the layout will be registered in para
499 if (!xLayout
->IsRelativeAnchored())
500 xLayout
->DoRegisterStyle();
501 rtl::Reference
<LwpVirtualLayout
> xNext(
502 dynamic_cast<LwpVirtualLayout
*>(xLayout
->GetNext().obj().get()));
508 * @descr find endnote supertable layout from the child layout list. Suppose that there is only one endnote supertablelayout in one division
509 * @return pointer to endnote supertable layout
511 rtl::Reference
<LwpVirtualLayout
> LwpHeadLayout::FindEnSuperTableLayout()
513 rtl::Reference
<LwpVirtualLayout
> xLayout(
514 dynamic_cast<LwpVirtualLayout
*>(GetChildHead().obj().get()));
515 o3tl::sorted_vector
<LwpVirtualLayout
*> aSeen
;
518 bool bAlreadySeen
= !aSeen
.insert(xLayout
.get()).second
;
520 throw std::runtime_error("loop in conversion");
521 if (xLayout
->GetLayoutType() == LWP_ENDNOTE_SUPERTABLE_LAYOUT
)
525 xLayout
.set(dynamic_cast<LwpVirtualLayout
*>(xLayout
->GetNext().obj().get()));
527 return rtl::Reference
<LwpVirtualLayout
>();
530 LwpLayoutStyle::LwpLayoutStyle()
531 : m_nStyleDefinition(0)
536 LwpLayoutStyle::~LwpLayoutStyle() {}
538 void LwpLayoutStyle::Read(LwpObjectStream
* pStrm
)
540 m_nStyleDefinition
= pStrm
->QuickReaduInt32();
541 m_aDescription
.Read(pStrm
);
542 if (pStrm
->CheckExtra())
544 m_nKey
= pStrm
->QuickReaduInt16();
549 LwpLayoutMisc::LwpLayoutMisc()
555 LwpLayoutMisc::~LwpLayoutMisc() {}
557 void LwpLayoutMisc::Read(LwpObjectStream
* pStrm
)
559 m_nGridType
= pStrm
->QuickReaduInt16();
560 m_nGridDistance
= pStrm
->QuickReadInt32();
561 m_aContentStyle
.Read(pStrm
);
565 LwpMiddleLayout::LwpMiddleLayout(LwpObjectHeader
const& objHdr
, LwpSvStream
* pStrm
)
566 : LwpVirtualLayout(objHdr
, pStrm
)
567 , m_bGettingGeometry(false)
568 , m_bGettingBackgroundStuff(false)
572 LwpMiddleLayout::~LwpMiddleLayout() {}
574 void LwpMiddleLayout::Read()
576 LwpObjectStream
* pStrm
= m_pObjStrm
.get();
578 LwpVirtualLayout::Read();
580 //skip CLiteLayout data;
581 LwpAtomHolder ContentClass
;
582 ContentClass
.Read(pStrm
);
585 // before layout hierarchy rework
586 if (LwpFileHeader::m_nFileRevision
< 0x000B)
589 m_Content
.ReadIndexed(pStrm
);
592 m_BasedOnStyle
.ReadIndexed(pStrm
);
593 m_TabPiece
.ReadIndexed(pStrm
);
595 sal_uInt8 nWhatsItGot
= pStrm
->QuickReaduInt8();
597 if (nWhatsItGot
& DISK_GOT_STYLE_STUFF
)
599 m_aStyleStuff
.Read(pStrm
);
601 if (nWhatsItGot
& DISK_GOT_MISC_STUFF
)
603 m_aMiscStuff
.Read(pStrm
);
606 m_LayGeometry
.ReadIndexed(pStrm
);
607 m_LayScale
.ReadIndexed(pStrm
);
608 m_LayMargins
.ReadIndexed(pStrm
);
609 m_LayBorderStuff
.ReadIndexed(pStrm
);
610 m_LayBackgroundStuff
.ReadIndexed(pStrm
);
612 if (pStrm
->CheckExtra())
614 m_LayExtBorderStuff
.ReadIndexed(pStrm
);
619 rtl::Reference
<LwpObject
> LwpMiddleLayout::GetBasedOnStyle() const
621 rtl::Reference
<LwpObject
> xRet(m_BasedOnStyle
.obj());
622 if (xRet
.get() == this)
624 SAL_WARN("lwp", "style based on itself");
625 return rtl::Reference
<LwpObject
>();
631 * @descr: Get the geometry of current layout
634 LwpLayoutGeometry
* LwpMiddleLayout::GetGeometry()
636 if (m_bGettingGeometry
)
637 throw std::runtime_error("recursion in layout");
638 m_bGettingGeometry
= true;
640 LwpLayoutGeometry
* pRet
= nullptr;
641 if (!m_LayGeometry
.IsNull())
643 pRet
= dynamic_cast<LwpLayoutGeometry
*>(m_LayGeometry
.obj().get());
647 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
648 if (LwpMiddleLayout
* pLay
= dynamic_cast<LwpMiddleLayout
*>(xBase
.get()))
650 pRet
= pLay
->GetGeometry();
654 m_bGettingGeometry
= false;
659 * @descr: Get layout height, measured by "cm"
662 double LwpMiddleLayout::GetGeometryHeight()
664 LwpLayoutGeometry
* pGeo
= GetGeometry();
667 return LwpTools::ConvertFromUnitsToMetric(pGeo
->GetHeight());
674 * @descr: Get layout width, measured by "cm"
677 double LwpMiddleLayout::GetGeometryWidth()
679 LwpLayoutGeometry
* pGeo
= GetGeometry();
682 return LwpTools::ConvertFromUnitsToMetric(pGeo
->GetWidth());
689 * @descr: Whether the margins is same as parent layout
692 bool LwpMiddleLayout::MarginsSameAsParent()
694 if (m_nOverrideFlag
& OVER_MARGINS
)
696 return LwpVirtualLayout::MarginsSameAsParent();
698 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
699 if (LwpVirtualLayout
* pLay
= dynamic_cast<LwpVirtualLayout
*>(xBase
.get()))
701 pLay
->GetMarginsSameAsParent();
703 return LwpVirtualLayout::MarginsSameAsParent();
708 * @param: nWhichSide - 0: left, 1: right, 2:top, 3: bottom
710 double LwpMiddleLayout::MarginsValue(sal_uInt8 nWhichSide
)
713 if ((nWhichSide
== MARGIN_LEFT
) || (nWhichSide
== MARGIN_RIGHT
))
715 if (GetMarginsSameAsParent())
717 rtl::Reference
<LwpVirtualLayout
> xParent(
718 dynamic_cast<LwpVirtualLayout
*>(GetParent().obj().get()));
719 if (xParent
.is() && !xParent
->IsHeader())
721 fValue
= xParent
->GetMarginsValue(nWhichSide
);
727 if (m_nOverrideFlag
& OVER_MARGINS
)
729 LwpLayoutMargins
* pMar1
= dynamic_cast<LwpLayoutMargins
*>(m_LayMargins
.obj().get());
732 fValue
= pMar1
->GetMargins().GetMarginsValue(nWhichSide
);
736 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
737 LwpVirtualLayout
* pStyle
= dynamic_cast<LwpVirtualLayout
*>(xBase
.get());
740 fValue
= pStyle
->GetMarginsValue(nWhichSide
);
743 return LwpVirtualLayout::MarginsValue(nWhichSide
);
746 * @descr: Get extmargin value
747 * @param: nWhichSide - 0: left, 1: right, 2:top, 3: bottom
751 double LwpMiddleLayout::ExtMarginsValue(sal_uInt8 nWhichSide
)
754 if (m_nOverrideFlag
& OVER_MARGINS
)
756 LwpLayoutMargins
* pMar1
= dynamic_cast<LwpLayoutMargins
*>(m_LayMargins
.obj().get());
759 fValue
= pMar1
->GetExtMargins().GetMarginsValue(nWhichSide
);
763 LwpVirtualLayout
* pStyle
= dynamic_cast<LwpVirtualLayout
*>(GetBasedOnStyle().get());
766 fValue
= pStyle
->GetExtMarginsValue(nWhichSide
);
769 return LwpVirtualLayout::ExtMarginsValue(nWhichSide
);
772 * @descr: Get the LwpBorderStuff object according to m_LayBorderStuff id.
774 LwpBorderStuff
* LwpMiddleLayout::GetBorderStuff()
776 if (m_bGettingBorderStuff
)
777 throw std::runtime_error("recursion in layout");
778 m_bGettingBorderStuff
= true;
780 LwpBorderStuff
* pRet
= nullptr;
782 if (m_nOverrideFlag
& OVER_BORDERS
)
784 LwpLayoutBorder
* pLayoutBorder
785 = dynamic_cast<LwpLayoutBorder
*>(m_LayBorderStuff
.obj().get());
786 pRet
= pLayoutBorder
? &pLayoutBorder
->GetBorderStuff() : nullptr;
790 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
791 if (LwpMiddleLayout
* pLay
= dynamic_cast<LwpMiddleLayout
*>(xBase
.get()))
793 pRet
= pLay
->GetBorderStuff();
797 m_bGettingBorderStuff
= false;
802 * @descr: Get LwpBackgroundStuff object according to m_LayBackgroundStuff id;
804 LwpBackgroundStuff
* LwpMiddleLayout::GetBackgroundStuff()
806 if (m_bGettingBackgroundStuff
)
807 throw std::runtime_error("recursion in layout");
808 m_bGettingBackgroundStuff
= true;
810 LwpBackgroundStuff
* pRet
= nullptr;
812 if (m_nOverrideFlag
& OVER_BACKGROUND
)
814 LwpLayoutBackground
* pLayoutBackground
815 = dynamic_cast<LwpLayoutBackground
*>(m_LayBackgroundStuff
.obj().get());
816 pRet
= pLayoutBackground
? &pLayoutBackground
->GetBackgoudStuff() : nullptr;
820 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
821 if (LwpMiddleLayout
* pLay
= dynamic_cast<LwpMiddleLayout
*>(xBase
.get()))
823 pRet
= pLay
->GetBackgroundStuff();
827 m_bGettingBackgroundStuff
= false;
832 * @descr: create xfborder.
834 std::unique_ptr
<XFBorders
> LwpMiddleLayout::GetXFBorders()
836 LwpBorderStuff
* pBorderStuff
= GetBorderStuff();
837 if (pBorderStuff
&& pBorderStuff
->GetSide() != 0)
839 //copy from lwpparastyle.
840 std::unique_ptr
<XFBorders
> xXFBorders(new XFBorders
);
841 // apply 4 borders respectively
842 LwpBorderStuff::BorderType
const pType
[] = { LwpBorderStuff::LEFT
, LwpBorderStuff::RIGHT
,
843 LwpBorderStuff::TOP
, LwpBorderStuff::BOTTOM
};
845 for (LwpBorderStuff::BorderType nC
: pType
)
847 if (pBorderStuff
->HasSide(nC
))
849 LwpParaStyle::ApplySubBorder(pBorderStuff
, nC
, xXFBorders
.get());
858 * @descr: Get text direction settings.
860 enumXFTextDir
LwpMiddleLayout::GetTextDirection()
862 enumXFTextDir eTextDir
= enumXFTextDirNone
;
863 sal_uInt8 nDirection
= GetContentOrientation();
866 case TEXT_ORIENT_LRTB
:
868 eTextDir
= enumXFTextDirLR_TB
;
871 case TEXT_ORIENT_TBRL
:
873 eTextDir
= enumXFTextDirTB_RL
;
876 case TEXT_ORIENT_RLBT
: // not supported now
878 eTextDir
= enumXFTextDirNone
;
881 case TEXT_ORIENT_BTLR
: // not supported now
883 eTextDir
= enumXFTextDirNone
;
892 * @descr: Get background color.
894 LwpColor
* LwpMiddleLayout::GetBackColor()
896 LwpBackgroundStuff
* pBackgroundStuff
= GetBackgroundStuff();
897 if (pBackgroundStuff
&& !pBackgroundStuff
->IsTransparent())
899 LwpColor
* pColor
= pBackgroundStuff
->GetFillColor();
900 if (pColor
->IsValidColor())
909 * @descr: Add back color settings into xfpagemaster.
911 LwpTabOverride
* LwpMiddleLayout::GetTabOverride()
913 if (m_nAttributes
& OVER_TABS
)
915 if (!m_TabPiece
.IsNull())
917 LwpTabPiece
* pPiece
= dynamic_cast<LwpTabPiece
*>(m_TabPiece
.obj().get());
918 return static_cast<LwpTabOverride
*>(pPiece
? pPiece
->GetOverride() : nullptr);
924 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
925 if (LwpMiddleLayout
* pLay
= dynamic_cast<LwpMiddleLayout
*>(xBase
.get()))
927 return pLay
->GetTabOverride();
934 * @descr: Layscale for graphic & watermark
936 sal_uInt16
LwpMiddleLayout::GetScaleMode()
938 if ((m_nOverrideFlag
& OVER_SCALING
) && m_LayScale
.obj().is() && GetLayoutScale())
939 return GetLayoutScale()->GetScaleMode();
940 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
942 return dynamic_cast<LwpMiddleLayout
&>(*xBase
).GetScaleMode();
944 return (LwpLayoutScale::FIT_IN_FRAME
| LwpLayoutScale::MAINTAIN_ASPECT_RATIO
);
947 sal_uInt16
LwpMiddleLayout::GetScaleTile()
949 if ((m_nOverrideFlag
& OVER_SCALING
) && m_LayScale
.obj().is() && GetLayoutScale())
950 return (GetLayoutScale()->GetPlacement() & LwpLayoutScale::TILED
) ? 1 : 0;
951 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
953 return dynamic_cast<LwpMiddleLayout
&>(*xBase
).GetScaleTile();
958 sal_uInt16
LwpMiddleLayout::GetScaleCenter()
960 if (m_bGettingScaleCenter
)
961 throw std::runtime_error("recursion in layout");
962 m_bGettingScaleCenter
= true;
966 if ((m_nOverrideFlag
& OVER_SCALING
) && m_LayScale
.obj().is() && GetLayoutScale())
968 nRet
= (GetLayoutScale()->GetPlacement() & LwpLayoutScale::CENTERED
) ? 1 : 0;
972 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
974 nRet
= dynamic_cast<LwpMiddleLayout
&>(*xBase
).GetScaleCenter();
977 m_bGettingScaleCenter
= false;
981 bool LwpMiddleLayout::CanSizeRight()
983 sal_uInt8 RelType
= GetRelativeType();
985 return !(RelType
== LwpLayoutRelativityGuts::LAY_INLINE
986 || RelType
== LwpLayoutRelativityGuts::LAY_PARA_RELATIVE
987 || RelType
== LwpLayoutRelativityGuts::LAY_INLINE_VERTICAL
);
989 sal_Int32
LwpMiddleLayout::GetMinimumWidth()
991 if (((m_nAttributes3
& STYLE3_WIDTHVALID
) != 0) && GetGeometry())
993 return GetGeometry()->GetWidth();
995 else if (m_nOverrideFlag
& OVER_SIZE
)
997 return DetermineWidth();
1001 sal_Int32
LwpMiddleLayout::DetermineWidth()
1003 if (IsSizeRightToContent())
1007 else if (IsSizeRightToContainer())
1011 else if (LwpLayoutGeometry
* pGeo
= GetGeometry())
1013 m_nAttributes3
|= STYLE3_WIDTHVALID
;
1014 return pGeo
->GetWidth();
1018 bool LwpMiddleLayout::IsSizeRightToContainer()
1020 if (!CanSizeRight())
1023 if (m_nOverrideFlag
& OVER_SIZE
)
1025 return (m_nDirection
& ((LAY_USEDIRECTION
| LAY_AUTOSIZE
| LAY_TOCONTAINER
) << SHIFT_RIGHT
))
1026 == ((LAY_USEDIRECTION
| LAY_TOCONTAINER
| LAY_AUTOSIZE
) << SHIFT_RIGHT
);
1028 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1031 LwpMiddleLayout
* pLayout
= dynamic_cast<LwpMiddleLayout
*>(xBase
.get());
1032 return pLayout
&& pLayout
->IsSizeRightToContainer();
1037 bool LwpMiddleLayout::IsSizeRightToContent()
1039 if (!CanSizeRight())
1042 if (m_nOverrideFlag
& OVER_SIZE
)
1044 return (m_nDirection
& ((LAY_USEDIRECTION
| LAY_AUTOSIZE
| LAY_TOCONTAINER
) << SHIFT_RIGHT
))
1045 == ((LAY_USEDIRECTION
| LAY_AUTOSIZE
) << SHIFT_RIGHT
);
1047 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1050 LwpMiddleLayout
* pLayout
= dynamic_cast<LwpMiddleLayout
*>(xBase
.get());
1051 return pLayout
&& pLayout
->IsSizeRightToContent();
1058 * @descr: Get layout height
1061 double LwpMiddleLayout::GetHeight() { return GetGeometryHeight(); }
1064 * @descr: Get layout height
1067 double LwpMiddleLayout::GetWidth() { return GetGeometryWidth(); }
1069 * @descr: Get layout origin point
1072 LwpPoint
LwpMiddleLayout::GetOrigin()
1074 LwpLayoutGeometry
* pGeo
= GetGeometry();
1077 sal_uInt8 nType
= GetRelativeType();
1078 if (nType
== LwpLayoutRelativityGuts::LAY_INLINE
1079 || nType
== LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE
)
1081 return pGeo
->GetAbsoluteOrigin();
1084 return pGeo
->GetOrigin();
1091 * @descr: Whether the fill is pattern fill or not
1092 * @return: True if yes, false if not.
1094 bool LwpMiddleLayout::IsPatternFill()
1096 LwpBackgroundStuff
* pBackgroundStuff
= GetBackgroundStuff();
1097 if (pBackgroundStuff
)
1099 return pBackgroundStuff
->IsPatternFill();
1106 * @descr: Get the fill pattern style. Data are saved in a XFBGImage object
1107 * @return: the fill pattern style.
1109 std::unique_ptr
<XFBGImage
> LwpMiddleLayout::GetFillPattern()
1111 LwpBackgroundStuff
* pBackgroundStuff
= GetBackgroundStuff();
1112 if (pBackgroundStuff
)
1114 return pBackgroundStuff
->GetFillPattern();
1117 return std::unique_ptr
<XFBGImage
>();
1121 * @descr: Whether the height and width of layout is auto grow
1124 bool LwpMiddleLayout::IsAutoGrow()
1126 if (m_nOverrideFlag
& OVER_SIZE
)
1128 return (m_nDirection
1129 & ((LAY_AUTOGROW
<< SHIFT_UP
) | (LAY_AUTOGROW
<< SHIFT_DOWN
)
1130 | (LAY_AUTOGROW
<< SHIFT_RIGHT
) | (LAY_AUTOGROW
<< SHIFT_LEFT
)))
1135 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1136 if (LwpMiddleLayout
* pLay
= dynamic_cast<LwpMiddleLayout
*>(xBase
.get()))
1138 return pLay
->IsAutoGrow();
1141 return LwpVirtualLayout::IsAutoGrow();
1145 * @descr: Whether the height of layout is auto grow down
1148 bool LwpMiddleLayout::IsAutoGrowDown()
1150 if (m_nOverrideFlag
& OVER_SIZE
)
1152 return (m_nDirection
& (LAY_AUTOGROW
<< SHIFT_DOWN
)) != 0;
1156 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1157 if (LwpMiddleLayout
* pLay
= dynamic_cast<LwpMiddleLayout
*>(xBase
.get()))
1159 return pLay
->GetIsAutoGrowDown();
1162 return LwpVirtualLayout::IsAutoGrowDown();
1166 * @descr: Whether the height of layout is auto grow up
1169 bool LwpMiddleLayout::IsAutoGrowUp()
1171 if (m_bGettingAutoGrowUp
)
1172 throw std::runtime_error("recursion in layout");
1173 m_bGettingAutoGrowUp
= true;
1177 if (m_nOverrideFlag
& OVER_SIZE
)
1179 bRet
= (m_nDirection
& (LAY_AUTOGROW
<< SHIFT_UP
)) != 0;
1183 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1184 if (LwpMiddleLayout
* pLay
= dynamic_cast<LwpMiddleLayout
*>(xBase
.get()))
1185 bRet
= pLay
->IsAutoGrowUp();
1187 bRet
= LwpVirtualLayout::IsAutoGrowUp();
1190 m_bGettingAutoGrowUp
= false;
1195 * @descr: Whether the height of layout is auto grow down
1198 bool LwpMiddleLayout::IsAutoGrowLeft()
1200 if (m_nOverrideFlag
& OVER_SIZE
)
1202 return (m_nDirection
& (LAY_AUTOGROW
<< SHIFT_LEFT
)) != 0;
1206 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1207 if (LwpMiddleLayout
* pLay
= dynamic_cast<LwpMiddleLayout
*>(xBase
.get()))
1209 return pLay
->IsAutoGrowLeft();
1212 return LwpVirtualLayout::IsAutoGrowLeft();
1216 * @descr: Whether the height of layout is auto grow down
1219 bool LwpMiddleLayout::IsAutoGrowRight()
1221 if (m_nOverrideFlag
& OVER_SIZE
)
1223 return (m_nDirection
& (LAY_AUTOGROW
<< SHIFT_RIGHT
)) != 0;
1227 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1228 if (LwpMiddleLayout
* pLay
= dynamic_cast<LwpMiddleLayout
*>(xBase
.get()))
1230 return pLay
->IsAutoGrowRight();
1233 return LwpVirtualLayout::IsAutoGrowRight();
1237 * @descr: Get contents orientation
1240 sal_uInt8
LwpMiddleLayout::GetContentOrientation()
1242 //content orientation in Graphic objects and OLE objects not supported now
1243 if ((m_nOverrideFlag
& OVER_ROTATION
) && !m_LayGeometry
.IsNull())
1245 LwpLayoutGeometry
* pLayGeometry
1246 = dynamic_cast<LwpLayoutGeometry
*>(m_LayGeometry
.obj().get());
1248 return pLayGeometry
->GetContentOrientation();
1252 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1253 if (LwpMiddleLayout
* pLay
= dynamic_cast<LwpMiddleLayout
*>(xBase
.get()))
1255 return pLay
->GetContentOrientation();
1258 return LwpVirtualLayout::GetContentOrientation();
1262 * @descr: Whether it is honoring protection
1265 bool LwpMiddleLayout::HonorProtection()
1267 if (m_nOverrideFlag
& OVER_MISC
)
1269 if (!(m_nAttributes2
& STYLE2_HONORPROTECTION
))
1272 rtl::Reference
<LwpVirtualLayout
> xParent(
1273 dynamic_cast<LwpVirtualLayout
*>(GetParent().obj().get()));
1274 if (xParent
.is() && !xParent
->IsHeader())
1276 return xParent
->GetHonorProtection();
1279 if (m_pFoundry
) //is null now
1281 LwpDocument
* pDoc
= m_pFoundry
->GetDocument();
1284 return pDoc
->GetHonorProtection();
1290 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1291 if (LwpMiddleLayout
* pLay
= dynamic_cast<LwpMiddleLayout
*>(xBase
.get()))
1293 return pLay
->GetHonorProtection();
1297 return LwpVirtualLayout::HonorProtection();
1301 * @descr: Whether it is protected
1304 bool LwpMiddleLayout::IsProtected()
1306 bool bProtected
= false;
1307 if (m_nOverrideFlag
& OVER_MISC
)
1309 bProtected
= (m_nAttributes
& STYLE_PROTECTED
) != 0;
1313 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1314 if (LwpMiddleLayout
* pLay
= dynamic_cast<LwpMiddleLayout
*>(xBase
.get()))
1316 bProtected
= pLay
->GetIsProtected();
1319 bProtected
= LwpVirtualLayout::IsProtected();
1322 rtl::Reference
<LwpVirtualLayout
> xParent(
1323 dynamic_cast<LwpVirtualLayout
*>(GetParent().obj().get()));
1324 if (xParent
.is() && !xParent
->IsHeader())
1326 /* If a parent's protected then none of its children can be accessed. */
1327 if (xParent
->GetIsProtected())
1330 if (xParent
->GetHonorProtection())
1333 /* If our parent isn't honoring protection then we aren't protected. */
1336 if (m_pFoundry
) //is null now
1338 LwpDocument
* pDoc
= m_pFoundry
->GetDocument();
1341 if (pDoc
->GetHonorProtection())
1344 /* If the document isn't honoring protection then we aren't protected.*/
1353 * @descr: Get watermark layout
1356 rtl::Reference
<LwpVirtualLayout
> LwpMiddleLayout::GetWaterMarkLayout()
1358 rtl::Reference
<LwpVirtualLayout
> xLay(
1359 dynamic_cast<LwpVirtualLayout
*>(GetChildHead().obj().get()));
1360 o3tl::sorted_vector
<LwpVirtualLayout
*> aSeen
;
1363 bool bAlreadySeen
= !aSeen
.insert(xLay
.get()).second
;
1365 throw std::runtime_error("loop in conversion");
1366 if (xLay
->IsForWaterMark())
1370 rtl::Reference
<LwpVirtualLayout
> xNext(
1371 dynamic_cast<LwpVirtualLayout
*>(xLay
->GetNext().obj().get()));
1374 return rtl::Reference
<LwpVirtualLayout
>();
1378 * @descr: Create and return xfbgimage object for watermark
1381 std::unique_ptr
<XFBGImage
> LwpMiddleLayout::GetXFBGImage()
1383 std::unique_ptr
<XFBGImage
> xXFBGImage
;
1385 rtl::Reference
<LwpVirtualLayout
> xWaterMarkLayout(GetWaterMarkLayout());
1386 LwpMiddleLayout
* pLay
= dynamic_cast<LwpMiddleLayout
*>(xWaterMarkLayout
.get());
1390 LwpGraphicObject
* pGrfObj
= dynamic_cast<LwpGraphicObject
*>(pLay
->GetContent().obj().get());
1393 xXFBGImage
.reset(new XFBGImage
);
1394 if (pGrfObj
->IsLinked())
1397 OUString linkedfilepath
= pGrfObj
->GetLinkedFilePath();
1398 OUString fileURL
= LwpTools::convertToFileUrl(
1399 OUStringToOString(linkedfilepath
, osl_getThreadTextEncoding()));
1400 xXFBGImage
->SetFileLink(fileURL
);
1404 std::vector
<sal_uInt8
> aGrafData
= pGrfObj
->GetRawGrafData();
1405 xXFBGImage
->SetImageData(aGrafData
.data(), aGrafData
.size());
1408 //automatic, top left
1409 xXFBGImage
->SetPosition(enumXFAlignStart
, enumXFAlignTop
);
1410 if (pLay
->GetScaleCenter())
1413 xXFBGImage
->SetPosition();
1415 else if (pLay
->GetScaleTile())
1418 xXFBGImage
->SetRepeate();
1420 //fit type, area type
1421 if ((pLay
->GetScaleMode() & LwpLayoutScale::FIT_IN_FRAME
) != 0)
1423 if ((pLay
->GetScaleMode() & LwpLayoutScale::MAINTAIN_ASPECT_RATIO
) == 0)
1425 xXFBGImage
->SetStretch();
1434 * @descr: Whether the page uses the printer setting
1437 bool LwpMiddleLayout::GetUsePrinterSettings()
1439 if (m_bGettingUsePrinterSettings
)
1440 throw std::runtime_error("recursion in layout");
1441 m_bGettingUsePrinterSettings
= true;
1445 if (m_nOverrideFlag
& OVER_SIZE
)
1447 bRet
= (m_nAttributes3
& STYLE3_USEPRINTERSETTINGS
) != 0;
1451 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1452 if (LwpMiddleLayout
* pLay
= dynamic_cast<LwpMiddleLayout
*>(xBase
.get()))
1454 bRet
= pLay
->GetUsePrinterSettings();
1458 m_bGettingUsePrinterSettings
= false;
1462 //Check whether there are contents in the layout
1463 bool LwpMiddleLayout::HasContent()
1465 rtl::Reference
<LwpObject
> content
= m_Content
.obj();
1466 return content
.is();
1469 LwpLayout::LwpLayout(LwpObjectHeader
const& objHdr
, LwpSvStream
* pStrm
)
1470 : LwpMiddleLayout(objHdr
, pStrm
)
1471 , m_bGettingShadow(false)
1472 , m_bGettingNumCols(false)
1476 LwpLayout::~LwpLayout() {}
1478 void LwpLayout::Read()
1480 LwpObjectStream
* pStrm
= m_pObjStrm
.get();
1482 LwpMiddleLayout::Read();
1483 if (LwpFileHeader::m_nFileRevision
< 0x000B)
1485 // read PreRevBLayout...
1489 sal_uInt16 nSimple
= pStrm
->QuickReaduInt16();
1493 m_aUseWhen
.Read(pStrm
);
1495 sal_uInt8 nFlag
= pStrm
->QuickReaduInt8();
1497 m_Position
.ReadIndexed(pStrm
);
1500 m_LayColumns
.ReadIndexed(pStrm
);
1501 m_LayGutterStuff
.ReadIndexed(pStrm
);
1502 m_LayJoinStuff
.ReadIndexed(pStrm
);
1503 m_LayShadow
.ReadIndexed(pStrm
);
1505 if (pStrm
->CheckExtra())
1507 m_LayExtJoinStuff
.ReadIndexed(pStrm
);
1514 * @descr: Get columns number
1517 sal_uInt16
LwpLayout::GetNumCols()
1519 if (m_bGettingNumCols
)
1520 throw std::runtime_error("recursion in layout");
1521 m_bGettingNumCols
= true;
1523 sal_uInt16 nRet
= 0;
1524 LwpLayoutColumns
* pLayColumns
= (m_nOverrideFlag
& OVER_COLUMNS
)
1525 ? dynamic_cast<LwpLayoutColumns
*>(m_LayColumns
.obj().get())
1529 nRet
= pLayColumns
->GetNumCols();
1533 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1534 LwpVirtualLayout
* pStyle
= dynamic_cast<LwpVirtualLayout
*>(xBase
.get());
1535 nRet
= pStyle
? pStyle
->GetNumCols() : LwpVirtualLayout::GetNumCols();
1537 m_bGettingNumCols
= false;
1542 * @descr: Get gap between columns
1543 * @param: the order of column
1545 double LwpLayout::GetColGap(sal_uInt16 nIndex
)
1547 if ((m_nOverrideFlag
& OVER_COLUMNS
) || (m_nAttributes2
& STYLE2_LOCALCOLUMNINFO
))
1549 LwpLayoutColumns
* pLayColumns
= dynamic_cast<LwpLayoutColumns
*>(m_LayColumns
.obj().get());
1552 return pLayColumns
->GetColGap(nIndex
);
1556 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1557 LwpVirtualLayout
* pStyle
= dynamic_cast<LwpVirtualLayout
*>(xBase
.get());
1560 return pStyle
->GetColGap(nIndex
);
1563 return LwpVirtualLayout::GetColGap(nIndex
);
1567 * @descr: Create and return XFColumns object
1570 XFColumns
* LwpLayout::GetXFColumns()
1572 //if there is only one column, do not need insert columns
1573 sal_uInt16 nCols
= GetNumCols();
1579 std::unique_ptr
<XFColumns
> xColumns(new XFColumns
);
1581 std::unique_ptr
<XFColumnSep
> xColumnSep(GetColumnSep());
1584 xColumns
->SetSeparator(*xColumnSep
);
1587 //set column count and column gap
1588 xColumns
->SetCount(nCols
);
1589 double fGap
= GetColGap(0);
1590 xColumns
->SetGap(fGap
);
1593 for (sal_uInt16 nIndex
= 0; nIndex
< nCols
; nIndex
++)
1596 sal_Int32 nWidth
= 8305 / nCols
; //relative width
1597 aColumn
.SetRelWidth(nWidth
);
1599 //the left and right margins is 0;
1600 double nGap
= GetColGap(nIndex
) / 2;
1601 aColumn
.SetMargins(nGap
, nGap
);
1604 aColumn
.SetMargins(0, nGap
);
1606 if (nIndex
== (nCols
- 1))
1608 aColumn
.SetMargins(nGap
, 0);
1610 xColumns
->AddColumn(aColumn
);
1613 return xColumns
.release();
1617 * @descr: Create and return XFColumnSep object
1620 XFColumnSep
* LwpLayout::GetColumnSep()
1622 //Get LwpLayoutGutters
1623 LwpLayoutGutters
* pLayoutGutters
1624 = dynamic_cast<LwpLayoutGutters
*>(m_LayGutterStuff
.obj().get());
1625 if (!pLayoutGutters
)
1630 LwpBorderStuff
& rBorderStuff
= pLayoutGutters
->GetBorderStuff();
1632 LwpBorderStuff::BorderType eType
= LwpBorderStuff::LEFT
;
1633 LwpColor aColor
= rBorderStuff
.GetSideColor(eType
);
1634 double fWidth
= rBorderStuff
.GetSideWidth(eType
);
1635 //sal_uInt16 nType = rBorderStuff->GetSideType(eType);
1637 XFColumnSep
* pColumnSep
= new XFColumnSep();
1638 XFColor
aXFColor(aColor
.To24Color());
1639 pColumnSep
->SetColor(aXFColor
);
1640 pColumnSep
->SetWidth(fWidth
);
1641 pColumnSep
->SetRelHeight(100);
1642 pColumnSep
->SetVerticalAlign(enumXFAlignTop
);
1648 * @descr: Get use when type
1651 LwpLayout::UseWhenType
LwpLayout::GetUseWhenType()
1653 UseWhenType eType
= StartWithinPage
;
1654 LwpUseWhen
* pUseWhen
= GetUseWhen();
1657 if (pUseWhen
->IsStartOnThisHF())
1659 eType
= StartWithinColume
;
1661 else if (pUseWhen
->IsStartOnThisPage())
1663 eType
= StartWithinPage
;
1665 else if (pUseWhen
->IsStartOnNextPage())
1667 eType
= StartOnNextPage
;
1669 else if (pUseWhen
->IsStartOnNextOddPage())
1671 eType
= StartOnOddPage
;
1673 else if (pUseWhen
->IsStartOnNextEvenPage())
1675 eType
= StartOnEvenPage
;
1680 eType
= StartOnNextPage
;
1686 * @descr: Get use page
1689 sal_uInt16
LwpLayout::GetUsePage()
1691 if (m_nOverrideFlag
& OVER_PLACEMENT
)
1693 LwpUseWhen
* pUseWhen
= GetUseWhen();
1695 return pUseWhen
->GetUsePage();
1701 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1702 if (LwpLayout
* pLay
= dynamic_cast<LwpLayout
*>(xBase
.get()))
1704 return pLay
->GetUsePage();
1711 * @descr: Get usewhen pointer
1714 LwpUseWhen
* LwpLayout::VirtualGetUseWhen()
1716 if (m_nOverrideFlag
& OVER_PLACEMENT
)
1722 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1723 if (LwpLayout
* pLay
= dynamic_cast<LwpLayout
*>(xBase
.get()))
1725 return pLay
->VirtualGetUseWhen();
1728 return LwpVirtualLayout::VirtualGetUseWhen();
1732 * @descr: Whether it is use on all pages
1735 bool LwpLayout::IsUseOnAllPages()
1737 if (m_nOverrideFlag
& OVER_PLACEMENT
)
1739 LwpUseWhen
* pUseWhen
= GetUseWhen();
1741 return pUseWhen
->IsUseOnAllPages();
1747 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1748 if (LwpLayout
* pLay
= dynamic_cast<LwpLayout
*>(xBase
.get()))
1750 return pLay
->IsUseOnAllPages();
1753 return LwpVirtualLayout::IsUseOnAllPages();
1757 * @descr: Whether it is use on all even pages
1760 bool LwpLayout::IsUseOnAllEvenPages()
1762 if (m_nOverrideFlag
& OVER_PLACEMENT
)
1764 LwpUseWhen
* pUseWhen
= GetUseWhen();
1766 return pUseWhen
->IsUseOnAllEvenPages();
1772 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1773 if (LwpLayout
* pLay
= dynamic_cast<LwpLayout
*>(xBase
.get()))
1775 return pLay
->IsUseOnAllEvenPages();
1778 return LwpVirtualLayout::IsUseOnAllEvenPages();
1782 * @descr: Whether it is use on all odd pages
1785 bool LwpLayout::IsUseOnAllOddPages()
1787 if (m_nOverrideFlag
& OVER_PLACEMENT
)
1789 LwpUseWhen
* pUseWhen
= GetUseWhen();
1791 return pUseWhen
->IsUseOnAllOddPages();
1797 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1798 if (LwpLayout
* pLay
= dynamic_cast<LwpLayout
*>(xBase
.get()))
1800 return pLay
->IsUseOnAllOddPages();
1803 return LwpVirtualLayout::IsUseOnAllOddPages();
1807 * @descr: Whether it is use on current page
1810 bool LwpLayout::IsUseOnPage()
1812 if (m_nOverrideFlag
& OVER_PLACEMENT
)
1814 LwpUseWhen
* pUseWhen
= GetUseWhen();
1816 return pUseWhen
->IsUseOnPage();
1822 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1823 if (LwpLayout
* pLay
= dynamic_cast<LwpLayout
*>(xBase
.get()))
1825 return pLay
->IsUseOnPage();
1828 return LwpVirtualLayout::IsUseOnPage();
1832 * @descr: Get the LwpShadow object according to m_LayShadow id.
1834 LwpShadow
* LwpLayout::GetShadow()
1836 if (m_bGettingShadow
)
1837 throw std::runtime_error("recursion in layout");
1838 m_bGettingShadow
= true;
1839 LwpShadow
* pRet
= nullptr;
1840 if (m_nOverrideFlag
& OVER_SHADOW
)
1842 LwpLayoutShadow
* pLayoutShadow
= dynamic_cast<LwpLayoutShadow
*>(m_LayShadow
.obj().get());
1843 pRet
= pLayoutShadow
? &pLayoutShadow
->GetShadow() : nullptr;
1847 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1848 if (LwpLayout
* pLay
= dynamic_cast<LwpLayout
*>(xBase
.get()))
1850 pRet
= pLay
->GetShadow();
1853 m_bGettingShadow
= false;
1858 * @descr: create xfshadow
1860 XFShadow
* LwpLayout::GetXFShadow()
1862 LwpShadow
* pShadow
= GetShadow();
1865 LwpColor color
= pShadow
->GetColor();
1866 double offsetX
= pShadow
->GetOffsetX();
1867 double offsetY
= pShadow
->GetOffsetY();
1869 if (!offsetX
|| !offsetY
|| !color
.IsValidColor())
1871 XFShadow
* pXFShadow
= new XFShadow();
1872 enumXFShadowPos eXFShadowPos
= enumXFShadowLeftTop
;
1885 eXFShadowPos
= enumXFShadowLeftTop
;
1887 eXFShadowPos
= enumXFShadowLeftBottom
;
1893 eXFShadowPos
= enumXFShadowRightTop
;
1895 eXFShadowPos
= enumXFShadowRightBottom
;
1898 pXFShadow
->SetPosition(eXFShadowPos
);
1899 pXFShadow
->SetOffset(fOffset
);
1900 pXFShadow
->SetColor(XFColor(color
.To24Color()));
1906 * @descr get the layout that containers the current frame layout
1909 rtl::Reference
<LwpVirtualLayout
> LwpLayout::GetContainerLayout()
1911 if (IsRelativeAnchored())
1914 LwpPara
* pPara
= dynamic_cast<LwpPara
*>(GetPosition().obj().get());
1917 LwpStory
* pStory
= pPara
->GetStory();
1918 return pStory
? pStory
->GetTabLayout() : nullptr;
1921 return GetParentLayout();
1924 LwpPlacableLayout::LwpPlacableLayout(LwpObjectHeader
const& objHdr
, LwpSvStream
* pStrm
)
1925 : LwpLayout(objHdr
, pStrm
)
1926 , m_bGettingWrapType(false)
1927 , m_bGettingLayoutRelativity(false)
1930 , m_nBaseLineOffset(0)
1934 LwpPlacableLayout::~LwpPlacableLayout() {}
1936 void LwpPlacableLayout::Read()
1938 LwpObjectStream
* pStrm
= m_pObjStrm
.get();
1940 if (LwpFileHeader::m_nFileRevision
< 0x000B)
1946 sal_uInt16 simple
= pStrm
->QuickReaduInt16();
1949 m_nWrapType
= pStrm
->QuickReaduInt8();
1950 m_nBuoyancy
= pStrm
->QuickReaduInt8();
1951 m_nBaseLineOffset
= pStrm
->QuickReadInt32();
1952 m_Script
.Read(pStrm
);
1956 m_nWrapType
= LAY_WRAP_AROUND
;
1957 m_nBuoyancy
= LAY_BUOYNEUTRAL
;
1958 m_nBaseLineOffset
= 0;
1960 m_LayRelativity
.ReadIndexed(pStrm
);
1961 if (pStrm
->CheckExtra())
1963 sal_uInt16 count
= pStrm
->QuickReaduInt16();
1966 // temporarily added by to avoid assertion
1979 * @descr: get wrap type
1981 sal_uInt8
LwpPlacableLayout::GetWrapType()
1983 if (m_bGettingWrapType
)
1984 throw std::runtime_error("recursion in layout");
1985 m_bGettingWrapType
= true;
1986 sal_uInt8 nWrapType
= LAY_WRAP_AROUND
;
1987 if (m_nOverrideFlag
& OVER_PLACEMENT
)
1989 nWrapType
= m_nWrapType
;
1993 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
1994 if (LwpPlacableLayout
* pLay
= dynamic_cast<LwpPlacableLayout
*>(xBase
.get()))
1996 nWrapType
= pLay
->GetWrapType();
1999 m_bGettingWrapType
= false;
2003 * @descr: get LayoutRelativity
2005 LwpLayoutRelativity
* LwpPlacableLayout::GetRelativityPiece()
2007 if (m_bGettingLayoutRelativity
)
2008 throw std::runtime_error("recursion in layout");
2009 m_bGettingLayoutRelativity
= true;
2010 LwpLayoutRelativity
* pRet
= nullptr;
2011 if (!m_LayRelativity
.IsNull())
2013 if (m_nOverrideFlag
& OVER_PLACEMENT
)
2015 pRet
= dynamic_cast<LwpLayoutRelativity
*>(m_LayRelativity
.obj().get());
2020 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
2021 if (LwpPlacableLayout
* pLay
= dynamic_cast<LwpPlacableLayout
*>(xBase
.get()))
2023 pRet
= pLay
->GetRelativityPiece();
2026 m_bGettingLayoutRelativity
= false;
2030 * @descr: Get relative type
2033 sal_uInt8
LwpPlacableLayout::GetRelativeType()
2035 LwpLayoutRelativity
* pLayRel
= GetRelativityPiece();
2038 return pLayRel
->GetRelGuts().GetRelativeType();
2040 return LwpVirtualLayout::GetRelativeType();
2043 * @descr: Get offset from the baseline
2046 sal_Int32
LwpPlacableLayout::GetBaseLineOffset()
2048 /* The baseline is only valid if this is flow-with-text */
2049 if (GetRelativeType() != LwpLayoutRelativityGuts::LAY_INLINE
)
2054 // First, ask our content if it has a baseline, ignore now
2056 if (Content && Content->GetBaseLineOffset(&Baseline))
2060 if (m_nOverrideFlag
& OVER_PLACEMENT
)
2062 return m_nBaseLineOffset
;
2066 rtl::Reference
<LwpObject
> xBase(GetBasedOnStyle());
2067 if (LwpPlacableLayout
* pLay
= dynamic_cast<LwpPlacableLayout
*>(xBase
.get()))
2069 return pLay
->GetBaseLineOffset();
2075 * @descr: whether the parent layout is page layout
2078 bool LwpPlacableLayout::IsAnchorPage()
2080 if (IsRelativeAnchored())
2083 rtl::Reference
<LwpVirtualLayout
> xLayout
= GetParentLayout();
2084 return xLayout
.is() && (xLayout
->IsPage() || xLayout
->IsHeader() || xLayout
->IsFooter());
2087 * @descr: whether the parent layout is frame layout
2090 bool LwpPlacableLayout::IsAnchorFrame()
2092 if (IsRelativeAnchored())
2095 rtl::Reference
<LwpVirtualLayout
> xLayout
= GetParentLayout();
2096 return xLayout
.is() && (xLayout
->IsFrame() || xLayout
->IsGroupHead());
2099 * @descr: whether the parent layout is cell layout
2102 bool LwpPlacableLayout::IsAnchorCell()
2104 if (IsRelativeAnchored())
2107 rtl::Reference
<LwpVirtualLayout
> xLayout
= GetParentLayout();
2108 return xLayout
.is() && xLayout
->IsCell();
2112 * @descr: Set font style for setting position of frame
2115 void LwpPlacableLayout::SetFont(rtl::Reference
<XFFont
> const& pFont
) { m_pFont
= pFont
; }
2117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */