FreeTypeAbstraction.jl
FreeTypeAbstraction.jl copied to clipboard
Add capability to fetch alternate glyphs
Some characters in some fonts have multiple glyph that can represent them. Typically the integral sign in math font has one version for inline math and one one for block equations.
Currently, it looks like the alternate glyph can be retrieved as follow:
julia> font = FTFont("assets/fonts/NewCMMath-Regular.otf")
FTFont(Ptr{FreeType.__JL_FT_FaceRec_} @0x000000001e67a810, true, Dict{Char, FontExtent{Float32}}())
julia> glyph_id = FT_Get_Name_Index(font, "integral.v1")
0x0000172a
julia> res = FT_Load_Glyph(font, glyph_id, FT_LOAD_NO_SCALE)
0
So I guess that adding methods to get_extent
, get_extent_internal
and load_char
to load from a glyph name may do the trick.
Ideally it would be good to retrieve the information on whether a char has alternate glyphs directly from the font, but I am no sure FreeType support that.
Ideally it would be good to retrieve the information on whether a char has alternate glyphs directly from the font, but I am no sure FreeType support that.
https://freetype.org/freetype2/docs/reference/ft2-glyph_variants.html
I think everything we need is here. I think what we need to do is make a new function load_glyph
and then a couple methods:
load_glyph(::Char) -> look up glyph via unicode char in charmap (via FT_Load_Char)
load_glyph(::Int) -> look up glyph via index in font (via FT_Load_Glyph)
load_glyph(::Char, ::Char) -> look up glyph modified with modifier (not sure about the type of the second argument)
load_glyph(::String or ::Symbol) -> look up glyph via name
And then Makie would actually just use the glyph index representation inside glyphcollection
because that is more generic than the unicode we use right now.