[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ft-devel] Detect all available characters in a font?
From: |
Werner LEMBERG |
Subject: |
Re: [ft-devel] Detect all available characters in a font? |
Date: |
Sun, 21 Nov 2010 08:13:52 +0100 (CET) |
> Is there any way to detect all the available characters in a loaded
> font?
It depends on how you define `character'. If you mean `I have an
input character code, and I want to know whether the font has a glyph
for it', then the answer is yes.
> It would be convenient if I had some way to do this:
>
> for (i=0; i<FT_Font_CountChars(font); i++ )
> {
> c = FT_Font_GetChar( i );
> //Proceed to load character 'c'...
> }
Well, just use
{
FT_ULong charcode;
FT_UInt gindex;
charcode = FT_Get_First_Char( face, &gindex );
while ( gindex != 0 )
{
... do something with (charcode,gindex) pair ...
charcode = FT_Get_Next_Char( face, charcode, &gindex );
}
}
to iterate over all characters contained in a given cmap. This is the
example from the documentation of FT_Get_First_Char.
Note, however, that this is a very naive approach which certainly
fails for non-latin scripts. For example, to properly render
Devanagari scripts, it's not sufficient to use the above code since
there are 112 glyphs defined in the block U+0900 - U+097F but you need
a few hundred glyphs to be accessed via input character code
reordering and heavy use of ligatures.
You can avoid such hassles if you try one of the various high-level
libraries like Qt, Pango, ICU, or, to a certain extent, libotf.
Werner