Skip to content

Commit

Permalink
Merge pull request #9985 from rouault/pdf_sdk_headers_split
Browse files Browse the repository at this point in the history
PDF: split import of SDK headers into separate file per backend
  • Loading branch information
rouault committed May 29, 2024
2 parents 25b4329 + fe08ea1 commit 76721fb
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 107 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ jobs:
base-devel git mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake mingw-w64-x86_64-ccache
mingw-w64-x86_64-pcre mingw-w64-x86_64-xerces-c mingw-w64-x86_64-zstd mingw-w64-x86_64-libarchive
mingw-w64-x86_64-geos mingw-w64-x86_64-libspatialite mingw-w64-x86_64-proj
mingw-w64-x86_64-cgal mingw-w64-x86_64-libfreexl mingw-w64-x86_64-hdf5 mingw-w64-x86_64-netcdf mingw-w64-x86_64-poppler mingw-w64-x86_64-postgresql
mingw-w64-x86_64-cgal mingw-w64-x86_64-libfreexl mingw-w64-x86_64-hdf5 mingw-w64-x86_64-netcdf mingw-w64-x86_64-poppler mingw-w64-x86_64-podofo mingw-w64-x86_64-postgresql
mingw-w64-x86_64-libgeotiff mingw-w64-x86_64-libpng mingw-w64-x86_64-libtiff mingw-w64-x86_64-openjpeg2
mingw-w64-x86_64-python-pip mingw-w64-x86_64-python-numpy mingw-w64-x86_64-python-pytest mingw-w64-x86_64-python-setuptools mingw-w64-x86_64-python-lxml mingw-w64-x86_64-swig mingw-w64-x86_64-python-psutil mingw-w64-x86_64-blosc
- name: Setup cache
Expand Down
5 changes: 4 additions & 1 deletion frmts/pdf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ add_gdal_driver(
pdfio.h
pdfobject.h
pdfcreatecopy.h
pdfsdk_headers.h
pdfsdk_headers_all.h
pdfsdk_headers_poppler.h
pdfsdk_headers_podofo.h
pdfsdk_headers_pdfium.h
ogrpdflayer.cpp
pdfcreatecopy.cpp
pdfdataset.cpp
Expand Down
2 changes: 1 addition & 1 deletion frmts/pdf/gdal_pdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#include <bitset> // For detecting usage of PDF library
#include <algorithm>

#include "pdfsdk_headers.h"
#include "pdfsdk_headers_all.h"

#include "pdfdrivercore.h"

Expand Down
2 changes: 1 addition & 1 deletion frmts/pdf/pdfobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#ifndef PDFOBJECT_H_INCLUDED
#define PDFOBJECT_H_INCLUDED

#include "pdfsdk_headers.h"
#include "pdfsdk_headers_all.h"

#include "cpl_string.h"
#include <map>
Expand Down
40 changes: 40 additions & 0 deletions frmts/pdf/pdfsdk_headers_all.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/******************************************************************************
*
* Project: GDAL
* Purpose: Includes PDF SDK headers
* Author: Even Rouault <even dot rouault at spatialys dot com>
*
******************************************************************************
* Copyright (c) 2015, Even Rouault <even dot rouault at spatialys dot com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/

#ifndef PDFSDK_HEADERS_ALL_H
#define PDFSDK_HEADERS_ALL_H

#if defined(__GNUC__) && !defined(_MSC_VER)
#pragma GCC system_header
#endif

#include "pdfsdk_headers_poppler.h"
#include "pdfsdk_headers_podofo.h"
#include "pdfsdk_headers_pdfium.h"

#endif // PDFSDK_HEADERS_ALL_H
108 changes: 5 additions & 103 deletions frmts/pdf/pdfsdk_headers.h → frmts/pdf/pdfsdk_headers_pdfium.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/******************************************************************************
*
* Project: GDAL
* Purpose: Includes PDF SDK headers
* Purpose: Includes PDFium headers
* Author: Even Rouault <even dot rouault at spatialys dot com>
*
******************************************************************************
Expand All @@ -26,111 +26,13 @@
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/

#ifndef PDFSDK_HEADERS_H
#define PDFSDK_HEADERS_H
#ifndef PDFSDK_HEADERS_PDFIUM_H
#define PDFSDK_HEADERS_PDFIUM_H

/* We avoid to include cpl_port.h directly or indirectly */
#if ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) && \
!defined(_MSC_VER))
#if defined(__GNUC__) && !defined(_MSC_VER)
#pragma GCC system_header
#endif

