How can I debug kerning support?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
sethcall
Posts: 15
Joined: 2015-10-23T05:47:36-07:00
Authentication code: 1151

How can I debug kerning support?

Post by sethcall »

I'm using a relatively new version of IM (tried 6.9.2-4, 6.9.3-0, MacOSX via brew as well as Linux via built-from-source), but it appears that kerning is not being processed correctly by IM.

I have a font that appears in any other program much differently than it does in IM. I.e., kerning looks to be ignored.

Specifically, some characters that are usually bunched closer together are spaced much further apart when IM renders it.

Any directions I should go off in to debug this?

Thanks all!
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How can I debug kerning support?

Post by magick »

There was a recent patch to ImageMagick that could affect kerning, you'll need ImageMagick-6.9.3-3 to verify. In the mean-time, add -debug annotate to your command line to see the type metrics.
sethcall
Posts: 15
Joined: 2015-10-23T05:47:36-07:00
Authentication code: 1151

Re: How can I debug kerning support?

Post by sethcall »

Oh wow. OK, I'll try this version ASAP. Thanks!
sethcall
Posts: 15
Joined: 2015-10-23T05:47:36-07:00
Authentication code: 1151

Re: How can I debug kerning support?

Post by sethcall »

Doh. That didn't make a difference.

Here's my command:

Code: Select all

convert -trim -gravity center -background transparent -fill '#333333' -density '53' -size '159x133' -font 'path/to/some/font.ttf' -alpha on label:'TIME' 'tmp/image.png'
Pretty typical usage I think? Anything I should consider doing differently? Any other tips? I ran -debug annotate with the command, and sure, I see a bunch of info, but really I'm not able to digest it as of yet. Nothing stands out as wrong or right, to my untrained eyes.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How can I debug kerning support?

Post by fmw42 »

Does this work any better with a more proper IM 6 syntax order.

Code: Select all

convert -size '159x133' -background transparent -fill '#333333' -font 'path/to/some/font.ttf' -gravity center label:'TIME' -trim +repage -alpha on -density '53' 'tmp/image.png'
sethcall
Posts: 15
Joined: 2015-10-23T05:47:36-07:00
Authentication code: 1151

Re: How can I debug kerning support?

Post by sethcall »

Hey Fred,

I was really hopeful about your suggestion. Unfortunately it created the exact same image as with the other syntax.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How can I debug kerning support?

Post by fmw42 »

What is the font? Can you provide a link to it?

This will get you the font metrics (-debug annotate)

Code: Select all

convert -debug annotate -size '159x133' -background transparent -fill '#333333' -font 'path/to/some/font.ttf' -gravity center label:'TIME' -trim +repage -alpha on -density '53' 'tmp/image.png'
sethcall
Posts: 15
Joined: 2015-10-23T05:47:36-07:00
Authentication code: 1151

Re: How can I debug kerning support?

Post by sethcall »

Hey...

The font is Script MT Bold. The problem is very obvious when you spell TIME. The T and I and M's spacing is large compared to when you do it in a text editor or other font-supporting program.

I'm not sure if Script MT Bold is legally free or not (I'm fairly sure we had to license it, or we did just to be careful), but for purposes of trying to create the issue, it seems to be available all over the place on the net...

Code: Select all

convert -size '159x133' -background transparent -fill '#333333' -font 'app/assets/fonts/script-mt-bold.ttf' -gravity center label:'TIME' -trim +repage -alpha on -density '53' 'tmp/image.png'
seth@ubuntu:~/ImageMagick-6.9.3-3$ convert -debug annotate -size '159x133' -background transparent -fill '#333333' -font 'app/assets/fonts/script-mt-bold.ttf' -gravity center label:'TIME' -trim +repage -alpha on -density '53' 'tmp/image.png'
2016-02-09T01:36:38-06:00 0:00.000 0.000u 6.9.3 Annotate convert[22316]: annotate.c/RenderFreetype/1420/Annotate
  Font app/assets/fonts/script-mt-bold.ttf; font-encoding none; text-encoding none; pointsize 12
2016-02-09T01:36:38-06:00 0:00.000 0.000u 6.9.3 Annotate convert[22316]: annotate.c/GetTypeMetrics/842/Annotate
  Metrics: text: TIME; width: 34.6562; height: 14; ascent: 9; descent: -4; max advance: 13; bounds: 0.34375,0  6.39062,8; origin: 33,0; pixels per em: 12,12; underline position: -1.5625; underline thickness: 0.78125
2016-02-09T01:36:38-06:00 0:00.000 0.000u 6.9.3 Annotate convert[22316]: annotate.c/RenderFreetype/1420/Annotate
  Font app/assets/fonts/script-mt-bold.ttf; font-encoding none; text-encoding none; pointsize 12
