how does GD's imagettftext determine whether a font supports a particular character

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

From the documentation for GD's imagettftex about unsupported characters:

"If a character is used in the string which is not supported by the font, a
hollow rectangle will replace the character."

This is rather less than great, because it means that GD will do something
other than what it was instructed to - namely, instead of drawing the
indicated text, it'll draw a *different text* without so much as a warning or
a return flag that says "I didn't generate what you wanted, you may want to
do something with that information". Is there a function in GD that lets one
test whether a font supports a character? If not, is there some other way to
determine whether a font supports a glyph (in PHP)?

I'm using GD to show what CJK characters look like in various asian
typefaces, and there isn't a font in existence that contains all CJK
characters (by virtue of the opentype/truetype specification only supporting
65355 characters per font). As such, I want to know whether the font it's
using supports the glyph and if not, not bother drawing it in the image.

Can GD be instructed to signal it did a string substitution when drawing
textIf not, is there ANY way to analyze a font in PHP in a way that lets one
determine whether it supports a specified glyph?

- Mike "Pomax" Kamermans

Re: how does GD's imagettftext determine whether a font supports a particular character wrote:
Quoted text here. Click to load it

I don't think PHP or GD have any knowledge about this. It all happens below
GD, inside Freetype. GD asks for an index to character "X" in the font, and
Freetype returns an index to the empty box because "X" doesn't exist in the
font. Well, actually, I think what Freetype returns is 0, which is the code
for Missing Glyph or Undefined Character Code, and which renders as the
box. If this is true, it means theoretically GD could indicate somehow that
the character doesn't exist - but currently it does not use that information.

Sorry, not much help, but I think that means you are out of luck. Perhaps
you could find some other tool - that uses Freetype directly - that can
determine what character codes exists in a font.

Site Timeline