LCOV - code coverage report
Current view: top level - drawinglayer/source/primitive2d - textstrikeoutprimitive2d.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 62 83 74.7 %
Date: 2012-08-25 Functions: 7 10 70.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 55 125 44.0 %

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