]> granicus.if.org Git - imagemagick/commitdiff
fix font decorate position, thickness issue (#1619)
authorPIGNOSE <kenneth@pigno.se>
Sat, 29 Jun 2019 11:24:28 +0000 (20:24 +0900)
committerImageMagick <urban-warrior@users.noreply.github.com>
Sat, 29 Jun 2019 11:24:28 +0000 (07:24 -0400)
* WIP: add line stroke color info for DrawPolygonPrimitive's condition

* WIP: fix an inaccurate underline formula

* WIP: add to follow stroke color when they're given

MagickCore/annotate.c

index 3f3ac7fa09dd577d54871475bc23c40fe5a6ea17..e72cb94a30c3125829e38a288c5b3a54d0d63523 100644 (file)
@@ -224,6 +224,7 @@ MagickExport MagickBooleanType AnnotateImage(Image *image,
 {
   char
     *p,
+    color[MagickPathExtent],
     primitive[MagickPathExtent],
     *text,
     **textlist;
@@ -238,6 +239,9 @@ MagickExport MagickBooleanType AnnotateImage(Image *image,
   MagickBooleanType
     status;
 
+  PixelInfo
+    pixel;
+
   PointInfo
     offset;
 
@@ -494,8 +498,19 @@ MagickExport MagickBooleanType AnnotateImage(Image *image,
       }
     annotate_info->affine.tx=offset.x;
     annotate_info->affine.ty=offset.y;
-    (void) FormatLocaleString(primitive,MagickPathExtent,"stroke-width %g "
-      "line 0,0 %g,0",metrics.underline_thickness,metrics.width);
+
+    pixel=annotate_info->fill;
+    if (annotate_info->stroke.alpha != TransparentAlpha)
+      pixel = annotate_info->stroke;
+
+    (void) QueryColorname(image,&pixel,AllCompliance,color,exception);
+    (void) FormatLocaleString(primitive,MagickPathExtent,"stroke %s "
+      "stroke-width %g "
+      "line 0,0 %g,0",color,(double) metrics.underline_thickness,(double) metrics.width);
+
+    /*
+      Annotate image with text.
+    */
     if (annotate->decorate == OverlineDecoration)
       {
         annotate_info->affine.ty-=(draw_info->affine.sy*(metrics.ascent+
@@ -503,27 +518,24 @@ MagickExport MagickBooleanType AnnotateImage(Image *image,
         (void) CloneString(&annotate_info->primitive,primitive);
         (void) DrawImage(image,annotate_info,exception);
       }
-    else
-      if (annotate->decorate == UnderlineDecoration)
-        {
-          annotate_info->affine.ty-=(draw_info->affine.sy*
-            metrics.underline_position);
-          (void) CloneString(&annotate_info->primitive,primitive);
-          (void) DrawImage(image,annotate_info,exception);
-        }
-    /*
-      Annotate image with text.
-    */
-    status=RenderType(image,annotate,&offset,&metrics,exception);
-    if (status == MagickFalse)
-      break;
-    if (annotate->decorate == LineThroughDecoration)
+    else if (annotate->decorate == UnderlineDecoration)
+      {
+        annotate_info->affine.ty-=(draw_info->affine.sy*
+          metrics.underline_position);
+        (void) CloneString(&annotate_info->primitive,primitive);
+        (void) DrawImage(image,annotate_info,exception);
+      }
+    else if (annotate->decorate == LineThroughDecoration)
       {
         annotate_info->affine.ty-=(draw_info->affine.sy*(height+
-          metrics.underline_position+metrics.descent)/2.0);
+          metrics.underline_position+metrics.descent*2)/2.0);
         (void) CloneString(&annotate_info->primitive,primitive);
         (void) DrawImage(image,annotate_info,exception);
       }
+
+    status=RenderType(image,annotate,&offset,&metrics,exception);
+    if (status == MagickFalse)
+      break;
   }
   /*
     Relinquish resources.
@@ -1464,8 +1476,9 @@ static MagickBooleanType RenderFreetype(Image *image,const DrawInfo *draw_info,
   metrics->bounds.y1=metrics->descent;
   metrics->bounds.x2=metrics->ascent+metrics->descent;
   metrics->bounds.y2=metrics->ascent+metrics->descent;
-  metrics->underline_position=face->underline_position/64.0;
-  metrics->underline_thickness=face->underline_thickness/64.0;
+  metrics->underline_position=face->underline_position*(metrics->pixels_per_em.x/face->units_per_EM);
+  metrics->underline_thickness=face->underline_thickness*(metrics->pixels_per_em.x/face->units_per_EM);
+
   if ((draw_info->text == (char *) NULL) || (*draw_info->text == '\0'))
     {
       (void) FT_Done_Face(face);