#ifdef HAVE_POPPLER

/* Horrible hack because there's a conflict between struct FlateDecode of */
/* include/poppler/Stream.h and the FlateDecode() function of */
/* pdfium/core/include/fpdfapi/fpdf_parser.h. */
/* The part of Stream.h where struct FlateDecode is defined isn't needed */
/* by GDAL, and is luckily protected by a #ifndef ENABLE_ZLIB section */
#ifdef HAVE_PDFIUM
#define ENABLE_ZLIB
#endif /* HAVE_PDFIUM */

#ifdef _MSC_VER
#pragma warning(push)
// conversion from 'const int' to 'Guchar', possible loss of data
#pragma warning(disable : 4244)
// conversion from 'size_t' to 'int', possible loss of data
#pragma warning(disable : 4267)
#endif

/* begin of poppler xpdf includes */
#include <Object.h>
#include <Stream.h>

#define private public /* Ugly! Page::pageObj is private but we need it... */
#include <Page.h>
#undef private

#include <Dict.h>

#define private \
public /* Ugly! Catalog::optContent is private but we need it... */
#include <Catalog.h>
#undef private

#define private public /* Ugly! PDFDoc::str is private but we need it... */
#include <PDFDoc.h>
#undef private

#include <splash/SplashBitmap.h>
#include <splash/Splash.h>
#include <SplashOutputDev.h>
#include <GlobalParams.h>
#include <ErrorCodes.h>

/* end of poppler xpdf includes */

#ifdef _MSC_VER
#pragma warning(pop)
#endif

#endif /* HAVE_POPPLER */

#ifdef HAVE_PODOFO

#ifdef _WIN32
/*
* Some Windows header defines a GetObject macro that
* shadows a GetObject() method in PoDoFo. As pdfdataset.cpp includes cpl_spawn.h
* which includes windows.h, so let's bite the bullet and important windows.h
* right now, and then undef GetObject. Undef'ing GetObject is done in some
* source files of PoDoFo itself.
*/
#include <windows.h>
#ifdef GetObject
#undef GetObject
#endif
#endif

// Related fix submitted per https://github.com/podofo/podofo/pull/98
#ifdef HAVE_PODOFO_0_10_OR_LATER
#define USE_HACK_BECAUSE_PdfInputStream_constructor_is_not_exported_in_podofo_0_11
#endif

#ifdef USE_HACK_BECAUSE_PdfInputStream_constructor_is_not_exported_in_podofo_0_11
// If we <sstream> is included after our below #define private public errors out
// with an error like:
// /usr/include/c++/13.2.1/sstream:457:7: error: 'struct std::__cxx11::basic_stringbuf<_CharT, _Traits, _Alloc>::__xfer_bufptrs' redeclared with different access
// 457 | struct __xfer_bufptrs
// so include it before, as otherwise it would get indirectly included by
// PdfDate.h, which includes <chrono>, which includes <sstream>
#include <sstream>
// Ugly! PfdObjectStream::GetParent() is private but we need it...
#define private public
#endif
#include "podofo.h"
#ifdef private
#undef private
#endif

#if PODOFO_VERSION_MAJOR > 0 || \
(PODOFO_VERSION_MAJOR == 0 && PODOFO_VERSION_MINOR >= 10)
#define PdfVecObjects PdfIndirectObjectList
#endif

#endif // HAVE_PODOFO

#ifdef HAVE_PDFIUM
#include "cpl_multiproc.h"

Expand Down Expand Up @@ -183,4 +85,4 @@

#endif // HAVE_PDFIUM

