-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to load fonts with specific glyph ranges (e.g., Chinese, Japanese, Korean) using hello_imgui.load_font #196
Labels
faq
A frequent issue, remaining opened to facilitate discoverability
Comments
I don't understand your question (there is none in your message, in fact). Does your work around work? |
pthom
changed the title
Missing fields
How to load chinese font with hello_imgui.load_font and set the glyph range (Python)
Jul 6, 2024
ImFontConfig.GlyphRanges
in python binding
Hello, I come back to this question after a few months, sorry for the delay. I understand that you needed a way to translate the glyph ranges coming from Dear ImGui, into ranges used by hello_imgui.load_font. This commit adds support for this. Example usage: """Demonstrates how to load a font with Chinese characters and display them in the GUI,
using the common glyph ranges defined in by ImGui.
"""
from imgui_bundle import imgui, hello_imgui, imgui_ctx
from imgui_bundle.demos_python import demo_utils
demo_utils.set_hello_imgui_demo_assets_folder()
font_cn: imgui.ImFont = None
def load_font():
global font_cn
if not hello_imgui.asset_exists("fonts/NotoSerifSC-VariableFont_wght.ttf"):
return
# Note: this font is not provided with the ImGui bundle (too large).
# You will need to provide it yourself, or use another font.
font_filename = "fonts/NotoSerifSC-VariableFont_wght.ttf"
# The range of Chinese characters is defined by ImGui as a single list of characters (List[ImWchar]), with a terminating 0.
# (each range is a pair of successive characters in this list, with the second character being the last one in the range)
cn_glyph_ranges_imgui = imgui.get_io().fonts.get_glyph_ranges_chinese_simplified_common()
# We need to convert this list into a list of pairs (List[ImWcharPair]), where each pair is a range of characters.
cn_glyph_ranges_pair = hello_imgui.translate_common_glyph_ranges(cn_glyph_ranges_imgui)
font_loading_params = hello_imgui.FontLoadingParams()
font_loading_params.glyph_ranges = cn_glyph_ranges_pair
font_cn = hello_imgui.load_font(font_filename, 40.0, font_loading_params)
def gui():
if font_cn is not None:
with imgui_ctx.push_font(font_cn):
imgui.text("Hello world")
imgui.text("你好,世界")
else:
imgui.text("Font file not found")
imgui.text_wrapped("""
This font is not provided with the ImGui bundle (too large).
You will need to provide it yourself, or use another font.
""")
runner_params = hello_imgui.RunnerParams()
runner_params.callbacks.load_additional_fonts = load_font
runner_params.callbacks.show_gui = gui
hello_imgui.run(runner_params) |
pthom
changed the title
How to load chinese font with hello_imgui.load_font and set the glyph range (Python)
How to load chinese font with hello_imgui.load_font and set the glyph range from get_glyph_ranges_chinese_simplified_common()
Jul 6, 2024
pthom
changed the title
How to load chinese font with hello_imgui.load_font and set the glyph range from get_glyph_ranges_chinese_simplified_common()
How to load fonts with specific glyph ranges (e.g., Chinese, Japanese, Korean) using hello_imgui.load_font
Jul 6, 2024
pthom
added
the
faq
A frequent issue, remaining opened to facilitate discoverability
label
Jul 6, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
env:
imgui-bundle
1.3.0imgui_bundle/bindings/imgui_bundle/imgui/__init__.pyi
Lines 9451 to 9460 in 541ed1a
https://github.com/ocornut/imgui/blame/d3c3514a59bb31406c954c2b525f330e9d167845/imgui.h#L2889
Context
I want to load Chinese fonts and specify glyph_range.
test code
Workaround
The text was updated successfully, but these errors were encountered: