-
Notifications
You must be signed in to change notification settings - Fork 5
/
patch_default_theme_3_2_2.diff
177 lines (172 loc) · 6.79 KB
/
patch_default_theme_3_2_2.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
diff --git a/scene/resources/default_theme/SCsub b/scene/resources/default_theme/SCsub
index b01e2fd54d..3b9c1cdaea 100644
--- a/scene/resources/default_theme/SCsub
+++ b/scene/resources/default_theme/SCsub
@@ -2,4 +2,23 @@
Import("env")
+import os
+import os.path
+from platform_methods import run_in_subprocess
+from compat import open_utf8
+import font_builders
+import glob
+
+path = env.Dir('.').abspath
+
+# Fonts
+flist = glob.glob(path + "/../../../thirdparty/fonts/*.ttf")
+flist.extend(glob.glob(path + "/../../../thirdparty/fonts/*.otf"))
+flist.sort()
+env.Depends('builtin_noto_fonts.gen.h', flist)
+env.CommandNoCache('builtin_noto_fonts.gen.h', flist, run_in_subprocess(font_builders.make_fonts_header))
+
+env.Append(CXXFLAGS=['-DGODOT_MODULE'])
+env.Append(CPPPATH=['#modules/godot_tl/src/resources', '#modules/godot_tl/src', '#modules/godot_tl/subprojects/graphite2/include', '#modules/godot_tl/subprojects/harfbuzz/src', '#modules/godot_tl/subprojects/icu4c/source/common'])
+
env.add_source_files(env.scene_sources, "*.cpp")
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index 00c56e5eb2..e144f586a5 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -35,8 +35,11 @@
#include "core/os/os.h"
#include "theme_data.h"
-#include "font_hidpi.inc"
-#include "font_lodpi.inc"
+#include "builtin_noto_fonts.gen.h"
+
+#include "modules/godot_tl/src/resources/tl_font_family.hpp"
+#include "modules/godot_tl/src/resources/tl_dynamic_font.hpp"
+#include "modules/godot_tl/src/resources/tl_gd_font_wrapper.hpp"
typedef Map<const void *, Ref<ImageTexture> > TexCacheMap;
@@ -877,10 +880,80 @@ void make_default_theme(bool p_hidpi, Ref<Font> p_font) {
Ref<Font> default_font;
if (p_font.is_valid()) {
default_font = p_font;
- } else if (p_hidpi) {
- default_font = make_font(_hidpi_font_height, _hidpi_font_ascent, _hidpi_font_charcount, &_hidpi_font_charrects[0][0], _hidpi_font_kerning_pair_count, &_hidpi_font_kerning_pairs[0][0], _hidpi_font_img_width, _hidpi_font_img_height, _hidpi_font_img_data);
} else {
- default_font = make_font(_lodpi_font_height, _lodpi_font_ascent, _lodpi_font_charcount, &_lodpi_font_charrects[0][0], _lodpi_font_kerning_pair_count, &_lodpi_font_kerning_pairs[0][0], _lodpi_font_img_width, _lodpi_font_img_height, _lodpi_font_img_data);
+#ifdef OSX_ENABLED
+ DynamicFaceHinting font_hinting = DF_HINTING_NONE;
+#else
+ DynamicFaceHinting font_hinting = DF_HINTING_LIGHT;
+#endif
+ Ref<TLDynamicFontFace> DefaultFont;
+ DefaultFont.instance();
+ DefaultFont->set_hinting(font_hinting);
+ DefaultFont->set_font_ptr(_font_NotoSansUI_Regular, _font_NotoSansUI_Regular_size);
+ DefaultFont->set_force_autohinter(true); //just looks better..i think?
+
+ Ref<TLDynamicFontFace> DefaultFontBold;
+ DefaultFontBold.instance();
+ DefaultFontBold->set_hinting(font_hinting);
+ DefaultFontBold->set_font_ptr(_font_NotoSansUI_Bold, _font_NotoSansUI_Bold_size);
+ DefaultFontBold->set_force_autohinter(true); // just looks better..i think?
+
+ Ref<TLDynamicFontFace> FontFallback;
+ FontFallback.instance();
+ FontFallback->set_hinting(font_hinting);
+ FontFallback->set_font_ptr(_font_DroidSansFallback, _font_DroidSansFallback_size);
+ FontFallback->set_force_autohinter(true); //just looks better..i think?
+
+ Ref<TLDynamicFontFace> FontJapanese;
+ FontJapanese.instance();
+ FontJapanese->set_hinting(font_hinting);
+ FontJapanese->set_font_ptr(_font_DroidSansJapanese, _font_DroidSansJapanese_size);
+ FontJapanese->set_force_autohinter(true); //just looks better..i think?
+
+ Ref<TLDynamicFontFace> FontArabic;
+ FontArabic.instance();
+ FontArabic->set_hinting(font_hinting);
+ FontArabic->set_font_ptr(_font_NotoNaskhArabicUI_Regular, _font_NotoNaskhArabicUI_Regular_size);
+ FontArabic->set_force_autohinter(true); //just looks better..i think?
+
+ Ref<TLDynamicFontFace> FontHebrew;
+ FontHebrew.instance();
+ FontHebrew->set_hinting(font_hinting);
+ FontHebrew->set_font_ptr(_font_NotoSansHebrew_Regular, _font_NotoSansHebrew_Regular_size);
+ FontHebrew->set_force_autohinter(true); //just looks better..i think?
+
+ Ref<TLDynamicFontFace> FontThai;
+ FontThai.instance();
+ FontThai->set_hinting(font_hinting);
+ FontThai->set_font_ptr(_font_NotoSansThaiUI_Regular, _font_NotoSansThaiUI_Regular_size);
+ FontThai->set_force_autohinter(true); //just looks better..i think?
+
+ Ref<TLDynamicFontFace> FontHindi;
+ FontHindi.instance();
+ FontHindi->set_hinting(font_hinting);
+ FontHindi->set_font_ptr(_font_NotoSansDevanagariUI_Regular, _font_NotoSansDevanagariUI_Regular_size);
+ FontHindi->set_force_autohinter(true); //just looks better..i think?
+
+ Ref<TLFontFamily> dff;
+ dff.instance();
+ dff->add_style("Default");
+ dff->add_style("Bold");
+ dff->add_style("Source");
+ dff->add_face("Default", DefaultFont);
+ dff->add_face("Default", FontArabic);
+ dff->add_face("Default", FontHebrew);
+ dff->add_face("Default", FontThai);
+ dff->add_face("Default", FontHindi);
+ dff->add_face("Default", FontJapanese);
+ dff->add_face("Default", FontFallback);
+
+ Ref<TLGDFontWrapper> df;
+ df.instance();
+ df->set_base_font(dff);
+ df->set_base_font_style("Default");
+ df->set_base_font_size(16);
+
+ default_font = df;
}
Ref<Font> large_font = default_font;
fill_default_theme(t, default_font, large_font, default_icon, default_style, p_hidpi ? 2.0 : 1.0);
diff --git a/scene/resources/default_theme/font_builders.py b/scene/resources/default_theme/font_builders.py
new file mode 100644
index 0000000000..dd78006e53
--- /dev/null
+++ b/scene/resources/default_theme/font_builders.py
@@ -0,0 +1,41 @@
+"""Functions used to generate source files during build time
+
+All such functions are invoked in a subprocess on Windows to prevent build flakiness.
+
+"""
+import os
+import os.path
+from platform_methods import subprocess_main
+from compat import encode_utf8, byte_to_str, open_utf8
+
+def make_fonts_header(target, source, env):
+
+ dst = target[0]
+
+ g = open_utf8(dst, "w")
+
+ g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
+ g.write("#ifndef _EDITOR_FONTS_H\n")
+ g.write("#define _EDITOR_FONTS_H\n")
+
+ # saving uncompressed, since freetype will reference from memory pointer
+ xl_names = []
+ for i in range(len(source)):
+ with open(source[i], "rb")as f:
+ buf = f.read()
+
+ name = os.path.splitext(os.path.basename(source[i]))[0]
+
+ g.write("static const int _font_" + name + "_size = " + str(len(buf)) + ";\n")
+ g.write("static const unsigned char _font_" + name + "[] = {\n")
+ for j in range(len(buf)):
+ g.write("\t" + byte_to_str(buf[j]) + ",\n")
+
+ g.write("};\n")
+
+ g.write("#endif")
+
+ g.close()
+
+if __name__ == '__main__':
+ subprocess_main(globals())