From 754b8f301475298c8c7a5126f2115fc42322246a Mon Sep 17 00:00:00 2001 From: Vincent Wei Date: Tue, 11 May 2021 10:41:54 +0800 Subject: [PATCH] Enhance `GetGlyphInfo` to return the FreeType face, font file path, and glyph index --- RELEASE-NOTES.md | 2 ++ include/gdi.h | 12 ++++++++++++ src/newgdi/glyph.c | 24 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 2001168c..de61f5cc 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -36,6 +36,8 @@ In this version, we fixed some bugs and made some optimizations and enhancements - Fix memory leaks when using block heap. - Fix a bug in ServerGetWinZNodeRegion. * ENHANCEMENTS: + - Enhance `GetGlyphInfo` to return the FreeType face, font file path, and glyph + index. - NEW API `StretchBltEx` to support different scaling filters and rotation. - Use Pixman to support color blending methods for `BitBlt` and `StretchBlt`. - Enhance fallback compositor to support animation when switching among layers. diff --git a/include/gdi.h b/include/gdi.h index 98b3ee6c..e3a1e938 100644 --- a/include/gdi.h +++ b/include/gdi.h @@ -12951,6 +12951,7 @@ MG_EXPORT int GUIAPI GetGlyphsExtentPoint (HDC hdc, Glyph32* glyphs, #define GLYPH_INFO_METRICS 0x01 #define GLYPH_INFO_BMP 0x02 +#define GLYPH_INFO_FACE 0x04 /** The type of glyph bitmap: monochrome */ #define GLYPHBMP_TYPE_MONO 0x00 @@ -12973,6 +12974,7 @@ typedef struct _GLYPHINFO { * or bitmap infomation. Or'ed with the following values: * - GLYPH_INFO_METRICS * - GLYPH_INFO_BMP + * - GLYPH_INFO_FACE */ Uint32 mask; @@ -13005,6 +13007,16 @@ typedef struct _GLYPHINFO { * It is only valid if bmp_type is GLYPHBMP_TYPE_PRERENDER */ BITMAP prbitmap; + + /** + * The FreeType face, font file path, and the glyph index + * (when mask has GLYPH_INFO_FACE set). + * You can use these information to render the glyph by yourself. + * Only available if the device font is a TrueType/OpenType font. + */ + void* ft_face; + const char* file_path; + Uint32 index; } GLYPHINFO; /** diff --git a/src/newgdi/glyph.c b/src/newgdi/glyph.c index 05bd23b0..8fe22770 100644 --- a/src/newgdi/glyph.c +++ b/src/newgdi/glyph.c @@ -198,6 +198,30 @@ int GUIAPI GetGlyphInfo (LOGFONT* logfont, Glyph32 glyph_value, } } + /* get FreeType face and glyph index */ + if (glyph_info->mask & GLYPH_INFO_FACE) { + glyph_info->index = glyph_value; + if (devfont->font_ops->get_ft_face) { + + /* keep sync with tagFTFACEINFO in freetype2.h */ + struct _FTFACEINFO { + char* path; + void* face; + }; + + struct _FTFACEINFO* face_info = (struct _FTFACEINFO*) + devfont->font_ops->get_ft_face (logfont, devfont); + assert (face_info); + + glyph_info->ft_face = face_info->face; + glyph_info->file_path = face_info->path; + } + else { + glyph_info->ft_face = NULL; + glyph_info->file_path = NULL; + } + } + glyph_info->bmp_width = sz.cx; glyph_info->bmp_height = sz.cy; return 0;