LCOV - code coverage report
Current view: top level - drawinglayer/source/primitive2d - textstrikeoutprimitive2d.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 61 82 74.4 %
Date: 2015-06-13 12:38:46 Functions: 7 10 70.0 %
Legend: Lines: hit not hit

          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        1080 :         BaseTextStrikeoutPrimitive2D::BaseTextStrikeoutPrimitive2D(
      37             :             const basegfx::B2DHomMatrix& rObjectTransformation,
      38             :             double fWidth,
      39             :             const basegfx::BColor& rFontColor)
      40             :         :   BufferedDecompositionPrimitive2D(),
      41             :             maObjectTransformation(rObjectTransformation),
      42             :             mfWidth(fWidth),
      43        1080 :             maFontColor(rFontColor)
      44             :         {
      45        1080 :         }
      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          47 :         Primitive2DSequence TextCharacterStrikeoutPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
      70             :         {
      71             :             // strikeout with character
      72          47 :             const OUString aSingleCharString(getStrikeoutChar());
      73          94 :             basegfx::B2DVector aScale, aTranslate;
      74             :             double fRotate, fShearX;
      75             : 
      76             :             // get decomposition
      77          47 :             getObjectTransformation().decompose(aScale, aTranslate, fRotate, fShearX);
      78             : 
      79             :             // prepare TextLayouter
      80          94 :             TextLayouterDevice aTextLayouter;
      81             : 
      82             :             aTextLayouter.setFontAttribute(
      83          47 :                 getFontAttribute(),
      84             :                 aScale.getX(),
      85             :                 aScale.getY(),
      86          94 :                 getLocale());
      87             : 
      88          47 :             const double fStrikeCharWidth(aTextLayouter.getTextWidth(aSingleCharString, 0, 1));
      89          47 :             const double fStrikeCharCount(fabs(getWidth()/fStrikeCharWidth));
      90          47 :             const sal_uInt32 nStrikeCharCount(static_cast< sal_uInt32 >(fStrikeCharCount + 0.5));
      91          94 :             std::vector<double> aDXArray(nStrikeCharCount);
      92          94 :             OUString aStrikeoutString;
      93             : 
      94         235 :             for(sal_uInt32 a(0); a < nStrikeCharCount; a++)
      95             :             {
      96         188 :                 aStrikeoutString += aSingleCharString;
      97         188 :                 aDXArray[a] = (a + 1) * fStrikeCharWidth;
      98             :             }
      99             : 
     100             :             Primitive2DReference xReference(
     101             :                 new TextSimplePortionPrimitive2D(
     102          47 :                     getObjectTransformation(),
     103             :                     aStrikeoutString,
     104             :                     0,
     105             :                     aStrikeoutString.getLength(),
     106             :                     aDXArray,
     107             :                     getFontAttribute(),
     108             :                     getLocale(),
     109          94 :                     getFontColor()));
     110             : 
     111          94 :             return Primitive2DSequence(&xReference, 1);
     112             :         }
     113             : 
     114          47 :         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          47 :             maLocale(rLocale)
     125             :         {
     126          47 :         }
     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          94 :         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        1033 :         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        1033 :             double fStrikeoutHeight(getHeight());
     161        1033 :             double fStrikeoutOffset(getOffset());
     162        1033 :             bool bDoubleLine(false);
     163             : 
     164             :             // get decomposition
     165        2066 :             basegfx::B2DVector aScale, aTranslate;
     166             :             double fRotate, fShearX;
     167        1033 :             getObjectTransformation().decompose(aScale, aTranslate, fRotate, fShearX);
     168             : 
     169             :             // set line attribute
     170        1033 :             switch(getTextStrikeout())
     171             :             {
     172             :                 default : // case primitive2d::TEXT_STRIKEOUT_SINGLE:
     173             :                 {
     174         225 :                     break;
     175             :                 }
     176             :                 case primitive2d::TEXT_STRIKEOUT_DOUBLE:
     177             :                 {
     178         612 :                     bDoubleLine = true;
     179         612 :                     break;
     180             :                 }
     181             :                 case primitive2d::TEXT_STRIKEOUT_BOLD:
     182             :                 {
     183         196 :                     fStrikeoutHeight *= 2.0;
     184         196 :                     break;
     185             :                 }
     186             :             }
     187             : 
     188        1033 :             if(bDoubleLine)
     189             :             {
     190         612 :                 fStrikeoutOffset -= 0.50 * fStrikeoutHeight;
     191         612 :                 fStrikeoutHeight *= 0.64;
     192             :             }
     193             : 
     194             :             // create base polygon and new primitive
     195        1033 :             basegfx::B2DPolygon aStrikeoutLine;
     196             : 
     197        1033 :             aStrikeoutLine.append(basegfx::B2DPoint(0.0, -fStrikeoutOffset));
     198        1033 :             aStrikeoutLine.append(basegfx::B2DPoint(getWidth(), -fStrikeoutOffset));
     199             : 
     200             :             const basegfx::B2DHomMatrix aUnscaledTransform(
     201             :                 basegfx::tools::createShearXRotateTranslateB2DHomMatrix(
     202        2066 :                     fShearX, fRotate, aTranslate));
     203             : 
     204        1033 :             aStrikeoutLine.transform(aUnscaledTransform);
     205             : 
     206             :             // add primitive
     207        2066 :             const attribute::LineAttribute aLineAttribute(getFontColor(), fStrikeoutHeight, basegfx::B2DLineJoin::NONE);
     208        2066 :             Primitive2DSequence xRetval(1);
     209        1033 :             xRetval[0] = Primitive2DReference(new PolygonStrokePrimitive2D(aStrikeoutLine, aLineAttribute));
     210             : 
     211        1033 :             if(bDoubleLine)
     212             :             {
     213             :                 // double line, create 2nd primitive with offset using TransformPrimitive based on
     214             :                 // already created NewPrimitive
     215         612 :                 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         612 :                     -aTranslate.getX(), -aTranslate.getY()));
     220         612 :                 aTransform.rotate(-fRotate);
     221             : 
     222             :                 // translate in Y by offset
     223         612 :                 aTransform.translate(0.0, -fLineDist);
     224             : 
     225             :                 // move back and rotate
     226         612 :                 aTransform.rotate(fRotate);
     227         612 :                 aTransform.translate(aTranslate.getX(), aTranslate.getY());
     228             : 
     229             :                 // add transform primitive
     230             :                 appendPrimitive2DReferenceToPrimitive2DSequence(xRetval,
     231             :                     Primitive2DReference(
     232             :                         new TransformPrimitive2D(
     233             :                             aTransform,
     234         612 :                             xRetval)));
     235             :             }
     236             : 
     237        3099 :             return xRetval;
     238             :         }
     239             : 
     240        1033 :         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        1033 :             meTextStrikeout(eTextStrikeout)
     251             :         {
     252        1033 :         }
     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        1116 :         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: */

Generated by: LCOV version 1.11