QueryFontMetrics / Resolution

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

QueryFontMetrics / Resolution

Post by mkoppanen »

Hello,

I recently received the following bug report http://pecl.php.net/bugs/bug.php?id=19907, which I am not sure about. Should the QueryFontMetrics honour resolution?
Mikko Koppanen
My blog: http://valokuva.org
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: QueryFontMetrics / Resolution

Post by magick »

Imagick is missing a method to set the drawing / annotation resolution. $im->setResolution() sets the image resolution. Imagick needs a $draw->setResolution() method that sets the draw_info->density member. Since density is a string, you simply take the setResolution() float values and convert them to a string and assign it to the density member of the DrawInfo structure. Imagick should also have a $draw->setPointsize() method as well.
George

Re: QueryFontMetrics / Resolution

Post by George »

There's no actual API method to set the draw resolution though, right? And, of course, using the Magick wand setresolution would cause an assertion failure for being a drawing wand.
George

Re: QueryFontMetrics / Resolution

Post by George »

Also, I'm not sure if this is related, but there seems to be a wild correlation between the textheight, and the boundingbox height. For example, here's a sample fontmetrics output of "Hello World", with resolution set to 300, and point size of 72 (I've quickly knocked together a DrawSetResolution function in drawing-wand.c). It should be around the equivalent of 1 inch.

array(10) {
["characterWidth"]=>
float(300)
["characterHeight"]=>
float(300)
["ascender"]=>
float(272)
["descender"]=>
float(-64)
["textWidth"]=>
float(1541)
["textHeight"]=>
float(345)
["maxHorizontalAdvance"]=>
float(600)
["boundingBox"]=>
array(4) {
["x1"]=>
float(0)
["y1"]=>
float(-3)
["x2"]=>
float(279)
["y2"]=>
float(215)
}
["originX"]=>
float(1545)
["originY"]=>
float(0)
}

The interesting thing is, after drawing the image, trimming, and identify'ing the output, the height of the image is 218px. the height of the bounding box in the queryfontmetrics output above, and not the textHeight.

Adding in a character with a descender lowers the y1 value as expected, but the sum of y1 and y2 are still not equal with the textHeight.
Post Reply