imgui_freetype.h 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // dear imgui: FreeType font builder (used as a replacement for the stb_truetype builder)
  2. // (headers)
  3. #pragma once
  4. #include "imgui.h" // IMGUI_API
  5. #ifndef IMGUI_DISABLE
  6. // Usage:
  7. // - Add '#define IMGUI_ENABLE_FREETYPE' in your imconfig to enable support for imgui_freetype in imgui.
  8. // Optional support for OpenType SVG fonts:
  9. // - Add '#define IMGUI_ENABLE_FREETYPE_PLUTOSVG' to use plutosvg (not provided). See #7927.
  10. // - Add '#define IMGUI_ENABLE_FREETYPE_LUNASVG' to use lunasvg (not provided). See #6591.
  11. // Forward declarations
  12. struct ImFontAtlas;
  13. struct ImFontBuilderIO;
  14. // Hinting greatly impacts visuals (and glyph sizes).
  15. // - By default, hinting is enabled and the font's native hinter is preferred over the auto-hinter.
  16. // - When disabled, FreeType generates blurrier glyphs, more or less matches the stb_truetype.h
  17. // - The Default hinting mode usually looks good, but may distort glyphs in an unusual way.
  18. // - The Light hinting mode generates fuzzier glyphs but better matches Microsoft's rasterizer.
  19. // You can set those flags globaly in ImFontAtlas::FontBuilderFlags
  20. // You can set those flags on a per font basis in ImFontConfig::FontBuilderFlags
  21. enum ImGuiFreeTypeBuilderFlags
  22. {
  23. ImGuiFreeTypeBuilderFlags_NoHinting = 1 << 0, // Disable hinting. This generally generates 'blurrier' bitmap glyphs when the glyph are rendered in any of the anti-aliased modes.
  24. ImGuiFreeTypeBuilderFlags_NoAutoHint = 1 << 1, // Disable auto-hinter.
  25. ImGuiFreeTypeBuilderFlags_ForceAutoHint = 1 << 2, // Indicates that the auto-hinter is preferred over the font's native hinter.
  26. ImGuiFreeTypeBuilderFlags_LightHinting = 1 << 3, // A lighter hinting algorithm for gray-level modes. Many generated glyphs are fuzzier but better resemble their original shape. This is achieved by snapping glyphs to the pixel grid only vertically (Y-axis), as is done by Microsoft's ClearType and Adobe's proprietary font renderer. This preserves inter-glyph spacing in horizontal text.
  27. ImGuiFreeTypeBuilderFlags_MonoHinting = 1 << 4, // Strong hinting algorithm that should only be used for monochrome output.
  28. ImGuiFreeTypeBuilderFlags_Bold = 1 << 5, // Styling: Should we artificially embolden the font?
  29. ImGuiFreeTypeBuilderFlags_Oblique = 1 << 6, // Styling: Should we slant the font, emulating italic style?
  30. ImGuiFreeTypeBuilderFlags_Monochrome = 1 << 7, // Disable anti-aliasing. Combine this with MonoHinting for best results!
  31. ImGuiFreeTypeBuilderFlags_LoadColor = 1 << 8, // Enable FreeType color-layered glyphs
  32. ImGuiFreeTypeBuilderFlags_Bitmap = 1 << 9 // Enable FreeType bitmap glyphs
  33. };
  34. namespace ImGuiFreeType
  35. {
  36. // This is automatically assigned when using '#define IMGUI_ENABLE_FREETYPE'.
  37. // If you need to dynamically select between multiple builders:
  38. // - you can manually assign this builder with 'atlas->FontBuilderIO = ImGuiFreeType::GetBuilderForFreeType()'
  39. // - prefer deep-copying this into your own ImFontBuilderIO instance if you use hot-reloading that messes up static data.
  40. IMGUI_API const ImFontBuilderIO* GetBuilderForFreeType();
  41. // Override allocators. By default ImGuiFreeType will use IM_ALLOC()/IM_FREE()
  42. // However, as FreeType does lots of allocations we provide a way for the user to redirect it to a separate memory heap if desired.
  43. IMGUI_API void SetAllocatorFunctions(void* (*alloc_func)(size_t sz, void* user_data), void (*free_func)(void* ptr, void* user_data), void* user_data = nullptr);
  44. // Obsolete names (will be removed soon)
  45. #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
  46. //static inline bool BuildFontAtlas(ImFontAtlas* atlas, unsigned int flags = 0) { atlas->FontBuilderIO = GetBuilderForFreeType(); atlas->FontBuilderFlags = flags; return atlas->Build(); } // Prefer using '#define IMGUI_ENABLE_FREETYPE'
  47. #endif
  48. }
  49. #endif // #ifndef IMGUI_DISABLE