summaryrefslogtreecommitdiff
path: root/drawinglayer/source/primitive2d/textdecoratedprimitive2d.cxx
blob: a253c81b1717417a78177e51b0c43ca3a330a2cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: textdecoratedprimitive2d.cxx,v $
 *
 *  $Revision: 1.12 $
 *
 *  last change: $Author: aw $ $Date: 2008-05-27 14:11:20 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_drawinglayer.hxx"

#include <drawinglayer/primitive2d/textdecoratedprimitive2d.hxx>
#include <drawinglayer/primitive2d/textlayoutdevice.hxx>
#include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
#include <drawinglayer/attribute/strokeattribute.hxx>
#include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <comphelper/processfactory.hxx>
#include <com/sun/star/i18n/WordType.hpp>
#include <drawinglayer/primitive2d/texteffectprimitive2d.hxx>
#include <drawinglayer/primitive2d/shadowprimitive2d.hxx>
#include <com/sun/star/i18n/XBreakIterator.hpp>
#include <drawinglayer/primitive2d/transformprimitive2d.hxx>

//////////////////////////////////////////////////////////////////////////////

namespace drawinglayer
{
    namespace primitive2d
    {
        void TextDecoratedPortionPrimitive2D::impCreateTextLine(
            std::vector< Primitive2DReference >& rTarget,
            basegfx::DecomposedB2DHomMatrixContainer& rDecTrans,
            const basegfx::B2DHomMatrix &rUnscaledTransform,
            FontUnderline eLineStyle,
            double fLineOffset,
            double fLineHeight,
            double fLineWidth,
            const basegfx::BColor& rLineColor) const
        {
            bool bDoubleLine(false);
            bool bWaveLine(false);
            bool bBoldLine(false);
            const int* pDotDashArray(0);
            basegfx::B2DLineJoin eLineJoin(basegfx::B2DLINEJOIN_NONE);

            static const int aDottedArray[]     = { 1, 1, 0};               // DOTTED LINE
            static const int aDotDashArray[]    = { 1, 1, 4, 1, 0};         // DASHDOT
            static const int aDashDotDotArray[] = { 1, 1, 1, 1, 4, 1, 0};   // DASHDOTDOT
            static const int aDashedArray[]     = { 5, 2, 0};               // DASHED LINE
            static const int aLongDashArray[]   = { 7, 2, 0};               // LONGDASH

            switch(eLineStyle)
            {
                default: // case FONT_UNDERLINE_SINGLE:
                {
                    break;
                }
                case FONT_UNDERLINE_DOUBLE:
                {
                    bDoubleLine = true;
                    break;
                }
                case FONT_UNDERLINE_DOTTED:
                {
                    pDotDashArray = aDottedArray;
                    break;
                }
                case FONT_UNDERLINE_DASH:
                {
                    pDotDashArray = aDashedArray;
                    break;
                }
                case FONT_UNDERLINE_LONGDASH:
                {
                    pDotDashArray = aLongDashArray;
                    break;
                }
                case FONT_UNDERLINE_DASHDOT:
                {
                    pDotDashArray = aDotDashArray;
                    break;
                }
                case FONT_UNDERLINE_DASHDOTDOT:
                {
                    pDotDashArray = aDashDotDotArray;
                    break;
                }
                case FONT_UNDERLINE_SMALLWAVE:
                {
                    bWaveLine = true;
                    break;
                }
                case FONT_UNDERLINE_WAVE:
                {
                    bWaveLine = true;
                    break;
                }
                case FONT_UNDERLINE_DOUBLEWAVE:
                {
                    bDoubleLine = true;
                    bWaveLine = true;
                    break;
                }
                case FONT_UNDERLINE_BOLD:
                {
                    bBoldLine = true;
                    break;
                }
                case FONT_UNDERLINE_BOLDDOTTED:
                {
                    bBoldLine = true;
                    pDotDashArray = aDottedArray;
                    break;
                }
                case FONT_UNDERLINE_BOLDDASH:
                {
                    bBoldLine = true;
                    pDotDashArray = aDashedArray;
                    break;
                }
                case FONT_UNDERLINE_BOLDLONGDASH:
                {
                    bBoldLine = true;
                    pDotDashArray = aLongDashArray;
                    break;
                }
                case FONT_UNDERLINE_BOLDDASHDOT:
                {
                    bBoldLine = true;
                    pDotDashArray = aDotDashArray;
                    break;
                }
                case FONT_UNDERLINE_BOLDDASHDOTDOT:
                {
                    bBoldLine = true;
                    pDotDashArray = aDashDotDotArray;
                    break;
                }
                case FONT_UNDERLINE_BOLDWAVE:
                {
                    bWaveLine = true;
                    bBoldLine = true;
                    break;
                }
            }

            if(bBoldLine)
            {
                fLineHeight *= 2.0;
            }

            if(bDoubleLine)
            {
                fLineOffset -= 0.50 * fLineHeight;
                fLineHeight *= 0.64;
            }

            if(bWaveLine)
            {
                eLineJoin = basegfx::B2DLINEJOIN_ROUND;
                fLineHeight *= 0.5;
            }

            // prepare Line and Stroke Attributes
            const attribute::LineAttribute aLineAttribute(rLineColor, fLineHeight, eLineJoin);
            attribute::StrokeAttribute aStrokeAttribute;

            if(pDotDashArray)
            {
                ::std::vector< double > aDoubleArray;

                for(const int* p = pDotDashArray; *p; ++p)
                {
                    aDoubleArray.push_back((double)(*p) * fLineHeight);
                }

                aStrokeAttribute = attribute::StrokeAttribute(aDoubleArray);
            }

            // create base polygon and new primitive
            basegfx::B2DPolygon aLine;
            Primitive2DReference aNewPrimitive;

            aLine.append(basegfx::B2DPoint(0.0, fLineOffset));
            aLine.append(basegfx::B2DPoint(fLineWidth, fLineOffset));
            aLine.transform(rUnscaledTransform);

            if(bWaveLine)
            {
                double fWaveWidth(4.0 * fLineHeight);

                if(FONT_UNDERLINE_SMALLWAVE == eLineStyle)
                {
                    fWaveWidth *= 0.7;
                }
                else if(FONT_UNDERLINE_WAVE == eLineStyle)
                {
                    // extra multiply to get the same WaveWidth as with the bold version
                    fWaveWidth *= 2.0;
                }

                aNewPrimitive = Primitive2DReference(new PolygonWavePrimitive2D(aLine, aLineAttribute, aStrokeAttribute, fWaveWidth, 0.5 * fWaveWidth));
            }
            else
            {
                aNewPrimitive = Primitive2DReference(new PolygonStrokePrimitive2D(aLine, aLineAttribute, aStrokeAttribute));
            }

            // add primitive
            rTarget.push_back(aNewPrimitive);

            if(bDoubleLine)
            {
                // double line, create 2nd primitive with offset using TransformPrimitive based on
                // already created NewPrimitive
                const double fLineDist((bWaveLine ? 3.0 : 2.0) * fLineHeight);
                basegfx::B2DHomMatrix aTransform;

                // move base point of text to 0.0 and de-rotate
                aTransform.translate(-rDecTrans.getTranslate().getX(), -rDecTrans.getTranslate().getY());
                aTransform.rotate(-rDecTrans.getRotate());

                // translate in Y by offset
                aTransform.translate(0.0, fLineDist);

                // move back and rotate
                aTransform.rotate(rDecTrans.getRotate());
                aTransform.translate(rDecTrans.getTranslate().getX(), rDecTrans.getTranslate().getY());

                // add transform primitive
                const Primitive2DSequence aContent(&aNewPrimitive, 1);
                rTarget.push_back(Primitive2DReference(new TransformPrimitive2D(aTransform, aContent)));
            }
        }

