LCOV - code coverage report
Current view: top level - sdext/source/pdfimport/inc - pdfihelper.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 75 79 94.9 %
Date: 2015-06-13 12:38:46 Functions: 13 13 100.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             : #ifndef INCLUDED_SDEXT_SOURCE_PDFIMPORT_INC_PDFIHELPER_HXX
      21             : #define INCLUDED_SDEXT_SOURCE_PDFIMPORT_INC_PDFIHELPER_HXX
      22             : 
      23             : #include "contentsink.hxx"
      24             : 
      25             : #include <rtl/ustring.hxx>
      26             : #include <rtl/math.h>
      27             : #include <basegfx/matrix/b2dhommatrix.hxx>
      28             : #include <basegfx/polygon/b2dpolypolygon.hxx>
      29             : #include <basegfx/polygon/b2dpolygon.hxx>
      30             : #include <com/sun/star/rendering/XColorSpace.hpp>
      31             : #include "com/sun/star/rendering/PathCapType.hpp"
      32             : #include "com/sun/star/rendering/PathJoinType.hpp"
      33             : 
      34             : #include <unordered_map>
      35             : #include <vector>
      36             : #include <boost/functional/hash.hpp>
      37             : 
      38             : // virtual resolution of the PDF OutputDev in dpi
      39             : #define PDFI_OUTDEV_RESOLUTION 7200
      40             : 
      41             : namespace com { namespace sun { namespace star { namespace task
      42             : { class XInteractionHandler; }}}}
      43             : 
      44             : namespace pdfi
      45             : {
      46             :     typedef std::unordered_map< OUString, OUString, OUStringHash > PropertyMap;
      47             :     typedef sal_Int32 ImageId;
      48             : 
      49             :     /// What to do with a polygon. values can be ORed together
      50             :     enum PolygonAction { PATH_STROKE=1, PATH_FILL=2, PATH_EOFILL=4 };
      51             : 
      52             :     OUString unitMMString( double fMM );
      53             :     OUString convertPixelToUnitString( double fPix );
      54             : 
      55         299 :     inline double convPx2mm( double fPix )
      56             :     {
      57         299 :         const double px2mm = 25.4/PDFI_OUTDEV_RESOLUTION;
      58         299 :         fPix *= px2mm;
      59         299 :         return fPix;
      60             :     }
      61             : 
      62          16 :     inline double convmm2Px( double fMM )
      63             :     {
      64          16 :         const double mm2px = PDFI_OUTDEV_RESOLUTION/25.4;
      65          16 :         fMM *= mm2px;
      66          16 :         return fMM;
      67             :     }
      68             : 
      69         120 :     inline double convPx2mmPrec2( double fPix )
      70             :     {
      71         120 :         return rtl_math_round( convPx2mm( fPix ), 2, rtl_math_RoundingMode_Floor );
      72             :     }
      73             : 
      74             :     /// Convert color to "#FEFEFE" color notation
      75             :     OUString getColorString( const css::rendering::ARGBColor& );
      76             :     OUString getPercentString(double value);
      77             : 
      78             :     double GetAverageTransformationScale(const basegfx::B2DHomMatrix& matrix);
      79             :     void FillDashStyleProps(PropertyMap& props, const std::vector<double>& dashArray, double scale);
      80             : 
      81             :     struct FontAttrHash
      82             :     {
      83          53 :         size_t operator()(const FontAttributes& rFont ) const
      84             :         {
      85          53 :             return (size_t)rFont.familyName.hashCode()
      86          53 :                 ^  size_t(rFont.isBold ? 0xd47be593 : 0)
      87          53 :                 ^  size_t(rFont.isItalic ? 0x1efd51a1 : 0)
      88          53 :                 ^  size_t(rFont.isUnderline ? 0xf6bd325a : 0)
      89          53 :                 ^  size_t(rFont.isOutline ?  0x12345678 : 0)
      90          53 :                 ^  size_t(rFont.size)
      91             :                 ;
      92             :         }
      93             :     };
      94             : 
      95        2995 :     struct GraphicsContext
      96             :     {
      97             :         css::rendering::ARGBColor     LineColor;
      98             :         css::rendering::ARGBColor     FillColor;
      99             :         sal_Int8                                   LineJoin;
     100             :         sal_Int8                                   LineCap;
     101             :         sal_Int8                                   BlendMode;
     102             :         double                                     Flatness;
     103             :         double                                     LineWidth;
     104             :         double                                     MiterLimit;
     105             :         std::vector<double>                        DashArray;
     106             :         sal_Int32                                  FontId;
     107             :         sal_Int32                                  TextRenderMode;
     108             :         basegfx::B2DHomMatrix                      Transformation;
     109             :         basegfx::B2DPolyPolygon                    Clip;
     110             : 
     111         308 :         GraphicsContext() :
     112             :             LineColor(),
     113             :             FillColor(),
     114             :             LineJoin(0),
     115             :             LineCap(0),
     116             :             BlendMode(0),
     117             :             Flatness(0.0),
     118             :             LineWidth(1.0),
     119             :             MiterLimit(10.0),
     120             :             DashArray(),
     121             :             FontId(0),
     122             :             TextRenderMode(0),
     123             :             Transformation(),
     124         308 :             Clip()
     125         308 :         {}
     126             : 
     127          24 :         bool operator==(const GraphicsContext& rRight ) const
     128             :         {
     129          48 :             return LineColor.Red == rRight.LineColor.Red &&
     130          48 :                 LineColor.Green == rRight.LineColor.Green &&
     131          48 :                 LineColor.Blue == rRight.LineColor.Blue &&
     132          48 :                 LineColor.Alpha == rRight.LineColor.Alpha &&
     133          48 :                 FillColor.Red == rRight.FillColor.Red &&
     134          48 :                 FillColor.Green == rRight.FillColor.Green &&
     135          48 :                 FillColor.Blue == rRight.FillColor.Blue &&
     136          48 :                 FillColor.Alpha == rRight.FillColor.Alpha &&
     137          48 :                 LineJoin  == rRight.LineJoin &&
     138          48 :                 LineCap   == rRight.LineCap &&
     139          48 :                 BlendMode == rRight.BlendMode &&
     140          48 :                 LineWidth == rRight.LineWidth &&
     141          48 :                 Flatness == rRight.Flatness &&
     142          48 :                 MiterLimit == rRight.MiterLimit &&
     143          48 :                 DashArray == rRight.DashArray &&
     144          48 :                 FontId    == rRight.FontId &&
     145          48 :                 TextRenderMode == rRight.TextRenderMode &&
     146          72 :                 Transformation == rRight.Transformation &&
     147          48 :                 Clip == rRight.Clip;
     148             :         }
     149             : 
     150           4 :         OUString GetLineJoinString() const
     151             :         {
     152           4 :             switch (LineJoin)
     153             :             {
     154             :             default:
     155             :             case css::rendering::PathJoinType::MITER:
     156           0 :                 return OUString("miter");
     157             :             case css::rendering::PathJoinType::ROUND:
     158           4 :                 return OUString("round");
     159             :             case css::rendering::PathJoinType::BEVEL:
     160           0 :                 return OUString("bevel");
     161             :             }
     162             :         }
     163             : 
     164           4 :         OUString GetLineCapString() const
     165             :         {
     166           4 :             switch (LineCap)
     167             :             {
     168             :             default:
     169             :             case css::rendering::PathCapType::BUTT:
     170           4 :                 return OUString("butt");
     171             :             case css::rendering::PathCapType::ROUND:
     172           0 :                 return OUString("round");
     173             :             case css::rendering::PathCapType::SQUARE:
     174           0 :                 return OUString("square");
     175             :             }
     176             :         }
     177             : 
     178         197 :         bool isRotatedOrSkewed() const
     179         394 :         { return Transformation.get( 0, 1 ) != 0.0 ||
     180         394 :                 Transformation.get( 1, 0 ) != 0.0; }
     181             :     };
     182             : 
     183             :     struct GraphicsContextHash
     184             :     {
     185         618 :         size_t operator()(const GraphicsContext& rGC ) const
     186             :         {
     187         618 :             return boost::hash_value(rGC.LineColor.Red)
     188         618 :                 ^  boost::hash_value(rGC.LineColor.Green)
     189         618 :                 ^  boost::hash_value(rGC.LineColor.Blue)
     190         618 :                 ^  boost::hash_value(rGC.LineColor.Alpha)
     191         618 :                 ^  boost::hash_value(rGC.FillColor.Red)
     192         618 :                 ^  boost::hash_value(rGC.FillColor.Green)
     193         618 :                 ^  boost::hash_value(rGC.FillColor.Blue)
     194         618 :                 ^  boost::hash_value(rGC.FillColor.Alpha)
     195         618 :                 ^  boost::hash_value(rGC.LineJoin)
     196         618 :                 ^  boost::hash_value(rGC.LineCap)
     197         618 :                 ^  boost::hash_value(rGC.BlendMode)
     198         618 :                 ^  boost::hash_value(rGC.LineWidth)
     199         618 :                 ^  boost::hash_value(rGC.Flatness)
     200         618 :                 ^  boost::hash_value(rGC.MiterLimit)
     201         618 :                 ^  rGC.DashArray.size()
     202         618 :                 ^  boost::hash_value(rGC.FontId)
     203         618 :                 ^  boost::hash_value(rGC.TextRenderMode)
     204         618 :                 ^  boost::hash_value(rGC.Transformation.get( 0, 0 ))
     205         618 :                 ^  boost::hash_value(rGC.Transformation.get( 1, 0 ))
     206         618 :                 ^  boost::hash_value(rGC.Transformation.get( 0, 1 ))
     207         618 :                 ^  boost::hash_value(rGC.Transformation.get( 1, 1 ))
     208         618 :                 ^  boost::hash_value(rGC.Transformation.get( 0, 2 ))
     209         618 :                 ^  boost::hash_value(rGC.Transformation.get( 1, 2 ))
     210         618 :                 ^  boost::hash_value(rGC.Clip.count() ? rGC.Clip.getB2DPolygon(0).count() : 0)
     211             :                 ;
     212             :         }
     213             :     };
     214             : 
     215             :     /** retrieve password from user
     216             :      */
     217             :     bool getPassword( const css::uno::Reference<
     218             :                             css::task::XInteractionHandler >& xHandler,
     219             :                       OUString&                                       rOutPwd,
     220             :                       bool                                                 bFirstTry,
     221             :                       const OUString&                                 rDocName
     222             :                       );
     223             : 
     224             :     void reportUnsupportedEncryptionFormat(
     225             :         css::uno::Reference<
     226             :             css::task::XInteractionHandler > const & handler);
     227             : }
     228             : 
     229             : #endif
     230             : 
     231             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11