1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdrtextprimitive2d.cxx,v $
11 * $Revision: 1.2.18.1 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "precompiled_svx.hxx"
33 #include <svx/sdr/primitive2d/sdrtextprimitive2d.hxx>
34 #include <svx/svdotext.hxx>
35 #include <basegfx/color/bcolor.hxx>
36 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
37 #include <drawinglayer/primitive2d/texthierarchyprimitive2d.hxx>
38 #include <svx/outlobj.hxx>
39 #include <svx/editobj.hxx>
40 #include <svx/flditem.hxx>
41 #include <drawinglayer/geometry/viewinformation2d.hxx>
43 #include <svx/svdpage.hxx>
44 #include <svx/svdmodel.hxx>
45 #include <svx/svdoutl.hxx>
46 #include <com/sun/star/beans/XPropertySet.hpp>
48 //////////////////////////////////////////////////////////////////////////////
50 using namespace com::sun::star
;
52 //////////////////////////////////////////////////////////////////////////////
56 sal_Int16
getPageNumber(const uno::Reference
< drawing::XDrawPage
>& rxDrawPage
)
59 uno::Reference
< beans::XPropertySet
> xSet(rxDrawPage
, uno::UNO_QUERY
);
65 const uno::Any
aNumber(xSet
->getPropertyValue(::rtl::OUString::createFromAscii("Number")));
68 catch(const uno::Exception
&)
77 sal_Int16
getPageCount(const uno::Reference
< drawing::XDrawPage
>& rxDrawPage
)
80 SdrPage
* pPage
= GetSdrPageFromXDrawPage(rxDrawPage
);
82 if(pPage
&& pPage
->GetModel())
84 const sal_uInt16
nPageCount(pPage
->GetModel()->GetPageCount());
85 nRetval
= ((sal_Int16
)nPageCount
- 1) / 2;
90 } // end of anonymous namespace
92 //////////////////////////////////////////////////////////////////////////////
94 namespace drawinglayer
98 // support for XTEXT_PAINTSHAPE_BEGIN/XTEXT_PAINTSHAPE_END Metafile comments
99 // for slideshow. This uses TextHierarchyBlockPrimitive2D to mark a text block.
100 // ATM there is only one text block per SdrObject, this may get more in the future
101 Primitive2DSequence
SdrTextPrimitive2D::encapsulateWithTextHierarchyBlockPrimitive2D(const Primitive2DSequence
& rCandidate
) const
103 Primitive2DReference
xReference(new TextHierarchyBlockPrimitive2D(rCandidate
));
104 Primitive2DSequence
xRetval(&xReference
, 1);
109 SdrTextPrimitive2D::SdrTextPrimitive2D(
110 const SdrText
* pSdrText
,
111 const OutlinerParaObject
& rOutlinerParaObject
)
113 mrSdrText(const_cast< SdrText
* >(pSdrText
)),
114 maOutlinerParaObject(rOutlinerParaObject
),
115 mxLastVisualizingPage(),
118 maLastTextBackgroundColor(),
119 mbContainsPageField(false),
120 mbContainsPageCountField(false),
121 mbContainsOtherFields(false)
123 const EditTextObject
& rETO
= maOutlinerParaObject
.GetTextObject();
125 mbContainsPageField
= rETO
.HasField(SvxPageField::StaticType());
126 mbContainsPageCountField
= rETO
.HasField(SvxPagesField::StaticType());
127 mbContainsOtherFields
= rETO
.HasField(SvxHeaderField::StaticType())
128 || rETO
.HasField(SvxFooterField::StaticType())
129 || rETO
.HasField(SvxDateTimeField::StaticType())
130 || rETO
.HasField(SvxAuthorField::StaticType());
133 bool SdrTextPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
135 if(BasePrimitive2D::operator==(rPrimitive
))
137 const SdrTextPrimitive2D
& rCompare
= (SdrTextPrimitive2D
&)rPrimitive
;
141 // compare OPO and content, but not WrongList
142 getOutlinerParaObject() == rCompare
.getOutlinerParaObject()
144 // also compare WrongList (not-persistent data, but visualized)
145 && getOutlinerParaObject().isWrongListEqual(rCompare
.getOutlinerParaObject()));
151 Primitive2DSequence
SdrTextPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D
& rViewInformation
) const
153 uno::Reference
< drawing::XDrawPage
> xCurrentlyVisualizingPage
;
154 bool bCurrentlyVisualizingPageIsSet(false);
155 Color aNewTextBackgroundColor
;
156 bool bNewTextBackgroundColorIsSet(false);
157 sal_Int16
nCurrentlyValidPageNumber(0);
158 sal_Int16
nCurrentlyValidPageCount(0);
160 if(getLocalDecomposition().hasElements())
162 bool bDoDelete(false);
164 // check visualized page
165 if(mbContainsPageField
|| mbContainsPageCountField
|| mbContainsOtherFields
)
167 // get visualized page and remember
168 xCurrentlyVisualizingPage
= rViewInformation
.getVisualizedPage();
169 bCurrentlyVisualizingPageIsSet
= true;
171 if(xCurrentlyVisualizingPage
!= mxLastVisualizingPage
)
176 // #i98870# check visualized PageNumber
177 if(!bDoDelete
&& mbContainsPageField
)
179 nCurrentlyValidPageNumber
= getPageNumber(xCurrentlyVisualizingPage
);
181 if(nCurrentlyValidPageNumber
!= mnLastPageNumber
)
187 // #i98870# check visualized PageCount, too
188 if(!bDoDelete
&& mbContainsPageCountField
)
190 nCurrentlyValidPageCount
= getPageCount(xCurrentlyVisualizingPage
);
192 if(nCurrentlyValidPageCount
!= mnLastPageCount
)
199 // #i101443# check change of TextBackgroundolor
200 if(!bDoDelete
&& getSdrText() && getSdrText()->GetModel())
202 SdrOutliner
& rDrawOutliner
= getSdrText()->GetModel()->GetDrawOutliner(0);
203 aNewTextBackgroundColor
= rDrawOutliner
.GetBackgroundColor();
204 bNewTextBackgroundColorIsSet
= true;
206 if(aNewTextBackgroundColor
!= maLastTextBackgroundColor
)
214 const_cast< SdrTextPrimitive2D
* >(this)->setLocalDecomposition(Primitive2DSequence());
218 if(!getLocalDecomposition().hasElements())
220 if(!bCurrentlyVisualizingPageIsSet
&& mbContainsPageField
)
222 xCurrentlyVisualizingPage
= rViewInformation
.getVisualizedPage();
225 if(!nCurrentlyValidPageNumber
&& mbContainsPageField
)
227 nCurrentlyValidPageNumber
= getPageNumber(xCurrentlyVisualizingPage
);
230 if(!nCurrentlyValidPageCount
&& mbContainsPageCountField
)
232 nCurrentlyValidPageCount
= getPageCount(xCurrentlyVisualizingPage
);
235 if(!bNewTextBackgroundColorIsSet
&& getSdrText() && getSdrText()->GetModel())
237 SdrOutliner
& rDrawOutliner
= getSdrText()->GetModel()->GetDrawOutliner(0);
238 aNewTextBackgroundColor
= rDrawOutliner
.GetBackgroundColor();
241 const_cast< SdrTextPrimitive2D
* >(this)->mxLastVisualizingPage
= xCurrentlyVisualizingPage
;
242 const_cast< SdrTextPrimitive2D
* >(this)->mnLastPageNumber
= nCurrentlyValidPageNumber
;
243 const_cast< SdrTextPrimitive2D
* >(this)->mnLastPageCount
= nCurrentlyValidPageCount
;
244 const_cast< SdrTextPrimitive2D
* >(this)->maLastTextBackgroundColor
= aNewTextBackgroundColor
;
248 return BasePrimitive2D::get2DDecomposition(rViewInformation
);
250 } // end of namespace primitive2d
251 } // end of namespace drawinglayer
253 //////////////////////////////////////////////////////////////////////////////
255 namespace drawinglayer
257 namespace primitive2d
259 Primitive2DSequence
SdrContourTextPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D
& aViewInformation
) const
261 Primitive2DSequence aRetval
;
262 getSdrText()->GetObject().impDecomposeContourTextPrimitive(aRetval
, *this, aViewInformation
);
264 return encapsulateWithTextHierarchyBlockPrimitive2D(aRetval
);
267 SdrContourTextPrimitive2D::SdrContourTextPrimitive2D(
268 const SdrText
* pSdrText
,
269 const OutlinerParaObject
& rOutlinerParaObject
,
270 const basegfx::B2DPolyPolygon
& rUnitPolyPolygon
,
271 const basegfx::B2DHomMatrix
& rObjectTransform
)
272 : SdrTextPrimitive2D(pSdrText
, rOutlinerParaObject
),
273 maUnitPolyPolygon(rUnitPolyPolygon
),
274 maObjectTransform(rObjectTransform
)
278 bool SdrContourTextPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
280 if(SdrTextPrimitive2D::operator==(rPrimitive
))
282 const SdrContourTextPrimitive2D
& rCompare
= (SdrContourTextPrimitive2D
&)rPrimitive
;
284 return (getUnitPolyPolygon() == rCompare
.getUnitPolyPolygon()
285 && getObjectTransform() == rCompare
.getObjectTransform());
291 SdrTextPrimitive2D
* SdrContourTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix
& rTransform
) const
293 return new SdrContourTextPrimitive2D(
295 getOutlinerParaObject(),
296 getUnitPolyPolygon(),
297 rTransform
* getObjectTransform());
301 ImplPrimitrive2DIDBlock(SdrContourTextPrimitive2D
, PRIMITIVE2D_ID_SDRCONTOURTEXTPRIMITIVE2D
)
303 } // end of namespace primitive2d
304 } // end of namespace drawinglayer
306 //////////////////////////////////////////////////////////////////////////////
308 namespace drawinglayer
310 namespace primitive2d
312 Primitive2DSequence
SdrPathTextPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D
& aViewInformation
) const
314 Primitive2DSequence aRetval
;
315 getSdrText()->GetObject().impDecomposePathTextPrimitive(aRetval
, *this, aViewInformation
);
317 return encapsulateWithTextHierarchyBlockPrimitive2D(aRetval
);
320 SdrPathTextPrimitive2D::SdrPathTextPrimitive2D(
321 const SdrText
* pSdrText
,
322 const OutlinerParaObject
& rOutlinerParaObject
,
323 const basegfx::B2DPolyPolygon
& rPathPolyPolygon
,
324 const attribute::SdrFormTextAttribute
& rSdrFormTextAttribute
)
325 : SdrTextPrimitive2D(pSdrText
, rOutlinerParaObject
),
326 maPathPolyPolygon(rPathPolyPolygon
),
327 maSdrFormTextAttribute(rSdrFormTextAttribute
)
331 bool SdrPathTextPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
333 if(SdrTextPrimitive2D::operator==(rPrimitive
))
335 const SdrPathTextPrimitive2D
& rCompare
= (SdrPathTextPrimitive2D
&)rPrimitive
;
337 return (getPathPolyPolygon() == rCompare
.getPathPolyPolygon()
338 && getSdrFormTextAttribute() == rCompare
.getSdrFormTextAttribute());
344 SdrTextPrimitive2D
* SdrPathTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix
& rTransform
) const
346 basegfx::B2DPolyPolygon
aNewPolyPolygon(getPathPolyPolygon());
347 aNewPolyPolygon
.transform(rTransform
);
349 return new SdrPathTextPrimitive2D(
351 getOutlinerParaObject(),
353 getSdrFormTextAttribute());
357 ImplPrimitrive2DIDBlock(SdrPathTextPrimitive2D
, PRIMITIVE2D_ID_SDRPATHTEXTPRIMITIVE2D
)
359 } // end of namespace primitive2d
360 } // end of namespace drawinglayer
362 //////////////////////////////////////////////////////////////////////////////
364 namespace drawinglayer
366 namespace primitive2d
368 Primitive2DSequence
SdrBlockTextPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D
& aViewInformation
) const
370 Primitive2DSequence aRetval
;
371 getSdrText()->GetObject().impDecomposeBlockTextPrimitive(aRetval
, *this, aViewInformation
);
373 return encapsulateWithTextHierarchyBlockPrimitive2D(aRetval
);
376 SdrBlockTextPrimitive2D::SdrBlockTextPrimitive2D(
377 const SdrText
* pSdrText
,
378 const OutlinerParaObject
& rOutlinerParaObject
,
379 const basegfx::B2DHomMatrix
& rTextRangeTransform
,
380 SdrTextHorzAdjust aSdrTextHorzAdjust
,
381 SdrTextVertAdjust aSdrTextVertAdjust
,
382 bool bFixedCellHeight
,
386 : SdrTextPrimitive2D(pSdrText
, rOutlinerParaObject
),
387 maTextRangeTransform(rTextRangeTransform
),
388 maSdrTextHorzAdjust(aSdrTextHorzAdjust
),
389 maSdrTextVertAdjust(aSdrTextVertAdjust
),
390 mbFixedCellHeight(bFixedCellHeight
),
391 mbUnlimitedPage(bUnlimitedPage
),
392 mbCellText(bCellText
),
393 mbWordWrap(bWordWrap
)
397 bool SdrBlockTextPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
399 if(SdrTextPrimitive2D::operator==(rPrimitive
))
401 const SdrBlockTextPrimitive2D
& rCompare
= (SdrBlockTextPrimitive2D
&)rPrimitive
;
403 return (getTextRangeTransform() == rCompare
.getTextRangeTransform()
404 && getSdrTextHorzAdjust() == rCompare
.getSdrTextHorzAdjust()
405 && getSdrTextVertAdjust() == rCompare
.getSdrTextVertAdjust()
406 && isFixedCellHeight() == rCompare
.isFixedCellHeight()
407 && getUnlimitedPage() == rCompare
.getUnlimitedPage()
408 && getCellText() == rCompare
.getCellText()
409 && getWordWrap() == rCompare
.getWordWrap());
415 SdrTextPrimitive2D
* SdrBlockTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix
& rTransform
) const
417 return new SdrBlockTextPrimitive2D(
419 getOutlinerParaObject(),
420 rTransform
* getTextRangeTransform(),
421 getSdrTextHorzAdjust(),
422 getSdrTextVertAdjust(),
430 ImplPrimitrive2DIDBlock(SdrBlockTextPrimitive2D
, PRIMITIVE2D_ID_SDRBLOCKTEXTPRIMITIVE2D
)
432 } // end of namespace primitive2d
433 } // end of namespace drawinglayer
435 //////////////////////////////////////////////////////////////////////////////
437 namespace drawinglayer
439 namespace primitive2d
441 Primitive2DSequence
SdrAutoFitTextPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D
& aViewInformation
) const
443 Primitive2DSequence aRetval
;
444 getSdrText()->GetObject().impDecomposeAutoFitTextPrimitive(aRetval
, *this, aViewInformation
);
446 return encapsulateWithTextHierarchyBlockPrimitive2D(aRetval
);
449 SdrAutoFitTextPrimitive2D::SdrAutoFitTextPrimitive2D(
450 const SdrText
* pSdrText
,
451 const OutlinerParaObject
& rParaObj
,
452 const ::basegfx::B2DHomMatrix
& rTextRangeTransform
,
454 : SdrTextPrimitive2D(pSdrText
, rParaObj
),
455 maTextRangeTransform(rTextRangeTransform
),
456 mbWordWrap(bWordWrap
)
460 bool SdrAutoFitTextPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
462 if(SdrTextPrimitive2D::operator==(rPrimitive
))
464 const SdrBlockTextPrimitive2D
& rCompare
= (SdrBlockTextPrimitive2D
&)rPrimitive
;
466 return (getTextRangeTransform() == rCompare
.getTextRangeTransform()
467 && getWordWrap() == rCompare
.getWordWrap());
473 SdrTextPrimitive2D
* SdrAutoFitTextPrimitive2D::createTransformedClone(const ::basegfx::B2DHomMatrix
& rTransform
) const
475 return new SdrAutoFitTextPrimitive2D(getSdrText(), getOutlinerParaObject(), rTransform
* getTextRangeTransform(), getWordWrap());
479 ImplPrimitrive2DIDBlock(SdrAutoFitTextPrimitive2D
, PRIMITIVE2D_ID_SDRAUTOFITTEXTPRIMITIVE2D
)
481 } // end of namespace primitive2d
482 } // end of namespace drawinglayer
484 //////////////////////////////////////////////////////////////////////////////
486 namespace drawinglayer
488 namespace primitive2d
490 Primitive2DSequence
SdrStretchTextPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D
& aViewInformation
) const
492 Primitive2DSequence aRetval
;
493 getSdrText()->GetObject().impDecomposeStretchTextPrimitive(aRetval
, *this, aViewInformation
);
495 return encapsulateWithTextHierarchyBlockPrimitive2D(aRetval
);
498 SdrStretchTextPrimitive2D::SdrStretchTextPrimitive2D(
499 const SdrText
* pSdrText
,
500 const OutlinerParaObject
& rOutlinerParaObject
,
501 const basegfx::B2DHomMatrix
& rTextRangeTransform
,
502 bool bFixedCellHeight
)
503 : SdrTextPrimitive2D(pSdrText
, rOutlinerParaObject
),
504 maTextRangeTransform(rTextRangeTransform
),
505 mbFixedCellHeight(bFixedCellHeight
)
509 bool SdrStretchTextPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
511 if(SdrTextPrimitive2D::operator==(rPrimitive
))
513 const SdrStretchTextPrimitive2D
& rCompare
= (SdrStretchTextPrimitive2D
&)rPrimitive
;
515 return (getTextRangeTransform() == rCompare
.getTextRangeTransform()
516 && isFixedCellHeight() == rCompare
.isFixedCellHeight());
522 SdrTextPrimitive2D
* SdrStretchTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix
& rTransform
) const
524 return new SdrStretchTextPrimitive2D(
526 getOutlinerParaObject(),
527 rTransform
* getTextRangeTransform(),
528 isFixedCellHeight());
532 ImplPrimitrive2DIDBlock(SdrStretchTextPrimitive2D
, PRIMITIVE2D_ID_SDRSTRETCHTEXTPRIMITIVE2D
)
534 } // end of namespace primitive2d
535 } // end of namespace drawinglayer
537 //////////////////////////////////////////////////////////////////////////////