LCOV - code coverage report
Current view: directory - frmts/pdf - pdfcreatecopy.h (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 10 6 60.0 %
Date: 2012-04-28 Functions: 14 9 64.3 %

       1                 : /******************************************************************************
       2                 :  * $Id: pdfcreatecopy.h 24184 2012-03-31 16:42:13Z rouault $
       3                 :  *
       4                 :  * Project:  PDF driver
       5                 :  * Purpose:  GDALDataset driver for PDF dataset.
       6                 :  * Author:   Even Rouault, <even dot rouault at mines dash paris dot org>
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2012, Even Rouault
      10                 :  *
      11                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      12                 :  * copy of this software and associated documentation files (the "Software"),
      13                 :  * to deal in the Software without restriction, including without limitation
      14                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      15                 :  * and/or sell copies of the Software, and to permit persons to whom the
      16                 :  * Software is furnished to do so, subject to the following conditions:
      17                 :  *
      18                 :  * The above copyright notice and this permission notice shall be included
      19                 :  * in all copies or substantial portions of the Software.
      20                 :  *
      21                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      22                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      23                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      24                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      25                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      26                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27                 :  * DEALINGS IN THE SOFTWARE.
      28                 :  ****************************************************************************/
      29                 : 
      30                 : #ifndef PDFCREATECOPY_H_INCLUDED
      31                 : #define PDFCREATECOPY_H_INCLUDED
      32                 : 
      33                 : #include "pdfobject.h"
      34                 : #include "gdal_priv.h"
      35                 : #include <vector>
      36                 : 
      37                 : #ifdef OGR_ENABLED
      38                 : #include "ogr_api.h"
      39                 : #endif
      40                 : 
      41                 : typedef enum
      42                 : {
      43                 :     COMPRESS_NONE,
      44                 :     COMPRESS_DEFLATE,
      45                 :     COMPRESS_JPEG,
      46                 :     COMPRESS_JPEG2000,
      47                 :     COMPRESS_DEFAULT
      48                 : } PDFCompressMethod;
      49                 : 
      50                 : typedef struct
      51                 : {
      52                 :     int nLeft;
      53                 :     int nRight;
      54                 :     int nTop;
      55                 :     int nBottom;
      56                 : } PDFMargins;
      57                 : 
      58                 : /************************************************************************/
      59                 : /*                          GDALPDFWriter                               */
      60                 : /************************************************************************/
      61                 : 
      62                 : class GDALXRefEntry
      63               0 : {
      64                 :     public:
      65                 :         vsi_l_offset    nOffset;
      66                 :         int             nGen;
      67                 :         int             bFree;
      68                 : 
      69            1206 :         GDALXRefEntry() : nOffset(0), nGen(0), bFree(FALSE) {}
      70                 :         GDALXRefEntry(vsi_l_offset nOffsetIn, int nGenIn = 0) : nOffset(nOffsetIn), nGen(nGen), bFree(FALSE) {}
      71            3454 :         GDALXRefEntry(const GDALXRefEntry& oOther) : nOffset(oOther.nOffset), nGen(oOther.nGen), bFree(oOther.bFree) {}
      72               0 :         GDALXRefEntry& operator= (const GDALXRefEntry& oOther) { nOffset = oOther.nOffset; nGen = oOther.nGen; bFree = oOther.bFree; return *this; }
      73                 : };
      74                 : 
      75                 : class GDALPDFImageDesc
      76               0 : {
      77                 :     public:
      78                 :         int          nImageId;
      79                 :         double       dfXOff;
      80                 :         double       dfYOff;
      81                 :         double       dfXSize;
      82                 :         double       dfYSize;
      83                 : };
      84                 : 
      85                 : class GDALPDFLayerDesc
      86              16 : {
      87                 :     public:
      88                 :         int          nOGCId;
      89                 :         int          nOCGTextId;
      90                 :         int          nFeatureLayerId;
      91                 :         CPLString    osLayerName;
      92                 :         int          bWriteOGRAttributes;
      93                 :         std::vector<int> aIds;
      94                 :         std::vector<int> aIdsText;
      95                 :         std::vector<int> aUserPropertiesIds;
      96                 :         std::vector<CPLString> aFeatureNames;
      97                 : };
      98                 : 
      99                 : class GDALPDFPageContext
     100             284 : {
     101                 :     public:
     102                 :         GDALDataset* poSrcDS;
     103                 :         PDFCompressMethod eStreamCompressMethod;
     104                 :         double       dfDPI;
     105                 :         PDFMargins   sMargins;
     106                 :         int          nPageId;
     107                 :         int          nContentId;
     108                 :         int          nResourcesId;
     109                 :         std::vector<GDALPDFImageDesc> asImageDesc;
     110                 :         std::vector<GDALPDFLayerDesc> asVectorDesc;
     111                 :         int          nOCGRasterId;
     112                 : };
     113                 : 
     114                 : class GDALPDFOCGDesc
     115               0 : {
     116                 :     public:
     117                 :         int          nId;
     118                 :         int          nParentId;
     119                 : };
     120                 : 
     121                 : class GDALPDFWriter
     122                 : {
     123                 :     VSILFILE* fp;
     124                 :     std::vector<GDALXRefEntry> asXRefEntries;
     125                 :     std::vector<int> asPageId;
     126                 :     std::vector<GDALPDFOCGDesc> asOCGs;
     127                 : 
     128                 :     int nInfoId;
     129                 :     int nInfoGen;
     130                 :     int nPageResourceId;
     131                 :     int nStructTreeRootId;
     132                 :     int nCatalogId;
     133                 :     int nCatalogGen;
     134                 :     int nXMPId;
     135                 :     int nXMPGen;
     136                 :     int bInWriteObj;
     137                 : 
     138                 :     int nLastStartXRef;
     139                 :     int nLastXRefSize;
     140                 :     int bCanUpdate;
     141                 : 
     142                 :     GDALPDFPageContext oPageContext;
     143                 : 
     144                 :     void    Init();
     145                 : 
     146                 :     void    StartObj(int nObjectId, int nGen = 0);
     147                 :     void    EndObj();
     148                 :     void    WriteXRefTableAndTrailer();
     149                 :     void    WritePages();
     150                 :     int     WriteBlock( GDALDataset* poSrcDS,
     151                 :                         int nXOff, int nYOff, int nReqXSize, int nReqYSize,
     152                 :                         int nColorTableId,
     153                 :                         PDFCompressMethod eCompressMethod,
     154                 :                         int nPredictor,
     155                 :                         int nJPEGQuality,
     156                 :                         const char* pszJPEG2000_DRIVER,
     157                 :                         GDALProgressFunc pfnProgress,
     158                 :                         void * pProgressData );
     159                 :     int     WriteMask(GDALDataset* poSrcDS,
     160                 :                       int nXOff, int nYOff, int nReqXSize, int nReqYSize,
     161                 :                       PDFCompressMethod eCompressMethod);
     162                 :     int     WriteOCG(const char* pszLayerName, int nParentId = 0);
     163                 : 
     164                 :     int     WriteColorTable(GDALDataset* poSrcDS);
     165                 : 
     166                 :     int     AllocNewObject();
     167                 : 
     168                 :     public:
     169                 :         GDALPDFWriter(VSILFILE* fpIn, int bAppend = FALSE);
     170                 :        ~GDALPDFWriter();
     171                 : 
     172                 :        void Close();
     173                 : 
     174               6 :        int  GetCatalogNum() { return nCatalogId; }
     175               6 :        int  GetCatalogGen() { return nCatalogGen; }
     176                 : 
     177                 :        int  ParseTrailerAndXRef();
     178                 :        void UpdateProj(GDALDataset* poSrcDS,
     179                 :                        double dfDPI,
     180                 :                        GDALPDFDictionaryRW* poPageDict,
     181                 :                        int nPageNum, int nPageGen);
     182                 :        void UpdateInfo(GDALDataset* poSrcDS);
     183                 :        void UpdateXMP (GDALDataset* poSrcDS,
     184                 :                        GDALPDFDictionaryRW* poCatalogDict);
     185                 : 
     186                 :        int     WriteSRS_ISO32000(GDALDataset* poSrcDS,
     187                 :                                 double dfUserUnit,
     188                 :                                 const char* pszNEATLINE,
     189                 :                                 PDFMargins* psMargins);
     190                 :        int     WriteSRS_OGC_BP(GDALDataset* poSrcDS,
     191                 :                                 double dfUserUnit,
     192                 :                                 const char* pszNEATLINE,
     193                 :                                 PDFMargins* psMargins);
     194                 : 
     195                 :        int  StartPage(GDALDataset* poSrcDS,
     196                 :                       double dfDPI,
     197                 :                       const char* pszGEO_ENCODING,
     198                 :                       const char* pszNEATLINE,
     199                 :                       PDFMargins* psMargins,
     200                 :                       PDFCompressMethod eStreamCompressMethod,
     201                 :                       int bHasOGRData);
     202                 : 
     203                 :        int WriteImagery(const char* pszLayerName,
     204                 :                         PDFCompressMethod eCompressMethod,
     205                 :                         int nPredictor,
     206                 :                         int nJPEGQuality,
     207                 :                         const char* pszJPEG2000_DRIVER,
     208                 :                         int nBlockXSize, int nBlockYSize,
     209                 :                         GDALProgressFunc pfnProgress,
     210                 :                         void * pProgressData);
     211                 : 
     212                 : #ifdef OGR_ENABLED
     213                 :        int WriteOGRDataSource(const char* pszOGRDataSource,
     214                 :                               const char* pszOGRDisplayField,
     215                 :                               const char* pszOGRDisplayLayerNames,
     216                 :                               int bWriteOGRAttributes);
     217                 : 
     218                 :        GDALPDFLayerDesc StartOGRLayer(CPLString osLayerName,
     219                 :                                       int bWriteOGRAttributes);
     220                 :        void EndOGRLayer(GDALPDFLayerDesc& osVectorDesc);
     221                 : 
     222                 :        int WriteOGRLayer(OGRDataSourceH hDS,
     223                 :                          int iLayer,
     224                 :                          const char* pszOGRDisplayField,
     225                 :                          CPLString osLayerName,
     226                 :                          int bWriteOGRAttributes,
     227                 :                          int& iObj);
     228                 : 
     229                 :        int WriteOGRFeature(GDALPDFLayerDesc& osVectorDesc,
     230                 :                            OGRFeatureH hFeat,
     231                 :                            const char* pszOGRDisplayField,
     232                 :                            int bWriteOGRAttributes,
     233                 :                            int& iObj,
     234                 :                            int& iObjLayer);
     235                 : #endif
     236                 : 
     237                 :        int  EndPage(const char* pszExtraImages,
     238                 :                     const char* pszExtraStream,
     239                 :                     const char* pszExtraLayerName);
     240                 : 
     241                 :        int  SetInfo(GDALDataset* poSrcDS,
     242                 :                     char** papszOptions);
     243                 :        int  SetXMP(GDALDataset* poSrcDS,
     244                 :                    const char* pszXMP);
     245                 : };
     246                 : 
     247                 : GDALDataset         *GDALPDFCreateCopy( const char *, GDALDataset *,
     248                 :                                         int, char **,
     249                 :                                         GDALProgressFunc pfnProgress,
     250                 :                                         void * pProgressData );
     251                 : 
     252                 : #endif // PDFCREATECOPY_H_INCLUDED

Generated by: LCOV version 1.7