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