2016-02-09T01:36:38-06:00 0:00.000 0.000u 6.9.3 Annotate convert[22316]: annotate.c/GetTypeMetrics/842/Annotate
  Metrics: text: TIME; width: 34.6562; height: 14; ascent: 9; descent: -4; max advance: 13; bounds: 0.34375,0  6.39062,8; origin: 33,0; pixels per em: 12,12; underline position: -1.5625; underline thickness: 0.78125
2016-02-09T01:36:38-06:00 0:00.000 0.000u 6.9.3 Annotate convert[22316]: annotate.c/RenderFreetype/1420/Annotate
  Font app/assets/fonts/script-mt-bold.ttf; font-encoding none; text-encoding none; pointsize 24
2016-02-09T01:36:38-06:00 0:00.000 0.000u 6.9.3 Annotate convert[22316]: annotate.c/GetTypeMetrics/842/Annotate
  Metrics: text: TIME; width: 68.2969; height: 29; ascent: 17; descent: -8; max advance: 25; bounds: 0.703125,0  12.7656,17; origin: 68,0; pixels per em: 24,24; underline position: -1.5625; underline thickness: 0.78125
2016-02-09T01:36:38-06:00 0:00.010 0.000u 6.9.3 Annotate convert[22316]: annotate.c/RenderFreetype/1420/Annotate
  Font app/assets/fonts/script-mt-bold.ttf; font-encoding none; text-encoding none; pointsize 48
2016-02-09T01:36:38-06:00 0:00.010 0.000u 6.9.3 Annotate convert[22316]: annotate.c/GetTypeMetrics/842/Annotate
  Metrics: text: TIME; width: 135.609; height: 58; ascent: 34; descent: -15; max advance: 50; bounds: 1.39062,-1  25.5312,34; origin: 135,0; pixels per em: 48,48; underline position: -1.5625; underline thickness: 0.78125
2016-02-09T01:36:38-06:00 0:00.010 0.000u 6.9.3 Annotate convert[22316]: annotate.c/RenderFreetype/1420/Annotate
  Font app/assets/fonts/script-mt-bold.ttf; font-encoding none; text-encoding none; pointsize 96
2016-02-09T01:36:38-06:00 0:00.010 0.000u 6.9.3 Annotate convert[22316]: annotate.c/GetTypeMetrics/842/Annotate
  Metrics: text: TIME; width: 269.219; height: 115; ascent: 67; descent: -30; max advance: 100; bounds: 2.78125,-1  51.0781,67; origin: 269,0; pixels per em: 96,96; underline position: -1.5625; underline thickness: 0.78125
2016-02-09T01:36:38-06:00 0:00.010 0.000u 6.9.3 Annotate convert[22316]: annotate.c/RenderFreetype/1420/Annotate
  Font app/assets/fonts/script-mt-bold.ttf; font-encoding none; text-encoding none; pointsize 192
2016-02-09T01:36:38-06:00 0:00.010 0.000u 6.9.3 Annotate convert[22316]: annotate.c/GetTypeMetrics/842/Annotate
  Metrics: text: TIME; width: 536.438; height: 230; ascent: 134; descent: -59; max advance: 200; bounds: 5.5625,-2  102.141,135; origin: 538,0; pixels per em: 192,192; underline position: -1.5625; underline thickness: 0.78125
2016-02-09T01:36:38-06:00 0:00.010 0.000u 6.9.3 Annotate convert[22316]: annotate.c/RenderFreetype/1420/Annotate
  Font app/assets/fonts/script-mt-bold.ttf; font-encoding none; text-encoding none; pointsize 96.5
2016-02-09T01:36:38-06:00 0:00.020 0.000u 6.9.3 Annotate convert[22316]: annotate.c/GetTypeMetrics/842/Annotate
  Metrics: text: TIME; width: 270.203; height: 116; ascent: 68; descent: -30; max advance: 101; bounds: 2.79688,-1  51.3438,67; origin: 270,0; pixels per em: 97,97; underline position: -1.5625; underline thickness: 0.78125
2016-02-09T01:36:38-06:00 0:00.020 0.010u 6.9.3 Annotate convert[22316]: annotate.c/RenderFreetype/1420/Annotate
  Font app/assets/fonts/script-mt-bold.ttf; font-encoding none; text-encoding none; pointsize 48.5
2016-02-09T01:36:38-06:00 0:00.020 0.010u 6.9.3 Annotate convert[22316]: annotate.c/GetTypeMetrics/842/Annotate
  Metrics: text: TIME; width: 136.594; height: 58; ascent: 34; descent: -15; max advance: 51; bounds: 1.40625,-1  25.7969,34; origin: 136,0; pixels per em: 49,49; underline position: -1.5625; underline thickness: 0.78125
