Package imgui

Class ImFontAtlas


public final class ImFontAtlas extends ImGuiStructDestroyable
Load and rasterize multiple TTF/OTF fonts into a same texture. The font atlas will build a single texture holding: - One or more fonts. - Custom graphics data needed to render the shapes needed by Dear ImGui. - Mouse cursor shapes for software cursor rendering (unless setting 'Flags |= ImFontAtlasFlags_NoMouseCursors' in the font atlas). It is the user-code responsibility to setup/build the atlas, then upload the pixel data into a texture accessible by your graphics api. - Optionally, call any of the AddFont*** functions. If you don't call any, the default font embedded in the code will be loaded for you. - Call GetTexDataAsAlpha8() or GetTexDataAsRGBA32() to build and retrieve pixels data. - Upload the pixels data into a texture within your graphics system (see imgui_impl_xxxx.cpp examples) - Call SetTexID(my_tex_id); and pass the pointer/identifier to your texture in a format natural to your graphics API. This value will be passed back to you during rendering to identify the texture. Read FAQ entry about ImTextureID for more details. Common pitfalls: - If you pass a 'glyph_ranges' array to AddFont*** functions, you need to make sure that your array persist up until the atlas is build (when calling GetTexData*** or Build()). We only copy the pointer, not the data. - Important: By default, AddFontFromMemoryTTF() takes ownership of the data. Even though we are not writing to it, we will free the pointer on destruction. You can set font_cfg.FontDataOwnedByAtlas=false to keep ownership of your data and it won't be freed, - Even though many functions are suffixed with "TTF", OTF data is supported just as well. - This is an old API and it is currently awkward for those and and various other reasons! We will address them in the future!
  • Constructor Details

    • ImFontAtlas

      public ImFontAtlas()
    • ImFontAtlas

      public ImFontAtlas(long ptr)
  • Method Details

    • create

      protected long create()
      Specified by:
      create in class ImGuiStructDestroyable
    • addFont

      public ImFont addFont(ImFontConfig imFontConfig)
    • addFontDefault

      public ImFont addFontDefault()
    • addFontDefault

      public ImFont addFontDefault(ImFontConfig imFontConfig)
    • addFontDefaultVector

      public ImFont addFontDefaultVector()
      Embedded scalable (vector) default font — recommended at any higher size. (since imgui 1.92)
    • addFontDefaultVector

      public ImFont addFontDefaultVector(ImFontConfig imFontConfig)
      Embedded scalable (vector) default font — recommended at any higher size. (since imgui 1.92)
    • addFontDefaultBitmap

      public ImFont addFontDefaultBitmap()
      Embedded classic pixel-clean bitmap default font — recommended at size 13px with no scaling. (since imgui 1.92)
    • addFontDefaultBitmap

      public ImFont addFontDefaultBitmap(ImFontConfig imFontConfig)
      Embedded classic pixel-clean bitmap default font — recommended at size 13px with no scaling. (since imgui 1.92)
    • addFontFromFileTTF

      public ImFont addFontFromFileTTF(String filename, float sizePixels)
    • addFontFromFileTTF

      public ImFont addFontFromFileTTF(String filename, float sizePixels, ImFontConfig fontConfig)
    • addFontFromFileTTF

      public ImFont addFontFromFileTTF(String filename, float sizePixels, ImFontConfig fontConfig, short[] glyphRanges)
    • addFontFromFileTTF

      public ImFont addFontFromFileTTF(String filename, float sizePixels, short[] glyphRanges)
    • addFontFromMemoryTTF

      public ImFont addFontFromMemoryTTF(byte[] fontData, float sizePixels)
      Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas. Set font_cfg.FontDataOwnedByAtlas=false to keep ownership of your data and it won't be freed.
    • addFontFromMemoryTTF

      public ImFont addFontFromMemoryTTF(byte[] fontData, float sizePixels, ImFontConfig fontConfig)
      Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas. Set font_cfg.FontDataOwnedByAtlas=false to keep ownership of your data and it won't be freed.
    • addFontFromMemoryTTF

      public ImFont addFontFromMemoryTTF(byte[] fontData, float sizePixels, ImFontConfig fontConfig, short[] glyphRanges)
      Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas. Set font_cfg.FontDataOwnedByAtlas=false to keep ownership of your data and it won't be freed.
    • addFontFromMemoryTTF

      public ImFont addFontFromMemoryTTF(byte[] fontData, float sizePixels, short[] glyphRanges)
      Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas. Set font_cfg.FontDataOwnedByAtlas=false to keep ownership of your data and it won't be freed.
    • addFontFromMemoryTTF

      public ImFont addFontFromMemoryTTF(byte[] fontData, int fontDataSize, float sizePixels)
      Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas. Set font_cfg.FontDataOwnedByAtlas=false to keep ownership of your data and it won't be freed.
    • addFontFromMemoryTTF

      public ImFont addFontFromMemoryTTF(byte[] fontData, int fontDataSize, float sizePixels, ImFontConfig fontConfig)
      Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas. Set font_cfg.FontDataOwnedByAtlas=false to keep ownership of your data and it won't be freed.
    • addFontFromMemoryTTF

      public ImFont addFontFromMemoryTTF(byte[] fontData, int fontDataSize, float sizePixels, ImFontConfig fontConfig, short[] glyphRanges)
      Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas. Set font_cfg.FontDataOwnedByAtlas=false to keep ownership of your data and it won't be freed.
    • addFontFromMemoryTTF

      public ImFont addFontFromMemoryTTF(byte[] fontData, int fontDataSize, float sizePixels, short[] glyphRanges)
      Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas. Set font_cfg.FontDataOwnedByAtlas=false to keep ownership of your data and it won't be freed.
    • addFontFromMemoryCompressedTTF

      public ImFont addFontFromMemoryCompressedTTF(byte[] compressedFontData, float sizePixels)
      'compressed_font_data' still owned by caller. Compress with binary_to_compressed_c.cpp.
    • addFontFromMemoryCompressedTTF

      public ImFont addFontFromMemoryCompressedTTF(byte[] compressedFontData, float sizePixels, ImFontConfig imFontConfig)
      'compressed_font_data' still owned by caller. Compress with binary_to_compressed_c.cpp.
    • addFontFromMemoryCompressedTTF

      public ImFont addFontFromMemoryCompressedTTF(byte[] compressedFontData, float sizePixels, ImFontConfig imFontConfig, short[] glyphRanges)
      'compressed_font_data' still owned by caller. Compress with binary_to_compressed_c.cpp.
    • addFontFromMemoryCompressedTTF

      public ImFont addFontFromMemoryCompressedTTF(byte[] compressedFontData, float sizePixels, short[] glyphRanges)
      'compressed_font_data' still owned by caller. Compress with binary_to_compressed_c.cpp.
    • addFontFromMemoryCompressedTTF

      public ImFont addFontFromMemoryCompressedTTF(byte[] compressedFontData, int compressedFontDataSize, float sizePixels)
      'compressed_font_data' still owned by caller. Compress with binary_to_compressed_c.cpp.
    • addFontFromMemoryCompressedTTF

      public ImFont addFontFromMemoryCompressedTTF(byte[] compressedFontData, int compressedFontDataSize, float sizePixels, ImFontConfig imFontConfig)
      'compressed_font_data' still owned by caller. Compress with binary_to_compressed_c.cpp.
    • addFontFromMemoryCompressedTTF

      public ImFont addFontFromMemoryCompressedTTF(byte[] compressedFontData, int compressedFontDataSize, float sizePixels, ImFontConfig imFontConfig, short[] glyphRanges)
      'compressed_font_data' still owned by caller. Compress with binary_to_compressed_c.cpp.
    • addFontFromMemoryCompressedTTF

      public ImFont addFontFromMemoryCompressedTTF(byte[] compressedFontData, int compressedFontDataSize, float sizePixels, short[] glyphRanges)
      'compressed_font_data' still owned by caller. Compress with binary_to_compressed_c.cpp.
    • addFontFromMemoryCompressedBase85TTF

      public ImFont addFontFromMemoryCompressedBase85TTF(String compressedFontDataBase85, float sizePixels, ImFontConfig fontConfig)
      'compressed_font_data_base85' still owned by caller. Compress with binary_to_compressed_c.cpp with -base85 parameter.
    • addFontFromMemoryCompressedBase85TTF

      public ImFont addFontFromMemoryCompressedBase85TTF(String compressedFontDataBase85, float sizePixels, ImFontConfig fontConfig, short[] glyphRanges)
      'compressed_font_data_base85' still owned by caller. Compress with binary_to_compressed_c.cpp with -base85 parameter.
    • clearInputData

      public void clearInputData()
      Clear input data (all ImFontConfig structures including sizes, TTF data, glyph ranges, etc.) = all the data used to build the texture and fonts.
    • clearTexData

      public void clearTexData()
      Clear output texture data (CPU side). Saves RAM once the texture has been copied to graphics memory.
    • clearFonts

      public void clearFonts()
      Clear output font data (glyphs storage, UV coordinates).
    • clear

      public void clear()
      Clear all input and output.
    • setFreeTypeRenderer

      public void setFreeTypeRenderer(boolean enabled)
      BINDING NOTICE: This method is specific to the imgui-java binding.

      Since FreeType is included in the final build, it's possible to use both font renderers (STB_TrueType and FreeType) simultaneously without needing to rebuild the library. By default, we use small hacks to set STB_TrueType as the default font renderer. However, this method allows you to enforce the use of the FreeType renderer.

      This method MUST be called before invoking the "#build" or "#getTexData*" methods.

      Parameters:
      enabled - true to enable the FreeType font renderer
    • build

      public boolean build()
      Build pixels data. This is called automatically for you by the GetTexData*** functions.
    • getTexDataAsAlpha8

      public ByteBuffer getTexDataAsAlpha8(ImInt outWidth, ImInt outHeight)
      1 byte-per-pixel
    • getTexDataAsAlpha8

      public ByteBuffer getTexDataAsAlpha8(ImInt outWidth, ImInt outHeight, ImInt outBytesPerPixel)
      1 byte-per-pixel
    • getTexDataAsRGBA32

      public ByteBuffer getTexDataAsRGBA32(ImInt outWidth, ImInt outHeight)
      4 bytes-per-pixel
    • getTexDataAsRGBA32

      public ByteBuffer getTexDataAsRGBA32(ImInt outWidth, ImInt outHeight, ImInt outBytesPerPixel)
      4 bytes-per-pixel
    • isBuilt

      public boolean isBuilt()
    • setTexID

      public void setTexID(long textureID)
      User data to refer to the texture once it has been uploaded to user's graphic systems. It is passed back to you during rendering via the ImDrawCmd structure.
    • getGlyphRangesDefault

      public short[] getGlyphRangesDefault()
      Basic Latin, Extended Latin
    • getGlyphRangesGreek

      public short[] getGlyphRangesGreek()
      Default + Greek and Coptic
    • getGlyphRangesKorean

      public short[] getGlyphRangesKorean()
      Default + Korean characters
    • getGlyphRangesJapanese

      public short[] getGlyphRangesJapanese()
      Default + Hiragana, Katakana, Half-Width, Selection of 2999 Ideographs
    • getGlyphRangesChineseFull

      public short[] getGlyphRangesChineseFull()
      Default + Half-Width + Japanese Hiragana/Katakana + full set of about 21000 CJK Unified Ideographs
    • getGlyphRangesChineseSimplifiedCommon

      public short[] getGlyphRangesChineseSimplifiedCommon()
      Default + Half-Width + Japanese Hiragana/Katakana + set of 2500 CJK Unified Ideographs for common simplified Chinese
    • getGlyphRangesCyrillic

      public short[] getGlyphRangesCyrillic()
      Default + about 400 Cyrillic characters
    • getGlyphRangesThai

      public short[] getGlyphRangesThai()
      Default + Thai characters
    • getGlyphRangesVietnamese

      public short[] getGlyphRangesVietnamese()
      Default + Vietnamese characters
    • addCustomRectRegular

      public int addCustomRectRegular(int width, int height)
    • addCustomRectFontGlyph

      public int addCustomRectFontGlyph(ImFont imFont, short id, int width, int height, float advanceX)
      Id needs to be < 0x110000 to register a rectangle to map into a specific font.
    • addCustomRectFontGlyph

      public int addCustomRectFontGlyph(ImFont imFont, short id, int width, int height, float advanceX, ImVec2 offset)
      Id needs to be < 0x110000 to register a rectangle to map into a specific font.
    • addCustomRectFontGlyph

      public int addCustomRectFontGlyph(ImFont imFont, short id, int width, int height, float advanceX, float offsetX, float offsetY)
      Id needs to be < 0x110000 to register a rectangle to map into a specific font.
    • getFlags

      public int getFlags()
      Build flags (see ImFontAtlasFlags)
    • setFlags

      public void setFlags(int value)
      Build flags (see ImFontAtlasFlags)
    • addFlags

      public void addFlags(int flags)
      Build flags (see ImFontAtlasFlags)
    • removeFlags

      public void removeFlags(int flags)
      Build flags (see ImFontAtlasFlags)
    • hasFlags

      public boolean hasFlags(int flags)
      Build flags (see ImFontAtlasFlags)
    • getTexMinWidth

      public int getTexMinWidth()
      Minimum desired atlas texture width (must be power of two). Default 512. (since imgui 1.92 — replaces the old TexDesiredWidth; set TexMinWidth = TexMaxWidth to pin a specific width.)
    • setTexMinWidth

      public void setTexMinWidth(int value)
      Minimum desired atlas texture width (must be power of two). Default 512. (since imgui 1.92 — replaces the old TexDesiredWidth; set TexMinWidth = TexMaxWidth to pin a specific width.)
    • getTexMinHeight

      public int getTexMinHeight()
      Minimum desired atlas texture height (must be power of two). Default 128. (since imgui 1.92)
    • setTexMinHeight

      public void setTexMinHeight(int value)
      Minimum desired atlas texture height (must be power of two). Default 128. (since imgui 1.92)
    • getTexMaxWidth

      public int getTexMaxWidth()
      Maximum desired atlas texture width (must be power of two). Default 8192. (since imgui 1.92) Increase when loading large glyph sets (e.g. full CJK) on legacy backends without ImGuiBackendFlags_RendererHasTextures support.
    • setTexMaxWidth

      public void setTexMaxWidth(int value)
      Maximum desired atlas texture width (must be power of two). Default 8192. (since imgui 1.92) Increase when loading large glyph sets (e.g. full CJK) on legacy backends without ImGuiBackendFlags_RendererHasTextures support.
    • getTexMaxHeight

      public int getTexMaxHeight()
      Maximum desired atlas texture height (must be power of two). Default 8192. (since imgui 1.92)
    • setTexMaxHeight

      public void setTexMaxHeight(int value)
      Maximum desired atlas texture height (must be power of two). Default 8192. (since imgui 1.92)
    • getTexGlyphPadding

      public int getTexGlyphPadding()
      Padding between glyphs within texture in pixels. Defaults to 1. If your rendering method doesn't rely on bilinear filtering you may set this to 0.
    • setTexGlyphPadding

      public void setTexGlyphPadding(int value)
      Padding between glyphs within texture in pixels. Defaults to 1. If your rendering method doesn't rely on bilinear filtering you may set this to 0.
    • getLocked

      public boolean getLocked()
      Marked as Locked by ImGui::NewFrame() so attempt to modify the atlas will assert.
    • setLocked

      public void setLocked(boolean value)
      Marked as Locked by ImGui::NewFrame() so attempt to modify the atlas will assert.