How to achieve font tracking / letter spacing with font file

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
griffin
Posts: 2
Joined: 2013-03-21T11:01:25-07:00
Authentication code: 6789

How to achieve font tracking / letter spacing with font file

Post by griffin »

Hello,

I'm currently using php Imagick extension to interface ImageMagick and have come to a halt over the past week in regards to how to achieve correct font kerning combined with changed tracking. I'm posting this here, as I couldn't get it to work with ImageMagick (command line interface) either.

Before I get into detail, here are commands so you know what I talk about (and no, I can't provide the font file because of its license, but the font has correct kerning information embedded):

Here the built in kerning is honored:

Code: Select all

convert magick:granite -gravity center -font fontfile.otf -pointsize 50 -fill white -draw "text 0,0 'EVA'" ./builtin-kerning-works.png
Here it isn't:

Code: Select all

convert magick:granite -gravity center -font fontfile.otf -pointsize 50 -kerning 0.5 -fill white -draw "text 0,0 'EVA'" ./builtin-kerning-does-not-work.png
What I would need:

Code: Select all

convert magick:granite -gravity center -font fontfile.otf -pointsize 50 -kerning 0.5 -fill white -draw "text 0,0 'EVA'" ./builtin-kerning-multiplied-by-one-point-five.png
And/Or:

Code: Select all

convert magick:granite -gravity center -font fontfile.otf -pointsize 50 -letterspacing 0.5 -fill white -draw "text 0,0 'EVA'" ./builtin-kerning-plus-letterspacing-increased-fifty-percent.png
(difference in kerning/tracking, which I also needed to read up on: kerning is specific to glyph pairs, e.g. it can be different between 'V'&'A' and 'V'&'V', while tracking/letter spacing is added regardless of glyph combinations between all glyphs)

Things I've tried and failed:

- using the kerning option: As soon as you use kerning, the built-in kerning of the selected font isn't being honored anymore.
- using pango: There is an outstanding bug ticket for pango to make pango being able to load font files ; at the moment you can only use system fonts, which makes it impossible to use for me (need to use it with a font file)
- using tex: could not get this to work as there does not seem to be enough documentation regarding this. I've done tons of things with LaTeX in the past, but I've not been able to just use text as input and get it rendered as raster- or vector image suitable as input for imagemagick. Also I'd like to avoid this method for 2 reasons: 1) TeX is not installed by default on debian (I'm building a software which is to be used on standard debian hosts with installing as few bits as possible - it also works with GD instead of imagick for that reason, but GD doesn't have support for changed tracking either) 2) I want to avoid intermediate files, because of locking issues, the need to have enough storage for them, security risks, ...
- using ghostscript: Couldn't get enough info on font rendering with ghostscript ; also it seems to be not better than LaTeX/XeTeX/WhatEverTex in any regard
- using GD: out of scope here, but php GD by default uses freetype for rendering text, and even though freetype supposedly has options for letter spacing (there is a freetype gimp plugin which is said to be able to do exactly that), they aren't exposed in php
- using cairo: would need additional pecl modules and as it seems also only rely on pango, so no difference here to ImageMagick?

So, any idea on how to achieve this?

I don't wanna think this hasn't been implemented yet, as I've found requests for this feature dating back to 2004, and as I've also built a _simple_ font rendering engine in flash, I know that it's pretty easy to get kerning + tracking _fairly_ right (imagemagick docs even list a simple algorithm regarding pen positions/sliding dot problem etc. which should work for that, if you just add tracking as a fixed value to the pen position after determining the new position by using the font kerning pair tables), so, as the ingenious guys that you are, building great new algorithms all the time, what am I overlooking?

Thank you very much,

Best Regards
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to achieve font tracking / letter spacing with font

Post by anthony »

perhaps you can put in a bug report?

The kerning additions likely, just added, probably without regard or thought to the effect of any build-in kerning that may already exist in the font.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply