Skip to content

Commit

Permalink
PDF: update PDFium to 5461
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Dec 6, 2022
1 parent 69d236f commit 3355dd4
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 73 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/cmake_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ jobs:
- name: Install pdfium
run: |
wget -q https://github.com/rouault/pdfium_build_gdal_3_5/releases/download/v1_pdfium_5106/install-ubuntu2004-rev5106.tar.gz \
&& tar -xzf install-ubuntu2004-rev5106.tar.gz \
wget -q https://github.com/rouault/pdfium_build_gdal_3_7/releases/download/pdfium_5461_v1/install-ubuntu2004-rev5461.tar.gz \
&& tar -xzf install-ubuntu2004-rev5461.tar.gz \
&& sudo chown -R root:root install \
&& sudo mv install/lib/* /usr/lib/ \
&& sudo mv install/include/* /usr/include/ \
&& sudo rm -rf install-ubuntu2004-rev5106.tar.gz install \
&& sudo rm -rf install-ubuntu2004-rev5461.tar.gz install \
&& sudo apt-get update -y \
&& sudo apt-get install -y --fix-missing --no-install-recommends liblcms2-dev
- name: Configure ccache
Expand Down Expand Up @@ -466,8 +466,8 @@ jobs:
- name: Install pdfium
shell: bash -l {0}
run: |
curl -LOs https://github.com/rouault/pdfium_build_gdal_3_5/releases/download/v1_pdfium_5106/install-win10-vs2019-x64-rev5106.zip
unzip install-win10-vs2019-x64-rev5106.zip
curl -LOs https://github.com/rouault/pdfium_build_gdal_3_7/releases/download/pdfium_5461_v1/install-win10-vs2019-x64-rev5461.zip
unzip install-win10-vs2019-x64-rev5461.zip
mv install install-pdfium
- name: Remove conflicting libraries
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ubuntu_20.04/build-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ mkdir geos \
&& rm -rf geos

# Install pdfium
wget -q https://github.com/rouault/pdfium_build_gdal_3_5/releases/download/v1_pdfium_5106/install-ubuntu2004-rev5106.tar.gz \
&& tar -xzf install-ubuntu2004-rev5106.tar.gz \
wget -q https://github.com/rouault/pdfium_build_gdal_3_7/releases/download/pdfium_5461_v1/install-ubuntu2004-rev5461.tar.gz \
&& tar -xzf install-ubuntu2004-rev5461.tar.gz \
&& chown -R root:root install \
&& mv install/lib/* /usr/lib/ \
&& mv install/include/* /usr/include/ \
&& rm -rf install-ubuntu2004-rev5106.tar.gz install \
&& rm -rf install-ubuntu2004-rev5461.tar.gz install \
&& apt-get update -y \
&& apt-get install -y --fix-missing --no-install-recommends liblcms2-dev \
&& rm -rf /var/lib/apt/lists/*
Expand Down
8 changes: 7 additions & 1 deletion doc/source/drivers/raster/pdf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,15 @@ Only GDAL builds against static builds of PDFium have been tested.
Building PDFium can be challenging, and particular builds must be used to
work properly with GDAL.

With GDAL >= 3.5
With GDAL >= 3.7
++++++++++++++++

The scripts in the `<https://github.com/rouault/pdfium_build_gdal_3_7>`__
repository must be used to build a patched version of PDFium.

With GDAL 3.5 and 3.6
+++++++++++++++++++++

The scripts in the `<https://github.com/rouault/pdfium_build_gdal_3_5>`__
repository must be used to build a patched version of PDFium.

Expand Down
6 changes: 3 additions & 3 deletions docker/ubuntu-full/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ RUN . /buildscripts/bh-set-envvars.sh \

ARG WITH_PDFIUM=yes
RUN if echo "$WITH_PDFIUM" | grep -Eiq "^(y(es)?|1|true)$" ; then ( \
wget -q https://github.com/rouault/pdfium_build_gdal_3_5/releases/download/v1_pdfium_5106/install-ubuntu2004-rev5106.tar.gz \
&& tar -xzf install-ubuntu2004-rev5106.tar.gz \
wget -q https://github.com/rouault/pdfium_build_gdal_3_7/releases/download/pdfium_5461_v1/install-ubuntu2004-rev5461.tar.gz \
&& tar -xzf install-ubuntu2004-rev5461.tar.gz \
&& chown -R root:root install \
&& mv install/lib/* /usr/lib/ \
&& mv install/include/* /usr/include/ \
&& rm -rf install-ubuntu2004-rev5106.tar.gz install \
&& rm -rf install-ubuntu2004-rev5461.tar.gz install \
&& apt-get update -y \
&& apt-get install -y --fix-missing --no-install-recommends liblcms2-dev${APT_ARCH_SUFFIX} \
&& rm -rf /var/lib/apt/lists/* \
Expand Down
4 changes: 3 additions & 1 deletion frmts/pdf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if (GDAL_USE_PODOFO)
gdal_target_link_libraries(gdal_PDF PRIVATE PODOFO::Podofo)
endif ()
if (GDAL_USE_PDFIUM)
target_compile_features(gdal_PDF PRIVATE cxx_std_14)
target_compile_features(gdal_PDF PRIVATE cxx_std_17)
target_compile_definitions(gdal_PDF PRIVATE -DHAVE_PDFIUM)
gdal_target_link_libraries(gdal_PDF PRIVATE PDFIUM::PDFIUM)
if (UNIX)
Expand All @@ -54,5 +54,7 @@ if (GDAL_USE_PDFIUM)
${OPENJPEG_LIBRARIES}
Threads::Threads
${LCMS2_LIBRARY})
else ()
gdal_target_link_libraries(gdal_PDF PRIVATE winmm.lib)
endif ()
endif ()
31 changes: 19 additions & 12 deletions frmts/pdf/pdfdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,14 +1199,15 @@ int LoadPdfiumDocumentPage(
TPdfiumPageStruct *poPage = nullptr;
// Page not loaded
if(itPage == poDoc->pages.end()) {
CPDF_Dictionary* pDict = poDoc->doc->GetPageDictionary(pageNum - 1);
auto pDict = poDoc->doc->GetPageDictionary(pageNum - 1);
if (pDict == nullptr) {
CPLError(CE_Failure, CPLE_AppDefined, "Invalid PDFium : invalid page");

CPLReleaseMutex(g_oPdfiumLoadDocMutex);
return FALSE;
}
auto pPage = pdfium::MakeRetain<CPDF_Page>(poDoc->doc, pDict);
auto pPage = pdfium::MakeRetain<CPDF_Page>(poDoc->doc,
pdfium::WrapRetain(const_cast<CPDF_Dictionary*>(pDict.Get())));

poPage = new TPdfiumPageStruct;
if(!poPage) {
Expand Down Expand Up @@ -1381,16 +1382,18 @@ class GDALPDFiumOCContext : public CPDF_OCContextInterface
GDALPDFiumOCContext(PDFDataset* poDS, CPDF_Document *pDoc, CPDF_OCContext::UsageType usage) :
m_poDS(poDS), m_DefaultOCContext(pdfium::MakeRetain<CPDF_OCContext>(pDoc, usage)) {}

virtual bool CheckOCGVisible(const CPDF_Dictionary *pOCGDict) const override
virtual bool CheckOCGDictVisible(const CPDF_Dictionary *pOCGDict) const override
{
// CPLDebug("PDF", "CheckOCGDictVisible(%d,%d)",
// pOCGDict->GetObjNum(), pOCGDict->GetGenNum() );
PDFDataset::VisibilityState eVisibility =
m_poDS->GetVisibilityStateForOGCPdfium(
pOCGDict->GetObjNum(), pOCGDict->GetGenNum() );
if( eVisibility == PDFDataset::VISIBILITY_ON )
return true;
if( eVisibility == PDFDataset::VISIBILITY_OFF )
return false;
return m_DefaultOCContext->CheckOCGVisible(pOCGDict);
return m_DefaultOCContext->CheckOCGDictVisible(pOCGDict);
}
};

Expand Down Expand Up @@ -1548,7 +1551,7 @@ class GDALPDFiumRenderDeviceDriver: public RenderDeviceDriverIface
return m_poParent->ContinueDIBits(handle, pPause);
}

virtual bool DrawDeviceText(pdfium::span<const TextCharPos> pCharPos,
virtual bool DrawDeviceText(const pdfium::span<const TextCharPos>& pCharPos,
CFX_Font* pFont,
const CFX_Matrix& mtObject2Device,
float font_size,
Expand Down Expand Up @@ -1602,6 +1605,9 @@ class GDALPDFiumRenderDeviceDriver: public RenderDeviceDriverIface
return true;
return m_poParent->SetBitsWithMask(pBitmap, pMask, left, top, bitmap_alpha, blend_type);
}
virtual void SetGroupKnockout(bool group_knockout) override {
m_poParent->SetGroupKnockout(group_knockout);
}
#endif
#if defined _SKIA_SUPPORT_ || defined _SKIA_SUPPORT_PATHS_
virtual void Flush() override { return m_poParent->Flush(); }
Expand Down Expand Up @@ -1684,8 +1690,8 @@ void myRenderPageImpl(PDFDataset* poDS,
pContext->m_pDevice->SetBaseClip(clipping_rect);
pContext->m_pDevice->SetClip_Rect(clipping_rect);
pContext->m_pContext = std::make_unique<CPDF_RenderContext>(
pPage->GetDocument(), pPage->GetPageResources(),
static_cast<CPDF_PageRenderCache*>(pPage->GetRenderCache()));
pPage->GetDocument(), pPage->GetMutablePageResources(),
pPage->GetPageImageCache());

pContext->m_pContext->AppendLayer(pPage, matrix);

Expand Down Expand Up @@ -2456,9 +2462,9 @@ GDALPDFObject* PDFDataset::GetCatalog()
#ifdef HAVE_PDFIUM
if(bUseLib.test(PDFLIB_PDFIUM))
{
CPDF_Dictionary* catalog = poDocPdfium->doc->GetRoot();
const CPDF_Dictionary* catalog = poDocPdfium->doc->GetRoot();
if(catalog)
poCatalogObject = GDALPDFObjectPdfium::Build(catalog);
poCatalogObject = GDALPDFObjectPdfium::Build(pdfium::WrapRetain(catalog));
}
#endif // ~ HAVE_PDFIUM

Expand Down Expand Up @@ -4008,7 +4014,7 @@ void PDFDataset::TurnLayersOnOffPdfium()
{
if (oIter->second.first >= 0 )
{
//CPLDebug("PDF", "Turn '%s' off", papszLayersOFF[i]);
//CPLDebug("PDF", "Turn '%s' (%d,%d) off", papszLayersOFF[i], oIter->second.first, oIter->second.second);
oMapOCGNumGenToVisibilityStatePdfium[ oIter->second ] = VISIBILITY_OFF;
}

Expand Down Expand Up @@ -4594,7 +4600,7 @@ PDFDataset *PDFDataset::Open( GDALOpenInfo * poOpenInfo )
return nullptr;
}

CPDF_Object* pageObj = poPagePdfium->page->GetDict();
const auto pageObj = poPagePdfium->page->GetDict();
if(pageObj == nullptr) {
CPLError(CE_Failure, CPLE_AppDefined, "Invalid PDF : invalid page object");
UnloadPdfiumDocumentPage(&poDocPdfium, &poPagePdfium);
Expand Down Expand Up @@ -5105,7 +5111,8 @@ PDFDataset *PDFDataset::Open( GDALOpenInfo * poOpenInfo )
#ifdef HAVE_PDFIUM
if (bUseLib.test(PDFLIB_PDFIUM))
{
GDALPDFObjectPdfium* poRoot = GDALPDFObjectPdfium::Build(poDocPdfium->doc->GetRoot());
GDALPDFObjectPdfium* poRoot = GDALPDFObjectPdfium::Build(
pdfium::WrapRetain(poDocPdfium->doc->GetRoot()));
if(poRoot->GetType() == PDFObjectType_Dictionary) {
GDALPDFDictionary* poDict = poRoot->GetDictionary();
GDALPDFObject* poMetadata(poDict->Get("Metadata"));
Expand Down
Loading

0 comments on commit 3355dd4

Please sign in to comment.