]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/annotate.c
(no commit message)
[imagemagick] / MagickCore / annotate.c
index 04434cd26ad8d6c87f0f14ea9d50e7a98e301f28..1966cb6bb96dcc3b652da4600975435da92f6e6a 100644 (file)
 %                   MagickCore Image Annotation Methods                       %
 %                                                                             %
 %                              Software Design                                %
-%                                John Cristy                                  %
+%                                   Cristy                                    %
 %                                 July 1992                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2013 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  %
@@ -47,6 +47,7 @@
 #include "MagickCore/annotate-private.h"
 #include "MagickCore/attribute.h"
 #include "MagickCore/cache-view.h"
+#include "MagickCore/channel.h"
 #include "MagickCore/client.h"
 #include "MagickCore/color.h"
 #include "MagickCore/color-private.h"
@@ -144,7 +145,8 @@ static MagickBooleanType
 */
 MagickPrivate MagickBooleanType AnnotateComponentGenesis(void)
 {
-  AcquireSemaphoreInfo(&annotate_semaphore);
+  if (annotate_semaphore == (SemaphoreInfo *) NULL)
+    annotate_semaphore=AcquireSemaphoreInfo();
   return(MagickTrue);
 }
 \f
@@ -169,8 +171,8 @@ MagickPrivate MagickBooleanType AnnotateComponentGenesis(void)
 MagickPrivate void AnnotateComponentTerminus(void)
 {
   if (annotate_semaphore == (SemaphoreInfo *) NULL)
-    AcquireSemaphoreInfo(&annotate_semaphore);
-  DestroySemaphoreInfo(&annotate_semaphore);
+    ActivateSemaphoreInfo(&annotate_semaphore);
+  RelinquishSemaphoreInfo(&annotate_semaphore);
 }
 \f
 /*
@@ -291,7 +293,7 @@ MagickExport MagickBooleanType AnnotateImage(Image *image,
   if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
     return(MagickFalse);
   if (IsGrayColorspace(image->colorspace) != MagickFalse)
-    (void) TransformImageColorspace(image,sRGBColorspace,exception);
+    (void) SetImageColorspace(image,sRGBColorspace,exception);
   status=MagickTrue;
   for (i=0; textlist[i] != (char *) NULL; i++)
   {
@@ -462,7 +464,7 @@ MagickExport MagickBooleanType AnnotateImage(Image *image,
         undercolor_info->affine.tx=offset.x-draw_info->affine.ry*metrics.ascent;
         undercolor_info->affine.ty=offset.y-draw_info->affine.sy*metrics.ascent;
         (void) FormatLocaleString(primitive,MaxTextExtent,
-          "rectangle 0,0 %g,%.20g",metrics.origin.x,(double) height);
+          "rectangle -0.5,-0.5 %g,%.20g",metrics.origin.x,(double) height);
         (void) CloneString(&undercolor_info->primitive,primitive);
         (void) DrawImage(image,undercolor_info,exception);
         (void) DestroyDrawInfo(undercolor_info);
@@ -585,7 +587,7 @@ MagickExport ssize_t FormatMagickCaption(Image *image,DrawInfo *draw_info,
     status=GetTypeMetrics(image,draw_info,metrics,exception);
     if (status == MagickFalse)
       break;
-    width=(size_t) floor(metrics->width+metrics->max_advance/2.0+0.5);
+    width=(size_t) floor(metrics->width+draw_info->stroke_width+0.5);
     if ((width <= image->columns) || (strcmp(text,draw_info->text) == 0))
       continue;
     (void) strcpy(text,draw_info->text);
@@ -1075,7 +1077,7 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
     encoding_type;
 
   FT_Error
-    status;
+    ft_status;
 
   FT_Face
     face;
@@ -1099,6 +1101,9 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
     glyph,
     last_glyph;
 
+  MagickBooleanType
+    status;
+
   PointInfo
     point,
     resolution;
@@ -1126,8 +1131,8 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
   /*
     Initialize Truetype library.
   */
-  status=FT_Init_FreeType(&library);
-  if (status != 0)
+  ft_status=FT_Init_FreeType(&library);
+  if (ft_status != 0)
     ThrowBinaryException(TypeError,"UnableToInitializeFreetypeLibrary",
       image->filename);
   args.flags=FT_OPEN_PATHNAME;
@@ -1139,9 +1144,9 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
     else
       args.pathname=ConstantString(draw_info->font+1);
   face=(FT_Face) NULL;
