Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/themes/editor_fonts.cpp
9896 views
1
/**************************************************************************/
2
/* editor_fonts.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "editor_fonts.h"
32
33
#include "core/io/dir_access.h"
34
#include "editor/editor_string_names.h"
35
#include "editor/settings/editor_settings.h"
36
#include "editor/themes/builtin_fonts.gen.h"
37
#include "editor/themes/editor_scale.h"
38
#include "scene/resources/font.h"
39
#include "scene/scene_string_names.h"
40
41
Ref<FontFile> load_external_font(const String &p_path, TextServer::Hinting p_hinting, TextServer::FontAntialiasing p_aa, bool p_autohint, TextServer::SubpixelPositioning p_font_subpixel_positioning, bool p_font_disable_embedded_bitmaps, bool p_msdf = false, TypedArray<Font> *r_fallbacks = nullptr) {
42
Ref<FontFile> font;
43
font.instantiate();
44
45
Vector<uint8_t> data = FileAccess::get_file_as_bytes(p_path);
46
47
font->set_data(data);
48
font->set_multichannel_signed_distance_field(p_msdf);
49
font->set_antialiasing(p_aa);
50
font->set_hinting(p_hinting);
51
font->set_force_autohinter(p_autohint);
52
font->set_subpixel_positioning(p_font_subpixel_positioning);
53
font->set_disable_embedded_bitmaps(p_font_disable_embedded_bitmaps);
54
55
if (r_fallbacks != nullptr) {
56
r_fallbacks->push_back(font);
57
}
58
59
return font;
60
}
61
62
Ref<SystemFont> load_system_font(const PackedStringArray &p_names, TextServer::Hinting p_hinting, TextServer::FontAntialiasing p_aa, bool p_autohint, TextServer::SubpixelPositioning p_font_subpixel_positioning, bool p_font_disable_embedded_bitmaps, bool p_msdf = false, TypedArray<Font> *r_fallbacks = nullptr) {
63
Ref<SystemFont> font;
64
font.instantiate();
65
66
font->set_font_names(p_names);
67
font->set_multichannel_signed_distance_field(p_msdf);
68
font->set_antialiasing(p_aa);
69
font->set_hinting(p_hinting);
70
font->set_force_autohinter(p_autohint);
71
font->set_subpixel_positioning(p_font_subpixel_positioning);
72
font->set_disable_embedded_bitmaps(p_font_disable_embedded_bitmaps);
73
74
if (r_fallbacks != nullptr) {
75
r_fallbacks->push_back(font);
76
}
77
78
return font;
79
}
80
81
Ref<FontFile> load_internal_font(const uint8_t *p_data, size_t p_size, TextServer::Hinting p_hinting, TextServer::FontAntialiasing p_aa, bool p_autohint, TextServer::SubpixelPositioning p_font_subpixel_positioning, bool p_font_disable_embedded_bitmaps, bool p_msdf = false, TypedArray<Font> *r_fallbacks = nullptr) {
82
Ref<FontFile> font;
83
font.instantiate();
84
85
font->set_data_ptr(p_data, p_size);
86
font->set_multichannel_signed_distance_field(p_msdf);
87
font->set_antialiasing(p_aa);
88
font->set_hinting(p_hinting);
89
font->set_force_autohinter(p_autohint);
90
font->set_subpixel_positioning(p_font_subpixel_positioning);
91
font->set_disable_embedded_bitmaps(p_font_disable_embedded_bitmaps);
92
93
if (r_fallbacks != nullptr) {
94
r_fallbacks->push_back(font);
95
}
96
97
return font;
98
}
99
100
Ref<FontVariation> make_bold_font(const Ref<Font> &p_font, double p_embolden, TypedArray<Font> *r_fallbacks = nullptr) {
101
Ref<FontVariation> font_var;
102
font_var.instantiate();
103
font_var->set_base_font(p_font);
104
font_var->set_variation_embolden(p_embolden);
105
106
if (r_fallbacks != nullptr) {
107
r_fallbacks->push_back(font_var);
108
}
109
110
return font_var;
111
}
112
113
void editor_register_fonts(const Ref<Theme> &p_theme) {
114
Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
115
116
TextServer::FontAntialiasing font_antialiasing = (TextServer::FontAntialiasing)(int)EDITOR_GET("interface/editor/font_antialiasing");
117
int font_hinting_setting = (int)EDITOR_GET("interface/editor/font_hinting");
118
TextServer::SubpixelPositioning font_subpixel_positioning = (TextServer::SubpixelPositioning)(int)EDITOR_GET("interface/editor/font_subpixel_positioning");
119
bool font_disable_embedded_bitmaps = (bool)EDITOR_GET("interface/editor/font_disable_embedded_bitmaps");
120
bool font_allow_msdf = (bool)EDITOR_GET("interface/editor/font_allow_msdf");
121
122
TextServer::Hinting font_hinting;
123
TextServer::Hinting font_mono_hinting;
124
switch (font_hinting_setting) {
125
case 0:
126
// The "Auto" setting uses the setting that best matches the OS' font rendering:
127
// - macOS doesn't use font hinting.
128
// - Windows uses ClearType, which is in between "Light" and "Normal" hinting.
129
// - Linux has configurable font hinting, but most distributions including Ubuntu default to "Light".
130
#ifdef MACOS_ENABLED
131
font_hinting = TextServer::HINTING_NONE;
132
font_mono_hinting = TextServer::HINTING_NONE;
133
#else
134
font_hinting = TextServer::HINTING_LIGHT;
135
font_mono_hinting = TextServer::HINTING_LIGHT;
136
#endif
137
break;
138
case 1:
139
font_hinting = TextServer::HINTING_NONE;
140
font_mono_hinting = TextServer::HINTING_NONE;
141
break;
142
case 2:
143
font_hinting = TextServer::HINTING_LIGHT;
144
font_mono_hinting = TextServer::HINTING_LIGHT;
145
break;
146
default:
147
font_hinting = TextServer::HINTING_NORMAL;
148
font_mono_hinting = TextServer::HINTING_LIGHT;
149
break;
150
}
151
152
// Load built-in fonts.
153
const int default_font_size = int(EDITOR_GET("interface/editor/main_font_size")) * EDSCALE;
154
const float embolden_strength = 0.6;
155
156
Ref<Font> default_font = load_internal_font(_font_NotoSans_Regular, _font_NotoSans_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false);
157
Ref<Font> default_font_msdf = load_internal_font(_font_NotoSans_Regular, _font_NotoSans_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, font_allow_msdf);
158
159
String noto_cjk_path;
160
String noto_cjk_bold_path;
161
String var_suffix[] = { "HK", "KR", "SC", "TC", "JP" }; // Note: All Noto Sans CJK versions support all glyph variations, it should not match current locale.
162
for (size_t i = 0; i < std::size(var_suffix); i++) {
163
if (noto_cjk_path.is_empty()) {
164
noto_cjk_path = OS::get_singleton()->get_system_font_path("Noto Sans CJK " + var_suffix[i], 400, 100);
165
}
166
if (noto_cjk_bold_path.is_empty()) {
167
noto_cjk_bold_path = OS::get_singleton()->get_system_font_path("Noto Sans CJK " + var_suffix[i], 800, 100);
168
}
169
}
170
171
TypedArray<Font> fallbacks;
172
Ref<FontFile> arabic_font = load_internal_font(_font_Vazirmatn_Regular, _font_Vazirmatn_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks);
173
Ref<FontFile> bengali_font = load_internal_font(_font_NotoSansBengaliUI_Regular, _font_NotoSansBengaliUI_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks);
174
Ref<FontFile> devanagari_font = load_internal_font(_font_NotoSansDevanagariUI_Regular, _font_NotoSansDevanagariUI_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks);
175
Ref<FontFile> georgian_font = load_internal_font(_font_NotoSansGeorgian_Regular, _font_NotoSansGeorgian_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks);
176
Ref<FontFile> hebrew_font = load_internal_font(_font_NotoSansHebrew_Regular, _font_NotoSansHebrew_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks);
177
Ref<FontFile> malayalam_font = load_internal_font(_font_NotoSansMalayalamUI_Regular, _font_NotoSansMalayalamUI_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks);
178
Ref<FontFile> oriya_font = load_internal_font(_font_NotoSansOriya_Regular, _font_NotoSansOriya_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks);
179
Ref<FontFile> sinhala_font = load_internal_font(_font_NotoSansSinhalaUI_Regular, _font_NotoSansSinhalaUI_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks);
180
Ref<FontFile> tamil_font = load_internal_font(_font_NotoSansTamilUI_Regular, _font_NotoSansTamilUI_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks);
181
Ref<FontFile> telugu_font = load_internal_font(_font_NotoSansTeluguUI_Regular, _font_NotoSansTeluguUI_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks);
182
Ref<FontFile> thai_font = load_internal_font(_font_NotoSansThai_Regular, _font_NotoSansThai_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks);
183
if (!noto_cjk_path.is_empty()) {
184
load_external_font(noto_cjk_path, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks);
185
}
186
Ref<FontFile> fallback_font = load_internal_font(_font_DroidSansFallback, _font_DroidSansFallback_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks);
187
Ref<FontFile> japanese_font = load_internal_font(_font_DroidSansJapanese, _font_DroidSansJapanese_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks);
188
default_font->set_fallbacks(fallbacks);
189
default_font_msdf->set_fallbacks(fallbacks);
190
191
Ref<FontFile> default_font_bold = load_internal_font(_font_NotoSans_Bold, _font_NotoSans_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false);
192
Ref<FontFile> default_font_bold_msdf = load_internal_font(_font_NotoSans_Bold, _font_NotoSans_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, font_allow_msdf);
193
194
TypedArray<Font> fallbacks_bold;
195
Ref<FontFile> arabic_font_bold = load_internal_font(_font_Vazirmatn_Bold, _font_Vazirmatn_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks_bold);
196
Ref<FontFile> bengali_font_bold = load_internal_font(_font_NotoSansBengaliUI_Bold, _font_NotoSansBengaliUI_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks_bold);
197
Ref<FontFile> devanagari_font_bold = load_internal_font(_font_NotoSansDevanagariUI_Bold, _font_NotoSansDevanagariUI_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks_bold);
198
Ref<FontFile> georgian_font_bold = load_internal_font(_font_NotoSansGeorgian_Bold, _font_NotoSansGeorgian_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks_bold);
199
Ref<FontFile> hebrew_font_bold = load_internal_font(_font_NotoSansHebrew_Bold, _font_NotoSansHebrew_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks_bold);
200
Ref<FontFile> malayalam_font_bold = load_internal_font(_font_NotoSansMalayalamUI_Bold, _font_NotoSansMalayalamUI_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks_bold);
201
Ref<FontFile> oriya_font_bold = load_internal_font(_font_NotoSansOriya_Bold, _font_NotoSansOriya_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks_bold);
202
Ref<FontFile> sinhala_font_bold = load_internal_font(_font_NotoSansSinhalaUI_Bold, _font_NotoSansSinhalaUI_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks_bold);
203
Ref<FontFile> tamil_font_bold = load_internal_font(_font_NotoSansTamilUI_Bold, _font_NotoSansTamilUI_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks_bold);
204
Ref<FontFile> telugu_font_bold = load_internal_font(_font_NotoSansTeluguUI_Bold, _font_NotoSansTeluguUI_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks_bold);
205
Ref<FontFile> thai_font_bold = load_internal_font(_font_NotoSansThai_Bold, _font_NotoSansThai_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks_bold);
206
if (!noto_cjk_bold_path.is_empty()) {
207
load_external_font(noto_cjk_bold_path, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false, &fallbacks_bold);
208
}
209
Ref<FontVariation> fallback_font_bold = make_bold_font(fallback_font, embolden_strength, &fallbacks_bold);
210
Ref<FontVariation> japanese_font_bold = make_bold_font(japanese_font, embolden_strength, &fallbacks_bold);
211
212
if (OS::get_singleton()->has_feature("system_fonts")) {
213
PackedStringArray emoji_font_names = {
214
"Apple Color Emoji",
215
"Segoe UI Emoji",
216
"Noto Color Emoji",
217
"Twitter Color Emoji",
218
"OpenMoji",
219
"EmojiOne Color"
220
};
221
Ref<SystemFont> emoji_font = load_system_font(emoji_font_names, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, false);
222
fallbacks.push_back(emoji_font);
223
fallbacks_bold.push_back(emoji_font);
224
}
225
226
default_font_bold->set_fallbacks(fallbacks_bold);
227
default_font_bold_msdf->set_fallbacks(fallbacks_bold);
228
229
Ref<FontFile> default_font_mono = load_internal_font(_font_JetBrainsMono_Regular, _font_JetBrainsMono_Regular_size, font_mono_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps);
230
default_font_mono->set_fallbacks(fallbacks);
231
232
// Init base font configs and load custom fonts.
233
String custom_font_path = EDITOR_GET("interface/editor/main_font");
234
String custom_font_path_bold = EDITOR_GET("interface/editor/main_font_bold");
235
String custom_font_path_source = EDITOR_GET("interface/editor/code_font");
236
237
Ref<FontVariation> default_fc;
238
default_fc.instantiate();
239
if (custom_font_path.length() > 0 && dir->file_exists(custom_font_path)) {
240
Ref<FontFile> custom_font = load_external_font(custom_font_path, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps);
241
{
242
TypedArray<Font> fallback_custom = { default_font };
243
custom_font->set_fallbacks(fallback_custom);
244
}
245
default_fc->set_base_font(custom_font);
246
} else {
247
EditorSettings::get_singleton()->set_manually("interface/editor/main_font", "");
248
default_fc->set_base_font(default_font);
249
}
250
default_fc->set_spacing(TextServer::SPACING_TOP, -EDSCALE);
251
default_fc->set_spacing(TextServer::SPACING_BOTTOM, -EDSCALE);
252
Dictionary default_fc_opentype;
253
default_fc_opentype["weight"] = 400;
254
default_fc->set_variation_opentype(default_fc_opentype);
255
256
Ref<FontVariation> default_fc_msdf;
257
default_fc_msdf.instantiate();
258
if (custom_font_path.length() > 0 && dir->file_exists(custom_font_path)) {
259
Ref<FontFile> custom_font = load_external_font(custom_font_path, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, font_allow_msdf);
260
{
261
TypedArray<Font> fallback_custom = { default_font_msdf };
262
custom_font->set_fallbacks(fallback_custom);
263
}
264
default_fc_msdf->set_base_font(custom_font);
265
} else {
266
EditorSettings::get_singleton()->set_manually("interface/editor/main_font", "");
267
default_fc_msdf->set_base_font(default_font_msdf);
268
}
269
default_fc_msdf->set_spacing(TextServer::SPACING_TOP, -EDSCALE);
270
default_fc_msdf->set_spacing(TextServer::SPACING_BOTTOM, -EDSCALE);
271
default_fc_msdf->set_variation_opentype(default_fc_opentype);
272
273
Ref<FontVariation> bold_fc;
274
bold_fc.instantiate();
275
if (custom_font_path_bold.length() > 0 && dir->file_exists(custom_font_path_bold)) {
276
Ref<FontFile> custom_font = load_external_font(custom_font_path_bold, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps);
277
{
278
TypedArray<Font> fallback_custom = { default_font_bold };
279
custom_font->set_fallbacks(fallback_custom);
280
}
281
bold_fc->set_base_font(custom_font);
282
} else if (custom_font_path.length() > 0 && dir->file_exists(custom_font_path)) {
283
Ref<FontFile> custom_font = load_external_font(custom_font_path, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps);
284
{
285
TypedArray<Font> fallback_custom = { default_font_bold };
286
custom_font->set_fallbacks(fallback_custom);
287
}
288
bold_fc->set_base_font(custom_font);
289
bold_fc->set_variation_embolden(embolden_strength);
290
} else {
291
EditorSettings::get_singleton()->set_manually("interface/editor/main_font_bold", "");
292
bold_fc->set_base_font(default_font_bold);
293
}
294
bold_fc->set_spacing(TextServer::SPACING_TOP, -EDSCALE);
295
bold_fc->set_spacing(TextServer::SPACING_BOTTOM, -EDSCALE);
296
Dictionary bold_fc_opentype;
297
bold_fc_opentype["weight"] = 700;
298
bold_fc->set_variation_opentype(bold_fc_opentype);
299
300
Ref<FontVariation> bold_fc_msdf;
301
bold_fc_msdf.instantiate();
302
if (custom_font_path_bold.length() > 0 && dir->file_exists(custom_font_path_bold)) {
303
Ref<FontFile> custom_font = load_external_font(custom_font_path_bold, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, font_allow_msdf);
304
{
305
TypedArray<Font> fallback_custom = { default_font_bold_msdf };
306
custom_font->set_fallbacks(fallback_custom);
307
}
308
bold_fc_msdf->set_base_font(custom_font);
309
} else if (custom_font_path.length() > 0 && dir->file_exists(custom_font_path)) {
310
Ref<FontFile> custom_font = load_external_font(custom_font_path, font_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps, font_allow_msdf);
311
{
312
TypedArray<Font> fallback_custom = { default_font_bold_msdf };
313
custom_font->set_fallbacks(fallback_custom);
314
}
315
bold_fc_msdf->set_base_font(custom_font);
316
bold_fc_msdf->set_variation_embolden(embolden_strength);
317
} else {
318
EditorSettings::get_singleton()->set_manually("interface/editor/main_font_bold", "");
319
bold_fc_msdf->set_base_font(default_font_bold_msdf);
320
}
321
bold_fc_msdf->set_spacing(TextServer::SPACING_TOP, -EDSCALE);
322
bold_fc_msdf->set_spacing(TextServer::SPACING_BOTTOM, -EDSCALE);
323
bold_fc_msdf->set_variation_opentype(bold_fc_opentype);
324
325
Ref<FontVariation> mono_fc;
326
mono_fc.instantiate();
327
if (custom_font_path_source.length() > 0 && dir->file_exists(custom_font_path_source)) {
328
Ref<FontFile> custom_font = load_external_font(custom_font_path_source, font_mono_hinting, font_antialiasing, true, font_subpixel_positioning, font_disable_embedded_bitmaps);
329
{
330
TypedArray<Font> fallback_custom = { default_font_mono };
331
custom_font->set_fallbacks(fallback_custom);
332
}
333
mono_fc->set_base_font(custom_font);
334
} else {
335
EditorSettings::get_singleton()->set_manually("interface/editor/code_font", "");
336
mono_fc->set_base_font(default_font_mono);
337
}
338
mono_fc->set_spacing(TextServer::SPACING_TOP, -EDSCALE);
339
mono_fc->set_spacing(TextServer::SPACING_BOTTOM, -EDSCALE);
340
341
Ref<FontVariation> mono_other_fc = mono_fc->duplicate();
342
343
// Enable contextual alternates (coding ligatures) and custom features for the source editor font.
344
int ot_mode = EDITOR_GET("interface/editor/code_font_contextual_ligatures");
345
switch (ot_mode) {
346
case 1: { // Disable ligatures.
347
Dictionary ftrs;
348
ftrs[TS->name_to_tag("calt")] = 0;
349
mono_fc->set_opentype_features(ftrs);
350
} break;
351
case 2: { // Custom.
352
Vector<String> subtag = String(EDITOR_GET("interface/editor/code_font_custom_opentype_features")).split(",");
353
Dictionary ftrs;
354
for (int i = 0; i < subtag.size(); i++) {
355
Vector<String> subtag_a = subtag[i].split("=");
356
if (subtag_a.size() == 2) {
357
ftrs[TS->name_to_tag(subtag_a[0])] = subtag_a[1].to_int();
358
} else if (subtag_a.size() == 1) {
359
ftrs[TS->name_to_tag(subtag_a[0])] = 1;
360
}
361
}
362
mono_fc->set_opentype_features(ftrs);
363
} break;
364
default: { // Enabled.
365
Dictionary ftrs;
366
ftrs[TS->name_to_tag("calt")] = 1;
367
mono_fc->set_opentype_features(ftrs);
368
} break;
369
}
370
371
{
372
// Disable contextual alternates (coding ligatures).
373
Dictionary ftrs;
374
ftrs[TS->name_to_tag("calt")] = 0;
375
mono_other_fc->set_opentype_features(ftrs);
376
}
377
378
// Use fake bold/italics to style the editor log's `print_rich()` output.
379
// Use stronger embolden strength to make bold easier to distinguish from regular text.
380
Ref<FontVariation> mono_other_fc_bold = mono_other_fc->duplicate();
381
mono_other_fc_bold->set_variation_embolden(0.8);
382
383
Ref<FontVariation> mono_other_fc_italic = mono_other_fc->duplicate();
384
mono_other_fc_italic->set_variation_transform(Transform2D(1.0, 0.2, 0.0, 1.0, 0.0, 0.0));
385
386
Ref<FontVariation> mono_other_fc_bold_italic = mono_other_fc->duplicate();
387
mono_other_fc_bold_italic->set_variation_embolden(0.8);
388
mono_other_fc_bold_italic->set_variation_transform(Transform2D(1.0, 0.2, 0.0, 1.0, 0.0, 0.0));
389
390
Ref<FontVariation> mono_other_fc_mono = mono_other_fc->duplicate();
391
// Use a different font style to distinguish `[code]` in rich prints.
392
// This emulates the "faint" styling used in ANSI escape codes by using a slightly thinner font.
393
mono_other_fc_mono->set_variation_embolden(-0.25);
394
mono_other_fc_mono->set_variation_transform(Transform2D(1.0, 0.1, 0.0, 1.0, 0.0, 0.0));
395
396
Ref<FontVariation> italic_fc = default_fc->duplicate();
397
italic_fc->set_variation_transform(Transform2D(1.0, 0.2, 0.0, 1.0, 0.0, 0.0));
398
399
Ref<FontVariation> bold_italic_fc = bold_fc->duplicate();
400
bold_italic_fc->set_variation_transform(Transform2D(1.0, 0.2, 0.0, 1.0, 0.0, 0.0));
401
402
// Setup theme.
403
404
p_theme->set_default_font(default_fc); // Default theme font config.
405
p_theme->set_default_font_size(default_font_size);
406
407
// Main font.
408
409
p_theme->set_font("main", EditorStringName(EditorFonts), default_fc);
410
p_theme->set_font("main_msdf", EditorStringName(EditorFonts), default_fc_msdf);
411
p_theme->set_font_size("main_size", EditorStringName(EditorFonts), default_font_size);
412
413
p_theme->set_font("bold", EditorStringName(EditorFonts), bold_fc);
414
p_theme->set_font("main_bold_msdf", EditorStringName(EditorFonts), bold_fc_msdf);
415
p_theme->set_font_size("bold_size", EditorStringName(EditorFonts), default_font_size);
416
417
p_theme->set_font("italic", EditorStringName(EditorFonts), italic_fc);
418
p_theme->set_font_size("italic_size", EditorStringName(EditorFonts), default_font_size);
419
420
// Title font.
421
422
p_theme->set_font("title", EditorStringName(EditorFonts), bold_fc);
423
p_theme->set_font_size("title_size", EditorStringName(EditorFonts), default_font_size + 1 * EDSCALE);
424
425
p_theme->set_type_variation("MainScreenButton", "Button");
426
p_theme->set_font(SceneStringName(font), "MainScreenButton", bold_fc);
427
p_theme->set_font_size(SceneStringName(font_size), "MainScreenButton", default_font_size + 2 * EDSCALE);
428
429
// Labels.
430
431
p_theme->set_font(SceneStringName(font), "Label", default_fc);
432
433
p_theme->set_type_variation("HeaderSmall", "Label");
434
p_theme->set_font(SceneStringName(font), "HeaderSmall", bold_fc);
435
p_theme->set_font_size(SceneStringName(font_size), "HeaderSmall", default_font_size);
436
437
p_theme->set_type_variation("HeaderMedium", "Label");
438
p_theme->set_font(SceneStringName(font), "HeaderMedium", bold_fc);
439
p_theme->set_font_size(SceneStringName(font_size), "HeaderMedium", default_font_size + 1 * EDSCALE);
440
441
p_theme->set_type_variation("HeaderLarge", "Label");
442
p_theme->set_font(SceneStringName(font), "HeaderLarge", bold_fc);
443
p_theme->set_font_size(SceneStringName(font_size), "HeaderLarge", default_font_size + 3 * EDSCALE);
444
445
p_theme->set_font("normal_font", "RichTextLabel", default_fc);
446
p_theme->set_font("bold_font", "RichTextLabel", bold_fc);
447
p_theme->set_font("italics_font", "RichTextLabel", italic_fc);
448
p_theme->set_font("bold_italics_font", "RichTextLabel", bold_italic_fc);
449
450
// Documentation fonts
451
p_theme->set_font_size("doc_size", EditorStringName(EditorFonts), int(EDITOR_GET("text_editor/help/help_font_size")) * EDSCALE);
452
p_theme->set_font("doc", EditorStringName(EditorFonts), default_fc);
453
p_theme->set_font("doc_bold", EditorStringName(EditorFonts), bold_fc);
454
p_theme->set_font("doc_italic", EditorStringName(EditorFonts), italic_fc);
455
p_theme->set_font_size("doc_title_size", EditorStringName(EditorFonts), int(EDITOR_GET("text_editor/help/help_title_font_size")) * EDSCALE);
456
p_theme->set_font("doc_title", EditorStringName(EditorFonts), bold_fc);
457
p_theme->set_font_size("doc_source_size", EditorStringName(EditorFonts), int(EDITOR_GET("text_editor/help/help_source_font_size")) * EDSCALE);
458
p_theme->set_font("doc_source", EditorStringName(EditorFonts), mono_fc);
459
p_theme->set_font_size("doc_keyboard_size", EditorStringName(EditorFonts), (int(EDITOR_GET("text_editor/help/help_source_font_size")) - 1) * EDSCALE);
460
p_theme->set_font("doc_keyboard", EditorStringName(EditorFonts), mono_fc);
461
462
// Ruler font
463
p_theme->set_font_size("rulers_size", EditorStringName(EditorFonts), 8 * EDSCALE);
464
p_theme->set_font("rulers", EditorStringName(EditorFonts), default_fc);
465
466
// Rotation widget font
467
p_theme->set_font_size("rotation_control_size", EditorStringName(EditorFonts), 13 * EDSCALE);
468
p_theme->set_font("rotation_control", EditorStringName(EditorFonts), default_fc);
469
470
// Code font
471
p_theme->set_font_size("source_size", EditorStringName(EditorFonts), int(EDITOR_GET("interface/editor/code_font_size")) * EDSCALE);
472
p_theme->set_font("source", EditorStringName(EditorFonts), mono_fc);
473
474
p_theme->set_font_size("expression_size", EditorStringName(EditorFonts), (int(EDITOR_GET("interface/editor/code_font_size")) - 1) * EDSCALE);
475
p_theme->set_font("expression", EditorStringName(EditorFonts), mono_other_fc);
476
477
p_theme->set_font_size("output_source_size", EditorStringName(EditorFonts), int(EDITOR_GET("run/output/font_size")) * EDSCALE);
478
p_theme->set_font("output_source", EditorStringName(EditorFonts), mono_other_fc);
479
p_theme->set_font("output_source_bold", EditorStringName(EditorFonts), mono_other_fc_bold);
480
p_theme->set_font("output_source_italic", EditorStringName(EditorFonts), mono_other_fc_italic);
481
p_theme->set_font("output_source_bold_italic", EditorStringName(EditorFonts), mono_other_fc_bold_italic);
482
p_theme->set_font("output_source_mono", EditorStringName(EditorFonts), mono_other_fc_mono);
483
484
p_theme->set_font_size("status_source_size", EditorStringName(EditorFonts), default_font_size);
485
p_theme->set_font("status_source", EditorStringName(EditorFonts), mono_other_fc);
486
}
487
488