summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Bader <williambader@hotmail.com>2020-06-21 17:22:24 +0000
committerAlbert Astals Cid <tsdgeos@yahoo.es>2020-06-21 17:22:24 +0000
commit6faf2739245b4ab24a4d536953f7d0cb763c9823 (patch)
treeb3cd758336361b10ff3b65103a99777dae54ce9d
parentbf15ccd4861d10e2338d0b1b2a65f222eb4e9893 (diff)
Add a pdftops -rasterize option with values always, never, or whenneeded
-rw-r--r--glib/poppler-page.cc7
-rw-r--r--poppler/PSOutputDev.cc8
-rw-r--r--poppler/PSOutputDev.h13
-rw-r--r--qt5/src/poppler-ps-converter.cc2
-rw-r--r--utils/pdftops.15
-rw-r--r--utils/pdftops.cc17
6 files changed, 43 insertions, 9 deletions
diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc
index c3002b91..78edfe0c 100644
--- a/glib/poppler-page.cc
+++ b/glib/poppler-page.cc
@@ -1144,8 +1144,11 @@ poppler_page_render_to_ps (PopplerPage *page,
ps_file->document->doc,
nullptr, pages,
psModePS, (int)ps_file->paper_width,
- (int)ps_file->paper_height, ps_file->duplex,
- false, 0, 0, 0, false, false);
+ (int)ps_file->paper_height,
+ false, ps_file->duplex,
+ 0, 0, 0, 0,
+ psRasterizeWhenNeeded, false,
+ nullptr, nullptr);
}
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 16ff64c4..f656a3d2 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -1088,7 +1088,7 @@ PSOutputDev::PSOutputDev(const char *fileName, PDFDoc *docA,
int paperWidthA, int paperHeightA,
bool noCropA, bool duplexA,
int imgLLXA, int imgLLYA, int imgURXA, int imgURYA,
- bool forceRasterizeA,
+ PSForceRasterize forceRasterizeA,
bool manualCtrlA,
PSOutCustomCodeCbk customCodeCbkA,
void *customCodeCbkDataA) {
@@ -1158,7 +1158,7 @@ PSOutputDev::PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA,
int paperWidthA, int paperHeightA,
bool noCropA, bool duplexA,
int imgLLXA, int imgLLYA, int imgURXA, int imgURYA,
- bool forceRasterizeA,
+ PSForceRasterize forceRasterizeA,
bool manualCtrlA,
PSOutCustomCodeCbk customCodeCbkA,
void *customCodeCbkDataA) {
@@ -3228,8 +3228,10 @@ bool PSOutputDev::checkPageSlice(Page *page, double /*hDPI*/, double /*vDPI*/,
if (!postInitDone) {
postInit();
}
- if (forceRasterize) {
+ if (forceRasterize == psAlwaysRasterize) {
rasterize = true;
+ } else if (forceRasterize == psNeverRasterize) {
+ rasterize = false;
} else {
scan = new PreScanOutputDev(doc);
page->displaySlice(scan, 72, 72, rotateA, useMediaBox, crop,
diff --git a/poppler/PSOutputDev.h b/poppler/PSOutputDev.h
index 757e3a06..d7de68fa 100644
--- a/poppler/PSOutputDev.h
+++ b/poppler/PSOutputDev.h
@@ -87,6 +87,12 @@ enum PSOutCustomCodeLocation {
psOutCustomPageSetup
};
+enum PSForceRasterize {
+ psRasterizeWhenNeeded, // default
+ psAlwaysRasterize, // always rasterize, useful for testing
+ psNeverRasterize // never rasterize, may produce incorrect output
+};
+
typedef void (*PSOutputFunc)(void *stream, const char *data, int len);
typedef GooString *(*PSOutCustomCodeCbk)(PSOutputDev *psOut,
@@ -106,7 +112,7 @@ public:
bool duplexA = true,
int imgLLXA = 0, int imgLLYA = 0,
int imgURXA = 0, int imgURYA = 0,
- bool forceRasterizeA = false,
+ PSForceRasterize forceRasterizeA = psRasterizeWhenNeeded,
bool manualCtrlA = false,
PSOutCustomCodeCbk customCodeCbkA = nullptr,
void *customCodeCbkDataA = nullptr);
@@ -122,7 +128,7 @@ public:
bool duplexA = true,
int imgLLXA = 0, int imgLLYA = 0,
int imgURXA = 0, int imgURYA = 0,
- bool forceRasterizeA = false,
+ PSForceRasterize forceRasterizeA = psRasterizeWhenNeeded,
bool manualCtrlA = false,
PSOutCustomCodeCbk customCodeCbkA = nullptr,
void *customCodeCbkDataA = nullptr);
@@ -315,6 +321,7 @@ public:
void setPSCenter(bool center) { psCenter = center; }
void setRasterAntialias(bool a) { rasterAntialias = a; }
+ void setForceRasterize(PSForceRasterize f) { forceRasterize = f; }
void setRasterResolution(double r) { rasterResolution = r; }
void setRasterMono(bool b) { rasterMono = b; }
void setUncompressPreloadedImages(bool b) { uncompressPreloadedImages = b; }
@@ -530,7 +537,7 @@ private:
bool t3FillColorOnly; // operators should only use the fill color
bool t3Cacheable; // cleared if char is not cacheable
bool t3NeedsRestore; // set if a 'q' operator was issued
- bool forceRasterize; // forces the page to be rasterized into a image before printing
+ PSForceRasterize forceRasterize; // controls the rasterization of pages into images
bool displayText; // displayText
bool psCenter; // center pages on the paper
bool rasterAntialias; // antialias on rasterize
diff --git a/qt5/src/poppler-ps-converter.cc b/qt5/src/poppler-ps-converter.cc
index c4dec24c..d809b011 100644
--- a/qt5/src/poppler-ps-converter.cc
+++ b/qt5/src/poppler-ps-converter.cc
@@ -235,7 +235,7 @@ bool PSConverter::convert()
d->marginBottom,
d->paperWidth - d->marginRight,
d->paperHeight - d->marginTop,
- (d->opts & ForceRasterization));
+ (d->opts & ForceRasterization) ? psAlwaysRasterize : psRasterizeWhenNeeded);
if (d->opts & StrictMargins)
{
diff --git a/utils/pdftops.1 b/utils/pdftops.1
index 6907b824..e74cb494 100644
--- a/utils/pdftops.1
+++ b/utils/pdftops.1
@@ -134,6 +134,11 @@ pdftops may need to rasterize transparencies and pattern image masks in the PDF.
If the PostScript will be printed, leave \-aaRaster disabled and set \-r to the resolution of the printer.
If the PostScript will be viewed, enabling \-aaRaster may make rasterized text easier to read.
.TP
+.BI \-rasterize " always | never | whenneeded"
+By default, pdftops rasterizes pages as needed, for example, if they contain transparencies.
+To force rasterization, set \-rasterize to "always". Use this to eliminate fonts.
+To prevent rasterization, set \-rasterize to "never". This may produce files that display incorrectly.
+.TP
.B \-optimizecolorspace
By default, bitmap images in the PDF pass through to the output PostScript
in their original color space, which produces predictable results.
diff --git a/utils/pdftops.cc b/utils/pdftops.cc
index a3cd70da..dae70a8e 100644
--- a/utils/pdftops.cc
+++ b/utils/pdftops.cc
@@ -101,6 +101,7 @@ static bool fontPassthrough = false;
static bool optimizeColorSpace = false;
static bool passLevel1CustomColor = false;
static char rasterAntialiasStr[16] = "";
+static char forceRasterizeStr[16] = "";
static bool preload = false;
static char paperSize[15] = "";
static int paperWidth = -1;
@@ -160,6 +161,8 @@ static const ArgDesc argDesc[] = {
"don't substitute missing fonts"},
{"-aaRaster", argString, rasterAntialiasStr, sizeof(rasterAntialiasStr),
"enable anti-aliasing on rasterization: yes, no"},
+ {"-rasterize", argString, forceRasterizeStr, sizeof(forceRasterizeStr),
+ "control rasterization: always, never, whenneeded"},
{"-optimizecolorspace", argFlag, &optimizeColorSpace,0,
"convert gray RGB images to gray color space"},
{"-passlevel1customcolor", argFlag, &passLevel1CustomColor, 0,
@@ -397,6 +400,20 @@ int main(int argc, char *argv[]) {
}
}
+ if (forceRasterizeStr[0]) {
+ PSForceRasterize forceRasterize = psRasterizeWhenNeeded;
+ if (strcmp(forceRasterizeStr, "whenneeded") == 0) {
+ forceRasterize = psRasterizeWhenNeeded;
+ } else if (strcmp(forceRasterizeStr, "always") == 0) {
+ forceRasterize = psAlwaysRasterize;
+ } else if (strcmp(forceRasterizeStr, "never") == 0) {
+ forceRasterize = psNeverRasterize;
+ } else {
+ fprintf(stderr, "Bad '-rasterize' value on command line\n");
+ }
+ psOut->setForceRasterize(forceRasterize);
+ }
+
if (splashResolution > 0) {
psOut->setRasterResolution(splashResolution);
}