Yet another QueryFontMetrics question

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
Ryland

Yet another QueryFontMetrics question

Post by Ryland »

QueryFontMetrics() returns the ascender and descender value for a font, and the height and width of a text string, but it doesn't give a relation between the two, that is, it doesn't give the font's actual height above the baseline (which is often different from the ascender value). Is there any way to do this, other than a hack such as getting the height of a capital M and calculating the height from baseline from that?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Yet another QueryFontMetrics question

Post by magick »

QueryFontMetrics returns
  • % 0 character width
    % 1 character height
    % 2 ascender
    % 3 descender
    % 4 text width
    % 5 text height
    % 6 maximum horizontal advance
However we have these additional values available which we currently do not return:
  • % 7 bounding box: x1
    % 8 bounding box: y1
    % 9 bounding box: x2
    % 10 bounding box: y2
    % 11 origin: x
    % 12 origin: y
We can expose the other values if they will return what you need. If not, define precisely what you need by consulting the source. See RenderFreetype() in magick/annotate.c around line 1360.
Ryland

Re: Yet another QueryFontMetrics question

Post by Ryland »

Well, it would be great to have those values, but if you're talking about releasing an updated version of ImageMagick, I'm not sure that would help me, as I'm using a webhosting service and I don't know how they'll feel about updating. (They're using version 6.2.9, for what it's worth.) I was just wondering if someone else had encountered the same problem and figured out a work-around.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Yet another QueryFontMetrics question

Post by anthony »

AN alturnative way is to actually render the character then trim it to determine the information. It will be relatively slow but it will always work.

I do some simular statistical gathering in IM Examples for the command line interface, but the principle is that same. For PerlMagick the image does not need to be written or exposed outside the script.
See Determining Font Metrics, without using an API for more info.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply