xref: /trunk/main/svx/source/svdraw/svdotextpathdecomposition.cxx (revision 3ce6c2dd3860afd353ceca3849779821e9b9f6f5)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include <svx/svdotext.hxx>
28 #include <svx/svdoutl.hxx>
29 #include <basegfx/vector/b2dvector.hxx>
30 #include <svx/sdr/primitive2d/sdrtextprimitive2d.hxx>
31 #include <basegfx/range/b2drange.hxx>
32 #include <vcl/salbtype.hxx>
33 #include <svl/itemset.hxx>
34 #include <basegfx/polygon/b2dpolygontools.hxx>
35 #include <basegfx/polygon/b2dpolygon.hxx>
36 #include <algorithm>
37 #include <functional>
38 #include <svx/xtextit.hxx>
39 #include <svx/xftshtit.hxx>
40 #include <vcl/virdev.hxx>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/i18n/ScriptType.hdl>
43 #include <com/sun/star/i18n/XBreakIterator.hpp>
44 #include <comphelper/processfactory.hxx>
45 #include <com/sun/star/i18n/CharacterIteratorMode.hdl>
46 #include <editeng/unolingu.hxx>
47 #include <drawinglayer/primitive2d/textlayoutdevice.hxx>
48 #include <drawinglayer/primitive2d/textprimitive2d.hxx>
49 #include <basegfx/color/bcolor.hxx>
50 
51 //////////////////////////////////////////////////////////////////////////////
52 // primitive decomposition helpers
53 
54 #include <basegfx/polygon/b2dlinegeometry.hxx>
55 #include <drawinglayer/attribute/strokeattribute.hxx>
56 #include <svx/xlnclit.hxx>
57 #include <svx/xlntrit.hxx>
58 #include <svx/xlnwtit.hxx>
59 #include <svx/xlinjoit.hxx>
60 #include <svx/xlndsit.hxx>
61 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
62 #include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
63 #include <editeng/editstat.hxx>
64 #include <svx/unoapi.hxx>
65 #include <drawinglayer/geometry/viewinformation2d.hxx>
66 #include <svx/sdr/attribute/sdrformtextoutlineattribute.hxx>
67 
68 //////////////////////////////////////////////////////////////////////////////
69 
70 using namespace ::com::sun::star::uno;
71 using namespace ::com::sun::star::lang;
72 using namespace ::com::sun::star::i18n;
73 
74 //////////////////////////////////////////////////////////////////////////////
75 // PathTextPortion helper
76 
77 namespace
78 {
79     class impPathTextPortion
80     {
81         basegfx::B2DVector                          maOffset;
82         String                                      maText;
83         xub_StrLen                                  mnTextStart;
84         xub_StrLen                                  mnTextLength;
85         sal_uInt16                                  mnParagraph;
86         xub_StrLen                                  mnIndex;
87         SvxFont                                     maFont;
88         ::std::vector< double >                     maDblDXArray;   // double DXArray, font size independent -> unit coordinate system
89         ::com::sun::star::lang::Locale              maLocale;
90 
91         // bitfield
92         unsigned                                    mbRTL : 1;
93 
94     public:
impPathTextPortion(DrawPortionInfo & rInfo)95         impPathTextPortion(DrawPortionInfo& rInfo)
96         :   maOffset(rInfo.mrStartPos.X(), rInfo.mrStartPos.Y()),
97             maText(rInfo.mrText),
98             mnTextStart(rInfo.mnTextStart),
99             mnTextLength(rInfo.mnTextLen),
100             mnParagraph(rInfo.mnPara),
101             mnIndex(rInfo.mnIndex),
102             maFont(rInfo.mrFont),
103             maDblDXArray(),
104             maLocale(rInfo.mpLocale ? *rInfo.mpLocale : ::com::sun::star::lang::Locale()),
105             mbRTL(rInfo.mrFont.IsVertical() ? false : rInfo.IsRTL())
106         {
107             if(mnTextLength && rInfo.mpDXArray)
108             {
109                 maDblDXArray.reserve(mnTextLength);
110 
111                 for(xub_StrLen a(0); a < mnTextLength; a++)
112                 {
113                     maDblDXArray.push_back((double)rInfo.mpDXArray[a]);
114                 }
115             }
116         }
117 
118         // for ::std::sort
operator <(const impPathTextPortion & rComp) const119         bool operator<(const impPathTextPortion& rComp) const
120         {
121             if(mnParagraph < rComp.mnParagraph)
122             {
123                 return true;
124             }
125 
126             if(maOffset.getX() < rComp.maOffset.getX())
127             {
128                 return true;
129             }
130 
131             return (maOffset.getY() < rComp.maOffset.getY());
132         }
133 
getOffset() const134         const basegfx::B2DVector& getOffset() const { return maOffset; }
getText() const135         const String& getText() const { return maText; }
getTextStart() const136         xub_StrLen getTextStart() const { return mnTextStart; }
getTextLength() const137         xub_StrLen getTextLength() const { return mnTextLength; }
getParagraph() const138         sal_uInt16 getParagraph() const { return mnParagraph; }
getIndex() const139         xub_StrLen getIndex() const { return mnIndex; }
getFont() const140         const SvxFont& getFont() const { return maFont; }
isRTL() const141         bool isRTL() const { return mbRTL; }
getDoubleDXArray() const142         const ::std::vector< double >& getDoubleDXArray() const { return maDblDXArray; }
getLocale() const143         const ::com::sun::star::lang::Locale& getLocale() const { return maLocale; }
144 
getPortionIndex(xub_StrLen nIndex,xub_StrLen nLength) const145         xub_StrLen getPortionIndex(xub_StrLen nIndex, xub_StrLen nLength) const
146         {
147             if(mbRTL)
148             {
149                 return (mnTextStart + (mnTextLength - (nIndex + nLength)));
150             }
151             else
152             {
153                 return (mnTextStart + nIndex);
154             }
155         }
156 
getDisplayLength(xub_StrLen nIndex,xub_StrLen nLength) const157         double getDisplayLength(xub_StrLen nIndex, xub_StrLen nLength) const
158         {
159             drawinglayer::primitive2d::TextLayouterDevice aTextLayouter;
160             double fRetval(0.0);
161 
162             if(maFont.IsVertical())
163             {
164                 fRetval = aTextLayouter.getTextHeight() * (double)nLength;
165             }
166             else
167             {
168                 fRetval = aTextLayouter.getTextWidth(maText, getPortionIndex(nIndex, nLength), nLength);
169             }
170 
171             return fRetval;
172         }
173     };
174 } // end of anonymous namespace
175 
176 //////////////////////////////////////////////////////////////////////////////
177 // TextBreakup helper
178 
179 namespace
180 {
181     class impTextBreakupHandler
182     {
183         SdrOutliner&                                mrOutliner;
184         ::std::vector< impPathTextPortion >         maPathTextPortions;
185 
186         DECL_LINK(decompositionPathTextPrimitive, DrawPortionInfo* );
187 
188     public:
impTextBreakupHandler(SdrOutliner & rOutliner)189         impTextBreakupHandler(SdrOutliner& rOutliner)
190         :   mrOutliner(rOutliner)
191         {
192         }
193 
decompositionPathTextPrimitive()194         const ::std::vector< impPathTextPortion >& decompositionPathTextPrimitive()
195         {
196             // strip portions to maPathTextPortions
197             mrOutliner.SetDrawPortionHdl(LINK(this, impTextBreakupHandler, decompositionPathTextPrimitive));
198             mrOutliner.StripPortions();
199 
200             if(!maPathTextPortions.empty())
201             {
202                 // sort portions by paragraph, x and y
203                 ::std::sort(maPathTextPortions.begin(), maPathTextPortions.end());
204             }
205 
206             return maPathTextPortions;
207         }
208     };
209 
IMPL_LINK(impTextBreakupHandler,decompositionPathTextPrimitive,DrawPortionInfo *,pInfo)210     IMPL_LINK(impTextBreakupHandler, decompositionPathTextPrimitive, DrawPortionInfo*, pInfo)
211     {
212         maPathTextPortions.push_back(impPathTextPortion(*pInfo));
213         return 0;
214     }
215 } // end of anonymous namespace
216 
217 //////////////////////////////////////////////////////////////////////////////
218 // TextBreakup one poly and one paragraph helper
219 
220 namespace
221 {
222     class impPolygonParagraphHandler
223     {
224         const drawinglayer::attribute::SdrFormTextAttribute         maSdrFormTextAttribute; // FormText parameters
225         std::vector< drawinglayer::primitive2d::BasePrimitive2D* >& mrDecomposition;        // destination primitive list
226         std::vector< drawinglayer::primitive2d::BasePrimitive2D* >& mrShadowDecomposition;  // destination primitive list for shadow
227         Reference < com::sun::star::i18n::XBreakIterator >          mxBreak;                // break iterator
228 
getParagraphTextLength(const::std::vector<const impPathTextPortion * > & rTextPortions)229         double getParagraphTextLength(const ::std::vector< const impPathTextPortion* >& rTextPortions)
230         {
231             drawinglayer::primitive2d::TextLayouterDevice aTextLayouter;
232             double fRetval(0.0);
233 
234             for(sal_uInt32 a(0L); a < rTextPortions.size(); a++)
235             {
236                 const impPathTextPortion* pCandidate = rTextPortions[a];
237 
238                 if(pCandidate && pCandidate->getTextLength())
239                 {
240                     aTextLayouter.setFont(pCandidate->getFont());
241                     fRetval += pCandidate->getDisplayLength(0L, pCandidate->getTextLength());
242                 }
243             }
244 
245             return fRetval;
246         }
247 
getNextGlyphLen(const impPathTextPortion * pCandidate,xub_StrLen nPosition,const::com::sun::star::lang::Locale & rFontLocale)248         xub_StrLen getNextGlyphLen(const impPathTextPortion* pCandidate, xub_StrLen nPosition, const ::com::sun::star::lang::Locale& rFontLocale)
249         {
250             xub_StrLen nNextGlyphLen(1);
251 
252             if(mxBreak.is())
253             {
254                 sal_Int32 nDone(0L);
255                 nNextGlyphLen = (xub_StrLen)mxBreak->nextCharacters(pCandidate->getText(), nPosition,
256                     rFontLocale, CharacterIteratorMode::SKIPCELL, 1, nDone) - nPosition;
257             }
258 
259             return nNextGlyphLen;
260         }
261 
262     public:
impPolygonParagraphHandler(const drawinglayer::attribute::SdrFormTextAttribute & rSdrFormTextAttribute,std::vector<drawinglayer::primitive2d::BasePrimitive2D * > & rDecomposition,std::vector<drawinglayer::primitive2d::BasePrimitive2D * > & rShadowDecomposition)263         impPolygonParagraphHandler(
264             const drawinglayer::attribute::SdrFormTextAttribute& rSdrFormTextAttribute,
265             std::vector< drawinglayer::primitive2d::BasePrimitive2D* >& rDecomposition,
266             std::vector< drawinglayer::primitive2d::BasePrimitive2D* >& rShadowDecomposition)
267         :   maSdrFormTextAttribute(rSdrFormTextAttribute),
268             mrDecomposition(rDecomposition),
269             mrShadowDecomposition(rShadowDecomposition)
270         {
271             // prepare BreakIterator
272             Reference < XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory();
273             Reference < XInterface > xInterface = xMSF->createInstance(::rtl::OUString::createFromAscii("com.sun.star.i18n.BreakIterator"));
274 
275             if(xInterface.is())
276             {
277                 Any x = xInterface->queryInterface(::getCppuType((const Reference< XBreakIterator >*)0));
278                 x >>= mxBreak;
279             }
280         }
281 
HandlePair(const basegfx::B2DPolygon rPolygonCandidate,const::std::vector<const impPathTextPortion * > & rTextPortions)282         void HandlePair(const basegfx::B2DPolygon rPolygonCandidate, const ::std::vector< const impPathTextPortion* >& rTextPortions)
283         {
284             // prepare polygon geometry, take into account as many parameters as possible
285             basegfx::B2DPolygon aPolygonCandidate(rPolygonCandidate);
286             const double fPolyLength(basegfx::tools::getLength(aPolygonCandidate));
287             double fPolyEnd(fPolyLength);
288             double fPolyStart(0.0);
289             double fAutosizeScaleFactor(1.0);
290             bool bAutosizeScale(false);
291 
292             if(maSdrFormTextAttribute.getFormTextMirror())
293             {
294                 aPolygonCandidate.flip();
295             }
296 
297             if(maSdrFormTextAttribute.getFormTextStart()
298                 && (XFT_LEFT == maSdrFormTextAttribute.getFormTextAdjust()
299                     || XFT_RIGHT == maSdrFormTextAttribute.getFormTextAdjust()))
300             {
301                 if(XFT_LEFT == maSdrFormTextAttribute.getFormTextAdjust())
302                 {
303                     fPolyStart += maSdrFormTextAttribute.getFormTextStart();
304 
305                     if(fPolyStart > fPolyEnd)
306                     {
307                         fPolyStart = fPolyEnd;
308                     }
309                 }
310                 else
311                 {
312                     fPolyEnd -= maSdrFormTextAttribute.getFormTextStart();
313 
314                     if(fPolyEnd < fPolyStart)
315                     {
316                         fPolyEnd = fPolyStart;
317                     }
318                 }
319             }
320 
321             if(XFT_LEFT != maSdrFormTextAttribute.getFormTextAdjust())
322             {
323                 // calculate total text length of this paragraph, some layout needs to be done
324                 const double fParagraphTextLength(getParagraphTextLength(rTextPortions));
325 
326                 // check if text is too long for paragraph. If yes, handle as if left aligned (default),
327                 // but still take care of XFT_AUTOSIZE in that case
328                 const bool bTextTooLong(fParagraphTextLength > (fPolyEnd - fPolyStart));
329 
330                 if(XFT_RIGHT == maSdrFormTextAttribute.getFormTextAdjust())
331                 {
332                     if(!bTextTooLong)
333                     {
334                         // if right aligned, add difference to polygon start
335                         fPolyStart += ((fPolyEnd - fPolyStart) - fParagraphTextLength);
336                     }
337                 }
338                 else if(XFT_CENTER == maSdrFormTextAttribute.getFormTextAdjust())
339                 {
340                     if(!bTextTooLong)
341                     {
342                         // if centered, add half of difference to polygon start
343                         fPolyStart += ((fPolyEnd - fPolyStart) - fParagraphTextLength) / 2.0;
344                     }
345                 }
346                 else if(XFT_AUTOSIZE == maSdrFormTextAttribute.getFormTextAdjust())
347                 {
348                     // if scale, prepare scale factor between curve length and text length
349                     if(0.0 != fParagraphTextLength)
350                     {
351                         fAutosizeScaleFactor = (fPolyEnd - fPolyStart) / fParagraphTextLength;
352                         bAutosizeScale = true;
353                     }
354                 }
355             }
356 
357             // handle text portions for this paragraph
358             for(sal_uInt32 a(0L); a < rTextPortions.size() && fPolyStart < fPolyEnd; a++)
359             {
360                 const impPathTextPortion* pCandidate = rTextPortions[a];
361                 basegfx::B2DVector aFontScaling;
362                 const drawinglayer::attribute::FontAttribute aCandidateFontAttribute(
363                     drawinglayer::primitive2d::getFontAttributeFromVclFont(
364                         aFontScaling,
365                         pCandidate->getFont(),
366                         pCandidate->isRTL(),
367                         false));
368 
369                 if(pCandidate && pCandidate->getTextLength())
370                 {
371                     drawinglayer::primitive2d::TextLayouterDevice aTextLayouter;
372                     aTextLayouter.setFont(pCandidate->getFont());
373                     xub_StrLen nUsedTextLength(0);
374 
375                     while(nUsedTextLength < pCandidate->getTextLength() && fPolyStart < fPolyEnd)
376                     {
377                         xub_StrLen nNextGlyphLen(getNextGlyphLen(pCandidate, pCandidate->getTextStart() + nUsedTextLength, pCandidate->getLocale()));
378 
379                         // prepare portion length. Takes RTL sections into account.
380                         double fPortionLength(pCandidate->getDisplayLength(nUsedTextLength, nNextGlyphLen));
381 
382                         if(bAutosizeScale)
383                         {
384                             // when autosize scaling, expand portion length
385                             fPortionLength *= fAutosizeScaleFactor;
386                         }
387 
388                         // create transformation
389                         basegfx::B2DHomMatrix aNewTransformA, aNewTransformB, aNewShadowTransform;
390                         basegfx::B2DPoint aStartPos(basegfx::tools::getPositionAbsolute(aPolygonCandidate, fPolyStart, fPolyLength));
391                         basegfx::B2DPoint aEndPos(aStartPos);
392 
393                         // add font scaling
394                         aNewTransformA.scale(aFontScaling.getX(), aFontScaling.getY());
395 
396                         // prepare scaling of text primitive
397                         if(bAutosizeScale)
398                         {
399                             // when autosize scaling, expand text primitive scaling to it
400                             aNewTransformA.scale(fAutosizeScaleFactor, fAutosizeScaleFactor);
401                         }
402 
403                         // eventually create shadow primitives from aDecomposition and add to rDecomposition
404                         const bool bShadow(XFTSHADOW_NONE != maSdrFormTextAttribute.getFormTextShadow());
405 
406                         if(bShadow)
407                         {
408                             if(XFTSHADOW_NORMAL == maSdrFormTextAttribute.getFormTextShadow())
409                             {
410                                 aNewShadowTransform.translate(
411                                     maSdrFormTextAttribute.getFormTextShdwXVal(),
412                                     -maSdrFormTextAttribute.getFormTextShdwYVal());
413                             }
414                             else // XFTSHADOW_SLANT
415                             {
416                                 double fScaleValue(maSdrFormTextAttribute.getFormTextShdwYVal() / 100.0);
417                                 double fShearValue(-maSdrFormTextAttribute.getFormTextShdwXVal() * F_PI1800);
418 
419                                 aNewShadowTransform.scale(1.0, fScaleValue);
420                                 aNewShadowTransform.shearX(sin(fShearValue));
421                                 aNewShadowTransform.scale(1.0, cos(fShearValue));
422                             }
423                         }
424 
425                         switch(maSdrFormTextAttribute.getFormTextStyle())
426                         {
427                             case XFT_ROTATE :
428                             {
429                                 aEndPos = basegfx::tools::getPositionAbsolute(aPolygonCandidate, fPolyStart + fPortionLength, fPolyLength);
430                                 const basegfx::B2DVector aDirection(aEndPos - aStartPos);
431                                 aNewTransformB.rotate(atan2(aDirection.getY(), aDirection.getX()));
432                                 aNewTransformB.translate(aStartPos.getX(), aStartPos.getY());
433 
434                                 break;
435                             }
436                             case XFT_UPRIGHT :
437                             {
438                                 aNewTransformB.translate(aStartPos.getX() - (fPortionLength / 2.0), aStartPos.getY());
439 
440                                 break;
441                             }
442                             case XFT_SLANTX :
443                             {
444                                 aEndPos = basegfx::tools::getPositionAbsolute(aPolygonCandidate, fPolyStart + fPortionLength, fPolyLength);
445                                 const basegfx::B2DVector aDirection(aEndPos - aStartPos);
446                                 const double fShearValue(atan2(aDirection.getY(), aDirection.getX()));
447                                 const double fSin(sin(fShearValue));
448                                 const double fCos(cos(fShearValue));
449 
450                                 aNewTransformB.shearX(-fSin);
451 
452                                 // Scale may lead to objects without height since fCos == 0.0 is possible.
453                                 // Renderers need to handle that, it's not a forbidden value and does not
454                                 // need to be avoided
455                                 aNewTransformB.scale(1.0, fCos);
456                                 aNewTransformB.translate(aStartPos.getX() - (fPortionLength / 2.0), aStartPos.getY());
457 
458                                 break;
459                             }
460                             case XFT_SLANTY :
461                             {
462                                 aEndPos = basegfx::tools::getPositionAbsolute(aPolygonCandidate, fPolyStart + fPortionLength, fPolyLength);
463                                 const basegfx::B2DVector aDirection(aEndPos - aStartPos);
464                                 const double fShearValue(atan2(aDirection.getY(), aDirection.getX()));
465                                 const double fCos(cos(fShearValue));
466                                 const double fTan(tan(fShearValue));
467 
468                                 // shear to 'stand' on the curve
469                                 aNewTransformB.shearY(fTan);
470 
471                                 // scale in X to make as tight as needed. As with XFT_SLANT_X, this may
472                                 // lead to primitives without width which the renderers will handle
473                                 aNewTransformA.scale(fCos, 1.0);
474 
475                                 aNewTransformB.translate(aStartPos.getX(), aStartPos.getY());
476 
477                                 break;
478                             }
479                             default : break; // XFT_NONE
480                         }
481 
482                         // distance from path?
483                         if(maSdrFormTextAttribute.getFormTextDistance())
484                         {
485                             if(aEndPos.equal(aStartPos))
486                             {
487                                 aEndPos = basegfx::tools::getPositionAbsolute(aPolygonCandidate, fPolyStart + fPortionLength, fPolyLength);
488                             }
489 
490                             // use back vector (aStartPos - aEndPos) here to get mirrored perpendicular as in old stuff
491                             const basegfx::B2DVector aPerpendicular(
492                                 basegfx::getNormalizedPerpendicular(aStartPos - aEndPos) *
493                                 maSdrFormTextAttribute.getFormTextDistance());
494                             aNewTransformB.translate(aPerpendicular.getX(), aPerpendicular.getY());
495                         }
496 
497                         if(pCandidate->getText().Len() && nNextGlyphLen)
498                         {
499                             const xub_StrLen nPortionIndex(pCandidate->getPortionIndex(nUsedTextLength, nNextGlyphLen));
500                             ::std::vector< double > aNewDXArray;
501 
502                             if(nNextGlyphLen > 1 && pCandidate->getDoubleDXArray().size())
503                             {
504                                 // copy DXArray for portion
505                                 aNewDXArray.insert(
506                                     aNewDXArray.begin(),
507                                     pCandidate->getDoubleDXArray().begin() + nPortionIndex,
508                                     pCandidate->getDoubleDXArray().begin() + (nPortionIndex + nNextGlyphLen));
509 
510                                 if(nPortionIndex > 0)
511                                 {
512                                     // adapt to portion start
513                                     double fDXOffset= *(pCandidate->getDoubleDXArray().begin() + (nPortionIndex - 1));
514                                     ::std::transform(
515                                         aNewDXArray.begin(), aNewDXArray.end(),
516                                         aNewDXArray.begin(), ::std::bind(::std::minus<double>(), ::std::placeholders::_1, fDXOffset));
517                                 }
518 
519                                 if(bAutosizeScale)
520                                 {
521                                     // when autosize scaling, adapt to DXArray, too
522                                     ::std::transform(
523                                         aNewDXArray.begin(), aNewDXArray.end(),
524                                         aNewDXArray.begin(), ::std::bind(::std::multiplies<double>(), ::std::placeholders::_1, fAutosizeScaleFactor));
525                                 }
526                             }
527 
528                             if(bShadow)
529                             {
530                                 // shadow primitive creation
531                                 const Color aShadowColor(maSdrFormTextAttribute.getFormTextShdwColor());
532                                 const basegfx::BColor aRGBShadowColor(aShadowColor.getBColor());
533 
534                                 drawinglayer::primitive2d::TextSimplePortionPrimitive2D* pNew =
535                                     new drawinglayer::primitive2d::TextSimplePortionPrimitive2D(
536                                         aNewTransformB * aNewShadowTransform * aNewTransformA,
537                                         pCandidate->getText(),
538                                         nPortionIndex,
539                                         nNextGlyphLen,
540                                         aNewDXArray,
541                                         aCandidateFontAttribute,
542                                         pCandidate->getLocale(),
543                                         aRGBShadowColor);
544 
545                                 mrShadowDecomposition.push_back(pNew);
546                             }
547 
548                             {
549                                 // primitive creation
550                                 const Color aColor(pCandidate->getFont().GetColor());
551                                 const basegfx::BColor aRGBColor(aColor.getBColor());
552 
553                                 drawinglayer::primitive2d::TextSimplePortionPrimitive2D* pNew =
554                                     new drawinglayer::primitive2d::TextSimplePortionPrimitive2D(
555                                         aNewTransformB * aNewTransformA,
556                                         pCandidate->getText(),
557                                         nPortionIndex,
558                                         nNextGlyphLen,
559                                         aNewDXArray,
560                                         aCandidateFontAttribute,
561                                         pCandidate->getLocale(),
562                                         aRGBColor);
563 
564                                 mrDecomposition.push_back(pNew);
565                             }
566                         }
567 
568                         // consume from portion // no += here, xub_StrLen is sal_uInt16 and the compiler will gererate a warning here
569                         nUsedTextLength = nUsedTextLength + nNextGlyphLen;
570 
571                         // consume from polygon
572                         fPolyStart += fPortionLength;
573                     }
574                 }
575             }
576         }
577     };
578 } // end of anonymous namespace
579 
580 //////////////////////////////////////////////////////////////////////////////
581 // primitive decomposition helpers
582 
583 namespace
584 {
impAddPolygonStrokePrimitives(const basegfx::B2DPolyPolygonVector & rB2DPolyPolyVector,const basegfx::B2DHomMatrix & rTransform,const drawinglayer::attribute::LineAttribute & rLineAttribute,const drawinglayer::attribute::StrokeAttribute & rStrokeAttribute,std::vector<drawinglayer::primitive2d::BasePrimitive2D * > & rTarget)585     void impAddPolygonStrokePrimitives(
586         const basegfx::B2DPolyPolygonVector& rB2DPolyPolyVector,
587         const basegfx::B2DHomMatrix& rTransform,
588         const drawinglayer::attribute::LineAttribute& rLineAttribute,
589         const drawinglayer::attribute::StrokeAttribute& rStrokeAttribute,
590         std::vector< drawinglayer::primitive2d::BasePrimitive2D* >& rTarget)
591     {
592         for(basegfx::B2DPolyPolygonVector::const_iterator aPolygon(rB2DPolyPolyVector.begin()); aPolygon != rB2DPolyPolyVector.end(); aPolygon++)
593         {
594             // prepare PolyPolygons
595             basegfx::B2DPolyPolygon aB2DPolyPolygon = *aPolygon;
596             aB2DPolyPolygon.transform(rTransform);
597 
598             for(sal_uInt32 a(0L); a < aB2DPolyPolygon.count(); a++)
599             {
600                 // create one primitive per polygon
601                 drawinglayer::primitive2d::PolygonStrokePrimitive2D* pNew =
602                     new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
603                         aB2DPolyPolygon.getB2DPolygon(a), rLineAttribute, rStrokeAttribute);
604                 rTarget.push_back(pNew);
605             }
606         }
607     }
608 
impAddPathTextOutlines(const std::vector<drawinglayer::primitive2d::BasePrimitive2D * > & rSource,const drawinglayer::attribute::SdrFormTextOutlineAttribute & rOutlineAttribute)609     drawinglayer::primitive2d::Primitive2DSequence impAddPathTextOutlines(
610         const std::vector< drawinglayer::primitive2d::BasePrimitive2D* >& rSource,
611         const drawinglayer::attribute::SdrFormTextOutlineAttribute& rOutlineAttribute)
612     {
613         std::vector< drawinglayer::primitive2d::BasePrimitive2D* > aNewPrimitives;
614 
615         for(sal_uInt32 a(0L); a < rSource.size(); a++)
616         {
617             const drawinglayer::primitive2d::TextSimplePortionPrimitive2D* pTextCandidate = dynamic_cast< const drawinglayer::primitive2d::TextSimplePortionPrimitive2D* >(rSource[a]);
618 
619             if(pTextCandidate)
620             {
621                 basegfx::B2DPolyPolygonVector aB2DPolyPolyVector;
622                 basegfx::B2DHomMatrix aPolygonTransform;
623 
624                 // get text outlines and their object transformation
625                 pTextCandidate->getTextOutlinesAndTransformation(aB2DPolyPolyVector, aPolygonTransform);
626 
627                 if(!aB2DPolyPolyVector.empty())
628                 {
629                     // create stroke primitives
630                     std::vector< drawinglayer::primitive2d::BasePrimitive2D* > aStrokePrimitives;
631                     impAddPolygonStrokePrimitives(
632                         aB2DPolyPolyVector,
633                         aPolygonTransform,
634                         rOutlineAttribute.getLineAttribute(),
635                         rOutlineAttribute.getStrokeAttribute(),
636                         aStrokePrimitives);
637                     const sal_uInt32 nStrokeCount(aStrokePrimitives.size());
638 
639                     if(nStrokeCount)
640                     {
641                         if(rOutlineAttribute.getTransparence())
642                         {
643                             // create UnifiedTransparencePrimitive2D
644                             drawinglayer::primitive2d::Primitive2DSequence aStrokePrimitiveSequence(nStrokeCount);
645 
646                             for(sal_uInt32 b(0L); b < nStrokeCount; b++)
647                             {
648                                 aStrokePrimitiveSequence[b] = drawinglayer::primitive2d::Primitive2DReference(aStrokePrimitives[b]);
649                             }
650 
651                             drawinglayer::primitive2d::UnifiedTransparencePrimitive2D* pNew2 =
652                                 new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
653                                     aStrokePrimitiveSequence,
654                                     (double)rOutlineAttribute.getTransparence() / 100.0);
655                             aNewPrimitives.push_back(pNew2);
656                         }
657                         else
658                         {
659                             // add polygons to rDecomposition as polygonStrokePrimitives
660                             aNewPrimitives.insert(aNewPrimitives.end(), aStrokePrimitives.begin(), aStrokePrimitives.end());
661                         }
662                     }
663                 }
664             }
665         }
666 
667         const sal_uInt32 nNewCount(aNewPrimitives.size());
668 
669         if(nNewCount)
670         {
671             drawinglayer::primitive2d::Primitive2DSequence aRetval(nNewCount);
672 
673             for(sal_uInt32 a(0L); a < nNewCount; a++)
674             {
675                 aRetval[a] = drawinglayer::primitive2d::Primitive2DReference(aNewPrimitives[a]);
676             }
677 
678             return aRetval;
679         }
680         else
681         {
682             return drawinglayer::primitive2d::Primitive2DSequence();
683         }
684     }
685 } // end of anonymous namespace
686 
687 //////////////////////////////////////////////////////////////////////////////
688 // primitive decomposition
689 
impDecomposePathTextPrimitive(drawinglayer::primitive2d::Primitive2DSequence & rTarget,const drawinglayer::primitive2d::SdrPathTextPrimitive2D & rSdrPathTextPrimitive,const drawinglayer::geometry::ViewInformation2D & aViewInformation) const690 void SdrTextObj::impDecomposePathTextPrimitive(
691     drawinglayer::primitive2d::Primitive2DSequence& rTarget,
692     const drawinglayer::primitive2d::SdrPathTextPrimitive2D& rSdrPathTextPrimitive,
693     const drawinglayer::geometry::ViewInformation2D& aViewInformation) const
694 {
695     drawinglayer::primitive2d::Primitive2DSequence aRetvalA;
696     drawinglayer::primitive2d::Primitive2DSequence aRetvalB;
697 
698     // prepare outliner
699     SdrOutliner& rOutliner = ImpGetDrawOutliner();
700     rOutliner.SetUpdateMode(true);
701     rOutliner.Clear();
702     rOutliner.SetPaperSize(Size(LONG_MAX,LONG_MAX));
703     rOutliner.SetText(rSdrPathTextPrimitive.getOutlinerParaObject());
704 
705     // set visualizing page at Outliner; needed e.g. for PageNumberField decomposition
706     rOutliner.setVisualizedPage(GetSdrPageFromXDrawPage(aViewInformation.getVisualizedPage()));
707 
708     // now break up to text portions
709     impTextBreakupHandler aConverter(rOutliner);
710     const ::std::vector< impPathTextPortion > rPathTextPortions = aConverter.decompositionPathTextPrimitive();
711 
712     if(!rPathTextPortions.empty())
713     {
714         // get FormText and polygon values
715         const drawinglayer::attribute::SdrFormTextAttribute& rFormTextAttribute = rSdrPathTextPrimitive.getSdrFormTextAttribute();
716         const basegfx::B2DPolyPolygon& rPathPolyPolygon(rSdrPathTextPrimitive.getPathPolyPolygon());
717 
718         // get loop count
719         sal_uInt32 nLoopCount(rPathPolyPolygon.count());
720 
721         if(rOutliner.GetParagraphCount() < nLoopCount)
722         {
723             nLoopCount = rOutliner.GetParagraphCount();
724         }
725 
726         if(nLoopCount)
727         {
728             // prepare common decomposition stuff
729             std::vector< drawinglayer::primitive2d::BasePrimitive2D* > aRegularDecomposition;
730             std::vector< drawinglayer::primitive2d::BasePrimitive2D* > aShadowDecomposition;
731             impPolygonParagraphHandler aPolygonParagraphHandler(
732                 rFormTextAttribute,
733                 aRegularDecomposition,
734                 aShadowDecomposition);
735             sal_uInt32 a;
736 
737             for(a = 0L; a < nLoopCount; a++)
738             {
739                 // filter text portions for this paragraph
740                 ::std::vector< const impPathTextPortion* > aParagraphTextPortions;
741 
742                 for(sal_uInt32 b(0L); b < rPathTextPortions.size(); b++)
743                 {
744                     const impPathTextPortion& rCandidate = rPathTextPortions[b];
745 
746                     if(rCandidate.getParagraph() == a)
747                     {
748                         aParagraphTextPortions.push_back(&rCandidate);
749                     }
750                 }
751 
752                 // handle data pair polygon/ParagraphTextPortions
753                 if(!aParagraphTextPortions.empty())
754                 {
755                     aPolygonParagraphHandler.HandlePair(rPathPolyPolygon.getB2DPolygon(a), aParagraphTextPortions);
756                 }
757             }
758 
759             const sal_uInt32 nShadowCount(aShadowDecomposition.size());
760             const sal_uInt32 nRegularCount(aRegularDecomposition.size());
761 
762             if(nShadowCount)
763             {
764                 // add shadow primitives to decomposition
765                 aRetvalA.realloc(nShadowCount);
766 
767                 for(a = 0L; a < nShadowCount; a++)
768                 {
769                     aRetvalA[a] = drawinglayer::primitive2d::Primitive2DReference(aShadowDecomposition[a]);
770                 }
771 
772                 // evtl. add shadow outlines
773                 if(rFormTextAttribute.getFormTextOutline()
774                     && !rFormTextAttribute.getShadowOutline().isDefault())
775                 {
776                     const drawinglayer::primitive2d::Primitive2DSequence aOutlines(
777                         impAddPathTextOutlines(
778                             aShadowDecomposition,
779                             rFormTextAttribute.getShadowOutline()));
780 
781                     drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(aRetvalA, aOutlines);
782                 }
783             }
784 
785             if(nRegularCount)
786             {
787                 // add normal primitives to decomposition
788                 aRetvalB.realloc(nRegularCount);
789 
790                 for(a = 0L; a < nRegularCount; a++)
791                 {
792                     aRetvalB[a] = drawinglayer::primitive2d::Primitive2DReference(aRegularDecomposition[a]);
793                 }
794 
795                 // evtl. add outlines
796                 if(rFormTextAttribute.getFormTextOutline()
797                     && !rFormTextAttribute.getOutline().isDefault())
798                 {
799                     const drawinglayer::primitive2d::Primitive2DSequence aOutlines(
800                         impAddPathTextOutlines(
801                             aRegularDecomposition,
802                             rFormTextAttribute.getOutline()));
803 
804                     drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(aRetvalB, aOutlines);
805                 }
806             }
807         }
808     }
809 
810     // cleanup outliner
811     rOutliner.SetDrawPortionHdl(Link());
812     rOutliner.Clear();
813     rOutliner.setVisualizedPage(0);
814 
815     // concatenate all results
816     drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget, aRetvalA);
817     drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget, aRetvalB);
818 }
819 
820 //////////////////////////////////////////////////////////////////////////////
821 // eof
822