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/wrongspellprimitive2d.hxx> 21 #include <basegfx/polygon/b2dpolygon.hxx> 22 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 23 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> 24 #include <drawinglayer/geometry/viewinformation2d.hxx> 25 26 27 namespace drawinglayer::primitive2d 28 { create2DDecomposition(Primitive2DContainer & rContainer,const geometry::ViewInformation2D &) const29 void WrongSpellPrimitive2D::create2DDecomposition(Primitive2DContainer& rContainer, const geometry::ViewInformation2D& /*rViewInformation*/) const 30 { 31 // ATM this decompose is view-independent, what the original VCL-Display is not. To mimic 32 // the old behaviour here if wanted it is necessary to add get2DDecomposition and implement 33 // it similar to the usage in e.g. HelplinePrimitive2D. Remembering the ViewTransformation 34 // should be enough then. 35 // The view-independent wavelines work well (if You ask me). Maybe the old VCL-Behaviour is only 36 // in place because it was not possible/too expensive at that time to scale the wavelines with the 37 // view... 38 // With the VCL-PixelRenderer this will not even be used since it implements WrongSpellPrimitive2D 39 // directly and mimics the old VCL-Display there. If You implemented a new renderer without 40 // direct WrongSpellPrimitive2D support, You may want to do the described change here. 41 42 // get the font height (part of scale), so decompose the matrix 43 basegfx::B2DVector aScale, aTranslate; 44 double fRotate, fShearX; 45 getTransformation().decompose(aScale, aTranslate, fRotate, fShearX); 46 47 // calculate distances based on a static default (to allow testing in debugger) 48 static const double fDefaultDistance(0.03); 49 const double fFontHeight(aScale.getY()); 50 const double fUnderlineDistance(fFontHeight * fDefaultDistance); 51 const double fWaveWidth(2.0 * fUnderlineDistance); 52 53 // the Y-distance needs to be relative to FontHeight since the points get 54 // transformed with the transformation containing that scale already. 55 const double fRelativeUnderlineDistance(basegfx::fTools::equalZero(aScale.getY()) ? 0.0 : fUnderlineDistance / aScale.getY()); 56 basegfx::B2DPoint aStart(getStart(), fRelativeUnderlineDistance); 57 basegfx::B2DPoint aStop(getStop(), fRelativeUnderlineDistance); 58 basegfx::B2DPolygon aPolygon; 59 60 aPolygon.append(getTransformation() * aStart); 61 aPolygon.append(getTransformation() * aStop); 62 63 // prepare line attribute 64 const attribute::LineAttribute aLineAttribute(getColor()); 65 66 // create the waveline primitive 67 rContainer.push_back(new PolygonWavePrimitive2D(aPolygon, aLineAttribute, fWaveWidth, 0.5 * fWaveWidth)); 68 } 69 WrongSpellPrimitive2D(const basegfx::B2DHomMatrix & rTransformation,double fStart,double fStop,const basegfx::BColor & rColor)70 WrongSpellPrimitive2D::WrongSpellPrimitive2D( 71 const basegfx::B2DHomMatrix& rTransformation, 72 double fStart, 73 double fStop, 74 const basegfx::BColor& rColor) 75 : BufferedDecompositionPrimitive2D(), 76 maTransformation(rTransformation), 77 mfStart(fStart), 78 mfStop(fStop), 79 maColor(rColor) 80 { 81 } 82 operator ==(const BasePrimitive2D & rPrimitive) const83 bool WrongSpellPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 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 99 ImplPrimitive2DIDBlock(WrongSpellPrimitive2D, PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D) 100 101 } // end of namespace 102 103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 104