Bump version to 6.4-15
[LibreOffice.git] / svx / source / sdr / primitive2d / sdrtextprimitive2d.cxx
blob00a5aa89c17cdda73e27aedbc2d7a985b3657b99
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <basegfx/color/bcolor.hxx>
23 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
24 #include <drawinglayer/primitive2d/texthierarchyprimitive2d.hxx>
25 #include <editeng/outlobj.hxx>
26 #include <editeng/editobj.hxx>
27 #include <editeng/flditem.hxx>
28 #include <drawinglayer/geometry/viewinformation2d.hxx>
29 #include <svx/unoapi.hxx>
30 #include <svx/svdpage.hxx>
31 #include <svx/svdmodel.hxx>
32 #include <svx/svdoutl.hxx>
33 #include <com/sun/star/beans/XPropertySet.hpp>
36 using namespace com::sun::star;
39 namespace
41 sal_Int16 getPageNumber(const uno::Reference< drawing::XDrawPage >& rxDrawPage)
43 sal_Int16 nRetval(0);
44 uno::Reference< beans::XPropertySet > xSet(rxDrawPage, uno::UNO_QUERY);
46 if (xSet.is())
48 try
50 const uno::Any aNumber(xSet->getPropertyValue("Number"));
51 aNumber >>= nRetval;
53 catch(const uno::Exception&)
55 OSL_ASSERT(false);
59 return nRetval;
62 sal_Int16 getPageCount(const uno::Reference< drawing::XDrawPage >& rxDrawPage)
64 sal_Int16 nRetval(0);
65 SdrPage* pPage = GetSdrPageFromXDrawPage(rxDrawPage);
67 if(pPage)
69 if( (pPage->GetPageNum() == 0) && !pPage->IsMasterPage() )
71 // handout page!
72 return pPage->getSdrModelFromSdrPage().getHandoutPageCount();
74 else
76 const sal_uInt16 nPageCount(pPage->getSdrModelFromSdrPage().GetPageCount());
77 nRetval = (static_cast<sal_Int16>(nPageCount) - 1) / 2;
81 return nRetval;
83 } // end of anonymous namespace
86 namespace drawinglayer
88 namespace primitive2d
90 // support for XTEXT_PAINTSHAPE_BEGIN/XTEXT_PAINTSHAPE_END Metafile comments
91 // for slideshow. This uses TextHierarchyBlockPrimitive2D to mark a text block.
92 // ATM there is only one text block per SdrObject, this may get more in the future
93 void SdrTextPrimitive2D::encapsulateWithTextHierarchyBlockPrimitive2D(Primitive2DContainer& rContainer, const Primitive2DContainer& rCandidate)
95 rContainer.push_back(new TextHierarchyBlockPrimitive2D(rCandidate));
98 SdrTextPrimitive2D::SdrTextPrimitive2D(
99 const SdrText* pSdrText,
100 const OutlinerParaObject& rOutlinerParaObject)
101 : BufferedDecompositionPrimitive2D(),
102 mrSdrText(const_cast< SdrText* >(pSdrText)),
103 maOutlinerParaObject(rOutlinerParaObject),
104 mxLastVisualizingPage(),
105 mnLastPageNumber(0),
106 mnLastPageCount(0),
107 maLastTextBackgroundColor(),
108 mbContainsPageField(false),
109 mbContainsPageCountField(false),
110 mbContainsOtherFields(false)
112 const EditTextObject& rETO = maOutlinerParaObject.GetTextObject();
114 mbContainsPageField = rETO.HasField(SvxPageField::CLASS_ID);
115 mbContainsPageCountField = rETO.HasField(SvxPagesField::CLASS_ID);
116 mbContainsOtherFields = rETO.HasField(SvxHeaderField::CLASS_ID)
117 || rETO.HasField(SvxFooterField::CLASS_ID)
118 || rETO.HasField(SvxDateTimeField::CLASS_ID)
119 || rETO.HasField(SvxAuthorField::CLASS_ID);
122 const SdrText* SdrTextPrimitive2D::getSdrText() const { return mrSdrText.get(); }
124 bool SdrTextPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
126 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
128 const SdrTextPrimitive2D& rCompare = static_cast<const SdrTextPrimitive2D&>(rPrimitive);
130 return (
132 // compare OPO and content, but not WrongList
133 getOutlinerParaObject() == rCompare.getOutlinerParaObject()
135 // also compare WrongList (not-persistent data, but visualized)
136 && getOutlinerParaObject().isWrongListEqual(rCompare.getOutlinerParaObject()));
139 return false;
142 void SdrTextPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const
144 uno::Reference< drawing::XDrawPage > xCurrentlyVisualizingPage;
145 bool bCurrentlyVisualizingPageIsSet(false);
146 Color aNewTextBackgroundColor;
147 bool bNewTextBackgroundColorIsSet(false);
148 sal_Int16 nCurrentlyValidPageNumber(0);
149 sal_Int16 nCurrentlyValidPageCount(0);
151 if(!getBuffered2DDecomposition().empty())
153 bool bDoDelete(false);
155 // check visualized page
156 if(mbContainsPageField || mbContainsPageCountField || mbContainsOtherFields)
158 // get visualized page and remember
159 xCurrentlyVisualizingPage = rViewInformation.getVisualizedPage();
160 bCurrentlyVisualizingPageIsSet = true;
162 if(xCurrentlyVisualizingPage != mxLastVisualizingPage)
164 bDoDelete = true;
167 // #i98870# check visualized PageNumber
168 if(!bDoDelete && mbContainsPageField)
170 nCurrentlyValidPageNumber = getPageNumber(xCurrentlyVisualizingPage);
172 if(nCurrentlyValidPageNumber != mnLastPageNumber)
174 bDoDelete = true;
178 // #i98870# check visualized PageCount, too
179 if(!bDoDelete && mbContainsPageCountField)
181 nCurrentlyValidPageCount = getPageCount(xCurrentlyVisualizingPage);
183 if(nCurrentlyValidPageCount != mnLastPageCount)
185 bDoDelete = true;
190 // #i101443# check change of TextBackgroundolor
191 if(!bDoDelete && getSdrText())
193 SdrOutliner& rDrawOutliner = getSdrText()->GetObject().getSdrModelFromSdrObject().GetDrawOutliner();
194 aNewTextBackgroundColor = rDrawOutliner.GetBackgroundColor();
195 bNewTextBackgroundColorIsSet = true;
197 if(aNewTextBackgroundColor != maLastTextBackgroundColor)
199 bDoDelete = true;
203 if(bDoDelete)
205 const_cast< SdrTextPrimitive2D* >(this)->setBuffered2DDecomposition(Primitive2DContainer());
209 if(getBuffered2DDecomposition().empty())
211 if(!bCurrentlyVisualizingPageIsSet && mbContainsPageField)
213 xCurrentlyVisualizingPage = rViewInformation.getVisualizedPage();
216 if(!nCurrentlyValidPageNumber && mbContainsPageField)
218 nCurrentlyValidPageNumber = getPageNumber(xCurrentlyVisualizingPage);
221 if(!nCurrentlyValidPageCount && mbContainsPageCountField)
223 nCurrentlyValidPageCount = getPageCount(xCurrentlyVisualizingPage);
226 if(!bNewTextBackgroundColorIsSet && getSdrText())
228 SdrOutliner& rDrawOutliner = getSdrText()->GetObject().getSdrModelFromSdrObject().GetDrawOutliner();
229 aNewTextBackgroundColor = rDrawOutliner.GetBackgroundColor();
232 const_cast< SdrTextPrimitive2D* >(this)->mxLastVisualizingPage = xCurrentlyVisualizingPage;
233 const_cast< SdrTextPrimitive2D* >(this)->mnLastPageNumber = nCurrentlyValidPageNumber;
234 const_cast< SdrTextPrimitive2D* >(this)->mnLastPageCount = nCurrentlyValidPageCount;
235 const_cast< SdrTextPrimitive2D* >(this)->maLastTextBackgroundColor = aNewTextBackgroundColor;
238 // call parent
239 BufferedDecompositionPrimitive2D::get2DDecomposition(rVisitor, rViewInformation);
241 } // end of namespace primitive2d
242 } // end of namespace drawinglayer
245 namespace drawinglayer
247 namespace primitive2d
249 void SdrContourTextPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& aViewInformation) const
251 Primitive2DContainer aRetval;
252 getSdrText()->GetObject().impDecomposeContourTextPrimitive(aRetval, *this, aViewInformation);
254 encapsulateWithTextHierarchyBlockPrimitive2D(rContainer, aRetval);
257 SdrContourTextPrimitive2D::SdrContourTextPrimitive2D(
258 const SdrText* pSdrText,
259 const OutlinerParaObject& rOutlinerParaObject,
260 const basegfx::B2DPolyPolygon& rUnitPolyPolygon,
261 const basegfx::B2DHomMatrix& rObjectTransform)
262 : SdrTextPrimitive2D(pSdrText, rOutlinerParaObject),
263 maUnitPolyPolygon(rUnitPolyPolygon),
264 maObjectTransform(rObjectTransform)
268 bool SdrContourTextPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
270 if(SdrTextPrimitive2D::operator==(rPrimitive))
272 const SdrContourTextPrimitive2D& rCompare = static_cast<const SdrContourTextPrimitive2D&>(rPrimitive);
274 return (getUnitPolyPolygon() == rCompare.getUnitPolyPolygon()
275 && getObjectTransform() == rCompare.getObjectTransform());
278 return false;
281 std::unique_ptr<SdrTextPrimitive2D> SdrContourTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix& rTransform) const
283 return std::make_unique<SdrContourTextPrimitive2D>(
284 getSdrText(),
285 getOutlinerParaObject(),
286 getUnitPolyPolygon(),
287 rTransform * getObjectTransform());
290 // provide unique ID
291 ImplPrimitive2DIDBlock(SdrContourTextPrimitive2D, PRIMITIVE2D_ID_SDRCONTOURTEXTPRIMITIVE2D)
293 } // end of namespace primitive2d
294 } // end of namespace drawinglayer
297 namespace drawinglayer
299 namespace primitive2d
301 void SdrPathTextPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& aViewInformation) const
303 Primitive2DContainer aRetval;
304 getSdrText()->GetObject().impDecomposePathTextPrimitive(aRetval, *this, aViewInformation);
306 encapsulateWithTextHierarchyBlockPrimitive2D(rContainer, aRetval);
309 SdrPathTextPrimitive2D::SdrPathTextPrimitive2D(
310 const SdrText* pSdrText,
311 const OutlinerParaObject& rOutlinerParaObject,
312 const basegfx::B2DPolyPolygon& rPathPolyPolygon,
313 const attribute::SdrFormTextAttribute& rSdrFormTextAttribute)
314 : SdrTextPrimitive2D(pSdrText, rOutlinerParaObject),
315 maPathPolyPolygon(rPathPolyPolygon),
316 maSdrFormTextAttribute(rSdrFormTextAttribute)
320 bool SdrPathTextPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
322 if(SdrTextPrimitive2D::operator==(rPrimitive))
324 const SdrPathTextPrimitive2D& rCompare = static_cast<const SdrPathTextPrimitive2D&>(rPrimitive);
326 return (getPathPolyPolygon() == rCompare.getPathPolyPolygon()
327 && getSdrFormTextAttribute() == rCompare.getSdrFormTextAttribute());
330 return false;
333 std::unique_ptr<SdrTextPrimitive2D> SdrPathTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix& rTransform) const
335 basegfx::B2DPolyPolygon aNewPolyPolygon(getPathPolyPolygon());
336 aNewPolyPolygon.transform(rTransform);
338 return std::make_unique<SdrPathTextPrimitive2D>(
339 getSdrText(),
340 getOutlinerParaObject(),
341 aNewPolyPolygon,
342 getSdrFormTextAttribute());
345 // provide unique ID
346 ImplPrimitive2DIDBlock(SdrPathTextPrimitive2D, PRIMITIVE2D_ID_SDRPATHTEXTPRIMITIVE2D)
348 } // end of namespace primitive2d
349 } // end of namespace drawinglayer
352 namespace drawinglayer
354 namespace primitive2d
356 void SdrBlockTextPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& aViewInformation) const
358 Primitive2DContainer aRetval;
359 getSdrText()->GetObject().impDecomposeBlockTextPrimitive(aRetval, *this, aViewInformation);
361 encapsulateWithTextHierarchyBlockPrimitive2D(rContainer, aRetval);
364 SdrBlockTextPrimitive2D::SdrBlockTextPrimitive2D(
365 const SdrText* pSdrText,
366 const OutlinerParaObject& rOutlinerParaObject,
367 const basegfx::B2DHomMatrix& rTextRangeTransform,
368 SdrTextHorzAdjust aSdrTextHorzAdjust,
369 SdrTextVertAdjust aSdrTextVertAdjust,
370 bool bFixedCellHeight,
371 bool bUnlimitedPage,
372 bool bCellText,
373 bool bWordWrap,
374 bool bClipOnBounds)
375 : SdrTextPrimitive2D(pSdrText, rOutlinerParaObject),
376 maTextRangeTransform(rTextRangeTransform),
377 maSdrTextHorzAdjust(aSdrTextHorzAdjust),
378 maSdrTextVertAdjust(aSdrTextVertAdjust),
379 mbFixedCellHeight(bFixedCellHeight),
380 mbUnlimitedPage(bUnlimitedPage),
381 mbCellText(bCellText),
382 mbWordWrap(bWordWrap),
383 mbClipOnBounds(bClipOnBounds)
387 bool SdrBlockTextPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
389 if(SdrTextPrimitive2D::operator==(rPrimitive))
391 const SdrBlockTextPrimitive2D& rCompare = static_cast<const SdrBlockTextPrimitive2D&>(rPrimitive);
393 return (getTextRangeTransform() == rCompare.getTextRangeTransform()
394 && getSdrTextHorzAdjust() == rCompare.getSdrTextHorzAdjust()
395 && getSdrTextVertAdjust() == rCompare.getSdrTextVertAdjust()
396 && isFixedCellHeight() == rCompare.isFixedCellHeight()
397 && getUnlimitedPage() == rCompare.getUnlimitedPage()
398 && getCellText() == rCompare.getCellText()
399 && getWordWrap() == rCompare.getWordWrap()
400 && getClipOnBounds() == rCompare.getClipOnBounds());
403 return false;
406 std::unique_ptr<SdrTextPrimitive2D> SdrBlockTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix& rTransform) const
408 return std::make_unique<SdrBlockTextPrimitive2D>(
409 getSdrText(),
410 getOutlinerParaObject(),
411 rTransform * getTextRangeTransform(),
412 getSdrTextHorzAdjust(),
413 getSdrTextVertAdjust(),
414 isFixedCellHeight(),
415 getUnlimitedPage(),
416 getCellText(),
417 getWordWrap(),
418 getClipOnBounds());
421 // provide unique ID
422 ImplPrimitive2DIDBlock(SdrBlockTextPrimitive2D, PRIMITIVE2D_ID_SDRBLOCKTEXTPRIMITIVE2D)
424 } // end of namespace primitive2d
425 } // end of namespace drawinglayer
428 namespace drawinglayer
430 namespace primitive2d
432 void SdrAutoFitTextPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& aViewInformation) const
434 Primitive2DContainer aRetval;
435 getSdrText()->GetObject().impDecomposeAutoFitTextPrimitive(aRetval, *this, aViewInformation);
437 encapsulateWithTextHierarchyBlockPrimitive2D(rContainer, aRetval);
440 SdrAutoFitTextPrimitive2D::SdrAutoFitTextPrimitive2D(
441 const SdrText* pSdrText,
442 const OutlinerParaObject& rParaObj,
443 const ::basegfx::B2DHomMatrix& rTextRangeTransform,
444 bool bWordWrap)
445 : SdrTextPrimitive2D(pSdrText, rParaObj),
446 maTextRangeTransform(rTextRangeTransform),
447 mbWordWrap(bWordWrap)
451 bool SdrAutoFitTextPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
453 if(SdrTextPrimitive2D::operator==(rPrimitive))
455 const SdrBlockTextPrimitive2D& rCompare = static_cast<const SdrBlockTextPrimitive2D&>(rPrimitive);
457 return (getTextRangeTransform() == rCompare.getTextRangeTransform()
458 && getWordWrap() == rCompare.getWordWrap());
461 return false;
464 std::unique_ptr<SdrTextPrimitive2D> SdrAutoFitTextPrimitive2D::createTransformedClone(const ::basegfx::B2DHomMatrix& rTransform) const
466 return std::make_unique<SdrAutoFitTextPrimitive2D>(getSdrText(), getOutlinerParaObject(), rTransform * getTextRangeTransform(), getWordWrap());
469 // provide unique ID
470 ImplPrimitive2DIDBlock(SdrAutoFitTextPrimitive2D, PRIMITIVE2D_ID_SDRAUTOFITTEXTPRIMITIVE2D)
472 } // end of namespace primitive2d
473 } // end of namespace drawinglayer
475 namespace drawinglayer
477 namespace primitive2d
480 SdrChainedTextPrimitive2D::SdrChainedTextPrimitive2D(
481 const SdrText* pSdrText,
482 const OutlinerParaObject& rOutlinerParaObject,
483 const basegfx::B2DHomMatrix& rTextRangeTransform)
484 : SdrTextPrimitive2D(pSdrText, rOutlinerParaObject),
485 maTextRangeTransform(rTextRangeTransform)
488 void SdrChainedTextPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& aViewInformation) const
490 Primitive2DContainer aRetval;
491 getSdrText()->GetObject().impDecomposeChainedTextPrimitive(aRetval, *this, aViewInformation);
493 encapsulateWithTextHierarchyBlockPrimitive2D(rContainer, aRetval);
496 bool SdrChainedTextPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
498 if(SdrTextPrimitive2D::operator==(rPrimitive))
500 const SdrBlockTextPrimitive2D& rCompare = static_cast<const SdrBlockTextPrimitive2D&>(rPrimitive);
502 return (getTextRangeTransform() == rCompare.getTextRangeTransform());
505 return false;
508 std::unique_ptr<SdrTextPrimitive2D> SdrChainedTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix& rTransform) const
510 return std::make_unique<SdrChainedTextPrimitive2D>(getSdrText(), getOutlinerParaObject(), rTransform * getTextRangeTransform());
513 // provide unique ID
514 ImplPrimitive2DIDBlock(SdrChainedTextPrimitive2D, PRIMITIVE2D_ID_SDRCHAINEDTEXTPRIMITIVE2D)
515 } // end of namespace primitive2d
516 } // end of namespace drawinglayer
519 namespace drawinglayer
521 namespace primitive2d
523 void SdrStretchTextPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& aViewInformation) const
525 Primitive2DContainer aRetval;
526 getSdrText()->GetObject().impDecomposeStretchTextPrimitive(aRetval, *this, aViewInformation);
528 encapsulateWithTextHierarchyBlockPrimitive2D(rContainer, aRetval);
531 SdrStretchTextPrimitive2D::SdrStretchTextPrimitive2D(
532 const SdrText* pSdrText,
533 const OutlinerParaObject& rOutlinerParaObject,
534 const basegfx::B2DHomMatrix& rTextRangeTransform,
535 bool bFixedCellHeight)
536 : SdrTextPrimitive2D(pSdrText, rOutlinerParaObject),
537 maTextRangeTransform(rTextRangeTransform),
538 mbFixedCellHeight(bFixedCellHeight)
542 bool SdrStretchTextPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
544 if(SdrTextPrimitive2D::operator==(rPrimitive))
546 const SdrStretchTextPrimitive2D& rCompare = static_cast<const SdrStretchTextPrimitive2D&>(rPrimitive);
548 return (getTextRangeTransform() == rCompare.getTextRangeTransform()
549 && isFixedCellHeight() == rCompare.isFixedCellHeight());
552 return false;
555 std::unique_ptr<SdrTextPrimitive2D> SdrStretchTextPrimitive2D::createTransformedClone(const basegfx::B2DHomMatrix& rTransform) const
557 return std::make_unique<SdrStretchTextPrimitive2D>(
558 getSdrText(),
559 getOutlinerParaObject(),
560 rTransform * getTextRangeTransform(),
561 isFixedCellHeight());
564 // provide unique ID
565 ImplPrimitive2DIDBlock(SdrStretchTextPrimitive2D, PRIMITIVE2D_ID_SDRSTRETCHTEXTPRIMITIVE2D)
567 } // end of namespace primitive2d
568 } // end of namespace drawinglayer
570 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */