|
6 | 6 |
|
7 | 7 | // CHANGELOG |
8 | 8 | // (minor and older changes stripped away, please see git history for details) |
| 9 | +// 2024/10/17: added plutosvg support for SVG Fonts (seems faster/better than lunasvg). Enable by using '#define IMGUI_ENABLE_FREETYPE_PLUTOSVG'. (#7927) |
9 | 10 | // 2023/11/13: added support for ImFontConfig::RasterizationDensity field for scaling render density without scaling metrics. |
10 | | -// 2023/08/01: added support for SVG fonts, enable by using '#define IMGUI_ENABLE_FREETYPE_LUNASVG' (#6591) |
| 11 | +// 2023/08/01: added support for SVG fonts, enable by using '#define IMGUI_ENABLE_FREETYPE_LUNASVG'. (#6591) |
11 | 12 | // 2023/01/04: fixed a packing issue which in some occurrences would prevent large amount of glyphs from being packed correctly. |
12 | 13 | // 2021/08/23: fixed crash when FT_Render_Glyph() fails to render a glyph and returns NULL. |
13 | 14 | // 2021/03/05: added ImGuiFreeTypeBuilderFlags_Bitmap to load bitmap glyphs. |
|
45 | 46 | #include FT_GLYPH_H // <freetype/ftglyph.h> |
46 | 47 | #include FT_SYNTHESIS_H // <freetype/ftsynth.h> |
47 | 48 |
|
48 | | -#ifdef IMGUI_ENABLE_FREETYPE_LUNASVG |
| 49 | +// Handle LunaSVG and PlutoSVG |
| 50 | +#if defined(IMGUI_ENABLE_FREETYPE_LUNASVG) && defined(IMGUI_ENABLE_FREETYPE_PLUTOSVG) |
| 51 | +#error "Cannot enable both IMGUI_ENABLE_FREETYPE_LUNASVG and IMGUI_ENABLE_FREETYPE_PLUTOSVG" |
| 52 | +#endif |
| 53 | +#ifdef IMGUI_ENABLE_FREETYPE_LUNASVG |
49 | 54 | #include FT_OTSVG_H // <freetype/otsvg.h> |
50 | 55 | #include FT_BBOX_H // <freetype/ftbbox.h> |
51 | 56 | #include <lunasvg.h> |
| 57 | +#endif |
| 58 | +#ifdef IMGUI_ENABLE_FREETYPE_PLUTOSVG |
| 59 | +#include <plutosvg.h> |
| 60 | +#endif |
| 61 | +#if defined(IMGUI_ENABLE_FREETYPE_LUNASVG) || defined (IMGUI_ENABLE_FREETYPE_PLUTOSVG) |
52 | 62 | #if !((FREETYPE_MAJOR >= 2) && (FREETYPE_MINOR >= 12)) |
53 | | -#error IMGUI_ENABLE_FREETYPE_LUNASVG requires FreeType version >= 2.12 |
| 63 | +#error IMGUI_ENABLE_FREETYPE_PLUTOSVG or IMGUI_ENABLE_FREETYPE_LUNASVG requires FreeType version >= 2.12 |
54 | 64 | #endif |
55 | 65 | #endif |
56 | 66 |
|
@@ -269,11 +279,11 @@ namespace |
269 | 279 |
|
270 | 280 | // Need an outline for this to work |
271 | 281 | FT_GlyphSlot slot = Face->glyph; |
272 | | -#ifdef IMGUI_ENABLE_FREETYPE_LUNASVG |
| 282 | +#if defined(IMGUI_ENABLE_FREETYPE_LUNASVG) || defined(IMGUI_ENABLE_FREETYPE_PLUTOSVG) |
273 | 283 | IM_ASSERT(slot->format == FT_GLYPH_FORMAT_OUTLINE || slot->format == FT_GLYPH_FORMAT_BITMAP || slot->format == FT_GLYPH_FORMAT_SVG); |
274 | 284 | #else |
275 | 285 | #if ((FREETYPE_MAJOR >= 2) && (FREETYPE_MINOR >= 12)) |
276 | | - IM_ASSERT(slot->format != FT_GLYPH_FORMAT_SVG && "The font contains SVG glyphs, you'll need to enable IMGUI_ENABLE_FREETYPE_LUNASVG in imconfig.h and install required libraries in order to use this font"); |
| 286 | + IM_ASSERT(slot->format != FT_GLYPH_FORMAT_SVG && "The font contains SVG glyphs, you'll need to enable IMGUI_ENABLE_FREETYPE_PLUTOSVG or IMGUI_ENABLE_FREETYPE_LUNASVG in imconfig.h and install required libraries in order to use this font"); |
277 | 287 | #endif |
278 | 288 | IM_ASSERT(slot->format == FT_GLYPH_FORMAT_OUTLINE || slot->format == FT_GLYPH_FORMAT_BITMAP); |
279 | 289 | #endif // IMGUI_ENABLE_FREETYPE_LUNASVG |
@@ -810,6 +820,10 @@ static bool ImFontAtlasBuildWithFreeType(ImFontAtlas* atlas) |
810 | 820 | SVG_RendererHooks hooks = { ImGuiLunasvgPortInit, ImGuiLunasvgPortFree, ImGuiLunasvgPortRender, ImGuiLunasvgPortPresetSlot }; |
811 | 821 | FT_Property_Set(ft_library, "ot-svg", "svg-hooks", &hooks); |
812 | 822 | #endif // IMGUI_ENABLE_FREETYPE_LUNASVG |
| 823 | +#ifdef IMGUI_ENABLE_FREETYPE_PLUTOSVG |
| 824 | + // With plutosvg, use provided hooks |
| 825 | + FT_Property_Set(ft_library, "ot-svg", "svg-hooks", plutosvg_ft_svg_hooks()); |
| 826 | +#endif // IMGUI_ENABLE_FREETYPE_PLUTOSVG |
813 | 827 |
|
814 | 828 | bool ret = ImFontAtlasBuildWithFreeTypeEx(ft_library, atlas, atlas->FontBuilderFlags); |
815 | 829 | FT_Done_Library(ft_library); |
|
0 commit comments