]> granicus.if.org Git - imagemagick/blobdiff - coders/pango.c
(no commit message)
[imagemagick] / coders / pango.c
index 3532784315b6ddf57f46d19763f748af6fa93fea..98942f12bc5eb54bd6f559f34248efcde4477c0b 100644 (file)
 %                     Read Pango Markup Language Format                       %
 %                                                                             %
 %                              Software Design                                %
-%                                John Cristy                                  %
+%                                   Cristy                                    %
 %                                 March 2012                                  %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
@@ -41,6 +41,7 @@
 */
 #include "MagickCore/studio.h"
 #include "MagickCore/annotate.h"
+#include "MagickCore/artifact.h"
 #include "MagickCore/blob.h"
 #include "MagickCore/blob-private.h"
 #include "MagickCore/composite-private.h"
@@ -125,6 +126,9 @@ static Image *ReadPANGOImage(const ImageInfo *image_info,
   MagickBooleanType
     status;
 
+  MemoryInfo
+    *pixel_info;
+
   PangoAlignment
     align;
 
@@ -178,13 +182,15 @@ static Image *ReadPANGOImage(const ImageInfo *image_info,
   */
   option=GetImageOption(image_info,"filename");
   if (option == (const char *) NULL)
-    property=InterpretImageProperties(image_info,image,image_info->filename,
-      exception);
+    property=InterpretImageProperties((ImageInfo *) image_info,image,
+      image_info->filename,exception);
   else
     if (LocaleNCompare(option,"pango:",6) == 0)
-      property=InterpretImageProperties(image_info,image,option+6,exception);
+      property=InterpretImageProperties((ImageInfo *) image_info,image,option+6,
+        exception);
     else
-      property=InterpretImageProperties(image_info,image,option,exception);
+      property=InterpretImageProperties((ImageInfo *) image_info,image,option,
+        exception);
   (void) SetImageProperty(image,"caption",property,exception);
   property=DestroyString(property);
   caption=ConstantString(GetImageProperty(image,"caption",exception));
@@ -193,7 +199,7 @@ static Image *ReadPANGOImage(const ImageInfo *image_info,
   */
   fontmap=pango_cairo_font_map_new();
   pango_cairo_font_map_set_resolution(PANGO_CAIRO_FONT_MAP(fontmap),
-    image->resolution.x);
+    image->resolution.x == 0.0 ? 90.0 : image->resolution.x);
   font_options=cairo_font_options_create();
   option=GetImageOption(image_info,"pango:hinting");
   if (option != (const char *) NULL)
@@ -293,7 +299,8 @@ static Image *ReadPANGOImage(const ImageInfo *image_info,
   option=GetImageOption(image_info,"pango:indent");
   if (option != (const char *) NULL)
     pango_layout_set_indent(layout,(int) ((StringToLong(option)*
-      image->resolution.x*PANGO_SCALE+36)/72.0+0.5));
+      (image->resolution.x == 0.0 ? 90.0 : image->resolution.x)*PANGO_SCALE+36)/
+      90.0+0.5));
   switch (draw_info->align)
   {
     case CenterAlign: align=PANGO_ALIGN_CENTER; break;
@@ -329,7 +336,7 @@ static Image *ReadPANGOImage(const ImageInfo *image_info,
       pango_font_description_free(description);
     }
   option=GetImageOption(image_info,"pango:markup");
-  if (IfMagickTrue(IsStringNotFalse(option))) /* enabled by default */
+  if ((option != (const char *) NULL) && (IsStringTrue(option) == MagickFalse))
     pango_layout_set_text(layout,caption,-1);
   else
     {
@@ -349,41 +356,43 @@ static Image *ReadPANGOImage(const ImageInfo *image_info,
     (void) ParseAbsoluteGeometry(image_info->page,&page);
   if (image->columns == 0)
     {
-      pango_layout_get_pixel_extents(layout,NULL,&extent);
-      image->columns=extent.x+extent.width+2*page.x;
+      pango_layout_get_extents(layout,NULL,&extent);
+      image->columns=(extent.x+extent.width+PANGO_SCALE/2)/PANGO_SCALE+2*page.x;
     }
   else
     {
       image->columns-=2*page.x;
       pango_layout_set_width(layout,(int) ((PANGO_SCALE*image->columns*
-        image->resolution.x+36.0)/72.0+0.5));
+        (image->resolution.x == 0.0 ? 90.0 : image->resolution.x)+45.0)/90.0+
+        0.5));
     }
   if (image->rows == 0)
     {
-      pango_layout_get_pixel_extents(layout,NULL,&extent);
-      image->rows=extent.y+extent.height+2*page.y;
+      pango_layout_get_extents(layout,NULL,&extent);
+      image->rows=(extent.y+extent.height+PANGO_SCALE/2)/PANGO_SCALE+2*page.y;
     }
   else
     {
       image->rows-=2*page.y;
       pango_layout_set_height(layout,(int) ((PANGO_SCALE*image->rows*
-        image->resolution.y+36.0)/72.0+0.5));
+        (image->resolution.y == 0.0 ? 90.0 : image->resolution.y)+45.0)/90.0+
+        0.5));
     }
   /*
     Render markup.
   */
   stride=(size_t) cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
