This is an automated email from the ASF dual-hosted git repository. leginee pushed a commit to branch backport/pdfimport-pdfbox in repository https://gitbox.apache.org/repos/asf/openoffice.git
commit ccad9e1fa589b44c917ef4382c175f0a321953d9 Author: Peter <[email protected]> AuthorDate: Wed Sep 9 00:14:42 2026 +0200 build: build PDF import with PDFBox, and drop poppler Completes the backport: the extension now builds and packages under dmake, and the poppler backend is removed rather than kept alongside. configure.ac --enable-pdfimport no longer also demands --with-system-poppler, which was a gate nothing could satisfy in an Apache release -- poppler is GPLv2, so the else-branch switched the extension back off and no release build ever shipped PDF import. The backend is Apache-2.0 now, so the extension is on by default and follows Java instead, since the helper needs a JDK to build and a JRE to run. --with-system-poppler and the POPPLER_* substitutions are gone. external_deps.lst The four PDFBox 3.0.8 jars, conditional on ENABLE_PDFIMPORT: pdfbox, pdfbox-io, fontbox and commons-logging, which is the complete non-optional runtime closure. BouncyCastle is deliberately absent -- PDFBox marks it optional and only public-key encrypted PDFs reach it. sdext New pdfboxwrapper module builds the helper jar and stages the four downloaded jars beside it, because the extension's packaging rule copies every CONVERTER_FILE out of $(BIN). The helper is started as `java -jar`, so it finds them through the Class-Path in its own manifest, which means all five must land in one directory -- they do, in the extension, which is also where pdfbackend.cxx probes. CONVERTER_FILE was the poppler helper executable and is now those jars; the extension manifest no longer declares an executable member. wrapper/ gains pdfbackend.obj. xpdfwrapper/ and xpdftest/ are deleted. Note for anyone reading build.lst: wrapper/ builds a library called xpdfwrapper.lib -- that is ours, it is only the TARGET name in wrapper/makefile.mk. The poppler helper lived in xpdfwrapper/, a different directory. Removing the wrong one links a DLL with no wrapper in it. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01CH5PJJyJfirMStqJEZTxBD --- main/configure.ac | 45 +- main/external_deps.lst | 31 + main/sdext/prj/build.lst | 5 +- main/sdext/source/pdfimport/config/manifest.xml | 2 - main/sdext/source/pdfimport/makefile.mk | 12 +- .../source/pdfimport/pdfboxwrapper/makefile.mk | 82 ++ .../source/pdfimport/pdfboxwrapper/manifest.mf | 2 + main/sdext/source/pdfimport/wrapper/makefile.mk | 3 +- .../source/pdfimport/xpdftest/binary_0_out.def | Bin 80097 -> 0 bytes main/sdext/source/pdfimport/xpdftest/makefile.mk | 64 -- main/sdext/source/pdfimport/xpdftest/testinput.odp | Bin 44591 -> 0 bytes main/sdext/source/pdfimport/xpdftest/testinput.pdf | Bin 64488 -> 0 bytes .../sdext/source/pdfimport/xpdftest/text_0_out.def | 202 ----- .../sdext/source/pdfimport/xpdfwrapper/makefile.mk | 60 -- .../pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx | 936 --------------------- .../pdfimport/xpdfwrapper/pdfioutdev_gpl.hxx | 275 ------ .../source/pdfimport/xpdfwrapper/pnghelper.cxx | 406 --------- .../source/pdfimport/xpdfwrapper/pnghelper.hxx | 83 -- .../source/pdfimport/xpdfwrapper/wrapper_gpl.cxx | 178 ---- 19 files changed, 150 insertions(+), 2236 deletions(-) diff --git a/main/configure.ac b/main/configure.ac index f2994c9974..5e41ae74b0 100644 --- a/main/configure.ac +++ b/main/configure.ac @@ -469,9 +469,6 @@ AC_ARG_WITH(system-python, AC_ARG_WITH(system-icu, [ --with-system-icu Use icu already on system ],,) -AC_ARG_WITH(system-poppler, -[ --with-system-poppler Use poppler already on system -],,) AC_ARG_WITH(system-lucene, [ --with-system-lucene Use lucene already on system ],,) @@ -6912,33 +6909,31 @@ fi AC_SUBST(ENABLE_OPENGL) +dnl =================================================================== +dnl PDF Import extension. +dnl +dnl The backend is Apache PDFBox, which runs as a helper process; see +dnl sdext/source/pdfimport/PROTOCOL.md. It needs a JRE at run time and a JDK +dnl to build the helper, so this follows Java rather than a native library. +dnl +dnl The poppler backend it replaces is GPLv2, which may not be linked into an +dnl Apache-licensed soffice.bin. That is why this extension used to demand +dnl --with-system-poppler and switch itself off without it, so no release build +dnl ever shipped PDF import. Nothing here is licence-encumbered, so it is on +dnl by default. +dnl =================================================================== AC_MSG_CHECKING([whether to build the PDF Import extension]) -if test -n "$enable_pdfimport" -a "$enable_pdfimport" != "no"; then - AC_MSG_RESULT([yes]) - ENABLE_PDFIMPORT=YES - - dnl =================================================================== - dnl Check for system poppler - dnl =================================================================== - AC_MSG_CHECKING([whether to use system pdf backend]) - if test -n "$with_system_poppler" -o -n "$with_system_libs" && \ - test "$with_system_poppler" != "no"; then - AC_MSG_RESULT([external]) - SYSTEM_POPPLER=YES - PKG_CHECK_MODULES( POPPLER, poppler >= 0.8.0 ) - else - AC_MSG_RESULT([no]) - SYSTEM_POPPLER=NO - ENABLE_PDFIMPORT=NO - fi -else +if test "$enable_pdfimport" = "no"; then AC_MSG_RESULT([no]) ENABLE_PDFIMPORT=NO +elif test "$WITH_JAVA" = "no"; then + AC_MSG_RESULT([no (requires Java)]) + ENABLE_PDFIMPORT=NO +else + AC_MSG_RESULT([yes]) + ENABLE_PDFIMPORT=YES fi AC_SUBST(ENABLE_PDFIMPORT) -AC_SUBST(SYSTEM_POPPLER) -AC_SUBST(POPPLER_CFLAGS) -AC_SUBST(POPPLER_LIBS) AC_MSG_CHECKING([whether to build the Wiki Publisher extension]) if test -n "$enable_wiki_publisher" -a "$enable_wiki_publisher" != "no" && test "$WITH_JAVA" != "no"; then diff --git a/main/external_deps.lst b/main/external_deps.lst index a17b74299a..8d0a5fefc0 100644 --- a/main/external_deps.lst +++ b/main/external_deps.lst @@ -256,6 +256,37 @@ if ( true ) URL1 = https://sourceforge.net/projects/sampleicc/files/sampleicc/SampleIcc-1.6.11/SampleICC-1.6.11.zip/download URL2 = $(OOO_EXTRAS)$(MD5)-$(name) +# Apache PDFBox -- the PDF Import extension's parsing backend, run as a helper +# process (sdext/source/pdfimport/PROTOCOL.md). Apache-2.0, which is the point: +# it replaces poppler, whose GPLv2 licence kept PDF import out of every release +# build. These four are the complete non-optional runtime closure; BouncyCastle +# is deliberately absent, being optional to PDFBox and reached only by +# public-key encrypted PDFs. Java 8 bytecode. + +if (ENABLE_PDFIMPORT==YES) + MD5 = 92ed0441337f2ed1f43eeaa901bd7814 + name = pdfbox-3.0.8.jar + URL1 = https://repo1.maven.org/maven2/org/apache/pdfbox/pdfbox/3.0.8/$(name) + URL2 = $(OOO_EXTRAS)$(MD5)-$(name) + +if (ENABLE_PDFIMPORT==YES) + MD5 = f45a2386cf4178b5955dda2807139745 + name = pdfbox-io-3.0.8.jar + URL1 = https://repo1.maven.org/maven2/org/apache/pdfbox/pdfbox-io/3.0.8/$(name) + URL2 = $(OOO_EXTRAS)$(MD5)-$(name) + +if (ENABLE_PDFIMPORT==YES) + MD5 = 379e6faf6ea614ad3318eda879e4f423 + name = fontbox-3.0.8.jar + URL1 = https://repo1.maven.org/maven2/org/apache/pdfbox/fontbox/3.0.8/$(name) + URL2 = $(OOO_EXTRAS)$(MD5)-$(name) + +if (ENABLE_PDFIMPORT==YES) + MD5 = 954e27d33e55e587a4694d5952a0c5c6 + name = commons-logging-1.4.0.jar + URL1 = https://repo1.maven.org/maven2/commons-logging/commons-logging/1.4.0/$(name) + URL2 = $(OOO_EXTRAS)$(MD5)-$(name) + if (RAT_JAR_HOME==BUILD) MD5 = 0f926196d42577addec7e1aa5b510605 name = apache-rat-0.10-bin.tar.bz2 diff --git a/main/sdext/prj/build.lst b/main/sdext/prj/build.lst index 1d2b2fad3f..e5f60dcbf3 100644 --- a/main/sdext/prj/build.lst +++ b/main/sdext/prj/build.lst @@ -4,12 +4,11 @@ dx sdext\prj get - all sdext_prj NULL dx sdext\source\minimizer nmake - all sdext_minimizer sdext_inc NULL dx sdext\source\presenter nmake - all sdext_presenter sdext_inc NULL dx sdext\inc nmake - all sdext_inc NULL -dx sdext\source\pdfimport\xpdfwrapper nmake - all dx_xpdfwrap NULL -dx sdext\source\pdfimport\xpdftest nmake - all dx_parsetest dx_xpdfwrap NULL dx sdext\source\pdfimport\wrapper nmake - all sdext_pdfwrap sdext_inc NULL dx sdext\source\pdfimport\misc nmake - all sdext_misc sdext_inc NULL dx sdext\source\pdfimport\odf nmake - all sdext_odf sdext_inc NULL dx sdext\source\pdfimport\pdfparse nmake - all sdext_pdfparse sdext_inc NULL dx sdext\source\pdfimport\sax nmake - all sdext_sax sdext_inc NULL dx sdext\source\pdfimport\tree nmake - all sdext_tree sdext_inc NULL -dx sdext\source\pdfimport nmake - all sdext_pdfi sdext_pdfwrap sdext_misc sdext_odf sdext_pdfparse sdext_sax sdext_tree sdext_inc dx_xpdfwrap NULL +dx sdext\source\pdfimport\pdfboxwrapper nmake - all sdext_pdfbox sdext_inc NULL +dx sdext\source\pdfimport nmake - all sdext_pdfi sdext_pdfwrap sdext_misc sdext_odf sdext_pdfparse sdext_sax sdext_tree sdext_inc sdext_pdfbox NULL diff --git a/main/sdext/source/pdfimport/config/manifest.xml b/main/sdext/source/pdfimport/config/manifest.xml index 72172327de..ea8ef4fa9b 100644 --- a/main/sdext/source/pdfimport/config/manifest.xml +++ b/main/sdext/source/pdfimport/config/manifest.xml @@ -23,8 +23,6 @@ <manifest:manifest xmlns:manifest="http://openoffice.org/2001/manifest"> <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-component;type=native" manifest:full-path="pdfimport.unoSHARED_EXTENSION"/> - <manifest:file-entry manifest:media-type="application/vnd.sun.star.executable" - manifest:full-path="xpdfimportEXEC_EXTENSION"/> <manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data" manifest:full-path="pdf_import_filter.xcu"/> <manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data" diff --git a/main/sdext/source/pdfimport/makefile.mk b/main/sdext/source/pdfimport/makefile.mk index 3c41bd1291..3a0f0833a3 100644 --- a/main/sdext/source/pdfimport/makefile.mk +++ b/main/sdext/source/pdfimport/makefile.mk @@ -61,6 +61,9 @@ SHL1LIBS=\ $(SLB)$/pdfsax.lib \ $(SLB)$/pdfparsetree.lib \ $(SLB)$/pdfodf.lib \ +# NB: xpdfwrapper.lib is wrapper/, which is ours -- wrapper/makefile.mk +# still calls its TARGET that. The poppler helper was xpdfwrapper/, a +# different directory, and is gone. $(SLB)$/xpdfwrapper.lib \ $(SLB)$/$(TARGET).lib @@ -101,8 +104,15 @@ COMPONENT_XCU= \ $(EXTENSIONDIR)$/pdf_import_filter.xcu \ $(EXTENSIONDIR)$/pdf_types.xcu +# The backend, and the jars it needs, packed into the extension. +# pdfbackend.cxx probes the extension directory for pdfimport-pdfbox.jar, so +# this is the lookup path rather than a convention. CONVERTER_FILE= \ - $(EXTENSIONDIR)$/xpdfimport$(EXECPOST) + $(EXTENSIONDIR)$/pdfimport-pdfbox.jar \ + $(EXTENSIONDIR)$/pdfbox-3.0.8.jar \ + $(EXTENSIONDIR)$/pdfbox-io-3.0.8.jar \ + $(EXTENSIONDIR)$/fontbox-3.0.8.jar \ + $(EXTENSIONDIR)$/commons-logging-1.4.0.jar COMPONENT_DIALOGS= \ $(EXTENSIONDIR)$/basic$/Module1.xba \ diff --git a/main/sdext/source/pdfimport/pdfboxwrapper/makefile.mk b/main/sdext/source/pdfimport/pdfboxwrapper/makefile.mk new file mode 100644 index 0000000000..d590f53bc4 --- /dev/null +++ b/main/sdext/source/pdfimport/pdfboxwrapper/makefile.mk @@ -0,0 +1,82 @@ +#************************************************************** +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +#************************************************************** + +PRJ=..$/..$/.. + +PRJNAME=sdext +TARGET=pdfimport-pdfbox +PACKAGE=org$/apache$/openoffice$/pdfimport + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +.IF "$(ENABLE_PDFIMPORT)" == "NO" || "$(SOLAR_JAVA)" == "" + +all: + @echo "PDF Import extension disabled." + +.ELSE + +# The four jars are downloaded by external_deps.lst into $(TARFILE_LOCATION). +# They are needed twice over: on the compile classpath here, and in the +# extension at run time, since the helper is started as `java -jar` and reaches +# them through the Class-Path in its own manifest. +PDFBOX_JARNAMES= \ + pdfbox-3.0.8.jar \ + pdfbox-io-3.0.8.jar \ + fontbox-3.0.8.jar \ + commons-logging-1.4.0.jar + +PDFBOX_JARS=$(foreach,i,$(PDFBOX_JARNAMES) $(TARFILE_LOCATION)$/$(i)) +DELIVERED_JARS=$(foreach,i,$(PDFBOX_JARNAMES) $(BIN)$/$(i)) + +# --- Files -------------------------------------------------------- + +JAVAFILES= \ + src$/$(PACKAGE)$/Main.java \ + src$/$(PACKAGE)$/PdfiEngine.java \ + src$/$(PACKAGE)$/PdfiWriter.java + +JAVACLASSFILES=$(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) + +# javac needs PDFBox on the classpath; the office's own jars are irrelevant +# here, as the helper is a plain process and links no UNO. +XCLASSPATH!:=$(XCLASSPATH)$(PATH_SEPERATOR)$(PDFBOX_JARS:t"$(PATH_SEPERATOR)") + +JARCLASSDIRS=org +JARTARGET=$(TARGET).jar +JARCOMPRESS=TRUE +CUSTOMMANIFESTFILE=manifest.mf + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + +# Stage the downloaded jars beside the built one, because the extension's +# packaging rule in ../makefile.mk copies every CONVERTER_FILE out of $(BIN). +ALLTAR : $(DELIVERED_JARS) + +$(DELIVERED_JARS) : $(TARFILE_LOCATION)$/$$(@:f) + @@-$(MKDIRHIER) $(@:d) + $(COPY) $< $@ + +.ENDIF # ENABLE_PDFIMPORT diff --git a/main/sdext/source/pdfimport/pdfboxwrapper/manifest.mf b/main/sdext/source/pdfimport/pdfboxwrapper/manifest.mf new file mode 100644 index 0000000000..f36a85c4b8 --- /dev/null +++ b/main/sdext/source/pdfimport/pdfboxwrapper/manifest.mf @@ -0,0 +1,2 @@ +Main-Class: org.apache.openoffice.pdfimport.Main +Class-Path: pdfbox-3.0.8.jar pdfbox-io-3.0.8.jar fontbox-3.0.8.jar commons-logging-1.4.0.jar diff --git a/main/sdext/source/pdfimport/wrapper/makefile.mk b/main/sdext/source/pdfimport/wrapper/makefile.mk index aaef506a31..76ef640e17 100644 --- a/main/sdext/source/pdfimport/wrapper/makefile.mk +++ b/main/sdext/source/pdfimport/wrapper/makefile.mk @@ -37,7 +37,8 @@ CDEFS+= -DPDFI_IMPL_IDENTIFIER=$(IMPLEMENTATION_IDENTIFIER) # --- Files -------------------------------------------------------- SLOFILES=\ - $(SLO)$/wrapper.obj + $(SLO)$/wrapper.obj \ + $(SLO)$/pdfbackend.obj # --- Targets ------------------------------------------------------ diff --git a/main/sdext/source/pdfimport/xpdftest/binary_0_out.def b/main/sdext/source/pdfimport/xpdftest/binary_0_out.def deleted file mode 100644 index 3729d923af..0000000000 Binary files a/main/sdext/source/pdfimport/xpdftest/binary_0_out.def and /dev/null differ diff --git a/main/sdext/source/pdfimport/xpdftest/makefile.mk b/main/sdext/source/pdfimport/xpdftest/makefile.mk deleted file mode 100644 index 046f671475..0000000000 --- a/main/sdext/source/pdfimport/xpdftest/makefile.mk +++ /dev/null @@ -1,64 +0,0 @@ -#************************************************************** -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -#************************************************************** - - - -PRJ=..$/..$/.. -PRJNAME=sdext -TARGET=xpdftest -TARGETTYPE=CUI -ENABLE_EXCEPTIONS=TRUE - -# --- Settings ----------------------------------------------------- - -.INCLUDE: settings.mk - -.IF "$(ENABLE_PDFIMPORT)" == "NO" -@all: - @echo "PDF Import extension disabled." -.ENDIF - -# --- Targets ------------------------------------------------------ - -.INCLUDE : target.mk - -#ALLTAR : $(MISC)$/test_0_succeeded - -$(MISC)$/test_0_succeeded: $(BIN)$/xpdfimport$(EXECPOST) binary_0_out.def text_0_out.def testinput.pdf - $(BIN)$/xpdfimport -f $(MISC)$/binary_0_out testinput.pdf > $(MISC)$/text_0_out - diff --strip-trailing-cr $(MISC)$/binary_0_out binary_0_out.def - diff --strip-trailing-cr $(MISC)$/text_0_out text_0_out.def - $(TOUCH) $@ - -# This test is disabled because -# - the PDF import extension is not part of the AOO build #i118592# -# - the test files are too huge (75MB + 5MB + 500kB) to remain in the tree -# The test files are still available at -# http://svn.apache.org/repos/asf/!svn/bc/1500000/openoffice/tags/AOO341/main/sdext/source/pdfimport/xpdftest/binary_1_out.def -# http://svn.apache.org/repos/asf/!svn/bc/1500000/openoffice/tags/AOO341/main/sdext/source/pdfimport/xpdftest/text_1_out.def -# http://svn.apache.org/repos/asf/!svn/bc/1500000/openoffice/tags/AOO341/main/sdext/source/pdfimport/xpdftest/book.pdf -# if you download them you can enable the test below: - -#$(MISC)$/test_1_succeeded: $(BIN)$/xpdfimport$(EXECPOST) binary_1_out.def text_1_out.def book.pdf -# $(BIN)$/xpdfimport -f $(MISC)$/binary_1_out book.pdf > $(MISC)$/text_1_out -# diff --strip-trailing-cr $(MISC)$/binary_1_out binary_1_out.def -# diff --strip-trailing-cr $(MISC)$/text_1_out text_1_out.def -# $(TOUCH) $@ diff --git a/main/sdext/source/pdfimport/xpdftest/testinput.odp b/main/sdext/source/pdfimport/xpdftest/testinput.odp deleted file mode 100644 index fdfa53a8cf..0000000000 Binary files a/main/sdext/source/pdfimport/xpdftest/testinput.odp and /dev/null differ diff --git a/main/sdext/source/pdfimport/xpdftest/testinput.pdf b/main/sdext/source/pdfimport/xpdftest/testinput.pdf deleted file mode 100644 index c1a1b84cea..0000000000 Binary files a/main/sdext/source/pdfimport/xpdftest/testinput.pdf and /dev/null differ diff --git a/main/sdext/source/pdfimport/xpdftest/text_0_out.def b/main/sdext/source/pdfimport/xpdftest/text_0_out.def deleted file mode 100644 index 2c9e52fa2f..0000000000 --- a/main/sdext/source/pdfimport/xpdftest/text_0_out.def +++ /dev/null @@ -1,202 +0,0 @@ -setPageNum 1 -startPage 79400.000000 59500.000000 -updateCtm 100.000000 0.000000 0.000000 -100.000000 0.000000 59500.000000 -updateLineDash -updateFlatness 1 -updateLineJoin 0 -updateLineCap 0 -updateMiterLimit 10.000000 -updateLineWidth 1.000000 -updateFillColor 0.000000 0.000000 0.000000 1.000000 -updateStrokeColor 0.000000 0.000000 0.000000 1.000000 -updateFillColor 0.000000 0.000000 0.000000 1.000000 -updateStrokeColor 0.000000 0.000000 0.000000 1.000000 -clipPath subpath 1 0.000000 0.000000 0 794.000000 0.000000 0 794.000000 595.000000 0 0.000000 595.000000 0 0.000000 0.000000 0 -saveState -updateLineWidth 0.100000 -saveState -eoClipPath subpath 1 0.000000 -0.300000 0 793.800000 -0.300000 0 793.800000 595.000000 0 0.000000 595.000000 0 0.000000 -0.300000 0 -saveState -updateFillColor 0.000000 0.000000 0.000000 1.000000 -updateFont 21 1 0 0 0 1400.000000 11128 BAAAAA+DejaVuSerif -drawChar 39.700000 52.692000 44.138000 38.692000 1.000000 0.000000 0.000000 1.000000 -endTextObject -restoreState -saveState -updateFillColor 0.000000 0.000000 0.000000 1.000000 -updateFont 21 1 0 0 0 1400.000000 0 BAAAAA+DejaVuSerif -drawChar 395.000000 52.692000 399.438000 38.692000 1.000000 0.000000 0.000000 1.000000 -endTextObject -restoreState -updateStrokeColor 0.000000 0.000000 0.000000 1.000000 -saveState -updateLineWidth 0.000000 -updateLineCap 0 -updateLineJoin 1 -updateLineDash 0.000000 4 14.376390 14.376390 14.376390 14.376390 -strokePath subpath 0 498.900000 538.300000 0 144.600000 297.400000 0 -restoreState -saveState -updateFillColor 0.000000 0.000000 0.000000 1.000000 -updateFont 16 1 0 0 0 1800.000000 23060 CAAAAA+DejaVuSans -drawChar 35.400000 466.704000 46.380000 448.704000 1.000000 0.000000 0.000000 1.000000 T -drawChar 46.398000 466.704000 57.792000 448.704000 1.000000 0.000000 0.000000 1.000000 h -drawChar 57.792000 466.704000 62.778000 448.704000 1.000000 0.000000 0.000000 1.000000 i -drawChar 62.796000 466.704000 72.156000 448.704000 1.000000 0.000000 0.000000 1.000000 s -drawChar 72.192000 466.704000 77.898000 448.704000 1.000000 0.000000 0.000000 1.000000 -drawChar 77.898000 466.704000 82.884000 448.704000 1.000000 0.000000 0.000000 1.000000 i -drawChar 82.902000 466.704000 92.262000 448.704000 1.000000 0.000000 0.000000 1.000000 s -drawChar 92.298000 466.704000 98.004000 448.704000 1.000000 0.000000 0.000000 1.000000 -drawChar 98.004000 466.704000 109.020000 448.704000 1.000000 0.000000 0.000000 1.000000 a -drawChar 109.002000 466.704000 114.708000 448.704000 1.000000 0.000000 0.000000 1.000000 -drawChar 114.708000 466.704000 121.764000 448.704000 1.000000 0.000000 0.000000 1.000000 t -drawChar 121.800000 466.704000 132.870000 448.704000 1.000000 0.000000 0.000000 1.000000 e -drawChar 132.906000 466.704000 142.266000 448.704000 1.000000 0.000000 0.000000 1.000000 s -drawChar 142.302000 466.704000 149.358000 448.704000 1.000000 0.000000 0.000000 1.000000 t -drawChar 149.394000 466.704000 156.450000 448.704000 1.000000 0.000000 0.000000 1.000000 t -drawChar 156.486000 466.704000 167.556000 448.704000 1.000000 0.000000 0.000000 1.000000 e -drawChar 167.286000 466.704000 177.924000 448.704000 1.000000 0.000000 0.000000 1.000000 x -drawChar 177.978000 466.704000 185.034000 448.704000 1.000000 0.000000 0.000000 1.000000 t -endTextObject -restoreState -saveState -updateFillColor 0.000000 0.000000 0.000000 1.000000 -updateFont 16 1 0 0 0 1800.000000 0 CAAAAA+DejaVuSans -drawChar 35.400000 445.804000 48.864000 427.804000 1.000000 0.000000 0.000000 1.000000 N -drawChar 48.900000 445.804000 59.970000 427.804000 1.000000 0.000000 0.000000 1.000000 e -drawChar 60.006000 445.804000 74.712000 427.804000 1.000000 0.000000 0.000000 1.000000 w -drawChar 74.712000 445.804000 80.418000 427.804000 1.000000 0.000000 0.000000 1.000000 -drawChar 80.418000 445.804000 91.830000 427.804000 1.000000 0.000000 0.000000 1.000000 p -drawChar 91.812000 445.804000 102.828000 427.804000 1.000000 0.000000 0.000000 1.000000 a -drawChar 102.810000 445.804000 110.208000 427.804000 1.000000 0.000000 0.000000 1.000000 r -drawChar 110.208000 445.804000 121.224000 427.804000 1.000000 0.000000 0.000000 1.000000 a -drawChar 121.206000 445.804000 132.618000 427.804000 1.000000 0.000000 0.000000 1.000000 g -drawChar 132.600000 445.804000 139.998000 427.804000 1.000000 0.000000 0.000000 1.000000 r -drawChar 139.998000 445.804000 151.014000 427.804000 1.000000 0.000000 0.000000 1.000000 a -drawChar 150.996000 445.804000 162.408000 427.804000 1.000000 0.000000 0.000000 1.000000 p -drawChar 162.390000 445.804000 173.784000 427.804000 1.000000 0.000000 0.000000 1.000000 h -drawChar 173.784000 445.804000 179.490000 427.804000 1.000000 0.000000 0.000000 1.000000 , -endTextObject -restoreState -saveState -updateFillColor 0.000000 0.000000 0.000000 1.000000 -updateFont 16 1 0 0 0 1800.000000 0 CAAAAA+DejaVuSans -drawChar 35.400000 425.004000 46.794000 407.004000 1.000000 0.000000 0.000000 1.000000 n -drawChar 46.794000 425.004000 57.864000 407.004000 1.000000 0.000000 0.000000 1.000000 e -drawChar 57.900000 425.004000 72.606000 407.004000 1.000000 0.000000 0.000000 1.000000 w -drawChar 72.606000 425.004000 78.312000 407.004000 1.000000 0.000000 0.000000 1.000000 -drawChar 78.312000 425.004000 83.298000 407.004000 1.000000 0.000000 0.000000 1.000000 l -drawChar 83.316000 425.004000 88.302000 407.004000 1.000000 0.000000 0.000000 1.000000 i -drawChar 88.320000 425.004000 99.714000 407.004000 1.000000 0.000000 0.000000 1.000000 n -drawChar 99.714000 425.004000 110.784000 407.004000 1.000000 0.000000 0.000000 1.000000 e -endTextObject -restoreState -saveState -updateFillColor 0.000000 0.000000 0.501953 1.000000 -updateFont 16 1 0 0 0 1800.000000 0 CAAAAA+DejaVuSans -drawChar 35.400000 404.104000 48.918000 386.104000 1.000000 0.000000 0.000000 1.000000 H -drawChar 48.900000 404.104000 59.538000 386.104000 1.000000 0.000000 0.000000 1.000000 y -drawChar 59.592000 404.104000 71.004000 386.104000 1.000000 0.000000 0.000000 1.000000 p -drawChar 70.986000 404.104000 82.056000 386.104000 1.000000 0.000000 0.000000 1.000000 e -drawChar 82.092000 404.104000 89.490000 386.104000 1.000000 0.000000 0.000000 1.000000 r -drawChar 89.490000 404.104000 94.476000 386.104000 1.000000 0.000000 0.000000 1.000000 l -drawChar 94.494000 404.104000 99.480000 386.104000 1.000000 0.000000 0.000000 1.000000 i -drawChar 99.498000 404.104000 110.892000 386.104000 1.000000 0.000000 0.000000 1.000000 n -drawChar 110.892000 404.104000 121.314000 386.104000 1.000000 0.000000 0.000000 1.000000 k -drawChar 121.296000 404.104000 127.002000 386.104000 1.000000 0.000000 0.000000 1.000000 , -drawChar 127.002000 404.104000 132.708000 386.104000 1.000000 0.000000 0.000000 1.000000 -drawChar 132.708000 404.104000 139.764000 386.104000 1.000000 0.000000 0.000000 1.000000 t -drawChar 139.800000 404.104000 151.194000 386.104000 1.000000 0.000000 0.000000 1.000000 h -drawChar 151.194000 404.104000 156.180000 386.104000 1.000000 0.000000 0.000000 1.000000 i -drawChar 156.198000 404.104000 165.558000 386.104000 1.000000 0.000000 0.000000 1.000000 s -drawChar 165.594000 404.104000 171.300000 386.104000 1.000000 0.000000 0.000000 1.000000 -drawChar 171.300000 404.104000 176.286000 386.104000 1.000000 0.000000 0.000000 1.000000 i -drawChar 176.304000 404.104000 185.664000 386.104000 1.000000 0.000000 0.000000 1.000000 s -endTextObject -restoreState -saveState -updateFillColor 0.000000 0.000000 0.000000 1.000000 -updateFont 11 1 0 0 0 1440.000000 1780 DAAAAA+OpenSymbol -drawChar 405.400000 244.990400 416.833600 230.590400 1.000000 0.000000 0.000000 1.000000 ● -endTextObject -restoreState -saveState -updateFillColor 0.000000 0.000000 0.000000 1.000000 -updateFont 16 1 0 0 0 3200.000000 0 CAAAAA+DejaVuSans -drawChar 430.900000 254.796000 450.420000 222.796000 1.000000 0.000000 0.000000 1.000000 T -drawChar 450.388000 254.796000 470.644000 222.796000 1.000000 0.000000 0.000000 1.000000 h -drawChar 470.676000 254.796000 479.540000 222.796000 1.000000 0.000000 0.000000 1.000000 i -drawChar 479.572000 254.796000 496.212000 222.796000 1.000000 0.000000 0.000000 1.000000 s -drawChar 496.276000 254.796000 506.420000 222.796000 1.000000 0.000000 0.000000 1.000000 -drawChar 506.484000 254.796000 515.348000 222.796000 1.000000 0.000000 0.000000 1.000000 i -drawChar 515.380000 254.796000 532.020000 222.796000 1.000000 0.000000 0.000000 1.000000 s -drawChar 532.084000 254.796000 542.228000 222.796000 1.000000 0.000000 0.000000 1.000000 -drawChar 542.292000 254.796000 573.460000 222.796000 1.000000 0.000000 0.000000 1.000000 m -drawChar 573.492000 254.796000 593.044000 222.796000 1.000000 0.000000 0.000000 1.000000 o -drawChar 593.108000 254.796000 606.260000 222.796000 1.000000 0.000000 0.000000 1.000000 r -drawChar 605.620000 254.796000 625.300000 222.796000 1.000000 0.000000 0.000000 1.000000 e -drawChar 625.332000 254.796000 635.476000 222.796000 1.000000 0.000000 0.000000 1.000000 -drawChar 635.540000 254.796000 648.084000 222.796000 1.000000 0.000000 0.000000 1.000000 t -drawChar 648.052000 254.796000 667.732000 222.796000 1.000000 0.000000 0.000000 1.000000 e -drawChar 667.156000 254.796000 686.068000 222.796000 1.000000 0.000000 0.000000 1.000000 x -drawChar 686.068000 254.796000 698.612000 222.796000 1.000000 0.000000 0.000000 1.000000 t -endTextObject -restoreState -saveState -updateFillColor 0.000000 0.000000 0.000000 1.000000 -updateFont 16 1 0 0 0 3200.000000 0 CAAAAA+DejaVuSans -drawChar 430.900000 217.396000 450.452000 185.396000 1.000000 0.000000 0.000000 1.000000 o -drawChar 450.516000 217.396000 470.772000 185.396000 1.000000 0.000000 0.000000 1.000000 u -drawChar 470.804000 217.396000 483.348000 185.396000 1.000000 0.000000 0.000000 1.000000 t -drawChar 483.316000 217.396000 492.180000 185.396000 1.000000 0.000000 0.000000 1.000000 l -drawChar 492.212000 217.396000 501.076000 185.396000 1.000000 0.000000 0.000000 1.000000 i -drawChar 501.108000 217.396000 521.364000 185.396000 1.000000 0.000000 0.000000 1.000000 n -drawChar 521.396000 217.396000 541.076000 185.396000 1.000000 0.000000 0.000000 1.000000 e -drawChar 541.108000 217.396000 551.252000 185.396000 1.000000 0.000000 0.000000 1.000000 -drawChar 551.316000 217.396000 582.484000 185.396000 1.000000 0.000000 0.000000 1.000000 m -drawChar 582.516000 217.396000 602.068000 185.396000 1.000000 0.000000 0.000000 1.000000 o -drawChar 602.132000 217.396000 622.420000 185.396000 1.000000 0.000000 0.000000 1.000000 d -drawChar 622.420000 217.396000 642.100000 185.396000 1.000000 0.000000 0.000000 1.000000 e -endTextObject -restoreState -saveState -updateFillColor 0.000000 0.000000 0.000000 1.000000 -updateFont 11 1 0 0 0 1440.000000 0 DAAAAA+OpenSymbol -drawChar 405.400000 156.190400 416.833600 141.790400 1.000000 0.000000 0.000000 1.000000 ● -endTextObject -restoreState -saveState -updateFillColor 0.000000 0.000000 0.000000 1.000000 -updateFont 16 1 0 0 0 3200.000000 0 CAAAAA+DejaVuSans -drawChar 430.900000 165.896000 454.836000 133.896000 1.000000 0.000000 0.000000 1.000000 N -drawChar 454.804000 165.896000 474.484000 133.896000 1.000000 0.000000 0.000000 1.000000 e -drawChar 474.516000 165.896000 500.660000 133.896000 1.000000 0.000000 0.000000 1.000000 w -drawChar 500.724000 165.896000 510.868000 133.896000 1.000000 0.000000 0.000000 1.000000 -drawChar 510.932000 165.896000 531.220000 133.896000 1.000000 0.000000 0.000000 1.000000 p -drawChar 531.220000 165.896000 550.804000 133.896000 1.000000 0.000000 0.000000 1.000000 a -drawChar 550.836000 165.896000 563.988000 133.896000 1.000000 0.000000 0.000000 1.000000 r -drawChar 564.052000 165.896000 583.636000 133.896000 1.000000 0.000000 0.000000 1.000000 a -drawChar 583.668000 165.896000 603.956000 133.896000 1.000000 0.000000 0.000000 1.000000 g -drawChar 603.956000 165.896000 617.108000 133.896000 1.000000 0.000000 0.000000 1.000000 r -drawChar 617.172000 165.896000 636.756000 133.896000 1.000000 0.000000 0.000000 1.000000 a -drawChar 636.788000 165.896000 657.076000 133.896000 1.000000 0.000000 0.000000 1.000000 p -drawChar 657.076000 165.896000 677.332000 133.896000 1.000000 0.000000 0.000000 1.000000 h -endTextObject -restoreState -updateFillColor 1.000000 0.000000 0.000000 1.000000 -eoFillPath subpath 1 120.500000 98.900000 0 77.400000 98.900000 1 42.500000 133.800000 1 42.500000 176.900000 0 42.500000 219.900000 1 77.400000 254.800000 1 120.500000 254.800000 0 163.500000 254.800000 1 198.400000 219.900000 1 198.400000 176.900000 0 198.400000 133.800000 1 163.500000 98.900000 1 120.500000 98.900000 0 -saveState -updateCtm 22680.000000 0.000000 0.000000 -14740.000000 49610.000000 27490.000000 -drawImage 800 600 0 JPEG 44129 -restoreState -updateStrokeColor 0.000000 1.000000 0.000000 1.000000 -saveState -updateLineWidth 28.299990 -updateLineCap 0 -updateLineJoin 1 -strokePath subpath 0 535.700000 518.500000 0 181.400000 277.500000 0 -restoreState -restoreState -restoreState -endPage -drawLink 36.500000 383.600000 185.600000 401.000000 http://download.openoffice.org/ diff --git a/main/sdext/source/pdfimport/xpdfwrapper/makefile.mk b/main/sdext/source/pdfimport/xpdfwrapper/makefile.mk deleted file mode 100644 index 9973439d02..0000000000 --- a/main/sdext/source/pdfimport/xpdfwrapper/makefile.mk +++ /dev/null @@ -1,60 +0,0 @@ -#************************************************************** -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -#************************************************************** - - - -PRJ=..$/..$/.. - -PRJNAME=sdext -TARGET=xpdfimport -TARGETTYPE=CUI -ENABLE_EXCEPTIONS=TRUE -EXTERNAL_WARNINGS_NOT_ERRORS := TRUE - -# --- Settings ----------------------------------------------------- - -.INCLUDE: settings.mk - -.IF "$(SYSTEM_ZLIB)" == "YES" -CFLAGS+=-DSYSTEM_ZLIB -.ENDIF - -.IF "$(ENABLE_PDFIMPORT)" == "NO" || "$(SYSTEM_POPPLER)" != "YES" -@all: - @echo "PDF Import extension disabled." -.ENDIF - -CFLAGS += $(POPPLER_CFLAGS) - -# --- Files -------------------------------------------------------- -UWINAPILIB:= -APP1TARGET=$(TARGET) -APP1LIBSALCPPRT= -APP1OBJS= \ - $(OBJ)$/wrapper_gpl.obj $(OBJ)/pdfioutdev_gpl.obj $(OBJ)/pnghelper.obj - -APP1STDLIBS+=$(ZLIB3RDLIB) - -APP1STDLIBS+=$(POPPLER_LIBS) - -# --- Targets ------------------------------------------------------ - -.INCLUDE : target.mk diff --git a/main/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx b/main/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx deleted file mode 100644 index 4b307bfbf8..0000000000 --- a/main/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx +++ /dev/null @@ -1,936 +0,0 @@ -/************************************************************** - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - *************************************************************/ - -#include "pdfioutdev_gpl.hxx" -#include "pnghelper.hxx" - -#include <stdlib.h> -#include <stdio.h> -#include <assert.h> -#include <math.h> -#include <vector> - -#include <boost/shared_array.hpp> - -#if defined __SUNPRO_CC -#pragma disable_warn -#elif defined _MSC_VER -#pragma warning(push, 1) -#endif - -#include "UTF8.h" - -#if defined __SUNPRO_CC -#pragma enable_warn -#elif defined _MSC_VER -#pragma warning(pop) -#endif - -#ifdef WNT -# define snprintf _snprintf -#endif - - -/* SYNC STREAMS - ============ - - We stream human-readble tokens to stdout, and binary data (fonts, - bitmaps) to g_binary_out. Another process reads from those pipes, and - there lies the rub: things can deadlock, if the two involved - processes access the pipes in different order. At any point in - time, both processes must access the same pipe. To ensure this, - data must be flushed to the OS before writing to a different pipe, - otherwise not-yet-written data will leave the reading process - waiting on the wrong pipe. - */ - -namespace pdfi -{ - -/// cut off very small numbers & clamp value to zero -inline double normalize( double val ) -{ - return fabs(val) < 0.0000001 ? 0.0 : val; -} - -namespace -{ - -/** Escapes line-ending characters (\n and \r) in input string. - */ -boost::shared_array<char> lcl_escapeLineFeeds(const char* const i_pStr) -{ - size_t nLength(strlen(i_pStr)); - char* pBuffer = new char[2*nLength+1]; - - const char* pRead = i_pStr; - char* pWrite = pBuffer; - while( nLength-- ) - { - if( *pRead == '\r' ) - { - *pWrite++ = '\\'; - *pWrite++ = 'r'; - } - else if( *pRead == '\n' ) - { - *pWrite++ = '\\'; - *pWrite++ = 'n'; - } - else if( *pRead == '\\' ) - { - *pWrite++ = '\\'; - *pWrite++ = '\\'; - } - else - *pWrite++ = *pRead; - pRead++; - } - *pWrite++ = 0; - - return boost::shared_array<char>(pBuffer); -} - -} - -/// for the temp char buffer the header gets snprintfed in -#define WRITE_BUFFER_SIZE 1024 - -/// for the initial std::vector capacity when copying stream from xpdf -#define WRITE_BUFFER_INITIAL_CAPACITY (1024*100) - -void initBuf(OutputBuffer& io_rBuffer) -{ - io_rBuffer.reserve(WRITE_BUFFER_INITIAL_CAPACITY); -} - -void writeBinaryBuffer( const OutputBuffer& rBuffer ) -{ - // ---sync point--- see SYNC STREAMS above - fflush(stdout); - - // put buffer to stderr - if( !rBuffer.empty() ) - if( fwrite(&rBuffer[0], sizeof(char), - rBuffer.size(), g_binary_out) != (size_t)rBuffer.size() ) - exit(1); // error - - // ---sync point--- see SYNC STREAMS above - fflush(g_binary_out); -} - -void writeJpeg_( OutputBuffer& o_rOutputBuf, Stream* str, bool bWithLinefeed ) -{ - // dump JPEG file as-is - str->reset(); - - int c; - o_rOutputBuf.clear(); - while((c=str->getChar()) != EOF) - o_rOutputBuf.push_back(static_cast<char>(c)); - - printf( " JPEG %d", (int)o_rOutputBuf.size() ); - if( bWithLinefeed ) - printf("\n"); - - str->close(); -} - -void writePbm_(OutputBuffer& o_rOutputBuf, Stream* str, int width, int height, bool bWithLinefeed, bool bInvert ) -{ - // write as PBM (char by char, to avoid stdlib lineend messing) - o_rOutputBuf.clear(); - o_rOutputBuf.resize(WRITE_BUFFER_SIZE); - o_rOutputBuf[0] = 'P'; - o_rOutputBuf[1] = '4'; - o_rOutputBuf[2] = 0x0A; - int nOutLen = snprintf(&o_rOutputBuf[3], WRITE_BUFFER_SIZE-10, "%d %d", width, height); - if( nOutLen < 0 ) - nOutLen = WRITE_BUFFER_SIZE-10; - o_rOutputBuf[3+nOutLen] =0x0A; - o_rOutputBuf[3+nOutLen+1]=0; - - const int header_size = 3+nOutLen+1; - const int size = height * ((width + 7) / 8); - - printf( " PBM %d", size + header_size ); - if( bWithLinefeed ) - printf("\n"); - - // trim buffer to exact header length - o_rOutputBuf.resize(header_size); - - // initialize stream - str->reset(); - - // copy the raw stream - if( bInvert ) - { - for( int i=0; i<size; ++i) - o_rOutputBuf.push_back(static_cast<char>(str->getChar() ^ 0xff)); - } - else - { - for( int i=0; i<size; ++i) - o_rOutputBuf.push_back(static_cast<char>(str->getChar())); - } - - str->close(); -} - -void writePpm_( OutputBuffer& o_rOutputBuf, - Stream* str, - int width, - int height, - GfxImageColorMap* colorMap, - bool bWithLinefeed ) -{ - // write as PPM (char by char, to avoid stdlib lineend messing) - o_rOutputBuf.clear(); - o_rOutputBuf.resize(WRITE_BUFFER_SIZE); - o_rOutputBuf[0] = 'P'; - o_rOutputBuf[1] = '6'; - o_rOutputBuf[2] = '\n'; - int nOutLen = snprintf(&o_rOutputBuf[3], WRITE_BUFFER_SIZE-10, "%d %d", width, height); - if( nOutLen < 0 ) - nOutLen = WRITE_BUFFER_SIZE-10; - o_rOutputBuf[3+nOutLen] ='\n'; - o_rOutputBuf[3+nOutLen+1]='2'; - o_rOutputBuf[3+nOutLen+2]='5'; - o_rOutputBuf[3+nOutLen+3]='5'; - o_rOutputBuf[3+nOutLen+4]='\n'; - o_rOutputBuf[3+nOutLen+5]=0; - - const int header_size = 3+nOutLen+5; - const int size = width*height*3 + header_size; - - printf( " PPM %d", size ); - if( bWithLinefeed ) - printf("\n"); - - // trim buffer to exact header size - o_rOutputBuf.resize(header_size); - - // initialize stream - Guchar *p; - GfxRGB rgb; - ImageStream* imgStr = - new ImageStream(str, - width, - colorMap->getNumPixelComps(), - colorMap->getBits()); - imgStr->reset(); - - for( int y=0; y<height; ++y) - { - p = imgStr->getLine(); - for( int x=0; x<width; ++x) - { - colorMap->getRGB(p, &rgb); - o_rOutputBuf.push_back(colToByte(rgb.r)); - o_rOutputBuf.push_back(colToByte(rgb.g)); - o_rOutputBuf.push_back(colToByte(rgb.b)); - - p +=colorMap->getNumPixelComps(); - } - } - - delete imgStr; - -} - -// call this only for 1 bit image streams ! -void writePng_( OutputBuffer& o_rOutputBuf, - Stream* str, - int width, - int height, - GfxRGB& zeroColor, - GfxRGB& oneColor, - bool bIsMask, - bool bWithLinefeed ) -{ - o_rOutputBuf.clear(); - - // get png image - PngHelper::createPng( o_rOutputBuf, str, width, height, zeroColor, oneColor, bIsMask ); - - printf( " PNG %d", (int)o_rOutputBuf.size() ); - if( bWithLinefeed ) - printf("\n"); -} - -void writePng_( OutputBuffer& o_rOutputBuf, - Stream* str, - int width, int height, GfxImageColorMap* colorMap, - Stream* maskStr, - int maskWidth, int maskHeight, GfxImageColorMap* maskColorMap, - bool bWithLinefeed ) -{ - o_rOutputBuf.clear(); - - // get png image - PngHelper::createPng( o_rOutputBuf, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap ); - - printf( " PNG %d", (int)o_rOutputBuf.size() ); - if( bWithLinefeed ) - printf("\n"); -} - -void writePng_( OutputBuffer& o_rOutputBuf, - Stream* str, - int width, int height, GfxImageColorMap* colorMap, - Stream* maskStr, - int maskWidth, int maskHeight, bool maskInvert, - bool bWithLinefeed ) -{ - o_rOutputBuf.clear(); - - // get png image - PngHelper::createPng( o_rOutputBuf, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert ); - - printf( " PNG %d", (int)o_rOutputBuf.size() ); - if( bWithLinefeed ) - printf("\n"); -} - -// stolen from ImageOutputDev.cc -void writeMask_( OutputBuffer& o_rOutputBuf, Stream* str, int width, int height, bool bWithLinefeed, bool bInvert ) -{ - if( str->getKind() == strDCT ) - writeJpeg_(o_rOutputBuf, str, bWithLinefeed); - else - writePbm_(o_rOutputBuf, str, width, height, bWithLinefeed, bInvert ); -} - -void writeImage_( OutputBuffer& o_rOutputBuf, - Stream* str, - int width, - int height, - GfxImageColorMap* colorMap, - bool bWithLinefeed ) -{ - // dump JPEG file - if( str->getKind() == strDCT && - (colorMap->getNumPixelComps() == 1 || - colorMap->getNumPixelComps() == 3) ) - { - writeJpeg_(o_rOutputBuf, str, bWithLinefeed); - } - else if (colorMap->getNumPixelComps() == 1 && - colorMap->getBits() == 1) - { - // this is a two color bitmap, write a png - // provide default colors - GfxRGB zeroColor = { 0, 0, 0 }, - oneColor = { byteToCol( 0xff ), byteToCol( 0xff ), byteToCol( 0xff ) }; - if( colorMap->getColorSpace()->getMode() == csIndexed || colorMap->getColorSpace()->getMode() == csDeviceGray ) - { - Guchar nIndex = 0; - colorMap->getRGB( &nIndex, &zeroColor ); - nIndex = 1; - colorMap->getRGB( &nIndex, &oneColor ); - } - writePng_( o_rOutputBuf, str, width, height, zeroColor, oneColor, false, bWithLinefeed ); - } - else - writePpm_( o_rOutputBuf, str, width, height, colorMap, bWithLinefeed ); -} - -// forwarders -// ------------------------------------------------------------------ - -inline void writeImage( OutputBuffer& o_rOutputBuf, - Stream* str, - int width, - int height, - GfxImageColorMap* colorMap ) { writeImage_(o_rOutputBuf,str,width,height,colorMap,false); } -inline void writeImageLF( OutputBuffer& o_rOutputBuf, - Stream* str, - int width, - int height, - GfxImageColorMap* colorMap ) { writeImage_(o_rOutputBuf,str,width,height,colorMap,true); } -inline void writeMask( OutputBuffer& o_rOutputBuf, - Stream* str, - int width, - int height, - bool bInvert ) { writeMask_(o_rOutputBuf,str,width,height,false,bInvert); } -inline void writeMaskLF( OutputBuffer& o_rOutputBuf, - Stream* str, - int width, - int height, - bool bInvert ) { writeMask_(o_rOutputBuf,str,width,height,true,bInvert); } - -// ------------------------------------------------------------------ - - -int PDFOutDev::parseFont( long long nNewId, GfxFont* gfxFont, GfxState* state ) const -{ - FontAttributes aNewFont; - int nSize = 0; - - GooString* pFamily = gfxFont->getName(); - if( pFamily ) - { - aNewFont.familyName.clear(); - aNewFont.familyName.append( gfxFont->getName() ); - } - else - { - aNewFont.familyName.clear(); - aNewFont.familyName.append( "Arial" ); - } - - aNewFont.isBold = gfxFont->isBold(); - aNewFont.isItalic = gfxFont->isItalic(); - aNewFont.size = state->getTransformedFontSize(); - aNewFont.isUnderline = false; - - if( gfxFont->getType() == fontTrueType || gfxFont->getType() == fontType1 ) - { - // TODO(P3): Unfortunately, need to read stream twice, since - // we must write byte count to stdout before - char* pBuf = gfxFont->readEmbFontFile( m_pDoc->getXRef(), &nSize ); - if( pBuf ) - aNewFont.isEmbedded = true; - } - - m_aFontMap[ nNewId ] = aNewFont; - return nSize; -} - -void PDFOutDev::writeFontFile( GfxFont* gfxFont ) const -{ - if( gfxFont->getType() != fontTrueType && gfxFont->getType() != fontType1 ) - return; - - int nSize = 0; - char* pBuf = gfxFont->readEmbFontFile( m_pDoc->getXRef(), &nSize ); - if( !pBuf ) - return; - - // ---sync point--- see SYNC STREAMS above - fflush(stdout); - - if( fwrite(pBuf, sizeof(char), nSize, g_binary_out) != (size_t)nSize ) - exit(1); // error - - // ---sync point--- see SYNC STREAMS above - fflush(g_binary_out); -} - -void PDFOutDev::printPath( GfxPath* pPath ) const -{ - int nSubPaths = pPath ? pPath->getNumSubpaths() : 0; - for( int i=0; i<nSubPaths; i++ ) - { - GfxSubpath* pSub = pPath->getSubpath( i ); - const int nPoints = pSub->getNumPoints(); - - printf( " subpath %d", pSub->isClosed() ); - - for( int n=0; n<nPoints; ++n ) - { - printf( " %f %f %d", - normalize(pSub->getX(n)), - normalize(pSub->getY(n)), - pSub->getCurve(n) ); - } - } -} - -PDFOutDev::PDFOutDev( PDFDoc* pDoc ) : - m_pDoc( pDoc ), - m_aFontMap(), - m_pUtf8Map( new UnicodeMap((char*)"UTF-8", gTrue, &mapUTF8) ) -{ -} - -void PDFOutDev::startPage(int /*pageNum*/, GfxState* state, XRef* /*xref*/) -{ - assert(state); - printf("startPage %f %f\n", - normalize(state->getPageWidth()), - normalize(state->getPageHeight())); -} - -void PDFOutDev::endPage() -{ - printf("endPage\n"); -} - -void PDFOutDev::processLink(AnnotLink* link) -{ - assert(link); - - double x1,x2,y1,y2; - link->getRect( &x1, &y1, &x2, &y2 ); - - LinkAction* pAction = link->getAction(); - if( pAction->getKind() == actionURI ) - { - const char* pURI = static_cast<LinkURI*>(pAction)->getURI()->getCString(); - - boost::shared_array<char> pEsc( lcl_escapeLineFeeds(pURI) ); - - printf( "drawLink %f %f %f %f %s\n", - normalize(x1), - normalize(y1), - normalize(x2), - normalize(y2), - pEsc.get() ); - } -} - -void PDFOutDev::saveState(GfxState*) -{ - printf( "saveState\n" ); -} - -void PDFOutDev::restoreState(GfxState*) -{ - printf( "restoreState\n" ); -} - -void PDFOutDev::setDefaultCTM(double *pMat) -{ - assert(pMat); - - OutputDev::setDefaultCTM(pMat); - - printf( "updateCtm %f %f %f %f %f %f\n", - normalize(pMat[0]), - normalize(pMat[2]), - normalize(pMat[1]), - normalize(pMat[3]), - normalize(pMat[4]), - normalize(pMat[5]) ); -} - -void PDFOutDev::updateCTM(GfxState* state, - double, double, - double, double, - double, double) -{ - assert(state); - - const double* const pMat = state->getCTM(); - assert(pMat); - - printf( "updateCtm %f %f %f %f %f %f\n", - normalize(pMat[0]), - normalize(pMat[2]), - normalize(pMat[1]), - normalize(pMat[3]), - normalize(pMat[4]), - normalize(pMat[5]) ); -} - -void PDFOutDev::updateLineDash(GfxState *state) -{ - assert(state); - - double* dashArray; int arrayLen; double startOffset; - state->getLineDash(&dashArray, &arrayLen, &startOffset); - - printf( "updateLineDash" ); - if( arrayLen && dashArray ) - { - printf( " %f %d", normalize(startOffset), arrayLen ); - for( int i=0; i<arrayLen; ++i ) - printf( " %f", normalize(*dashArray++) ); - } - printf( "\n" ); -} - -void PDFOutDev::updateFlatness(GfxState *state) -{ - assert(state); - printf( "updateFlatness %d\n", state->getFlatness() ); -} - -void PDFOutDev::updateLineJoin(GfxState *state) -{ - assert(state); - printf( "updateLineJoin %d\n", state->getLineJoin() ); -} - -void PDFOutDev::updateLineCap(GfxState *state) -{ - assert(state); - printf( "updateLineCap %d\n", state->getLineCap() ); -} - -void PDFOutDev::updateMiterLimit(GfxState *state) -{ - assert(state); - printf( "updateMiterLimit %f\n", normalize(state->getMiterLimit()) ); -} - -void PDFOutDev::updateLineWidth(GfxState *state) -{ - assert(state); - printf( "updateLineWidth %f\n", normalize(state->getLineWidth()) ); -} - -void PDFOutDev::updateFillColor(GfxState *state) -{ - assert(state); - - GfxRGB aRGB; - state->getFillRGB( &aRGB ); - - printf( "updateFillColor %f %f %f %f\n", - normalize(colToDbl(aRGB.r)), - normalize(colToDbl(aRGB.g)), - normalize(colToDbl(aRGB.b)), - normalize(state->getFillOpacity()) ); -} - -void PDFOutDev::updateStrokeColor(GfxState *state) -{ - assert(state); - - GfxRGB aRGB; - state->getStrokeRGB( &aRGB ); - - printf( "updateStrokeColor %f %f %f %f\n", - normalize(colToDbl(aRGB.r)), - normalize(colToDbl(aRGB.g)), - normalize(colToDbl(aRGB.b)), - normalize(state->getFillOpacity()) ); -} - -void PDFOutDev::updateFillOpacity(GfxState *state) -{ - updateFillColor(state); -} - -void PDFOutDev::updateStrokeOpacity(GfxState *state) -{ - updateStrokeColor(state); -} - -void PDFOutDev::updateBlendMode(GfxState*) -{ -} - -void PDFOutDev::updateFont(GfxState *state) -{ - assert(state); - - GfxFont *gfxFont = state->getFont(); - if( gfxFont ) - { - FontAttributes aFont; - int nEmbedSize=0; - - Ref* pID = gfxFont->getID(); - // TODO(Q3): Portability problem - long long fontID = (long long)pID->gen << 32 | (long long)pID->num; - std::unordered_map< long long, FontAttributes >::const_iterator it = - m_aFontMap.find( fontID ); - if( it == m_aFontMap.end() ) - { - nEmbedSize = parseFont( fontID, gfxFont, state ); - it = m_aFontMap.find( fontID ); - } - - printf( "updateFont" ); - if( it != m_aFontMap.end() ) - { - // conflating this with printf below crashes under Windoze - printf( " %lld", fontID ); - - aFont = it->second; - - boost::shared_array<char> pEsc( lcl_escapeLineFeeds(aFont.familyName.getCString()) ); - printf( " %d %d %d %d %f %d %s", - aFont.isEmbedded, - aFont.isBold, - aFont.isItalic, - aFont.isUnderline, - normalize(state->getTransformedFontSize()), - nEmbedSize, - pEsc.get() ); - } - printf( "\n" ); - - if( nEmbedSize ) - writeFontFile(gfxFont); - } -} - -void PDFOutDev::updateRender(GfxState *state) -{ - assert(state); - - printf( "setTextRenderMode %d\n", state->getRender() ); -} - -void PDFOutDev::stroke(GfxState *state) -{ - assert(state); - - printf( "strokePath" ); - printPath( state->getPath() ); - printf( "\n" ); -} - -void PDFOutDev::fill(GfxState *state) -{ - assert(state); - - printf( "fillPath" ); - printPath( state->getPath() ); - printf( "\n" ); -} - -void PDFOutDev::eoFill(GfxState *state) -{ - assert(state); - - printf( "eoFillPath" ); - printPath( state->getPath() ); - printf( "\n" ); -} - -void PDFOutDev::clip(GfxState *state) -{ - assert(state); - - printf( "clipPath" ); - printPath( state->getPath() ); - printf( "\n" ); -} - -void PDFOutDev::eoClip(GfxState *state) -{ - assert(state); - - printf( "eoClipPath" ); - printPath( state->getPath() ); - printf( "\n" ); -} - -/** Output one glyph - - - @param dx - horizontal skip for character (already scaled with font size) + - inter-char space: cursor is shifted by this amount for next char - - @param dy - vertical skip for character (zero for horizontal writing mode): - cursor is shifted by this amount for next char - - @param originX - local offset of character (zero for horizontal writing mode). not - taken into account for output pos updates. Used for vertical writing. - - @param originY - local offset of character (zero for horizontal writing mode). not - taken into account for output pos updates. Used for vertical writing. - */ -void PDFOutDev::drawChar(GfxState *state, double x, double y, - double dx, double dy, - double originX, double originY, - CharCode, int /*nBytes*/, Unicode *u, int uLen) -{ - assert(state); - - if( u == NULL ) - return; - - // normalize coordinates: correct from baseline-relative to upper - // left corner of glyphs - double x2(0.0), y2(0.0); - state->textTransformDelta( 0.0, - state->getFont()->getAscent(), - &x2, &y2 ); - const double fFontSize(state->getFontSize()); - x += x2*fFontSize; - y += y2*fFontSize; - - const double aPositionX(x-originX); - const double aPositionY(y-originY); - // TODO(F2): use leading here, when set - const double nWidth(dx != 0.0 ? dx : fFontSize); - const double nHeight(dy != 0.0 ? dy : fFontSize); - - const double* pTextMat=state->getTextMat(); - printf( "drawChar %f %f %f %f %f %f %f %f ", - normalize(aPositionX), - normalize(aPositionY), - normalize(aPositionX+nWidth), - normalize(aPositionY-nHeight), - normalize(pTextMat[0]), - normalize(pTextMat[2]), - normalize(pTextMat[1]), - normalize(pTextMat[3]) ); - - // silence spurious warning - (void)&mapUCS2; - - char buf[9]; - for( int i=0; i<uLen; ++i ) - { - buf[ m_pUtf8Map->mapUnicode(u[i], buf, sizeof(buf)-1) ] = 0; - boost::shared_array<char> pEsc( lcl_escapeLineFeeds(buf) ); - printf( "%s", pEsc.get() ); - } - - printf( "\n" ); -} - -void PDFOutDev::drawString(GfxState*, GooString* /*s*/) -{ - // TODO(F3): NYI -} - -void PDFOutDev::endTextObject(GfxState*) -{ - printf( "endTextObject\n" ); -} - -void PDFOutDev::drawImageMask(GfxState* pState, Object*, Stream* str, - int width, int height, GBool invert, - GBool /*inlineImg*/ ) -{ - OutputBuffer aBuf; initBuf(aBuf); - - printf( "drawMask %d %d %d", width, height, invert ); - - int bitsPerComponent = 1; - StreamColorSpaceMode csMode = streamCSNone; - str->getImageParams( &bitsPerComponent, &csMode ); - if( bitsPerComponent == 1 && (csMode == streamCSNone || csMode == streamCSDeviceGray) ) - { - GfxRGB oneColor = { dblToCol( 1.0 ), dblToCol( 1.0 ), dblToCol( 1.0 ) }; - GfxRGB zeroColor = { dblToCol( 0.0 ), dblToCol( 0.0 ), dblToCol( 0.0 ) }; - pState->getFillColorSpace()->getRGB( pState->getFillColor(), &zeroColor ); - if( invert ) - writePng_( aBuf, str, width, height, oneColor, zeroColor, true, true ); - else - writePng_( aBuf, str, width, height, zeroColor, oneColor, true, true ); - } - else - writeMaskLF(aBuf, str, width, height, invert != 0); - writeBinaryBuffer(aBuf); -} - -void PDFOutDev::drawImage(GfxState*, Object*, Stream* str, - int width, int height, GfxImageColorMap* colorMap, - int* maskColors, GBool /*inlineImg*/ ) -{ - OutputBuffer aBuf; initBuf(aBuf); - OutputBuffer aMaskBuf; - - printf( "drawImage %d %d", width, height ); - - if( maskColors ) - { - // write mask colors. nBytes must be even - first half is - // lower bound values, second half upper bound values - if( colorMap->getColorSpace()->getMode() == csIndexed ) - { - aMaskBuf.push_back( (char)maskColors[0] ); - aMaskBuf.push_back( (char)maskColors[gfxColorMaxComps] ); - } - else - { - GfxRGB aMinRGB; - colorMap->getColorSpace()->getRGB( - (GfxColor*)maskColors, - &aMinRGB ); - - GfxRGB aMaxRGB; - colorMap->getColorSpace()->getRGB( - (GfxColor*)maskColors+gfxColorMaxComps, - &aMaxRGB ); - - aMaskBuf.push_back( colToByte(aMinRGB.r) ); - aMaskBuf.push_back( colToByte(aMinRGB.g) ); - aMaskBuf.push_back( colToByte(aMinRGB.b) ); - aMaskBuf.push_back( colToByte(aMaxRGB.r) ); - aMaskBuf.push_back( colToByte(aMaxRGB.g) ); - aMaskBuf.push_back( colToByte(aMaxRGB.b) ); - } - } - - printf( " %d", (int)aMaskBuf.size() ); - writeImageLF( aBuf, str, width, height, colorMap ); - writeBinaryBuffer(aBuf); - writeBinaryBuffer(aMaskBuf); -} - -void PDFOutDev::drawMaskedImage(GfxState*, Object*, Stream* str, - int width, int height, - GfxImageColorMap* colorMap, - Stream* maskStr, - int maskWidth, int maskHeight, - GBool maskInvert) -{ - OutputBuffer aBuf; initBuf(aBuf); - printf( "drawImage %d %d 0", width, height ); - writePng_( aBuf, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskInvert, true ); - writeBinaryBuffer( aBuf ); - #if 0 - OutputBuffer aBuf; initBuf(aBuf); - OutputBuffer aMaskBuf; initBuf(aMaskBuf); - - printf( "drawMaskedImage %d %d %d %d %d", width, height, maskWidth, maskHeight, 0 /*maskInvert note: currently we do inversion here*/ ); - writeImage( aBuf, str, width, height, colorMap ); - writeMaskLF( aMaskBuf, maskStr, width, height, maskInvert ); - writeBinaryBuffer(aBuf); - writeBinaryBuffer(aMaskBuf); - #endif -} - -void PDFOutDev::drawSoftMaskedImage(GfxState*, Object*, Stream* str, - int width, int height, - GfxImageColorMap* colorMap, - Stream* maskStr, - int maskWidth, int maskHeight, - GfxImageColorMap* maskColorMap ) -{ - OutputBuffer aBuf; initBuf(aBuf); - printf( "drawImage %d %d 0", width, height ); - writePng_( aBuf, str, width, height, colorMap, maskStr, maskWidth, maskHeight, maskColorMap, true ); - writeBinaryBuffer( aBuf ); - #if 0 - OutputBuffer aBuf; initBuf(aBuf); - OutputBuffer aMaskBuf; initBuf(aMaskBuf); - - printf( "drawSoftMaskedImage %d %d %d %d", width, height, maskWidth, maskHeight ); - writeImage( aBuf, str, width, height, colorMap ); - writeImageLF( aMaskBuf, maskStr, maskWidth, maskHeight, maskColorMap ); - writeBinaryBuffer(aBuf); - writeBinaryBuffer(aMaskBuf); - #endif -} - -void PDFOutDev::setPageNum( int nNumPages ) -{ - // TODO(F3): printf might format int locale-dependent! - printf("setPageNum %d\n", nNumPages); -} - -} diff --git a/main/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.hxx b/main/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.hxx deleted file mode 100644 index f314c38218..0000000000 --- a/main/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.hxx +++ /dev/null @@ -1,275 +0,0 @@ -/************************************************************** - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - *************************************************************/ - -#ifndef INCLUDED_PDFI_OUTDEV_HXX -#define INCLUDED_PDFI_OUTDEV_HXX - -#if defined __GNUC__ -#pragma GCC system_header -#elif defined __SUNPRO_CC -#pragma disable_warn -#elif defined _MSC_VER -#pragma warning(push, 1) -#endif - -#include "GfxState.h" -#include "GfxFont.h" -#include "UnicodeMap.h" -#include "Link.h" -#include "Object.h" -#include "OutputDev.h" -#include "Stream.h" -#include "GlobalParams.h" -#include "PDFDoc.h" - -#if defined __SUNPRO_CC -#pragma enable_warn -#elif defined _MSC_VER -#pragma warning(pop) -#endif - -#include <unordered_map> -#include <vector> - -class GfxPath; -class GfxFont; -class PDFDoc; - -namespace pdfi -{ - struct FontAttributes - { - FontAttributes( const GooString& familyName_, - bool isEmbedded_, - bool isBold_, - bool isItalic_, - bool isUnderline_, - double size_ ) : - familyName(), - isEmbedded(isEmbedded_), - isBold(isBold_), - isItalic(isItalic_), - isUnderline(isUnderline_), - size(size_) - { - familyName.append(const_cast<GooString*>(&familyName_)); - } - - FontAttributes() : - familyName(), - isEmbedded(false), - isBold(false), - isItalic(false), - isUnderline(false), - size(0.0) - {} - - // xpdf goo stuff is so totally borked... - // ...need to hand-code assignment - FontAttributes( const FontAttributes& rSrc ) : - familyName(), - isEmbedded(rSrc.isEmbedded), - isBold(rSrc.isBold), - isItalic(rSrc.isItalic), - isUnderline(rSrc.isUnderline), - size(rSrc.size) - { - familyName.append(const_cast<GooString*>(&rSrc.familyName)); - } - - FontAttributes& operator=( const FontAttributes& rSrc ) - { - familyName.clear(); - familyName.append(const_cast<GooString*>(&rSrc.familyName)); - - isEmbedded = rSrc.isEmbedded; - isBold = rSrc.isBold; - isItalic = rSrc.isItalic; - isUnderline = rSrc.isUnderline; - size = rSrc.size; - - return *this; - } - - bool operator==(const FontAttributes& rFont) const - { - return const_cast<GooString*>(&familyName)->cmp( - const_cast<GooString*>(&rFont.familyName))==0 && - isEmbedded == rFont.isEmbedded && - isBold == rFont.isBold && - isItalic == rFont.isItalic && - isUnderline == rFont.isUnderline && - size == rFont.size; - } - - GooString familyName; - bool isEmbedded; - bool isBold; - bool isItalic; - bool isUnderline; - double size; - }; - - class PDFOutDev : public OutputDev - { - // not owned by this class - PDFDoc* m_pDoc; - mutable std::unordered_map< long long, - FontAttributes > m_aFontMap; - UnicodeMap* m_pUtf8Map; - - int parseFont( long long nNewId, GfxFont* pFont, GfxState* state ) const; - void writeFontFile( GfxFont* gfxFont ) const; - void printPath( GfxPath* pPath ) const; - - public: - explicit PDFOutDev( PDFDoc* pDoc ); - - //----- get info about output device - - // Does this device use upside-down coordinates? - // (Upside-down means (0,0) is the top left corner of the page.) - virtual GBool upsideDown() { return gTrue; } - - // Does this device use drawChar() or drawString()? - virtual GBool useDrawChar() { return gTrue; } - - // Does this device use beginType3Char/endType3Char? Otherwise, - // text in Type 3 fonts will be drawn with drawChar/drawString. - virtual GBool interpretType3Chars() { return gFalse; } - - // Does this device need non-text content? - virtual GBool needNonText() { return gTrue; } - - //----- initialization and control - - // Set default transform matrix. - virtual void setDefaultCTM(double *ctm); - - // Start a page. - virtual void startPage(int pageNum, GfxState *state, XRef *xref); - - // End a page. - virtual void endPage(); - - // Dump page contents to display. - // virtual void dump() {} - - //----- coordinate conversion - - // Convert between device and user coordinates. - // virtual void cvtDevToUser(double dx, double dy, double *ux, double *uy); - // virtual void cvtUserToDev(double ux, double uy, int *dx, int *dy); - - //----- link borders - virtual void processLink(AnnotLink *link); - - //----- save/restore graphics state - virtual void saveState(GfxState *state); - virtual void restoreState(GfxState *state); - - //----- update graphics state - // virtual void updateAll(GfxState *state); - virtual void updateCTM(GfxState *state, double m11, double m12, - double m21, double m22, double m31, double m32); - virtual void updateLineDash(GfxState *state); - virtual void updateFlatness(GfxState *state); - virtual void updateLineJoin(GfxState *state); - virtual void updateLineCap(GfxState *state); - virtual void updateMiterLimit(GfxState *state); - virtual void updateLineWidth(GfxState *state); - virtual void updateFillColor(GfxState *state); - virtual void updateStrokeColor(GfxState *state); - virtual void updateFillOpacity(GfxState *state); - virtual void updateStrokeOpacity(GfxState *state); - virtual void updateBlendMode(GfxState *state); - - //----- update text state - virtual void updateFont(GfxState *state); - // virtual void updateTextMat(GfxState *state); - // virtual void updateCharSpace(GfxState *state) {} - virtual void updateRender(GfxState *state); - // virtual void updateRise(GfxState *state) {} - // virtual void updateWordSpace(GfxState *state) {} - // virtual void updateHorizScaling(GfxState *state) {} - // virtual void updateTextPos(GfxState *state) {} - // virtual void updateTextShift(GfxState *state, double shift) {} - - //----- path painting - virtual void stroke(GfxState *state); - virtual void fill(GfxState *state); - virtual void eoFill(GfxState *state); - - //----- path clipping - virtual void clip(GfxState *state); - virtual void eoClip(GfxState *state); - - //----- text drawing - virtual void drawChar(GfxState *state, double x, double y, - double dx, double dy, - double originX, double originY, - CharCode code, int nBytes, Unicode *u, int uLen); - virtual void drawString(GfxState *state, GooString *s); - virtual void endTextObject(GfxState *state); - - //----- image drawing - virtual void drawImageMask(GfxState *state, Object *ref, Stream *str, - int width, int height, GBool invert, - GBool inlineImg); - virtual void drawImage(GfxState *state, Object *ref, Stream *str, - int width, int height, GfxImageColorMap *colorMap, - int *maskColors, GBool inlineImg); - virtual void drawMaskedImage(GfxState *state, Object *ref, Stream *str, - int width, int height, - GfxImageColorMap *colorMap, - Stream *maskStr, int maskWidth, int maskHeight, - GBool maskInvert); - virtual void drawSoftMaskedImage(GfxState *state, Object *ref, Stream *str, - int width, int height, - GfxImageColorMap *colorMap, - Stream *maskStr, - int maskWidth, int maskHeight, - GfxImageColorMap *maskColorMap); - - //----- OPI functions - // virtual void opiBegin(GfxState *state, Dict *opiDict); - // virtual void opiEnd(GfxState *state, Dict *opiDict); - - //----- Type 3 font operators - // virtual void type3D0(GfxState *state, double wx, double wy) {} - // virtual void type3D1(GfxState *state, double wx, double wy, - // double llx, double lly, double urx, double ury) {} - - //----- PostScript XObjects - // virtual void psXObject(Stream *psStream, Stream *level1Stream) {} - - void setPageNum( int nNumPages ); - }; -} - -extern FILE* g_binary_out; - -// note: if you ever hcange Output_t, please keep in mind that the current code -// relies on it being of 8 bit size -typedef char Output_t; -typedef std::vector< Output_t > OutputBuffer; - -#endif /* INCLUDED_PDFI_OUTDEV_HXX */ diff --git a/main/sdext/source/pdfimport/xpdfwrapper/pnghelper.cxx b/main/sdext/source/pdfimport/xpdfwrapper/pnghelper.cxx deleted file mode 100644 index 8208b19e3e..0000000000 --- a/main/sdext/source/pdfimport/xpdfwrapper/pnghelper.cxx +++ /dev/null @@ -1,406 +0,0 @@ -/************************************************************** - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - *************************************************************/ - -#include "pnghelper.hxx" - -#ifdef SYSTEM_ZLIB -#include "zlib.h" -#else -#define ZLIB_INTERNAL 1 -#include <zlib/zlib.h> -#endif - -using namespace pdfi; - -// checksum helpers, courtesy of libpng.org - -/* Table of CRCs of all 8-bit messages. */ -sal_uInt32 PngHelper::crc_table[256]; - -/* Flag: has the table been computed? Initially false. */ -bool PngHelper::bCRCTableInit = true; - -/* Make the table for a fast CRC. */ -void PngHelper::initCRCTable() -{ - for (sal_uInt32 n = 0; n < 256; n++) - { - sal_uInt32 c = n; - for (int k = 0; k < 8; k++) - { - if (c & 1) - c = 0xedb88320L ^ (c >> 1); - else - c = c >> 1; - } - crc_table[n] = c; - } - bCRCTableInit = false; -} - -/* Update a running CRC with the bytes buf[0..len-1]--the CRC - should be initialized to all 1's, and the transmitted value - is the 1's complement of the final running CRC (see the - crc() routine below)). */ - -void PngHelper::updateCRC( sal_uInt32& io_rCRC, const sal_uInt8* i_pBuf, size_t i_nLen ) -{ - if( bCRCTableInit ) - initCRCTable(); - - sal_uInt32 nCRC = io_rCRC; - for( size_t n = 0; n < i_nLen; n++ ) - nCRC = crc_table[(nCRC ^ i_pBuf[n]) & 0xff] ^ (nCRC >> 8); - io_rCRC = nCRC; -} - -sal_uInt32 PngHelper::getCRC( const sal_uInt8* i_pBuf, size_t i_nLen ) -{ - sal_uInt32 nCRC = 0xffffffff; - updateCRC( nCRC, i_pBuf, i_nLen ); - return nCRC ^ 0xffffffff; -} - -sal_uInt32 PngHelper::deflateBuffer( const Output_t* i_pBuf, size_t i_nLen, OutputBuffer& o_rOut ) -{ - size_t nOrigSize = o_rOut.size(); - - // prepare z stream - z_stream aStream; - aStream.zalloc = Z_NULL; - aStream.zfree = Z_NULL; - aStream.opaque = Z_NULL; - deflateInit( &aStream, Z_BEST_COMPRESSION ); - aStream.avail_in = uInt(i_nLen); - aStream.next_in = (Bytef*)i_pBuf; - - sal_uInt8 aOutBuf[ 32768 ]; - do - { - aStream.avail_out = sizeof( aOutBuf ); - aStream.next_out = aOutBuf; - - if( deflate( &aStream, Z_FINISH ) == Z_STREAM_ERROR ) - { - deflateEnd( &aStream ); - // scrao the data of this broken stream - o_rOut.resize( nOrigSize ); - return 0; - } - - // append compressed bytes - sal_uInt32 nCompressedBytes = sizeof( aOutBuf ) - aStream.avail_out; - if( nCompressedBytes ) - o_rOut.insert( o_rOut.end(), aOutBuf, aOutBuf+nCompressedBytes ); - - } while( aStream.avail_out == 0 ); - - // cleanup - deflateEnd( &aStream ); - - return sal_uInt32( o_rOut.size() - nOrigSize ); -} - -void PngHelper::appendFileHeader( OutputBuffer& o_rOutputBuf ) -{ - static const Output_t aHeader[] = { static_cast<char>(0x89), 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a }; - - o_rOutputBuf.insert( o_rOutputBuf.end(), aHeader, aHeader + sizeof(aHeader)/sizeof(aHeader[0]) ); -} - -size_t PngHelper::startChunk( const char* pChunkName, OutputBuffer& o_rOutputBuf ) -{ - size_t nIndex = sal_uInt32( o_rOutputBuf.size() ); - o_rOutputBuf.insert( o_rOutputBuf.end(), 4, (Output_t)0 ); - o_rOutputBuf.push_back( pChunkName[0] ); - o_rOutputBuf.push_back( pChunkName[1] ); - o_rOutputBuf.push_back( pChunkName[2] ); - o_rOutputBuf.push_back( pChunkName[3] ); - return nIndex; -} - -void PngHelper::set( sal_uInt32 i_nValue, OutputBuffer& o_rOutputBuf, size_t i_nIndex ) -{ - o_rOutputBuf[ i_nIndex ] = (i_nValue & 0xff000000) >> 24; - o_rOutputBuf[ i_nIndex+1 ] = (i_nValue & 0x00ff0000) >> 16; - o_rOutputBuf[ i_nIndex+2 ] = (i_nValue & 0x0000ff00) >> 8; - o_rOutputBuf[ i_nIndex+3 ] = (i_nValue & 0x000000ff); -} - -void PngHelper::endChunk( size_t nStart, OutputBuffer& o_rOutputBuf ) -{ - if( nStart+8 > o_rOutputBuf.size() ) - return; // something broken is going on - - // update chunk length - size_t nLen = o_rOutputBuf.size() - nStart; - sal_uInt32 nDataLen = sal_uInt32(nLen)-8; - set( nDataLen, o_rOutputBuf, nStart ); - - // append chunk crc - sal_uInt32 nChunkCRC = getCRC( (sal_uInt8*)&o_rOutputBuf[nStart+4], nLen-4 ); - append( nChunkCRC, o_rOutputBuf ); -} - -void PngHelper::appendIHDR( OutputBuffer& o_rOutputBuf, int width, int height, int depth, int colortype ) -{ - size_t nStart = startChunk( "IHDR", o_rOutputBuf ); - append( width, o_rOutputBuf ); - append( height, o_rOutputBuf ); - o_rOutputBuf.push_back( Output_t(depth) ); - o_rOutputBuf.push_back( Output_t(colortype) ); - o_rOutputBuf.push_back( 0 ); // compression method deflate - o_rOutputBuf.push_back( 0 ); // filtering method 0 (default) - o_rOutputBuf.push_back( 0 ); // no interlacing - endChunk( nStart, o_rOutputBuf ); -} - -void PngHelper::appendIEND( OutputBuffer& o_rOutputBuf ) -{ - size_t nStart = startChunk( "IEND", o_rOutputBuf ); - endChunk( nStart, o_rOutputBuf ); -} - -void PngHelper::createPng( OutputBuffer& o_rOutputBuf, - Stream* str, - int width, - int height, - GfxRGB& zeroColor, - GfxRGB& oneColor, - bool bIsMask - ) -{ - appendFileHeader( o_rOutputBuf ); - appendIHDR( o_rOutputBuf, width, height, 1, 3 ); - - // write palette - size_t nIdx = startChunk( "PLTE", o_rOutputBuf ); - // write colors 0 and 1 - o_rOutputBuf.push_back(colToByte(zeroColor.r)); - o_rOutputBuf.push_back(colToByte(zeroColor.g)); - o_rOutputBuf.push_back(colToByte(zeroColor.b)); - o_rOutputBuf.push_back(colToByte(oneColor.r)); - o_rOutputBuf.push_back(colToByte(oneColor.g)); - o_rOutputBuf.push_back(colToByte(oneColor.b)); - // end PLTE chunk - endChunk( nIdx, o_rOutputBuf ); - - if( bIsMask ) - { - // write tRNS chunk - nIdx = startChunk( "tRNS", o_rOutputBuf ); - o_rOutputBuf.push_back( 0xff ); - o_rOutputBuf.push_back( 0 ); - // end tRNS chunk - endChunk( nIdx, o_rOutputBuf ); - } - - // create scan line data buffer - OutputBuffer aScanlines; - int nLineSize = (width + 7)/8; - aScanlines.reserve( nLineSize * height + height ); - - str->reset(); - for( int y = 0; y < height; y++ ) - { - // determine filter type (none) for this scanline - aScanlines.push_back( 0 ); - for( int x = 0; x < nLineSize; x++ ) - aScanlines.push_back( str->getChar() ); - } - - // begin IDAT chunk for scanline data - nIdx = startChunk( "IDAT", o_rOutputBuf ); - // compress scanlines - deflateBuffer( &aScanlines[0], aScanlines.size(), o_rOutputBuf ); - // end IDAT chunk - endChunk( nIdx, o_rOutputBuf ); - - // output IEND - appendIEND( o_rOutputBuf ); -} - -void PngHelper::createPng( OutputBuffer& o_rOutputBuf, - Stream* str, - int width, int height, GfxImageColorMap* colorMap, - Stream* maskStr, - int maskWidth, int maskHeight, GfxImageColorMap* maskColorMap ) -{ - appendFileHeader( o_rOutputBuf ); - appendIHDR( o_rOutputBuf, width, height, 8, 6 ); // RGBA image - - // initialize stream - Guchar *p, *pm; - GfxRGB rgb; - GfxGray alpha; - ImageStream* imgStr = - new ImageStream(str, - width, - colorMap->getNumPixelComps(), - colorMap->getBits()); - imgStr->reset(); - - // create scan line data buffer - OutputBuffer aScanlines; - aScanlines.reserve( width*height*4 + height ); - - for( int y=0; y<height; ++y) - { - aScanlines.push_back( 0 ); - p = imgStr->getLine(); - for( int x=0; x<width; ++x) - { - colorMap->getRGB(p, &rgb); - aScanlines.push_back(colToByte(rgb.r)); - aScanlines.push_back(colToByte(rgb.g)); - aScanlines.push_back(colToByte(rgb.b)); - aScanlines.push_back( 0xff ); - - p +=colorMap->getNumPixelComps(); - } - } - - - // now fill in the mask data - - // CAUTION: originally this was done in one single loop - // it caused merry chaos; the reason is that maskStr and str are - // not independent streams, it happens that reading one advances - // the other, too. Hence the two passes are imperative ! - - // initialize mask stream - ImageStream* imgStrMask = - new ImageStream(maskStr, - maskWidth, - maskColorMap->getNumPixelComps(), - maskColorMap->getBits()); - - imgStrMask->reset(); - for( int y = 0; y < maskHeight; ++y ) - { - pm = imgStrMask->getLine(); - for( int x = 0; x < maskWidth; ++x ) - { - maskColorMap->getGray(pm,&alpha); - pm += maskColorMap->getNumPixelComps(); - int nIndex = (y*height/maskHeight) * (width*4+1) + // mapped line - (x*width/maskWidth)*4 + 1 + 3 // mapped column - ; - aScanlines[ nIndex ] = colToByte(alpha); - } - } - - delete imgStr; - delete imgStrMask; - - // begind IDAT chunk for scanline data - size_t nIdx = startChunk( "IDAT", o_rOutputBuf ); - // compress scanlines - deflateBuffer( &aScanlines[0], aScanlines.size(), o_rOutputBuf ); - // end IDAT chunk - endChunk( nIdx, o_rOutputBuf ); - // output IEND - appendIEND( o_rOutputBuf ); -} - -// one bit mask; 0 bits opaque -void PngHelper::createPng( OutputBuffer& o_rOutputBuf, - Stream* str, - int width, int height, GfxImageColorMap* colorMap, - Stream* maskStr, - int maskWidth, int maskHeight, - bool maskInvert - ) -{ - appendFileHeader( o_rOutputBuf ); - appendIHDR( o_rOutputBuf, width, height, 8, 6 ); // RGBA image - - // initialize stream - Guchar *p; - GfxRGB rgb; - ImageStream* imgStr = - new ImageStream(str, - width, - colorMap->getNumPixelComps(), - colorMap->getBits()); - imgStr->reset(); - - // create scan line data buffer - OutputBuffer aScanlines; - aScanlines.reserve( width*height*4 + height ); - - for( int y=0; y<height; ++y) - { - aScanlines.push_back( 0 ); - p = imgStr->getLine(); - for( int x=0; x<width; ++x) - { - colorMap->getRGB(p, &rgb); - aScanlines.push_back(colToByte(rgb.r)); - aScanlines.push_back(colToByte(rgb.g)); - aScanlines.push_back(colToByte(rgb.b)); - aScanlines.push_back( 0xff ); - - p +=colorMap->getNumPixelComps(); - } - } - - - // now fill in the mask data - - // CAUTION: originally this was done in one single loop - // it caused merry chaos; the reason is that maskStr and str are - // not independent streams, it happens that reading one advances - // the other, too. Hence the two passes are imperative ! - - // initialize mask stream - ImageStream* imgStrMask = - new ImageStream(maskStr, maskWidth, 1, 1); - - imgStrMask->reset(); - for( int y = 0; y < maskHeight; ++y ) - { - for( int x = 0; x < maskWidth; ++x ) - { - Guchar aPixel = 0; - imgStrMask->getPixel( &aPixel ); - int nIndex = (y*height/maskHeight) * (width*4+1) + // mapped line - (x*width/maskWidth)*4 + 1 + 3 // mapped column - ; - if( maskInvert ) - aScanlines[ nIndex ] = aPixel ? 0xff : 0x00; - else - aScanlines[ nIndex ] = aPixel ? 0x00 : 0xff; - } - } - - delete imgStr; - delete imgStrMask; - - // begind IDAT chunk for scanline data - size_t nIdx = startChunk( "IDAT", o_rOutputBuf ); - // compress scanlines - deflateBuffer( &aScanlines[0], aScanlines.size(), o_rOutputBuf ); - // end IDAT chunk - endChunk( nIdx, o_rOutputBuf ); - // output IEND - appendIEND( o_rOutputBuf ); -} diff --git a/main/sdext/source/pdfimport/xpdfwrapper/pnghelper.hxx b/main/sdext/source/pdfimport/xpdfwrapper/pnghelper.hxx deleted file mode 100644 index 5d7739c756..0000000000 --- a/main/sdext/source/pdfimport/xpdfwrapper/pnghelper.hxx +++ /dev/null @@ -1,83 +0,0 @@ -/************************************************************** - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - *************************************************************/ -#ifndef _IPDF_PNGHELPER_HXX -#define _IPDF_PNGHELPER_HXX - -#include "sal/types.h" -#include "pdfioutdev_gpl.hxx" - - -namespace pdfi -{ - class PngHelper - { - static sal_uInt32 crc_table[ 256 ]; - static bool bCRCTableInit; - - static void initCRCTable(); - static void appendFileHeader( OutputBuffer& o_rOutputBuf ); - static size_t startChunk( const char* pChunkName, OutputBuffer& o_rOut ); - static void endChunk( size_t nStart, OutputBuffer& o_rOut ); - - static void set( sal_uInt32 i_nValue, OutputBuffer& o_rOutputBuf, size_t i_nIndex ); - static void append( sal_uInt32 i_nValue, OutputBuffer& o_rOutputBuf ) - { - size_t nCur = o_rOutputBuf.size(); - o_rOutputBuf.insert( o_rOutputBuf.end(), 4, (Output_t)0 ); - set( i_nValue, o_rOutputBuf, nCur ); - } - - static void appendIHDR( OutputBuffer& o_rOutputBuf, int width, int height, int depth, int colortype ); - static void appendIEND( OutputBuffer& o_rOutputBuf ); - - public: - static void updateCRC( sal_uInt32& io_rCRC, const sal_uInt8* i_pBuf, size_t i_nLen ); - static sal_uInt32 getCRC( const sal_uInt8* i_pBuf, size_t i_nLen ); - - // deflates the passed buff i_pBuf and appends it to the output vector - // returns the number of bytes added to the output - static sal_uInt32 deflateBuffer( const Output_t* i_pBuf, size_t i_nLen, OutputBuffer& o_rOut ); - - static void createPng( OutputBuffer& o_rOutputBuf, - Stream* str, - int width, - int height, - GfxRGB& zeroColor, - GfxRGB& oneColor, - bool bIsMask - ); - static void createPng( OutputBuffer& o_rOutputBuf, - Stream* str, - int width, int height, GfxImageColorMap* colorMap, - Stream* maskStr, - int maskWidth, int maskHeight, GfxImageColorMap* maskColorMap ); - - // for one bit masks - static void createPng( OutputBuffer& o_rOutputBuf, - Stream* str, - int width, int height, GfxImageColorMap* colorMap, - Stream* maskStr, - int maskWidth, int maskHeight, bool maskInvert ); - - }; -} - -#endif diff --git a/main/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx b/main/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx deleted file mode 100644 index 97fffebde7..0000000000 --- a/main/sdext/source/pdfimport/xpdfwrapper/wrapper_gpl.cxx +++ /dev/null @@ -1,178 +0,0 @@ -/************************************************************** - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - *************************************************************/ - -#include "pdfioutdev_gpl.hxx" -//#include "SecurityHandler.h" -#ifdef WNT -# include <io.h> -# include <fcntl.h> /*_O_BINARY*/ -#endif - -FILE* g_binary_out=stderr; - -static const char *ownerPassword = "\001"; -static const char *userPassword = "\001"; -static const char *outputFile = "\001"; - -int main(int argc, char **argv) -{ - int k = 0; - while (k < argc) - { - if (!strcmp(argv[k], "-f")) - { - outputFile = argv[k+1]; - --argc; - for (int j = k; j < argc; ++j) - argv[j] = argv[j+1]; - } - else if (!strcmp(argv[k], "-opw")) - { - ownerPassword = argv[k+1]; - --argc; - for (int j = k; j < argc; ++j) - argv[j] = argv[j+1]; - } - else if (!strcmp(argv[k], "-upw")) - { - userPassword = argv[k+1]; - --argc; - for (int j = k; j < argc; ++j) - argv[j] = argv[j+1]; - } - ++k; - } - - if( argc < 2 ) - return 1; - - // read config file - globalParams = new GlobalParams( - ); - globalParams->setErrQuiet(gTrue); -#ifdef _MSC_VER - globalParams->setupBaseFonts(NULL); -#endif - - // try to read a possible open password form stdin - char aPwBuf[129]; - aPwBuf[128] = 0; - if( ! fgets( aPwBuf, sizeof(aPwBuf)-1, stdin ) ) - aPwBuf[0] = 0; // mark as empty - else - { - for( unsigned int i = 0; i < sizeof(aPwBuf); i++ ) - { - if( aPwBuf[i] == '\n' ) - { - aPwBuf[i] = 0; - break; - } - } - } - - // PDFDoc takes over ownership for all strings below - GooString* pFileName = new GooString(argv[1]); - GooString* pTempErrFileName = new GooString("_err.pdf"); - GooString* pTempErrFileNamePath = new GooString(argv[0]); - - GooString* pErrFileName = new GooString(pTempErrFileNamePath,pTempErrFileName); - - - // check for password string(s) - GooString* pOwnerPasswordStr( aPwBuf[0] != 0 - ? new GooString( aPwBuf ) - : (ownerPassword[0] != '\001' - ? new GooString(ownerPassword) - : (GooString *)NULL ) ); - GooString* pUserPasswordStr( userPassword[0] != '\001' - ? new GooString(userPassword) - : (GooString *)NULL ); - if( outputFile[0] != '\001' ) - g_binary_out = fopen(outputFile,"wb"); - -#ifdef WNT - // Win actually modifies output for O_TEXT file mode, so need to - // revert to binary here - _setmode( _fileno( g_binary_out ), _O_BINARY ); -#endif - - PDFDoc aDoc( pFileName, - pOwnerPasswordStr, - pUserPasswordStr ); - - PDFDoc aErrDoc( pErrFileName, - pOwnerPasswordStr, - pUserPasswordStr ); - - - // Check various permissions. - if ( !aDoc.isOk()|| - !aDoc.okToPrint() || - !aDoc.okToChange()|| - !aDoc.okToCopy()|| - !aDoc.okToAddNotes() ) - { - pdfi::PDFOutDev* pOutDev( new pdfi::PDFOutDev(&aErrDoc) ); - - const int nPages = aErrDoc.isOk() ? aErrDoc.getNumPages() : 0; - - // tell receiver early - needed for proper progress calculation - pOutDev->setPageNum( nPages ); - - // virtual resolution of the PDF OutputDev in dpi - static const int PDFI_OUTDEV_RESOLUTION=7200; - - // do the conversion - for( int i=1; i<=nPages; ++i ) - { - aErrDoc.displayPage( pOutDev, - i, - PDFI_OUTDEV_RESOLUTION, - PDFI_OUTDEV_RESOLUTION, - 0, gTrue, gTrue, gTrue ); - aErrDoc.processLinks( pOutDev, i ); - } - } - else - { - pdfi::PDFOutDev* pOutDev( new pdfi::PDFOutDev(&aDoc) ); - - // tell receiver early - needed for proper progress calculation - pOutDev->setPageNum( aDoc.getNumPages() ); - - // virtual resolution of the PDF OutputDev in dpi - static const int PDFI_OUTDEV_RESOLUTION=7200; - - // do the conversion - const int nPages = aDoc.getNumPages(); - for( int i=1; i<=nPages; ++i ) - { - aDoc.displayPage( pOutDev, - i, - PDFI_OUTDEV_RESOLUTION, - PDFI_OUTDEV_RESOLUTION, - 0, gTrue, gTrue, gTrue ); - aDoc.processLinks( pOutDev, i ); - } - } - return 0; -}
