Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/drawinglayer/source/primitive2d/textlineprimitive2d.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <primitive2d/textlineprimitive2d.hxx>
21
#include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
22
#include <drawinglayer/attribute/strokeattribute.hxx>
23
#include <drawinglayer/attribute/lineattribute.hxx>
24
#include <basegfx/matrix/b2dhommatrixtools.hxx>
25
#include <drawinglayer/primitive2d/transformprimitive2d.hxx>
26
#include <drawinglayer/primitive2d/PolygonWavePrimitive2D.hxx>
27
#include <utility>
28
29
30
namespace drawinglayer::primitive2d
31
{
32
        Primitive2DReference TextLinePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
33
0
        {
34
0
            if(TEXT_LINE_NONE == getTextLine())
35
0
                return nullptr;
36
37
0
            bool bDoubleLine(false);
38
0
            bool bWaveLine(false);
39
0
            bool bBoldLine(false);
40
0
            const int* pDotDashArray(nullptr);
41
0
            basegfx::B2DLineJoin eLineJoin(basegfx::B2DLineJoin::NONE);
42
0
            double fOffset(getOffset());
43
0
            double fHeight(getHeight());
44
45
0
            static const int aDottedArray[]     = { 1, 1, 0};               // DOTTED LINE
46
0
            static const int aDotDashArray[]    = { 1, 1, 4, 1, 0};         // DASHDOT
47
0
            static const int aDashDotDotArray[] = { 1, 1, 1, 1, 4, 1, 0};   // DASHDOTDOT
48
0
            static const int aDashedArray[]     = { 5, 2, 0};               // DASHED LINE
49
0
            static const int aLongDashArray[]   = { 7, 2, 0};               // LONGDASH
50
51
            // get decomposition
52
0
            basegfx::B2DVector aScale, aTranslate;
53
0
            double fRotate, fShearX;
54
0
            getObjectTransformation().decompose(aScale, aTranslate, fRotate, fShearX);
55
56
0
            switch(getTextLine())
57
0
            {
58
0
                default: // case TEXT_LINE_SINGLE:
59
0
                {
60
0
                    break;
61
0
                }
62
0
                case TEXT_LINE_DOUBLE:
63
0
                {
64
0
                    bDoubleLine = true;
65
0
                    break;
66
0
                }
67
0
                case TEXT_LINE_DOTTED:
68
0
                {
69
0
                    pDotDashArray = aDottedArray;
70
0
                    break;
71
0
                }
72
0
                case TEXT_LINE_DASH:
73
0
                {
74
0
                    pDotDashArray = aDashedArray;
75
0
                    break;
76
0
                }
77
0
                case TEXT_LINE_LONGDASH:
78
0
                {
79
0
                    pDotDashArray = aLongDashArray;
80
0
                    break;
81
0
                }
82
0
                case TEXT_LINE_DASHDOT:
83
0
                {
84
0
                    pDotDashArray = aDotDashArray;
85
0
                    break;
86
0
                }
87
0
                case TEXT_LINE_DASHDOTDOT:
88
0
                {
89
0
                    pDotDashArray = aDashDotDotArray;
90
0
                    break;
91
0
                }
92
0
                case TEXT_LINE_SMALLWAVE:
93
0
                case TEXT_LINE_WAVE:
94
0
                {
95
0
                    bWaveLine = true;
96
0
                    break;
97
0
                }
98
0
                case TEXT_LINE_DOUBLEWAVE:
99
0
                {
100
0
                    bDoubleLine = true;
101
0
                    bWaveLine = true;
102
0
                    break;
103
0
                }
104
0
                case TEXT_LINE_BOLD:
105
0
                {
106
0
                    bBoldLine = true;
107
0
                    break;
108
0
                }
109
0
                case TEXT_LINE_BOLDDOTTED:
110
0
                {
111
0
                    bBoldLine = true;
112
0
                    pDotDashArray = aDottedArray;
113
0
                    break;
114
0
                }
115
0
                case TEXT_LINE_BOLDDASH:
116
0
                {
117
0
                    bBoldLine = true;
118
0
                    pDotDashArray = aDashedArray;
119
0
                    break;
120
0
                }
121
0
                case TEXT_LINE_BOLDLONGDASH:
122
0
                {
123
0
                    bBoldLine = true;
124
0
                    pDotDashArray = aLongDashArray;
125
0
                    break;
126
0
                }
127
0
                case TEXT_LINE_BOLDDASHDOT:
128
0
                {
129
0
                    bBoldLine = true;
130
0
                    pDotDashArray = aDotDashArray;
131
0
                    break;
132
0
                }
133
0
                case TEXT_LINE_BOLDDASHDOTDOT:
134
0
                {
135
0
                    bBoldLine = true;
136
0
                    pDotDashArray = aDashDotDotArray;
137
0
                    break;
138
0
                }
139
0
                case TEXT_LINE_BOLDWAVE:
140
0
                {
141
0
                    bWaveLine = true;
142
0
                    bBoldLine = true;
143
0
                    break;
144
0
                }
145
0
            }
146
147
0
            if(bBoldLine)
148
0
            {
149
0
                fHeight *= 2.0;
150
0
            }
151
152
0
            if(bDoubleLine)
153
0
            {
154
0
                fOffset -= 0.50 * fHeight;
155
0
                fHeight *= 0.64;
156
0
            }
157
158
0
            if(bWaveLine)
159
0
            {
160
0
                eLineJoin = basegfx::B2DLineJoin::Round;
161
0
                fHeight *= 0.25;
162
0
            }
163
164
            // prepare Line and Stroke Attributes
165
0
            const attribute::LineAttribute aLineAttribute(getLineColor(), fHeight, eLineJoin);
166
0
            attribute::StrokeAttribute aStrokeAttribute;
167
168
0
            if(pDotDashArray)
169
0
            {
170
0
                std::vector< double > aDoubleArray;
171
172
0
                for(const int* p = pDotDashArray; *p; ++p)
173
0
                {
174
0
                    aDoubleArray.push_back(static_cast<double>(*p) * fHeight);
175
0
                }
176
177
0
                aStrokeAttribute = attribute::StrokeAttribute(std::move(aDoubleArray));
178
0
            }
179
180
            // create base polygon and new primitive
181
0
            basegfx::B2DPolygon aLine;
182
0
            Primitive2DReference aNewPrimitive;
183
184
0
            aLine.append(basegfx::B2DPoint(0.0, fOffset));
185
0
            aLine.append(basegfx::B2DPoint(getWidth(), fOffset));
186
187
0
            const basegfx::B2DHomMatrix aUnscaledTransform(
188
0
                basegfx::utils::createShearXRotateTranslateB2DHomMatrix(
189
0
                    fShearX, fRotate, aTranslate));
190
191
0
            aLine.transform(aUnscaledTransform);
192
193
0
            if(bWaveLine)
194
0
            {
195
0
                double fWaveWidth(10.6 * fHeight);
196
197
0
                if(TEXT_LINE_SMALLWAVE == getTextLine())
198
0
                {
199
0
                    fWaveWidth *= 0.7;
200
0
                }
201
0
                else if(TEXT_LINE_WAVE == getTextLine())
202
0
                {
203
                    // extra multiply to get the same WaveWidth as with the bold version
204
0
                    fWaveWidth *= 2.0;
205
0
                }
206
207
0
                aNewPrimitive = new PolygonWavePrimitive2D(aLine, aLineAttribute, aStrokeAttribute, fWaveWidth, fWaveWidth * 0.5);
208
0
            }
209
0
            else
210
0
            {
211
0
                aNewPrimitive = new PolygonStrokePrimitive2D(std::move(aLine), aLineAttribute, std::move(aStrokeAttribute));
212
0
            }
213
214
0
            if(!bDoubleLine)
215
0
                return aNewPrimitive;
216
217
            // add primitive
218
0
            Primitive2DContainer aContainer;
219
0
            aContainer.push_back(aNewPrimitive);
220
221
            // double line, create 2nd primitive with offset using TransformPrimitive based on
222
            // already created NewPrimitive
223
0
            double fLineDist(2.3 * fHeight);
224
225
0
            if(bWaveLine)
226
0
            {
227
0
                fLineDist = 6.3 * fHeight;
228
0
            }
229
230
            // move base point of text to 0.0 and de-rotate
231
0
            basegfx::B2DHomMatrix aTransform(basegfx::utils::createTranslateB2DHomMatrix(
232
0
                -aTranslate.getX(), -aTranslate.getY()));
233
0
            aTransform.rotate(-fRotate);
234
235
            // translate in Y by offset
236
0
            aTransform.translate(0.0, fLineDist);
237
238
            // move back and rotate
239
0
            aTransform.rotate(fRotate);
240
0
            aTransform.translate(aTranslate.getX(), aTranslate.getY());
241
242
            // add transform primitive
243
0
            Primitive2DContainer aContent { aNewPrimitive };
244
0
            aContainer.push_back(new TransformPrimitive2D(aTransform, std::move(aContent)));
245
0
            return new GroupPrimitive2D(std::move(aContainer));
246
0
        }
247
248
        TextLinePrimitive2D::TextLinePrimitive2D(
249
            basegfx::B2DHomMatrix aObjectTransformation,
250
            double fWidth,
251
            double fOffset,
252
            double fHeight,
253
            TextLine eTextLine,
254
            const basegfx::BColor& rLineColor)
255
0
        :   maObjectTransformation(std::move(aObjectTransformation)),
256
0
            mfWidth(fWidth),
257
0
            mfOffset(fOffset),
258
0
            mfHeight(fHeight),
259
0
            meTextLine(eTextLine),
260
0
            maLineColor(rLineColor)
261
0
        {
262
0
        }
263
264
        bool TextLinePrimitive2D::operator==( const BasePrimitive2D& rPrimitive ) const
265
0
        {
266
0
            if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
267
0
            {
268
0
                const TextLinePrimitive2D& rCompare = static_cast<const TextLinePrimitive2D&>(rPrimitive);
269
270
0
                return (getObjectTransformation() == rCompare.getObjectTransformation()
271
0
                    && getWidth() == rCompare.getWidth()
272
0
                    && getOffset() == rCompare.getOffset()
273
0
                    && getHeight() == rCompare.getHeight()
274
0
                    && getTextLine() == rCompare.getTextLine()
275
0
                    && getLineColor() == rCompare.getLineColor());
276
0
            }
277
278
0
            return false;
279
0
        }
280
281
        // provide unique ID
282
        sal_uInt32 TextLinePrimitive2D::getPrimitive2DID() const
283
0
        {
284
0
            return PRIMITIVE2D_ID_TEXTLINEPRIMITIVE2D;
285
0
        }
286
287
} // end of namespace
288
289
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */