ArnoChen commited on
Commit
742c08d
·
1 Parent(s): 79103ad

better font handling

Browse files
extra/VisualizationTool/assets/Geist-Regular.ttf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1462ccd6f9b8ddf05af952cd66789ac74f29727f0177584163fcd8b177462e5c
3
+ size 111644
extra/VisualizationTool/assets/LICENSE - Geist.txt ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (c) 2023 Vercel, in collaboration with basement.studio
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+ -----------------------------------------------------------
8
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
9
+ -----------------------------------------------------------
10
+
11
+ PREAMBLE
12
+ The goals of the Open Font License (OFL) are to stimulate worldwide
13
+ development of collaborative font projects, to support the font creation
14
+ efforts of academic and linguistic communities, and to provide a free and
15
+ open framework in which fonts may be shared and improved in partnership
16
+ with others.
17
+
18
+ The OFL allows the licensed fonts to be used, studied, modified and
19
+ redistributed freely as long as they are not sold by themselves. The
20
+ fonts, including any derivative works, can be bundled, embedded,
21
+ redistributed and/or sold with any software provided that any reserved
22
+ names are not used by derivative works. The fonts and derivatives,
23
+ however, cannot be released under any other type of license. The
24
+ requirement for fonts to remain under this license does not apply
25
+ to any document created using the fonts or their derivatives.
26
+
27
+ DEFINITIONS
28
+ "Font Software" refers to the set of files released by the Copyright
29
+ Holder(s) under this license and clearly marked as such. This may
30
+ include source files, build scripts and documentation.
31
+
32
+ "Reserved Font Name" refers to any names specified as such after the
33
+ copyright statement(s).
34
+
35
+ "Original Version" refers to the collection of Font Software components as
36
+ distributed by the Copyright Holder(s).
37
+
38
+ "Modified Version" refers to any derivative made by adding to, deleting,
39
+ or substituting -- in part or in whole -- any of the components of the
40
+ Original Version, by changing formats or by porting the Font Software to a
41
+ new environment.
42
+
43
+ "Author" refers to any designer, engineer, programmer, technical
44
+ writer or other person who contributed to the Font Software.
45
+
46
+ PERMISSION AND CONDITIONS
47
+ Permission is hereby granted, free of charge, to any person obtaining
48
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
49
+ redistribute, and sell modified and unmodified copies of the Font
50
+ Software, subject to the following conditions:
51
+
52
+ 1) Neither the Font Software nor any of its individual components,
53
+ in Original or Modified Versions, may be sold by itself.
54
+
55
+ 2) Original or Modified Versions of the Font Software may be bundled,
56
+ redistributed and/or sold with any software, provided that each copy
57
+ contains the above copyright notice and this license. These can be
58
+ included either as stand-alone text files, human-readable headers or
59
+ in the appropriate machine-readable metadata fields within text or
60
+ binary files as long as those fields can be easily viewed by the user.
61
+
62
+ 3) No Modified Version of the Font Software may use the Reserved Font
63
+ Name(s) unless explicit written permission is granted by the corresponding
64
+ Copyright Holder. This restriction only applies to the primary font name as
65
+ presented to the users.
66
+
67
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
68
+ Software shall not be used to promote, endorse or advertise any
69
+ Modified Version, except to acknowledge the contribution(s) of the
70
+ Copyright Holder(s) and the Author(s) or with their explicit written
71
+ permission.
72
+
73
+ 5) The Font Software, modified or unmodified, in part or in whole,
74
+ must be distributed entirely under this license, and must not be
75
+ distributed under any other license. The requirement for fonts to
76
+ remain under this license does not apply to any document created
77
+ using the Font Software.
78
+
79
+ TERMINATION
80
+ This license becomes null and void if any of the above conditions are
81
+ not met.
82
+
83
+ DISCLAIMER
84
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
85
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
86
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
87
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
88
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
89
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
90
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
91
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
92
+ OTHER DEALINGS IN THE FONT SOFTWARE.
extra/VisualizationTool/assets/LICENSE - SmileySans.txt ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (c) 2022--2024, atelierAnchor <https://atelier-anchor.com>,
2
+ with Reserved Font Name <Smiley> and <得意黑>.
3
+
4
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
5
+ This license is copied below, and is also available with a FAQ at:
6
+ http://scripts.sil.org/OFL
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
extra/VisualizationTool/assets/SmileySans-Oblique.ttf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b447d7e781f08bc95c4c9f23ba71ed2b8ebb639aa7184485c71c4ca5afcd25c4
3
+ size 2629764
extra/VisualizationTool/graph_visualizer.py CHANGED
@@ -20,6 +20,9 @@ import os
20
 
