1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sdr/primitive2d/sdrtextprimitive2d.hxx>
21 #include <svx/svdotext.hxx>
22 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
23 #include <drawinglayer/primitive2d/texthierarchyprimitive2d.hxx>
24 #include <editeng/outlobj.hxx>
25 #include <editeng/editobj.hxx>
26 #include <editeng/flditem.hxx>
27 #include <drawinglayer/geometry/viewinformation2d.hxx>
28 #include <svx/unoapi.hxx>
29 #include <svx/svdpage.hxx>
30 #include <svx/svdmodel.hxx>
31 #include <svx/svdoutl.hxx>
32 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <osl/diagnose.h>
37 using namespace com::sun::star
;
42 sal_Int16
getPageNumber(const uno::Reference
< drawing::XDrawPage
>& rxDrawPage
)
45 uno::Reference
< beans::XPropertySet
> xSet(rxDrawPage
, uno::UNO_QUERY
);
51 const uno::Any
aNumber(xSet
->getPropertyValue("Number"));
54 catch(const uno::Exception
&)
63 sal_Int16
getPageCount(const uno::Reference
< drawing::XDrawPage
>& rxDrawPage
)
66 SdrPage
* pPage
= GetSdrPageFromXDrawPage(rxDrawPage
);
70 if( (pPage
->GetPageNum() == 0) && !pPage
->IsMasterPage() )
73 return pPage
->getSdrModelFromSdrPage().getHandoutPageCount();
77 const sal_uInt16
nPageCount(pPage
->getSdrModelFromSdrPage().GetPageCount());
78 nRetval
= (static_cast<sal_Int16
>(nPageCount
) - 1) / 2;
84 } // end of anonymous namespace
87 namespace drawinglayer::primitive2d
89 // support for XTEXT_PAINTSHAPE_BEGIN/XTEXT_PAINTSHAPE_END Metafile comments
90 // for slideshow. This uses TextHierarchyBlockPrimitive2D to mark a text block.
91 // ATM there is only one text block per SdrObject, this may get more in the future
92 void SdrTextPrimitive2D::encapsulateWithTextHierarchyBlockPrimitive2D(Primitive2DContainer
& rContainer
, Primitive2DContainer
&& aCandidate
)
94 rContainer
.push_back(new TextHierarchyBlockPrimitive2D(drawinglayer::primitive2d::Primitive2DContainer(aCandidate
)));
97 SdrTextPrimitive2D::SdrTextPrimitive2D(
98 const SdrText
* pSdrText
,
99 OutlinerParaObject aOutlinerParaObject
)
100 : mxSdrText(const_cast< SdrText
* >(pSdrText
)),
101 maOutlinerParaObject(std::move(aOutlinerParaObject
)),
104 mbContainsPageField(false),
105 mbContainsPageCountField(false),
106 mbContainsOtherFields(false)
108 const EditTextObject
& rETO
= maOutlinerParaObject
.GetTextObject();
110 mbContainsPageField
= rETO
.HasField(SvxPageField::CLASS_ID
);
111 mbContainsPageCountField
= rETO
.HasField(SvxPagesField::CLASS_ID
);
112 mbContainsOtherFields
= rETO
.HasField(SvxHeaderField::CLASS_ID
)
113 || rETO
.HasField(SvxFooterField::CLASS_ID
)
114 || rETO
.HasField(SvxDateTimeField::CLASS_ID
)
115 || rETO
.HasField(SvxAuthorField::CLASS_ID
);
118 const SdrText
* SdrTextPrimitive2D::getSdrText() const { return mxSdrText
.get().get(); }
120 bool SdrTextPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
122 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive
))
124 const SdrTextPrimitive2D
& rCompare
= static_cast<const SdrTextPrimitive2D
&>(rPrimitive
);
128 // compare OPO and content, but not WrongList
129 getOutlinerParaObject() == rCompare
.getOutlinerParaObject()
131 // also compare WrongList (not-persistent data, but visualized)
132 && getOutlinerParaObject().isWrongListEqual(rCompare
.getOutlinerParaObject()));
138 void SdrTextPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor
& rVisitor
, const geometry::ViewInformation2D
& rViewInformation
) const
140 uno::Reference
< drawing::XDrawPage
> xCurrentlyVisualizingPage
;
141 bool bCurrentlyVisualizingPageIsSet(false);
142 Color aNewTextBackgroundColor
;
143 bool bNewTextBackgroundColorIsSet(false);
144 sal_Int16
nCurrentlyValidPageNumber(0);
145 sal_Int16
nCurrentlyValidPageCount(0);
147 if(!getBuffered2DDecomposition().empty())
149 bool bDoDelete(false);
151 // check visualized page
152 if(mbContainsPageField
|| mbContainsPageCountField
|| mbContainsOtherFields
)
154 // get visualized page and remember
155 xCurrentlyVisualizingPage
= rViewInformation
.getVisualizedPage();
156 bCurrentlyVisualizingPageIsSet
= true;
158 if(xCurrentlyVisualizingPage
!= mxLastVisualizingPage
)
163 // #i98870# check visualized PageNumber
164 if(!bDoDelete
&& mbContainsPageField
)
166 nCurrentlyValidPageNumber
= getPageNumber(xCurrentlyVisualizingPage
);
168 if(nCurrentlyValidPageNumber
!= mnLastPageNumber
)
174 // #i98870# check visualized PageCount, too
175 if(!bDoDelete
&& mbContainsPageCountField
)
177 nCurrentlyValidPageCount
= getPageCount(xCurrentlyVisualizingPage
);
179 if(nCurrentlyValidPageCount
!= mnLastPageCount
)
186 // #i101443# check change of TextBackgroundolor
187 if(!bDoDelete
&& getSdrText())
189 SdrOutliner
& rDrawOutliner
= getSdrText()->GetObject().getSdrModelFromSdrObject().GetDrawOutliner();
190 aNewTextBackgroundColor
= rDrawOutliner
.GetBackgroundColor();
191 bNewTextBackgroundColorIsSet
= true;
193 if(aNewTextBackgroundColor
!= maLastTextBackgroundColor
)
201 const_cast< SdrTextPrimitive2D
* >(this)->setBuffered2DDecomposition(Primitive2DContainer());
205 if(getBuffered2DDecomposition().empty())
207 if(!bCurrentlyVisualizingPageIsSet
&& mbContainsPageField
)
209 xCurrentlyVisualizingPage
= rViewInformation
.getVisualizedPage();
212 if(!nCurrentlyValidPageNumber
&& mbContainsPageField
)
214 nCurrentlyValidPageNumber
= getPageNumber(xCurrentlyVisualizingPage
);
217 if(!nCurrentlyValidPageCount
&& mbContainsPageCountField
)
219 nCurrentlyValidPageCount
= getPageCount(xCurrentlyVisualizingPage
);
222 if(!bNewTextBackgroundColorIsSet
&& getSdrText())
224 SdrOutliner
& rDrawOutliner
= getSdrText()->GetObject().getSdrModelFromSdrObject().GetDrawOutliner();
225 aNewTextBackgroundColor
= rDrawOutliner
.GetBackgroundColor();
228 const_cast< SdrTextPrimitive2D
* >(this)->mxLastVisualizingPage
= xCurrentlyVisualizingPage
;
229 const_cast< SdrTextPrimitive2D
* >(this)->mnLastPageNumber
= nCurrentlyValidPageNumber
;
230 const_cast< SdrTextPrimitive2D
* >(this)->mnLastPageCount
= nCurrentlyValidPageCount
;
231 const_cast< SdrTextPrimitive2D
* >(this)->maLastTextBackgroundColor
= aNewTextBackgroundColor
;
235 BufferedDecompositionPrimitive2D::get2DDecomposition(rVisitor
, rViewInformation
);
241 void SdrContourTextPrimitive2D::create2DDecomposition(Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& aViewInformation
) const
243 Primitive2DContainer aRetval
;
244 getSdrText()->GetObject().impDecomposeContourTextPrimitive(aRetval
, *this, aViewInformation
);
246 encapsulateWithTextHierarchyBlockPrimitive2D(rContainer
, std::move(aRetval
));
249 SdrContourTextPrimitive2D::SdrContourTextPrimitive2D(
250 const SdrText
* pSdrText
,
251 const OutlinerParaObject
& rOutlinerParaObject
,
252 basegfx::B2DPolyPolygon aUnitPolyPolygon
,
253 basegfx::B2DHomMatrix aObjectTransform
)
254 : SdrTextPrimitive2D(pSdrText
, rOutlinerParaObject
),
255 maUnitPolyPolygon(std::move(aUnitPolyPolygon
)),
256 maObjectTransform(std::move(aObjectTransform
))
260 bool SdrContourTextPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
262 if(SdrTextPrimitive2D::operator==(rPrimitive
))
264 const SdrContourTextPrimitive2D
& rCompare
= static_cast<const SdrContourTextPrimitive2D
&>(rPrimitive
);
266 return (getUnitPolyPolygon() == rCompare
.getUnitPolyPolygon()
267 && getObjectTransform() == rCompare
.getObjectTransform());
273 rtl::Reference
<SdrTextPrimitive2D
> SdrContourTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix
& rTransform
) const
275 return new SdrContourTextPrimitive2D(
277 getOutlinerParaObject(),
278 getUnitPolyPolygon(),
279 rTransform
* getObjectTransform());
283 sal_uInt32
SdrContourTextPrimitive2D::getPrimitive2DID() const
285 return PRIMITIVE2D_ID_SDRCONTOURTEXTPRIMITIVE2D
;
290 void SdrPathTextPrimitive2D::create2DDecomposition(Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& aViewInformation
) const
292 Primitive2DContainer aRetval
;
293 getSdrText()->GetObject().impDecomposePathTextPrimitive(aRetval
, *this, aViewInformation
);
295 encapsulateWithTextHierarchyBlockPrimitive2D(rContainer
, std::move(aRetval
));
298 SdrPathTextPrimitive2D::SdrPathTextPrimitive2D(
299 const SdrText
* pSdrText
,
300 const OutlinerParaObject
& rOutlinerParaObject
,
301 basegfx::B2DPolyPolygon aPathPolyPolygon
,
302 attribute::SdrFormTextAttribute aSdrFormTextAttribute
)
303 : SdrTextPrimitive2D(pSdrText
, rOutlinerParaObject
),
304 maPathPolyPolygon(std::move(aPathPolyPolygon
)),
305 maSdrFormTextAttribute(std::move(aSdrFormTextAttribute
))
309 bool SdrPathTextPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
311 if(SdrTextPrimitive2D::operator==(rPrimitive
))
313 const SdrPathTextPrimitive2D
& rCompare
= static_cast<const SdrPathTextPrimitive2D
&>(rPrimitive
);
315 return (getPathPolyPolygon() == rCompare
.getPathPolyPolygon()
316 && getSdrFormTextAttribute() == rCompare
.getSdrFormTextAttribute());
322 rtl::Reference
<SdrTextPrimitive2D
> SdrPathTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix
& rTransform
) const
324 basegfx::B2DPolyPolygon
aNewPolyPolygon(getPathPolyPolygon());
325 aNewPolyPolygon
.transform(rTransform
);
327 return new SdrPathTextPrimitive2D(
329 getOutlinerParaObject(),
330 std::move(aNewPolyPolygon
),
331 getSdrFormTextAttribute());
335 sal_uInt32
SdrPathTextPrimitive2D::getPrimitive2DID() const
337 return PRIMITIVE2D_ID_SDRPATHTEXTPRIMITIVE2D
;
342 void SdrBlockTextPrimitive2D::create2DDecomposition(Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& aViewInformation
) const
344 Primitive2DContainer aRetval
;
345 getSdrText()->GetObject().impDecomposeBlockTextPrimitive(aRetval
, *this, aViewInformation
);
347 encapsulateWithTextHierarchyBlockPrimitive2D(rContainer
, std::move(aRetval
));
350 SdrBlockTextPrimitive2D::SdrBlockTextPrimitive2D(
351 const SdrText
* pSdrText
,
352 const OutlinerParaObject
& rOutlinerParaObject
,
353 basegfx::B2DHomMatrix aTextRangeTransform
,
354 SdrTextHorzAdjust aSdrTextHorzAdjust
,
355 SdrTextVertAdjust aSdrTextVertAdjust
,
356 bool bFixedCellHeight
,
360 : SdrTextPrimitive2D(pSdrText
, rOutlinerParaObject
),
361 maTextRangeTransform(std::move(aTextRangeTransform
)),
362 maSdrTextHorzAdjust(aSdrTextHorzAdjust
),
363 maSdrTextVertAdjust(aSdrTextVertAdjust
),
364 mbFixedCellHeight(bFixedCellHeight
),
365 mbUnlimitedPage(bUnlimitedPage
),
366 mbCellText(bCellText
),
367 mbWordWrap(bWordWrap
)
371 bool SdrBlockTextPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
373 if(SdrTextPrimitive2D::operator==(rPrimitive
))
375 const SdrBlockTextPrimitive2D
& rCompare
= static_cast<const SdrBlockTextPrimitive2D
&>(rPrimitive
);
377 return (getTextRangeTransform() == rCompare
.getTextRangeTransform()
378 && getSdrTextHorzAdjust() == rCompare
.getSdrTextHorzAdjust()
379 && getSdrTextVertAdjust() == rCompare
.getSdrTextVertAdjust()
380 && isFixedCellHeight() == rCompare
.isFixedCellHeight()
381 && getUnlimitedPage() == rCompare
.getUnlimitedPage()
382 && getCellText() == rCompare
.getCellText()
383 && getWordWrap() == rCompare
.getWordWrap());
389 rtl::Reference
<SdrTextPrimitive2D
> SdrBlockTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix
& rTransform
) const
391 return new SdrBlockTextPrimitive2D(
393 getOutlinerParaObject(),
394 rTransform
* getTextRangeTransform(),
395 getSdrTextHorzAdjust(),
396 getSdrTextVertAdjust(),
404 sal_uInt32
SdrBlockTextPrimitive2D::getPrimitive2DID() const
406 return PRIMITIVE2D_ID_SDRBLOCKTEXTPRIMITIVE2D
;
411 void SdrAutoFitTextPrimitive2D::create2DDecomposition(Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& aViewInformation
) const
413 Primitive2DContainer aRetval
;
414 getSdrText()->GetObject().impDecomposeAutoFitTextPrimitive(aRetval
, *this, aViewInformation
);
416 encapsulateWithTextHierarchyBlockPrimitive2D(rContainer
, std::move(aRetval
));
419 SdrAutoFitTextPrimitive2D::SdrAutoFitTextPrimitive2D(
420 const SdrText
* pSdrText
,
421 const OutlinerParaObject
& rParaObj
,
422 ::basegfx::B2DHomMatrix aTextRangeTransform
,
424 : SdrTextPrimitive2D(pSdrText
, rParaObj
),
425 maTextRangeTransform(std::move(aTextRangeTransform
)),
426 mbWordWrap(bWordWrap
)
430 bool SdrAutoFitTextPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
432 if(SdrTextPrimitive2D::operator==(rPrimitive
))
434 const SdrBlockTextPrimitive2D
& rCompare
= static_cast<const SdrBlockTextPrimitive2D
&>(rPrimitive
);
436 return (getTextRangeTransform() == rCompare
.getTextRangeTransform()
437 && getWordWrap() == rCompare
.getWordWrap());
443 rtl::Reference
<SdrTextPrimitive2D
> SdrAutoFitTextPrimitive2D::createTransformedClone(const ::basegfx::B2DHomMatrix
& rTransform
) const
445 return new SdrAutoFitTextPrimitive2D(getSdrText(), getOutlinerParaObject(), rTransform
* getTextRangeTransform(), getWordWrap());
449 sal_uInt32
SdrAutoFitTextPrimitive2D::getPrimitive2DID() const
451 return PRIMITIVE2D_ID_SDRAUTOFITTEXTPRIMITIVE2D
;
457 SdrChainedTextPrimitive2D::SdrChainedTextPrimitive2D(
458 const SdrText
* pSdrText
,
459 const OutlinerParaObject
& rOutlinerParaObject
,
460 basegfx::B2DHomMatrix aTextRangeTransform
)
461 : SdrTextPrimitive2D(pSdrText
, rOutlinerParaObject
),
462 maTextRangeTransform(std::move(aTextRangeTransform
))
465 void SdrChainedTextPrimitive2D::create2DDecomposition(Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& aViewInformation
) const
467 Primitive2DContainer aRetval
;
468 getSdrText()->GetObject().impDecomposeChainedTextPrimitive(aRetval
, *this, aViewInformation
);
470 encapsulateWithTextHierarchyBlockPrimitive2D(rContainer
, std::move(aRetval
));
473 bool SdrChainedTextPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
475 if(SdrTextPrimitive2D::operator==(rPrimitive
))
477 const SdrBlockTextPrimitive2D
& rCompare
= static_cast<const SdrBlockTextPrimitive2D
&>(rPrimitive
);
479 return (getTextRangeTransform() == rCompare
.getTextRangeTransform());
485 rtl::Reference
<SdrTextPrimitive2D
> SdrChainedTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix
& rTransform
) const
487 return new SdrChainedTextPrimitive2D(getSdrText(), getOutlinerParaObject(), rTransform
* getTextRangeTransform());
491 sal_uInt32
SdrChainedTextPrimitive2D::getPrimitive2DID() const
493 return PRIMITIVE2D_ID_SDRCHAINEDTEXTPRIMITIVE2D
;
497 void SdrStretchTextPrimitive2D::create2DDecomposition(Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& aViewInformation
) const
499 Primitive2DContainer aRetval
;
500 getSdrText()->GetObject().impDecomposeStretchTextPrimitive(aRetval
, *this, aViewInformation
);
502 encapsulateWithTextHierarchyBlockPrimitive2D(rContainer
, std::move(aRetval
));
505 SdrStretchTextPrimitive2D::SdrStretchTextPrimitive2D(
506 const SdrText
* pSdrText
,
507 const OutlinerParaObject
& rOutlinerParaObject
,
508 basegfx::B2DHomMatrix aTextRangeTransform
,
509 bool bFixedCellHeight
)
510 : SdrTextPrimitive2D(pSdrText
, rOutlinerParaObject
),
511 maTextRangeTransform(std::move(aTextRangeTransform
)),
512 mbFixedCellHeight(bFixedCellHeight
)
516 bool SdrStretchTextPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
518 if(SdrTextPrimitive2D::operator==(rPrimitive
))
520 const SdrStretchTextPrimitive2D
& rCompare
= static_cast<const SdrStretchTextPrimitive2D
&>(rPrimitive
);
522 return (getTextRangeTransform() == rCompare
.getTextRangeTransform()
523 && isFixedCellHeight() == rCompare
.isFixedCellHeight());
529 rtl::Reference
<SdrTextPrimitive2D
> SdrStretchTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix
& rTransform
) const
531 return new SdrStretchTextPrimitive2D(
533 getOutlinerParaObject(),
534 rTransform
* getTextRangeTransform(),
535 isFixedCellHeight());
539 sal_uInt32
SdrStretchTextPrimitive2D::getPrimitive2DID() const
541 return PRIMITIVE2D_ID_SDRSTRETCHTEXTPRIMITIVE2D
;
544 } // end of namespace
546 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */