LibreOffice Module drawinglayer (master) 1
wrongspellprimitive2d.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
25#include <utility>
26
27
29{
31 {
32 // ATM this decompose is view-independent, what the original VCL-Display is not. To mimic
33 // the old behaviour here if wanted it is necessary to add get2DDecomposition and implement
34 // it similar to the usage in e.g. HelplinePrimitive2D. Remembering the ViewTransformation
35 // should be enough then.
36 // The view-independent wavelines work well (if You ask me). Maybe the old VCL-Behaviour is only
37 // in place because it was not possible/too expensive at that time to scale the wavelines with the
38 // view...
39 // With the VCL-PixelRenderer this will not even be used since it implements WrongSpellPrimitive2D
40 // directly and mimics the old VCL-Display there. If You implemented a new renderer without
41 // direct WrongSpellPrimitive2D support, You may want to do the described change here.
42
43 // get the font height (part of scale), so decompose the matrix
44 basegfx::B2DVector aScale, aTranslate;
45 double fRotate, fShearX;
46 getTransformation().decompose(aScale, aTranslate, fRotate, fShearX);
47
48 // calculate distances based on a static default (to allow testing in debugger)
49 static const double fDefaultDistance(0.03);
50 const double fFontHeight(aScale.getY());
51 const double fUnderlineDistance(fFontHeight * fDefaultDistance);
52 const double fWaveWidth(2.0 * fUnderlineDistance);
53
54 // the Y-distance needs to be relative to FontHeight since the points get
55 // transformed with the transformation containing that scale already.
56 const double fRelativeUnderlineDistance(basegfx::fTools::equalZero(aScale.getY()) ? 0.0 : fUnderlineDistance / aScale.getY());
57 basegfx::B2DPoint aStart(getStart(), fRelativeUnderlineDistance);
58 basegfx::B2DPoint aStop(getStop(), fRelativeUnderlineDistance);
59 basegfx::B2DPolygon aPolygon;
60
61 aPolygon.append(getTransformation() * aStart);
62 aPolygon.append(getTransformation() * aStop);
63
64 // prepare line attribute
65 const attribute::LineAttribute aLineAttribute(getColor());
66
67 // create the waveline primitive
68 rContainer.push_back(new PolygonWavePrimitive2D(aPolygon, aLineAttribute, fWaveWidth, 0.5 * fWaveWidth));
69 }
70
72 basegfx::B2DHomMatrix aTransformation,
73 double fStart,
74 double fStop,
75 const basegfx::BColor& rColor)
76 : maTransformation(std::move(aTransformation)),
77 mfStart(fStart),
78 mfStop(fStop),
79 maColor(rColor)
80 {
81 }
82
84 {
85 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
86 {
87 const WrongSpellPrimitive2D& rCompare = static_cast<const WrongSpellPrimitive2D&>(rPrimitive);
88
89 return (getTransformation() == rCompare.getTransformation()
90 && getStart() == rCompare.getStart()
91 && getStop() == rCompare.getStop()
92 && getColor() == rCompare.getColor());
93 }
94
95 return false;
96 }
97
98 // provide unique ID
100 {
102 }
103
104} // end of namespace
105
106/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
basegfx::BColor maColor
bool decompose(B2DTuple &rScale, B2DTuple &rTranslate, double &rRotate, double &rShearX) const
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
TYPE getY() const
WrongSpellPrimitive2D(basegfx::B2DHomMatrix aTransformation, double fStart, double fStop, const basegfx::BColor &rColor)
constructor
virtual bool operator==(const BasePrimitive2D &rPrimitive) const override
compare operator
virtual void create2DDecomposition(Primitive2DContainer &rContainer, const geometry::ViewInformation2D &rViewInformation) const override
create local decomposition
const basegfx::B2DHomMatrix & getTransformation() const
data read access
virtual sal_uInt32 getPrimitive2DID() const override
provide unique ID
#define PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D
bool equalZero(const T &rfVal)
basegfx::B2DHomMatrix maTransformation