21
  CUSTOM_FONT = "font.ttf"
22
 
 
 
 
23
 
24
  class Node3D:
25
  """Class representing a 3D node in the graph"""
@@ -1169,39 +1172,38 @@ def main():
1169
  # You will need to provide it yourself, or use another font.
1170
  font_filename = CUSTOM_FONT
1171
 
1172
- use_custom_font = False
1173
- if not hello_imgui.asset_exists(font_filename):
1174
- asset_dir = os.path.join(os.path.dirname(__file__), "assets")
1175
- if os.path.isfile(os.path.join(asset_dir, font_filename)):
1176
- hello_imgui.set_assets_folder(asset_dir)
1177
- use_custom_font = True
1178
-
1179
  io = imgui.get_io()
1180
  io.fonts.tex_desired_width = 4096 # Larger texture for better CJK font quality
1181
-
1182
- if not use_custom_font:
1183
- io.fonts.add_font_default()
 
 
 
 
 
 
 
 
 
 
1184
  return
1185
 
1186
- # Set up font loading parameters with Chinese character support
1187
- font_loading_params = hello_imgui.FontLoadingParams()
1188
- font_loading_params.glyph_ranges = hello_imgui.translate_common_glyph_ranges(
1189
- imgui.get_io().fonts.get_glyph_ranges_chinese_full()
1190
  )
1191
 
1192
- custom_font = hello_imgui.load_font(font_filename, 16.0, font_loading_params)
1193
-
1194
- # # Merge with default font
1195
- # font_config = imgui.ImFontConfig()
1196
- # font_config.merge_mode = True
1197
- # custom_font = io.fonts.add_font_from_file_ttf(
1198
- # filename= "assets/" + font_filename,
1199
- # size_pixels=16.0,
1200
- # font_cfg=font_config,
1201
- # glyph_ranges_as_int_list=cn_glyph_ranges_imgui,
1202
- # )
1203
 
1204
- io.font_default = custom_font
 
 
 
 
 
1205
 
1206
  runner_params.callbacks.load_additional_fonts = load_font
1207
 
 
20
 
21
  CUSTOM_FONT = "font.ttf"
22
 
23
+ DEFAULT_FONT_ENG = "Geist-Regular.ttf"
24
+ DEFAULT_FONT_CHI = "SmileySans-Oblique.ttf"
25
+
26
 
27
  class Node3D:
28
  """Class representing a 3D node in the graph"""
 
1172
  # You will need to provide it yourself, or use another font.
1173
  font_filename = CUSTOM_FONT
1174
 
 
 
 
 
 
 
 
1175
  io = imgui.get_io()
1176
  io.fonts.tex_desired_width = 4096 # Larger texture for better CJK font quality
1177
+ font_size_pixels = 14
1178
+ asset_dir = os.path.join(os.path.dirname(__file__), "assets")
1179
+
1180
+ # Try to load custom font
1181
+ if not os.path.isfile(font_filename):
1182
+ font_filename = os.path.join(asset_dir, font_filename)
1183
+ if os.path.isfile(font_filename):
1184
+ custom_font = io.fonts.add_font_from_file_ttf(
1185
+ filename=font_filename,
1186
+ size_pixels=font_size_pixels,
1187
+ glyph_ranges_as_int_list=io.fonts.get_glyph_ranges_chinese_full(),
1188
+ )
1189
+ io.font_default = custom_font
1190
  return
1191
 
1192
+ # Load default fonts
1193
+ io.fonts.add_font_from_file_ttf(
1194
+ filename=os.path.join(asset_dir, DEFAULT_FONT_ENG),
1195
+ size_pixels=font_size_pixels,
1196
  )
1197
 
1198
+ font_config = imgui.ImFontConfig()
1199
+ font_config.merge_mode = True
 
 
 
 
 
 
 
 
 
1200
 
1201
+ io.font_default = io.fonts.add_font_from_file_ttf(
1202
+ filename=os.path.join(asset_dir, DEFAULT_FONT_CHI),
1203
+ size_pixels=font_size_pixels,
1204
+ font_cfg=font_config,
1205
+ glyph_ranges_as_int_list=io.fonts.get_glyph_ranges_chinese_full(),
1206
+ )
1207
 
1208
  runner_params.callbacks.load_additional_fonts = load_font
1209