]> granicus.if.org Git - imagemagick/blobdiff - coders/pdf.c
(no commit message)
[imagemagick] / coders / pdf.c
index 0353845a0e5657a3c863b68e97e293d34f435543..bb4162e40ce54b2c113811f1e2af064959a23162 100644 (file)
@@ -175,6 +175,7 @@ static MagickBooleanType InvokePDFDelegate(const MagickBooleanType verbose,
       status=SystemCommand(MagickFalse,verbose,command,exception);
       return(status == 0 ? MagickTrue : MagickFalse);
     }
+  code=0;
   argv=StringToArgv(command,&argc);
   status=(ghost_info->init_with_args)(interpreter,argc-1,argv+1);
   if (status == 0)
@@ -288,7 +289,6 @@ static MagickBooleanType IsPDFRendered(const char *path)
 
 static Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception)
 {
-#define AdobeIllustrator  "âãÏÓ"
 #define CropBox  "CropBox"
 #define DeviceCMYK  "DeviceCMYK"
 #define MediaBox  "MediaBox"
@@ -328,10 +328,10 @@ static Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception)
     *read_info;
 
   int
+    c,
     file;
 
   MagickBooleanType
-    adobe_illustrator,
     cmyk,
     cropbox,
     trimbox,
@@ -350,8 +350,8 @@ static Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception)
   register char
     *p;
 
-  register int
-    c;
+  register ssize_t
+    i;
 
   SegmentInfo
     bounds,
@@ -424,7 +424,6 @@ static Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception)
   hires_bounds.x2=0.0;
   hires_bounds.y2=0.0;
   angle=0.0;
-  adobe_illustrator=MagickFalse;
   p=command;
   for (c=ReadBlobByte(image); c != EOF; c=ReadBlobByte(image))
   {
@@ -434,7 +433,7 @@ static Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception)
     if (c == '\n')
       c=' ';
     *p++=(char) c;
-    if ((c != (int) '/') && (c != (int) '%') && 
+    if ((c != (int) '/') && (c != (int) '%') &&
         ((size_t) (p-command) < (MaxTextExtent-1)))
       continue;
     *(--p)='\0';
@@ -446,8 +445,6 @@ static Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception)
     */
     if (LocaleNCompare(DeviceCMYK,command,strlen(DeviceCMYK)) == 0)
       cmyk=MagickTrue;
-    if (LocaleNCompare(AdobeIllustrator,command,strlen(AdobeIllustrator)) == 0)
-      adobe_illustrator=MagickTrue;
     if (LocaleNCompare(SpotColor,command,strlen(SpotColor)) == 0)
       {
         char
@@ -573,10 +570,7 @@ static Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception)
      if (cmyk != MagickFalse)
        delegate_info=GetDelegateInfo("ps:cmyk",(char *) NULL,exception);
      else
-       if (adobe_illustrator != MagickFalse)
-         delegate_info=GetDelegateInfo("ps:alpha",(char *) NULL,exception);
-       else
-         delegate_info=GetDelegateInfo("ps:color",(char *) NULL,exception);
+       delegate_info=GetDelegateInfo("ps:alpha",(char *) NULL,exception);
   if (delegate_info == (const DelegateInfo *) NULL)
     {
       (void) RelinquishUniqueFileResource(postscript_filename);
@@ -592,17 +586,17 @@ static Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception)
       if ((flags & SigmaValue) == 0)
         image->y_resolution=image->x_resolution;
     }
-  (void) FormatMagickString(density,MaxTextExtent,"%gx%g",
-    image->x_resolution,image->y_resolution);
+  (void) FormatMagickString(density,MaxTextExtent,"%gx%g",image->x_resolution,
+    image->y_resolution);
   if (image_info->page != (char *) NULL)
     {
       (void) ParseAbsoluteGeometry(image_info->page,&page);
-      page.width=(size_t) floor(page.width*image->x_resolution/delta.x+
-        0.5);
-      page.height=(size_t) floor(page.height*image->y_resolution/delta.y+
-        0.5);
-      (void) FormatMagickString(options,MaxTextExtent,"-g%.20gx%.20g ",
-        (double) page.width,(double) page.height);
+      page.width=(size_t) floor((double) (page.width*image->x_resolution/
+        delta.x)+0.5);
+      page.height=(size_t) floor((double) (page.height*image->y_resolution/
+        delta.y)+0.5);
+      (void) FormatMagickString(options,MaxTextExtent,"-g%.20gx%.20g ",(double)
+        page.width,(double) page.height);
     }
   if (cmyk != MagickFalse)
     (void) ConcatenateMagickString(options,"-dUseCIEColor ",MaxTextExtent);
