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