WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 04d9a04

Browse files
pthomocornut
authored andcommitted
imgui_freetype: Added support for plutosvg to render OpenType SVG fonts. (#7927, #7187 + #6591, #6607)
See #7927 for details.
1 parent 83ecc84 commit 04d9a04

File tree

5 files changed

+58
-12
lines changed

5 files changed

+58
-12
lines changed

docs/CHANGELOG.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ Other changes:
9393
preventing use of external shortcuts not guarded by an ActiveId check. (#8048) [@geertbleyen]
9494
- InputText: ensure mouse cursor shape is set regardless of whether keyboard mode is
9595
enabled or not. (#6417)
96+
- imgui_freetype: Added support for plutosvg (as an alternative to lunasvg) to render
97+
OpenType SVG fonts. Requires defining IMGUI_ENABLE_FREETYPE_PLUTOSVG along with IMGUI_ENABLE_FREETYPE.
98+
Providing headers/librairies for plutosvg + plutovg is up to you (see #7927 for help).
99+
(#7927, #7187, #6591, #6607) [@pthom]
96100
- Backends: DX11, DX12, SDLRenderer2/3. Vulkan, WGPU: expose selected state in
97101
ImGui_ImplXXXX_RenderState structures during render loop. (#6969, #5834, #7468, #3590)
98102
- Backends: DX9, DX10, DX11, DX12, OpenGL, Vulkan, WGPU: Changed default texture sampler

imconfig.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,13 @@
8383
// On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'.
8484
//#define IMGUI_ENABLE_FREETYPE
8585

86-
//---- Use FreeType+lunasvg library to render OpenType SVG fonts (SVGinOT)
87-
// Requires lunasvg headers to be available in the include path + program to be linked with the lunasvg library (not provided).
86+
//---- Use FreeType + plutosvg or lunasvg to render OpenType SVG fonts (SVGinOT)
8887
// Only works in combination with IMGUI_ENABLE_FREETYPE.
89-
// (implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement)
88+
// - lunasvg is currently easier to acquire/install, as e.g. it is part of vcpkg.
89+
// - plutosvg will support more fonts and may load them faster. It currently requires to be built manually but it is fairly easy. See misc/freetype/README for instructions.
90+
// - Both require headers to be available in the include path + program to be linked with the library code (not provided).
91+
// - (note: lunasvg implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement)
92+
//#define IMGUI_ENABLE_FREETYPE_PLUTOSVG
9093
//#define IMGUI_ENABLE_FREETYPE_LUNASVG
9194

9295
//---- Use stb_truetype to build and rasterize the font atlas (default)

misc/freetype/README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,25 @@ You can use the `ImGuiFreeTypeBuilderFlags_LoadColor` flag to load certain color
3838

3939
### Using OpenType SVG fonts (SVGinOT)
4040
- *SVG in Open Type* is a standard by Adobe and Mozilla for color OpenType and Open Font Format fonts. It allows font creators to embed complete SVG files within a font enabling full color and even animations.
41-
- Popular fonts such as [twemoji](https://github.com/13rac1/twemoji-color-font) and fonts made with [scfbuild](https://github.com/13rac1/scfbuild) is SVGinOT
42-
- Requires: [lunasvg](https://github.com/sammycage/lunasvg) v2.3.2 and above
43-
1. Add `#define IMGUI_ENABLE_FREETYPE_LUNASVG` in your `imconfig.h`.
44-
2. Get latest lunasvg binaries or build yourself. Under Windows you may use vcpkg with: `vcpkg install lunasvg --triplet=x64-windows`.
41+
- Popular fonts such as [twemoji](https://github.com/13rac1/twemoji-color-font) and fonts made with [scfbuild](https://github.com/13rac1/scfbuild) is SVGinOT
42+
- Two alternatives are possible to render SVG fonts: use "lunasvg" or "plutosvg". plutosvg will support some more fonts (e.g. NotoColorEmoji-Regular) and may load them faster.
43+
44+
#### Using lunasvg
45+
Requires: [lunasvg](https://github.com/sammycage/lunasvg) v2.3.2 and above
46+
- Add `#define IMGUI_ENABLE_FREETYPE_LUNASVG` in your `imconfig.h`.
47+
- Get latest lunasvg binaries or build yourself. Under Windows you may use vcpkg with: `vcpkg install lunasvg --triplet=x64-windows`.
48+
49+
#### Using plutosvg (and plutovg)
50+
- Add `#define IMGUI_ENABLE_FREETYPE_PLUTOSVG` in your `imconfig.h`.
51+
- Compile and link with plutosvg *and* plutovg (which is required by plutosvg)
52+
53+
_Compilation hints for plutovg_
54+
- Compile all source files in `plutovg/source/*.c`
55+
- Add include directory: `plutovg/include` + `plutovg/stb`
56+
57+
_Compilation hints for plutosvg_
58+
- Compile `plutosvg/source/plutosvg.c`
59+
- Add include directory: `plutosvg/source`
60+
- Add define: `PLUTOSVG_HAS_FREETYPE`
61+
- Link with: plutovg, freetype
62+

misc/freetype/imgui_freetype.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
// CHANGELOG
88
// (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)
910
// 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)
1112
// 2023/01/04: fixed a packing issue which in some occurrences would prevent large amount of glyphs from being packed correctly.
1213
// 2021/08/23: fixed crash when FT_Render_Glyph() fails to render a glyph and returns NULL.
1314
// 2021/03/05: added ImGuiFreeTypeBuilderFlags_Bitmap to load bitmap glyphs.
@@ -45,12 +46,21 @@
4546
#include FT_GLYPH_H // <freetype/ftglyph.h>
4647
#include FT_SYNTHESIS_H // <freetype/ftsynth.h>
4748

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
4954
#include FT_OTSVG_H // <freetype/otsvg.h>
5055
#include FT_BBOX_H // <freetype/ftbbox.h>
5156
#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)
5262
#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
5464
#endif
5565
#endif
5666

@@ -269,11 +279,11 @@ namespace
269279

270280
// Need an outline for this to work
271281
FT_GlyphSlot slot = Face->glyph;
272-
#ifdef IMGUI_ENABLE_FREETYPE_LUNASVG
282+
#if defined(IMGUI_ENABLE_FREETYPE_LUNASVG) || defined(IMGUI_ENABLE_FREETYPE_PLUTOSVG)
273283
IM_ASSERT(slot->format == FT_GLYPH_FORMAT_OUTLINE || slot->format == FT_GLYPH_FORMAT_BITMAP || slot->format == FT_GLYPH_FORMAT_SVG);
274284
#else
275285
#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");
277287
#endif
278288
IM_ASSERT(slot->format == FT_GLYPH_FORMAT_OUTLINE || slot->format == FT_GLYPH_FORMAT_BITMAP);
279289
#endif // IMGUI_ENABLE_FREETYPE_LUNASVG
@@ -810,6 +820,10 @@ static bool ImFontAtlasBuildWithFreeType(ImFontAtlas* atlas)
810820
SVG_RendererHooks hooks = { ImGuiLunasvgPortInit, ImGuiLunasvgPortFree, ImGuiLunasvgPortRender, ImGuiLunasvgPortPresetSlot };
811821
FT_Property_Set(ft_library, "ot-svg", "svg-hooks", &hooks);
812822
#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
813827

814828
bool ret = ImFontAtlasBuildWithFreeTypeEx(ft_library, atlas, atlas->FontBuilderFlags);
815829
FT_Done_Library(ft_library);

misc/freetype/imgui_freetype.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
#include "imgui.h" // IMGUI_API
66
#ifndef IMGUI_DISABLE
77

8+
// Usage:
9+
// - Add '#define IMGUI_ENABLE_FREETYPE' in your imconfig to enable support for imgui_freetype in imgui.
10+
11+
// Optional support for OpenType SVG fonts:
12+
// - Add '#define IMGUI_ENABLE_FREETYPE_PLUTOSVG' to use plutosvg (not provided). See #7927.
13+
// - Add '#define IMGUI_ENABLE_FREETYPE_LUNASVG' to use lunasvg (not provided). See #6591.
14+
815
// Forward declarations
916
struct ImFontAtlas;
1017
struct ImFontBuilderIO;

0 commit comments

Comments
 (0)