LCOV - code coverage report
Current view: top level - sdext/source/pdfimport/inc - pdfihelper.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 68 68 100.0 %
Date: 2014-04-11 Functions: 11 11 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             : 
      32             : #include <vector>
      33             : #include <boost/unordered_map.hpp>
      34             : 
      35             : // virtual resolution of the PDF OutputDev in dpi
      36             : #define PDFI_OUTDEV_RESOLUTION 7200
      37             : 
      38             : namespace com { namespace sun { namespace star { namespace task
      39             : { class XInteractionHandler; }}}}
      40             : 
      41             : namespace pdfi
      42             : {
      43             :     typedef boost::unordered_map< OUString, OUString, OUStringHash > PropertyMap;
      44             :     typedef sal_Int32 ImageId;
      45             : 
      46             :     /// What to do with a polygon. values can be ORed together
      47             :     enum PolygonAction { PATH_STROKE=1, PATH_FILL=2, PATH_EOFILL=4 };
      48             : 
      49             :     OUString unitMMString( double fMM );
      50             :     OUString convertPixelToUnitString( double fPix );
      51             : 
      52         316 :     inline double convPx2mm( double fPix )
      53             :     {
      54         316 :         const double px2mm = 25.4/PDFI_OUTDEV_RESOLUTION;
      55         316 :         fPix *= px2mm;
      56         316 :         return fPix;
      57             :     }
      58             : 
      59           8 :     inline double convmm2Px( double fMM )
      60             :     {
      61           8 :         const double mm2px = PDFI_OUTDEV_RESOLUTION/25.4;
      62           8 :         fMM *= mm2px;
      63           8 :         return fMM;
      64             :     }
      65             : 
      66         124 :     inline double convPx2mmPrec2( double fPix )
      67             :     {
      68         124 :         return rtl_math_round( convPx2mm( fPix ), 2, rtl_math_RoundingMode_Floor );
      69             :     }
      70             : 
      71             :     /// Convert color to "#FEFEFE" color notation
      72             :     OUString getColorString( const ::com::sun::star::rendering::ARGBColor& );
      73             : 
      74             :     struct FontAttrHash
      75             :     {
      76          47 :         size_t operator()(const FontAttributes& rFont ) const
      77             :         {
      78          47 :             return (size_t)rFont.familyName.hashCode()
      79          47 :                 ^  size_t(rFont.isBold ? 0xd47be593 : 0)
      80          47 :                 ^  size_t(rFont.isItalic ? 0x1efd51a1 : 0)
      81          47 :                 ^  size_t(rFont.isUnderline ? 0xf6bd325a : 0)
      82          47 :                 ^  size_t(rFont.isOutline ?  0x12345678 : 0)
      83          47 :                 ^  size_t(rFont.size)
      84             :                 ;
      85             :         }
      86             :     };
      87             : 
      88        2483 :     struct GraphicsContext
      89             :     {
      90             :         ::com::sun::star::rendering::ARGBColor     LineColor;
      91             :         ::com::sun::star::rendering::ARGBColor     FillColor;
      92             :         sal_Int8                                   LineJoin;
      93             :         sal_Int8                                   LineCap;
      94             :         sal_Int8                                   BlendMode;
      95             :         double                                     Flatness;
      96             :         double                                     LineWidth;
      97             :         double                                     MiterLimit;
      98             :         std::vector<double>                        DashArray;
      99             :         sal_Int32                                  FontId;
     100             :         sal_Int32                                  TextRenderMode;
     101             :         basegfx::B2DHomMatrix                      Transformation;
     102             :         basegfx::B2DPolyPolygon                    Clip;
     103             : 
     104         223 :         GraphicsContext() :
     105             :             LineColor(),
     106             :             FillColor(),
     107             :             LineJoin(0),
     108             :             LineCap(0),
     109             :             BlendMode(0),
     110             :             Flatness(0.0),
     111             :             LineWidth(1.0),
     112             :             MiterLimit(10.0),
     113             :             DashArray(),
     114             :             FontId(0),
     115             :             TextRenderMode(0),
     116             :             Transformation(),
     117         223 :             Clip()
     118         223 :         {}
     119             : 
     120          26 :         bool operator==(const GraphicsContext& rRight ) const
     121             :         {
     122          52 :             return LineColor.Red == rRight.LineColor.Red &&
     123          52 :                 LineColor.Green == rRight.LineColor.Green &&
     124          52 :                 LineColor.Blue == rRight.LineColor.Blue &&
     125          52 :                 LineColor.Alpha == rRight.LineColor.Alpha &&
     126          52 :                 FillColor.Red == rRight.FillColor.Red &&
     127          52 :                 FillColor.Green == rRight.FillColor.Green &&
     128          52 :                 FillColor.Blue == rRight.FillColor.Blue &&
     129          52 :                 FillColor.Alpha == rRight.FillColor.Alpha &&
     130          52 :                 LineJoin  == rRight.LineJoin &&
     131          52 :                 LineCap   == rRight.LineCap &&
     132          52 :                 BlendMode == rRight.BlendMode &&
     133          52 :                 LineWidth == rRight.LineWidth &&
     134          52 :                 Flatness == rRight.Flatness &&
     135          52 :                 MiterLimit == rRight.MiterLimit &&
     136          52 :                 DashArray == rRight.DashArray &&
     137          48 :                 FontId    == rRight.FontId &&
     138          44 :                 TextRenderMode == rRight.TextRenderMode &&
     139          70 :                 Transformation == rRight.Transformation &&
     140          48 :                 Clip == rRight.Clip;
     141             :         }
     142             : 
     143         197 :         bool isRotatedOrSkewed() const
     144         394 :         { return Transformation.get( 0, 1 ) != 0.0 ||
     145         394 :                 Transformation.get( 1, 0 ) != 0.0; }
     146             :     };
     147             : 
     148             :     struct GraphicsContextHash
     149             :     {
     150         456 :         size_t operator()(const GraphicsContext& rGC ) const
     151             :         {
     152             :             return size_t(rGC.LineColor.Red)
     153         456 :                 ^  size_t(rGC.LineColor.Green)
     154         456 :                 ^  size_t(rGC.LineColor.Blue)
     155         456 :                 ^  size_t(rGC.LineColor.Alpha)
     156         456 :                 ^  size_t(rGC.FillColor.Red)
     157         456 :                 ^  size_t(rGC.FillColor.Green)
     158         456 :                 ^  size_t(rGC.FillColor.Blue)
     159         456 :                 ^  size_t(rGC.FillColor.Alpha)
     160         456 :                 ^  size_t(rGC.LineJoin)
     161         456 :                 ^  size_t(rGC.LineCap)
     162         456 :                 ^  size_t(rGC.BlendMode)
     163         456 :                 ^  size_t(rGC.LineWidth)
     164         456 :                 ^  size_t(rGC.Flatness)
     165         456 :                 ^  size_t(rGC.MiterLimit)
     166         456 :                 ^  rGC.DashArray.size()
     167         456 :                 ^  size_t(rGC.FontId)
     168         456 :                 ^  size_t(rGC.TextRenderMode)
     169         456 :                 ^  size_t(rGC.Transformation.get( 0, 0 ))
     170         456 :                 ^  size_t(rGC.Transformation.get( 1, 0 ))
     171         456 :                 ^  size_t(rGC.Transformation.get( 0, 1 ))
     172         456 :                 ^  size_t(rGC.Transformation.get( 1, 1 ))
     173         456 :                 ^  size_t(rGC.Transformation.get( 0, 2 ))
     174         456 :                 ^  size_t(rGC.Transformation.get( 1, 2 ))
     175         456 :                 ^  size_t(rGC.Clip.count() ? rGC.Clip.getB2DPolygon(0).count() : 0)
     176             :                 ;
     177             :         }
     178             :     };
     179             : 
     180             :     /** retrieve password from user
     181             :      */
     182             :     bool getPassword( const ::com::sun::star::uno::Reference<
     183             :                             ::com::sun::star::task::XInteractionHandler >& xHandler,
     184             :                       OUString&                                       rOutPwd,
     185             :                       bool                                                 bFirstTry,
     186             :                       const OUString&                                 rDocName
     187             :                       );
     188             : 
     189             :     void reportUnsupportedEncryptionFormat(
     190             :         com::sun::star::uno::Reference<
     191             :             com::sun::star::task::XInteractionHandler > const & handler);
     192             : }
     193             : 
     194             : #endif
     195             : 
     196             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10