[gimp] plug-ins: also omit hidden layer groups in PDF export.



commit 24a0b0c53a91ec62144895badc121a5e3ab930ca
Author: Jehan <jehan girinstud io>
Date:   Wed Jan 1 18:40:52 2020 +0100

    plug-ins: also omit hidden layer groups in PDF export.
    
    When the "Omit hidden layers and layers with zero opacity" option is
    set, this property was only checked on non-group layers. So if we had
    non-hidden layers inside hidden layer groups, they ended up exported,
    which is not the expected behavior.
    
    See https://gitlab.gnome.org/GNOME/gimp/issues/4425#note_675350

 plug-ins/common/file-pdf-save.c | 128 ++++++++++++++++++++--------------------
 1 file changed, 63 insertions(+), 65 deletions(-)
---
diff --git a/plug-ins/common/file-pdf-save.c b/plug-ins/common/file-pdf-save.c
index 4f079a1dd3..dd4382ba07 100644
--- a/plug-ins/common/file-pdf-save.c
+++ b/plug-ins/common/file-pdf-save.c
@@ -1896,12 +1896,18 @@ draw_layer (GimpLayer   **layers,
             GError      **error)
 {
   GimpLayer *layer;
+  gdouble    opacity;
 
   if (optimize.reverse_order && optimize.layers_as_pages)
     layer = layers [j];
   else
     layer = layers [n_layers - j - 1];
 
+  opacity = gimp_layer_get_opacity (layer) / 100.0;
+  if ((! gimp_item_get_visible (GIMP_ITEM (layer)) || opacity == 0.0) &&
+      optimize.ignore_hidden)
+    return TRUE;
+
   if (gimp_item_is_group (GIMP_ITEM (layer)))
     {
       GimpItem **children;
@@ -1924,89 +1930,81 @@ draw_layer (GimpLayer   **layers,
     {
       cairo_surface_t *mask_image = NULL;
       GimpLayerMask   *mask       = NULL;
-      gdouble          opacity;
+      gint             x, y;
 
-      opacity = gimp_layer_get_opacity (layer) / 100.0;
+      mask = gimp_layer_get_mask (layer);
+      if (mask)
+        {
+          mask_image = get_cairo_surface (GIMP_DRAWABLE (mask), TRUE,
+                                          error);
 
-      if ((gimp_item_get_visible (GIMP_ITEM (layer)) && opacity > 0.0) ||
-          ! optimize.ignore_hidden)
+          if (*error)
+            return FALSE;
+        }
+
+      gimp_drawable_offsets (GIMP_DRAWABLE (layer), &x, &y);
+
+      if (! gimp_item_is_text_layer (GIMP_ITEM (layer)) || optimize.convert_text)
         {
-          gint x, y;
+          /* For raster layers */
 
-          mask = gimp_layer_get_mask (layer);
-          if (mask)
-            {
-              mask_image = get_cairo_surface (GIMP_DRAWABLE (mask), TRUE,
-                                              error);
+          GimpRGB  layer_color;
+          gboolean single_color = FALSE;
 
-              if (*error)
-                return FALSE;
-            }
+          layer_color = get_layer_color (layer, &single_color);
 
-          gimp_drawable_offsets (GIMP_DRAWABLE (layer), &x, &y);
+          cairo_rectangle (cr, x, y,
+                           gimp_drawable_width  (GIMP_DRAWABLE (layer)),
+                           gimp_drawable_height (GIMP_DRAWABLE (layer)));
 
-          if (! gimp_item_is_text_layer (GIMP_ITEM (layer)) || optimize.convert_text)
+          if (optimize.vectorize && single_color)
             {
-              /* For raster layers */
-
-              GimpRGB  layer_color;
-              gboolean single_color = FALSE;
-
-              layer_color = get_layer_color (layer, &single_color);
-
-              cairo_rectangle (cr, x, y,
-                               gimp_drawable_width  (GIMP_DRAWABLE (layer)),
-                               gimp_drawable_height (GIMP_DRAWABLE (layer)));
-
-              if (optimize.vectorize && single_color)
-                {
-                  cairo_set_source_rgba (cr,
-                                         layer_color.r,
-                                         layer_color.g,
-                                         layer_color.b,
-                                         layer_color.a * opacity);
-                  if (mask)
-                    cairo_mask_surface (cr, mask_image, x, y);
-                  else
-                    cairo_fill (cr);
-                }
+              cairo_set_source_rgba (cr,
+                                     layer_color.r,
+                                     layer_color.g,
+                                     layer_color.b,
+                                     layer_color.a * opacity);
+              if (mask)
+                cairo_mask_surface (cr, mask_image, x, y);
               else
-                {
-                  cairo_surface_t *layer_image;
+                cairo_fill (cr);
+            }
+          else
+            {
+              cairo_surface_t *layer_image;
 
-                  layer_image = get_cairo_surface (GIMP_DRAWABLE (layer), FALSE,
-                                                   error);
+              layer_image = get_cairo_surface (GIMP_DRAWABLE (layer), FALSE,
+                                               error);
 
-                  if (*error)
-                    return FALSE;
+              if (*error)
+                return FALSE;
 
-                  cairo_clip (cr);
+              cairo_clip (cr);
 
-                  cairo_set_source_surface (cr, layer_image, x, y);
-                  cairo_push_group (cr);
-                  cairo_paint_with_alpha (cr, opacity);
-                  cairo_pop_group_to_source (cr);
+              cairo_set_source_surface (cr, layer_image, x, y);
+              cairo_push_group (cr);
+              cairo_paint_with_alpha (cr, opacity);
+              cairo_pop_group_to_source (cr);
 
-                  if (mask)
-                    cairo_mask_surface (cr, mask_image, x, y);
-                  else
-                    cairo_paint (cr);
+              if (mask)
+                cairo_mask_surface (cr, mask_image, x, y);
+              else
+                cairo_paint (cr);
 
-                  cairo_reset_clip (cr);
+              cairo_reset_clip (cr);
 
-                  cairo_surface_destroy (layer_image);
-                }
-            }
-          else
-            {
-              /* For text layers */
-              drawText (layer, opacity, cr, x_res, y_res);
+              cairo_surface_destroy (layer_image);
             }
-
-          /* draw new page if "layers as pages" option is checked */
-          if (optimize.layers_as_pages)
-            cairo_show_page (cr);
         }
+      else
+        {
+          /* For text layers */
+          drawText (layer, opacity, cr, x_res, y_res);
+        }
+
+      /* draw new page if "layers as pages" option is checked */
+      if (optimize.layers_as_pages)
+        cairo_show_page (cr);
 
       /* We are done with the layer - time to free some resources */
       if (mask)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]