@@ -629,20 +623,39 @@ static Image *ReadPDFImage(const ImageInfo *image_info,ExceptionInfo *exception)
     (void) FormatMagickString(options+strlen(options),MaxTextExtent,
       " -sPDFPassword=%s",read_info->authenticate);
   (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
-  (void) AcquireUniqueFilename(read_info->filename);
+  (void) AcquireUniqueFilename(filename);
+  (void) ConcatenateMagickString(filename,"-%08d",MaxTextExtent);
   (void) FormatMagickString(command,MaxTextExtent,
     GetDelegateCommands(delegate_info),
     read_info->antialias != MagickFalse ? 4 : 1,
-    read_info->antialias != MagickFalse ? 4 : 1,density,options,
-    read_info->filename,postscript_filename,input_filename);
+    read_info->antialias != MagickFalse ? 4 : 1,density,options,filename,
+    postscript_filename,input_filename);
   status=InvokePDFDelegate(read_info->verbose,command,exception);
-  pdf_image=(Image *) NULL;
-  if ((status != MagickFalse) &&
-      (IsPDFRendered(read_info->filename) != MagickFalse))
-    pdf_image=ReadImage(read_info,exception);
   (void) RelinquishUniqueFileResource(postscript_filename);
-  (void) RelinquishUniqueFileResource(read_info->filename);
   (void) RelinquishUniqueFileResource(input_filename);
+  pdf_image=(Image *) NULL;
+  if (status == MagickFalse)
+    for (i=1; ; i++)
+    {
+      (void) InterpretImageFilename(image_info,image,filename,(int) i,
+        read_info->filename);
+      if (IsPDFRendered(read_info->filename) == MagickFalse)
+        break;
+      (void) RelinquishUniqueFileResource(read_info->filename);
+    }
+  else
+    for (i=1; ; i++)
+    {
+      (void) InterpretImageFilename(image_info,image,filename,(int) i,
+        read_info->filename);
+      if (IsPDFRendered(read_info->filename) == MagickFalse)
+        break;
+      next=ReadImage(read_info,exception);
+      (void) RelinquishUniqueFileResource(read_info->filename);
+      if (next == (Image *) NULL)
+        break;
+      AppendImageToList(&pdf_image,next);
+    }
   read_info=DestroyImageInfo(read_info);
   if (pdf_image == (Image *) NULL)
     {
@@ -947,6 +960,7 @@ static MagickBooleanType WritePDFImage(const ImageInfo *image_info,Image *image)
     XMPProfileMagick[4]= { (char) 0xef, (char) 0xbb, (char) 0xbf, (char) 0x00 };
 
   char
+    basename[MaxTextExtent],
     buffer[MaxTextExtent],
     date[MaxTextExtent],
     **labels,
@@ -1262,8 +1276,8 @@ static MagickBooleanType WritePDFImage(const ImageInfo *image_info,Image *image)
       }
     if (image->units == PixelsPerCentimeterResolution)
       {
-        resolution.x=(size_t) (100.0*2.54*resolution.x+0.5)/100.0;
-        resolution.y=(size_t) (100.0*2.54*resolution.y+0.5)/100.0;
+        resolution.x=(double) ((size_t) (100.0*2.54*resolution.x+0.5)/100.0);
+        resolution.y=(double) ((size_t) (100.0*2.54*resolution.y+0.5)/100.0);
       }
     SetGeometry(image,&geometry);
     (void) FormatMagickString(page_geometry,MaxTextExtent,"%.20gx%.20g",
@@ -1302,6 +1316,7 @@ static MagickBooleanType WritePDFImage(const ImageInfo *image_info,Image *image)
     value=GetImageProperty(image,"Label");
     if (value != (const char *) NULL)
       text_size=(size_t) (MultilineCensus(value)*pointsize+12);
+    (void) text_size;
     /*
       Write Page object.
     */
@@ -2496,8 +2511,9 @@ static MagickBooleanType WritePDFImage(const ImageInfo *image_info,Image *image)
     object);
   (void) WriteBlobString(image,buffer);
   (void) WriteBlobString(image,"<<\n");
+  GetPathComponent(image->filename,BasePath,basename);
   (void) FormatMagickString(buffer,MaxTextExtent,"/Title (%s)\n",
-    EscapeParenthesis(image->filename));
+    EscapeParenthesis(basename));
   (void) WriteBlobString(image,buffer);
   seconds=time((time_t *) NULL);
 #if defined(MAGICKCORE_HAVE_LOCALTIME_R)