LCOV - code coverage report
Current view: top level - sdext/source/pdfimport/xpdfwrapper - pdfioutdev_gpl.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 16 17 94.1 %
Date: 2015-06-13 12:38:46 Functions: 6 7 85.7 %
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_XPDFWRAPPER_PDFIOUTDEV_GPL_HXX
      21             : #define INCLUDED_SDEXT_SOURCE_PDFIMPORT_XPDFWRAPPER_PDFIOUTDEV_GPL_HXX
      22             : 
      23             : #include <sal/types.h>
      24             : #include <config_poppler.h>
      25             : 
      26             : #if defined __GNUC__
      27             : # pragma GCC diagnostic push
      28             : # pragma GCC diagnostic ignored "-Wunused-parameter"
      29             : #elif defined _MSC_VER
      30             : #pragma warning(push, 1)
      31             : #endif
      32             : 
      33             : #include "GfxState.h"
      34             : #include "GfxFont.h"
      35             : #include "UnicodeMap.h"
      36             : #include "Link.h"
      37             : #include "Object.h"
      38             : #include "OutputDev.h"
      39             : #include "GlobalParams.h"
      40             : #include "PDFDoc.h"
      41             : 
      42             : #if defined __GNUC__
      43             : # pragma GCC diagnostic pop
      44             : #elif defined _MSC_VER
      45             : #pragma warning(pop)
      46             : #endif
      47             : 
      48             : #include <unordered_map>
      49             : #include <vector>
      50             : 
      51             : class GfxPath;
      52             : class GfxFont;
      53             : class PDFDoc;
      54             : #if HAVE_POPPLER_VERSION_H
      55             : #include <cpp/poppler-version.h>
      56             : #else
      57             : #define POPPLER_VERSION "0.12.3"
      58             : #define POPPLER_VERSION_MAJOR 0
      59             : #define POPPLER_VERSION_MINOR 12
      60             : #define POPPLER_VERSION_MICRO 3
      61             : #endif
      62             : #define POPPLER_CHECK_VERSION(major,minor,micro) \
      63             :   (POPPLER_VERSION_MAJOR > (major) || \
      64             :    (POPPLER_VERSION_MAJOR == (major) && POPPLER_VERSION_MINOR > (minor)) || \
      65             :    (POPPLER_VERSION_MAJOR == (major) && POPPLER_VERSION_MINOR == (minor) && POPPLER_VERSION_MICRO >= (micro)))
      66             : 
      67             : namespace pdfi
      68             : {
      69          57 :     struct FontAttributes
      70             :     {
      71             :         FontAttributes( const GooString& familyName_,
      72             :                         bool           isEmbedded_,
      73             :                         bool           isBold_,
      74             :                         bool           isItalic_,
      75             :                         bool           isUnderline_,
      76             :                         double         size_ ) :
      77             :             familyName(),
      78             :             isEmbedded(isEmbedded_),
      79             :             isBold(isBold_),
      80             :             isItalic(isItalic_),
      81             :             isUnderline(isUnderline_),
      82             :             size(size_)
      83             :         {
      84             :             familyName.append(const_cast<GooString*>(&familyName_));
      85             :         }
      86             : 
      87          57 :         FontAttributes() :
      88             :             familyName(),
      89             :             isEmbedded(false),
      90             :             isBold(false),
      91             :             isItalic(false),
      92             :             isUnderline(false),
      93          57 :             size(0.0)
      94          57 :         {}
      95             : 
      96             :         // xdpf goo stuff is so totally borked...
      97             :         // ...need to hand-code assignment
      98             :         FontAttributes( const FontAttributes& rSrc ) :
      99             :             familyName(),
     100             :             isEmbedded(rSrc.isEmbedded),
     101             :             isBold(rSrc.isBold),
     102             :             isItalic(rSrc.isItalic),
     103             :             isUnderline(rSrc.isUnderline),
     104             :             size(rSrc.size)
     105             :         {
     106             :             familyName.append(const_cast<GooString*>(&rSrc.familyName));
     107             :         }
     108             : 
     109          46 :         FontAttributes& operator=( const FontAttributes& rSrc )
     110             :         {
     111          46 :             familyName.clear();
     112          46 :             familyName.append(const_cast<GooString*>(&rSrc.familyName));
     113             : 
     114          46 :             isEmbedded  = rSrc.isEmbedded;
     115          46 :             isBold      = rSrc.isBold;
     116          46 :             isItalic    = rSrc.isItalic;
     117          46 :             isUnderline = rSrc.isUnderline;
     118          46 :             size        = rSrc.size;
     119             : 
     120          46 :             return *this;
     121             :         }
     122             : 
     123             :         bool operator==(const FontAttributes& rFont) const
     124             :         {
     125             :             return familyName.cmp(
     126             :                 const_cast<GooString*>(&rFont.familyName))==0 &&
     127             :                 isEmbedded == rFont.isEmbedded &&
     128             :                 isBold == rFont.isBold &&
     129             :                 isItalic == rFont.isItalic &&
     130             :                 isUnderline == rFont.isUnderline &&
     131             :                 size == rFont.size;
     132             :         }
     133             : 
     134             :         GooString     familyName;
     135             :         bool        isEmbedded;
     136             :         bool        isBold;
     137             :         bool        isItalic;
     138             :         bool        isUnderline;
     139             :         double      size;
     140             :     };
     141             : 
     142             :     class PDFOutDev : public OutputDev
     143             :     {
     144             :         // not owned by this class
     145             :         PDFDoc*                                 m_pDoc;
     146             :         mutable std::unordered_map< long long,
     147             :                                FontAttributes > m_aFontMap;
     148             :         UnicodeMap*                             m_pUtf8Map;
     149             :         bool                                    m_bSkipImages;
     150             : 
     151             :         int  parseFont( long long nNewId, GfxFont* pFont, GfxState* state ) const;
     152             :         void writeFontFile( GfxFont* gfxFont ) const;
     153             :         static void printPath( GfxPath* pPath );
     154             : 
     155             :     public:
     156             :         explicit PDFOutDev( PDFDoc* pDoc );
     157             :         virtual ~PDFOutDev();
     158             : 
     159             :         //----- get info about output device
     160             : 
     161             :         // Does this device use upside-down coordinates?
     162             :         // (Upside-down means (0,0) is the top left corner of the page.)
     163          10 :         virtual GBool upsideDown() SAL_OVERRIDE { return gTrue; }
     164             : 
     165             :         // Does this device use drawChar() or drawString()?
     166         708 :         virtual GBool useDrawChar() SAL_OVERRIDE { return gTrue; }
     167             : 
     168             :         // Does this device use beginType3Char/endType3Char?  Otherwise,
     169             :         // text in Type 3 fonts will be drawn with drawChar/drawString.
     170           0 :         virtual GBool interpretType3Chars() SAL_OVERRIDE { return gFalse; }
     171             : 
     172             :         // Does this device need non-text content?
     173          10 :         virtual GBool needNonText() SAL_OVERRIDE { return gTrue; }
     174             : 
     175             :         //----- initialization and control
     176             : 
     177             :         // Set default transform matrix.
     178             :         virtual void setDefaultCTM(double *ctm) SAL_OVERRIDE;
     179             : 
     180             :         // Start a page.
     181             :         virtual void startPage(int pageNum, GfxState *state
     182             : #if POPPLER_CHECK_VERSION(0, 23, 0) || POPPLER_CHECK_VERSION(0, 24, 0)
     183             :                                , XRef *xref
     184             : #endif
     185             :         ) SAL_OVERRIDE;
     186             : 
     187             :         // End a page.
     188             :         virtual void endPage() SAL_OVERRIDE;
     189             : 
     190             :         //----- link borders
     191             :         #if POPPLER_CHECK_VERSION(0, 19, 0)
     192             :         virtual void processLink(AnnotLink *link) SAL_OVERRIDE;
     193             :     #elif POPPLER_CHECK_VERSION(0, 17, 0)
     194             :         virtual void processLink(AnnotLink *link, Catalog *catalog) SAL_OVERRIDE;
     195             :     #else
     196             :         virtual void processLink(Link *link, Catalog *catalog) SAL_OVERRIDE;
     197             :     #endif
     198             : 
     199             :         //----- save/restore graphics state
     200             :         virtual void saveState(GfxState *state) SAL_OVERRIDE;
     201             :         virtual void restoreState(GfxState *state) SAL_OVERRIDE;
     202             : 
     203             :         //----- update graphics state
     204             :         virtual void updateCTM(GfxState *state, double m11, double m12,
     205             :                                double m21, double m22, double m31, double m32) SAL_OVERRIDE;
     206             :         virtual void updateLineDash(GfxState *state) SAL_OVERRIDE;
     207             :         virtual void updateFlatness(GfxState *state) SAL_OVERRIDE;
     208             :         virtual void updateLineJoin(GfxState *state) SAL_OVERRIDE;
     209             :         virtual void updateLineCap(GfxState *state) SAL_OVERRIDE;
     210             :         virtual void updateMiterLimit(GfxState *state) SAL_OVERRIDE;
     211             :         virtual void updateLineWidth(GfxState *state) SAL_OVERRIDE;
     212             :         virtual void updateFillColor(GfxState *state) SAL_OVERRIDE;
     213             :         virtual void updateStrokeColor(GfxState *state) SAL_OVERRIDE;
     214             :         virtual void updateFillOpacity(GfxState *state) SAL_OVERRIDE;
     215             :         virtual void updateStrokeOpacity(GfxState *state) SAL_OVERRIDE;
     216             :         virtual void updateBlendMode(GfxState *state) SAL_OVERRIDE;
     217             : 
     218             :         //----- update text state
     219             :         virtual void updateFont(GfxState *state) SAL_OVERRIDE;
     220             :         virtual void updateRender(GfxState *state) SAL_OVERRIDE;
     221             : 
     222             :         //----- path painting
     223             :         virtual void stroke(GfxState *state) SAL_OVERRIDE;
     224             :         virtual void fill(GfxState *state) SAL_OVERRIDE;
     225             :         virtual void eoFill(GfxState *state) SAL_OVERRIDE;
     226             : 
     227             :         //----- path clipping
     228             :         virtual void clip(GfxState *state) SAL_OVERRIDE;
     229             :         virtual void eoClip(GfxState *state) SAL_OVERRIDE;
     230             : 
     231             :         //----- text drawing
     232             :         virtual void drawChar(GfxState *state, double x, double y,
     233             :                               double dx, double dy,
     234             :                               double originX, double originY,
     235             :                               CharCode code, int nBytes, Unicode *u, int uLen) SAL_OVERRIDE;
     236             :         virtual void drawString(GfxState *state, GooString *s) SAL_OVERRIDE;
     237             :         virtual void endTextObject(GfxState *state) SAL_OVERRIDE;
     238             : 
     239             :         //----- image drawing
     240             :         virtual void drawImageMask(GfxState *state, Object *ref, Stream *str,
     241             :                                    int width, int height, GBool invert,
     242             : #if POPPLER_CHECK_VERSION(0, 12, 0)
     243             :                                    GBool interpolate,
     244             : #endif
     245             :                                    GBool inlineImg) SAL_OVERRIDE;
     246             :         virtual void drawImage(GfxState *state, Object *ref, Stream *str,
     247             :                                int width, int height, GfxImageColorMap *colorMap,
     248             : #if POPPLER_CHECK_VERSION(0, 12, 0)
     249             :                                GBool interpolate,
     250             : #endif
     251             :                                int *maskColors, GBool inlineImg) SAL_OVERRIDE;
     252             :         virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str,
     253             :                                      int width, int height,
     254             :                                      GfxImageColorMap *colorMap,
     255             : #if POPPLER_CHECK_VERSION(0, 12, 0)
     256             :                                      GBool interpolate,
     257             : #endif
     258             :                                      Stream *maskStr, int maskWidth, int maskHeight,
     259             :                                      GBool maskInvert
     260             : #if POPPLER_CHECK_VERSION(0, 12, 0)
     261             :                                      , GBool maskInterpolate
     262             : #endif
     263             :                                     ) SAL_OVERRIDE;
     264             :         virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str,
     265             :                                          int width, int height,
     266             :                                          GfxImageColorMap *colorMap,
     267             : #if POPPLER_CHECK_VERSION(0, 12, 0)
     268             :                                          GBool interpolate,
     269             : #endif
     270             :                                          Stream *maskStr,
     271             :                                          int maskWidth, int maskHeight,
     272             :                                          GfxImageColorMap *maskColorMap
     273             : #if POPPLER_CHECK_VERSION(0, 12, 0)
     274             :                                          , GBool maskInterpolate
     275             : #endif
     276             :                                         ) SAL_OVERRIDE;
     277             : 
     278             :         static void setPageNum( int nNumPages );
     279             :         void setSkipImages ( bool bSkipImages );
     280             :     };
     281             : }
     282             : 
     283             : extern FILE* g_binary_out;
     284             : 
     285             : // note: if you ever hcange Output_t, please keep in mind that the current code
     286             : // relies on it being of 8 bit size
     287             : typedef Guchar Output_t;
     288             : typedef std::vector< Output_t > OutputBuffer;
     289             : 
     290             : #endif // INCLUDED_SDEXT_SOURCE_PDFIMPORT_XPDFWRAPPER_PDFIOUTDEV_GPL_HXX
     291             : 
     292             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11