LCOV - code coverage report
Current view: top level - sdext/source/pdfimport/misc - pdfihelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 55 61 90.2 %
Date: 2014-11-03 Functions: 5 6 83.3 %
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             : 
      21             : #include "pdfihelper.hxx"
      22             : 
      23             : #include <rtl/ustrbuf.hxx>
      24             : #include <basegfx/numeric/ftools.hxx>
      25             : 
      26             : #include <math.h>
      27             : 
      28             : using namespace pdfi;
      29             : using namespace com::sun::star;
      30             : 
      31           8 : double pdfi::GetAverageTransformationScale(const basegfx::B2DHomMatrix& matrix)
      32             : {
      33             :     double rotate, shearX;
      34          16 :     basegfx::B2DTuple scale, translation;
      35           8 :     matrix.decompose(scale, translation, rotate, shearX);
      36          16 :     return (fabs(scale.getX()) + fabs(scale.getY())) / 2.0;
      37             : }
      38             : 
      39           4 : void pdfi::FillDashStyleProps(PropertyMap& props, const std::vector<double>& dashArray, double scale)
      40             : {
      41           4 :     size_t pairCount = dashArray.size() / 2;
      42             : 
      43           4 :     double distance = 0.0;
      44          12 :     for (size_t i = 0; i < pairCount; i++)
      45           8 :         distance += dashArray[i * 2 + 1];
      46           4 :     distance /= pairCount;
      47             : 
      48           4 :     props["draw:style"] = "rect";
      49           4 :     props["draw:distance"] = convertPixelToUnitString(distance * scale);
      50             : 
      51           4 :     int dotStage = 0;
      52           4 :     int dotCounts[3] = {0, 0, 0};
      53           4 :     double dotLengths[3] = {0.0, 0.0, 0.0};
      54             : 
      55          12 :     for (size_t i = 0; i < pairCount; i++)
      56             :     {
      57           8 :         if (dotLengths[dotStage] != dashArray[i * 2])
      58             :         {
      59           4 :             dotStage++;
      60           4 :             if (dotStage == 3)
      61           0 :                 break;
      62             : 
      63           4 :             dotCounts[dotStage] = 1;
      64           4 :             dotLengths[dotStage] = dashArray[i * 2];
      65             :         }
      66             :         else
      67             :         {
      68           4 :             dotCounts[dotStage]++;
      69             :         }
      70             :     }
      71             : 
      72          12 :     for (int i = 1; i < 3; i++)
      73             :     {
      74           8 :         if (dotCounts[i] == 0)
      75           4 :             continue;
      76           4 :         props["draw:dots" + OUString::number(i)] = OUString::number(dotCounts[i]);
      77           8 :         props["draw:dots" + OUString::number(i) + "-length"] =
      78           8 :             convertPixelToUnitString(dotLengths[i] * scale);
      79             :     }
      80           4 : }
      81             : 
      82         242 : OUString pdfi::getColorString( const rendering::ARGBColor& rCol )
      83             : {
      84         242 :     OUStringBuffer aBuf( 7 );
      85         242 :     const sal_uInt8 nRed  ( sal::static_int_cast<sal_Int8>( basegfx::fround( rCol.Red * 255.0 ) ) );
      86         242 :     const sal_uInt8 nGreen( sal::static_int_cast<sal_Int8>( basegfx::fround( rCol.Green * 255.0 ) ) );
      87         242 :     const sal_uInt8 nBlue ( sal::static_int_cast<sal_Int8>( basegfx::fround( rCol.Blue * 255.0 ) ) );
      88         242 :     aBuf.append( '#' );
      89         242 :     if( nRed < 16 )
      90         238 :         aBuf.append( '0' );
      91         242 :     aBuf.append( sal_Int32(nRed), 16 );
      92         242 :     if( nGreen < 16 )
      93         238 :         aBuf.append( '0' );
      94         242 :     aBuf.append( sal_Int32(nGreen), 16 );
      95         242 :     if( nBlue < 16 )
      96         204 :         aBuf.append( '0' );
      97         242 :     aBuf.append( sal_Int32(nBlue), 16 );
      98             : 
      99         242 :     return aBuf.makeStringAndClear();
     100             : }
     101             : 
     102           0 : OUString pdfi::getPercentString(double value)
     103             : {
     104           0 :     OUStringBuffer buf(32);
     105           0 :     buf.append(value);
     106           0 :     buf.appendAscii("%");
     107           0 :     return buf.makeStringAndClear();
     108             : }
     109             : 
     110          24 : OUString pdfi::unitMMString( double fMM )
     111             : {
     112          24 :     OUStringBuffer aBuf( 32 );
     113          24 :     aBuf.append( rtl_math_round( fMM, 2, rtl_math_RoundingMode_Floor ) );
     114          24 :     aBuf.appendAscii( "mm" );
     115             : 
     116          24 :     return aBuf.makeStringAndClear();
     117             : }
     118             : 
     119         376 : OUString pdfi::convertPixelToUnitString( double fPix )
     120             : {
     121         376 :     OUStringBuffer aBuf( 32 );
     122         376 :     aBuf.append( rtl_math_round( convPx2mm( fPix ), 2, rtl_math_RoundingMode_Floor ) );
     123         376 :     aBuf.appendAscii( "mm" );
     124             : 
     125         376 :     return aBuf.makeStringAndClear();
     126             : }
     127             : 
     128             : 
     129             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10