Re: [IDEA] Facilities to extract TT fonts from TTC font collections
On Mon, 23 Oct 2023 at 18:13, Behdad Esfahbod wrote: > If you don't need to do this from C necessarily, check out ftCLI: > I need it from C/C++, and I am already doing efficient subsetting[1] on fetched fonts, but thank you anyway (3rd party tools helps debugging). Cheers, Francesco [1] https://github.com/podofo/podofo/blob/master/src/podofo/main/PdfFontTrueTypeSubset.cpp
Re: [IDEA] Facilities to extract TT fonts from TTC font collections
On Mon, 23 Oct 2023 at 18:35, Werner LEMBERG wrote: > In general, FreeType is not the right tool for such operations. > Yes, I understand the point. Still FreeType provides some validation of the font that one can benefit from, that's why I mainly requested the ability to fetch the Table Directory, and not something more advanced. > > For example, a special tag TTAG_tdir > > could be defined to access the raw Table Directory data with > > FT_Load_Sfnt_Table, like the following: > > Please file a feature request at > Done: https://gitlab.freedesktop.org/freetype/freetype/-/issues/1263
Re: [IDEA] Facilities to extract TT fonts from TTC font collections
On Monday, 23 October 2023 at 17:36:09 BST, Werner LEMBERG wrote: > > I recently had to extract a TrueType font from a TTC font collection > > as part of fixing bugs in the podofo library[1]. > In general, FreeType is not the right tool for such operations. > FreeType is a *rendering* library that provides a thin API for > extracting SFNT tables, mainly the ones FreeType isn't parsing by > itself. As Behdad mentioned, the `fonttools` package should help you > with your task. Besides fonttools, this isn't heavily advertised, but Font Validator's ironpython scripting interface has an example script called "ttc-splitter.py" for doing exactly that. And a "ttc-merger.py" script too, as well as a "ttx-l.py" script, which does what fonttools "ttx -l" does, ie listing font tables. They are located in Font-Validator/bin/scripting-examples/ . FontVal contains very little font-modification/writing related code as it is a font checking tool, but somehow Microsoft had included some font-writing code in there, for unknown purposes. The scripting interface uses Ironpython (an implementation of python interpreter running on microsoft Dot Net / xamarin mono) and we bundle the iron python interpreter, actually. But AFAIK I am the only person who uses that part of FontVal as part of the bulk half-yearly-ish testing on all fedora-shipped fonts.
Re: [IDEA] Facilities to extract TT fonts from TTC font collections
> I recently had to extract a TrueType font from a TTC font collection > as part of fixing bugs in the podofo library[1]. In general, FreeType is not the right tool for such operations. FreeType is a *rendering* library that provides a thin API for extracting SFNT tables, mainly the ones FreeType isn't parsing by itself. As Behdad mentioned, the `fonttools` package should help you with your task. > For example, a special tag TTAG_tdir > could be defined to access the raw Table Directory data with > FT_Load_Sfnt_Table, like the following: > > FT_ULong size = 0; > FT_Load_Sfnt_Table(face, TTAG_tdir, 0, NULL, ); Please file a feature request at https://gitlab.freedesktop.org/freetype/freetype/-/issues/ Werner
Re: [IDEA] Facilities to extract TT fonts from TTC font collections
If you don't need to do this from C necessarily, check out ftCLI: https://github.com/ftCLI/FoundryTools-CLI Or "fonttools ttLib --help" from fonttools: https://github.com/fonttools/fonttools behdad http://behdad.org/ On Mon, Oct 23, 2023 at 6:44 AM Francesco Pretto wrote: > Hello, > > I recently had to extract a TrueType font from a TTC font collection > as part of fixing bugs in the podofo library[1]. Since I couldn't find > an API suited for the task, I found myself in need to manually parse > the TTC Header, which is not a type exposed in the FreeType public > API. I believe FreeType could have helped me much better if, for > example, it would have provided a way to extract the actual face Table > Directory[2] from the font data. For example, a special tag TTAG_tdir > could be defined to access the raw Table Directory data with > FT_Load_Sfnt_Table, like the following: > > FT_ULong size = 0; > FT_Load_Sfnt_Table(face, TTAG_tdir, 0, NULL, ); > > Interestingly enough, Windows GetFontData[3] seems to do something > similar (but with inverted semantics) when using the special table > "0", while to access whole file in case of collections it uses the > special ttcf "table tag". > > Since I already crafted my own solution, I'm not in a rush for > improvements in FreeType, but it could be something good to have in a > future release. > > Regards, > Francesco > > [1] > https://github.com/podofo/podofo/blob/df36740b176fa535a8dc6dfc5a1b940f84710aa8/src/podofo/private/FreetypePrivate.cpp#L177 > [2] > https://learn.microsoft.com/en-us/typography/opentype/spec/otff#table-directory > [3] > https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getfontdata > >