|
@@ -6,8 +6,9 @@
|
|
|
|
|
|
// CHANGELOG
|
|
|
// (minor and older changes stripped away, please see git history for details)
|
|
|
+// 2024/10/17: added plutosvg support for SVG Fonts (seems faster/better than lunasvg). Enable by using '#define IMGUI_ENABLE_FREETYPE_PLUTOSVG'. (#7927)
|
|
|
// 2023/11/13: added support for ImFontConfig::RasterizationDensity field for scaling render density without scaling metrics.
|
|
|
-// 2023/08/01: added support for SVG fonts, enable by using '#define IMGUI_ENABLE_FREETYPE_LUNASVG' (#6591)
|
|
|
+// 2023/08/01: added support for SVG fonts, enable by using '#define IMGUI_ENABLE_FREETYPE_LUNASVG'. (#6591)
|
|
|
// 2023/01/04: fixed a packing issue which in some occurrences would prevent large amount of glyphs from being packed correctly.
|
|
|
// 2021/08/23: fixed crash when FT_Render_Glyph() fails to render a glyph and returns NULL.
|
|
|
// 2021/03/05: added ImGuiFreeTypeBuilderFlags_Bitmap to load bitmap glyphs.
|
|
@@ -45,12 +46,21 @@
|
|
|
#include FT_GLYPH_H // <freetype/ftglyph.h>
|
|
|
#include FT_SYNTHESIS_H // <freetype/ftsynth.h>
|
|
|
|
|
|
-#ifdef IMGUI_ENABLE_FREETYPE_LUNASVG
|
|
|
+// Handle LunaSVG and PlutoSVG
|
|
|
+#if defined(IMGUI_ENABLE_FREETYPE_LUNASVG) && defined(IMGUI_ENABLE_FREETYPE_PLUTOSVG)
|
|
|
+#error "Cannot enable both IMGUI_ENABLE_FREETYPE_LUNASVG and IMGUI_ENABLE_FREETYPE_PLUTOSVG"
|
|
|
+#endif
|
|
|
+#ifdef IMGUI_ENABLE_FREETYPE_LUNASVG
|
|
|
#include FT_OTSVG_H // <freetype/otsvg.h>
|
|
|
#include FT_BBOX_H // <freetype/ftbbox.h>
|
|
|
#include <lunasvg.h>
|
|
|
+#endif
|
|
|
+#ifdef IMGUI_ENABLE_FREETYPE_PLUTOSVG
|
|
|
+#include <plutosvg.h>
|
|
|
+#endif
|
|
|
+#if defined(IMGUI_ENABLE_FREETYPE_LUNASVG) || defined (IMGUI_ENABLE_FREETYPE_PLUTOSVG)
|
|
|
#if !((FREETYPE_MAJOR >= 2) && (FREETYPE_MINOR >= 12))
|
|
|
-#error IMGUI_ENABLE_FREETYPE_LUNASVG requires FreeType version >= 2.12
|
|
|
+#error IMGUI_ENABLE_FREETYPE_PLUTOSVG or IMGUI_ENABLE_FREETYPE_LUNASVG requires FreeType version >= 2.12
|
|
|
#endif
|
|
|
#endif
|
|
|
|
|
@@ -269,11 +279,11 @@ namespace
|
|
|
|
|
|
// Need an outline for this to work
|
|
|
FT_GlyphSlot slot = Face->glyph;
|
|
|
-#ifdef IMGUI_ENABLE_FREETYPE_LUNASVG
|
|
|
+#if defined(IMGUI_ENABLE_FREETYPE_LUNASVG) || defined(IMGUI_ENABLE_FREETYPE_PLUTOSVG)
|
|
|
IM_ASSERT(slot->format == FT_GLYPH_FORMAT_OUTLINE || slot->format == FT_GLYPH_FORMAT_BITMAP || slot->format == FT_GLYPH_FORMAT_SVG);
|
|
|
#else
|
|
|
#if ((FREETYPE_MAJOR >= 2) && (FREETYPE_MINOR >= 12))
|
|
|
- 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");
|
|
|
+ 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");
|
|
|
#endif
|
|
|
IM_ASSERT(slot->format == FT_GLYPH_FORMAT_OUTLINE || slot->format == FT_GLYPH_FORMAT_BITMAP);
|
|
|
#endif // IMGUI_ENABLE_FREETYPE_LUNASVG
|
|
@@ -810,6 +820,10 @@ static bool ImFontAtlasBuildWithFreeType(ImFontAtlas* atlas)
|
|
|
SVG_RendererHooks hooks = { ImGuiLunasvgPortInit, ImGuiLunasvgPortFree, ImGuiLunasvgPortRender, ImGuiLunasvgPortPresetSlot };
|
|
|
FT_Property_Set(ft_library, "ot-svg", "svg-hooks", &hooks);
|
|
|
#endif // IMGUI_ENABLE_FREETYPE_LUNASVG
|
|
|
+#ifdef IMGUI_ENABLE_FREETYPE_PLUTOSVG
|
|
|
+ // With plutosvg, use provided hooks
|
|
|
+ FT_Property_Set(ft_library, "ot-svg", "svg-hooks", plutosvg_ft_svg_hooks());
|
|
|
+#endif // IMGUI_ENABLE_FREETYPE_PLUTOSVG
|
|
|
|
|
|
bool ret = ImFontAtlasBuildWithFreeTypeEx(ft_library, atlas, atlas->FontBuilderFlags);
|
|
|
FT_Done_Library(ft_library);
|