]> granicus.if.org Git - imagemagick/blobdiff - coders/pango.c
...
[imagemagick] / coders / pango.c
index 4a6f80472cbd91406bc6381f2aa6134c09aab4ec..c40624e9cce4149f49c8cee1d3980554ae6f3b27 100644 (file)
@@ -6,24 +6,24 @@
 %                     PPPP    AAA   N   N   GGGG   OOO                        %
 %                     P   P  A   A  NN  N  G      O   O                       %
 %                     PPPP   AAAAA  N N N  G GGG  O   O                       %
-%                     P   M  A   A  N  NN  G   G  O   O                       %
+%                     P      A   A  N  NN  G   G  O   O                       %
 %                     P      A   A  N   N   GGGG   OOO                        %
 %                                                                             %
 %                                                                             %
 %                     Read Pango Markup Language Format                       %
 %                                                                             %
 %                              Software Design                                %
-%                                John Cristy                                  %
+%                                   Cristy                                    %
 %                                 March 2012                                  %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2017 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  %
 %  obtain a copy of the License at                                            %
 %                                                                             %
-%    http://www.imagemagick.org/script/license.php                            %
+%    https://www.imagemagick.org/script/license.php                           %
 %                                                                             %
 %  Unless required by applicable law or agreed to in writing, software        %
 %  distributed under the License is distributed on an "AS IS" BASIS,          %
@@ -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,12 +126,18 @@ static Image *ReadPANGOImage(const ImageInfo *image_info,
   MagickBooleanType
     status;
 
+  MemoryInfo
+    *pixel_info;
+
   PangoAlignment
     align;
 
   PangoContext
     *context;
 
+  PangoFontDescription
+    *description;
+
   PangoFontMap
     *fontmap;
 
@@ -165,12 +172,12 @@ static Image *ReadPANGOImage(const ImageInfo *image_info,
     Initialize Image structure.
   */
   assert(image_info != (const ImageInfo *) NULL);
-  assert(image_info->signature == MagickSignature);
+  assert(image_info->signature == MagickCoreSignature);
   if (image_info->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       image_info->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   image=AcquireImage(image_info,exception);
   (void) ResetImagePage(image,"0x0+0+0");
   /*
@@ -178,13 +185,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));
@@ -275,10 +284,10 @@ static Image *ReadPANGOImage(const ImageInfo *image_info,
         pango_layout_set_ellipsize(layout,PANGO_ELLIPSIZE_START);
     }
   option=GetImageOption(image_info,"pango:justify");
-  if (IfMagickTrue(IsStringTrue(option)))
+  if (IsStringTrue(option) != MagickFalse)
     pango_layout_set_justify(layout,1);
   option=GetImageOption(image_info,"pango:single-paragraph");
-  if (IfMagickTrue(IsStringTrue(option)))
+  if (IsStringTrue(option) != MagickFalse)
     pango_layout_set_single_paragraph_mode(layout,1);
   option=GetImageOption(image_info,"pango:wrap");
   if (option != (const char *) NULL)
@@ -315,20 +324,14 @@ static Image *ReadPANGOImage(const ImageInfo *image_info,
       (draw_info->direction == RightToLeftDirection))
     align=(PangoAlignment) (PANGO_ALIGN_LEFT+PANGO_ALIGN_RIGHT-align);
   pango_layout_set_alignment(layout,align);
-  if (draw_info->font != (char *) NULL)
-    {
-      PangoFontDescription
-        *description;
-
-      /*
-        Set font.
-      */
-      description=pango_font_description_from_string(draw_info->font);
-      pango_font_description_set_size(description,(int) (PANGO_SCALE*
-        draw_info->pointsize+0.5));
-      pango_layout_set_font_description(layout,description);
-      pango_font_description_free(description);
-    }
+  if (draw_info->font == (char *) NULL)
+    description=pango_font_description_new();
+  else
+    description=pango_font_description_from_string(draw_info->font);
+  pango_font_description_set_size(description,(int) (PANGO_SCALE*
+    draw_info->pointsize+0.5));
+  pango_layout_set_font_description(layout,description);
+  pango_font_description_free(description);
   option=GetImageOption(image_info,"pango:markup");
   if ((option != (const char *) NULL) && (IsStringTrue(option) == MagickFalse))
     pango_layout_set_text(layout,caption,-1);
@@ -350,48 +353,54 @@ 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);
+      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 == 0.0 : 90.0 : image->resolution.x)+45.0)/90.0+
+        (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);
+      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 == 0.0 : 90.0 : image->resolution.y)+45.0)/90.0+
+        (image->resolution.y == 0.0 ? 90.0 : image->resolution.y)+45.0)/90.0+
         0.5));
     }
+  status=SetImageExtent(image,image->columns,image->rows,exception);
+  if (status == MagickFalse)
+    return(DestroyImageList(image));
   /*
     Render markup.
   */
   stride=(size_t) cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32,
-    image->columns);
-  pixels=(unsigned char *) AcquireQuantumMemory(image->rows,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);
   cairo_set_operator(cairo_image,CAIRO_OPERATOR_OVER);
   cairo_translate(cairo_image,page.x,page.y);
+  cairo_set_source_rgba(cairo_image,QuantumScale*draw_info->fill.red,
+    QuantumScale*draw_info->fill.green,QuantumScale*draw_info->fill.blue,
+    QuantumScale*draw_info->fill.alpha);
   pango_cairo_show_layout(cairo_image,layout);
   cairo_destroy(cairo_image);
   cairo_surface_destroy(surface);
@@ -426,7 +435,7 @@ static Image *ReadPANGOImage(const ImageInfo *image_info,
       /*
         Disassociate alpha.
       */
-      gamma=1.0-QuantumScale*fill_color.alpha;
+      gamma=QuantumScale*fill_color.alpha;
       gamma=PerceptibleReciprocal(gamma);
       fill_color.blue*=gamma;
       fill_color.green*=gamma;
@@ -448,7 +457,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));
@@ -481,25 +490,23 @@ static Image *ReadPANGOImage(const ImageInfo *image_info,
 ModuleExport size_t RegisterPANGOImage(void)
 {
   char
-    version[MaxTextExtent];
+    version[MagickPathExtent];
 
   MagickInfo
     *entry;
 
   *version='\0';
 #if defined(PANGO_VERSION_STRING)
-  (void) FormatLocaleString(version,MaxTextExtent,"Pangocairo %s",
+  (void) FormatLocaleString(version,MagickPathExtent,"Pangocairo %s",
     PANGO_VERSION_STRING);
 #endif
-  entry=SetMagickInfo("PANGO");
+  entry=AcquireMagickInfo("PANGO","PANGO","Pango Markup Language");
 #if defined(MAGICKCORE_PANGOCAIRO_DELEGATE)
   entry->decoder=(DecodeImageHandler *) ReadPANGOImage;
 #endif
-  entry->description=ConstantString("Pango Markup Language");
   if (*version != '\0')
     entry->version=ConstantString(version);
-  entry->adjoin=MagickFalse;
-  entry->module=ConstantString("PANGO");
+  entry->flags^=CoderAdjoinFlag;
   (void) RegisterMagickInfo(entry);
   return(MagickImageCoderSignature);
 }