2016-02-09T01:36:38-06:00 0:00.020 0.010u 6.9.3 Annotate convert[22316]: annotate.c/RenderFreetype/1420/Annotate
  Font app/assets/fonts/script-mt-bold.ttf; font-encoding none; text-encoding none; pointsize 72.5
2016-02-09T01:36:38-06:00 0:00.020 0.010u 6.9.3 Annotate convert[22316]: annotate.c/GetTypeMetrics/842/Annotate
  Metrics: text: TIME; width: 203.891; height: 87; ascent: 51; descent: -23; max advance: 76; bounds: 2.10938,-1  38.5625,50; origin: 204,0; pixels per em: 73,73; underline position: -1.5625; underline thickness: 0.78125
2016-02-09T01:36:38-06:00 0:00.020 0.010u 6.9.3 Annotate convert[22316]: annotate.c/RenderFreetype/1420/Annotate
  Font app/assets/fonts/script-mt-bold.ttf; font-encoding none; text-encoding none; pointsize 60.5
2016-02-09T01:36:38-06:00 0:00.020 0.010u 6.9.3 Annotate convert[22316]: annotate.c/GetTypeMetrics/842/Annotate
  Metrics: text: TIME; width: 171.25; height: 73; ascent: 43; descent: -19; max advance: 63; bounds: 1.75,-1  32.1875,42; origin: 171,0; pixels per em: 61,61; underline position: -1.5625; underline thickness: 0.78125
2016-02-09T01:36:38-06:00 0:00.020 0.010u 6.9.3 Annotate convert[22316]: annotate.c/RenderFreetype/1420/Annotate
  Font app/assets/fonts/script-mt-bold.ttf; font-encoding none; text-encoding none; pointsize 54.5
2016-02-09T01:36:38-06:00 0:00.020 0.010u 6.9.3 Annotate convert[22316]: annotate.c/GetTypeMetrics/842/Annotate
  Metrics: text: TIME; width: 153.422; height: 65; ascent: 38; descent: -17; max advance: 57; bounds: 1.57812,-1  29,39; origin: 153,0; pixels per em: 55,55; underline position: -1.5625; underline thickness: 0.78125
2016-02-09T01:36:38-06:00 0:00.020 0.010u 6.9.3 Annotate convert[22316]: annotate.c/RenderFreetype/1420/Annotate
  Font app/assets/fonts/script-mt-bold.ttf; font-encoding none; text-encoding none; pointsize 57.5
2016-02-09T01:36:38-06:00 0:00.020 0.010u 6.9.3 Annotate convert[22316]: annotate.c/GetTypeMetrics/842/Annotate
  Metrics: text: TIME; width: 162.328; height: 69; ascent: 40; descent: -18; max advance: 60; bounds: 1.67188,-1  30.5938,40; origin: 162,0; pixels per em: 58,58; underline position: -1.5625; underline thickness: 0.78125
2016-02-09T01:36:38-06:00 0:00.020 0.010u 6.9.3 Annotate convert[22316]: annotate.c/RenderFreetype/1420/Annotate
  Font app/assets/fonts/script-mt-bold.ttf; font-encoding none; text-encoding none; pointsize 56
2016-02-09T01:36:38-06:00 0:00.020 0.010u 6.9.3 Annotate convert[22316]: annotate.c/GetTypeMetrics/842/Annotate
  Metrics: text: TIME; width: 157.375; height: 67; ascent: 39; descent: -18; max advance: 58; bounds: 1.625,-1  29.7969,39; origin: 157,0; pixels per em: 56,56; underline position: -1.5625; underline thickness: 0.78125
2016-02-09T01:36:38-06:00 0:00.020 0.010u 6.9.3 Annotate convert[22316]: annotate.c/RenderFreetype/1420/Annotate
  Font app/assets/fonts/script-mt-bold.ttf; font-encoding none; text-encoding none; pointsize 56.25
2016-02-09T01:36:38-06:00 0:00.030 0.010u 6.9.3 Annotate convert[22316]: annotate.c/GetTypeMetrics/842/Annotate
  Metrics: text: TIME; width: 157.375; height: 68; ascent: 40; descent: -18; max advance: 59; bounds: 1.625,-1  29.9219,39; origin: 157,0; pixels per em: 56,56; underline position: -1.5625; underline thickness: 0.78125
2016-02-09T01:36:38-06:00 0:00.030 0.010u 6.9.3 Annotate convert[22316]: annotate.c/RenderFreetype/1420/Annotate
  Font app/assets/fonts/script-mt-bold.ttf; font-encoding none; text-encoding none; pointsize 56.25
