diff --git a/fastplotlib/layouts/_figure.py b/fastplotlib/layouts/_figure.py index 8fd5dc666..67c806075 100644 --- a/fastplotlib/layouts/_figure.py +++ b/fastplotlib/layouts/_figure.py @@ -53,6 +53,8 @@ def __init__( size: tuple[int, int] = (500, 300), names: list | np.ndarray = None, show_tooltips: bool = False, + custom_fonts: list[tuple[str, float]] = None, + override_default_font: bool = False, ): """ Create a Figure containing Subplots. @@ -127,6 +129,11 @@ def __init__( show_tooltips: bool, default False show tooltips on graphics + custom_fonts: list[tuple[str, float]], optional + Custom font file path and pixel sizes, TrueType/OpenType are supported. + + override_default_font: bool, default False + Load custom fonts before default fonts """ if rects is not None: diff --git a/fastplotlib/layouts/_imgui_figure.py b/fastplotlib/layouts/_imgui_figure.py index 046c622ea..523c25cae 100644 --- a/fastplotlib/layouts/_imgui_figure.py +++ b/fastplotlib/layouts/_imgui_figure.py @@ -45,6 +45,8 @@ def __init__( size: tuple[int, int] = (500, 300), names: list | np.ndarray = None, show_tooltips: bool = False, + custom_fonts: list[tuple[str, float]] = None, + override_default_font: bool = False, ): self._guis: dict[str, EdgeWindow] = {k: None for k in GUI_EDGES} @@ -62,6 +64,8 @@ def __init__( size=size, names=names, show_tooltips=show_tooltips, + custom_fonts=custom_fonts, + override_default_font=override_default_font, ) self._imgui_renderer = ImguiRenderer(self.renderer.device, self.canvas) @@ -82,18 +86,26 @@ def __init__( io = imgui.get_io() - self._default_imgui_font = io.fonts.add_font_from_file_ttf( - sans_serif_font, 14, imgui.ImFontConfig() - ) - - font_config = imgui.ImFontConfig() - font_config.merge_mode = True + default_fonts = [(sans_serif_font, 14), (fa_6_fonts_path, 14.0)] + custom_fonts = custom_fonts if custom_fonts is not None else [] - self._default_imgui_font = io.fonts.add_font_from_file_ttf( - fa_6_fonts_path, - 14, - font_config, - ) + if override_default_font: + font_list = custom_fonts + default_fonts + else: + font_list = default_fonts + custom_fonts + + first_font = True + for font_path, font_size in font_list: + font_config = imgui.ImFontConfig() + font_config.merge_mode = not first_font + if first_font: + first_font = False + + self._default_imgui_font = io.fonts.add_font_from_file_ttf( + font_path, + font_size, + font_config, + ) imgui.push_font(self._default_imgui_font, self._default_imgui_font.legacy_size)