        void TextDecoratedPortionPrimitive2D::impCreateGeometryContent(
            std::vector< Primitive2DReference >& rTarget,
            basegfx::DecomposedB2DHomMatrixContainer& rDecTrans,
            const String& rText,
            xub_StrLen aTextPosition,
            xub_StrLen aTextLength,
            const ::std::vector< double >& rDXArray,
            const FontAttributes& rFontAttributes) const
        {
            // create the SimpleTextPrimitive needed in any case
            rTarget.push_back(Primitive2DReference(new TextSimplePortionPrimitive2D(
                rDecTrans.getB2DHomMatrix(),
                rText,
                aTextPosition,
                aTextLength,
                rDXArray,
                rFontAttributes,
                getLocale(),
                getFontColor())));

            // see if something else needs to be done
            const bool bOverlineUsed(FONT_UNDERLINE_NONE != getFontOverline());
            const bool bUnderlineUsed(FONT_UNDERLINE_NONE != getFontUnderline());
            const bool bStrikeoutUsed(FONT_STRIKEOUT_NONE != getFontStrikeout());

            if(bUnderlineUsed || bStrikeoutUsed || bOverlineUsed)
            {
                // common preparations
                basegfx::B2DHomMatrix aUnscaledTransform;
                TextLayouterDevice aTextLayouter;

                // unscaled is needed since scale contains already the font size
                aUnscaledTransform.shearX(rDecTrans.getShearX());
                aUnscaledTransform.rotate(rDecTrans.getRotate());
                aUnscaledTransform.translate(rDecTrans.getTranslate().getX(), rDecTrans.getTranslate().getY());

                // TextLayouterDevice is needed to get metrics for text decorations like
                // underline/strikeout/emphasis marks from it. For setup, the font size is needed
                aTextLayouter.setFontAttributes(getFontAttributes(), rDecTrans.getScale().getX(), rDecTrans.getScale().getY());

                // get text width
                double fTextWidth(0.0);

                if(rDXArray.empty())
                {
                    fTextWidth = aTextLayouter.getTextWidth(rText, aTextPosition, aTextLength);
                }
                else
                {
                    fTextWidth = rDXArray.back() * rDecTrans.getScale().getX();
                }

                if(bOverlineUsed)
                {
                    // create primitive geometry for overline
                    impCreateTextLine(rTarget, rDecTrans, aUnscaledTransform, getFontOverline(), aTextLayouter.getOverlineOffset(),
                                      aTextLayouter.getOverlineHeight(), fTextWidth, getOverlineColor());
                }

                if(bUnderlineUsed)
                {
                    // create primitive geometry for underline
                    impCreateTextLine(rTarget, rDecTrans, aUnscaledTransform, getFontUnderline(), aTextLayouter.getUnderlineOffset(),
                                      aTextLayouter.getUnderlineHeight(), fTextWidth, getTextlineColor());
                }

                if(bStrikeoutUsed)
                {
                    // create primitive geometry for strikeout
                    if(FONT_STRIKEOUT_SLASH == getFontStrikeout() || FONT_STRIKEOUT_X == getFontStrikeout())
                    {
                        // strikeout with character
                        const sal_Unicode aStrikeoutChar(FONT_STRIKEOUT_SLASH == getFontStrikeout() ? '/' : 'X');
                        const String aSingleCharString(aStrikeoutChar);
                        const double fStrikeCharWidth(aTextLayouter.getTextWidth(aSingleCharString, 0, 1));
                        const double fStrikeCharCount(fabs(fTextWidth/fStrikeCharWidth));
                        const sal_uInt32 nStrikeCharCount(static_cast< sal_uInt32 >(fStrikeCharCount + 0.9));
                        const double fScaleX(rDecTrans.getScale().getX());
                        const double fStrikeCharWidthUnscaled(basegfx::fTools::equalZero(fScaleX) ? fStrikeCharWidth : fStrikeCharWidth/fScaleX);

                        std::vector<double> aDXArray(nStrikeCharCount);
                        String aStrikeoutString;

                        for(sal_uInt32 a(0); a < nStrikeCharCount; a++)
                        {
                            aStrikeoutString += aSingleCharString;
                            aDXArray[a] = (a + 1) * fStrikeCharWidthUnscaled;
                        }

                        rTarget.push_back(Primitive2DReference(new TextSimplePortionPrimitive2D(
                            rDecTrans.getB2DHomMatrix(),
                            aStrikeoutString,
                            0,
                            aStrikeoutString.Len(),
                            aDXArray,
                            rFontAttributes,
                            getLocale(),
                            getFontColor())));
                    }
                    else
                    {
                        // strikeout with geometry
                        double fStrikeoutHeight(aTextLayouter.getUnderlineHeight());
                        double fStrikeoutOffset(aTextLayouter.getStrikeoutOffset());
                        bool bDoubleLine(false);

                        // set line attribute
                        switch(getFontStrikeout())
                        {
                            default : // case primitive2d::FONT_STRIKEOUT_SINGLE:
                            {
                                break;
                            }
                            case primitive2d::FONT_STRIKEOUT_DOUBLE:
                            {
                                bDoubleLine = true;
                                break;
                            }
                            case primitive2d::FONT_STRIKEOUT_BOLD:
                            {
                                fStrikeoutHeight *= 2.0;
                                break;
                            }
                        }

                        if(bDoubleLine)
                        {
                            fStrikeoutOffset -= 0.50 * fStrikeoutHeight;
                            fStrikeoutHeight *= 0.64;
                        }

                        // create base polygon and new primitive
                        basegfx::B2DPolygon aStrikeoutLine;

                        aStrikeoutLine.append(basegfx::B2DPoint(0.0, -fStrikeoutOffset));
                        aStrikeoutLine.append(basegfx::B2DPoint(fTextWidth, -fStrikeoutOffset));
                        aStrikeoutLine.transform(aUnscaledTransform);

                        const attribute::LineAttribute aLineAttribute(getFontColor(), fStrikeoutHeight, basegfx::B2DLINEJOIN_NONE);
                        Primitive2DReference aNewPrimitive(new PolygonStrokePrimitive2D(aStrikeoutLine, aLineAttribute));

                        // add primitive
                        rTarget.push_back(aNewPrimitive);

                        if(bDoubleLine)
                        {
                            // double line, create 2nd primitive with offset using TransformPrimitive based on
                            // already created NewPrimitive
                            const double fLineDist(2.0 * fStrikeoutHeight);
                            basegfx::B2DHomMatrix aTransform;

                            // move base point of text to 0.0 and de-rotate
                            aTransform.translate(-rDecTrans.getTranslate().getX(), -rDecTrans.getTranslate().getY());
                            aTransform.rotate(-rDecTrans.getRotate());

                            // translate in Y by offset
                            aTransform.translate(0.0, -fLineDist);

                            // move back and rotate
                            aTransform.rotate(rDecTrans.getRotate());
                            aTransform.translate(rDecTrans.getTranslate().getX(), rDecTrans.getTranslate().getY());

                            // add transform primitive
                            const Primitive2DSequence aContent(&aNewPrimitive, 1);
                            rTarget.push_back(Primitive2DReference(new TransformPrimitive2D(aTransform, aContent)));
                        }
                    }
                }
            }

            // TODO: Handle Font Emphasis Above/Below
        }

