Line data Source code
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 <drawinglayer/primitive2d/textstrikeoutprimitive2d.hxx>
21 : #include <drawinglayer/primitive2d/textlayoutdevice.hxx>
22 : #include <drawinglayer/primitive2d/textprimitive2d.hxx>
23 : #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
24 : #include <basegfx/polygon/b2dpolygon.hxx>
25 : #include <basegfx/matrix/b2dhommatrixtools.hxx>
26 : #include <drawinglayer/attribute/lineattribute.hxx>
27 : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
28 : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
29 :
30 :
31 :
32 : namespace drawinglayer
33 : {
34 : namespace primitive2d
35 : {
36 1366 : BaseTextStrikeoutPrimitive2D::BaseTextStrikeoutPrimitive2D(
37 : const basegfx::B2DHomMatrix& rObjectTransformation,
38 : double fWidth,
39 : const basegfx::BColor& rFontColor)
40 : : BufferedDecompositionPrimitive2D(),
41 : maObjectTransformation(rObjectTransformation),
42 : mfWidth(fWidth),
43 1366 : maFontColor(rFontColor)
44 : {
45 1366 : }
46 :
47 0 : bool BaseTextStrikeoutPrimitive2D::operator==( const BasePrimitive2D& rPrimitive ) const
48 : {
49 0 : if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
50 : {
51 0 : const BaseTextStrikeoutPrimitive2D& rCompare = static_cast<const BaseTextStrikeoutPrimitive2D&>(rPrimitive);
52 :
53 0 : return (getObjectTransformation() == rCompare.getObjectTransformation()
54 0 : && getWidth() == rCompare.getWidth()
55 0 : && getFontColor() == rCompare.getFontColor());
56 : }
57 :
58 0 : return false;
59 : }
60 : } // end of namespace primitive2d
61 : } // end of namespace drawinglayer
62 :
63 :
64 :
65 : namespace drawinglayer
66 : {
67 : namespace primitive2d
68 : {
69 8 : Primitive2DSequence TextCharacterStrikeoutPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
70 : {
71 : // strikeout with character
72 8 : const OUString aSingleCharString(getStrikeoutChar());
73 16 : basegfx::B2DVector aScale, aTranslate;
74 : double fRotate, fShearX;
75 :
76 : // get decomposition
77 8 : getObjectTransformation().decompose(aScale, aTranslate, fRotate, fShearX);
78 :
79 : // prepare TextLayouter
80 16 : TextLayouterDevice aTextLayouter;
81 :
82 : aTextLayouter.setFontAttribute(
83 8 : getFontAttribute(),
84 : aScale.getX(),
85 : aScale.getY(),
86 16 : getLocale());
87 :
88 8 : const double fStrikeCharWidth(aTextLayouter.getTextWidth(aSingleCharString, 0, 1));
89 8 : const double fStrikeCharCount(fabs(getWidth()/fStrikeCharWidth));
90 8 : const sal_uInt32 nStrikeCharCount(static_cast< sal_uInt32 >(fStrikeCharCount + 0.5));
91 16 : std::vector<double> aDXArray(nStrikeCharCount);
92 16 : OUString aStrikeoutString;
93 :
94 48 : for(sal_uInt32 a(0); a < nStrikeCharCount; a++)
95 : {
96 40 : aStrikeoutString += aSingleCharString;
97 40 : aDXArray[a] = (a + 1) * fStrikeCharWidth;
98 : }
99 :
100 : Primitive2DReference xReference(
101 : new TextSimplePortionPrimitive2D(
102 8 : getObjectTransformation(),
103 : aStrikeoutString,
104 : 0,
105 : aStrikeoutString.getLength(),
106 : aDXArray,
107 : getFontAttribute(),
108 : getLocale(),
109 16 : getFontColor()));
110 :
111 16 : return Primitive2DSequence(&xReference, 1);
112 : }
113 :
114 8 : TextCharacterStrikeoutPrimitive2D::TextCharacterStrikeoutPrimitive2D(
115 : const basegfx::B2DHomMatrix& rObjectTransformation,
116 : double fWidth,
117 : const basegfx::BColor& rFontColor,
118 : sal_Unicode aStrikeoutChar,
119 : const attribute::FontAttribute& rFontAttribute,
120 : const ::com::sun::star::lang::Locale& rLocale)
121 : : BaseTextStrikeoutPrimitive2D(rObjectTransformation, fWidth, rFontColor),
122 : maStrikeoutChar(aStrikeoutChar),
123 : maFontAttribute(rFontAttribute),
124 8 : maLocale(rLocale)
125 : {
126 8 : }
127 :
128 0 : bool TextCharacterStrikeoutPrimitive2D::operator==( const BasePrimitive2D& rPrimitive ) const
129 : {
130 0 : if(BaseTextStrikeoutPrimitive2D::operator==(rPrimitive))
131 : {
132 0 : const TextCharacterStrikeoutPrimitive2D& rCompare = static_cast<const TextCharacterStrikeoutPrimitive2D&>(rPrimitive);
133 :
134 0 : return (getStrikeoutChar() == rCompare.getStrikeoutChar()
135 0 : && getFontAttribute() == rCompare.getFontAttribute()
136 0 : && LocalesAreEqual(getLocale(), rCompare.getLocale()));
137 : }
138 :
139 0 : return false;
140 : }
141 :
142 : // provide unique ID
143 16 : ImplPrimitive2DIDBlock(TextCharacterStrikeoutPrimitive2D, PRIMITIVE2D_ID_TEXTCHARACTERSTRIKEOUTPRIMITIVE2D)
144 :
145 : } // end of namespace primitive2d
146 : } // end of namespace drawinglayer
147 :
148 :
149 :
150 : namespace drawinglayer
151 : {
152 : namespace primitive2d
153 : {
154 1358 : Primitive2DSequence TextGeometryStrikeoutPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
155 : {
156 : OSL_ENSURE(TEXT_STRIKEOUT_SLASH != getTextStrikeout() && TEXT_STRIKEOUT_X != getTextStrikeout(),
157 : "Wrong TEXT_STRIKEOUT type; a TextCharacterStrikeoutPrimitive2D should be used (!)");
158 :
159 : // strikeout with geometry
160 1358 : double fStrikeoutHeight(getHeight());
161 1358 : double fStrikeoutOffset(getOffset());
162 1358 : bool bDoubleLine(false);
163 :
164 : // get decomposition
165 2716 : basegfx::B2DVector aScale, aTranslate;
166 : double fRotate, fShearX;
167 1358 : getObjectTransformation().decompose(aScale, aTranslate, fRotate, fShearX);
168 :
169 : // set line attribute
170 1358 : switch(getTextStrikeout())
171 : {
172 : default : // case primitive2d::TEXT_STRIKEOUT_SINGLE:
173 : {
174 484 : break;
175 : }
176 : case primitive2d::TEXT_STRIKEOUT_DOUBLE:
177 : {
178 835 : bDoubleLine = true;
179 835 : break;
180 : }
181 : case primitive2d::TEXT_STRIKEOUT_BOLD:
182 : {
183 39 : fStrikeoutHeight *= 2.0;
184 39 : break;
185 : }
186 : }
187 :
188 1358 : if(bDoubleLine)
189 : {
190 835 : fStrikeoutOffset -= 0.50 * fStrikeoutHeight;
191 835 : fStrikeoutHeight *= 0.64;
192 : }
193 :
194 : // create base polygon and new primitive
195 1358 : basegfx::B2DPolygon aStrikeoutLine;
196 :
197 1358 : aStrikeoutLine.append(basegfx::B2DPoint(0.0, -fStrikeoutOffset));
198 1358 : aStrikeoutLine.append(basegfx::B2DPoint(getWidth(), -fStrikeoutOffset));
199 :
200 : const basegfx::B2DHomMatrix aUnscaledTransform(
201 : basegfx::tools::createShearXRotateTranslateB2DHomMatrix(
202 2716 : fShearX, fRotate, aTranslate));
203 :
204 1358 : aStrikeoutLine.transform(aUnscaledTransform);
205 :
206 : // add primitive
207 2716 : const attribute::LineAttribute aLineAttribute(getFontColor(), fStrikeoutHeight, basegfx::B2DLINEJOIN_NONE);
208 2716 : Primitive2DSequence xRetval(1);
209 1358 : xRetval[0] = Primitive2DReference(new PolygonStrokePrimitive2D(aStrikeoutLine, aLineAttribute));
210 :
211 1358 : if(bDoubleLine)
212 : {
213 : // double line, create 2nd primitive with offset using TransformPrimitive based on
214 : // already created NewPrimitive
215 835 : const double fLineDist(2.0 * fStrikeoutHeight);
216 :
217 : // move base point of text to 0.0 and de-rotate
218 : basegfx::B2DHomMatrix aTransform(basegfx::tools::createTranslateB2DHomMatrix(
219 835 : -aTranslate.getX(), -aTranslate.getY()));
220 835 : aTransform.rotate(-fRotate);
221 :
222 : // translate in Y by offset
223 835 : aTransform.translate(0.0, -fLineDist);
224 :
225 : // move back and rotate
226 835 : aTransform.rotate(fRotate);
227 835 : aTransform.translate(aTranslate.getX(), aTranslate.getY());
228 :
229 : // add transform primitive
230 : appendPrimitive2DReferenceToPrimitive2DSequence(xRetval,
231 : Primitive2DReference(
232 : new TransformPrimitive2D(
233 : aTransform,
234 835 : xRetval)));
235 : }
236 :
237 4074 : return xRetval;
238 : }
239 :
240 1358 : TextGeometryStrikeoutPrimitive2D::TextGeometryStrikeoutPrimitive2D(
241 : const basegfx::B2DHomMatrix& rObjectTransformation,
242 : double fWidth,
243 : const basegfx::BColor& rFontColor,
244 : double fHeight,
245 : double fOffset,
246 : TextStrikeout eTextStrikeout)
247 : : BaseTextStrikeoutPrimitive2D(rObjectTransformation, fWidth, rFontColor),
248 : mfHeight(fHeight),
249 : mfOffset(fOffset),
250 1358 : meTextStrikeout(eTextStrikeout)
251 : {
252 1358 : }
253 :
254 0 : bool TextGeometryStrikeoutPrimitive2D::operator==( const BasePrimitive2D& rPrimitive ) const
255 : {
256 0 : if(BaseTextStrikeoutPrimitive2D::operator==(rPrimitive))
257 : {
258 0 : const TextGeometryStrikeoutPrimitive2D& rCompare = static_cast<const TextGeometryStrikeoutPrimitive2D&>(rPrimitive);
259 :
260 0 : return (getHeight() == rCompare.getHeight()
261 0 : && getOffset() == rCompare.getOffset()
262 0 : && getTextStrikeout() == rCompare.getTextStrikeout());
263 : }
264 :
265 0 : return false;
266 : }
267 :
268 : // provide unique ID
269 252 : ImplPrimitive2DIDBlock(TextGeometryStrikeoutPrimitive2D, PRIMITIVE2D_ID_TEXTGEOMETRYSTRIKEOUTPRIMITIVE2D)
270 :
271 : } // end of namespace primitive2d
272 : } // end of namespace drawinglayer
273 :
274 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|