2016-02-09T01:36:38-06:00 0:00.030 0.010u 6.9.3 Annotate convert[22316]: annotate.c/GetTypeMetrics/842/Annotate
  Metrics: text: TIME; width: 157.375; height: 68; ascent: 40; descent: -18; max advance: 59; bounds: 1.625,-1  29.9219,39; origin: 157,0; pixels per em: 56,56; underline position: -1.5625; underline thickness: 0.78125
2016-02-09T01:36:38-06:00 0:00.030 0.010u 6.9.3 Annotate convert[22316]: annotate.c/RenderFreetype/1420/Annotate
  Font app/assets/fonts/script-mt-bold.ttf; font-encoding none; text-encoding none; pointsize 56.25
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How can I debug kerning support?

Post by fmw42 »

I have downloaded the script mt bold font and run the following two commands. Does this look correct to you? It looks reasonable to me. If not, then post examples of what you get from IM and from your other programs.

Code: Select all

convert -size 200x200 xc:white -gravity center -font /Library/fonts/Script_MT_Bold.ttf -fill black \
-pointsize 36 -annotate +0+0 "Testing" -trim +repage -bordercolor white -border 5 font_script_mt_bold1.png
Image

Code: Select all

convert -background white -gravity center -font /Library/fonts/Script_MT_Bold.ttf -fill black \
-pointsize 36 label:"Testing" -trim +repage -bordercolor white -border 5 font_script_mt_bold2.png
Image

This is a screensnap from MS Word. (Ignore the small vertical line at the bottom left corner. I think it was the tip of the type indicator for the next character showing in the screen snap).
Image

The cap T in the IM rendering seems to overlap a bit; whereas in Word it does not. But I think it looks better in IM than Word.
sethcall
Posts: 15
Joined: 2015-10-23T05:47:36-07:00
Authentication code: 1151

Re: How can I debug kerning support?

Post by sethcall »

Ok, now that's interesting and confusing.

When I run 'Testing' in ImageMagick, I get what you got in MS Word (a large space between T and e, which is the same problem I've seen when I do TIME in ImageMagick--the space between T, I, and M is large -- it exaggerates this problem).

However, when I run Testing in 'Pages' (MacOSX freebie MSWord), I get what you got from ImageMagick--small gap between T and e, which I believe to be the correct behavior.

So let me focus on this; I think your ImageMagick is correctly behaving, and mine is not. So that implies dependencies/environment differences.

And so my goal is to get my ImageMagick to behave like your ImageMagick, since it's doing what I think it should be.

Could you share what version of ImageMagick you are using, and also your version of freetype? (not sure what else might be at play here; I think those are the two biggest possible culprits here)
sethcall
Posts: 15
Joined: 2015-10-23T05:47:36-07:00
Authentication code: 1151

Re: How can I debug kerning support?

Post by sethcall »

Focusing on linux, my versions are:

IM: 6.9.3-3
freetype: 2.4.8 as well as 2.5.2-1ubuntu2.5 (different test machines, both show problem)

Edit: tried FreeType 2.6.3-3 (latest I see on the website); no difference.

Thinking it's not FreeType related at the moment.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How can I debug kerning support?

Post by fmw42 »

I am on Mac OSX Snow Leopard


convert -version
Version: ImageMagick 6.9.3-3 Q16 x86_64 2016-02-07 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib cairo fftw fontconfig freetype gslib jbig jng jp2 jpeg lcms lqr ltdl lzma openexr png ps rsvg tiff webp x xml zlib


freetype @2.6.2_0

fontconfig @2.11.1_0


Code: Select all

convert -size 200x200 xc:white -gravity center -font /Library/fonts/Script_MT_Bold.ttf -fill black \
-pointsize 36 -annotate +0+0 "TIME" -trim +repage -bordercolor white -border 5 font_script_mt_bold1.png
Image

Code: Select all

convert -background white -gravity center -font /Library/fonts/Script_MT_Bold.ttf -fill black \
-pointsize 36 label:"TIME" -trim +repage -bordercolor white -border 5 font_script_mt_bold2.png
Image

This is a screensnap from MS Word.
Image
sethcall
Posts: 15
Joined: 2015-10-23T05:47:36-07:00
Authentication code: 1151

Re: How can I debug kerning support?

Post by sethcall »

Thanks for being so helpful fred.

So, I just went to one of these many web sites that have the font, and grabbed a version of it, and the different version now 'works'. Figuring that's what you must have done.

Sigh. So the version we *bought* is basically not so great.

Also, noticed that MS Word does not seem to honor the kerning either on MacOSX, Pages does though.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How can I debug kerning support?

Post by fmw42 »

Post Reply