dynamic_font_import_settings.cpp 58 KB

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