        void TextDecoratedPortionPrimitive2D::impCorrectTextBoundary(::com::sun::star::i18n::Boundary& rNextWordBoundary) const
        {
            // truncate aNextWordBoundary to min/max possible values. This is necessary since the word start may be
            // before/after getTextPosition() when a long string is the content and getTextPosition()
            // is right inside a word. Same for end.
            const sal_Int32 aMinPos(static_cast< sal_Int32 >(getTextPosition()));
            const sal_Int32 aMaxPos(aMinPos + static_cast< sal_Int32 >(getTextLength()));

            if(rNextWordBoundary.startPos < aMinPos)
            {
                rNextWordBoundary.startPos = aMinPos;
            }
            else if(rNextWordBoundary.startPos > aMaxPos)
            {
                rNextWordBoundary.startPos = aMaxPos;
            }

            if(rNextWordBoundary.endPos < aMinPos)
            {
                rNextWordBoundary.endPos = aMinPos;
            }
            else if(rNextWordBoundary.endPos > aMaxPos)
            {
                rNextWordBoundary.endPos = aMaxPos;
            }
        }

        void TextDecoratedPortionPrimitive2D::impSplitSingleWords(
            std::vector< Primitive2DReference >& rTarget,
            basegfx::DecomposedB2DHomMatrixContainer& rDecTrans) const
        {
            // break iterator support
            // made static so it only needs to be fetched once, even with many single
            // constructed VclMetafileProcessor2D. It's still incarnated on demand,
            // but exists for OOo runtime now by purpose.
            static ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XBreakIterator > xLocalBreakIterator;

            if(!xLocalBreakIterator.is())
            {
                ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xMSF(::comphelper::getProcessServiceFactory());
                xLocalBreakIterator.set(xMSF->createInstance(rtl::OUString::createFromAscii("com.sun.star.i18n.BreakIterator")), ::com::sun::star::uno::UNO_QUERY);
            }

            if(xLocalBreakIterator.is())
            {
                // init word iterator, get first word and truncate to possibilities
                ::com::sun::star::i18n::Boundary aNextWordBoundary(xLocalBreakIterator->getWordBoundary(
                    getText(), getTextPosition(), getLocale(), ::com::sun::star::i18n::WordType::ANYWORD_IGNOREWHITESPACES, sal_True));
                impCorrectTextBoundary(aNextWordBoundary);

                // prepare new font attributes WITHOUT outline
                const FontAttributes aNewFontAttributes(
                    getFontAttributes().getFamilyName(),
                    getFontAttributes().getStyleName(),
                    getFontAttributes().getWeight(),
                    getFontAttributes().getSymbol(),
                    getFontAttributes().getVertical(),
                    getFontAttributes().getItalic(),
                    false,             // no outline anymore, handled locally
                    getFontAttributes().getRTL(),
                    getFontAttributes().getBiDiStrong());

                if(aNextWordBoundary.startPos == getTextPosition() && aNextWordBoundary.endPos == getTextLength())
                {
                    // it IS only a single word, handle as one word
                    impCreateGeometryContent(rTarget, rDecTrans, getText(), getTextPosition(), getTextLength(), getDXArray(), aNewFontAttributes);
                }
                else
                {
                    // prepare TextLayouter
                    const bool bNoDXArray(getDXArray().empty());
                    TextLayouterDevice aTextLayouter;

                    if(bNoDXArray)
                    {
                        // ..but only completely when no DXArray
                        aTextLayouter.setFontAttributes(getFontAttributes(), rDecTrans.getScale().getX(), rDecTrans.getScale().getY());
                    }

                    // do iterate over single words
                    while(aNextWordBoundary.startPos != aNextWordBoundary.endPos)
                    {
                        // prepare values for new portion
                        const xub_StrLen nNewTextStart(static_cast< xub_StrLen >(aNextWordBoundary.startPos));
                        const xub_StrLen nNewTextEnd(static_cast< xub_StrLen >(aNextWordBoundary.endPos));

                        // prepare transform for the single word
                        basegfx::B2DHomMatrix aNewTransform;
                        ::std::vector< double > aNewDXArray;
                        const bool bNewStartIsNotOldStart(nNewTextStart > getTextPosition());

                        if(!bNoDXArray)
                        {
                            // prepare new DXArray for the single word
                            aNewDXArray = ::std::vector< double >(
                                getDXArray().begin() + static_cast< sal_uInt32 >(nNewTextStart - getTextPosition()), 
                                getDXArray().begin() + static_cast< sal_uInt32 >(nNewTextEnd - getTextPosition()));
                        }

                        if(bNewStartIsNotOldStart)
                        {
                            // needs to be moved to a new start position
                            double fOffset(0.0);
                            
                            if(bNoDXArray)
                            {
                                // evaluate using TextLayouter
                                fOffset = aTextLayouter.getTextWidth(getText(), getTextPosition(), nNewTextStart);
                            }
                            else
                            {
                                // get from DXArray
                                const sal_uInt32 nIndex(static_cast< sal_uInt32 >(nNewTextStart - getTextPosition()));
                                fOffset = getDXArray()[nIndex - 1];
                            }

                            // apply needed offset to transformation
                            aNewTransform.translate(fOffset, 0.0);

                            if(!bNoDXArray)
                            {
                                // DXArray values need to be corrected with the offset, too
                                const sal_uInt32 nArraySize(aNewDXArray.size());

                                for(sal_uInt32 a(0); a < nArraySize; a++)
                                {
                                    aNewDXArray[a] -= fOffset;
                                }
                            }
                        }

                        // add text transformation to new transformation
                        aNewTransform *= rDecTrans.getB2DHomMatrix();

                        // create geometry content for the single word. Do not forget
                        // to use the new transformation
                        basegfx::DecomposedB2DHomMatrixContainer aDecTrans(aNewTransform);
                        
                        impCreateGeometryContent(rTarget, aDecTrans, getText(), nNewTextStart, 
                            nNewTextEnd - nNewTextStart, aNewDXArray, aNewFontAttributes);

                        // prepare next word and truncate to possibilities
                        aNextWordBoundary = xLocalBreakIterator->nextWord(
                            getText(), aNextWordBoundary.endPos, getLocale(),
                            ::com::sun::star::i18n::WordType::ANYWORD_IGNOREWHITESPACES);
                        
                        impCorrectTextBoundary(aNextWordBoundary);
                    }
                }
            }
        }

