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 * the class for VO_FrameLayout
59 ************************************************************************/
60 /*************************************************************************
63 ************************************************************************/
64 #include "lwpframelayout.hxx"
65 #include "lwppara.hxx"
66 #include "xfilter/xfstylemanager.hxx"
67 #include "xfilter/xfparagraph.hxx"
68 #include "xfilter/xffloatframe.hxx"
69 #include "xfilter/xfrubystyle.hxx"
70 #include "lwppagelayout.hxx"
71 #include "lwpoleobject.hxx"
72 #include "lwptablelayout.hxx"
73 #include "lwpgrfobj.hxx"
74 #include "lwpglobalmgr.hxx"
76 LwpFrame::LwpFrame(LwpPlacableLayout
* pLayout
):m_pLayout(pLayout
)
85 * @param: register frame style
86 * @param: pFrameStyle - Frame Style object
89 void LwpFrame::RegisterStyle(XFFrameStyle
* pFrameStyle
)
91 ApplyWrapType(pFrameStyle
);
92 ApplyMargins(pFrameStyle
);
93 ApplyPadding(pFrameStyle
);
94 ApplyBorders(pFrameStyle
);
95 ApplyColumns(pFrameStyle
);
96 ApplyShadow(pFrameStyle
);
97 ApplyBackGround(pFrameStyle
);
98 ApplyWatermark(pFrameStyle
);
99 // ApplyBackColor(pFrameStyle);
100 ApplyProtect(pFrameStyle
);
101 ApplyTextDir(pFrameStyle
);
102 ApplyPosType(pFrameStyle
);
104 pFrameStyle
->SetStyleName(m_pLayout
->GetName().str());
105 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
106 m_StyleName
= pXFStyleManager
->AddStyle(pFrameStyle
).m_pStyle
->GetStyleName();
107 m_pLayout
->SetStyleName(m_StyleName
);
110 * @descr: parse frame and set frame properties
111 * @param: pXFFrame - XFFrame object
112 * @param: nPageNo - the page number that the frame anchors
115 void LwpFrame::Parse(XFFrame
* pXFFrame
, sal_Int32 nPageNo
)
117 //set the frame style name
118 pXFFrame
->SetStyleName(m_StyleName
);
120 //SetAnchorType and position,if it's page anchor,set the page number.
121 ParseAnchorType(pXFFrame
);
124 pXFFrame
->SetAnchorPage(nPageNo
);
128 OUString aFrameName
= m_pLayout
->GetName().str();
129 if(!aFrameName
.isEmpty())
131 //cause the bug of SODC, the linkframe name can not be "Frame1", so I change the frame name
132 /*if(aFrameName.equals("Frame1"))
134 aFrameName = "Frame1_COPY";
136 pXFFrame->SetName(aFrameName);*/
137 pXFFrame
->SetName(m_StyleName
);
140 LwpLayoutGeometry
* pLayoutGeo
= m_pLayout
->GetGeometry();
141 //Set frame Width and height
144 double fWidth
= m_pLayout
->GetWidth();
145 double fHeight
= m_pLayout
->GetHeight();
147 pXFFrame
->SetWidth( fWidth
);
148 pXFFrame
->SetHeight( fHeight
);
151 /*LwpObject* pObj =*/ m_pLayout
->GetContent().obj();
152 if(m_pLayout
->IsGroupHead()&&(m_pLayout
->IsMinimumHeight()))
154 //process grouplayout height. there is problems now
155 pXFFrame
->SetHeight( fHeight
);
158 else if(m_pLayout->IsFitGraphic() && pObj && pObj->GetTag() == VO_GRAPHIC)
160 //If is graphic, get original size and set it;
161 LwpGraphicObject* pGrpObj = static_cast<LwpGraphicObject*>(pObj);
162 long nHeight =0, nWidth =0;
163 pGrpObj->GetGrafOrgSize(nWidth, nHeight);
164 //add margins to the width and height;
165 fWidth = (double)nWidth/TWIPS_PER_CM + m_pLayout->GetMarginsValue(MARGIN_LEFT) + m_pLayout->GetMarginsValue(MARGIN_RIGHT);
166 fHeight = (double)nHeight/TWIPS_PER_CM + m_pLayout->GetMarginsValue(MARGIN_TOP) + m_pLayout->GetMarginsValue(MARGIN_BOTTOM);
167 pXFFrame->SetWidth(fWidth);
168 pXFFrame->SetHeight(fHeight);
171 else if(m_pLayout
->IsAutoGrow())
173 pXFFrame
->SetMinHeight( fHeight
);
177 if(m_pLayout
->IsFrame())
179 //Set frame link. Only frame layout has this feature
180 LwpFrameLayout
* pLayout
= static_cast<LwpFrameLayout
*>(m_pLayout
);
181 pXFFrame
->SetNextLink(pLayout
->GetNextLinkName());
186 * @descr: parse frame relative to page, frame or cell
187 * @param: pCont - content container which contains the frame
190 void LwpFrame::XFConvert(XFContentContainer
* pCont
)
192 //parse the frame which anchor to page
193 LwpVirtualLayout
* pParent
= m_pLayout
->GetParentLayout();
194 if(pParent
->IsPage()&& pParent
->GetParentLayout()->IsPage())
196 //for mirror page, problems exist if the parent layout is header or footer layout,
197 pParent
= pParent
->GetParentLayout();
199 if(m_pLayout
->IsAnchorPage()&& pParent
->IsPage())
202 if(m_pLayout
->IsUseOnPage())
204 sal_Int32 nPageNo
= pParent
->GetPageNumber(m_pLayout
->GetUsePage());
206 m_pLayout
->XFConvertFrame(pCont
, nPageNo
);
208 else if(m_pLayout
->IsUseOnAllPages())
210 sal_Int32 nFirst
= pParent
->GetPageNumber(FIRST_LAYOUTPAGENO
);
211 sal_Int32 nLast
= pParent
->GetPageNumber(LAST_LAYOUTPAGENO
);
213 m_pLayout
->XFConvertFrame(pCont
, nFirst
, nLast
, true);
216 else if(m_pLayout
->IsUseOnAllOddPages()||m_pLayout
->IsUseOnAllEvenPages())
218 sal_Int32 nFirst
= pParent
->GetPageNumber(FIRST_LAYOUTPAGENO
);
219 sal_Int32 nLast
= pParent
->GetPageNumber(LAST_LAYOUTPAGENO
);
222 sal_uInt16 first
= static_cast<sal_uInt16
>(nFirst
);
223 if((m_pLayout
->IsUseOnAllOddPages() && !LwpTools::IsOddNumber(first
))
224 || (m_pLayout
->IsUseOnAllEvenPages() && !LwpTools::IsEvenNumber(first
)))
228 m_pLayout
->XFConvertFrame(pCont
, nFirst
, nLast
, false);
235 m_pLayout
->XFConvertFrame(pCont
);
240 * @descr: set frame wrap type style
241 * @param: pFrameStyle - Frame Style object
244 void LwpFrame::ApplyWrapType(XFFrameStyle
*pFrameStyle
)
246 enumXFWrap eWrap
= enumXFWrapNone
;
247 switch(m_pLayout
->GetWrapType())
249 case LwpPlacableLayout::LAY_WRAP_AROUND
: //fall through
250 case LwpPlacableLayout::LAY_WRAP_IRREG_BIGGEST
:
252 //In SODC, if Optimal wrap type is used and the distance between the frame object
253 //and page margins is less than 2cm, the text is not wrapped. While there is no this feature in Word Pro
254 //So the optimal wrap type is translated to left side or right side wrap type according to the distance
255 //between the frame object and page margins
257 eWrap
= enumXFWrapBest
;
258 LwpMiddleLayout
* pParent
= static_cast<LwpMiddleLayout
*>(m_pLayout
->GetContainerLayout());
262 eWrap
= enumXFWrapLeft
;
264 eWrap
= enumXFWrapRight
;
268 case LwpPlacableLayout::LAY_NO_WRAP_BESIDE
:
270 eWrap
= enumXFWrapNone
;
273 case LwpPlacableLayout::LAY_NO_WRAP_AROUND
:
275 eWrap
= enumXFWrapRunThrough
;
276 if(!m_pLayout
->GetBackColor() && !m_pLayout
->GetWaterMarkLayout())
278 //pFrameStyle->SetBackGround(sal_True);
279 XFColor
aXFColor(0xffffff); //white color
280 pFrameStyle
->SetBackColor(aXFColor
);
281 pFrameStyle
->SetTransparency(100); //transparency
285 case LwpPlacableLayout::LAY_WRAP_LEFT
: //fall through
286 case LwpPlacableLayout::LAY_WRAP_IRREG_LEFT
:
288 eWrap
= enumXFWrapLeft
;
291 case LwpPlacableLayout::LAY_WRAP_RIGHT
: //fall through
292 case LwpPlacableLayout::LAY_WRAP_IRREG_RIGHT
:
294 eWrap
= enumXFWrapRight
;
297 case LwpPlacableLayout::LAY_WRAP_BOTH
: //fall through
298 case LwpPlacableLayout::LAY_WRAP_IRREG_BOTH
:
300 eWrap
= enumXFWrapParallel
;
307 //If it is the type of with para above, wrap type is enumXFWrapNone
308 if(m_pLayout
->GetRelativeType()==LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE
)
310 eWrap
= enumXFWrapNone
;
313 pFrameStyle
->SetWrapType(eWrap
);
316 * @descr: set frame margins style
317 * @param: pFrameStyle - Frame Style object
320 void LwpFrame::ApplyMargins(XFFrameStyle
*pFrameStyle
)
322 double fLeft
= m_pLayout
->GetExtMarginsValue(MARGIN_LEFT
);
323 double fRight
= m_pLayout
->GetExtMarginsValue(MARGIN_RIGHT
);
324 double fTop
= m_pLayout
->GetExtMarginsValue(MARGIN_TOP
);
325 double fBottom
= m_pLayout
->GetExtMarginsValue(MARGIN_BOTTOM
);
326 pFrameStyle
->SetMargins(fLeft
,fRight
,fTop
,fBottom
);
329 * @descr: set padding border style
330 * @param: pFrameStyle - Frame Style object
333 void LwpFrame::ApplyPadding(XFFrameStyle
*pFrameStyle
)
335 double fLeft
= m_pLayout
->GetMarginsValue(MARGIN_LEFT
);
336 double fRight
= m_pLayout
->GetMarginsValue(MARGIN_RIGHT
);
337 double fTop
= m_pLayout
->GetMarginsValue(MARGIN_TOP
);
338 double fBottom
= m_pLayout
->GetMarginsValue(MARGIN_BOTTOM
);
339 pFrameStyle
->SetPadding(fLeft
,fRight
,fTop
,fBottom
);
342 * @descr: set frame border style
343 * @param: pFrameStyle - Frame Style object
346 void LwpFrame::ApplyBorders(XFFrameStyle
*pFrameStyle
)
348 XFBorders
* pBordres
= m_pLayout
->GetXFBorders();
351 pFrameStyle
->SetBorders(pBordres
);
355 * @descr: set frame columns style
356 * @param: pFrameStyle - Frame Style object
359 void LwpFrame::ApplyColumns(XFFrameStyle
*pFrameStyle
)
361 XFColumns
* pColumns
= m_pLayout
->GetXFColumns();
364 pFrameStyle
->SetColumns(pColumns
);
368 * @descr: set frame shadow style
369 * @param: pFrameStyle - Frame Style object
372 void LwpFrame::ApplyShadow(XFFrameStyle
* pFrameStyle
)
374 XFShadow
* pXFShadow
= m_pLayout
->GetXFShadow();
377 pFrameStyle
->SetShadow(pXFShadow
);
381 * @descr: set frame back color style
382 * @param: pFrameStyle - Frame Style object
385 void LwpFrame::ApplyBackColor(XFFrameStyle
* pFrameStyle
)
387 LwpColor
* pColor
= m_pLayout
->GetBackColor();
390 XFColor
aXFColor(pColor
->To24Color());
391 pFrameStyle
->SetBackColor(aXFColor
);
395 * @descr: set frame protect style
396 * @param: pFrameStyle - Frame Style object
399 void LwpFrame::ApplyProtect(XFFrameStyle
* pFrameStyle
)
401 if(m_pLayout
->IsProtected())
403 pFrameStyle
->SetProtect(true,true,true);
407 * @descr: set frame text direction style
408 * @param: pFrameStyle - Frame Style object
411 void LwpFrame::ApplyTextDir(XFFrameStyle
* pFrameStyle
)
413 pFrameStyle
->SetTextDir(m_pLayout
->GetTextDirection());
416 * @descr: set frame position type style
417 * @param: pFrameStyle - Frame Style object
420 void LwpFrame::ApplyPosType(XFFrameStyle
* pFrameStyle
)
422 enumXFFrameXPos eXPos
= enumXFFrameXPosCenter
;
423 enumXFFrameXRel eXRel
= enumXFFrameXRelPara
;
424 enumXFFrameYPos eYPos
= enumXFFrameYPosMiddle
;
425 enumXFFrameYRel eYRel
= enumXFFrameYRelPara
;
426 sal_uInt8 nType
= m_pLayout
->GetRelativeType();
429 case LwpLayoutRelativityGuts::LAY_PARENT_RELATIVE
://fall through
430 case LwpLayoutRelativityGuts::LAY_CONTENT_RELATIVE
:
432 //anchor to page, frame and cell
433 eXPos
= enumXFFrameXPosFromLeft
;
434 eXRel
= enumXFFrameXRelPage
;
435 //set vertical position
436 if(m_pLayout
->IsAnchorPage())//in page
438 LwpVirtualLayout
* pContainer
= m_pLayout
->GetContainerLayout();
439 if(pContainer
&& (pContainer
->IsHeader() || pContainer
->IsFooter()))
441 //Only anchor to para, the frame can display in header and footer of each page
442 eYPos
= enumXFFrameYPosFromTop
; //from top
443 eYRel
= enumXFFrameYRelPara
; //from margin
447 eYPos
= enumXFFrameYPosFromTop
;
448 eYRel
= enumXFFrameYRelPage
;
451 if(m_pLayout
->IsAnchorFrame()) //in frame
453 eYPos
= enumXFFrameYPosFromTop
;
454 eYRel
= enumXFFrameYRelPage
;
456 if(m_pLayout
->IsAnchorCell())
458 //SODC has no this type, simulate this feature
459 eYPos
= enumXFFrameYPosFromTop
; //from top
460 eYRel
= enumXFFrameYRelPara
; //from margin
464 case LwpLayoutRelativityGuts::LAY_PARA_RELATIVE
: //same page as text
466 eXPos
= enumXFFrameXPosFromLeft
;
467 eXRel
= enumXFFrameXRelPage
;
468 eYPos
= enumXFFrameYPosBelow
; //below
469 eYRel
= enumXFFrameYRelChar
; //from char
470 //set vertical position
471 LwpVirtualLayout
* pContainer
= m_pLayout
->GetContainerLayout();
472 if(pContainer
&& pContainer
->IsPage())//in page
474 //eYPos = enumXFFrameYPosFromTop;
475 //eYRel = enumXFFrameYRelPage;
476 eYPos
= enumXFFrameYPosBelow
;
477 eYRel
= enumXFFrameYRelChar
;
479 else if(pContainer
&& pContainer
->IsFrame()) //in frame
481 eYPos
= enumXFFrameYPosFromTop
;
482 eYRel
= enumXFFrameYRelPage
;
486 eYPos
= enumXFFrameYPosFromTop
; //from top
487 eYRel
= enumXFFrameYRelPara
; //from margin
491 case LwpLayoutRelativityGuts::LAY_INLINE
: //in text
493 eXPos
= enumXFFrameXPosFromLeft
; //need not be set
494 eXRel
= enumXFFrameXRelParaContent
; //need not be set
495 eYPos
= enumXFFrameYPosTop
; //should be from top
496 eYRel
= enumXFFrameYRelBaseLine
;
497 sal_Int32 nOffset
= m_pLayout
->GetBaseLineOffset();
500 eYPos
= enumXFFrameYPosFromTop
;
504 case LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE
: //with para above
506 eXPos
= enumXFFrameXPosFromLeft
;
507 eXRel
= enumXFFrameXRelParaContent
;
508 //eYPos = enumXFFrameYPosTop;
509 eYPos
= enumXFFrameYPosBottom
;
510 eYRel
= enumXFFrameYRelParaContent
;
513 case LwpLayoutRelativityGuts::LAY_INLINE_VERTICAL
: //in text - vertical
515 eXPos
= enumXFFrameXPosFromLeft
;
516 eXRel
= enumXFFrameXRelPage
;
517 eYPos
= enumXFFrameYPosFromTop
; //should be below position
518 eYRel
= enumXFFrameYRelChar
;
525 pFrameStyle
->SetXPosType(eXPos
,eXRel
);
526 pFrameStyle
->SetYPosType(eYPos
,eYRel
);
529 * @descr: set frame watermark style
530 * @param: pFrameStyle - Frame Style object
533 void LwpFrame::ApplyWatermark(XFFrameStyle
*pFrameStyle
)
535 XFBGImage
* pBGImage
= m_pLayout
->GetXFBGImage();
538 pFrameStyle
->SetBackImage(pBGImage
);
539 //set watermark transparent
540 LwpMiddleLayout
* pLay
= static_cast<LwpMiddleLayout
*>(m_pLayout
->GetWaterMarkLayout());
541 LwpBackgroundStuff
* pBackgroundStuff
= pLay
->GetBackgroundStuff();
542 if(pBackgroundStuff
&& !pBackgroundStuff
->IsTransparent())
544 pFrameStyle
->SetTransparency(100);
550 * @short Apply pattern fill to frame style
551 * @param pFrameStyle - pointer of XFFrameStyle
554 void LwpFrame::ApplyPatternFill(XFFrameStyle
* pFrameStyle
)
556 XFBGImage
* pXFBGImage
= m_pLayout
->GetFillPattern();
559 pFrameStyle
->SetBackImage(pXFBGImage
);
564 * @short Apply background to frame style
565 * @param pFrameStyle - pointer of XFFrameStyle
568 void LwpFrame::ApplyBackGround(XFFrameStyle
* pFrameStyle
)
575 if (m_pLayout
->IsPatternFill())
577 ApplyPatternFill(pFrameStyle
);
581 ApplyBackColor(pFrameStyle
);
586 * @descr: set frame size, anchor type, anchored page number
587 * @param: pXFFrame - XFFrame object
590 void LwpFrame::ParseAnchorType(XFFrame
*pXFFrame
)
596 sal_uInt16 nPageNum
= 0;
598 enumXFAnchor eAnchor
= enumXFAnchorNone
;
600 LwpLayoutGeometry
* pLayoutGeo
= m_pLayout
->GetGeometry();
603 LwpPoint aPoint
= pLayoutGeo
->GetOrigin();
604 fXOffset
= LwpTools::ConvertFromUnitsToMetric(aPoint
.GetX());
605 fYOffset
= LwpTools::ConvertFromUnitsToMetric(aPoint
.GetY());
608 eAnchor
= enumXFAnchorNone
;
609 sal_uInt8 nType
= m_pLayout
->GetRelativeType();
612 case LwpLayoutRelativityGuts::LAY_PARENT_RELATIVE
://fall through
613 case LwpLayoutRelativityGuts::LAY_CONTENT_RELATIVE
:
615 //anchor to page, frame and cell
616 if(m_pLayout
->IsAnchorPage())//in page
618 LwpVirtualLayout
* pContainer
= m_pLayout
->GetContainerLayout();
619 if(pContainer
&& (pContainer
->IsHeader() || pContainer
->IsFooter()))
621 eAnchor
= enumXFAnchorPara
;
622 fYOffset
-= pContainer
->GetMarginsValue(MARGIN_TOP
);
625 eAnchor
= enumXFAnchorPage
;
627 if(m_pLayout
->IsAnchorFrame()) //in frame
629 eAnchor
= enumXFAnchorFrame
;
631 if(m_pLayout
->IsAnchorCell()) //in cell
633 //eAnchor = enumXFAnchorChar;
634 eAnchor
= enumXFAnchorPara
;
635 LwpMiddleLayout
* pContainer
= static_cast<LwpMiddleLayout
*>(m_pLayout
->GetContainerLayout());
638 fYOffset
-= pContainer
->GetMarginsValue(MARGIN_TOP
);
643 case LwpLayoutRelativityGuts::LAY_PARA_RELATIVE
: //same page as text
645 eAnchor
= enumXFAnchorChar
;
646 LwpVirtualLayout
* pContainer
= m_pLayout
->GetContainerLayout();
647 if(pContainer
&& pContainer
->IsPage())//in page
649 //eAnchor = enumXFAnchorPage;
650 eAnchor
= enumXFAnchorChar
;// to character
652 else if(pContainer
&& pContainer
->IsFrame()) //in frame
654 eAnchor
= enumXFAnchorFrame
;
656 else if(pContainer
&& pContainer
->IsCell()) //in cell
658 //eAnchor = enumXFAnchorChar;
659 eAnchor
= enumXFAnchorPara
;
660 fYOffset
-= pContainer
->GetMarginsValue(MARGIN_TOP
);
662 else if(pContainer
&& (pContainer
->IsHeader() || pContainer
->IsFooter()))//in header or footer
664 eAnchor
= enumXFAnchorPara
;
665 fYOffset
-= pContainer
->GetMarginsValue(MARGIN_TOP
);
669 case LwpLayoutRelativityGuts::LAY_INLINE
: //in text
671 eAnchor
= enumXFAnchorAsChar
;
672 sal_Int32 nOffset
= m_pLayout
->GetBaseLineOffset();
673 if(nOffset
>0 && pLayoutGeo
)
676 fYOffset
=-(m_pLayout
->GetGeometryHeight()+2*m_pLayout
->GetExtMarginsValue(MARGIN_BOTTOM
)-LwpTools::ConvertFromUnitsToMetric(nOffset
));
680 case LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE
: //with para above
682 eAnchor
= enumXFAnchorPara
;
685 case LwpLayoutRelativityGuts::LAY_INLINE_VERTICAL
: //in text - vertical
687 eAnchor
= enumXFAnchorChar
;
688 //set vertical position
691 //because of the different feature between Word Pro and SODC, I simulate the vertical base offset
692 //between anchor and frame origin using the font height.
693 //LwpPara* pPara = static_cast<LwpPara*>(m_pLayout->GetPosition()->obj());
694 rtl::Reference
<XFFont
> pFont
= m_pLayout
->GetFont();
697 offset
= (double)(pFont
->GetFontSize())*CM_PER_INCH
/POINTS_PER_INCH
;
699 fYOffset
= offset
-fYOffset
;
706 pXFFrame
->SetX(fXOffset
);
707 pXFFrame
->SetY(fYOffset
);
708 pXFFrame
->SetAnchorPage(nPageNum
);
709 pXFFrame
->SetAnchorType(eAnchor
);
713 * @descr Calculate the distance between the frame object and the page margins.
714 * And determine which side(left or right) is wider
716 bool LwpFrame::IsLeftWider()
718 //LwpMiddleLayout* pParent = static_cast<LwpMiddleLayout*>(m_pLayout->GetContainerLayout());
719 LwpVirtualLayout
* pParent
= static_cast<LwpVirtualLayout
*>(m_pLayout
->GetContainerLayout());
722 LwpPoint aPoint
= m_pLayout
->GetOrigin();
723 double fXOffset
= LwpTools::ConvertFromUnitsToMetric(aPoint
.GetX());
724 double fWidth
= m_pLayout
->GetWidth();
725 double fWrapLeft
= m_pLayout
->GetExtMarginsValue(MARGIN_LEFT
);
726 double fWrapRight
= m_pLayout
->GetExtMarginsValue(MARGIN_RIGHT
);
728 //LwpPoint aParentPoint = pParent->GetOrigin();
729 //double fParentXOffset = LwpTools::ConvertFromUnitsToMetric(aParentPoint.GetX());
730 double fParentWidth
= pParent
->GetWidth();
731 if(pParent
->IsCell())
733 //Get actual width of this cell layout
734 fParentWidth
= static_cast<LwpCellLayout
*>(pParent
)->GetActualWidth();
736 double fParentMarginLeft
= pParent
->GetMarginsValue(MARGIN_LEFT
);
737 double fParentMarginRight
= pParent
->GetMarginsValue(MARGIN_RIGHT
);
739 double fLeft
= fXOffset
- fWrapLeft
-fParentMarginLeft
;
740 double fRight
= fParentWidth
- fParentMarginRight
-(fXOffset
+ fWidth
+ fWrapRight
);
747 LwpFrameLink::LwpFrameLink()
750 LwpFrameLink::~LwpFrameLink()
754 * @descr frame link information
757 void LwpFrameLink::Read(LwpObjectStream
* pStrm
)
759 m_PreviousLayout
.ReadIndexed(pStrm
);
760 m_NextLayout
.ReadIndexed(pStrm
);
764 LwpFrameLayout::LwpFrameLayout(LwpObjectHeader
&objHdr
, LwpSvStream
* pStrm
)
765 : LwpPlacableLayout(objHdr
, pStrm
), m_pFrame(NULL
)
769 LwpFrameLayout::~LwpFrameLayout()
775 * @descr read frame layout object
778 void LwpFrameLayout::Read()
780 LwpPlacableLayout::Read();
781 if(LwpFileHeader::m_nFileRevision
>= 0x000B)
783 if(m_pObjStrm
->QuickReaduInt16())
785 m_Link
.Read(m_pObjStrm
);
788 m_pObjStrm
->SkipExtra();
792 * @descr create a xfframe and add into content container
793 * @param: pCont - content container that contains the frame.
796 void LwpFrameLayout::XFConvert(XFContentContainer
* pCont
)
800 //parse the frame which anchor to paragraph
801 if(IsRelativeAnchored())
803 XFConvertFrame(pCont
);
807 m_pFrame
->XFConvert(pCont
);
813 * @descr create a xfframe and add into content container, called by XFConvert
814 * @param: pCont - content container that contains the frame.
815 * @param: nPageNo - the page number that the frame anchors
818 void LwpFrameLayout::XFConvertFrame(XFContentContainer
* pCont
, sal_Int32 nStart
, sal_Int32 nEnd
, bool bAll
)
822 XFFrame
* pXFFrame
= NULL
;
825 pXFFrame
= new XFFrame();
829 pXFFrame
= new XFFloatFrame(nStart
, nEnd
, bAll
);
832 m_pFrame
->Parse(pXFFrame
, nStart
);
833 //if it is a link frame, parse contents only once
834 if(!HasPreviousLinkLayout())
836 rtl::Reference
<LwpObject
> content
= m_Content
.obj();
839 content
->XFConvert(pXFFrame
);
840 //set frame size according to ole size
841 ApplyGraphicSize(pXFFrame
);
844 pCont
->Add(pXFFrame
);
848 * @descr register frame style
851 void LwpFrameLayout::RegisterStyle()
853 //if it is for water mark, don't register style
854 if (IsForWaterMark())
860 //register frame style
861 XFFrameStyle
* pFrameStyle
= new XFFrameStyle();
862 m_pFrame
= new LwpFrame(this);
863 m_pFrame
->RegisterStyle(pFrameStyle
);
865 //register content style
866 rtl::Reference
<LwpObject
> content
= m_Content
.obj();
869 content
->SetFoundry(m_pFoundry
);
870 content
->RegisterStyle();
873 //register child frame style
874 RegisterChildStyle();
878 * @descr get the name of the frame that current frame links
881 OUString
LwpFrameLayout::GetNextLinkName()
884 LwpObjectID
& rObjectID
= m_Link
.GetNextLayout();
885 if(!rObjectID
.IsNull())
887 LwpLayout
* pLayout
= dynamic_cast<LwpLayout
*>(rObjectID
.obj().get());
890 LwpAtomHolder
& rHolder
= pLayout
->GetName();
891 aName
= rHolder
.str();
892 //for division name confict
893 if(!pLayout
->GetStyleName().isEmpty())
894 aName
= pLayout
->GetStyleName();
900 * @descr whether current frame is linked by other frame
903 bool LwpFrameLayout::HasPreviousLinkLayout()
905 LwpObjectID
& rObjectID
= m_Link
.GetPreviousLayout();
906 if(rObjectID
.IsNull())
911 * @descr whether current frame is for water mark. Problem maybe exsits by this method, must be tracking
914 bool LwpFrameLayout::IsForWaterMark()
916 if(m_nBuoyancy
>=LAY_BUOYLAYER
)
918 if(!m_Content
.IsNull() && (m_Content
.obj()->GetTag()==VO_GRAPHIC
) )
927 * @descr Get frame width
930 double LwpFrameLayout::GetWidth()
932 double fWidth
= LwpMiddleLayout::GetWidth();
933 if(IsInlineToMargin() && IsAutoGrowWidth())
935 //for text field entry when choosing maximize field length
936 fWidth
= GetMaxWidth();
942 * @descr Get frame width when the text field chooses maximize field length
945 double LwpFrameLayout::GetMaxWidth()
947 double fActualWidth
= 0;
948 LwpMiddleLayout
* pParent
= static_cast<LwpMiddleLayout
*>(GetContainerLayout());
951 LwpPoint aPoint
= GetOrigin();
952 double fXOffset
= LwpTools::ConvertFromUnitsToMetric(aPoint
.GetX());
953 double fWrapRight
= GetExtMarginsValue(MARGIN_RIGHT
);
955 //Get parent layout width
956 double fParentWidth
= pParent
->GetWidth();
957 if(pParent
->IsCell())
959 //Get actual width of this cell layout
960 fParentWidth
= static_cast<LwpCellLayout
*>(pParent
)->GetActualWidth();
963 double fParentMarginRight
= 0;
964 sal_uInt8 nType
= GetRelativeType();
965 if(nType
== LwpLayoutRelativityGuts::LAY_INLINE
966 || nType
== LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE
)
968 fParentMarginRight
= pParent
->GetMarginsValue(MARGIN_RIGHT
);
971 fActualWidth
= fParentWidth
- fXOffset
- fParentMarginRight
- fWrapRight
;
978 * @descr Set frame size according to graphic size
981 void LwpFrameLayout::ApplyGraphicSize(XFFrame
* pXFFrame
)
983 rtl::Reference
<LwpObject
> content
= m_Content
.obj();
984 if(content
.is() && (content
->GetTag() == VO_GRAPHIC
985 || content
->GetTag() == VO_OLEOBJECT
))
987 LwpGraphicOleObject
* pGraOle
= static_cast<LwpGraphicOleObject
*>(content
.get());
988 //Get frame geometry size
991 pGraOle
->GetGrafScaledSize(fWidth
, fHeight
);
995 fWidth
+= GetMarginsValue(MARGIN_LEFT
) + GetMarginsValue(MARGIN_RIGHT
);
996 fHeight
+= GetMarginsValue(MARGIN_TOP
) + GetMarginsValue(MARGIN_BOTTOM
);
998 else if(IsAutoGrowDown() || IsAutoGrowUp())
1000 fWidth
= GetWidth();
1001 fHeight
+= GetMarginsValue(MARGIN_TOP
) + GetMarginsValue(MARGIN_BOTTOM
);
1003 else if( IsAutoGrowLeft() || IsAutoGrowRight())
1005 fHeight
= GetHeight();
1006 fWidth
+= GetMarginsValue(MARGIN_LEFT
) + GetMarginsValue(MARGIN_RIGHT
);
1010 fWidth
= GetWidth();
1011 fHeight
= GetHeight();
1013 pXFFrame
->SetWidth(fWidth
);
1014 pXFFrame
->SetHeight(fHeight
);
1018 LwpGroupLayout::LwpGroupLayout(LwpObjectHeader
&objHdr
, LwpSvStream
* pStrm
)
1019 : LwpPlacableLayout(objHdr
, pStrm
)
1025 LwpGroupLayout::~LwpGroupLayout()
1030 * @descr read group layout object
1033 void LwpGroupLayout::Read()
1035 LwpPlacableLayout::Read();
1036 m_pObjStrm
->SkipExtra();
1039 * @descr register group frame style
1042 void LwpGroupLayout::RegisterStyle()
1047 //register frame style
1048 XFFrameStyle
* pFrameStyle
= new XFFrameStyle();
1049 m_pFrame
= new LwpFrame(this);
1050 m_pFrame
->RegisterStyle(pFrameStyle
);
1052 //register child frame style
1053 RegisterChildStyle();
1056 * @descr create a xfframe and add into content container
1057 * @param: pCont - content container that contains the frame.
1060 void LwpGroupLayout::XFConvert(XFContentContainer
*pCont
)
1064 //parse the frame which anchor to paragraph
1065 if(IsRelativeAnchored())
1067 XFConvertFrame(pCont
);
1071 m_pFrame
->XFConvert(pCont
);
1077 * @descr create a xfframe and add into content container, called by XFConvert
1078 * @param: pCont - content container that contains the frame.
1079 * @param: nPageNo - the page number that the frame anchors
1082 void LwpGroupLayout::XFConvertFrame(XFContentContainer
* pCont
, sal_Int32 nStart
, sal_Int32 nEnd
, bool bAll
)
1086 XFFrame
* pXFFrame
= NULL
;
1089 pXFFrame
= new XFFrame();
1093 pXFFrame
= new XFFloatFrame(nStart
, nEnd
, bAll
);
1096 m_pFrame
->Parse(pXFFrame
, nStart
);
1098 //add child frame into group
1099 LwpVirtualLayout
* pLayout
= static_cast<LwpVirtualLayout
*>(GetChildHead().obj().get());
1102 pLayout
->XFConvert(pXFFrame
);
1103 pLayout
= static_cast<LwpVirtualLayout
*>(pLayout
->GetNext().obj().get());
1106 pCont
->Add(pXFFrame
);
1110 LwpGroupFrame::LwpGroupFrame(LwpObjectHeader
&objHdr
, LwpSvStream
* pStrm
)
1111 :LwpContent(objHdr
, pStrm
)
1114 LwpGroupFrame::~LwpGroupFrame()
1117 void LwpGroupFrame::Read()
1120 m_pObjStrm
->SkipExtra();
1124 void LwpGroupFrame::RegisterStyle()
1128 void LwpGroupFrame::XFConvert(XFContentContainer
* /*pCont*/)
1132 LwpDropcapLayout::LwpDropcapLayout(LwpObjectHeader
&objHdr
, LwpSvStream
* pStrm
)
1133 : LwpFrameLayout(objHdr
, pStrm
)
1139 void LwpDropcapLayout::Read()
1141 LwpFrameLayout::Read();
1142 m_nLines
= m_pObjStrm
->QuickReaduInt16();
1143 m_pObjStrm
->SeekRel(1);
1144 m_pObjStrm
->SkipExtra();
1147 void LwpDropcapLayout::Parse(IXFStream
* pOutputStream
)
1149 LwpStory
* pStory
= static_cast<LwpStory
*>(m_Content
.obj(VO_STORY
).get());
1152 rtl::Reference
<LwpObject
> pPara
= pStory
->GetFirstPara().obj(VO_PARA
);
1155 pPara
->SetFoundry(m_pFoundry
);
1156 pPara
->Parse(pOutputStream
);
1160 void LwpDropcapLayout::XFConvert(XFContentContainer
* pCont
)
1162 LwpStory
* pStory
= static_cast<LwpStory
*>(m_Content
.obj(VO_STORY
).get());
1165 pStory
->SetFoundry(m_pFoundry
);
1166 pStory
->XFConvert(pCont
);
1170 LwpStory
* LwpDropcapLayout::GetContentStory()
1172 return static_cast<LwpStory
*>(m_Content
.obj(VO_STORY
).get());
1175 void LwpDropcapLayout::RegisterStyle(LwpFoundry
* pFoundry
)
1177 LwpStory
* pStory
= GetContentStory();
1180 pStory
->SetDropcapFlag(true);
1181 pStory
->SetFoundry(pFoundry
);
1182 LwpPara
* pPara
= static_cast<LwpPara
*>(pStory
->GetFirstPara().obj().get());
1185 pPara
->SetFoundry(pFoundry
);
1186 pPara
->RegisterStyle();
1187 pPara
= static_cast<LwpPara
*>(pPara
->GetNext().obj().get());
1196 void LwpDropcapLayout::RegisterStyle()
1200 LwpRubyLayout::LwpRubyLayout(LwpObjectHeader
&objHdr
, LwpSvStream
* pStrm
)
1201 : LwpFrameLayout(objHdr
, pStrm
)
1210 void LwpRubyLayout::Read()
1212 LwpFrameLayout::Read();
1213 m_nPlacement
= m_pObjStrm
->QuickReaduInt8();
1214 m_nAlignment
= m_pObjStrm
->QuickReaduInt8();
1215 m_nStateFlag
= m_pObjStrm
->QuickReaduInt16();
1216 m_nXOffset
= m_pObjStrm
->QuickReadInt32();
1217 m_nYOffset
= m_pObjStrm
->QuickReadInt32();
1218 m_objRubyMarker
.ReadIndexed(m_pObjStrm
);
1219 m_pObjStrm
->SkipExtra();
1222 LwpRubyMarker
* LwpRubyLayout::GetMarker()
1224 return static_cast<LwpRubyMarker
*>(m_objRubyMarker
.obj(VO_RUBYMARKER
).get());
1227 LwpStory
* LwpRubyLayout::GetContentStory()
1229 return static_cast<LwpStory
*>(m_Content
.obj(VO_STORY
).get());
1232 void LwpRubyLayout::ConvertContentText()
1234 LwpStory
* pStory
= GetContentStory();
1235 LwpRubyMarker
* pMarker
= GetMarker();
1236 if (pStory
&& pMarker
)
1237 pMarker
->SetRubyText(pStory
->GetContentText(true));
1240 void LwpRubyLayout::RegisterStyle()
1242 LwpRubyMarker
* pMarker
= GetMarker();
1244 XFRubyStyle
* pRubyStyle
= new XFRubyStyle
;
1246 enumXFRubyPosition eType
= enumXFRubyLeft
;
1247 if (m_nAlignment
== LEFT
)
1249 eType
= enumXFRubyLeft
;
1251 else if(m_nAlignment
== RIGHT
)
1253 eType
= enumXFRubyRight
;
1255 else if(m_nAlignment
== CENTER
)
1257 eType
= enumXFRubyCenter
;
1259 pRubyStyle
->SetAlignment(eType
);
1261 eType
= enumXFRubyTop
;
1262 if (m_nPlacement
== TOP
)
1264 eType
= enumXFRubyTop
;
1266 else if(m_nPlacement
== BOTTOM
)
1268 eType
= enumXFRubyBottom
;
1270 pRubyStyle
->SetPosition(eType
);
1272 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1273 OUString rubyStyle
= pXFStyleManager
->AddStyle(pRubyStyle
).m_pStyle
->GetStyleName();
1274 pMarker
->SetRubyStyleName(rubyStyle
);
1276 LwpStory
* pStory
= GetContentStory();
1277 pStory
->SetFoundry(m_pFoundry
);
1278 OUString textStyle
= pStory
->RegisterFirstFribStyle();
1279 pMarker
->SetTextStyleName(textStyle
);
1282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */