calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / drawinglayer / source / primitive2d / wrongspellprimitive2d.cxx
blob8ce5948d969acdd8f39e9c37fa9b6a4b6ae83eaa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <drawinglayer/primitive2d/wrongspellprimitive2d.hxx>
21 #include <basegfx/polygon/b2dpolygon.hxx>
22 #include <drawinglayer/primitive2d/PolygonWavePrimitive2D.hxx>
23 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
24 #include <drawinglayer/geometry/viewinformation2d.hxx>
25 #include <utility>
28 namespace drawinglayer::primitive2d
30 void WrongSpellPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*rViewInformation*/) const
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.
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);
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);
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;
61 aPolygon.append(getTransformation() * aStart);
62 aPolygon.append(getTransformation() * aStop);
64 // prepare line attribute
65 const attribute::LineAttribute aLineAttribute(getColor());
67 // create the waveline primitive
68 rContainer.push_back(new PolygonWavePrimitive2D(aPolygon, aLineAttribute, fWaveWidth, 0.5 * fWaveWidth));
71 WrongSpellPrimitive2D::WrongSpellPrimitive2D(
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)
83 bool WrongSpellPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
85 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
87 const WrongSpellPrimitive2D& rCompare = static_cast<const WrongSpellPrimitive2D&>(rPrimitive);
89 return (getTransformation() == rCompare.getTransformation()
90 && getStart() == rCompare.getStart()
91 && getStop() == rCompare.getStop()
92 && getColor() == rCompare.getColor());
95 return false;
98 // provide unique ID
99 sal_uInt32 WrongSpellPrimitive2D::getPrimitive2DID() const
101 return PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D;
104 } // end of namespace
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */