LCOV - code coverage report
Current view: top level - drawinglayer/source/primitive2d - textlineprimitive2d.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 57 110 51.8 %
Date: 2012-08-25 Functions: 3 4 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 52 131 39.7 %

           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/textlineprimitive2d.hxx>
      21                 :            : #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
      22                 :            : #include <drawinglayer/attribute/strokeattribute.hxx>
      23                 :            : #include <drawinglayer/attribute/lineattribute.hxx>
      24                 :            : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      25                 :            : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
      26                 :            : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
      27                 :            : 
      28                 :            : //////////////////////////////////////////////////////////////////////////////
      29                 :            : 
      30                 :            : namespace drawinglayer
      31                 :            : {
      32                 :            :     namespace primitive2d
      33                 :            :     {
      34                 :       4218 :         Primitive2DSequence TextLinePrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
      35                 :            :         {
      36                 :       4218 :             Primitive2DSequence xRetval;
      37                 :            : 
      38         [ +  - ]:       4218 :             if(TEXT_LINE_NONE != getTextLine())
      39                 :            :             {
      40                 :       4218 :                 bool bDoubleLine(false);
      41                 :       4218 :                 bool bWaveLine(false);
      42                 :       4218 :                 bool bBoldLine(false);
      43                 :       4218 :                 const int* pDotDashArray(0);
      44                 :       4218 :                 basegfx::B2DLineJoin eLineJoin(basegfx::B2DLINEJOIN_NONE);
      45                 :       4218 :                 double fOffset(getOffset());
      46                 :       4218 :                 double fHeight(getHeight());
      47                 :            : 
      48                 :            :                 static const int aDottedArray[]     = { 1, 1, 0};               // DOTTED LINE
      49                 :            :                 static const int aDotDashArray[]    = { 1, 1, 4, 1, 0};         // DASHDOT
      50                 :            :                 static const int aDashDotDotArray[] = { 1, 1, 1, 1, 4, 1, 0};   // DASHDOTDOT
      51                 :            :                 static const int aDashedArray[]     = { 5, 2, 0};               // DASHED LINE
      52                 :            :                 static const int aLongDashArray[]   = { 7, 2, 0};               // LONGDASH
      53                 :            : 
      54                 :            :                 // get decomposition
      55                 :       4218 :                 basegfx::B2DVector aScale, aTranslate;
      56                 :            :                 double fRotate, fShearX;
      57         [ +  - ]:       4218 :                 getObjectTransformation().decompose(aScale, aTranslate, fRotate, fShearX);
      58                 :            : 
      59   [ +  +  +  +  :       4218 :                 switch(getTextLine())
          -  -  -  -  -  
          -  -  -  -  -  
                -  -  - ]
      60                 :            :                 {
      61                 :            :                     default: // case TEXT_LINE_SINGLE:
      62                 :            :                     {
      63                 :       2157 :                         break;
      64                 :            :                     }
      65                 :            :                     case TEXT_LINE_DOUBLE:
      66                 :            :                     {
      67                 :       1333 :                         bDoubleLine = true;
      68                 :       1333 :                         break;
      69                 :            :                     }
      70                 :            :                     case TEXT_LINE_DOTTED:
      71                 :            :                     {
      72                 :        660 :                         pDotDashArray = aDottedArray;
      73                 :        660 :                         break;
      74                 :            :                     }
      75                 :            :                     case TEXT_LINE_DASH:
      76                 :            :                     {
      77                 :         68 :                         pDotDashArray = aDashedArray;
      78                 :         68 :                         break;
      79                 :            :                     }
      80                 :            :                     case TEXT_LINE_LONGDASH:
      81                 :            :                     {
      82                 :          0 :                         pDotDashArray = aLongDashArray;
      83                 :          0 :                         break;
      84                 :            :                     }
      85                 :            :                     case TEXT_LINE_DASHDOT:
      86                 :            :                     {
      87                 :          0 :                         pDotDashArray = aDotDashArray;
      88                 :          0 :                         break;
      89                 :            :                     }
      90                 :            :                     case TEXT_LINE_DASHDOTDOT:
      91                 :            :                     {
      92                 :          0 :                         pDotDashArray = aDashDotDotArray;
      93                 :          0 :                         break;
      94                 :            :                     }
      95                 :            :                     case TEXT_LINE_SMALLWAVE:
      96                 :            :                     {
      97                 :          0 :                         bWaveLine = true;
      98                 :          0 :                         break;
      99                 :            :                     }
     100                 :            :                     case TEXT_LINE_WAVE:
     101                 :            :                     {
     102                 :          0 :                         bWaveLine = true;
     103                 :          0 :                         break;
     104                 :            :                     }
     105                 :            :                     case TEXT_LINE_DOUBLEWAVE:
     106                 :            :                     {
     107                 :          0 :                         bDoubleLine = true;
     108                 :          0 :                         bWaveLine = true;
     109                 :          0 :                         break;
     110                 :            :                     }
     111                 :            :                     case TEXT_LINE_BOLD:
     112                 :            :                     {
     113                 :          0 :                         bBoldLine = true;
     114                 :          0 :                         break;
     115                 :            :                     }
     116                 :            :                     case TEXT_LINE_BOLDDOTTED:
     117                 :            :                     {
     118                 :          0 :                         bBoldLine = true;
     119                 :          0 :                         pDotDashArray = aDottedArray;
     120                 :          0 :                         break;
     121                 :            :                     }
     122                 :            :                     case TEXT_LINE_BOLDDASH:
     123                 :            :                     {
     124                 :          0 :                         bBoldLine = true;
     125                 :          0 :                         pDotDashArray = aDashedArray;
     126                 :          0 :                         break;
     127                 :            :                     }
     128                 :            :                     case TEXT_LINE_BOLDLONGDASH:
     129                 :            :                     {
     130                 :          0 :                         bBoldLine = true;
     131                 :          0 :                         pDotDashArray = aLongDashArray;
     132                 :          0 :                         break;
     133                 :            :                     }
     134                 :            :                     case TEXT_LINE_BOLDDASHDOT:
     135                 :            :                     {
     136                 :          0 :                         bBoldLine = true;
     137                 :          0 :                         pDotDashArray = aDotDashArray;
     138                 :          0 :                         break;
     139                 :            :                     }
     140                 :            :                     case TEXT_LINE_BOLDDASHDOTDOT:
     141                 :            :                     {
     142                 :          0 :                         bBoldLine = true;
     143                 :          0 :                         pDotDashArray = aDashDotDotArray;
     144                 :          0 :                         break;
     145                 :            :                     }
     146                 :            :                     case TEXT_LINE_BOLDWAVE:
     147                 :            :                     {
     148                 :          0 :                         bWaveLine = true;
     149                 :          0 :                         bBoldLine = true;
     150                 :          0 :                         break;
     151                 :            :                     }
     152                 :            :                 }
     153                 :            : 
     154         [ -  + ]:       4218 :                 if(bBoldLine)
     155                 :            :                 {
     156                 :          0 :                     fHeight *= 2.0;
     157                 :            :                 }
     158                 :            : 
     159         [ +  + ]:       4218 :                 if(bDoubleLine)
     160                 :            :                 {
     161                 :       1333 :                     fOffset -= 0.50 * fHeight;
     162                 :       1333 :                     fHeight *= 0.64;
     163                 :            :                 }
     164                 :            : 
     165         [ -  + ]:       4218 :                 if(bWaveLine)
     166                 :            :                 {
     167                 :          0 :                     eLineJoin = basegfx::B2DLINEJOIN_ROUND;
     168                 :          0 :                     fHeight *= 0.25;
     169                 :            :                 }
     170                 :            : 
     171                 :            :                 // prepare Line and Stroke Attributes
     172         [ +  - ]:       4218 :                 const attribute::LineAttribute aLineAttribute(getLineColor(), fHeight, eLineJoin);
     173         [ +  - ]:       4218 :                 attribute::StrokeAttribute aStrokeAttribute;
     174                 :            : 
     175         [ +  + ]:       4218 :                 if(pDotDashArray)
     176                 :            :                 {
     177         [ +  - ]:        728 :                     ::std::vector< double > aDoubleArray;
     178                 :            : 
     179         [ +  + ]:       2184 :                     for(const int* p = pDotDashArray; *p; ++p)
     180                 :            :                     {
     181         [ +  - ]:       1456 :                         aDoubleArray.push_back((double)(*p) * fHeight);
     182                 :            :                     }
     183                 :            : 
     184 [ +  - ][ +  - ]:        728 :                     aStrokeAttribute = attribute::StrokeAttribute(aDoubleArray);
                 [ +  - ]
     185                 :            :                 }
     186                 :            : 
     187                 :            :                 // create base polygon and new primitive
     188         [ +  - ]:       4218 :                 basegfx::B2DPolygon aLine;
     189                 :       4218 :                 Primitive2DReference aNewPrimitive;
     190                 :            : 
     191         [ +  - ]:       4218 :                 aLine.append(basegfx::B2DPoint(0.0, fOffset));
     192         [ +  - ]:       4218 :                 aLine.append(basegfx::B2DPoint(getWidth(), fOffset));
     193                 :            : 
     194                 :            :                 const basegfx::B2DHomMatrix aUnscaledTransform(
     195                 :            :                     basegfx::tools::createShearXRotateTranslateB2DHomMatrix(
     196         [ +  - ]:       4218 :                         fShearX, fRotate, aTranslate));
     197                 :            : 
     198         [ +  - ]:       4218 :                 aLine.transform(aUnscaledTransform);
     199                 :            : 
     200         [ -  + ]:       4218 :                 if(bWaveLine)
     201                 :            :                 {
     202                 :          0 :                     double fWaveWidth(10.6 * fHeight);
     203                 :            : 
     204         [ #  # ]:          0 :                     if(TEXT_LINE_SMALLWAVE == getTextLine())
     205                 :            :                     {
     206                 :          0 :                         fWaveWidth *= 0.7;
     207                 :            :                     }
     208         [ #  # ]:          0 :                     else if(TEXT_LINE_WAVE == getTextLine())
     209                 :            :                     {
     210                 :            :                         // extra multiply to get the same WaveWidth as with the bold version
     211                 :          0 :                         fWaveWidth *= 2.0;
     212                 :            :                     }
     213                 :            : 
     214 [ #  # ][ #  # ]:          0 :                     aNewPrimitive = Primitive2DReference(new PolygonWavePrimitive2D(aLine, aLineAttribute, aStrokeAttribute, fWaveWidth, fWaveWidth * 0.5));
         [ #  # ][ #  # ]
     215                 :            :                 }
     216                 :            :                 else
     217                 :            :                 {
     218 [ +  - ][ +  - ]:       4218 :                     aNewPrimitive = Primitive2DReference(new PolygonStrokePrimitive2D(aLine, aLineAttribute, aStrokeAttribute));
         [ +  - ][ +  - ]
     219                 :            :                 }
     220                 :            : 
     221                 :            :                 // add primitive
     222         [ +  - ]:       4218 :                 appendPrimitive2DReferenceToPrimitive2DSequence(xRetval, aNewPrimitive);
     223                 :            : 
     224         [ +  + ]:       4218 :                 if(bDoubleLine)
     225                 :            :                 {
     226                 :            :                     // double line, create 2nd primitive with offset using TransformPrimitive based on
     227                 :            :                     // already created NewPrimitive
     228                 :       1333 :                     double fLineDist(2.3 * fHeight);
     229                 :            : 
     230         [ -  + ]:       1333 :                     if(bWaveLine)
     231                 :            :                     {
     232                 :          0 :                         fLineDist = 6.3 * fHeight;
     233                 :            :                     }
     234                 :            : 
     235                 :            :                     // move base point of text to 0.0 and de-rotate
     236                 :            :                     basegfx::B2DHomMatrix aTransform(basegfx::tools::createTranslateB2DHomMatrix(
     237         [ +  - ]:       1333 :                         -aTranslate.getX(), -aTranslate.getY()));
     238         [ +  - ]:       1333 :                     aTransform.rotate(-fRotate);
     239                 :            : 
     240                 :            :                     // translate in Y by offset
     241         [ +  - ]:       1333 :                     aTransform.translate(0.0, fLineDist);
     242                 :            : 
     243                 :            :                     // move back and rotate
     244         [ +  - ]:       1333 :                     aTransform.rotate(fRotate);
     245         [ +  - ]:       1333 :                     aTransform.translate(aTranslate.getX(), aTranslate.getY());
     246                 :            : 
     247                 :            :                     // add transform primitive
     248         [ +  - ]:       1333 :                     const Primitive2DSequence aContent(&aNewPrimitive, 1);
     249                 :            :                     appendPrimitive2DReferenceToPrimitive2DSequence(xRetval,
     250 [ +  - ][ +  - ]:       1333 :                         Primitive2DReference(new TransformPrimitive2D(aTransform, aContent)));
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     251 [ +  - ][ +  - ]:       4218 :                 }
         [ +  - ][ +  - ]
     252                 :            :             }
     253                 :            : 
     254                 :       4218 :             return xRetval;
     255                 :            :         }
     256                 :            : 
     257                 :       4218 :         TextLinePrimitive2D::TextLinePrimitive2D(
     258                 :            :             const basegfx::B2DHomMatrix& rObjectTransformation,
     259                 :            :             double fWidth,
     260                 :            :             double fOffset,
     261                 :            :             double fHeight,
     262                 :            :             TextLine eTextLine,
     263                 :            :             const basegfx::BColor& rLineColor)
     264                 :            :         :   BufferedDecompositionPrimitive2D(),
     265                 :            :             maObjectTransformation(rObjectTransformation),
     266                 :            :             mfWidth(fWidth),
     267                 :            :             mfOffset(fOffset),
     268                 :            :             mfHeight(fHeight),
     269                 :            :             meTextLine(eTextLine),
     270         [ +  - ]:       4218 :             maLineColor(rLineColor)
     271                 :            :         {
     272                 :       4218 :         }
     273                 :            : 
     274                 :          0 :         bool TextLinePrimitive2D::operator==( const BasePrimitive2D& rPrimitive ) const
     275                 :            :         {
     276         [ #  # ]:          0 :             if(BufferedDecompositionPrimitive2D::operator==(rPrimitive))
     277                 :            :             {
     278                 :          0 :                 const TextLinePrimitive2D& rCompare = (TextLinePrimitive2D&)rPrimitive;
     279                 :            : 
     280                 :          0 :                 return (getObjectTransformation() == rCompare.getObjectTransformation()
     281                 :          0 :                     && getWidth() == rCompare.getWidth()
     282                 :          0 :                     && getOffset() == rCompare.getOffset()
     283                 :          0 :                     && getHeight() == rCompare.getHeight()
     284                 :          0 :                     && getTextLine() == rCompare.getTextLine()
     285 [ #  # ][ #  #  :          0 :                     && getLineColor() == rCompare.getLineColor());
          #  #  #  #  #  
                #  #  # ]
     286                 :            :             }
     287                 :            : 
     288                 :          0 :             return false;
     289                 :            :         }
     290                 :            : 
     291                 :            :         // provide unique ID
     292                 :       2764 :         ImplPrimitrive2DIDBlock(TextLinePrimitive2D, PRIMITIVE2D_ID_TEXTLINEPRIMITIVE2D)
     293                 :            : 
     294                 :            :     } // end of namespace primitive2d
     295                 :            : } // end of namespace drawinglayer
     296                 :            : 
     297                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10