QueryFontMetrics Problem

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

QueryFontMetrics Problem

Post by Ghostbuster_2009 »

Hi all,

I am working with PerlMagick on three different machines, let's say
  • A (Solaris, ImageMagick 6.2.6 04/25/06 Q16),
    B (Solaris, ImageMagick 6.3.2 02/13/07 Q16) and
    C (OpenSolaris, ImageMagick 6.3.4 04/08/09 Q16).
Why does QueryFontMetrics produce different results on these machines for the same input data? I am primarily interested on the width and height return values.

Look at the following test program:

Code: Select all

#!/usr/bin/perl
use Image::Magick;
use strict;

my ($image, $x_ppem, $y_ppem, $ascender, $descender, $width, $height, $max_advance, $predict);

$image = new Image::Magick;
$image->Set(size=>"300x500",
						pointsize=>20, font=>"Arial", 
						antialias=>'true',
						density=>"50x50");
$image->Read('xc:none');

($x_ppem, $y_ppem, $ascender, $descender, $width, $height, $max_advance) 
                  = $image->QueryFontMetrics(text=>' ');

print "x_ppem        = ", $x_ppem, "\n";
print "y_ppem        = ", $y_ppem, "\n";
print "ascender      = ", $ascender, "\n";
print "descender     = ", $descender, "\n";
print "width         = ", $width, "\n";
print "height        = ", $height, "\n";
print "max_advance   = ", $max_advance, "\n";
I'd like to determine the pixel width of the space character according to the density given.

Look at the results on machine A
fontsize = 12:

Code: Select all

x_ppem        = 8
y_ppem        = 8
ascender      = 8
descender     = -2
width         = 2
height        = 10
max_advance   = 10
fontsize = 20:

Code: Select all

x_ppem        = 14
y_ppem        = 14
ascender      = 13
descender     = -3
width         = 4
height        = 16
max_advance   = 17
I think this makes sense.

Look at the results on machine B:
fontsize = 12:

Code: Select all

x_ppem        = 8
y_ppem        = 8
ascender      = 8
descender     = -2
width         = 1
height        = 10
max_advance   = 10
fontsize = 20:

Code: Select all

x_ppem        = 14
y_ppem        = 14
ascender      = 13
descender     = -3
width         = 1
height        = 16
max_advance   = 17
In both cases the same value is returned for width. For me, that does not make sense. Of course, I do use the same font data.

Look at the results on machine C:
fontsize = 12:

Code: Select all

x_ppem        = 8
y_ppem        = 8
ascender      = 7
descender     = -2
width         = 0
height        = 10
max_advance   = 8
fontsize = 20:

Code: Select all

x_ppem        = 14
y_ppem        = 14
ascender      = 11
descender     = -4
width         = 0
height        = 17
max_advance   = 14
In both cases width is returned as 0 which does as little as it makes sense for case B for me. When using other characters I am surprised to get different values for width on each machine.

What's wrong?

I'd like to use QueryFontMetrics to determine if a given text fits into a placeholder and the result should be the same on each machine where I am going to install the software.

Thanks in advance for any help,

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

Re: QueryFontMetrics Problem

Post by magick »

Type
  • identify -list font
Since Arial is Microsoft copyrighted font, we suspect its not available on your hosts. If not, ImageMagick picks a default font which may be different on each machine. Another difference is the Freetype library. Different versions may return different results for the font metrics. We tried your script with ImageMagick 6.5.9-0 and Freetype 2.3.11 on 3 different Linux hosts and it consistently returned:
  • x_ppem = 14
    y_ppem = 14
    ascender = 11
    descender = -4
    width = 4
    height = 17
    max_advance = 15
for the default font (since Arial is not available).
Ghostbuster_2009

Re: QueryFontMetrics Problem

Post by Ghostbuster_2009 »

Thanks for the very quick response, but it does not help. Arial is obviously available on Solaris. At least when typing

> identify -list Type

I get the following results:

On host A:

Code: Select all

Path: /usr/local/ImageMagick/ImageMagick-6.2.6/lib/ImageMagick-6.2.6/config/type-solaris.xml

Name                             Family                  Style   Stretch  Weight
--------------------------------------------------------------------------------
Arial                            Arial                   Normal  Normal    400
Arial-Bold                       Arial                   Normal  Normal    700
Arial-Bold-Italic                Arial                   Italic  Normal    700
Arial-Italic                     Arial                   Italic  Normal    400
...
On host B:

Code: Select all

Path: /usr/local/ImageMagick/ImageMagick-6.3.2/lib/ImageMagick-6.3.2/config/type-solaris.xml

Name                             Family                 Style   Stretch   Weight
--------------------------------------------------------------------------------
Arial                            Arial                  Normal  Normal       400
Arial-Bold                       Arial                  Normal  Normal       700
Arial-Bold-Italic                Arial                  Italic  Normal       700
Arial-Italic                     Arial                  Italic  Normal       400
Arial-Narrow                     Arial Narrow           Normal  Condensed    400
...
AND the same versions of the freetype library seems be installed on both Solaris hosts. At least the pkginfo -l command returns the same version string 'VERSION: 6.6.2.7400,REV=0.2004.12.15'. But, even if there are different version installed (the libraries do have different sizes) I don't understand why the same width (1) is return for all fontsizes on host B even though Arial font is installed.
Post Reply