In trying to clean up my libTERE text reassembler code so that it works properly with R->L languages like Hebrew I found that the Hebrew glyphs mostly contain no useful vertical extent information, even though this information is present for English language characters. Here is the code (in C, this is not strictly a part of Inksape, but is used by it):
int TR_getadvance(FNT_SPECS *fsp, uint32_t wc, uint32_t pc, int load_flags, int kern_mode, int *ymin, int *ymax){ FT_Glyph glyph; int glyph_index; int advance=-1; FT_BBox bbox;
glyph_index = FT_Get_Char_Index( fsp->face, wc); if (!FT_Load_Glyph( fsp->face, glyph_index, load_flags )){ printf("DEBUG TR_getadvance 1\n");fflush(stdout); if ( !FT_Get_Glyph( fsp->face->glyph, &glyph ) ) { printf("DEBUG TR_getadvance 2\n");fflush(stdout); advance = fsp->face->glyph->advance.x; FT_Glyph_Get_CBox( glyph, FT_GLYPH_BBOX_UNSCALED, &bbox ); printf("DEBUG TR_getadvance bbox.ymax/ymin %d,%d\n",bbox.yMax,bbox.yMin);fflush(stdout); printf("DEBUG TR_getadvance glyph metrics height %d vertbearing Y %d\n",fsp->face->glyph->metrics.height,fsp->face->glyph->metrics.vertBearingY);fflush(stdout); if(ymin && (bbox.yMin < *ymin))*ymin=bbox.yMin; if(ymax && (bbox.yMax > *ymax))*ymax=bbox.yMax; if(pc)advance += TR_getkern2(fsp, wc, pc, kern_mode); FT_Done_Glyph(glyph); } } return(advance); }
When the font is "Century Schoolbook L", for instance all Hebrew strings trigger a series of these output lines: DEBUG TR_getadvance 1 DEBUG TR_getadvance 2 DEBUG TR_getadvance bbox.ymax/ymin 0,0 DEBUG TR_getadvance glyph metrics height 0 vertbearing Y 0
and ymin,ymax are returned as zero. So far only one tested font actually had this vertical extent information for these glyphs - Verdana.
The glyph does eventually render OK in Cairo, but not being able to figure out the vertical extent of the bounding box really makes it difficult to reassemble complex text into <text><tspan> structures!
Is there some trick for pulling these vertical extent values out when the font itself appears not to hold them? Perhaps a function that will calculate them from the glyph instead of reading them from the font? The only other approach I could think of was to fall back to looking up the vertical extents for some glyph that does have these values, like "A", and applying them for the missing Hebrew glyph. That would be a terrible approximation, but better than saying the vertical extent is zero!
Thanks,
David Mathog mathog@...1176... Manager, Sequence Analysis Facility, Biology Division, Caltech