        Primitive2DSequence TextDecoratedPortionPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
        {
            std::vector< Primitive2DReference > aNewPrimitives;
            basegfx::DecomposedB2DHomMatrixContainer aDecTrans(getTextTransform());
            Primitive2DSequence aRetval;

            // create basic geometry such as SimpleTextPrimitive, Overline, Underline,
            // Strikeout, etc...
            if(getWordLineMode())
            {
                // support for single word mode
                impSplitSingleWords(aNewPrimitives, aDecTrans);
            }
            else
            {
                // prepare new font attributes WITHOUT outline
                const FontAttributes aNewFontAttributes(
                    getFontAttributes().getFamilyName(),
                    getFontAttributes().getStyleName(),
                    getFontAttributes().getWeight(),
                    getFontAttributes().getSymbol(),
                    getFontAttributes().getVertical(),
                    getFontAttributes().getItalic(),
                    false,             // no outline anymore, handled locally
                    getFontAttributes().getRTL(),
                    getFontAttributes().getBiDiStrong());

                // handle as one word
                impCreateGeometryContent(aNewPrimitives, aDecTrans, getText(), getTextPosition(), getTextLength(), getDXArray(), aNewFontAttributes);
            }

            // convert to Primitive2DSequence
            const sal_uInt32 nMemberCount(aNewPrimitives.size());

            if(nMemberCount)
            {
                aRetval.realloc(nMemberCount);

                for(sal_uInt32 a(0); a < nMemberCount; a++)
                {
                    aRetval[a] = aNewPrimitives[a];
                }
            }

            // Handle Shadow, Outline and FontRelief
            if(aRetval.hasElements())
            {
                // outline AND shadow depend on NO FontRelief (see dialog)
                const bool bHasFontRelief(FONT_RELIEF_NONE != getFontRelief());
                const bool bHasShadow(!bHasFontRelief && getShadow());
                const bool bHasOutline(!bHasFontRelief && getFontAttributes().getOutline());

                if(bHasShadow || bHasFontRelief || bHasOutline)
                {
                    Primitive2DReference aShadow;

                    if(bHasShadow)
                    {
                        // create shadow with current content (in aRetval). Text shadow
                        // is constant, relative to font size, rotated with the text and has a
                        // constant color.
                        // shadow parameter values
                        static double fFactor(1.0 / 24.0);
                        const double fTextShadowOffset(aDecTrans.getScale().getY() * fFactor);
                        static basegfx::BColor aShadowColor(0.3, 0.3, 0.3);

                        // preapare shadow transform matrix
                        basegfx::B2DHomMatrix aShadowTransform;
                        aShadowTransform.translate(fTextShadowOffset, fTextShadowOffset);

                        // create shadow primitive
                        aShadow = Primitive2DReference(new ShadowPrimitive2D(
                            aShadowTransform,
                            aShadowColor,
                            aRetval));
                    }

                    if(bHasFontRelief)
                    {
                        // create emboss using an own helper primitive since this will
                        // be view-dependent
                        const basegfx::BColor aBBlack(0.0, 0.0, 0.0);
                        const bool bDefaultTextColor(aBBlack == getFontColor());
                        TextEffectStyle2D aTextEffectStyle2D(TEXTEFFECTSTYLE2D_RELIEF_EMBOSSED);

                        if(bDefaultTextColor)
                        {
                            if(FONT_RELIEF_ENGRAVED == getFontRelief())
                            {
                                aTextEffectStyle2D = TEXTEFFECTSTYLE2D_RELIEF_ENGRAVED_DEFAULT;
                            }
                            else
                            {
                                aTextEffectStyle2D = TEXTEFFECTSTYLE2D_RELIEF_EMBOSSED_DEFAULT;
                            }
                        }
                        else
                        {
                            if(FONT_RELIEF_ENGRAVED == getFontRelief())
                            {
                                aTextEffectStyle2D = TEXTEFFECTSTYLE2D_RELIEF_ENGRAVED;
                            }
                            else
                            {
                                aTextEffectStyle2D = TEXTEFFECTSTYLE2D_RELIEF_EMBOSSED;
                            }
                        }

                        Primitive2DReference aNewTextEffect(new TextEffectPrimitive2D(
                            aRetval,
                            aDecTrans.getTranslate(),
                            aDecTrans.getRotate(),
                            aTextEffectStyle2D));
                        aRetval = Primitive2DSequence(&aNewTextEffect, 1);
                    }
                    else if(bHasOutline)
                    {
                        // create outline using an own helper primitive since this will
                        // be view-dependent
                        Primitive2DReference aNewTextEffect(new TextEffectPrimitive2D(
                            aRetval,
                            aDecTrans.getTranslate(),
                            aDecTrans.getRotate(),
                            TEXTEFFECTSTYLE2D_OUTLINE));
                        aRetval = Primitive2DSequence(&aNewTextEffect, 1);
                    }

                    if(aShadow.is())
                    {
                        // put shadow in front if there is one to paint timely before
                        // but placed behind content
                        const Primitive2DSequence aContent(aRetval);
                        aRetval = Primitive2DSequence(&aShadow, 1);
                        appendPrimitive2DSequenceToPrimitive2DSequence(aRetval, aContent);
                    }
                }
            }

            return aRetval;
        }

