Bugs with unused font being referenced in PNG-to-EPS conversion (level 1 and 2)

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
jdagresta
Posts: 2
Joined: 2016-12-14T17:13:52-07:00
Authentication code: 1151
Location: Wakefield, MA, USA

Bugs with unused font being referenced in PNG-to-EPS conversion (level 1 and 2)

Post by jdagresta »

There are bugs with an unused font being referenced in the PNG-to-EPS conversion results, both level 1 and level 2 PS output (bug does not exist in code for level 3 PS output).

It has to do with the font being referenced for the "label" in the PS output, even when the option to output the image "label" is not being specified.

The unused font being referenced in the EPS results can cause some distillers to fail when processing PS containing the EPS conversion results if the unused font is not available to the distiller (and even though the font is actually unused).

The fixes are to the ImageMagick/coders/ps.c file (level 1 PS output) and to the ImageMagick/coders/ps2.c file (level 2 PS output).

Here are the "unified diffs" for the patches:

Code: Select all

--- orig/ImageMagick/coders/ps.c	2016-12-14 19:44:07.689461000 -0500
+++ new/ImageMagick/coders/ps.c	2016-12-14 19:44:51.053878000 -0500
@@ -1438,7 +1438,6 @@
       "  token pop /y exch def pop",
       "  currentfile buffer readline pop",
       "  token pop /pointsize exch def pop",
-      "  /Times-Roman findfont pointsize scalefont setfont",
       (const char *) NULL
     },
     *const PostscriptEpilog[]=
@@ -1809,6 +1808,9 @@
         }
         value=GetImageProperty(image,"label",exception);
         if (value != (const char *) NULL)
+        {
+          (void) WriteBlobString(image,
+            "  /Times-Roman findfont pointsize scalefont setfont\n");
           for (j=(ssize_t) MultilineCensus(value)-1; j >= 0; j--)
           {
             (void) WriteBlobString(image,"  /label 512 string def\n");
@@ -1817,6 +1819,7 @@
               "  0 y %g add moveto label show pop\n",j*pointsize+12);
             (void) WriteBlobString(image,buffer);
           }
+        }
         for (s=PostscriptEpilog; *s != (char *) NULL; s++)
         {
           (void) FormatLocaleString(buffer,MagickPathExtent,"%s\n",*s);
In the case of ps2.c, not only was the "label" font reference written out even when the label was not being used, but the label font being referenced was the wrong font, as for the level 2 PS output the Helvetica font is being used for the label but the code was writing out a Times-Roman font reference (which was the label font that was used for the level 1 PS output). This problem is also fixed in the following ps2.c patch.

Code: Select all

--- orig/ImageMagick/coders/ps2.c	2016-12-14 19:44:28.491188000 -0500
+++ new/ImageMagick/coders/ps2.c	2016-12-14 19:44:53.428761000 -0500
@@ -357,7 +357,6 @@
       "  token pop /y exch def pop",
       "  currentfile buffer readline pop",
       "  token pop /pointsize exch def pop",
-      "  /Helvetica findfont pointsize scalefont setfont",
       (const char *) NULL
     },
     *const PostscriptEpilog[]=
@@ -657,6 +656,9 @@
         }
         value=GetImageProperty(image,"label",exception);
         if (value != (const char *) NULL)
+        {
+          (void) WriteBlobString(image,
+            "  /Helvetica findfont pointsize scalefont setfont\n");
           for (j=(ssize_t) MultilineCensus(value)-1; j >= 0; j--)
           {
             (void) WriteBlobString(image,"  /label 512 string def\n");
@@ -665,6 +667,7 @@
               "  0 y %g add moveto label show pop\n",j*pointsize+12);
             (void) WriteBlobString(image,buffer);
           }
+        }
         for (q=PostscriptEpilog; *q; q++)
         {
           (void) FormatLocaleString(buffer,MagickPathExtent,"%s\n",*q);
@@ -693,7 +696,7 @@
       bounds.y2=(double) geometry.y+(geometry.height+text_size)-1;
     value=GetImageProperty(image,"label",exception);
     if (value != (const char *) NULL)
-      (void) WriteBlobString(image,"%%PageResources: font Times-Roman\n");
+      (void) WriteBlobString(image,"%%PageResources: font Helvetica\n");
     if (LocaleCompare(image_info->magick,"PS2") != 0)
       (void) WriteBlobString(image,"userdict begin\n");
     start=TellBlob(image);
jdagresta
Posts: 2
Joined: 2016-12-14T17:13:52-07:00
Authentication code: 1151
Location: Wakefield, MA, USA

Re: Bugs with unused font being referenced in PNG-to-EPS conversion (level 1 and 2)

Post by jdagresta »

To reproduce and see the problems being reported: use any image.png where the PNG image does not reference any Helvetica or Times-Roman font within the image.

Run the following commands:

Code: Select all

convert png:image.png -alpha background eps:ps.eps

Code: Select all

convert png:image.png -alpha background eps2:ps2.eps
Look at the ps.eps and ps2.eps conversion results and in the PS output inside the /DisplayImage PS function you will see the following references to an unused (label) font:

Code: Select all

   /Times-Roman findfont pointsize scalefont setfont

Code: Select all

   /Helvetica findfont pointsize scalefont setfont
In the case of ps2.c and the level 2 PS output, if the -label option was being specified then the PS output would contain this incorrect font reference:

Code: Select all

%%PageResources: font Times-Roman
It should be referencing the Helvetica font since in the level 2 PS output that is the font being used for the image "label".
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Bugs with unused font being referenced in PNG-to-EPS conversion (level 1 and 2)

Post by magick »

Thanks you for the detailed problem report and patch. We'll apply it against the upcoming ImageMagick 6.9.7 and 7.0.4 releases.
Post Reply