LibreOffice Module drawinglayer (master) 1
textstrikeoutprimitive2d.cxx
Go to the documentation of this file.
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
29#include <osl/diagnose.h>
30#include <rtl/ustrbuf.hxx>
31#include <utility>
32
33
35{
37 basegfx::B2DHomMatrix aObjectTransformation,
38 double fWidth,
39 const basegfx::BColor& rFontColor)
40 : maObjectTransformation(std::move(aObjectTransformation)),
41 mfWidth(fWidth),
42 maFontColor(rFontColor)
43 {
44 }
45
47 {
48 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
49 {
50 const BaseTextStrikeoutPrimitive2D& rCompare = static_cast<const BaseTextStrikeoutPrimitive2D&>(rPrimitive);
51
53 && getWidth() == rCompare.getWidth()
54 && getFontColor() == rCompare.getFontColor());
55 }
56
57 return false;
58 }
59
60
62 {
63 // strikeout with character
64 const OUString aSingleCharString(getStrikeoutChar());
65 basegfx::B2DVector aScale, aTranslate;
66 double fRotate, fShearX;
67
68 // get decomposition
69 getObjectTransformation().decompose(aScale, aTranslate, fRotate, fShearX);
70
71 // prepare TextLayouter
72 TextLayouterDevice aTextLayouter;
73
74 aTextLayouter.setFontAttribute(
76 aScale.getX(),
77 aScale.getY(),
78 getLocale());
79
80 const double fStrikeCharWidth(aTextLayouter.getTextWidth(aSingleCharString, 0, 1));
81 const double fStrikeCharCount(fabs(getWidth()/fStrikeCharWidth));
82 const sal_uInt32 nStrikeCharCount(static_cast< sal_uInt32 >(fStrikeCharCount + 0.5));
83 std::vector<double> aDXArray(nStrikeCharCount);
84 OUStringBuffer aStrikeoutString;
85
86 for(sal_uInt32 a(0); a < nStrikeCharCount; a++)
87 {
88 aStrikeoutString.append(aSingleCharString);
89 aDXArray[a] = (a + 1) * fStrikeCharWidth;
90 }
91
92 auto len = aStrikeoutString.getLength();
93 rContainer.push_back(
96 aStrikeoutString.makeStringAndClear(),
97 0,
98 len,
99 std::move(aDXArray),
100 {},
102 getLocale(),
103 getFontColor()));
104 }
105
107 const basegfx::B2DHomMatrix& rObjectTransformation,
108 double fWidth,
109 const basegfx::BColor& rFontColor,
110 sal_Unicode aStrikeoutChar,
111 attribute::FontAttribute aFontAttribute,
112 css::lang::Locale aLocale)
113 : BaseTextStrikeoutPrimitive2D(rObjectTransformation, fWidth, rFontColor),
114 maStrikeoutChar(aStrikeoutChar),
115 maFontAttribute(std::move(aFontAttribute)),
116 maLocale(std::move(aLocale))
117 {
118 }
119
121 {
122 if(BaseTextStrikeoutPrimitive2D::operator==(rPrimitive))
123 {
124 const TextCharacterStrikeoutPrimitive2D& rCompare = static_cast<const TextCharacterStrikeoutPrimitive2D&>(rPrimitive);
125
126 return (getStrikeoutChar() == rCompare.getStrikeoutChar()
127 && getFontAttribute() == rCompare.getFontAttribute()
128 && LocalesAreEqual(getLocale(), rCompare.getLocale()));
129 }
130
131 return false;
132 }
133
134 // provide unique ID
136 {
138 }
139
141 {
143 "Wrong TEXT_STRIKEOUT type; a TextCharacterStrikeoutPrimitive2D should be used (!)");
144
145 // strikeout with geometry
146 double fStrikeoutHeight(getHeight());
147 double fStrikeoutOffset(getOffset());
148 bool bDoubleLine(false);
149
150 // get decomposition
151 basegfx::B2DVector aScale, aTranslate;
152 double fRotate, fShearX;
153 getObjectTransformation().decompose(aScale, aTranslate, fRotate, fShearX);
154
155 // set line attribute
156 switch(getTextStrikeout())
157 {
158 default : // case primitive2d::TEXT_STRIKEOUT_SINGLE:
159 {
160 break;
161 }
163 {
164 bDoubleLine = true;
165 break;
166 }
168 {
169 fStrikeoutHeight *= 2.0;
170 break;
171 }
172 }
173
174 if(bDoubleLine)
175 {
176 fStrikeoutOffset -= 0.50 * fStrikeoutHeight;
177 fStrikeoutHeight *= 0.64;
178 }
179
180 // create base polygon and new primitive
181 basegfx::B2DPolygon aStrikeoutLine;
182
183 aStrikeoutLine.append(basegfx::B2DPoint(0.0, -fStrikeoutOffset));
184 aStrikeoutLine.append(basegfx::B2DPoint(getWidth(), -fStrikeoutOffset));
185
186 const basegfx::B2DHomMatrix aUnscaledTransform(
188 fShearX, fRotate, aTranslate));
189
190 aStrikeoutLine.transform(aUnscaledTransform);
191
192 // add primitive
193 const attribute::LineAttribute aLineAttribute(getFontColor(), fStrikeoutHeight, basegfx::B2DLineJoin::NONE);
194 Primitive2DContainer xRetval(1);
195 xRetval[0] = new PolygonStrokePrimitive2D(std::move(aStrikeoutLine), aLineAttribute);
196
197 if(bDoubleLine)
198 {
199 // double line, create 2nd primitive with offset using TransformPrimitive based on
200 // already created NewPrimitive
201 const double fLineDist(2.0 * fStrikeoutHeight);
202
203 // move base point of text to 0.0 and de-rotate
205 -aTranslate.getX(), -aTranslate.getY()));
206 aTransform.rotate(-fRotate);
207
208 // translate in Y by offset
209 aTransform.translate(0.0, -fLineDist);
210
211 // move back and rotate
212 aTransform.rotate(fRotate);
213 aTransform.translate(aTranslate.getX(), aTranslate.getY());
214
215 // add transform primitive
216 xRetval.push_back(
218 aTransform,
219 Primitive2DContainer(xRetval)));
220 }
221
222 rContainer.append(std::move(xRetval));
223 }
224
226 const basegfx::B2DHomMatrix& rObjectTransformation,
227 double fWidth,
228 const basegfx::BColor& rFontColor,
229 double fHeight,
230 double fOffset,
231 TextStrikeout eTextStrikeout)
232 : BaseTextStrikeoutPrimitive2D(rObjectTransformation, fWidth, rFontColor),
233 mfHeight(fHeight),
234 mfOffset(fOffset),
235 meTextStrikeout(eTextStrikeout)
236 {
237 }
238
240 {
241 if(BaseTextStrikeoutPrimitive2D::operator==(rPrimitive))
242 {
243 const TextGeometryStrikeoutPrimitive2D& rCompare = static_cast<const TextGeometryStrikeoutPrimitive2D&>(rPrimitive);
244
245 return (getHeight() == rCompare.getHeight()
246 && getOffset() == rCompare.getOffset()
247 && getTextStrikeout() == rCompare.getTextStrikeout());
248 }
249
250 return false;
251 }
252
253 // provide unique ID
255 {
257 }
258
259} // end of namespace
260
261/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool decompose(B2DTuple &rScale, B2DTuple &rTranslate, double &rRotate, double &rShearX) const
void rotate(double fRadiant)
void translate(double fX, double fY)
void transform(const basegfx::B2DHomMatrix &rMatrix)
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
TYPE getX() const
TYPE getY() const
BaseTextStrikeoutPrimitive2D(basegfx::B2DHomMatrix aObjectTransformation, double fWidth, const basegfx::BColor &rFontColor)
constructor
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
compare operator
const basegfx::B2DHomMatrix & getObjectTransformation() const
data read access
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
compare operator
virtual sal_uInt32 getPrimitive2DID() const override
provide unique ID
virtual void create2DDecomposition(Primitive2DContainer &rContainer, const geometry::ViewInformation2D &rViewInformation) const override
local decomposition.
TextCharacterStrikeoutPrimitive2D(const basegfx::B2DHomMatrix &rObjectTransformation, double fWidth, const basegfx::BColor &rFontColor, sal_Unicode aStrikeoutChar, attribute::FontAttribute aFontAttribute, css::lang::Locale aLocale)
constructor
TextGeometryStrikeoutPrimitive2D(const basegfx::B2DHomMatrix &rObjectTransformation, double fWidth, const basegfx::BColor &rFontColor, double fHeight, double fOffset, TextStrikeout eTextStrikeout)
constructor
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
compare operator
virtual void create2DDecomposition(Primitive2DContainer &rContainer, const geometry::ViewInformation2D &rViewInformation) const override
local decomposition.
virtual sal_uInt32 getPrimitive2DID() const override
provide unique ID
void setFontAttribute(const attribute::FontAttribute &rFontAttribute, double fFontScaleX, double fFontScaleY, const css::lang::Locale &rLocale)
double getTextWidth(const OUString &rText, sal_uInt32 nIndex, sal_uInt32 nLength) const
#define PRIMITIVE2D_ID_TEXTCHARACTERSTRIKEOUTPRIMITIVE2D
#define PRIMITIVE2D_ID_TEXTGEOMETRYSTRIKEOUTPRIMITIVE2D
uno_Any a
B2DHomMatrix createTranslateB2DHomMatrix(double fTranslateX, double fTranslateY)
B2DHomMatrix createShearXRotateTranslateB2DHomMatrix(double fShearX, double fRadiant, double fTranslateX, double fTranslateY)
bool LocalesAreEqual(const css::lang::Locale &rA, const css::lang::Locale &rB)
small helper to have a compare operator for Locale
TextStrikeout
FontStrikeout definition.
sal_uInt16 sal_Unicode