LCOV - code coverage report
Current view: top level - writerfilter/source/dmapper - WrapPolygonHandler.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 70 75 93.3 %
Date: 2015-06-13 12:38:46 Functions: 14 17 82.4 %
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 <com/sun/star/drawing/PointSequence.hpp>
      21             : #include <comphelper/sequence.hxx>
      22             : 
      23             : #include <ooxml/resourceids.hxx>
      24             : 
      25             : #include "ConversionHelper.hxx"
      26             : #include "WrapPolygonHandler.hxx"
      27             : #include "util.hxx"
      28             : 
      29             : namespace writerfilter {
      30             : 
      31             : using namespace com::sun::star;
      32             : 
      33             : namespace dmapper {
      34             : 
      35          63 : WrapPolygon::WrapPolygon()
      36             : {
      37          63 : }
      38             : 
      39         126 : WrapPolygon::~WrapPolygon()
      40             : {
      41         126 : }
      42             : 
      43         620 : void WrapPolygon::addPoint(const awt::Point & rPoint)
      44             : {
      45         620 :     mPoints.push_back(rPoint);
      46         620 : }
      47             : 
      48           0 : WrapPolygon::Points_t::const_iterator WrapPolygon::begin() const
      49             : {
      50           0 :     return mPoints.begin();
      51             : }
      52             : 
      53           0 : WrapPolygon::Points_t::const_iterator WrapPolygon::end() const
      54             : {
      55           0 :     return mPoints.end();
      56             : }
      57             : 
      58          30 : WrapPolygon::Points_t::iterator WrapPolygon::begin()
      59             : {
      60          30 :     return mPoints.begin();
      61             : }
      62             : 
      63          30 : WrapPolygon::Points_t::iterator WrapPolygon::end()
      64             : {
      65          30 :     return mPoints.end();
      66             : }
      67             : 
      68          10 : WrapPolygon::Pointer_t WrapPolygon::move(const awt::Point & rPoint)
      69             : {
      70          10 :     WrapPolygon::Pointer_t pResult(new WrapPolygon);
      71             : 
      72          10 :     Points_t::iterator aIt = begin();
      73          10 :     Points_t::iterator aItEnd = end();
      74             : 
      75         106 :     while (aIt != aItEnd)
      76             :     {
      77          86 :         awt::Point aPoint(aIt->X + rPoint.X, aIt->Y + rPoint.Y);
      78          86 :         pResult->addPoint(aPoint);
      79          86 :         ++aIt;
      80             :     }
      81             : 
      82          10 :     return pResult;
      83             : }
      84             : 
      85          20 : WrapPolygon::Pointer_t WrapPolygon::scale(const Fraction & rFractionX, const Fraction & rFractionY)
      86             : {
      87          20 :     WrapPolygon::Pointer_t pResult(new WrapPolygon);
      88             : 
      89          20 :     Points_t::iterator aIt = begin();
      90          20 :     Points_t::iterator aItEnd = end();
      91             : 
      92         212 :     while (aIt != aItEnd)
      93             :     {
      94         172 :         awt::Point aPoint((Fraction(long(aIt->X)) * rFractionX).operator long(), (Fraction(long(aIt->Y)) * rFractionY).operator long());
      95         172 :         pResult->addPoint(aPoint);
      96         172 :         ++aIt;
      97             :     }
      98             : 
      99          20 :     return pResult;
     100             : }
     101             : 
     102          10 : WrapPolygon::Pointer_t WrapPolygon::correctWordWrapPolygon(const awt::Size & rSrcSize)
     103             : {
     104          10 :     WrapPolygon::Pointer_t pResult;
     105             : 
     106          10 :     const long nWrap100Percent = 21600;
     107             : 
     108          20 :     Fraction aMove(nWrap100Percent, rSrcSize.Width);
     109          10 :     aMove = aMove * Fraction(15, 1);
     110          10 :     awt::Point aMovePoint(aMove.operator long(), 0);
     111          10 :     pResult = move(aMovePoint);
     112             : 
     113          20 :     Fraction aScaleX(nWrap100Percent, Fraction(nWrap100Percent) + aMove);
     114          20 :     Fraction aScaleY(nWrap100Percent, Fraction(nWrap100Percent) - aMove);
     115          10 :     pResult = pResult->scale(aScaleX, aScaleY);
     116             : 
     117          20 :     Fraction aScaleSrcX(rSrcSize.Width, nWrap100Percent);
     118          20 :     Fraction aScaleSrcY(rSrcSize.Height, nWrap100Percent);
     119          10 :     pResult = pResult->scale(aScaleSrcX, aScaleSrcY);
     120             : 
     121          20 :     return pResult;
     122             : }
     123             : 
     124          43 : drawing::PointSequenceSequence WrapPolygon::getPointSequenceSequence() const
     125             : {
     126          43 :     drawing::PointSequenceSequence aPolyPolygon(1L);
     127          86 :     drawing::PointSequence aPolygon = comphelper::containerToSequence(mPoints);
     128          43 :     aPolyPolygon[0] = aPolygon;
     129          86 :     return aPolyPolygon;
     130             : }
     131             : 
     132          33 : WrapPolygonHandler::WrapPolygonHandler()
     133             :     : LoggedProperties("WrapPolygonHandler")
     134          33 :     , mpPolygon(new WrapPolygon)
     135             :     , mnX(0)
     136          66 :     , mnY(0)
     137             : {
     138          33 : }
     139             : 
     140          33 : WrapPolygonHandler::~WrapPolygonHandler()
     141             : {
     142          33 : }
     143             : 
     144         754 : void WrapPolygonHandler::lcl_attribute(Id Name, Value & val)
     145             : {
     146         754 :     sal_Int32 nIntValue = val.getInt();
     147             : 
     148         754 :     switch(Name)
     149             :     {
     150             :     case NS_ooxml::LN_CT_Point2D_x:
     151         362 :         mnX = nIntValue;
     152         362 :         break;
     153             :     case NS_ooxml::LN_CT_Point2D_y:
     154         362 :         mnY = nIntValue;
     155         362 :         break;
     156             :     default:
     157             :         SAL_WARN("writerfilter", "WrapPolygonHandler::lcl_attribute: unhandled token: " << Name);
     158          30 :         break;
     159             :     }
     160         754 : }
     161             : 
     162         362 : void WrapPolygonHandler::lcl_sprm(Sprm & _sprm)
     163             : {
     164         362 :     switch (_sprm.getId())
     165             :     {
     166             :     case NS_ooxml::LN_CT_WrapPath_lineTo:
     167             :     case NS_ooxml::LN_CT_WrapPath_start:
     168             :         {
     169         362 :             resolveSprmProps(*this, _sprm);
     170             : 
     171         362 :             awt::Point aPoint(mnX, mnY);
     172         362 :             mpPolygon->addPoint(aPoint);
     173             :         }
     174         362 :         break;
     175             :     default:
     176             :         SAL_WARN("writerfilter", "WrapPolygonHandler::lcl_sprm: unhandled token: " << _sprm.getId());
     177           0 :         break;
     178             :     }
     179         362 : }
     180             : 
     181             : 
     182             : }}
     183             : 
     184             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11