dynamic_font_import_settings.cpp 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543
  1. /**************************************************************************/
  2. /* dynamic_font_import_settings.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 "dynamic_font_import_settings.h"
  31. #include "core/config/project_settings.h"
  32. #include "editor/editor_file_system.h"
  33. #include "editor/editor_inspector.h"
  34. #include "editor/editor_locale_dialog.h"
  35. #include "editor/editor_node.h"
  36. #include "editor/editor_property_name_processor.h"
  37. #include "editor/editor_scale.h"
  38. #include "editor/editor_settings.h"
  39. #include "editor/editor_string_names.h"
  40. #include "editor/gui/editor_file_dialog.h"
  41. /*************************************************************************/
  42. /* Settings data */
  43. /*************************************************************************/
  44. bool DynamicFontImportSettingsData::_set(const StringName &p_name, const Variant &p_value) {
  45. if (defaults.has(p_name) && defaults[p_name] == p_value) {
  46. settings.erase(p_name);
  47. } else {
  48. settings[p_name] = p_value;
  49. }
  50. return true;
  51. }
  52. bool DynamicFontImportSettingsData::_get(const StringName &p_name, Variant &r_ret) const {
  53. if (settings.has(p_name)) {
  54. r_ret = settings[p_name];
  55. return true;
  56. }
  57. if (defaults.has(p_name)) {
  58. r_ret = defaults[p_name];
  59. return true;
  60. }
  61. return false;
  62. }
  63. void DynamicFontImportSettingsData::_get_property_list(List<PropertyInfo> *p_list) const {
  64. for (const List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) {
  65. if (owner && owner->import_settings_data.is_valid()) {
  66. if (owner->import_settings_data->get("multichannel_signed_distance_field") && (E->get().option.name == "size" || E->get().option.name == "outline_size" || E->get().option.name == "oversampling")) {
  67. continue;
  68. }
  69. if (!owner->import_settings_data->get("multichannel_signed_distance_field") && (E->get().option.name == "msdf_pixel_range" || E->get().option.name == "msdf_size")) {
  70. continue;
  71. }
  72. }
  73. p_list->push_back(E->get().option);
  74. }
  75. }
  76. Ref<FontFile> DynamicFontImportSettingsData::get_font() const {
  77. return fd;
  78. }
  79. /*************************************************************************/
  80. /* Glyph ranges */
  81. /*************************************************************************/
  82. struct UniRange {
  83. int32_t start;
  84. int32_t end;
  85. String name;
  86. };
  87. // Unicode Character Blocks
  88. // Source: https://www.unicode.org/Public/14.0.0/ucd/Blocks.txt
  89. static UniRange unicode_ranges[] = {
  90. { 0x0000, 0x007F, U"Basic Latin" },
  91. { 0x0080, 0x00FF, U"Latin-1 Supplement" },
  92. { 0x0100, 0x017F, U"Latin Extended-A" },
  93. { 0x0180, 0x024F, U"Latin Extended-B" },
  94. { 0x0250, 0x02AF, U"IPA Extensions" },
  95. { 0x02B0, 0x02FF, U"Spacing Modifier Letters" },
  96. { 0x0300, 0x036F, U"Combining Diacritical Marks" },
  97. { 0x0370, 0x03FF, U"Greek and Coptic" },
  98. { 0x0400, 0x04FF, U"Cyrillic" },
  99. { 0x0500, 0x052F, U"Cyrillic Supplement" },
  100. { 0x0530, 0x058F, U"Armenian" },
  101. { 0x0590, 0x05FF, U"Hebrew" },
  102. { 0x0600, 0x06FF, U"Arabic" },
  103. { 0x0700, 0x074F, U"Syriac" },
  104. { 0x0750, 0x077F, U"Arabic Supplement" },
  105. { 0x0780, 0x07BF, U"Thaana" },
  106. { 0x07C0, 0x07FF, U"NKo" },
  107. { 0x0800, 0x083F, U"Samaritan" },
  108. { 0x0840, 0x085F, U"Mandaic" },
  109. { 0x0860, 0x086F, U"Syriac Supplement" },
  110. { 0x0870, 0x089F, U"Arabic Extended-B" },
  111. { 0x08A0, 0x08FF, U"Arabic Extended-A" },
  112. { 0x0900, 0x097F, U"Devanagari" },
  113. { 0x0980, 0x09FF, U"Bengali" },
  114. { 0x0A00, 0x0A7F, U"Gurmukhi" },
  115. { 0x0A80, 0x0AFF, U"Gujarati" },
  116. { 0x0B00, 0x0B7F, U"Oriya" },
  117. { 0x0B80, 0x0BFF, U"Tamil" },
  118. { 0x0C00, 0x0C7F, U"Telugu" },
  119. { 0x0C80, 0x0CFF, U"Kannada" },
  120. { 0x0D00, 0x0D7F, U"Malayalam" },
  121. { 0x0D80, 0x0DFF, U"Sinhala" },
  122. { 0x0E00, 0x0E7F, U"Thai" },
  123. { 0x0E80, 0x0EFF, U"Lao" },
  124. { 0x0F00, 0x0FFF, U"Tibetan" },
  125. { 0x1000, 0x109F, U"Myanmar" },
  126. { 0x10A0, 0x10FF, U"Georgian" },
  127. { 0x1100, 0x11FF, U"Hangul Jamo" },
  128. { 0x1200, 0x137F, U"Ethiopic" },
  129. { 0x1380, 0x139F, U"Ethiopic Supplement" },
  130. { 0x13A0, 0x13FF, U"Cherokee" },
  131. { 0x1400, 0x167F, U"Unified Canadian Aboriginal Syllabics" },
  132. { 0x1680, 0x169F, U"Ogham" },
  133. { 0x16A0, 0x16FF, U"Runic" },
  134. { 0x1700, 0x171F, U"Tagalog" },
  135. { 0x1720, 0x173F, U"Hanunoo" },
  136. { 0x1740, 0x175F, U"Buhid" },
  137. { 0x1760, 0x177F, U"Tagbanwa" },
  138. { 0x1780, 0x17FF, U"Khmer" },
  139. { 0x1800, 0x18AF, U"Mongolian" },
  140. { 0x18B0, 0x18FF, U"Unified Canadian Aboriginal Syllabics Extended" },
  141. { 0x1900, 0x194F, U"Limbu" },
  142. { 0x1950, 0x197F, U"Tai Le" },
  143. { 0x1980, 0x19DF, U"New Tai Lue" },
  144. { 0x19E0, 0x19FF, U"Khmer Symbols" },
  145. { 0x1A00, 0x1A1F, U"Buginese" },
  146. { 0x1A20, 0x1AAF, U"Tai Tham" },
  147. { 0x1AB0, 0x1AFF, U"Combining Diacritical Marks Extended" },
  148. { 0x1B00, 0x1B7F, U"Balinese" },
  149. { 0x1B80, 0x1BBF, U"Sundanese" },
  150. { 0x1BC0, 0x1BFF, U"Batak" },
  151. { 0x1C00, 0x1C4F, U"Lepcha" },
  152. { 0x1C50, 0x1C7F, U"Ol Chiki" },
  153. { 0x1C80, 0x1C8F, U"Cyrillic Extended-C" },
  154. { 0x1C90, 0x1CBF, U"Georgian Extended" },
  155. { 0x1CC0, 0x1CCF, U"Sundanese Supplement" },
  156. { 0x1CD0, 0x1CFF, U"Vedic Extensions" },
  157. { 0x1D00, 0x1D7F, U"Phonetic Extensions" },
  158. { 0x1D80, 0x1DBF, U"Phonetic Extensions Supplement" },
  159. { 0x1DC0, 0x1DFF, U"Combining Diacritical Marks Supplement" },
  160. { 0x1E00, 0x1EFF, U"Latin Extended Additional" },
  161. { 0x1F00, 0x1FFF, U"Greek Extended" },
  162. { 0x2000, 0x206F, U"General Punctuation" },
  163. { 0x2070, 0x209F, U"Superscripts and Subscripts" },
  164. { 0x20A0, 0x20CF, U"Currency Symbols" },
  165. { 0x20D0, 0x20FF, U"Combining Diacritical Marks for Symbols" },
  166. { 0x2100, 0x214F, U"Letterlike Symbols" },
  167. { 0x2150, 0x218F, U"Number Forms" },
  168. { 0x2190, 0x21FF, U"Arrows" },
  169. { 0x2200, 0x22FF, U"Mathematical Operators" },
  170. { 0x2300, 0x23FF, U"Miscellaneous Technical" },
  171. { 0x2400, 0x243F, U"Control Pictures" },
  172. { 0x2440, 0x245F, U"Optical Character Recognition" },
  173. { 0x2460, 0x24FF, U"Enclosed Alphanumerics" },
  174. { 0x2500, 0x257F, U"Box Drawing" },
  175. { 0x2580, 0x259F, U"Block Elements" },
  176. { 0x25A0, 0x25FF, U"Geometric Shapes" },
  177. { 0x2600, 0x26FF, U"Miscellaneous Symbols" },
  178. { 0x2700, 0x27BF, U"Dingbats" },
  179. { 0x27C0, 0x27EF, U"Miscellaneous Mathematical Symbols-A" },
  180. { 0x27F0, 0x27FF, U"Supplemental Arrows-A" },
  181. { 0x2800, 0x28FF, U"Braille Patterns" },
  182. { 0x2900, 0x297F, U"Supplemental Arrows-B" },
  183. { 0x2980, 0x29FF, U"Miscellaneous Mathematical Symbols-B" },
  184. { 0x2A00, 0x2AFF, U"Supplemental Mathematical Operators" },
  185. { 0x2B00, 0x2BFF, U"Miscellaneous Symbols and Arrows" },
  186. { 0x2C00, 0x2C5F, U"Glagolitic" },
  187. { 0x2C60, 0x2C7F, U"Latin Extended-C" },
  188. { 0x2C80, 0x2CFF, U"Coptic" },
  189. { 0x2D00, 0x2D2F, U"Georgian Supplement" },
  190. { 0x2D30, 0x2D7F, U"Tifinagh" },
  191. { 0x2D80, 0x2DDF, U"Ethiopic Extended" },
  192. { 0x2DE0, 0x2DFF, U"Cyrillic Extended-A" },
  193. { 0x2E00, 0x2E7F, U"Supplemental Punctuation" },
  194. { 0x2E80, 0x2EFF, U"CJK Radicals Supplement" },
  195. { 0x2F00, 0x2FDF, U"Kangxi Radicals" },
  196. { 0x2FF0, 0x2FFF, U"Ideographic Description Characters" },
  197. { 0x3000, 0x303F, U"CJK Symbols and Punctuation" },
  198. { 0x3040, 0x309F, U"Hiragana" },
  199. { 0x30A0, 0x30FF, U"Katakana" },
  200. { 0x3100, 0x312F, U"Bopomofo" },
  201. { 0x3130, 0x318F, U"Hangul Compatibility Jamo" },
  202. { 0x3190, 0x319F, U"Kanbun" },
  203. { 0x31A0, 0x31BF, U"Bopomofo Extended" },
  204. { 0x31C0, 0x31EF, U"CJK Strokes" },
  205. { 0x31F0, 0x31FF, U"Katakana Phonetic Extensions" },
  206. { 0x3200, 0x32FF, U"Enclosed CJK Letters and Months" },
  207. { 0x3300, 0x33FF, U"CJK Compatibility" },
  208. { 0x3400, 0x4DBF, U"CJK Unified Ideographs Extension A" },
  209. { 0x4DC0, 0x4DFF, U"Yijing Hexagram Symbols" },
  210. { 0x4E00, 0x9FFF, U"CJK Unified Ideographs" },
  211. { 0xA000, 0xA48F, U"Yi Syllables" },
  212. { 0xA490, 0xA4CF, U"Yi Radicals" },
  213. { 0xA4D0, 0xA4FF, U"Lisu" },
  214. { 0xA500, 0xA63F, U"Vai" },
  215. { 0xA640, 0xA69F, U"Cyrillic Extended-B" },
  216. { 0xA6A0, 0xA6FF, U"Bamum" },
  217. { 0xA700, 0xA71F, U"Modifier Tone Letters" },
  218. { 0xA720, 0xA7FF, U"Latin Extended-D" },
  219. { 0xA800, 0xA82F, U"Syloti Nagri" },
  220. { 0xA830, 0xA83F, U"Common Indic Number Forms" },
  221. { 0xA840, 0xA87F, U"Phags-pa" },
  222. { 0xA880, 0xA8DF, U"Saurashtra" },
  223. { 0xA8E0, 0xA8FF, U"Devanagari Extended" },
  224. { 0xA900, 0xA92F, U"Kayah Li" },
  225. { 0xA930, 0xA95F, U"Rejang" },
  226. { 0xA960, 0xA97F, U"Hangul Jamo Extended-A" },
  227. { 0xA980, 0xA9DF, U"Javanese" },
  228. { 0xA9E0, 0xA9FF, U"Myanmar Extended-B" },
  229. { 0xAA00, 0xAA5F, U"Cham" },
  230. { 0xAA60, 0xAA7F, U"Myanmar Extended-A" },
  231. { 0xAA80, 0xAADF, U"Tai Viet" },
  232. { 0xAAE0, 0xAAFF, U"Meetei Mayek Extensions" },
  233. { 0xAB00, 0xAB2F, U"Ethiopic Extended-A" },
  234. { 0xAB30, 0xAB6F, U"Latin Extended-E" },
  235. { 0xAB70, 0xABBF, U"Cherokee Supplement" },
  236. { 0xABC0, 0xABFF, U"Meetei Mayek" },
  237. { 0xAC00, 0xD7AF, U"Hangul Syllables" },
  238. { 0xD7B0, 0xD7FF, U"Hangul Jamo Extended-B" },
  239. //{ 0xD800, 0xDB7F, U"High Surrogates" },
  240. //{ 0xDB80, 0xDBFF, U"High Private Use Surrogates" },
  241. //{ 0xDC00, 0xDFFF, U"Low Surrogates" },
  242. { 0xE000, 0xF8FF, U"Private Use Area" },
  243. { 0xF900, 0xFAFF, U"CJK Compatibility Ideographs" },
  244. { 0xFB00, 0xFB4F, U"Alphabetic Presentation Forms" },
  245. { 0xFB50, 0xFDFF, U"Arabic Presentation Forms-A" },
  246. //{ 0xFE00, 0xFE0F, U"Variation Selectors" },
  247. { 0xFE10, 0xFE1F, U"Vertical Forms" },
  248. { 0xFE20, 0xFE2F, U"Combining Half Marks" },
  249. { 0xFE30, 0xFE4F, U"CJK Compatibility Forms" },
  250. { 0xFE50, 0xFE6F, U"Small Form Variants" },
  251. { 0xFE70, 0xFEFF, U"Arabic Presentation Forms-B" },
  252. { 0xFF00, 0xFFEF, U"Halfwidth and Fullwidth Forms" },
  253. //{ 0xFFF0, 0xFFFF, U"Specials" },
  254. { 0x10000, 0x1007F, U"Linear B Syllabary" },
  255. { 0x10080, 0x100FF, U"Linear B Ideograms" },
  256. { 0x10100, 0x1013F, U"Aegean Numbers" },
  257. { 0x10140, 0x1018F, U"Ancient Greek Numbers" },
  258. { 0x10190, 0x101CF, U"Ancient Symbols" },
  259. { 0x101D0, 0x101FF, U"Phaistos Disc" },
  260. { 0x10280, 0x1029F, U"Lycian" },
  261. { 0x102A0, 0x102DF, U"Carian" },
  262. { 0x102E0, 0x102FF, U"Coptic Epact Numbers" },
  263. { 0x10300, 0x1032F, U"Old Italic" },
  264. { 0x10330, 0x1034F, U"Gothic" },
  265. { 0x10350, 0x1037F, U"Old Permic" },
  266. { 0x10380, 0x1039F, U"Ugaritic" },
  267. { 0x103A0, 0x103DF, U"Old Persian" },
  268. { 0x10400, 0x1044F, U"Deseret" },
  269. { 0x10450, 0x1047F, U"Shavian" },
  270. { 0x10480, 0x104AF, U"Osmanya" },
  271. { 0x104B0, 0x104FF, U"Osage" },
  272. { 0x10500, 0x1052F, U"Elbasan" },
  273. { 0x10530, 0x1056F, U"Caucasian Albanian" },
  274. { 0x10570, 0x105BF, U"Vithkuqi" },
  275. { 0x10600, 0x1077F, U"Linear A" },
  276. { 0x10780, 0x107BF, U"Latin Extended-F" },
  277. { 0x10800, 0x1083F, U"Cypriot Syllabary" },
  278. { 0x10840, 0x1085F, U"Imperial Aramaic" },
  279. { 0x10860, 0x1087F, U"Palmyrene" },
  280. { 0x10880, 0x108AF, U"Nabataean" },
  281. { 0x108E0, 0x108FF, U"Hatran" },
  282. { 0x10900, 0x1091F, U"Phoenician" },
  283. { 0x10920, 0x1093F, U"Lydian" },
  284. { 0x10980, 0x1099F, U"Meroitic Hieroglyphs" },
  285. { 0x109A0, 0x109FF, U"Meroitic Cursive" },
  286. { 0x10A00, 0x10A5F, U"Kharoshthi" },
  287. { 0x10A60, 0x10A7F, U"Old South Arabian" },
  288. { 0x10A80, 0x10A9F, U"Old North Arabian" },
  289. { 0x10AC0, 0x10AFF, U"Manichaean" },
  290. { 0x10B00, 0x10B3F, U"Avestan" },
  291. { 0x10B40, 0x10B5F, U"Inscriptional Parthian" },
  292. { 0x10B60, 0x10B7F, U"Inscriptional Pahlavi" },
  293. { 0x10B80, 0x10BAF, U"Psalter Pahlavi" },
  294. { 0x10C00, 0x10C4F, U"Old Turkic" },
  295. { 0x10C80, 0x10CFF, U"Old Hungarian" },
  296. { 0x10D00, 0x10D3F, U"Hanifi Rohingya" },
  297. { 0x10E60, 0x10E7F, U"Rumi Numeral Symbols" },
  298. { 0x10E80, 0x10EBF, U"Yezidi" },
  299. { 0x10EC0, 0x10EFF, U"Arabic Extended-C" },
  300. { 0x10F00, 0x10F2F, U"Old Sogdian" },
  301. { 0x10F30, 0x10F6F, U"Sogdian" },
  302. { 0x10F70, 0x10FAF, U"Old Uyghur" },
  303. { 0x10FB0, 0x10FDF, U"Chorasmian" },
  304. { 0x10FE0, 0x10FFF, U"Elymaic" },
  305. { 0x11000, 0x1107F, U"Brahmi" },
  306. { 0x11080, 0x110CF, U"Kaithi" },
  307. { 0x110D0, 0x110FF, U"Sora Sompeng" },
  308. { 0x11100, 0x1114F, U"Chakma" },
  309. { 0x11150, 0x1117F, U"Mahajani" },
  310. { 0x11180, 0x111DF, U"Sharada" },
  311. { 0x111E0, 0x111FF, U"Sinhala Archaic Numbers" },
  312. { 0x11200, 0x1124F, U"Khojki" },
  313. { 0x11280, 0x112AF, U"Multani" },
  314. { 0x112B0, 0x112FF, U"Khudawadi" },
  315. { 0x11300, 0x1137F, U"Grantha" },
  316. { 0x11400, 0x1147F, U"Newa" },
  317. { 0x11480, 0x114DF, U"Tirhuta" },
  318. { 0x11580, 0x115FF, U"Siddham" },
  319. { 0x11600, 0x1165F, U"Modi" },
  320. { 0x11660, 0x1167F, U"Mongolian Supplement" },
  321. { 0x11680, 0x116CF, U"Takri" },
  322. { 0x11700, 0x1174F, U"Ahom" },
  323. { 0x11800, 0x1184F, U"Dogra" },
  324. { 0x118A0, 0x118FF, U"Warang Citi" },
  325. { 0x11900, 0x1195F, U"Dives Akuru" },
  326. { 0x119A0, 0x119FF, U"Nandinagari" },
  327. { 0x11A00, 0x11A4F, U"Zanabazar Square" },
  328. { 0x11A50, 0x11AAF, U"Soyombo" },
  329. { 0x11AB0, 0x11ABF, U"Unified Canadian Aboriginal Syllabics Extended-A" },
  330. { 0x11AC0, 0x11AFF, U"Pau Cin Hau" },
  331. { 0x11B00, 0x11B5F, U"Devanagari Extended-A" },
  332. { 0x11C00, 0x11C6F, U"Bhaiksuki" },
  333. { 0x11C70, 0x11CBF, U"Marchen" },
  334. { 0x11D00, 0x11D5F, U"Masaram Gondi" },
  335. { 0x11D60, 0x11DAF, U"Gunjala Gondi" },
  336. { 0x11EE0, 0x11EFF, U"Makasar" },
  337. { 0x11F00, 0x11F5F, U"Kawi" },
  338. { 0x11FB0, 0x11FBF, U"Lisu Supplement" },
  339. { 0x11FC0, 0x11FFF, U"Tamil Supplement" },
  340. { 0x12000, 0x123FF, U"Cuneiform" },
  341. { 0x12400, 0x1247F, U"Cuneiform Numbers and Punctuation" },
  342. { 0x12480, 0x1254F, U"Early Dynastic Cuneiform" },
  343. { 0x12F90, 0x12FFF, U"Cypro-Minoan" },
  344. { 0x13000, 0x1342F, U"Egyptian Hieroglyphs" },
  345. { 0x13430, 0x1343F, U"Egyptian Hieroglyph Format Controls" },
  346. { 0x14400, 0x1467F, U"Anatolian Hieroglyphs" },
  347. { 0x16800, 0x16A3F, U"Bamum Supplement" },
  348. { 0x16A40, 0x16A6F, U"Mro" },
  349. { 0x16A70, 0x16ACF, U"Tangsa" },
  350. { 0x16AD0, 0x16AFF, U"Bassa Vah" },
  351. { 0x16B00, 0x16B8F, U"Pahawh Hmong" },
  352. { 0x16E40, 0x16E9F, U"Medefaidrin" },
  353. { 0x16F00, 0x16F9F, U"Miao" },
  354. { 0x16FE0, 0x16FFF, U"Ideographic Symbols and Punctuation" },
  355. { 0x17000, 0x187FF, U"Tangut" },
  356. { 0x18800, 0x18AFF, U"Tangut Components" },
  357. { 0x18B00, 0x18CFF, U"Khitan Small Script" },
  358. { 0x18D00, 0x18D7F, U"Tangut Supplement" },
  359. { 0x1AFF0, 0x1AFFF, U"Kana Extended-B" },
  360. { 0x1B000, 0x1B0FF, U"Kana Supplement" },
  361. { 0x1B100, 0x1B12F, U"Kana Extended-A" },
  362. { 0x1B130, 0x1B16F, U"Small Kana Extension" },
  363. { 0x1B170, 0x1B2FF, U"Nushu" },
  364. { 0x1BC00, 0x1BC9F, U"Duployan" },
  365. { 0x1BCA0, 0x1BCAF, U"Shorthand Format Controls" },
  366. { 0x1CF00, 0x1CFCF, U"Znamenny Musical Notation" },
  367. { 0x1D000, 0x1D0FF, U"Byzantine Musical Symbols" },
  368. { 0x1D100, 0x1D1FF, U"Musical Symbols" },
  369. { 0x1D200, 0x1D24F, U"Ancient Greek Musical Notation" },
  370. { 0x1D2C0, 0x1D2DF, U"Kaktovik Numerals" },
  371. { 0x1D2E0, 0x1D2FF, U"Mayan Numerals" },
  372. { 0x1D300, 0x1D35F, U"Tai Xuan Jing Symbols" },
  373. { 0x1D360, 0x1D37F, U"Counting Rod Numerals" },
  374. { 0x1D400, 0x1D7FF, U"Mathematical Alphanumeric Symbols" },
  375. { 0x1D800, 0x1DAAF, U"Sutton SignWriting" },
  376. { 0x1DF00, 0x1DFFF, U"Latin Extended-G" },
  377. { 0x1E000, 0x1E02F, U"Glagolitic Supplement" },
  378. { 0x1E030, 0x1E08F, U"Cyrillic Extended-D" },
  379. { 0x1E100, 0x1E14F, U"Nyiakeng Puachue Hmong" },
  380. { 0x1E290, 0x1E2BF, U"Toto" },
  381. { 0x1E2C0, 0x1E2FF, U"Wancho" },
  382. { 0x1E4D0, 0x1E4FF, U"Nag Mundari" },
  383. { 0x1E7E0, 0x1E7FF, U"Ethiopic Extended-B" },
  384. { 0x1E800, 0x1E8DF, U"Mende Kikakui" },
  385. { 0x1E900, 0x1E95F, U"Adlam" },
  386. { 0x1EC70, 0x1ECBF, U"Indic Siyaq Numbers" },
  387. { 0x1ED00, 0x1ED4F, U"Ottoman Siyaq Numbers" },
  388. { 0x1EE00, 0x1EEFF, U"Arabic Mathematical Alphabetic Symbols" },
  389. { 0x1F000, 0x1F02F, U"Mahjong Tiles" },
  390. { 0x1F030, 0x1F09F, U"Domino Tiles" },
  391. { 0x1F0A0, 0x1F0FF, U"Playing Cards" },
  392. { 0x1F100, 0x1F1FF, U"Enclosed Alphanumeric Supplement" },
  393. { 0x1F200, 0x1F2FF, U"Enclosed Ideographic Supplement" },
  394. { 0x1F300, 0x1F5FF, U"Miscellaneous Symbols and Pictographs" },
  395. { 0x1F600, 0x1F64F, U"Emoticons" },
  396. { 0x1F650, 0x1F67F, U"Ornamental Dingbats" },
  397. { 0x1F680, 0x1F6FF, U"Transport and Map Symbols" },
  398. { 0x1F700, 0x1F77F, U"Alchemical Symbols" },
  399. { 0x1F780, 0x1F7FF, U"Geometric Shapes Extended" },
  400. { 0x1F800, 0x1F8FF, U"Supplemental Arrows-C" },
  401. { 0x1F900, 0x1F9FF, U"Supplemental Symbols and Pictographs" },
  402. { 0x1FA00, 0x1FA6F, U"Chess Symbols" },
  403. { 0x1FA70, 0x1FAFF, U"Symbols and Pictographs Extended-A" },
  404. { 0x1FB00, 0x1FBFF, U"Symbols for Legacy Computing" },
  405. { 0x20000, 0x2A6DF, U"CJK Unified Ideographs Extension B" },
  406. { 0x2A700, 0x2B73F, U"CJK Unified Ideographs Extension C" },
  407. { 0x2B740, 0x2B81F, U"CJK Unified Ideographs Extension D" },
  408. { 0x2B820, 0x2CEAF, U"CJK Unified Ideographs Extension E" },
  409. { 0x2CEB0, 0x2EBEF, U"CJK Unified Ideographs Extension F" },
  410. { 0x2F800, 0x2FA1F, U"CJK Compatibility Ideographs Supplement" },
  411. { 0x30000, 0x3134F, U"CJK Unified Ideographs Extension G" },
  412. { 0x31350, 0x323AF, U"CJK Unified Ideographs Extension H" },
  413. //{ 0xE0000, 0xE007F, U"Tags" },
  414. //{ 0xE0100, 0xE01EF, U"Variation Selectors Supplement" },
  415. { 0xF0000, 0xFFFFF, U"Supplementary Private Use Area-A" },
  416. { 0x100000, 0x10FFFF, U"Supplementary Private Use Area-B" },
  417. { 0x10FFFF, 0x10FFFF, String() }
  418. };
  419. void DynamicFontImportSettings::_add_glyph_range_item(int32_t p_start, int32_t p_end, const String &p_name) {
  420. const int page_size = 512;
  421. int pages = (p_end - p_start) / page_size;
  422. int remain = (p_end - p_start) % page_size;
  423. int32_t start = p_start;
  424. for (int i = 0; i < pages; i++) {
  425. TreeItem *item = glyph_tree->create_item(glyph_root);
  426. ERR_FAIL_NULL(item);
  427. item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  428. item->set_text(0, _pad_zeros(String::num_int64(start, 16)) + " - " + _pad_zeros(String::num_int64(start + page_size, 16)));
  429. item->set_text(1, p_name);
  430. item->set_metadata(0, Vector2i(start, start + page_size));
  431. start += page_size;
  432. }
  433. if (remain > 0) {
  434. TreeItem *item = glyph_tree->create_item(glyph_root);
  435. ERR_FAIL_NULL(item);
  436. item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  437. item->set_text(0, _pad_zeros(String::num_int64(start, 16)) + " - " + _pad_zeros(String::num_int64(p_end, 16)));
  438. item->set_text(1, p_name);
  439. item->set_metadata(0, Vector2i(start, p_end));
  440. }
  441. }
  442. /*************************************************************************/
  443. /* Page 1 callbacks: Rendering Options */
  444. /*************************************************************************/
  445. void DynamicFontImportSettings::_main_prop_changed(const String &p_edited_property) {
  446. // Update font preview.
  447. if (font_preview.is_valid()) {
  448. if (p_edited_property == "antialiasing") {
  449. font_preview->set_antialiasing((TextServer::FontAntialiasing)import_settings_data->get("antialiasing").operator int());
  450. } else if (p_edited_property == "generate_mipmaps") {
  451. font_preview->set_generate_mipmaps(import_settings_data->get("generate_mipmaps"));
  452. } else if (p_edited_property == "multichannel_signed_distance_field") {
  453. font_preview->set_multichannel_signed_distance_field(import_settings_data->get("multichannel_signed_distance_field"));
  454. _variation_selected();
  455. _variations_validate();
  456. } else if (p_edited_property == "msdf_pixel_range") {
  457. font_preview->set_msdf_pixel_range(import_settings_data->get("msdf_pixel_range"));
  458. } else if (p_edited_property == "msdf_size") {
  459. font_preview->set_msdf_size(import_settings_data->get("msdf_size"));
  460. } else if (p_edited_property == "allow_system_fallback") {
  461. font_preview->set_allow_system_fallback(import_settings_data->get("allow_system_fallback"));
  462. } else if (p_edited_property == "force_autohinter") {
  463. font_preview->set_force_autohinter(import_settings_data->get("force_autohinter"));
  464. } else if (p_edited_property == "hinting") {
  465. font_preview->set_hinting((TextServer::Hinting)import_settings_data->get("hinting").operator int());
  466. } else if (p_edited_property == "subpixel_positioning") {
  467. font_preview->set_subpixel_positioning((TextServer::SubpixelPositioning)import_settings_data->get("subpixel_positioning").operator int());
  468. } else if (p_edited_property == "oversampling") {
  469. font_preview->set_oversampling(import_settings_data->get("oversampling"));
  470. }
  471. }
  472. font_preview_label->add_theme_font_override("font", font_preview);
  473. font_preview_label->add_theme_font_size_override("font_size", 200 * EDSCALE);
  474. font_preview_label->queue_redraw();
  475. }
  476. /*************************************************************************/
  477. /* Page 2 callbacks: Configurations */
  478. /*************************************************************************/
  479. void DynamicFontImportSettings::_variation_add() {
  480. TreeItem *vars_item = vars_list->create_item(vars_list_root);
  481. ERR_FAIL_NULL(vars_item);
  482. vars_item->set_text(0, TTR("New Configuration"));
  483. vars_item->set_editable(0, true);
  484. vars_item->add_button(1, get_editor_theme_icon(SNAME("Remove")), BUTTON_REMOVE_VAR, false, TTR("Remove Variation"));
  485. vars_item->set_button_color(1, 0, Color(1, 1, 1, 0.75));
  486. Ref<DynamicFontImportSettingsData> import_variation_data;
  487. import_variation_data.instantiate();
  488. import_variation_data->owner = this;
  489. ERR_FAIL_NULL(import_variation_data);
  490. for (List<ResourceImporter::ImportOption>::Element *E = options_variations.front(); E; E = E->next()) {
  491. import_variation_data->defaults[E->get().option.name] = E->get().default_value;
  492. }
  493. import_variation_data->options = options_variations;
  494. inspector_vars->edit(import_variation_data.ptr());
  495. import_variation_data->notify_property_list_changed();
  496. import_variation_data->fd = font_main;
  497. vars_item->set_metadata(0, import_variation_data);
  498. _variations_validate();
  499. }
  500. void DynamicFontImportSettings::_variation_selected() {
  501. TreeItem *vars_item = vars_list->get_selected();
  502. if (vars_item) {
  503. Ref<DynamicFontImportSettingsData> import_variation_data = vars_item->get_metadata(0);
  504. ERR_FAIL_NULL(import_variation_data);
  505. inspector_vars->edit(import_variation_data.ptr());
  506. import_variation_data->notify_property_list_changed();
  507. label_glyphs->set_text(vformat(TTR("Preloaded glyphs: %d"), import_variation_data->selected_glyphs.size()));
  508. _range_selected();
  509. _change_text_opts();
  510. btn_fill->set_disabled(false);
  511. btn_fill_locales->set_disabled(false);
  512. } else {
  513. btn_fill->set_disabled(true);
  514. btn_fill_locales->set_disabled(true);
  515. }
  516. }
  517. void DynamicFontImportSettings::_variation_remove(Object *p_item, int p_column, int p_id, MouseButton p_button) {
  518. if (p_button != MouseButton::LEFT) {
  519. return;
  520. }
  521. TreeItem *vars_item = (TreeItem *)p_item;
  522. ERR_FAIL_NULL(vars_item);
  523. inspector_vars->edit(nullptr);
  524. vars_list_root->remove_child(vars_item);
  525. memdelete(vars_item);
  526. if (vars_list_root->get_first_child()) {
  527. Ref<DynamicFontImportSettingsData> import_variation_data = vars_list_root->get_first_child()->get_metadata(0);
  528. inspector_vars->edit(import_variation_data.ptr());
  529. import_variation_data->notify_property_list_changed();
  530. }
  531. _variations_validate();
  532. vars_item = vars_list->get_selected();
  533. if (vars_item) {
  534. btn_fill->set_disabled(false);
  535. btn_fill_locales->set_disabled(false);
  536. } else {
  537. btn_fill->set_disabled(true);
  538. btn_fill_locales->set_disabled(true);
  539. }
  540. }
  541. void DynamicFontImportSettings::_variation_changed(const String &p_edited_property) {
  542. _variations_validate();
  543. }
  544. void DynamicFontImportSettings::_variations_validate() {
  545. String warn;
  546. if (!vars_list_root->get_first_child()) {
  547. warn = TTR("Warning: There are no configurations specified, no glyphs will be pre-rendered.");
  548. }
  549. for (TreeItem *vars_item_a = vars_list_root->get_first_child(); vars_item_a; vars_item_a = vars_item_a->get_next()) {
  550. Ref<DynamicFontImportSettingsData> import_variation_data_a = vars_item_a->get_metadata(0);
  551. ERR_FAIL_NULL(import_variation_data_a);
  552. for (TreeItem *vars_item_b = vars_list_root->get_first_child(); vars_item_b; vars_item_b = vars_item_b->get_next()) {
  553. if (vars_item_b != vars_item_a) {
  554. bool match = true;
  555. for (const KeyValue<StringName, Variant> &E : import_variation_data_a->settings) {
  556. Ref<DynamicFontImportSettingsData> import_variation_data_b = vars_item_b->get_metadata(0);
  557. ERR_FAIL_NULL(import_variation_data_b);
  558. match = match && (import_variation_data_b->settings[E.key] == E.value);
  559. }
  560. if (match) {
  561. warn = TTR("Warning: Multiple configurations have identical settings. Duplicates will be ignored.");
  562. break;
  563. }
  564. }
  565. }
  566. }
  567. if ((TextServer::FontAntialiasing)(int)import_settings_data->get("antialiasing") == TextServer::FONT_ANTIALIASING_LCD) {
  568. warn += "\n" + TTR("Note: LCD Subpixel antialiasing is selected, each of the glyphs will be pre-rendered for all supported subpixel layouts (5x).");
  569. }
  570. if ((TextServer::SubpixelPositioning)(int)import_settings_data->get("subpixel_positioning") != TextServer::SUBPIXEL_POSITIONING_DISABLED) {
  571. warn += "\n" + TTR("Note: Subpixel positioning is selected, each of the glyphs might be pre-rendered for multiple subpixel offsets (up to 4x).");
  572. }
  573. if (warn.is_empty()) {
  574. label_warn->set_text("");
  575. label_warn->hide();
  576. } else {
  577. label_warn->set_text(warn);
  578. label_warn->show();
  579. }
  580. }
  581. /*************************************************************************/
  582. /* Page 2.1 callbacks: Text to select glyphs */
  583. /*************************************************************************/
  584. void DynamicFontImportSettings::_change_text_opts() {
  585. Ref<DynamicFontImportSettingsData> import_variation_data;
  586. TreeItem *vars_item = vars_list->get_selected();
  587. if (vars_item) {
  588. import_variation_data = vars_item->get_metadata(0);
  589. }
  590. if (import_variation_data.is_null()) {
  591. return;
  592. }
  593. Ref<FontVariation> font_main_text;
  594. font_main_text.instantiate();
  595. font_main_text->set_base_font(font_main);
  596. font_main_text->set_opentype_features(text_settings_data->get("opentype_features"));
  597. font_main_text->set_variation_opentype(import_variation_data->get("variation_opentype"));
  598. font_main_text->set_variation_embolden(import_variation_data->get("variation_embolden"));
  599. font_main_text->set_variation_face_index(import_variation_data->get("variation_face_index"));
  600. font_main_text->set_variation_transform(import_variation_data->get("variation_transform"));
  601. text_edit->add_theme_font_override("font", font_main_text);
  602. }
  603. void DynamicFontImportSettings::_glyph_update_lbl() {
  604. Ref<DynamicFontImportSettingsData> import_variation_data;
  605. TreeItem *vars_item = vars_list->get_selected();
  606. if (vars_item) {
  607. import_variation_data = vars_item->get_metadata(0);
  608. }
  609. if (import_variation_data.is_null()) {
  610. return;
  611. }
  612. int linked_glyphs = 0;
  613. for (const char32_t &c : import_variation_data->selected_chars) {
  614. if (import_variation_data->selected_glyphs.has(font_main->get_glyph_index(16, c))) {
  615. linked_glyphs++;
  616. }
  617. }
  618. int unlinked_glyphs = import_variation_data->selected_glyphs.size() - linked_glyphs;
  619. label_glyphs->set_text(vformat(TTR("Preloaded glyphs: %d"), unlinked_glyphs + import_variation_data->selected_chars.size()));
  620. }
  621. void DynamicFontImportSettings::_glyph_clear() {
  622. Ref<DynamicFontImportSettingsData> import_variation_data;
  623. TreeItem *vars_item = vars_list->get_selected();
  624. if (vars_item) {
  625. import_variation_data = vars_item->get_metadata(0);
  626. }
  627. if (import_variation_data.is_null()) {
  628. return;
  629. }
  630. import_variation_data->selected_glyphs.clear();
  631. _glyph_update_lbl();
  632. _range_selected();
  633. }
  634. void DynamicFontImportSettings::_glyph_text_selected() {
  635. Ref<DynamicFontImportSettingsData> import_variation_data;
  636. TreeItem *vars_item = vars_list->get_selected();
  637. if (vars_item) {
  638. import_variation_data = vars_item->get_metadata(0);
  639. }
  640. if (import_variation_data.is_null()) {
  641. return;
  642. }
  643. RID text_rid = TS->create_shaped_text();
  644. if (text_rid.is_valid()) {
  645. TS->shaped_text_add_string(text_rid, text_edit->get_text(), font_main->get_rids(), 16, text_settings_data->get("opentype_features"), text_settings_data->get("language"));
  646. TS->shaped_text_shape(text_rid);
  647. const Glyph *gl = TS->shaped_text_get_glyphs(text_rid);
  648. const int gl_size = TS->shaped_text_get_glyph_count(text_rid);
  649. for (int i = 0; i < gl_size; i++) {
  650. if (gl[i].font_rid.is_valid() && gl[i].index != 0) {
  651. import_variation_data->selected_glyphs.insert(gl[i].index);
  652. }
  653. }
  654. TS->free_rid(text_rid);
  655. _glyph_update_lbl();
  656. }
  657. _range_selected();
  658. }
  659. /*************************************************************************/
  660. /* Page 2.2 callbacks: Character map */
  661. /*************************************************************************/
  662. void DynamicFontImportSettings::_glyph_selected() {
  663. Ref<DynamicFontImportSettingsData> import_variation_data;
  664. TreeItem *vars_item = vars_list->get_selected();
  665. if (vars_item) {
  666. import_variation_data = vars_item->get_metadata(0);
  667. }
  668. if (import_variation_data.is_null()) {
  669. return;
  670. }
  671. TreeItem *item = glyph_table->get_selected();
  672. ERR_FAIL_NULL(item);
  673. Color scol = glyph_table->get_theme_color(SNAME("box_selection_fill_color"), EditorStringName(Editor));
  674. Color fcol = glyph_table->get_theme_color(SNAME("font_selected_color"), EditorStringName(Editor));
  675. scol.a = 1.f;
  676. int32_t c = item->get_metadata(glyph_table->get_selected_column());
  677. if (font_main->has_char(c)) {
  678. if (_char_update(c)) {
  679. item->set_custom_color(glyph_table->get_selected_column(), fcol);
  680. item->set_custom_bg_color(glyph_table->get_selected_column(), scol);
  681. } else {
  682. item->clear_custom_color(glyph_table->get_selected_column());
  683. item->clear_custom_bg_color(glyph_table->get_selected_column());
  684. }
  685. }
  686. _glyph_update_lbl();
  687. item = glyph_tree->get_selected();
  688. ERR_FAIL_NULL(item);
  689. Vector2i range = item->get_metadata(0);
  690. int total_chars = range.y - range.x;
  691. int selected_count = 0;
  692. for (int i = range.x; i < range.y; i++) {
  693. if (!font_main->has_char(i)) {
  694. total_chars--;
  695. }
  696. if (import_variation_data->selected_chars.has(i)) {
  697. selected_count++;
  698. }
  699. }
  700. if (selected_count == total_chars) {
  701. item->set_checked(0, true);
  702. } else if (selected_count > 0) {
  703. item->set_indeterminate(0, true);
  704. } else {
  705. item->set_checked(0, false);
  706. }
  707. }
  708. void DynamicFontImportSettings::_range_edited() {
  709. TreeItem *item = glyph_tree->get_selected();
  710. ERR_FAIL_NULL(item);
  711. Vector2i range = item->get_metadata(0);
  712. _range_update(range.x, range.y);
  713. }
  714. void DynamicFontImportSettings::_range_selected() {
  715. TreeItem *item = glyph_tree->get_selected();
  716. if (item) {
  717. Vector2i range = item->get_metadata(0);
  718. _edit_range(range.x, range.y);
  719. }
  720. }
  721. void DynamicFontImportSettings::_edit_range(int32_t p_start, int32_t p_end) {
  722. Ref<DynamicFontImportSettingsData> import_variation_data;
  723. TreeItem *vars_item = vars_list->get_selected();
  724. if (vars_item) {
  725. import_variation_data = vars_item->get_metadata(0);
  726. }
  727. if (import_variation_data.is_null()) {
  728. return;
  729. }
  730. glyph_table->clear();
  731. TreeItem *root = glyph_table->create_item();
  732. ERR_FAIL_NULL(root);
  733. Color scol = glyph_table->get_theme_color(SNAME("box_selection_fill_color"), EditorStringName(Editor));
  734. Color fcol = glyph_table->get_theme_color(SNAME("font_selected_color"), EditorStringName(Editor));
  735. scol.a = 1.f;
  736. TreeItem *item = nullptr;
  737. int col = 0;
  738. Ref<Font> font_main_big = font_main->duplicate();
  739. for (int32_t c = p_start; c <= p_end; c++) {
  740. if (col == 0) {
  741. item = glyph_table->create_item(root);
  742. ERR_FAIL_NULL(item);
  743. item->set_text(0, _pad_zeros(String::num_int64(c, 16)));
  744. item->set_text_alignment(0, HORIZONTAL_ALIGNMENT_LEFT);
  745. item->set_selectable(0, false);
  746. item->set_custom_bg_color(0, glyph_table->get_theme_color(SNAME("dark_color_3"), EditorStringName(Editor)));
  747. }
  748. if (font_main->has_char(c)) {
  749. item->set_text(col + 1, String::chr(c));
  750. item->set_custom_color(col + 1, Color(1, 1, 1));
  751. if (import_variation_data->selected_chars.has(c) || import_variation_data->selected_glyphs.has(font_main->get_glyph_index(16, c))) {
  752. item->set_custom_color(col + 1, fcol);
  753. item->set_custom_bg_color(col + 1, scol);
  754. } else {
  755. item->clear_custom_color(col + 1);
  756. item->clear_custom_bg_color(col + 1);
  757. }
  758. } else {
  759. item->set_custom_bg_color(col + 1, glyph_table->get_theme_color(SNAME("dark_color_2"), EditorStringName(Editor)));
  760. }
  761. item->set_metadata(col + 1, c);
  762. item->set_text_alignment(col + 1, HORIZONTAL_ALIGNMENT_CENTER);
  763. item->set_selectable(col + 1, true);
  764. item->set_custom_font(col + 1, font_main_big);
  765. item->set_custom_font_size(col + 1, get_theme_font_size(SNAME("font_size")) * 2);
  766. col++;
  767. if (col == 16) {
  768. col = 0;
  769. }
  770. }
  771. _glyph_update_lbl();
  772. }
  773. bool DynamicFontImportSettings::_char_update(int32_t p_char) {
  774. Ref<DynamicFontImportSettingsData> import_variation_data;
  775. TreeItem *vars_item = vars_list->get_selected();
  776. if (vars_item) {
  777. import_variation_data = vars_item->get_metadata(0);
  778. }
  779. if (import_variation_data.is_null()) {
  780. return false;
  781. }
  782. if (import_variation_data->selected_chars.has(p_char)) {
  783. import_variation_data->selected_chars.erase(p_char);
  784. return false;
  785. } else if (font_main.is_valid() && import_variation_data->selected_glyphs.has(font_main->get_glyph_index(16, p_char))) {
  786. import_variation_data->selected_glyphs.erase(font_main->get_glyph_index(16, p_char));
  787. return false;
  788. } else {
  789. import_variation_data->selected_chars.insert(p_char);
  790. return true;
  791. }
  792. }
  793. void DynamicFontImportSettings::_range_update(int32_t p_start, int32_t p_end) {
  794. Ref<DynamicFontImportSettingsData> import_variation_data;
  795. TreeItem *vars_item = vars_list->get_selected();
  796. if (vars_item) {
  797. import_variation_data = vars_item->get_metadata(0);
  798. }
  799. if (import_variation_data.is_null()) {
  800. return;
  801. }
  802. bool all_selected = true;
  803. for (int32_t i = p_start; i <= p_end; i++) {
  804. if (font_main->has_char(i)) {
  805. if (font_main.is_valid()) {
  806. all_selected = all_selected && (import_variation_data->selected_chars.has(i) || import_variation_data->selected_glyphs.has(font_main->get_glyph_index(16, i)));
  807. } else {
  808. all_selected = all_selected && import_variation_data->selected_chars.has(i);
  809. }
  810. }
  811. }
  812. for (int32_t i = p_start; i <= p_end; i++) {
  813. if (font_main->has_char(i)) {
  814. if (!all_selected) {
  815. import_variation_data->selected_chars.insert(i);
  816. } else {
  817. import_variation_data->selected_chars.erase(i);
  818. if (font_main.is_valid()) {
  819. import_variation_data->selected_glyphs.erase(font_main->get_glyph_index(16, i));
  820. }
  821. }
  822. }
  823. }
  824. _edit_range(p_start, p_end);
  825. TreeItem *item = glyph_tree->get_selected();
  826. ERR_FAIL_NULL(item);
  827. item->set_checked(0, !all_selected);
  828. }
  829. /*************************************************************************/
  830. /* Common */
  831. /*************************************************************************/
  832. DynamicFontImportSettings *DynamicFontImportSettings::singleton = nullptr;
  833. String DynamicFontImportSettings::_pad_zeros(const String &p_hex) const {
  834. int len = CLAMP(5 - p_hex.length(), 0, 5);
  835. return String("0").repeat(len) + p_hex;
  836. }
  837. void DynamicFontImportSettings::_notification(int p_what) {
  838. switch (p_what) {
  839. case NOTIFICATION_READY: {
  840. connect("confirmed", callable_mp(this, &DynamicFontImportSettings::_re_import));
  841. } break;
  842. case NOTIFICATION_THEME_CHANGED: {
  843. add_var->set_icon(get_editor_theme_icon(SNAME("Add")));
  844. label_warn->add_theme_color_override("font_color", get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
  845. } break;
  846. }
  847. }
  848. void DynamicFontImportSettings::_re_import() {
  849. HashMap<StringName, Variant> main_settings;
  850. main_settings["face_index"] = import_settings_data->get("face_index");
  851. main_settings["antialiasing"] = import_settings_data->get("antialiasing");
  852. main_settings["generate_mipmaps"] = import_settings_data->get("generate_mipmaps");
  853. main_settings["multichannel_signed_distance_field"] = import_settings_data->get("multichannel_signed_distance_field");
  854. main_settings["msdf_pixel_range"] = import_settings_data->get("msdf_pixel_range");
  855. main_settings["msdf_size"] = import_settings_data->get("msdf_size");
  856. main_settings["allow_system_fallback"] = import_settings_data->get("allow_system_fallback");
  857. main_settings["force_autohinter"] = import_settings_data->get("force_autohinter");
  858. main_settings["hinting"] = import_settings_data->get("hinting");
  859. main_settings["subpixel_positioning"] = import_settings_data->get("subpixel_positioning");
  860. main_settings["oversampling"] = import_settings_data->get("oversampling");
  861. main_settings["fallbacks"] = import_settings_data->get("fallbacks");
  862. main_settings["compress"] = import_settings_data->get("compress");
  863. Array configurations;
  864. for (TreeItem *vars_item = vars_list_root->get_first_child(); vars_item; vars_item = vars_item->get_next()) {
  865. Ref<DynamicFontImportSettingsData> import_variation_data = vars_item->get_metadata(0);
  866. ERR_FAIL_NULL(import_variation_data);
  867. Dictionary preload_config;
  868. preload_config["name"] = vars_item->get_text(0);
  869. Size2i conf_size = Vector2i(16, 0);
  870. for (const KeyValue<StringName, Variant> &E : import_variation_data->settings) {
  871. if (E.key == "size") {
  872. conf_size.x = E.value;
  873. }
  874. if (E.key == "outline_size") {
  875. conf_size.y = E.value;
  876. } else {
  877. preload_config[E.key] = E.value;
  878. }
  879. }
  880. preload_config["size"] = conf_size;
  881. Array chars;
  882. for (const char32_t &E : import_variation_data->selected_chars) {
  883. chars.push_back(E);
  884. }
  885. preload_config["chars"] = chars;
  886. Array glyphs;
  887. for (const int32_t &E : import_variation_data->selected_glyphs) {
  888. glyphs.push_back(E);
  889. }
  890. preload_config["glyphs"] = glyphs;
  891. configurations.push_back(preload_config);
  892. }
  893. main_settings["preload"] = configurations;
  894. main_settings["language_support"] = import_settings_data->get("language_support");
  895. main_settings["script_support"] = import_settings_data->get("script_support");
  896. main_settings["opentype_features"] = import_settings_data->get("opentype_features");
  897. if (OS::get_singleton()->is_stdout_verbose()) {
  898. print_line("Import settings:");
  899. for (const KeyValue<StringName, Variant> &E : main_settings) {
  900. print_line(String(" ") + String(E.key).utf8().get_data() + " == " + String(E.value).utf8().get_data());
  901. }
  902. }
  903. EditorFileSystem::get_singleton()->reimport_file_with_custom_parameters(base_path, "font_data_dynamic", main_settings);
  904. }
  905. void DynamicFontImportSettings::_locale_edited() {
  906. TreeItem *item = locale_tree->get_selected();
  907. ERR_FAIL_NULL(item);
  908. item->set_checked(0, !item->is_checked(0));
  909. }
  910. void DynamicFontImportSettings::_process_locales() {
  911. Ref<DynamicFontImportSettingsData> import_variation_data;
  912. TreeItem *vars_item = vars_list->get_selected();
  913. if (vars_item) {
  914. import_variation_data = vars_item->get_metadata(0);
  915. }
  916. if (import_variation_data.is_null()) {
  917. return;
  918. }
  919. for (int i = 0; i < locale_root->get_child_count(); i++) {
  920. TreeItem *item = locale_root->get_child(i);
  921. if (item) {
  922. if (item->is_checked(0)) {
  923. String locale = item->get_text(0);
  924. Ref<Translation> tr = ResourceLoader::load(locale);
  925. if (tr.is_valid()) {
  926. Vector<String> messages = tr->get_translated_message_list();
  927. for (const String &E : messages) {
  928. RID text_rid = TS->create_shaped_text();
  929. if (text_rid.is_valid()) {
  930. TS->shaped_text_add_string(text_rid, E, font_main->get_rids(), 16, Dictionary(), tr->get_locale());
  931. TS->shaped_text_shape(text_rid);
  932. const Glyph *gl = TS->shaped_text_get_glyphs(text_rid);
  933. const int gl_size = TS->shaped_text_get_glyph_count(text_rid);
  934. for (int j = 0; j < gl_size; j++) {
  935. if (gl[j].font_rid.is_valid() && gl[j].index != 0) {
  936. import_variation_data->selected_glyphs.insert(gl[j].index);
  937. }
  938. }
  939. TS->free_rid(text_rid);
  940. }
  941. }
  942. }
  943. }
  944. }
  945. }
  946. _glyph_update_lbl();
  947. _range_selected();
  948. }
  949. void DynamicFontImportSettings::open_settings(const String &p_path) {
  950. // Load base font data.
  951. Vector<uint8_t> font_data = FileAccess::get_file_as_bytes(p_path);
  952. // Load project locale list.
  953. locale_tree->clear();
  954. locale_root = locale_tree->create_item();
  955. ERR_FAIL_NULL(locale_root);
  956. Vector<String> translations = GLOBAL_GET("internationalization/locale/translations");
  957. for (const String &E : translations) {
  958. TreeItem *item = locale_tree->create_item(locale_root);
  959. ERR_FAIL_NULL(item);
  960. item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  961. item->set_text(0, E);
  962. }
  963. // Load font for preview.
  964. font_preview.instantiate();
  965. font_preview->set_data(font_data);
  966. String font_name = vformat("%s (%s)", font_preview->get_font_name(), font_preview->get_font_style_name());
  967. String sample;
  968. static const String sample_base = U"12漢字ԱբΑαАбΑαאבابܐܒހށआআਆઆଆஆఆಆആආกิກິༀကႠა한글ሀᎣᐁᚁᚠᜀᜠᝀᝠកᠠᤁᥐAb😀";
  969. for (int i = 0; i < sample_base.length(); i++) {
  970. if (font_preview->has_char(sample_base[i])) {
  971. sample += sample_base[i];
  972. }
  973. }
  974. if (sample.is_empty()) {
  975. sample = font_preview->get_supported_chars().substr(0, 6);
  976. }
  977. font_preview_label->set_text(sample);
  978. Ref<Font> bold_font = get_theme_font(SNAME("bold"), EditorStringName(EditorFonts));
  979. if (bold_font.is_valid()) {
  980. font_name_label->add_theme_font_override("bold_font", bold_font);
  981. }
  982. font_name_label->set_text(font_name);
  983. // Load second copy of font with MSDF disabled for the glyph table and metadata extraction.
  984. font_main.instantiate();
  985. font_main->set_data(font_data);
  986. font_main->set_multichannel_signed_distance_field(false);
  987. text_edit->add_theme_font_override("font", font_main);
  988. base_path = p_path;
  989. inspector_vars->edit(nullptr);
  990. inspector_text->edit(nullptr);
  991. inspector_general->edit(nullptr);
  992. text_settings_data.instantiate();
  993. ERR_FAIL_NULL(text_settings_data);
  994. text_settings_data->owner = this;
  995. for (List<ResourceImporter::ImportOption>::Element *F = options_text.front(); F; F = F->next()) {
  996. text_settings_data->defaults[F->get().option.name] = F->get().default_value;
  997. }
  998. text_settings_data->fd = font_main;
  999. text_settings_data->options = options_text;
  1000. inspector_text->edit(text_settings_data.ptr());
  1001. int gww = get_theme_font(SNAME("font"))->get_string_size("00000").x + 50;
  1002. glyph_table->set_column_custom_minimum_width(0, gww);
  1003. glyph_table->clear();
  1004. vars_list->clear();
  1005. glyph_tree->set_selected(glyph_root->get_child(0));
  1006. vars_list_root = vars_list->create_item();
  1007. import_settings_data->settings.clear();
  1008. import_settings_data->defaults.clear();
  1009. for (List<ResourceImporter::ImportOption>::Element *E = options_general.front(); E; E = E->next()) {
  1010. import_settings_data->defaults[E->get().option.name] = E->get().default_value;
  1011. }
  1012. Ref<ConfigFile> config;
  1013. config.instantiate();
  1014. ERR_FAIL_NULL(config);
  1015. Error err = config->load(p_path + ".import");
  1016. print_verbose("Loading import settings:");
  1017. if (err == OK) {
  1018. List<String> keys;
  1019. config->get_section_keys("params", &keys);
  1020. for (List<String>::Element *E = keys.front(); E; E = E->next()) {
  1021. String key = E->get();
  1022. print_verbose(String(" ") + key + " == " + String(config->get_value("params", key)));
  1023. if (key == "preload") {
  1024. Array preload_configurations = config->get_value("params", key);
  1025. for (int i = 0; i < preload_configurations.size(); i++) {
  1026. Dictionary preload_config = preload_configurations[i];
  1027. Dictionary variation = preload_config.has("variation_opentype") ? preload_config["variation_opentype"].operator Dictionary() : Dictionary();
  1028. double embolden = preload_config.has("variation_embolden") ? preload_config["variation_embolden"].operator double() : 0;
  1029. int face_index = preload_config.has("variation_face_index") ? preload_config["variation_face_index"].operator int() : 0;
  1030. Transform2D transform = preload_config.has("variation_transform") ? preload_config["variation_transform"].operator Transform2D() : Transform2D();
  1031. Vector2i font_size = preload_config.has("size") ? preload_config["size"].operator Vector2i() : Vector2i(16, 0);
  1032. String cfg_name = preload_config.has("name") ? preload_config["name"].operator String() : vformat("Configuration %d", i);
  1033. TreeItem *vars_item = vars_list->create_item(vars_list_root);
  1034. ERR_FAIL_NULL(vars_item);
  1035. vars_item->set_text(0, cfg_name);
  1036. vars_item->set_editable(0, true);
  1037. vars_item->add_button(1, get_editor_theme_icon(SNAME("Remove")), BUTTON_REMOVE_VAR, false, TTR("Remove Variation"));
  1038. vars_item->set_button_color(1, 0, Color(1, 1, 1, 0.75));
  1039. Ref<DynamicFontImportSettingsData> import_variation_data_custom;
  1040. import_variation_data_custom.instantiate();
  1041. ERR_FAIL_NULL(import_variation_data_custom);
  1042. import_variation_data_custom->owner = this;
  1043. for (List<ResourceImporter::ImportOption>::Element *F = options_variations.front(); F; F = F->next()) {
  1044. import_variation_data_custom->defaults[F->get().option.name] = F->get().default_value;
  1045. }
  1046. import_variation_data_custom->fd = font_main;
  1047. import_variation_data_custom->options = options_variations;
  1048. vars_item->set_metadata(0, import_variation_data_custom);
  1049. import_variation_data_custom->set("size", font_size.x);
  1050. import_variation_data_custom->set("outline_size", font_size.y);
  1051. import_variation_data_custom->set("variation_opentype", variation);
  1052. import_variation_data_custom->set("variation_embolden", embolden);
  1053. import_variation_data_custom->set("variation_face_index", face_index);
  1054. import_variation_data_custom->set("variation_transform", transform);
  1055. Array chars = preload_config["chars"];
  1056. for (int j = 0; j < chars.size(); j++) {
  1057. char32_t c = chars[j].operator int();
  1058. import_variation_data_custom->selected_chars.insert(c);
  1059. }
  1060. Array glyphs = preload_config["glyphs"];
  1061. for (int j = 0; j < glyphs.size(); j++) {
  1062. int32_t c = glyphs[j];
  1063. import_variation_data_custom->selected_glyphs.insert(c);
  1064. }
  1065. }
  1066. if (preload_configurations.is_empty()) {
  1067. _variation_add(); // Add default variation.
  1068. }
  1069. vars_list->set_selected(vars_list_root->get_child(0));
  1070. } else {
  1071. Variant value = config->get_value("params", key);
  1072. import_settings_data->defaults[key] = value;
  1073. }
  1074. }
  1075. }
  1076. import_settings_data->fd = font_main;
  1077. import_settings_data->options = options_general;
  1078. inspector_general->edit(import_settings_data.ptr());
  1079. import_settings_data->notify_property_list_changed();
  1080. if (font_preview.is_valid()) {
  1081. font_preview->set_antialiasing((TextServer::FontAntialiasing)import_settings_data->get("antialiasing").operator int());
  1082. font_preview->set_multichannel_signed_distance_field(import_settings_data->get("multichannel_signed_distance_field"));
  1083. font_preview->set_msdf_pixel_range(import_settings_data->get("msdf_pixel_range"));
  1084. font_preview->set_msdf_size(import_settings_data->get("msdf_size"));
  1085. font_preview->set_allow_system_fallback(import_settings_data->get("allow_system_fallback"));
  1086. font_preview->set_force_autohinter(import_settings_data->get("force_autohinter"));
  1087. font_preview->set_hinting((TextServer::Hinting)import_settings_data->get("hinting").operator int());
  1088. font_preview->set_subpixel_positioning((TextServer::SubpixelPositioning)import_settings_data->get("subpixel_positioning").operator int());
  1089. font_preview->set_oversampling(import_settings_data->get("oversampling"));
  1090. }
  1091. font_preview_label->add_theme_font_override("font", font_preview);
  1092. font_preview_label->add_theme_font_size_override("font_size", 200 * EDSCALE);
  1093. font_preview_label->queue_redraw();
  1094. _variations_validate();
  1095. popup_centered_ratio();
  1096. set_title(vformat(TTR("Advanced Import Settings for '%s'"), base_path.get_file()));
  1097. }
  1098. DynamicFontImportSettings *DynamicFontImportSettings::get_singleton() {
  1099. return singleton;
  1100. }
  1101. DynamicFontImportSettings::DynamicFontImportSettings() {
  1102. singleton = this;
  1103. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Rendering", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant()));
  1104. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "antialiasing", PROPERTY_HINT_ENUM, "None,Grayscale,LCD Subpixel"), 1));
  1105. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "generate_mipmaps"), false));
  1106. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "multichannel_signed_distance_field", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), true));
  1107. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "msdf_pixel_range", PROPERTY_HINT_RANGE, "1,100,1"), 8));
  1108. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "msdf_size", PROPERTY_HINT_RANGE, "1,250,1"), 48));
  1109. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "allow_system_fallback"), true));
  1110. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "force_autohinter"), false));
  1111. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "hinting", PROPERTY_HINT_ENUM, "None,Light,Normal"), 1));
  1112. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "subpixel_positioning", PROPERTY_HINT_ENUM, "Disabled,Auto,One Half of a Pixel,One Quarter of a Pixel"), 1));
  1113. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::FLOAT, "oversampling", PROPERTY_HINT_RANGE, "0,10,0.1"), 0.0));
  1114. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Metadata Overrides", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant()));
  1115. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "language_support"), Dictionary()));
  1116. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "script_support"), Dictionary()));
  1117. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "opentype_features"), Dictionary()));
  1118. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Fallbacks", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant()));
  1119. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::ARRAY, "fallbacks", PROPERTY_HINT_ARRAY_TYPE, MAKE_RESOURCE_TYPE_HINT("Font")), Array()));
  1120. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Compress", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant()));
  1121. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "compress", PROPERTY_HINT_NONE, ""), false));
  1122. options_text.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "opentype_features"), Dictionary()));
  1123. options_text.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::STRING, "language", PROPERTY_HINT_LOCALE_ID, ""), ""));
  1124. options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "size", PROPERTY_HINT_RANGE, "0,127,1"), 16));
  1125. options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "outline_size", PROPERTY_HINT_RANGE, "0,127,1"), 0));
  1126. options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Variation", PROPERTY_HINT_NONE, "variation", PROPERTY_USAGE_GROUP), Variant()));
  1127. options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "variation_opentype"), Dictionary()));
  1128. options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::FLOAT, "variation_embolden", PROPERTY_HINT_RANGE, "-2,2,0.01"), 0));
  1129. options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "variation_face_index"), 0));
  1130. options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::TRANSFORM2D, "variation_transform"), Transform2D()));
  1131. // Root layout
  1132. VBoxContainer *root_vb = memnew(VBoxContainer);
  1133. add_child(root_vb);
  1134. main_pages = memnew(TabContainer);
  1135. main_pages->set_tab_alignment(TabBar::ALIGNMENT_CENTER);
  1136. main_pages->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1137. main_pages->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1138. main_pages->set_theme_type_variation("TabContainerOdd");
  1139. root_vb->add_child(main_pages);
  1140. label_warn = memnew(Label);
  1141. label_warn->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  1142. label_warn->set_text("");
  1143. root_vb->add_child(label_warn);
  1144. label_warn->hide();
  1145. // Page 1 layout: Rendering Options
  1146. VBoxContainer *page1_vb = memnew(VBoxContainer);
  1147. page1_vb->set_name(TTR("Rendering Options"));
  1148. main_pages->add_child(page1_vb);
  1149. page1_description = memnew(Label);
  1150. page1_description->set_text(TTR("Select font rendering options, fallback font, and metadata override:"));
  1151. page1_description->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1152. page1_vb->add_child(page1_description);
  1153. HSplitContainer *page1_hb = memnew(HSplitContainer);
  1154. page1_hb->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1155. page1_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1156. page1_vb->add_child(page1_hb);
  1157. VBoxContainer *page1_lbl_vb = memnew(VBoxContainer);
  1158. page1_lbl_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1159. page1_lbl_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1160. page1_hb->add_child(page1_lbl_vb);
  1161. font_name_label = memnew(Label);
  1162. font_name_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  1163. font_name_label->set_clip_text(true);
  1164. font_name_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1165. page1_lbl_vb->add_child(font_name_label);
  1166. font_preview_label = memnew(Label);
  1167. font_preview_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  1168. font_preview_label->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
  1169. font_preview_label->set_autowrap_mode(TextServer::AUTOWRAP_ARBITRARY);
  1170. font_preview_label->set_clip_text(true);
  1171. font_preview_label->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1172. font_preview_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1173. page1_lbl_vb->add_child(font_preview_label);
  1174. inspector_general = memnew(EditorInspector);
  1175. inspector_general->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1176. inspector_general->set_custom_minimum_size(Size2(300 * EDSCALE, 250 * EDSCALE));
  1177. page1_hb->add_child(inspector_general);
  1178. inspector_general->connect("property_edited", callable_mp(this, &DynamicFontImportSettings::_main_prop_changed));
  1179. // Page 2 layout: Configurations
  1180. VBoxContainer *page2_vb = memnew(VBoxContainer);
  1181. page2_vb->set_name(TTR("Pre-render Configurations"));
  1182. main_pages->add_child(page2_vb);
  1183. page2_description = memnew(Label);
  1184. page2_description->set_text(TTR("Add font size, and variation coordinates, and select glyphs to pre-render:"));
  1185. page2_description->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1186. page2_description->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  1187. page2_description->set_custom_minimum_size(Size2(300 * EDSCALE, 1));
  1188. page2_vb->add_child(page2_description);
  1189. HSplitContainer *page2_hb = memnew(HSplitContainer);
  1190. page2_hb->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1191. page2_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1192. page2_vb->add_child(page2_hb);
  1193. VBoxContainer *page2_side_vb = memnew(VBoxContainer);
  1194. page2_hb->add_child(page2_side_vb);
  1195. HBoxContainer *page2_hb_vars = memnew(HBoxContainer);
  1196. page2_side_vb->add_child(page2_hb_vars);
  1197. label_vars = memnew(Label);
  1198. label_vars->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  1199. label_vars->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1200. label_vars->set_text(TTR("Configuration:"));
  1201. page2_hb_vars->add_child(label_vars);
  1202. add_var = memnew(Button);
  1203. add_var->set_tooltip_text(TTR("Add configuration"));
  1204. page2_hb_vars->add_child(add_var);
  1205. add_var->connect("pressed", callable_mp(this, &DynamicFontImportSettings::_variation_add));
  1206. vars_list = memnew(Tree);
  1207. vars_list->set_custom_minimum_size(Size2(300 * EDSCALE, 0));
  1208. vars_list->set_hide_root(true);
  1209. vars_list->set_columns(2);
  1210. vars_list->set_column_expand(0, true);
  1211. vars_list->set_column_custom_minimum_width(0, 80 * EDSCALE);
  1212. vars_list->set_column_expand(1, false);
  1213. vars_list->set_column_custom_minimum_width(1, 50 * EDSCALE);
  1214. vars_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1215. page2_side_vb->add_child(vars_list);
  1216. vars_list->connect("item_selected", callable_mp(this, &DynamicFontImportSettings::_variation_selected));
  1217. vars_list->connect("button_clicked", callable_mp(this, &DynamicFontImportSettings::_variation_remove));
  1218. inspector_vars = memnew(EditorInspector);
  1219. inspector_vars->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1220. page2_side_vb->add_child(inspector_vars);
  1221. inspector_vars->connect("property_edited", callable_mp(this, &DynamicFontImportSettings::_variation_changed));
  1222. VBoxContainer *preload_pages_vb = memnew(VBoxContainer);
  1223. page2_hb->add_child(preload_pages_vb);
  1224. preload_pages = memnew(TabContainer);
  1225. preload_pages->set_tab_alignment(TabBar::ALIGNMENT_CENTER);
  1226. preload_pages->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1227. preload_pages->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1228. preload_pages_vb->add_child(preload_pages);
  1229. HBoxContainer *gl_hb = memnew(HBoxContainer);
  1230. gl_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1231. preload_pages_vb->add_child(gl_hb);
  1232. label_glyphs = memnew(Label);
  1233. label_glyphs->set_text(vformat(TTR("Preloaded glyphs: %d"), 0));
  1234. label_glyphs->set_custom_minimum_size(Size2(50 * EDSCALE, 0));
  1235. gl_hb->add_child(label_glyphs);
  1236. Button *btn_clear = memnew(Button);
  1237. btn_clear->set_text(TTR("Clear Glyph List"));
  1238. gl_hb->add_child(btn_clear);
  1239. btn_clear->connect("pressed", callable_mp(this, &DynamicFontImportSettings::_glyph_clear));
  1240. VBoxContainer *page2_0_vb = memnew(VBoxContainer);
  1241. page2_0_vb->set_name(TTR("Glyphs from the Translations"));
  1242. preload_pages->add_child(page2_0_vb);
  1243. page2_0_description = memnew(Label);
  1244. page2_0_description->set_text(TTR("Select translations to add all required glyphs to pre-render list:"));
  1245. page2_0_description->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1246. page2_0_description->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  1247. page2_0_description->set_custom_minimum_size(Size2(300 * EDSCALE, 1));
  1248. page2_0_vb->add_child(page2_0_description);
  1249. locale_tree = memnew(Tree);
  1250. locale_tree->set_columns(1);
  1251. locale_tree->set_hide_root(true);
  1252. locale_tree->set_column_expand(0, true);
  1253. locale_tree->set_column_custom_minimum_width(0, 120 * EDSCALE);
  1254. locale_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1255. page2_0_vb->add_child(locale_tree);
  1256. locale_tree->connect("item_activated", callable_mp(this, &DynamicFontImportSettings::_locale_edited));
  1257. locale_root = locale_tree->create_item();
  1258. HBoxContainer *locale_hb = memnew(HBoxContainer);
  1259. locale_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1260. page2_0_vb->add_child(locale_hb);
  1261. btn_fill_locales = memnew(Button);
  1262. btn_fill_locales->set_text(TTR("Shape all Strings in the Translations and Add Glyphs"));
  1263. locale_hb->add_child(btn_fill_locales);
  1264. btn_fill_locales->connect("pressed", callable_mp(this, &DynamicFontImportSettings::_process_locales));
  1265. // Page 2.1 layout: Text to select glyphs
  1266. VBoxContainer *page2_1_vb = memnew(VBoxContainer);
  1267. page2_1_vb->set_name(TTR("Glyphs from the Text"));
  1268. preload_pages->add_child(page2_1_vb);
  1269. page2_1_description = memnew(Label);
  1270. page2_1_description->set_text(TTR("Enter a text and select OpenType features to shape and add all required glyphs to pre-render list:"));
  1271. page2_1_description->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1272. page2_1_description->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  1273. page2_1_description->set_custom_minimum_size(Size2(300 * EDSCALE, 1));
  1274. page2_1_vb->add_child(page2_1_description);
  1275. HSplitContainer *page2_1_hb = memnew(HSplitContainer);
  1276. page2_1_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1277. page2_1_hb->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1278. page2_1_vb->add_child(page2_1_hb);
  1279. inspector_text = memnew(EditorInspector);
  1280. inspector_text->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1281. inspector_text->set_custom_minimum_size(Size2(300 * EDSCALE, 250 * EDSCALE));
  1282. page2_1_hb->add_child(inspector_text);
  1283. inspector_text->connect("property_edited", callable_mp(this, &DynamicFontImportSettings::_change_text_opts));
  1284. text_edit = memnew(TextEdit);
  1285. text_edit->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1286. text_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1287. page2_1_hb->add_child(text_edit);
  1288. HBoxContainer *text_hb = memnew(HBoxContainer);
  1289. text_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1290. page2_1_vb->add_child(text_hb);
  1291. btn_fill = memnew(Button);
  1292. btn_fill->set_text(TTR("Shape Text and Add Glyphs"));
  1293. text_hb->add_child(btn_fill);
  1294. btn_fill->connect("pressed", callable_mp(this, &DynamicFontImportSettings::_glyph_text_selected));
  1295. // Page 2.2 layout: Character map
  1296. VBoxContainer *page2_2_vb = memnew(VBoxContainer);
  1297. page2_2_vb->set_name(TTR("Glyphs from the Character Map"));
  1298. preload_pages->add_child(page2_2_vb);
  1299. page2_2_description = memnew(Label);
  1300. page2_2_description->set_text(TTR("Add or remove glyphs from the character map to pre-render list:\nNote: Some stylistic alternatives and glyph variants do not have one-to-one correspondence to character, and not shown in this map, use \"Glyphs from the text\" tab to add these."));
  1301. page2_2_description->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1302. page2_2_description->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  1303. page2_2_description->set_custom_minimum_size(Size2(300 * EDSCALE, 1));
  1304. page2_2_vb->add_child(page2_2_description);
  1305. HSplitContainer *glyphs_split = memnew(HSplitContainer);
  1306. glyphs_split->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1307. glyphs_split->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1308. page2_2_vb->add_child(glyphs_split);
  1309. glyph_table = memnew(Tree);
  1310. glyph_table->set_custom_minimum_size(Size2((30 * 16 + 100) * EDSCALE, 0));
  1311. glyph_table->set_columns(17);
  1312. glyph_table->set_column_expand(0, false);
  1313. glyph_table->set_hide_root(true);
  1314. glyph_table->set_allow_reselect(true);
  1315. glyph_table->set_select_mode(Tree::SELECT_SINGLE);
  1316. glyph_table->set_column_titles_visible(true);
  1317. for (int i = 0; i < 16; i++) {
  1318. glyph_table->set_column_title(i + 1, String::num_int64(i, 16));
  1319. }
  1320. glyph_table->add_theme_style_override("selected", glyph_table->get_theme_stylebox(SNAME("panel")));
  1321. glyph_table->add_theme_style_override("selected_focus", glyph_table->get_theme_stylebox(SNAME("panel")));
  1322. glyph_table->add_theme_constant_override("h_separation", 0);
  1323. glyph_table->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1324. glyph_table->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1325. glyphs_split->add_child(glyph_table);
  1326. glyph_table->connect("item_activated", callable_mp(this, &DynamicFontImportSettings::_glyph_selected));
  1327. glyph_tree = memnew(Tree);
  1328. glyph_tree->set_custom_minimum_size(Size2(300 * EDSCALE, 0));
  1329. glyph_tree->set_columns(2);
  1330. glyph_tree->set_hide_root(true);
  1331. glyph_tree->set_column_expand(0, false);
  1332. glyph_tree->set_column_expand(1, true);
  1333. glyph_tree->set_column_custom_minimum_width(0, 120 * EDSCALE);
  1334. glyph_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1335. glyph_root = glyph_tree->create_item();
  1336. for (int i = 0; !unicode_ranges[i].name.is_empty(); i++) {
  1337. _add_glyph_range_item(unicode_ranges[i].start, unicode_ranges[i].end, unicode_ranges[i].name);
  1338. }
  1339. glyphs_split->add_child(glyph_tree);
  1340. glyph_tree->connect("item_activated", callable_mp(this, &DynamicFontImportSettings::_range_edited));
  1341. glyph_tree->connect("item_selected", callable_mp(this, &DynamicFontImportSettings::_range_selected));
  1342. // Common
  1343. import_settings_data.instantiate();
  1344. import_settings_data->owner = this;
  1345. set_ok_button_text(TTR("Reimport"));
  1346. set_cancel_button_text(TTR("Close"));
  1347. }