-    image->columns);
-  pixels=(unsigned char *) AcquireQuantumMemory(image->columns,stride*
-    sizeof(*pixels));
-  if (pixels == (unsigned char *) NULL)
+    (int) image->columns);
+  pixel_info=AcquireVirtualMemory(image->rows,stride*sizeof(*pixels));
+  if (pixel_info == (MemoryInfo *) NULL)
     {
       draw_info=DestroyDrawInfo(draw_info);
       caption=DestroyString(caption);
       ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
     }
+  pixels=(unsigned char *) GetVirtualMemoryBlob(pixel_info);
   surface=cairo_image_surface_create_for_data(pixels,CAIRO_FORMAT_ARGB32,
-    image->columns,image->rows,stride);
+    (int) image->columns,(int) image->rows,(int) stride);
   cairo_image=cairo_create(surface);
   cairo_set_operator(cairo_image,CAIRO_OPERATOR_CLEAR);
   cairo_paint(cairo_image);
@@ -416,19 +425,19 @@ static Image *ReadPANGOImage(const ImageInfo *image_info,
       double
         gamma;
 
-      fill_color.blue=(MagickRealType) ScaleCharToQuantum(*p++);
-      fill_color.green=(MagickRealType) ScaleCharToQuantum(*p++);
-      fill_color.red=(MagickRealType) ScaleCharToQuantum(*p++);
-      fill_color.alpha=(MagickRealType) ScaleCharToQuantum(*p++);
+      fill_color.blue=(double) ScaleCharToQuantum(*p++);
+      fill_color.green=(double) ScaleCharToQuantum(*p++);
+      fill_color.red=(double) ScaleCharToQuantum(*p++);
+      fill_color.alpha=(double) ScaleCharToQuantum(*p++);
       /*
         Disassociate alpha.
       */
       gamma=1.0-QuantumScale*fill_color.alpha;
-      gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
+      gamma=PerceptibleReciprocal(gamma);
       fill_color.blue*=gamma;
       fill_color.green*=gamma;
       fill_color.red*=gamma;
-      CompositePixelOver(image,&fill_color,fill_color.alpha,q,(MagickRealType)
+      CompositePixelOver(image,&fill_color,fill_color.alpha,q,(double)
         GetPixelAlpha(image,q),q);
       q+=GetPixelChannels(image);
     }
@@ -445,7 +454,7 @@ static Image *ReadPANGOImage(const ImageInfo *image_info,
   /*
     Relinquish resources.
   */
-  pixels=(unsigned char *) RelinquishMagickMemory(pixels);
+  pixel_info=RelinquishVirtualMemory(pixel_info);
   draw_info=DestroyDrawInfo(draw_info);
   caption=DestroyString(caption);
   return(GetFirstImageInList(image));