ogios
(OGIOS)
December 25, 2024, 1:42am
1
i’m trying to load a custimized font, it’s not a file but static &[u8]
.
it’s a small font and only used for numbers.
but i can only manage to load it into cairo::FontFace
with freetype
but don’t know how to use it with pango::Layout
:
// load into `cairo::FontFace`
let fc = ft::Library::init()
.map_err(|e| format!("Init freetype error: {e}"))
.and_then(|lib| {
let fontface = lib
.new_memory_face(Rc::new(raw::RAW_FONT.to_vec()), 0)
.map_err(|e| format!("Init ft fontface error: {e}"))?;
FontFace::create_from_ft(&fontface)
.map_err(|e| format!("Init cairo fontface error: {e}"))
});
lb90
December 25, 2024, 11:31am
2
Hi @ogios ,
Pango cannot import Cairo fonts directly. It would be a problem because Pango needs to access font tables. Pango also needs to know some properties of the font to do font fallback.
There is a new API in Pango 1.55 to import font files: Pango.FontMap.add_font_file . To import fonts from data you can use API of the underlying font discovery & management system (FontConfig, DirectWrite, CoreText). See McEs, A Hacker Life: How to use custom application fonts with Pango
1 Like
ogios
(OGIOS)
December 25, 2024, 12:19pm
3
@lb90 thanks!
i tried the new pango fontmap api, first save the memory buffer as a font file under /tmp and load it with that api, and it worked.
as for the second workaround, it suggested an issue that opend for 10years: FcConfigAppFontAddFile equivalent that takes memory or FT_Face (#12) · Issues · fontconfig / fontconfig · GitLab
maybe there’s still no way to load font directly from memory i guess?
system
(system)
Closed
January 24, 2025, 12:20pm
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.