#endif
#endif // PDFSDK_HEADERS_PDFIUM_H
80 changes: 80 additions & 0 deletions frmts/pdf/pdfsdk_headers_podofo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/******************************************************************************
*
* Project: GDAL
* Purpose: Includes PoDoFo headers
* Author: Even Rouault <even dot rouault at spatialys dot com>
*
******************************************************************************
* Copyright (c) 2015, Even Rouault <even dot rouault at spatialys dot com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/

#ifndef PDFSDK_HEADERS_PODOFO_H
#define PDFSDK_HEADERS_PODOFO_H

#if defined(__GNUC__) && !defined(_MSC_VER)
#pragma GCC system_header
#endif

#ifdef HAVE_PODOFO

#ifdef _WIN32
/*
* Some Windows header defines a GetObject macro that
* shadows a GetObject() method in PoDoFo. As pdfdataset.cpp includes cpl_spawn.h
* which includes windows.h, so let's bite the bullet and important windows.h
* right now, and then undef GetObject. Undef'ing GetObject is done in some
* source files of PoDoFo itself.
*/
#include <windows.h>
#ifdef GetObject
#undef GetObject
#endif
#endif

// Related fix submitted per https://github.com/podofo/podofo/pull/98
#ifdef HAVE_PODOFO_0_10_OR_LATER
#define USE_HACK_BECAUSE_PdfInputStream_constructor_is_not_exported_in_podofo_0_11
#endif

#ifdef USE_HACK_BECAUSE_PdfInputStream_constructor_is_not_exported_in_podofo_0_11
// If we <sstream> is included after our below #define private public errors out
// with an error like:
// /usr/include/c++/13.2.1/sstream:457:7: error: 'struct std::__cxx11::basic_stringbuf<_CharT, _Traits, _Alloc>::__xfer_bufptrs' redeclared with different access
// 457 | struct __xfer_bufptrs
// so include it before, as otherwise it would get indirectly included by
// PdfDate.h, which includes <chrono>, which includes <sstream>
#include <sstream>
// Ugly! PfdObjectStream::GetParent() is private but we need it...
#define private public
#endif
#include "podofo.h"
#ifdef private
#undef private
#endif

#if PODOFO_VERSION_MAJOR > 0 || \
(PODOFO_VERSION_MAJOR == 0 && PODOFO_VERSION_MINOR >= 10)
#define PdfVecObjects PdfIndirectObjectList
#endif

#endif // HAVE_PODOFO

#endif // PDFSDK_HEADERS_PODOFO_H
88 changes: 88 additions & 0 deletions frmts/pdf/pdfsdk_headers_poppler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/******************************************************************************
*
* Project: GDAL
* Purpose: Includes Poppler headers
* Author: Even Rouault <even dot rouault at spatialys dot com>
*
******************************************************************************
* Copyright (c) 2015, Even Rouault <even dot rouault at spatialys dot com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/

#ifndef PDFSDK_HEADERS_POPPLER_H
#define PDFSDK_HEADERS_POPPLER_H

#if defined(__GNUC__) && !defined(_MSC_VER)
#pragma GCC system_header
#endif

#ifdef HAVE_POPPLER

/* Horrible hack because there's a conflict between struct FlateDecode of */
/* include/poppler/Stream.h and the FlateDecode() function of */
/* pdfium/core/include/fpdfapi/fpdf_parser.h. */
/* The part of Stream.h where struct FlateDecode is defined isn't needed */
/* by GDAL, and is luckily protected by a #ifndef ENABLE_ZLIB section */
#ifdef HAVE_PDFIUM
#define ENABLE_ZLIB
#endif /* HAVE_PDFIUM */

#ifdef _MSC_VER
#pragma warning(push)
// conversion from 'const int' to 'Guchar', possible loss of data
#pragma warning(disable : 4244)
// conversion from 'size_t' to 'int', possible loss of data
#pragma warning(disable : 4267)
#endif

/* begin of poppler xpdf includes */
#include <Object.h>
#include <Stream.h>

#define private public /* Ugly! Page::pageObj is private but we need it... */
#include <Page.h>
#undef private

#include <Dict.h>

#define private \
public /* Ugly! Catalog::optContent is private but we need it... */
#include <Catalog.h>
#undef private

#define private public /* Ugly! PDFDoc::str is private but we need it... */
#include <PDFDoc.h>
#undef private

#include <splash/SplashBitmap.h>
#include <splash/Splash.h>
#include <SplashOutputDev.h>
#include <GlobalParams.h>
#include <ErrorCodes.h>

/* end of poppler xpdf includes */

#ifdef _MSC_VER
#pragma warning(pop)
#endif

#endif /* HAVE_POPPLER */

#endif // PDFSDK_HEADERS_POPPLER_H

0 comments on commit 76721fb

Please sign in to comment.