        TextDecoratedPortionPrimitive2D::TextDecoratedPortionPrimitive2D(

            // TextSimplePortionPrimitive2D parameters
            const basegfx::B2DHomMatrix& rNewTransform,
            const String& rText,
            xub_StrLen aTextPosition,
            xub_StrLen aTextLength,
            const ::std::vector< double >& rDXArray,
            const FontAttributes& rFontAttributes,
            const ::com::sun::star::lang::Locale& rLocale,
            const basegfx::BColor& rFontColor,

            // local parameters
            const basegfx::BColor& rOverlineColor,
            const basegfx::BColor& rTextlineColor,
            FontUnderline eFontOverline,
            FontUnderline eFontUnderline,
            bool bUnderlineAbove,
            FontStrikeout eFontStrikeout,
            bool bWordLineMode,
            FontEmphasisMark eFontEmphasisMark,
            bool bEmphasisMarkAbove,
            bool bEmphasisMarkBelow,
            FontRelief eFontRelief,
            bool bShadow)
        :	TextSimplePortionPrimitive2D(rNewTransform, rText, aTextPosition, aTextLength, rDXArray, rFontAttributes, rLocale, rFontColor),
            maOverlineColor(rOverlineColor),
            maTextlineColor(rTextlineColor),
            meFontOverline(eFontOverline),
            meFontUnderline(eFontUnderline),
            meFontStrikeout(eFontStrikeout),
            meFontEmphasisMark(eFontEmphasisMark),
            meFontRelief(eFontRelief),
            mbUnderlineAbove(bUnderlineAbove),
            mbWordLineMode(bWordLineMode),
            mbEmphasisMarkAbove(bEmphasisMarkAbove),
            mbEmphasisMarkBelow(bEmphasisMarkBelow),
            mbShadow(bShadow)
        {
        }

