[poppler] poppler/CairoOutputDev.cc poppler/CairoOutputDev.h utils/pdftocairo.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Oct 1 08:18:24 UTC 2021


 poppler/CairoOutputDev.cc |   26 +++++++-------------------
 poppler/CairoOutputDev.h  |    4 +---
 utils/pdftocairo.cc       |   10 +++++++++-
 3 files changed, 17 insertions(+), 23 deletions(-)

New commits:
commit e0a0f50a278df6bc1d3618e685494244d7139783
Author: Christian Persch <chpe at src.gnome.org>
Date:   Thu Sep 30 16:38:42 2021 +0200

    poppler: cairo: Don't override the antialias settings from the cairo_t
    
    This partially reverts commit 853e9499, which made CairoOutputDev store
    the antialias setting, and applying it to its cairo context.
    
    Instead, just copy the antialias (and font antialias) setting from the
    passed cairo context to newly created contexts.  That way, the application
    can control the antialias settings.
    
    Use this in pdftocairo to implement its -antialias option.
    
    Fixes: https://gitlab.freedesktop.org/poppler/poppler/-/merge_requests/282
    https://bugs.freedesktop.org/show_bug.cgi?id=94977
    https://gitlab.freedesktop.org/poppler/poppler/merge_requests/89

diff --git a/poppler/CairoOutputDev.cc b/poppler/CairoOutputDev.cc
index 2cfcb79d..e3606418 100644
--- a/poppler/CairoOutputDev.cc
+++ b/poppler/CairoOutputDev.cc
@@ -154,7 +154,6 @@ CairoOutputDev::CairoOutputDev()
     inType3Char = false;
     t3_glyph_has_bbox = false;
     text_matrix_valid = true;
-    antialias = CAIRO_ANTIALIAS_DEFAULT;
 
     groupColorSpaceStack = nullptr;
     maskStack = nullptr;
@@ -216,7 +215,6 @@ void CairoOutputDev::setCairo(cairo_t *c)
         /* save the initial matrix so that we can use it for type3 fonts. */
         // XXX: is this sufficient? could we miss changes to the matrix somehow?
         cairo_get_matrix(cairo, &orig_matrix);
-        setContextAntialias(cairo, antialias);
     } else {
         cairo = nullptr;
         cairo_shape = nullptr;
@@ -239,22 +237,12 @@ void CairoOutputDev::setTextPage(TextPage *text)
     }
 }
 
-void CairoOutputDev::setAntialias(cairo_antialias_t a)
+void CairoOutputDev::copyAntialias(cairo_t *cr, cairo_t *source_cr)
 {
-    antialias = a;
-    if (cairo)
-        setContextAntialias(cairo, antialias);
-    if (cairo_shape)
-        setContextAntialias(cairo_shape, antialias);
-}
+    cairo_set_antialias(cr, cairo_get_antialias(source_cr));
 
-void CairoOutputDev::setContextAntialias(cairo_t *cr, cairo_antialias_t antialias)
-{
-    cairo_font_options_t *font_options;
-    cairo_set_antialias(cr, antialias);
-    font_options = cairo_font_options_create();
-    cairo_get_font_options(cr, font_options);
-    cairo_font_options_set_antialias(font_options, antialias);
+    cairo_font_options_t *font_options = cairo_font_options_create();
+    cairo_get_font_options(source_cr, font_options);
     cairo_set_font_options(cr, font_options);
     cairo_font_options_destroy(font_options);
 }
@@ -941,7 +929,7 @@ bool CairoOutputDev::tilingPatternFill(GfxState *state, Gfx *gfxA, Catalog *cat,
     old_cairo = cairo;
     cairo = cairo_create(surface);
     cairo_surface_destroy(surface);
-    setContextAntialias(cairo, antialias);
+    copyAntialias(cairo, old_cairo);
 
     box.x1 = bbox[0];
     box.y1 = bbox[1];
@@ -1623,7 +1611,7 @@ void CairoOutputDev::beginTransparencyGroup(GfxState * /*state*/, const double *
             cairo_surface_t *cairo_shape_surface = cairo_surface_create_similar_clip(cairo, CAIRO_CONTENT_ALPHA);
             cairo_shape = cairo_create(cairo_shape_surface);
             cairo_surface_destroy(cairo_shape_surface);
-            setContextAntialias(cairo_shape, antialias);
+            copyAntialias(cairo_shape, cairo);
 
             /* the color doesn't matter as long as it is opaque */
             cairo_set_source_rgb(cairo_shape, 0, 0, 0);
@@ -1778,7 +1766,7 @@ void CairoOutputDev::setSoftMask(GfxState *state, const double *bbox, bool alpha
 
         cairo_surface_t *source = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
         cairo_t *maskCtx = cairo_create(source);
-        setContextAntialias(maskCtx, antialias);
+        copyAntialias(maskCtx, cairo);
 
         // XXX: hopefully this uses the correct color space */
         if (!alpha && groupColorSpaceStack->cs) {
diff --git a/poppler/CairoOutputDev.h b/poppler/CairoOutputDev.h
index dc101e22..04e71451 100644
--- a/poppler/CairoOutputDev.h
+++ b/poppler/CairoOutputDev.h
@@ -238,7 +238,7 @@ public:
         printing = printingA;
         needFontUpdate = true;
     }
-    void setAntialias(cairo_antialias_t antialias);
+    void copyAntialias(cairo_t *cr, cairo_t *source_cr);
 
     void setInType3Char(bool inType3CharA) { inType3Char = inType3CharA; }
     void getType3GlyphWidth(double *wx, double *wy)
@@ -264,7 +264,6 @@ protected:
 #if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 15, 10)
     bool setMimeDataForCCITTParams(Stream *str, cairo_surface_t *image, int height);
 #endif
-    static void setContextAntialias(cairo_t *cr, cairo_antialias_t antialias);
 
     GfxRGB fill_color, stroke_color;
     cairo_pattern_t *fill_pattern, *stroke_pattern;
@@ -317,7 +316,6 @@ protected:
     double t3_glyph_wx, t3_glyph_wy;
     bool t3_glyph_has_bbox;
     double t3_glyph_bbox[4];
-    cairo_antialias_t antialias;
     bool prescaleImages;
 
     TextPage *textPage; // text for the current page
diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc
index 1e4b3986..342ca213 100644
--- a/utils/pdftocairo.cc
+++ b/utils/pdftocairo.cc
@@ -648,12 +648,20 @@ static void renderPage(PDFDoc *doc, CairoOutputDev *cairoOut, int pg, double pag
     cairo_t *cr;
     cairo_status_t status;
     cairo_matrix_t m;
+    cairo_font_options_t *font_options;
 
     cr = cairo_create(surface);
 
+    cairo_set_antialias(cr, antialiasEnum);
+
+    font_options = cairo_font_options_create();
+    cairo_get_font_options(cr, font_options);
+    cairo_font_options_set_antialias(font_options, antialiasEnum);
+    cairo_set_font_options(cr, font_options);
+    cairo_font_options_destroy(font_options);
+
     cairoOut->setCairo(cr);
     cairoOut->setPrinting(printing);
-    cairoOut->setAntialias(antialiasEnum);
 
     cairo_save(cr);
     if (ps && output_w > output_h) {


More information about the poppler mailing list