Derek Leach
2010-Aug-27 15:26 UTC
[Fontconfig] fontconfig/freetype: resolving glyph index from another font when base font does not contain particular glyph
Hi everyone, I have fontconfig and freetype installed, and "working" for rendering "base" fonts, i.e. the family name is resolved properly, like Arial, and if the glyph is contained within that font, all the rendering proceeds. Now, I need to figure out what is necessary to "properly" implement glyph fallback ... 1) What API calls do I use to request fontconfig, given a glyph index, or character code, to find the font which contains the glyph I need? 2) I know fontconfig contains a map of the glyph indices within the font, so is the process obtaining a list of font faces from fontconfig, and iterating them one by one, or does fontconfig have a more direct approach? I guess the above two questions are the same, but I just wanted to clarify things even further. I will look at Pango, but if some can provide me with the "simple/direct" approach for accomplishing this, I would truly appreciate it. Kind Regards, -Derek -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.freedesktop.org/archives/fontconfig/attachments/20100827/d4371dd7/attachment.htm>
mpsuzuki at hiroshima-u.ac.jp
2010-Aug-28 05:24 UTC
[Fontconfig] fontconfig/freetype: resolving glyph index from another font when base font does not contain particular glyph
Hi, On Fri, 27 Aug 2010 11:26:13 -0400 "Derek Leach" <DLeach at qnx.com> wrote:>I have fontconfig and freetype installed, and "working" for rendering >"base" fonts, i.e. the family name is resolved properly, like Arial, and >if the glyph is contained within that font, all the rendering proceeds. > >Now, I need to figure out what is necessary to "properly" implement >glyph fallback ... > >1) What API calls do I use to request fontconfig, given a glyph >index, or character code, to find the font which contains the glyph I >need?To seach a font by fontconfig, the "pattern" object should be created and passed to fontconfig. To check the existence of valid glyph for a specified character code point(s), the query process would be following: 1) create a FcCharSet including target character 1-a) create an empty FcCharSet by FcCharSetCreate() 1-b) add the target characters to the FcCharset by FcCharSetAddChar() 2) create a FcPattern including FcCharSet that we created 2-a) create an empty FcPattern by FcPatternCreate() 2-b) add the FcCharSet to FcPattern by FcPatternAddCharSet() 3) lookup the fonts matching with the pattern by FcFontMatch() 4) finalize FcPattern & FcCharSet after the query. I''m afraid fontconfig can check the existence of valid glyph for specified character code, but cannot answer for specified glyph index. Checking the source freetype/src/fcfreetype.c, the glyph index in FcFreeTypeCharSetAndSpacingForSize() is not exported to out of the function. Also, fontconfig.h defines FcCharSet structure, but I cannot find something like FcGlyphSet. I don''t find a fontconfig function taking a glyph index in its argument. It seems that fontconfig can handle the database of the glyph names, but I have no experience.>2) I know fontconfig contains a map of the glyph indices within >the font,Oh, I didn''t know. Which data structure has the map of glyph index? Regards, mpsuzuki
Behdad Esfahbod
2010-Aug-31 01:09 UTC
[Fontconfig] fontconfig/freetype: resolving glyph index from another font when base font does not contain particular glyph
On 08/27/10 11:26, Derek Leach wrote:> 2) I know fontconfig contains a map of the glyph indices within > the font, so is the process obtaining a list of font faces from > fontconfig, and iterating them one by one, or does fontconfig have a > more direct approach?Yes, that''s the idea. FcFontSort() gives you a list of font patterns. You walk them one by one, check their charset and choose the first one supporting the character you are interested in. behdad
Many thanks to Behdad and mpsuzuki, I have my character fallbacks "working" now! :-) Now I have added this (below) to my fonts.conf <match> <test name="lang"> <string>utf-8</string> <string>euc-jp</string> <string>jp</string> </test> <test qual="all" name="family" target="default"> <string>sans-serif</string> <string>serif</string> <string>monospace</string> <string>PrimaSans BT</string> <string>PrimaSansMono BT</string> <string>Courier10 BT</string> <string>Swis721 BT</string> <string>Dutch801 Rm BT</string> <string>arial</string> </test> <edit name="family" mode="append"> <string>HonMincho BT</string> </edit> <edit name="family" mode="append"> <string>SquareGothicMd BT</string> </edit> </match> The system always returns MSungGB-C_LTUnivers88 (contains the uniChar), instead of HonMincho BT or SquareGothicMd BT (contains uniChar, but want these to be the preferred). Do I have anything wrong with the above syntax, or is my code wrong (see attached)? In the code that I tried ''forcing'' the family to Arial to try and get it to match the configuration, just for testing purposes. Do I need to set the ''lang'' as well? I basically want to be able to override the fallback fonts for a specific family ... if the uniChar is in those fonts, otherwise the standard fallback procedure should then happen. Kind Regards + Many Thanks, -Derek -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.freedesktop.org/archives/fontconfig/attachments/20100901/7a247781/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: example.cpp Type: application/octet-stream Size: 2457 bytes Desc: example.cpp URL: <http://lists.freedesktop.org/archives/fontconfig/attachments/20100901/7a247781/attachment.obj>