|
From: | Balraj Balakrishnan, Integra-PDY, IN |
Subject: | [ft] FW: Getting the charcode Value when the Glyph ID is known |
Date: | Fri, 29 Apr 2011 12:01:54 +0000 |
Dear Werner LEMBERG, Thanks a lot for your response. 1. There is a slight issue in differentiating two similar fonts having the same shape: if we take into consideration Quote right (Glyph ID : 2; Character Code: 8217; Font File Name: Times New Roman) and Comma(Glyph
ID : 3; Character Code: 44; Font File Name: Times New Roman) there shapes are alike, based on their position in the image we can differentiate if it is a comma or a quote right, but the code snippet (referred from the sample example2.cpp) below cuts the outline
based upon the size of the glyph which makes it difficult to recognize if the image is really a quote right or comma. Snippet: FT_UInt gindex = FT_Get_Char_Index(face, ch); if (FT_Load_Glyph(face, gindex, FT_LOAD_NO_BITMAP) == 0) { // Need an outline for this to work. if (face->glyph->format == FT_GLYPH_FORMAT_OUTLINE) { // Render the basic glyph to a span list. Spans spans; RenderSpans(library, &face->glyph->outline, &spans); // Next we need the spans for the outline. Spans outlineSpans; // Set up a stroker. FT_Stroker stroker; FT_Stroker_New(library, &stroker); FT_Stroker_Set(stroker, (int)(outlineWidth * 64), FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0); FT_Glyph glyph; if (FT_Get_Glyph(face->glyph, &glyph) == 0) { FT_Glyph_StrokeBorder(&glyph, stroker, 0, 1); // Again, this needs to be an outline to work. if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) { // Render the outline spans to the span list FT_Outline *o = &reinterpret_cast<FT_OutlineGlyph>(glyph)->outline; RenderSpans(library, o, &outlineSpans); } // Clean up afterwards. FT_Stroker_Done(stroker); FT_Done_Glyph(glyph); Void RenderSpans(FT_Library &library, FT_Outline * const outline, Spans *spans) { FT_Raster_Params params; memset(¶ms, 0, sizeof(params)); params.flags = FT_RASTER_FLAG_AA | FT_RASTER_FLAG_DIRECT; params.gray_spans = RasterCallback; params.user = spans; FT_Outline_Render(library, outline, ¶ms); } Snippet End How can I achieve the glyph image with its proper positioning, in order to tackle this scenario? Note: Attached please find the two relevant glyph images and the corresponding Font File related to the issue. 2. If you want to iterate over all glyphs you shouldn't use FT_*_Char functions. Can you help me with other alternatives which are there to iterate all the glyphs present in the font file irrespective of the cmap table. Be Well, Amith Sai -----Original Message----- From: Werner LEMBERG [mailto:address@hidden Sent: 26 April 2011 22:52 To: Balraj Balakrishnan, Integra-PDY, IN Cc: address@hidden; Amith Pradeep, Integra-PDY, IN Subject: Re: [ft] Getting the charcode Value when the Glyph ID is known > 1. While using the FT_Get_First_Char and FT_Get_Next_Char to iterate
> the glyphs id's one by one to retrieve all the glyphs present in the
> font file, it fails to get all the glyph id's from the font file, some
> of the glyph id's are gone missing. This means that the cmap (which you have selected manually, or which has been selected as a default by FreeType) doesn't map a character code to the particular glyph. Especially with rich-featured OpenType
fonts there are a lot of such glyphs because the `GSUB' table can further manipulate glyph IDs. Just think of Indic fonts which need a lot of ligatures which don't have a character code. If you want to iterate over all glyphs you shouldn't use FT_*_Char
functions. > 2. In order to suppress the previous problem, I did a work around by
> putting a for loop to retrieve all the glyph id's present in the range
> between 1 to 256, so far its working fine, but my concern with this
> is: > > a. Now that I am retrieving the glyph's, how can I get the character
> code for each glyph ID? There is no one-to-one mapping between character codes and glyph IDs! Please read the OpenType specification for more details. The same is true for PS fonts; some fonts contain named glyphs with no proper corresponding (Unicode) character code. Ditto for CID-keyed fonts. > b. Can the glyph ID exceed the range of 1-255? Yes, of course. Usually, it's in the range 0x0000-0xFFFF, but some font formats support even higher glyph index values (e.g. BDF). Werner |
2~quoteright~8217.tga
Description: 2~quoteright~8217.tga
3~comma~44.tga
Description: 3~comma~44.tga
TimesNewRoman.pfa
Description: TimesNewRoman.pfa
[Prev in Thread] | Current Thread | [Next in Thread] |