-  status=FT_Open_Face(library,&args,(long) draw_info->face,&face);
+  ft_status=FT_Open_Face(library,&args,(long) draw_info->face,&face);
   args.pathname=DestroyString(args.pathname);
-  if (status != 0)
+  if (ft_status != 0)
     {
       (void) FT_Done_FreeType(library);
       (void) ThrowMagickException(exception,GetMagickModule(),TypeError,
@@ -1152,9 +1157,9 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
       (IsPathAccessible(draw_info->metrics) != MagickFalse))
     (void) FT_Attach_File(face,draw_info->metrics);
   encoding_type=ft_encoding_unicode;
-  status=FT_Select_Charmap(face,encoding_type);
-  if ((status != 0) && (face->num_charmaps != 0))
-    status=FT_Set_Charmap(face,face->charmaps[0]);
+  ft_status=FT_Select_Charmap(face,encoding_type);
+  if ((ft_status != 0) && (face->num_charmaps != 0))
+    ft_status=FT_Set_Charmap(face,face->charmaps[0]);
   if (encoding != (const char *) NULL)
     {
       if (LocaleCompare(encoding,"AdobeCustom") == 0)
@@ -1187,9 +1192,13 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
         encoding_type=ft_encoding_unicode;
       if (LocaleCompare(encoding,"Wansung") == 0)
         encoding_type=ft_encoding_wansung;
-      status=FT_Select_Charmap(face,encoding_type);
-      if (status != 0)
-        ThrowBinaryException(TypeError,"UnrecognizedFontEncoding",encoding);
+      ft_status=FT_Select_Charmap(face,encoding_type);
+      if (ft_status != 0)
+        {
+          (void) FT_Done_Face(face);
+          (void) FT_Done_FreeType(library);
+          ThrowBinaryException(TypeError,"UnrecognizedFontEncoding",encoding);
+        }
     }
   /*
     Set text size.
@@ -1210,7 +1219,7 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
       if ((flags & SigmaValue) == 0)
         resolution.y=resolution.x;
     }
-  status=FT_Set_Char_Size(face,(FT_F26Dot6) (64.0*draw_info->pointsize),
+  ft_status=FT_Set_Char_Size(face,(FT_F26Dot6) (64.0*draw_info->pointsize),
     (FT_F26Dot6) (64.0*draw_info->pointsize),(FT_UInt) resolution.x,
     (FT_UInt) resolution.y);
   metrics->pixels_per_em.x=face->size->metrics.x_ppem;
@@ -1303,6 +1312,7 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
       if (utf8 != (unsigned char *) NULL)
         p=(char *) utf8;
     }
+  status=MagickTrue;
   for (code=0; GetUTFCode(p) != 0; p+=GetUTFOctets(p))
   {
     /*
@@ -1321,22 +1331,22 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
               FT_Vector
                 kerning;
 
-              status=FT_Get_Kerning(face,last_glyph.id,glyph.id,
+              ft_status=FT_Get_Kerning(face,last_glyph.id,glyph.id,
                 ft_kerning_default,&kerning);
-              if (status == 0)
+              if (ft_status == 0)
                 origin.x+=(FT_Pos) (direction*kerning.x);
             }
         }
     glyph.origin=origin;
-    status=FT_Load_Glyph(face,glyph.id,flags);
-    if (status != 0)
+    ft_status=FT_Load_Glyph(face,glyph.id,flags);
+    if (ft_status != 0)
       continue;
-    status=FT_Get_Glyph(face->glyph,&glyph.image);
-    if (status != 0)
+    ft_status=FT_Get_Glyph(face->glyph,&glyph.image);
+    if (ft_status != 0)
       continue;
-    status=FT_Outline_Get_BBox(&((FT_OutlineGlyph) glyph.image)->outline,
+    ft_status=FT_Outline_Get_BBox(&((FT_OutlineGlyph) glyph.image)->outline,
       &bounds);
-    if (status != 0)
+    if (ft_status != 0)
       continue;
     if ((p == draw_info->text) || (bounds.xMin < metrics->bounds.x1))
       metrics->bounds.x1=(double) bounds.xMin;
@@ -1346,23 +1356,25 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
       metrics->bounds.x2=(double) bounds.xMax;
     if ((p == draw_info->text) || (bounds.yMax > metrics->bounds.y2))
       metrics->bounds.y2=(double) bounds.yMax;
-    if (draw_info->render != MagickFalse)
-      if ((draw_info->stroke.alpha != TransparentAlpha) ||
-          (draw_info->stroke_pattern != (Image *) NULL))
-        {
-          /*
-            Trace the glyph.
-          */
-          annotate_info->affine.tx=glyph.origin.x/64.0;
-          annotate_info->affine.ty=glyph.origin.y/64.0;
-          (void) FT_Outline_Decompose(&((FT_OutlineGlyph) glyph.image)->
-            outline,&OutlineMethods,annotate_info);
+    if ((draw_info->stroke.alpha != TransparentAlpha) ||
+        (draw_info->stroke_pattern != (Image *) NULL))
+      {
+        if ((status != MagickFalse) && (draw_info->render != MagickFalse))
+          {
+            /*
+              Trace the glyph.
+            */
+            annotate_info->affine.tx=glyph.origin.x/64.0;
+            annotate_info->affine.ty=glyph.origin.y/64.0;
+            (void) FT_Outline_Decompose(&((FT_OutlineGlyph) glyph.image)->
+              outline,&OutlineMethods,annotate_info);
+          }
         }
     FT_Vector_Transform(&glyph.origin,&affine);
     (void) FT_Glyph_Transform(glyph.image,&affine,&glyph.origin);
-    status=FT_Glyph_To_Bitmap(&glyph.image,ft_render_mode_normal,
+    ft_status=FT_Glyph_To_Bitmap(&glyph.image,ft_render_mode_normal,
       (FT_Vector *) NULL,MagickTrue);
-    if (status != 0)
+    if (ft_status != 0)
       continue;
     bitmap=(FT_BitmapGlyph) glyph.image;
     point.x=offset->x+bitmap->left;
@@ -1374,16 +1386,12 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
         CacheView
           *image_view;
 
-        MagickBooleanType
-          status;
-
         register unsigned char
           *p;
 
         /*
           Rasterize the glyph.
         */
-        status=MagickTrue;
         image_view=AcquireAuthenticCacheView(image,exception);
         p=bitmap->bitmap.buffer;
         for (y=0; y < (ssize_t) bitmap->bitmap.rows; y++)
@@ -1491,7 +1499,7 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
   if ((draw_info->stroke.alpha != TransparentAlpha) ||
       (draw_info->stroke_pattern != (Image *) NULL))
     {
-      if (draw_info->render != MagickFalse)
+      if ((status != MagickFalse) && (draw_info->render != MagickFalse))
         {
           /*
             Draw text stroke.
@@ -1508,19 +1516,19 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
   */
   glyph.id=FT_Get_Char_Index(face,'_');
   glyph.origin=origin;
-  status=FT_Load_Glyph(face,glyph.id,flags);
-  if (status == 0)
+  ft_status=FT_Load_Glyph(face,glyph.id,flags);
+  if (ft_status == 0)
     {
-      status=FT_Get_Glyph(face->glyph,&glyph.image);
-      if (status == 0)
+      ft_status=FT_Get_Glyph(face->glyph,&glyph.image);
+      if (ft_status == 0)
         {
-          status=FT_Outline_Get_BBox(&((FT_OutlineGlyph) glyph.image)->outline,
-            &bounds);
-          if (status == 0)
+          ft_status=FT_Outline_Get_BBox(&((FT_OutlineGlyph) glyph.image)->
+            outline,&bounds);
+          if (ft_status == 0)
             {
               FT_Vector_Transform(&glyph.origin,&affine);
               (void) FT_Glyph_Transform(glyph.image,&affine,&glyph.origin);
-              status=FT_Glyph_To_Bitmap(&glyph.image,ft_render_mode_normal,
+              ft_status=FT_Glyph_To_Bitmap(&glyph.image,ft_render_mode_normal,
                 (FT_Vector *) NULL,MagickTrue);
               bitmap=(FT_BitmapGlyph) glyph.image;
               if (bitmap->left > metrics->width)
@@ -1543,7 +1551,7 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
   annotate_info=DestroyDrawInfo(annotate_info);
   (void) FT_Done_Face(face);
   (void) FT_Done_FreeType(library);
-  return(MagickTrue);
+  return(status);
 }
 #else
 static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
@@ -1897,7 +1905,7 @@ static MagickBooleanType RenderX11(Image *image,const DrawInfo *draw_info,
     status;
 
   if (annotate_semaphore == (SemaphoreInfo *) NULL)
-    AcquireSemaphoreInfo(&annotate_semaphore);
+    ActivateSemaphoreInfo(&annotate_semaphore);
   LockSemaphoreInfo(annotate_semaphore);
   status=XRenderImage(image,draw_info,offset,metrics,exception);
   UnlockSemaphoreInfo(annotate_semaphore);