editor_fonts.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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. #include "editor_fonts.h"
  31. #include "builtin_fonts.gen.h"
  32. #include "core/io/dir_access.h"
  33. #include "editor/editor_scale.h"
  34. #include "editor/editor_settings.h"
  35. #include "editor/editor_string_names.h"
  36. #include "scene/resources/font.h"
  37. 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_msdf = false, TypedArray<Font> *r_fallbacks = nullptr) {
  38. Ref<FontFile> font;
  39. font.instantiate();
  40. Vector<uint8_t> data = FileAccess::get_file_as_bytes(p_path);
  41. font->set_data(data);
  42. font->set_multichannel_signed_distance_field(p_msdf);
  43. font->set_antialiasing(p_aa);
  44. font->set_hinting(p_hinting);
  45. font->set_force_autohinter(p_autohint);
  46. font->set_subpixel_positioning(p_font_subpixel_positioning);
  47. if (r_fallbacks != nullptr) {
  48. r_fallbacks->push_back(font);
  49. }
  50. return font;
  51. }
  52. 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_msdf = false, TypedArray<Font> *r_fallbacks = nullptr) {
  53. Ref<SystemFont> font;
  54. font.instantiate();
  55. font->set_font_names(p_names);
  56. font->set_multichannel_signed_distance_field(p_msdf);
  57. font->set_antialiasing(p_aa);
  58. font->set_hinting(p_hinting);
  59. font->set_force_autohinter(p_autohint);
  60. font->set_subpixel_positioning(p_font_subpixel_positioning);
  61. if (r_fallbacks != nullptr) {
  62. r_fallbacks->push_back(font);
  63. }
  64. return font;
  65. }
  66. 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_msdf = false, TypedArray<Font> *r_fallbacks = nullptr) {
  67. Ref<FontFile> font;
  68. font.instantiate();
  69. font->set_data_ptr(p_data, p_size);
  70. font->set_multichannel_signed_distance_field(p_msdf);
  71. font->set_antialiasing(p_aa);
  72. font->set_hinting(p_hinting);
  73. font->set_force_autohinter(p_autohint);
  74. font->set_subpixel_positioning(p_font_subpixel_positioning);
  75. if (r_fallbacks != nullptr) {
  76. r_fallbacks->push_back(font);
  77. }
  78. return font;
  79. }
  80. Ref<FontVariation> make_bold_font(const Ref<Font> &p_font, double p_embolden, TypedArray<Font> *r_fallbacks = nullptr) {
  81. Ref<FontVariation> font_var;
  82. font_var.instantiate();
  83. font_var->set_base_font(p_font);
  84. font_var->set_variation_embolden(p_embolden);
  85. if (r_fallbacks != nullptr) {
  86. r_fallbacks->push_back(font_var);
  87. }
  88. return font_var;
  89. }
  90. void editor_register_fonts(Ref<Theme> p_theme) {
  91. OS::get_singleton()->benchmark_begin_measure("editor_register_fonts");
  92. Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
  93. TextServer::FontAntialiasing font_antialiasing = (TextServer::FontAntialiasing)(int)EDITOR_GET("interface/editor/font_antialiasing");
  94. int font_hinting_setting = (int)EDITOR_GET("interface/editor/font_hinting");
  95. TextServer::SubpixelPositioning font_subpixel_positioning = (TextServer::SubpixelPositioning)(int)EDITOR_GET("interface/editor/font_subpixel_positioning");
  96. TextServer::Hinting font_hinting;
  97. TextServer::Hinting font_mono_hinting;
  98. switch (font_hinting_setting) {
  99. case 0:
  100. // The "Auto" setting uses the setting that best matches the OS' font rendering:
  101. // - macOS doesn't use font hinting.
  102. // - Windows uses ClearType, which is in between "Light" and "Normal" hinting.
  103. // - Linux has configurable font hinting, but most distributions including Ubuntu default to "Light".
  104. #ifdef MACOS_ENABLED
  105. font_hinting = TextServer::HINTING_NONE;
  106. font_mono_hinting = TextServer::HINTING_NONE;
  107. #else
  108. font_hinting = TextServer::HINTING_LIGHT;
  109. font_mono_hinting = TextServer::HINTING_LIGHT;
  110. #endif
  111. break;
  112. case 1:
  113. font_hinting = TextServer::HINTING_NONE;
  114. font_mono_hinting = TextServer::HINTING_NONE;
  115. break;
  116. case 2:
  117. font_hinting = TextServer::HINTING_LIGHT;
  118. font_mono_hinting = TextServer::HINTING_LIGHT;
  119. break;
  120. default:
  121. font_hinting = TextServer::HINTING_NORMAL;
  122. font_mono_hinting = TextServer::HINTING_LIGHT;
  123. break;
  124. }
  125. // Load built-in fonts.
  126. const int default_font_size = int(EDITOR_GET("interface/editor/main_font_size")) * EDSCALE;
  127. const float embolden_strength = 0.6;
  128. Ref<Font> default_font = load_internal_font(_font_NotoSans_Regular, _font_NotoSans_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false);
  129. Ref<Font> default_font_msdf = load_internal_font(_font_NotoSans_Regular, _font_NotoSans_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, true);
  130. TypedArray<Font> fallbacks;
  131. Ref<FontFile> arabic_font = load_internal_font(_font_NotoNaskhArabicUI_Regular, _font_NotoNaskhArabicUI_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks);
  132. Ref<FontFile> bengali_font = load_internal_font(_font_NotoSansBengaliUI_Regular, _font_NotoSansBengaliUI_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks);
  133. Ref<FontFile> devanagari_font = load_internal_font(_font_NotoSansDevanagariUI_Regular, _font_NotoSansDevanagariUI_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks);
  134. Ref<FontFile> georgian_font = load_internal_font(_font_NotoSansGeorgian_Regular, _font_NotoSansGeorgian_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks);
  135. Ref<FontFile> hebrew_font = load_internal_font(_font_NotoSansHebrew_Regular, _font_NotoSansHebrew_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks);
  136. Ref<FontFile> malayalam_font = load_internal_font(_font_NotoSansMalayalamUI_Regular, _font_NotoSansMalayalamUI_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks);
  137. Ref<FontFile> oriya_font = load_internal_font(_font_NotoSansOriya_Regular, _font_NotoSansOriya_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks);
  138. Ref<FontFile> sinhala_font = load_internal_font(_font_NotoSansSinhalaUI_Regular, _font_NotoSansSinhalaUI_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks);
  139. Ref<FontFile> tamil_font = load_internal_font(_font_NotoSansTamilUI_Regular, _font_NotoSansTamilUI_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks);
  140. Ref<FontFile> telugu_font = load_internal_font(_font_NotoSansTeluguUI_Regular, _font_NotoSansTeluguUI_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks);
  141. Ref<FontFile> thai_font = load_internal_font(_font_NotoSansThai_Regular, _font_NotoSansThai_Regular_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks);
  142. Ref<FontFile> fallback_font = load_internal_font(_font_DroidSansFallback, _font_DroidSansFallback_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks);
  143. Ref<FontFile> japanese_font = load_internal_font(_font_DroidSansJapanese, _font_DroidSansJapanese_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks);
  144. default_font->set_fallbacks(fallbacks);
  145. default_font_msdf->set_fallbacks(fallbacks);
  146. Ref<FontFile> default_font_bold = load_internal_font(_font_NotoSans_Bold, _font_NotoSans_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false);
  147. Ref<FontFile> default_font_bold_msdf = load_internal_font(_font_NotoSans_Bold, _font_NotoSans_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, true);
  148. TypedArray<Font> fallbacks_bold;
  149. Ref<FontFile> arabic_font_bold = load_internal_font(_font_NotoNaskhArabicUI_Bold, _font_NotoNaskhArabicUI_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks_bold);
  150. Ref<FontFile> bengali_font_bold = load_internal_font(_font_NotoSansBengaliUI_Bold, _font_NotoSansBengaliUI_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks_bold);
  151. Ref<FontFile> devanagari_font_bold = load_internal_font(_font_NotoSansDevanagariUI_Bold, _font_NotoSansDevanagariUI_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks_bold);
  152. Ref<FontFile> georgian_font_bold = load_internal_font(_font_NotoSansGeorgian_Bold, _font_NotoSansGeorgian_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks_bold);
  153. Ref<FontFile> hebrew_font_bold = load_internal_font(_font_NotoSansHebrew_Bold, _font_NotoSansHebrew_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks_bold);
  154. Ref<FontFile> malayalam_font_bold = load_internal_font(_font_NotoSansMalayalamUI_Bold, _font_NotoSansMalayalamUI_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks_bold);
  155. Ref<FontFile> oriya_font_bold = load_internal_font(_font_NotoSansOriya_Bold, _font_NotoSansOriya_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks_bold);
  156. Ref<FontFile> sinhala_font_bold = load_internal_font(_font_NotoSansSinhalaUI_Bold, _font_NotoSansSinhalaUI_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks_bold);
  157. Ref<FontFile> tamil_font_bold = load_internal_font(_font_NotoSansTamilUI_Bold, _font_NotoSansTamilUI_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks_bold);
  158. Ref<FontFile> telugu_font_bold = load_internal_font(_font_NotoSansTeluguUI_Bold, _font_NotoSansTeluguUI_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks_bold);
  159. Ref<FontFile> thai_font_bold = load_internal_font(_font_NotoSansThai_Bold, _font_NotoSansThai_Bold_size, font_hinting, font_antialiasing, true, font_subpixel_positioning, false, &fallbacks_bold);
  160. Ref<FontVariation> fallback_font_bold = make_bold_font(fallback_font, embolden_strength, &fallbacks_bold);
  161. Ref<FontVariation> japanese_font_bold = make_bold_font(japanese_font, embolden_strength, &fallbacks_bold);
  162. if (OS::get_singleton()->has_feature("system_fonts")) {
  163. PackedStringArray emoji_font_names;
  164. emoji_font_names.push_back("Apple Color Emoji");
  165. emoji_font_names.push_back("Segoe UI Emoji");
  166. emoji_font_names.push_back("Noto Color Emoji");
  167. emoji_font_names.push_back("Twitter Color Emoji");
  168. emoji_font_names.push_back("OpenMoji");
  169. emoji_font_names.push_back("EmojiOne Color");
  170. Ref<SystemFont> emoji_font = load_system_font(emoji_font_names, font_hinting, font_antialiasing, true, font_subpixel_positioning, false);
  171. fallbacks.push_back(emoji_font);
  172. fallbacks_bold.push_back(emoji_font);
  173. }
  174. default_font_bold->set_fallbacks(fallbacks_bold);
  175. default_font_bold_msdf->set_fallbacks(fallbacks_bold);
  176. Ref<FontFile> default_font_mono = load_internal_font(_font_JetBrainsMono_Regular, _font_JetBrainsMono_Regular_size, font_mono_hinting, font_antialiasing, true, font_subpixel_positioning);
  177. default_font_mono->set_fallbacks(fallbacks);
  178. // Init base font configs and load custom fonts.
  179. String custom_font_path = EDITOR_GET("interface/editor/main_font");
  180. String custom_font_path_bold = EDITOR_GET("interface/editor/main_font_bold");
  181. String custom_font_path_source = EDITOR_GET("interface/editor/code_font");
  182. Ref<FontVariation> default_fc;
  183. default_fc.instantiate();
  184. if (custom_font_path.length() > 0 && dir->file_exists(custom_font_path)) {
  185. Ref<FontFile> custom_font = load_external_font(custom_font_path, font_hinting, font_antialiasing, true, font_subpixel_positioning);
  186. {
  187. TypedArray<Font> fallback_custom;
  188. fallback_custom.push_back(default_font);
  189. custom_font->set_fallbacks(fallback_custom);
  190. }
  191. default_fc->set_base_font(custom_font);
  192. } else {
  193. EditorSettings::get_singleton()->set_manually("interface/editor/main_font", "");
  194. default_fc->set_base_font(default_font);
  195. }
  196. default_fc->set_spacing(TextServer::SPACING_TOP, -EDSCALE);
  197. default_fc->set_spacing(TextServer::SPACING_BOTTOM, -EDSCALE);
  198. Ref<FontVariation> default_fc_msdf;
  199. default_fc_msdf.instantiate();
  200. if (custom_font_path.length() > 0 && dir->file_exists(custom_font_path)) {
  201. Ref<FontFile> custom_font = load_external_font(custom_font_path, font_hinting, font_antialiasing, true, font_subpixel_positioning);
  202. {
  203. TypedArray<Font> fallback_custom;
  204. fallback_custom.push_back(default_font_msdf);
  205. custom_font->set_fallbacks(fallback_custom);
  206. }
  207. default_fc_msdf->set_base_font(custom_font);
  208. } else {
  209. EditorSettings::get_singleton()->set_manually("interface/editor/main_font", "");
  210. default_fc_msdf->set_base_font(default_font_msdf);
  211. }
  212. default_fc_msdf->set_spacing(TextServer::SPACING_TOP, -EDSCALE);
  213. default_fc_msdf->set_spacing(TextServer::SPACING_BOTTOM, -EDSCALE);
  214. Ref<FontVariation> bold_fc;
  215. bold_fc.instantiate();
  216. if (custom_font_path_bold.length() > 0 && dir->file_exists(custom_font_path_bold)) {
  217. Ref<FontFile> custom_font = load_external_font(custom_font_path_bold, font_hinting, font_antialiasing, true, font_subpixel_positioning);
  218. {
  219. TypedArray<Font> fallback_custom;
  220. fallback_custom.push_back(default_font_bold);
  221. custom_font->set_fallbacks(fallback_custom);
  222. }
  223. bold_fc->set_base_font(custom_font);
  224. } else if (custom_font_path.length() > 0 && dir->file_exists(custom_font_path)) {
  225. Ref<FontFile> custom_font = load_external_font(custom_font_path, font_hinting, font_antialiasing, true, font_subpixel_positioning);
  226. {
  227. TypedArray<Font> fallback_custom;
  228. fallback_custom.push_back(default_font_bold);
  229. custom_font->set_fallbacks(fallback_custom);
  230. }
  231. bold_fc->set_base_font(custom_font);
  232. bold_fc->set_variation_embolden(embolden_strength);
  233. } else {
  234. EditorSettings::get_singleton()->set_manually("interface/editor/main_font_bold", "");
  235. bold_fc->set_base_font(default_font_bold);
  236. }
  237. bold_fc->set_spacing(TextServer::SPACING_TOP, -EDSCALE);
  238. bold_fc->set_spacing(TextServer::SPACING_BOTTOM, -EDSCALE);
  239. Ref<FontVariation> bold_fc_msdf;
  240. bold_fc_msdf.instantiate();
  241. if (custom_font_path_bold.length() > 0 && dir->file_exists(custom_font_path_bold)) {
  242. Ref<FontFile> custom_font = load_external_font(custom_font_path_bold, font_hinting, font_antialiasing, true, font_subpixel_positioning);
  243. {
  244. TypedArray<Font> fallback_custom;
  245. fallback_custom.push_back(default_font_bold_msdf);
  246. custom_font->set_fallbacks(fallback_custom);
  247. }
  248. bold_fc_msdf->set_base_font(custom_font);
  249. } else if (custom_font_path.length() > 0 && dir->file_exists(custom_font_path)) {
  250. Ref<FontFile> custom_font = load_external_font(custom_font_path, font_hinting, font_antialiasing, true, font_subpixel_positioning);
  251. {
  252. TypedArray<Font> fallback_custom;
  253. fallback_custom.push_back(default_font_bold_msdf);
  254. custom_font->set_fallbacks(fallback_custom);
  255. }
  256. bold_fc_msdf->set_base_font(custom_font);
  257. bold_fc_msdf->set_variation_embolden(embolden_strength);
  258. } else {
  259. EditorSettings::get_singleton()->set_manually("interface/editor/main_font_bold", "");
  260. bold_fc_msdf->set_base_font(default_font_bold_msdf);
  261. }
  262. bold_fc_msdf->set_spacing(TextServer::SPACING_TOP, -EDSCALE);
  263. bold_fc_msdf->set_spacing(TextServer::SPACING_BOTTOM, -EDSCALE);
  264. Ref<FontVariation> mono_fc;
  265. mono_fc.instantiate();
  266. if (custom_font_path_source.length() > 0 && dir->file_exists(custom_font_path_source)) {
  267. Ref<FontFile> custom_font = load_external_font(custom_font_path_source, font_mono_hinting, font_antialiasing, true, font_subpixel_positioning);
  268. {
  269. TypedArray<Font> fallback_custom;
  270. fallback_custom.push_back(default_font_mono);
  271. custom_font->set_fallbacks(fallback_custom);
  272. }
  273. mono_fc->set_base_font(custom_font);
  274. } else {
  275. EditorSettings::get_singleton()->set_manually("interface/editor/code_font", "");
  276. mono_fc->set_base_font(default_font_mono);
  277. }
  278. mono_fc->set_spacing(TextServer::SPACING_TOP, -EDSCALE);
  279. mono_fc->set_spacing(TextServer::SPACING_BOTTOM, -EDSCALE);
  280. Ref<FontVariation> mono_other_fc = mono_fc->duplicate();
  281. // Enable contextual alternates (coding ligatures) and custom features for the source editor font.
  282. int ot_mode = EDITOR_GET("interface/editor/code_font_contextual_ligatures");
  283. switch (ot_mode) {
  284. case 1: { // Disable ligatures.
  285. Dictionary ftrs;
  286. ftrs[TS->name_to_tag("calt")] = 0;
  287. mono_fc->set_opentype_features(ftrs);
  288. } break;
  289. case 2: { // Custom.
  290. Vector<String> subtag = String(EDITOR_GET("interface/editor/code_font_custom_opentype_features")).split(",");
  291. Dictionary ftrs;
  292. for (int i = 0; i < subtag.size(); i++) {
  293. Vector<String> subtag_a = subtag[i].split("=");
  294. if (subtag_a.size() == 2) {
  295. ftrs[TS->name_to_tag(subtag_a[0])] = subtag_a[1].to_int();
  296. } else if (subtag_a.size() == 1) {
  297. ftrs[TS->name_to_tag(subtag_a[0])] = 1;
  298. }
  299. }
  300. mono_fc->set_opentype_features(ftrs);
  301. } break;
  302. default: { // Enabled.
  303. Dictionary ftrs;
  304. ftrs[TS->name_to_tag("calt")] = 1;
  305. mono_fc->set_opentype_features(ftrs);
  306. } break;
  307. }
  308. {
  309. // Disable contextual alternates (coding ligatures).
  310. Dictionary ftrs;
  311. ftrs[TS->name_to_tag("calt")] = 0;
  312. mono_other_fc->set_opentype_features(ftrs);
  313. }
  314. // Use fake bold/italics to style the editor log's `print_rich()` output.
  315. // Use stronger embolden strength to make bold easier to distinguish from regular text.
  316. Ref<FontVariation> mono_other_fc_bold = mono_other_fc->duplicate();
  317. mono_other_fc_bold->set_variation_embolden(0.8);
  318. Ref<FontVariation> mono_other_fc_italic = mono_other_fc->duplicate();
  319. mono_other_fc_italic->set_variation_transform(Transform2D(1.0, 0.2, 0.0, 1.0, 0.0, 0.0));
  320. Ref<FontVariation> mono_other_fc_bold_italic = mono_other_fc->duplicate();
  321. mono_other_fc_bold_italic->set_variation_embolden(0.8);
  322. mono_other_fc_bold_italic->set_variation_transform(Transform2D(1.0, 0.2, 0.0, 1.0, 0.0, 0.0));
  323. Ref<FontVariation> mono_other_fc_mono = mono_other_fc->duplicate();
  324. // Use a different font style to distinguish `[code]` in rich prints.
  325. // This emulates the "faint" styling used in ANSI escape codes by using a slightly thinner font.
  326. mono_other_fc_mono->set_variation_embolden(-0.25);
  327. mono_other_fc_mono->set_variation_transform(Transform2D(1.0, 0.1, 0.0, 1.0, 0.0, 0.0));
  328. Ref<FontVariation> italic_fc = default_fc->duplicate();
  329. italic_fc->set_variation_transform(Transform2D(1.0, 0.2, 0.0, 1.0, 0.0, 0.0));
  330. // Setup theme.
  331. p_theme->set_default_font(default_fc); // Default theme font config.
  332. p_theme->set_default_font_size(default_font_size);
  333. // Main font.
  334. p_theme->set_font("main", EditorStringName(EditorFonts), default_fc);
  335. p_theme->set_font("main_msdf", EditorStringName(EditorFonts), default_fc_msdf);
  336. p_theme->set_font_size("main_size", EditorStringName(EditorFonts), default_font_size);
  337. p_theme->set_font("bold", EditorStringName(EditorFonts), bold_fc);
  338. p_theme->set_font("main_bold_msdf", EditorStringName(EditorFonts), bold_fc_msdf);
  339. p_theme->set_font_size("bold_size", EditorStringName(EditorFonts), default_font_size);
  340. // Title font.
  341. p_theme->set_font("title", EditorStringName(EditorFonts), bold_fc);
  342. p_theme->set_font_size("title_size", EditorStringName(EditorFonts), default_font_size + 1 * EDSCALE);
  343. p_theme->set_font("main_button_font", EditorStringName(EditorFonts), bold_fc);
  344. p_theme->set_font_size("main_button_font_size", EditorStringName(EditorFonts), default_font_size + 1 * EDSCALE);
  345. p_theme->set_font("font", "Label", default_fc);
  346. p_theme->set_type_variation("HeaderSmall", "Label");
  347. p_theme->set_font("font", "HeaderSmall", bold_fc);
  348. p_theme->set_font_size("font_size", "HeaderSmall", default_font_size);
  349. p_theme->set_type_variation("HeaderMedium", "Label");
  350. p_theme->set_font("font", "HeaderMedium", bold_fc);
  351. p_theme->set_font_size("font_size", "HeaderMedium", default_font_size + 1 * EDSCALE);
  352. p_theme->set_type_variation("HeaderLarge", "Label");
  353. p_theme->set_font("font", "HeaderLarge", bold_fc);
  354. p_theme->set_font_size("font_size", "HeaderLarge", default_font_size + 3 * EDSCALE);
  355. // Documentation fonts
  356. p_theme->set_font_size("doc_size", EditorStringName(EditorFonts), int(EDITOR_GET("text_editor/help/help_font_size")) * EDSCALE);
  357. p_theme->set_font("doc", EditorStringName(EditorFonts), default_fc);
  358. p_theme->set_font("doc_bold", EditorStringName(EditorFonts), bold_fc);
  359. p_theme->set_font("doc_italic", EditorStringName(EditorFonts), italic_fc);
  360. p_theme->set_font_size("doc_title_size", EditorStringName(EditorFonts), int(EDITOR_GET("text_editor/help/help_title_font_size")) * EDSCALE);
  361. p_theme->set_font("doc_title", EditorStringName(EditorFonts), bold_fc);
  362. p_theme->set_font_size("doc_source_size", EditorStringName(EditorFonts), int(EDITOR_GET("text_editor/help/help_source_font_size")) * EDSCALE);
  363. p_theme->set_font("doc_source", EditorStringName(EditorFonts), mono_fc);
  364. p_theme->set_font_size("doc_keyboard_size", EditorStringName(EditorFonts), (int(EDITOR_GET("text_editor/help/help_source_font_size")) - 1) * EDSCALE);
  365. p_theme->set_font("doc_keyboard", EditorStringName(EditorFonts), mono_fc);
  366. // Ruler font
  367. p_theme->set_font_size("rulers_size", EditorStringName(EditorFonts), 8 * EDSCALE);
  368. p_theme->set_font("rulers", EditorStringName(EditorFonts), default_fc);
  369. // Rotation widget font
  370. p_theme->set_font_size("rotation_control_size", EditorStringName(EditorFonts), 14 * EDSCALE);
  371. p_theme->set_font("rotation_control", EditorStringName(EditorFonts), default_fc);
  372. // Code font
  373. p_theme->set_font_size("source_size", EditorStringName(EditorFonts), int(EDITOR_GET("interface/editor/code_font_size")) * EDSCALE);
  374. p_theme->set_font("source", EditorStringName(EditorFonts), mono_fc);
  375. p_theme->set_font_size("expression_size", EditorStringName(EditorFonts), (int(EDITOR_GET("interface/editor/code_font_size")) - 1) * EDSCALE);
  376. p_theme->set_font("expression", EditorStringName(EditorFonts), mono_other_fc);
  377. p_theme->set_font_size("output_source_size", EditorStringName(EditorFonts), int(EDITOR_GET("run/output/font_size")) * EDSCALE);
  378. p_theme->set_font("output_source", EditorStringName(EditorFonts), mono_other_fc);
  379. p_theme->set_font("output_source_bold", EditorStringName(EditorFonts), mono_other_fc_bold);
  380. p_theme->set_font("output_source_italic", EditorStringName(EditorFonts), mono_other_fc_italic);
  381. p_theme->set_font("output_source_bold_italic", EditorStringName(EditorFonts), mono_other_fc_bold_italic);
  382. p_theme->set_font("output_source_mono", EditorStringName(EditorFonts), mono_other_fc_mono);
  383. p_theme->set_font_size("status_source_size", EditorStringName(EditorFonts), default_font_size);
  384. p_theme->set_font("status_source", EditorStringName(EditorFonts), mono_other_fc);
  385. OS::get_singleton()->benchmark_end_measure("editor_register_fonts");
  386. }