        bool TextDecoratedPortionPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
        {
            if(TextSimplePortionPrimitive2D::operator==(rPrimitive))
            {
                const TextDecoratedPortionPrimitive2D& rCompare = (TextDecoratedPortionPrimitive2D&)rPrimitive;

                return (getOverlineColor() == rCompare.getOverlineColor()
                    && getTextlineColor() == rCompare.getTextlineColor()
                    && getFontOverline() == rCompare.getFontOverline()
                    && getFontUnderline() == rCompare.getFontUnderline()
                    && getFontStrikeout() == rCompare.getFontStrikeout()
                    && getFontEmphasisMark() == rCompare.getFontEmphasisMark()
                    && getFontRelief() == rCompare.getFontRelief()
                    && getUnderlineAbove() == rCompare.getUnderlineAbove()
                    && getWordLineMode() == rCompare.getWordLineMode()
                    && getEmphasisMarkAbove() == rCompare.getEmphasisMarkAbove()
                    && getEmphasisMarkBelow() == rCompare.getEmphasisMarkBelow()
                    && getShadow() == rCompare.getShadow());
            }

            return false;
        }

        // provide unique ID
        ImplPrimitrive2DIDBlock(TextDecoratedPortionPrimitive2D, PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D)

    } // end of namespace primitive2d
} // end of namespace drawinglayer

//////////////////////////////////////////////////////////////////////////////
// eof