dynamic_font_import_settings.cpp 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620
  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 "core/string/translation.h"
  33. #include "editor/editor_file_system.h"
  34. #include "editor/editor_inspector.h"
  35. #include "editor/editor_locale_dialog.h"
  36. #include "editor/editor_node.h"
  37. #include "editor/editor_string_names.h"
  38. #include "editor/gui/editor_file_dialog.h"
  39. #include "editor/themes/editor_scale.h"
  40. #include "scene/gui/split_container.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")) {
  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/16.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. { 0x105C0, 0x105FF, U"Todhri" },
  276. { 0x10600, 0x1077F, U"Linear A" },
  277. { 0x10780, 0x107BF, U"Latin Extended-F" },
  278. { 0x10800, 0x1083F, U"Cypriot Syllabary" },
  279. { 0x10840, 0x1085F, U"Imperial Aramaic" },
  280. { 0x10860, 0x1087F, U"Palmyrene" },
  281. { 0x10880, 0x108AF, U"Nabataean" },
  282. { 0x108E0, 0x108FF, U"Hatran" },
  283. { 0x10900, 0x1091F, U"Phoenician" },
  284. { 0x10920, 0x1093F, U"Lydian" },
  285. { 0x10980, 0x1099F, U"Meroitic Hieroglyphs" },
  286. { 0x109A0, 0x109FF, U"Meroitic Cursive" },
  287. { 0x10A00, 0x10A5F, U"Kharoshthi" },
  288. { 0x10A60, 0x10A7F, U"Old South Arabian" },
  289. { 0x10A80, 0x10A9F, U"Old North Arabian" },
  290. { 0x10AC0, 0x10AFF, U"Manichaean" },
  291. { 0x10B00, 0x10B3F, U"Avestan" },
  292. { 0x10B40, 0x10B5F, U"Inscriptional Parthian" },
  293. { 0x10B60, 0x10B7F, U"Inscriptional Pahlavi" },
  294. { 0x10B80, 0x10BAF, U"Psalter Pahlavi" },
  295. { 0x10C00, 0x10C4F, U"Old Turkic" },
  296. { 0x10C80, 0x10CFF, U"Old Hungarian" },
  297. { 0x10D00, 0x10D3F, U"Hanifi Rohingya" },
  298. { 0x10D40, 0x10D8F, U"Garay" },
  299. { 0x10E60, 0x10E7F, U"Rumi Numeral Symbols" },
  300. { 0x10E80, 0x10EBF, U"Yezidi" },
  301. { 0x10EC0, 0x10EFF, U"Arabic Extended-C" },
  302. { 0x10F00, 0x10F2F, U"Old Sogdian" },
  303. { 0x10F30, 0x10F6F, U"Sogdian" },
  304. { 0x10F70, 0x10FAF, U"Old Uyghur" },
  305. { 0x10FB0, 0x10FDF, U"Chorasmian" },
  306. { 0x10FE0, 0x10FFF, U"Elymaic" },
  307. { 0x11000, 0x1107F, U"Brahmi" },
  308. { 0x11080, 0x110CF, U"Kaithi" },
  309. { 0x110D0, 0x110FF, U"Sora Sompeng" },
  310. { 0x11100, 0x1114F, U"Chakma" },
  311. { 0x11150, 0x1117F, U"Mahajani" },
  312. { 0x11180, 0x111DF, U"Sharada" },
  313. { 0x111E0, 0x111FF, U"Sinhala Archaic Numbers" },
  314. { 0x11200, 0x1124F, U"Khojki" },
  315. { 0x11280, 0x112AF, U"Multani" },
  316. { 0x112B0, 0x112FF, U"Khudawadi" },
  317. { 0x11300, 0x1137F, U"Grantha" },
  318. { 0x11380, 0x113FF, U"Tulu-Tigalari" },
  319. { 0x11400, 0x1147F, U"Newa" },
  320. { 0x11480, 0x114DF, U"Tirhuta" },
  321. { 0x11580, 0x115FF, U"Siddham" },
  322. { 0x11600, 0x1165F, U"Modi" },
  323. { 0x11660, 0x1167F, U"Mongolian Supplement" },
  324. { 0x11680, 0x116CF, U"Takri" },
  325. { 0x116D0, 0x116FF, U"Myanmar Extended-C" },
  326. { 0x11700, 0x1174F, U"Ahom" },
  327. { 0x11800, 0x1184F, U"Dogra" },
  328. { 0x118A0, 0x118FF, U"Warang Citi" },
  329. { 0x11900, 0x1195F, U"Dives Akuru" },
  330. { 0x119A0, 0x119FF, U"Nandinagari" },
  331. { 0x11A00, 0x11A4F, U"Zanabazar Square" },
  332. { 0x11A50, 0x11AAF, U"Soyombo" },
  333. { 0x11AB0, 0x11ABF, U"Unified Canadian Aboriginal Syllabics Extended-A" },
  334. { 0x11AC0, 0x11AFF, U"Pau Cin Hau" },
  335. { 0x11B00, 0x11B5F, U"Devanagari Extended-A" },
  336. { 0x11BC0, 0x11BFF, U"Sunuwar" },
  337. { 0x11C00, 0x11C6F, U"Bhaiksuki" },
  338. { 0x11C70, 0x11CBF, U"Marchen" },
  339. { 0x11D00, 0x11D5F, U"Masaram Gondi" },
  340. { 0x11D60, 0x11DAF, U"Gunjala Gondi" },
  341. { 0x11EE0, 0x11EFF, U"Makasar" },
  342. { 0x11F00, 0x11F5F, U"Kawi" },
  343. { 0x11FB0, 0x11FBF, U"Lisu Supplement" },
  344. { 0x11FC0, 0x11FFF, U"Tamil Supplement" },
  345. { 0x12000, 0x123FF, U"Cuneiform" },
  346. { 0x12400, 0x1247F, U"Cuneiform Numbers and Punctuation" },
  347. { 0x12480, 0x1254F, U"Early Dynastic Cuneiform" },
  348. { 0x12F90, 0x12FFF, U"Cypro-Minoan" },
  349. { 0x13000, 0x1342F, U"Egyptian Hieroglyphs" },
  350. { 0x13430, 0x1343F, U"Egyptian Hieroglyph Format Controls" },
  351. { 0x13460, 0x143FF, U"Egyptian Hieroglyphs Extended-A" },
  352. { 0x14400, 0x1467F, U"Anatolian Hieroglyphs" },
  353. { 0x16100, 0x1613F, U"Gurung Khema" },
  354. { 0x16800, 0x16A3F, U"Bamum Supplement" },
  355. { 0x16A40, 0x16A6F, U"Mro" },
  356. { 0x16A70, 0x16ACF, U"Tangsa" },
  357. { 0x16AD0, 0x16AFF, U"Bassa Vah" },
  358. { 0x16B00, 0x16B8F, U"Pahawh Hmong" },
  359. { 0x16D40, 0x16D7F, U"Kirat Rai" },
  360. { 0x16E40, 0x16E9F, U"Medefaidrin" },
  361. { 0x16F00, 0x16F9F, U"Miao" },
  362. { 0x16FE0, 0x16FFF, U"Ideographic Symbols and Punctuation" },
  363. { 0x17000, 0x187FF, U"Tangut" },
  364. { 0x18800, 0x18AFF, U"Tangut Components" },
  365. { 0x18B00, 0x18CFF, U"Khitan Small Script" },
  366. { 0x18D00, 0x18D7F, U"Tangut Supplement" },
  367. { 0x1AFF0, 0x1AFFF, U"Kana Extended-B" },
  368. { 0x1B000, 0x1B0FF, U"Kana Supplement" },
  369. { 0x1B100, 0x1B12F, U"Kana Extended-A" },
  370. { 0x1B130, 0x1B16F, U"Small Kana Extension" },
  371. { 0x1B170, 0x1B2FF, U"Nushu" },
  372. { 0x1BC00, 0x1BC9F, U"Duployan" },
  373. { 0x1BCA0, 0x1BCAF, U"Shorthand Format Controls" },
  374. { 0x1CC00, 0x1CEBF, U"Symbols for Legacy Computing Supplement" },
  375. { 0x1CF00, 0x1CFCF, U"Znamenny Musical Notation" },
  376. { 0x1D000, 0x1D0FF, U"Byzantine Musical Symbols" },
  377. { 0x1D100, 0x1D1FF, U"Musical Symbols" },
  378. { 0x1D200, 0x1D24F, U"Ancient Greek Musical Notation" },
  379. { 0x1D2C0, 0x1D2DF, U"Kaktovik Numerals" },
  380. { 0x1D2E0, 0x1D2FF, U"Mayan Numerals" },
  381. { 0x1D300, 0x1D35F, U"Tai Xuan Jing Symbols" },
  382. { 0x1D360, 0x1D37F, U"Counting Rod Numerals" },
  383. { 0x1D400, 0x1D7FF, U"Mathematical Alphanumeric Symbols" },
  384. { 0x1D800, 0x1DAAF, U"Sutton SignWriting" },
  385. { 0x1DF00, 0x1DFFF, U"Latin Extended-G" },
  386. { 0x1E000, 0x1E02F, U"Glagolitic Supplement" },
  387. { 0x1E030, 0x1E08F, U"Cyrillic Extended-D" },
  388. { 0x1E100, 0x1E14F, U"Nyiakeng Puachue Hmong" },
  389. { 0x1E290, 0x1E2BF, U"Toto" },
  390. { 0x1E2C0, 0x1E2FF, U"Wancho" },
  391. { 0x1E4D0, 0x1E4FF, U"Nag Mundari" },
  392. { 0x1E5D0, 0x1E5FF, U"Ol Onal" },
  393. { 0x1E7E0, 0x1E7FF, U"Ethiopic Extended-B" },
  394. { 0x1E800, 0x1E8DF, U"Mende Kikakui" },
  395. { 0x1E900, 0x1E95F, U"Adlam" },
  396. { 0x1EC70, 0x1ECBF, U"Indic Siyaq Numbers" },
  397. { 0x1ED00, 0x1ED4F, U"Ottoman Siyaq Numbers" },
  398. { 0x1EE00, 0x1EEFF, U"Arabic Mathematical Alphabetic Symbols" },
  399. { 0x1F000, 0x1F02F, U"Mahjong Tiles" },
  400. { 0x1F030, 0x1F09F, U"Domino Tiles" },
  401. { 0x1F0A0, 0x1F0FF, U"Playing Cards" },
  402. { 0x1F100, 0x1F1FF, U"Enclosed Alphanumeric Supplement" },
  403. { 0x1F200, 0x1F2FF, U"Enclosed Ideographic Supplement" },
  404. { 0x1F300, 0x1F5FF, U"Miscellaneous Symbols and Pictographs" },
  405. { 0x1F600, 0x1F64F, U"Emoticons" },
  406. { 0x1F650, 0x1F67F, U"Ornamental Dingbats" },
  407. { 0x1F680, 0x1F6FF, U"Transport and Map Symbols" },
  408. { 0x1F700, 0x1F77F, U"Alchemical Symbols" },
  409. { 0x1F780, 0x1F7FF, U"Geometric Shapes Extended" },
  410. { 0x1F800, 0x1F8FF, U"Supplemental Arrows-C" },
  411. { 0x1F900, 0x1F9FF, U"Supplemental Symbols and Pictographs" },
  412. { 0x1FA00, 0x1FA6F, U"Chess Symbols" },
  413. { 0x1FA70, 0x1FAFF, U"Symbols and Pictographs Extended-A" },
  414. { 0x1FB00, 0x1FBFF, U"Symbols for Legacy Computing" },
  415. { 0x20000, 0x2A6DF, U"CJK Unified Ideographs Extension B" },
  416. { 0x2A700, 0x2B73F, U"CJK Unified Ideographs Extension C" },
  417. { 0x2B740, 0x2B81F, U"CJK Unified Ideographs Extension D" },
  418. { 0x2B820, 0x2CEAF, U"CJK Unified Ideographs Extension E" },
  419. { 0x2CEB0, 0x2EBEF, U"CJK Unified Ideographs Extension F" },
  420. { 0x2EBF0, 0x2EE5F, U"CJK Unified Ideographs Extension I" },
  421. { 0x2F800, 0x2FA1F, U"CJK Compatibility Ideographs Supplement" },
  422. { 0x30000, 0x3134F, U"CJK Unified Ideographs Extension G" },
  423. { 0x31350, 0x323AF, U"CJK Unified Ideographs Extension H" },
  424. //{ 0xE0000, 0xE007F, U"Tags" },
  425. //{ 0xE0100, 0xE01EF, U"Variation Selectors Supplement" },
  426. { 0xF0000, 0xFFFFF, U"Supplementary Private Use Area-A" },
  427. { 0x100000, 0x10FFFF, U"Supplementary Private Use Area-B" },
  428. { 0x10FFFF, 0x10FFFF, String() }
  429. };
  430. void DynamicFontImportSettingsDialog::_add_glyph_range_item(int32_t p_start, int32_t p_end, const String &p_name) {
  431. const int page_size = 512;
  432. int pages = (p_end - p_start) / page_size;
  433. int remain = (p_end - p_start) % page_size;
  434. int32_t start = p_start;
  435. for (int i = 0; i < pages; i++) {
  436. TreeItem *item = glyph_tree->create_item(glyph_root);
  437. ERR_FAIL_NULL(item);
  438. item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  439. item->set_text(0, _pad_zeros(String::num_int64(start, 16)) + " - " + _pad_zeros(String::num_int64(start + page_size, 16)));
  440. item->set_text(1, p_name);
  441. item->set_metadata(0, Vector2i(start, start + page_size));
  442. start += page_size;
  443. }
  444. if (remain > 0) {
  445. TreeItem *item = glyph_tree->create_item(glyph_root);
  446. ERR_FAIL_NULL(item);
  447. item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  448. item->set_text(0, _pad_zeros(String::num_int64(start, 16)) + " - " + _pad_zeros(String::num_int64(p_end, 16)));
  449. item->set_text(1, p_name);
  450. item->set_metadata(0, Vector2i(start, p_end));
  451. }
  452. }
  453. /*************************************************************************/
  454. /* Page 1 callbacks: Rendering Options */
  455. /*************************************************************************/
  456. void DynamicFontImportSettingsDialog::_main_prop_changed(const String &p_edited_property) {
  457. // Update font preview.
  458. if (font_preview.is_valid()) {
  459. if (p_edited_property == "antialiasing") {
  460. font_preview->set_antialiasing((TextServer::FontAntialiasing)import_settings_data->get("antialiasing").operator int());
  461. _variations_validate();
  462. } else if (p_edited_property == "generate_mipmaps") {
  463. font_preview->set_generate_mipmaps(import_settings_data->get("generate_mipmaps"));
  464. } else if (p_edited_property == "disable_embedded_bitmaps") {
  465. font_preview->set_disable_embedded_bitmaps(import_settings_data->get("disable_embedded_bitmaps"));
  466. } else if (p_edited_property == "multichannel_signed_distance_field") {
  467. font_preview->set_multichannel_signed_distance_field(import_settings_data->get("multichannel_signed_distance_field"));
  468. _variation_selected();
  469. _variations_validate();
  470. } else if (p_edited_property == "msdf_pixel_range") {
  471. font_preview->set_msdf_pixel_range(import_settings_data->get("msdf_pixel_range"));
  472. } else if (p_edited_property == "msdf_size") {
  473. font_preview->set_msdf_size(import_settings_data->get("msdf_size"));
  474. } else if (p_edited_property == "allow_system_fallback") {
  475. font_preview->set_allow_system_fallback(import_settings_data->get("allow_system_fallback"));
  476. } else if (p_edited_property == "force_autohinter") {
  477. font_preview->set_force_autohinter(import_settings_data->get("force_autohinter"));
  478. } else if (p_edited_property == "modulate_color_glyphs") {
  479. font_preview->set_modulate_color_glyphs(import_settings_data->get("modulate_color_glyphs"));
  480. } else if (p_edited_property == "hinting") {
  481. font_preview->set_hinting((TextServer::Hinting)import_settings_data->get("hinting").operator int());
  482. } else if (p_edited_property == "subpixel_positioning") {
  483. int font_subpixel_positioning = import_settings_data->get("subpixel_positioning").operator int();
  484. if (font_subpixel_positioning == 4 /* Auto (Except Pixel Fonts) */) {
  485. if (is_pixel) {
  486. font_subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_DISABLED;
  487. } else {
  488. font_subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO;
  489. }
  490. }
  491. font_preview->set_subpixel_positioning((TextServer::SubpixelPositioning)font_subpixel_positioning);
  492. _variations_validate();
  493. } else if (p_edited_property == "keep_rounding_remainders") {
  494. font_preview->set_keep_rounding_remainders(import_settings_data->get("keep_rounding_remainders"));
  495. }
  496. }
  497. font_preview_label->add_theme_font_override(SceneStringName(font), font_preview);
  498. font_preview_label->add_theme_font_size_override(SceneStringName(font_size), 200 * EDSCALE);
  499. font_preview_label->queue_redraw();
  500. }
  501. /*************************************************************************/
  502. /* Page 2 callbacks: Configurations */
  503. /*************************************************************************/
  504. void DynamicFontImportSettingsDialog::_variation_add() {
  505. TreeItem *vars_item = vars_list->create_item(vars_list_root);
  506. ERR_FAIL_NULL(vars_item);
  507. vars_item->set_text(0, TTR("New Configuration"));
  508. vars_item->set_editable(0, true);
  509. vars_item->add_button(1, get_editor_theme_icon(SNAME("Remove")), BUTTON_REMOVE_VAR, false, TTR("Remove Variation"));
  510. vars_item->set_button_color(1, 0, Color(1, 1, 1, 0.75));
  511. Ref<DynamicFontImportSettingsData> import_variation_data;
  512. import_variation_data.instantiate();
  513. import_variation_data->owner = this;
  514. ERR_FAIL_COND(import_variation_data.is_null());
  515. for (const ResourceImporter::ImportOption &option : options_variations) {
  516. import_variation_data->defaults[option.option.name] = option.default_value;
  517. }
  518. import_variation_data->options = options_variations;
  519. inspector_vars->edit(import_variation_data.ptr());
  520. import_variation_data->notify_property_list_changed();
  521. import_variation_data->fd = font_main;
  522. vars_item->set_metadata(0, import_variation_data);
  523. _variations_validate();
  524. }
  525. void DynamicFontImportSettingsDialog::_variation_selected() {
  526. TreeItem *vars_item = vars_list->get_selected();
  527. if (vars_item) {
  528. Ref<DynamicFontImportSettingsData> import_variation_data = vars_item->get_metadata(0);
  529. ERR_FAIL_COND(import_variation_data.is_null());
  530. inspector_vars->edit(import_variation_data.ptr());
  531. import_variation_data->notify_property_list_changed();
  532. label_glyphs->set_text(vformat(TTR("Preloaded glyphs: %d"), import_variation_data->selected_glyphs.size()));
  533. _range_selected();
  534. _change_text_opts();
  535. btn_fill->set_disabled(false);
  536. btn_fill_locales->set_disabled(false);
  537. } else {
  538. btn_fill->set_disabled(true);
  539. btn_fill_locales->set_disabled(true);
  540. }
  541. }
  542. void DynamicFontImportSettingsDialog::_variation_remove(Object *p_item, int p_column, int p_id, MouseButton p_button) {
  543. if (p_button != MouseButton::LEFT) {
  544. return;
  545. }
  546. TreeItem *vars_item = (TreeItem *)p_item;
  547. ERR_FAIL_NULL(vars_item);
  548. inspector_vars->edit(nullptr);
  549. vars_list_root->remove_child(vars_item);
  550. memdelete(vars_item);
  551. if (vars_list_root->get_first_child()) {
  552. Ref<DynamicFontImportSettingsData> import_variation_data = vars_list_root->get_first_child()->get_metadata(0);
  553. inspector_vars->edit(import_variation_data.ptr());
  554. import_variation_data->notify_property_list_changed();
  555. }
  556. _variations_validate();
  557. vars_item = vars_list->get_selected();
  558. if (vars_item) {
  559. btn_fill->set_disabled(false);
  560. btn_fill_locales->set_disabled(false);
  561. } else {
  562. btn_fill->set_disabled(true);
  563. btn_fill_locales->set_disabled(true);
  564. }
  565. }
  566. void DynamicFontImportSettingsDialog::_variation_changed(const String &p_edited_property) {
  567. _variations_validate();
  568. }
  569. void DynamicFontImportSettingsDialog::_variations_validate() {
  570. String warn;
  571. if (!vars_list_root->get_first_child()) {
  572. warn = TTR("Warning: There are no configurations specified, no glyphs will be pre-rendered.");
  573. }
  574. for (TreeItem *vars_item_a = vars_list_root->get_first_child(); vars_item_a; vars_item_a = vars_item_a->get_next()) {
  575. Ref<DynamicFontImportSettingsData> import_variation_data_a = vars_item_a->get_metadata(0);
  576. ERR_FAIL_COND(import_variation_data_a.is_null());
  577. for (TreeItem *vars_item_b = vars_list_root->get_first_child(); vars_item_b; vars_item_b = vars_item_b->get_next()) {
  578. if (vars_item_b != vars_item_a) {
  579. bool match = true;
  580. for (const KeyValue<StringName, Variant> &E : import_variation_data_a->settings) {
  581. Ref<DynamicFontImportSettingsData> import_variation_data_b = vars_item_b->get_metadata(0);
  582. ERR_FAIL_COND(import_variation_data_b.is_null());
  583. match = match && (import_variation_data_b->settings[E.key] == E.value);
  584. }
  585. if (match) {
  586. warn = TTR("Warning: Multiple configurations have identical settings. Duplicates will be ignored.");
  587. break;
  588. }
  589. }
  590. }
  591. }
  592. if ((TextServer::FontAntialiasing)(int)import_settings_data->get("antialiasing") == TextServer::FONT_ANTIALIASING_LCD) {
  593. warn += "\n" + TTR("Note: LCD Subpixel antialiasing is selected, each of the glyphs will be pre-rendered for all supported subpixel layouts (5x).");
  594. }
  595. int font_subpixel_positioning = import_settings_data->get("subpixel_positioning").operator int();
  596. if (font_subpixel_positioning == 4 /* Auto (Except Pixel Fonts) */) {
  597. if (is_pixel) {
  598. font_subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_DISABLED;
  599. } else {
  600. font_subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO;
  601. }
  602. }
  603. if ((TextServer::SubpixelPositioning)font_subpixel_positioning != TextServer::SUBPIXEL_POSITIONING_DISABLED) {
  604. warn += "\n" + TTR("Note: Subpixel positioning is selected, each of the glyphs might be pre-rendered for multiple subpixel offsets (up to 4x).");
  605. }
  606. if (warn.is_empty()) {
  607. label_warn->set_text("");
  608. label_warn->hide();
  609. } else {
  610. label_warn->set_text(warn);
  611. label_warn->show();
  612. }
  613. }
  614. /*************************************************************************/
  615. /* Page 2.1 callbacks: Text to select glyphs */
  616. /*************************************************************************/
  617. void DynamicFontImportSettingsDialog::_change_text_opts() {
  618. Ref<DynamicFontImportSettingsData> import_variation_data;
  619. TreeItem *vars_item = vars_list->get_selected();
  620. if (vars_item) {
  621. import_variation_data = vars_item->get_metadata(0);
  622. }
  623. if (import_variation_data.is_null()) {
  624. return;
  625. }
  626. Ref<FontVariation> font_main_text;
  627. font_main_text.instantiate();
  628. font_main_text->set_base_font(font_main);
  629. font_main_text->set_opentype_features(text_settings_data->get("opentype_features"));
  630. font_main_text->set_variation_opentype(import_variation_data->get("variation_opentype"));
  631. font_main_text->set_variation_embolden(import_variation_data->get("variation_embolden"));
  632. font_main_text->set_variation_face_index(import_variation_data->get("variation_face_index"));
  633. font_main_text->set_variation_transform(import_variation_data->get("variation_transform"));
  634. text_edit->add_theme_font_override(SceneStringName(font), font_main_text);
  635. }
  636. void DynamicFontImportSettingsDialog::_glyph_update_lbl() {
  637. Ref<DynamicFontImportSettingsData> import_variation_data;
  638. TreeItem *vars_item = vars_list->get_selected();
  639. if (vars_item) {
  640. import_variation_data = vars_item->get_metadata(0);
  641. }
  642. if (import_variation_data.is_null()) {
  643. return;
  644. }
  645. int linked_glyphs = 0;
  646. for (const char32_t &c : import_variation_data->selected_chars) {
  647. if (import_variation_data->selected_glyphs.has(font_main->get_glyph_index(16, c))) {
  648. linked_glyphs++;
  649. }
  650. }
  651. int unlinked_glyphs = import_variation_data->selected_glyphs.size() - linked_glyphs;
  652. label_glyphs->set_text(vformat(TTR("Preloaded glyphs: %d"), unlinked_glyphs + import_variation_data->selected_chars.size()));
  653. }
  654. void DynamicFontImportSettingsDialog::_glyph_clear() {
  655. Ref<DynamicFontImportSettingsData> import_variation_data;
  656. TreeItem *vars_item = vars_list->get_selected();
  657. if (vars_item) {
  658. import_variation_data = vars_item->get_metadata(0);
  659. }
  660. if (import_variation_data.is_null()) {
  661. return;
  662. }
  663. import_variation_data->selected_glyphs.clear();
  664. _glyph_update_lbl();
  665. _range_selected();
  666. }
  667. void DynamicFontImportSettingsDialog::_glyph_text_selected() {
  668. Ref<DynamicFontImportSettingsData> import_variation_data;
  669. TreeItem *vars_item = vars_list->get_selected();
  670. if (vars_item) {
  671. import_variation_data = vars_item->get_metadata(0);
  672. }
  673. if (import_variation_data.is_null()) {
  674. return;
  675. }
  676. RID text_rid = TS->create_shaped_text();
  677. if (text_rid.is_valid()) {
  678. 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"));
  679. TS->shaped_text_shape(text_rid);
  680. const Glyph *gl = TS->shaped_text_get_glyphs(text_rid);
  681. const int gl_size = TS->shaped_text_get_glyph_count(text_rid);
  682. for (int i = 0; i < gl_size; i++) {
  683. if (gl[i].font_rid.is_valid() && gl[i].index != 0) {
  684. import_variation_data->selected_glyphs.insert(gl[i].index);
  685. }
  686. }
  687. TS->free_rid(text_rid);
  688. _glyph_update_lbl();
  689. }
  690. _range_selected();
  691. }
  692. /*************************************************************************/
  693. /* Page 2.2 callbacks: Character map */
  694. /*************************************************************************/
  695. void DynamicFontImportSettingsDialog::_glyph_selected() {
  696. Ref<DynamicFontImportSettingsData> import_variation_data;
  697. TreeItem *vars_item = vars_list->get_selected();
  698. if (vars_item) {
  699. import_variation_data = vars_item->get_metadata(0);
  700. }
  701. if (import_variation_data.is_null()) {
  702. return;
  703. }
  704. TreeItem *item = glyph_table->get_selected();
  705. ERR_FAIL_NULL(item);
  706. Color scol = glyph_table->get_theme_color(SNAME("box_selection_fill_color"), EditorStringName(Editor));
  707. Color fcol = glyph_table->get_theme_color(SNAME("font_selected_color"), EditorStringName(Editor));
  708. scol.a = 1.f;
  709. int32_t c = item->get_metadata(glyph_table->get_selected_column());
  710. if (font_main->has_char(c)) {
  711. if (_char_update(c)) {
  712. item->set_custom_color(glyph_table->get_selected_column(), fcol);
  713. item->set_custom_bg_color(glyph_table->get_selected_column(), scol);
  714. } else {
  715. item->clear_custom_color(glyph_table->get_selected_column());
  716. item->clear_custom_bg_color(glyph_table->get_selected_column());
  717. }
  718. }
  719. _glyph_update_lbl();
  720. item = glyph_tree->get_selected();
  721. ERR_FAIL_NULL(item);
  722. Vector2i range = item->get_metadata(0);
  723. int total_chars = range.y - range.x;
  724. int selected_count = 0;
  725. for (int i = range.x; i < range.y; i++) {
  726. if (!font_main->has_char(i)) {
  727. total_chars--;
  728. }
  729. if (import_variation_data->selected_chars.has(i)) {
  730. selected_count++;
  731. }
  732. }
  733. if (selected_count == total_chars) {
  734. item->set_checked(0, true);
  735. } else if (selected_count > 0) {
  736. item->set_indeterminate(0, true);
  737. } else {
  738. item->set_checked(0, false);
  739. }
  740. }
  741. void DynamicFontImportSettingsDialog::_range_edited() {
  742. TreeItem *item = glyph_tree->get_selected();
  743. ERR_FAIL_NULL(item);
  744. Vector2i range = item->get_metadata(0);
  745. _range_update(range.x, range.y);
  746. }
  747. void DynamicFontImportSettingsDialog::_range_selected() {
  748. TreeItem *item = glyph_tree->get_selected();
  749. if (item) {
  750. Vector2i range = item->get_metadata(0);
  751. _edit_range(range.x, range.y);
  752. }
  753. }
  754. void DynamicFontImportSettingsDialog::_edit_range(int32_t p_start, int32_t p_end) {
  755. Ref<DynamicFontImportSettingsData> import_variation_data;
  756. TreeItem *vars_item = vars_list->get_selected();
  757. if (vars_item) {
  758. import_variation_data = vars_item->get_metadata(0);
  759. }
  760. if (import_variation_data.is_null()) {
  761. return;
  762. }
  763. glyph_table->clear();
  764. TreeItem *root = glyph_table->create_item();
  765. ERR_FAIL_NULL(root);
  766. Color scol = glyph_table->get_theme_color(SNAME("box_selection_fill_color"), EditorStringName(Editor));
  767. Color fcol = glyph_table->get_theme_color(SNAME("font_selected_color"), EditorStringName(Editor));
  768. scol.a = 1.f;
  769. TreeItem *item = nullptr;
  770. int col = 0;
  771. Ref<Font> font_main_big = font_main->duplicate();
  772. for (int32_t c = p_start; c <= p_end; c++) {
  773. if (col == 0) {
  774. item = glyph_table->create_item(root);
  775. ERR_FAIL_NULL(item);
  776. item->set_text(0, _pad_zeros(String::num_int64(c, 16)));
  777. item->set_text_alignment(0, HORIZONTAL_ALIGNMENT_LEFT);
  778. item->set_selectable(0, false);
  779. item->set_custom_bg_color(0, glyph_table->get_theme_color(SNAME("dark_color_3"), EditorStringName(Editor)));
  780. }
  781. if (font_main->has_char(c)) {
  782. item->set_text(col + 1, String::chr(c));
  783. item->set_custom_color(col + 1, Color(1, 1, 1));
  784. if (import_variation_data->selected_chars.has(c) || import_variation_data->selected_glyphs.has(font_main->get_glyph_index(16, c))) {
  785. item->set_custom_color(col + 1, fcol);
  786. item->set_custom_bg_color(col + 1, scol);
  787. } else {
  788. item->clear_custom_color(col + 1);
  789. item->clear_custom_bg_color(col + 1);
  790. }
  791. } else {
  792. item->set_custom_bg_color(col + 1, glyph_table->get_theme_color(SNAME("dark_color_2"), EditorStringName(Editor)));
  793. }
  794. item->set_metadata(col + 1, c);
  795. item->set_text_alignment(col + 1, HORIZONTAL_ALIGNMENT_CENTER);
  796. item->set_selectable(col + 1, true);
  797. item->set_custom_font(col + 1, font_main_big);
  798. item->set_custom_font_size(col + 1, get_theme_font_size(SceneStringName(font_size)) * 2);
  799. col++;
  800. if (col == 16) {
  801. col = 0;
  802. }
  803. }
  804. _glyph_update_lbl();
  805. }
  806. bool DynamicFontImportSettingsDialog::_char_update(int32_t p_char) {
  807. Ref<DynamicFontImportSettingsData> import_variation_data;
  808. TreeItem *vars_item = vars_list->get_selected();
  809. if (vars_item) {
  810. import_variation_data = vars_item->get_metadata(0);
  811. }
  812. if (import_variation_data.is_null()) {
  813. return false;
  814. }
  815. if (import_variation_data->selected_chars.has(p_char)) {
  816. import_variation_data->selected_chars.erase(p_char);
  817. return false;
  818. } else if (font_main.is_valid() && import_variation_data->selected_glyphs.has(font_main->get_glyph_index(16, p_char))) {
  819. import_variation_data->selected_glyphs.erase(font_main->get_glyph_index(16, p_char));
  820. return false;
  821. } else {
  822. import_variation_data->selected_chars.insert(p_char);
  823. return true;
  824. }
  825. }
  826. void DynamicFontImportSettingsDialog::_range_update(int32_t p_start, int32_t p_end) {
  827. Ref<DynamicFontImportSettingsData> import_variation_data;
  828. TreeItem *vars_item = vars_list->get_selected();
  829. if (vars_item) {
  830. import_variation_data = vars_item->get_metadata(0);
  831. }
  832. if (import_variation_data.is_null()) {
  833. return;
  834. }
  835. bool all_selected = true;
  836. for (int32_t i = p_start; i <= p_end; i++) {
  837. if (font_main->has_char(i)) {
  838. if (font_main.is_valid()) {
  839. all_selected = all_selected && (import_variation_data->selected_chars.has(i) || import_variation_data->selected_glyphs.has(font_main->get_glyph_index(16, i)));
  840. } else {
  841. all_selected = all_selected && import_variation_data->selected_chars.has(i);
  842. }
  843. }
  844. }
  845. for (int32_t i = p_start; i <= p_end; i++) {
  846. if (font_main->has_char(i)) {
  847. if (!all_selected) {
  848. import_variation_data->selected_chars.insert(i);
  849. } else {
  850. import_variation_data->selected_chars.erase(i);
  851. if (font_main.is_valid()) {
  852. import_variation_data->selected_glyphs.erase(font_main->get_glyph_index(16, i));
  853. }
  854. }
  855. }
  856. }
  857. _edit_range(p_start, p_end);
  858. TreeItem *item = glyph_tree->get_selected();
  859. ERR_FAIL_NULL(item);
  860. item->set_checked(0, !all_selected);
  861. }
  862. /*************************************************************************/
  863. /* Common */
  864. /*************************************************************************/
  865. DynamicFontImportSettingsDialog *DynamicFontImportSettingsDialog::singleton = nullptr;
  866. String DynamicFontImportSettingsDialog::_pad_zeros(const String &p_hex) const {
  867. int len = CLAMP(5 - p_hex.length(), 0, 5);
  868. return String("0").repeat(len) + p_hex;
  869. }
  870. void DynamicFontImportSettingsDialog::_notification(int p_what) {
  871. switch (p_what) {
  872. case NOTIFICATION_READY: {
  873. connect(SceneStringName(confirmed), callable_mp(this, &DynamicFontImportSettingsDialog::_re_import));
  874. } break;
  875. case NOTIFICATION_THEME_CHANGED: {
  876. add_var->set_button_icon(get_editor_theme_icon(SNAME("Add")));
  877. label_warn->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
  878. } break;
  879. }
  880. }
  881. void DynamicFontImportSettingsDialog::_re_import() {
  882. HashMap<StringName, Variant> main_settings;
  883. main_settings["face_index"] = import_settings_data->get("face_index");
  884. main_settings["antialiasing"] = import_settings_data->get("antialiasing");
  885. main_settings["generate_mipmaps"] = import_settings_data->get("generate_mipmaps");
  886. main_settings["disable_embedded_bitmaps"] = import_settings_data->get("disable_embedded_bitmaps");
  887. main_settings["multichannel_signed_distance_field"] = import_settings_data->get("multichannel_signed_distance_field");
  888. main_settings["msdf_pixel_range"] = import_settings_data->get("msdf_pixel_range");
  889. main_settings["msdf_size"] = import_settings_data->get("msdf_size");
  890. main_settings["allow_system_fallback"] = import_settings_data->get("allow_system_fallback");
  891. main_settings["force_autohinter"] = import_settings_data->get("force_autohinter");
  892. main_settings["modulate_color_glyphs"] = import_settings_data->get("modulate_color_glyphs");
  893. main_settings["hinting"] = import_settings_data->get("hinting");
  894. main_settings["subpixel_positioning"] = import_settings_data->get("subpixel_positioning");
  895. main_settings["keep_rounding_remainders"] = import_settings_data->get("keep_rounding_remainders");
  896. main_settings["fallbacks"] = import_settings_data->get("fallbacks");
  897. main_settings["compress"] = import_settings_data->get("compress");
  898. Array configurations;
  899. for (TreeItem *vars_item = vars_list_root->get_first_child(); vars_item; vars_item = vars_item->get_next()) {
  900. Ref<DynamicFontImportSettingsData> import_variation_data = vars_item->get_metadata(0);
  901. ERR_FAIL_COND(import_variation_data.is_null());
  902. Dictionary preload_config;
  903. preload_config["name"] = vars_item->get_text(0);
  904. Size2i conf_size = Vector2i(16, 0);
  905. for (const KeyValue<StringName, Variant> &E : import_variation_data->settings) {
  906. if (E.key == "size") {
  907. conf_size.x = E.value;
  908. }
  909. if (E.key == "outline_size") {
  910. conf_size.y = E.value;
  911. } else {
  912. preload_config[E.key] = E.value;
  913. }
  914. }
  915. preload_config["size"] = conf_size;
  916. Array chars;
  917. for (const char32_t &E : import_variation_data->selected_chars) {
  918. chars.push_back(E);
  919. }
  920. preload_config["chars"] = chars;
  921. Array glyphs;
  922. for (const int32_t &E : import_variation_data->selected_glyphs) {
  923. glyphs.push_back(E);
  924. }
  925. preload_config["glyphs"] = glyphs;
  926. configurations.push_back(preload_config);
  927. }
  928. main_settings["preload"] = configurations;
  929. main_settings["language_support"] = import_settings_data->get("language_support");
  930. main_settings["script_support"] = import_settings_data->get("script_support");
  931. main_settings["opentype_features"] = import_settings_data->get("opentype_features");
  932. if (OS::get_singleton()->is_stdout_verbose()) {
  933. print_line("Import settings:");
  934. for (const KeyValue<StringName, Variant> &E : main_settings) {
  935. print_line(String(" ") + String(E.key).utf8().get_data() + " == " + String(E.value).utf8().get_data());
  936. }
  937. }
  938. EditorFileSystem::get_singleton()->reimport_file_with_custom_parameters(base_path, "font_data_dynamic", main_settings);
  939. }
  940. void DynamicFontImportSettingsDialog::_locale_edited() {
  941. TreeItem *item = locale_tree->get_selected();
  942. ERR_FAIL_NULL(item);
  943. item->set_checked(0, !item->is_checked(0));
  944. }
  945. void DynamicFontImportSettingsDialog::_process_locales() {
  946. Ref<DynamicFontImportSettingsData> import_variation_data;
  947. TreeItem *vars_item = vars_list->get_selected();
  948. if (vars_item) {
  949. import_variation_data = vars_item->get_metadata(0);
  950. }
  951. if (import_variation_data.is_null()) {
  952. return;
  953. }
  954. for (int i = 0; i < locale_root->get_child_count(); i++) {
  955. TreeItem *item = locale_root->get_child(i);
  956. if (item) {
  957. if (item->is_checked(0)) {
  958. String locale = item->get_text(0);
  959. Ref<Translation> tr = ResourceLoader::load(locale);
  960. if (tr.is_valid()) {
  961. Vector<String> messages = tr->get_translated_message_list();
  962. for (const String &E : messages) {
  963. RID text_rid = TS->create_shaped_text();
  964. if (text_rid.is_valid()) {
  965. TS->shaped_text_add_string(text_rid, E, font_main->get_rids(), 16, Dictionary(), tr->get_locale());
  966. TS->shaped_text_shape(text_rid);
  967. const Glyph *gl = TS->shaped_text_get_glyphs(text_rid);
  968. const int gl_size = TS->shaped_text_get_glyph_count(text_rid);
  969. for (int j = 0; j < gl_size; j++) {
  970. if (gl[j].font_rid.is_valid() && gl[j].index != 0) {
  971. import_variation_data->selected_glyphs.insert(gl[j].index);
  972. }
  973. }
  974. TS->free_rid(text_rid);
  975. }
  976. }
  977. }
  978. }
  979. }
  980. }
  981. _glyph_update_lbl();
  982. _range_selected();
  983. }
  984. void DynamicFontImportSettingsDialog::open_settings(const String &p_path) {
  985. // Load base font data.
  986. Vector<uint8_t> font_data = FileAccess::get_file_as_bytes(p_path);
  987. // Load project locale list.
  988. locale_tree->clear();
  989. locale_root = locale_tree->create_item();
  990. ERR_FAIL_NULL(locale_root);
  991. Vector<String> translations = GLOBAL_GET("internationalization/locale/translations");
  992. for (const String &E : translations) {
  993. TreeItem *item = locale_tree->create_item(locale_root);
  994. ERR_FAIL_NULL(item);
  995. item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  996. item->set_text(0, E);
  997. }
  998. // Load font for preview.
  999. font_preview.instantiate();
  1000. font_preview->set_data(font_data);
  1001. Array rids = font_preview->get_rids();
  1002. if (!rids.is_empty()) {
  1003. PackedInt32Array glyphs = TS->font_get_supported_glyphs(rids[0]);
  1004. is_pixel = true;
  1005. for (int32_t gl : glyphs) {
  1006. Dictionary ct = TS->font_get_glyph_contours(rids[0], 16, gl);
  1007. PackedInt32Array contours = ct["contours"];
  1008. PackedVector3Array points = ct["points"];
  1009. int prev_start = 0;
  1010. for (int i = 0; i < contours.size(); i++) {
  1011. for (int j = prev_start; j <= contours[i]; j++) {
  1012. int next_point = (j < contours[i]) ? (j + 1) : prev_start;
  1013. if ((points[j].z != TextServer::CONTOUR_CURVE_TAG_ON) || (!Math::is_equal_approx(points[j].x, points[next_point].x) && !Math::is_equal_approx(points[j].y, points[next_point].y))) {
  1014. is_pixel = false;
  1015. break;
  1016. }
  1017. }
  1018. prev_start = contours[i] + 1;
  1019. if (!is_pixel) {
  1020. break;
  1021. }
  1022. }
  1023. if (!is_pixel) {
  1024. break;
  1025. }
  1026. }
  1027. }
  1028. String font_name = vformat("%s (%s)", font_preview->get_font_name(), font_preview->get_font_style_name());
  1029. String sample;
  1030. static const String sample_base = U"12漢字ԱբΑαАбΑαאבابܐܒހށआআਆઆଆஆఆಆആආกิກິༀကႠა한글ሀᎣᐁᚁᚠᜀᜠᝀᝠកᠠᤁᥐAb😀";
  1031. for (int i = 0; i < sample_base.length(); i++) {
  1032. if (font_preview->has_char(sample_base[i])) {
  1033. sample += sample_base[i];
  1034. }
  1035. }
  1036. if (sample.is_empty()) {
  1037. sample = font_preview->get_supported_chars().substr(0, 6);
  1038. }
  1039. font_preview_label->set_text(sample);
  1040. Ref<Font> bold_font = get_theme_font(SNAME("bold"), EditorStringName(EditorFonts));
  1041. if (bold_font.is_valid()) {
  1042. font_name_label->add_theme_font_override("bold_font", bold_font);
  1043. }
  1044. font_name_label->set_text(font_name);
  1045. // Load second copy of font with MSDF disabled for the glyph table and metadata extraction.
  1046. font_main.instantiate();
  1047. font_main->set_data(font_data);
  1048. font_main->set_multichannel_signed_distance_field(false);
  1049. text_edit->add_theme_font_override(SceneStringName(font), font_main);
  1050. base_path = p_path;
  1051. inspector_vars->edit(nullptr);
  1052. inspector_text->edit(nullptr);
  1053. inspector_general->edit(nullptr);
  1054. text_settings_data.instantiate();
  1055. ERR_FAIL_COND(text_settings_data.is_null());
  1056. text_settings_data->owner = this;
  1057. for (const ResourceImporter::ImportOption &option : options_text) {
  1058. text_settings_data->defaults[option.option.name] = option.default_value;
  1059. }
  1060. text_settings_data->fd = font_main;
  1061. text_settings_data->options = options_text;
  1062. inspector_text->edit(text_settings_data.ptr());
  1063. int gww = get_theme_font(SceneStringName(font))->get_string_size("00000").x + 50;
  1064. glyph_table->set_column_custom_minimum_width(0, gww);
  1065. glyph_table->clear();
  1066. vars_list->clear();
  1067. glyph_tree->set_selected(glyph_root->get_child(0));
  1068. vars_list_root = vars_list->create_item();
  1069. import_settings_data->settings.clear();
  1070. import_settings_data->defaults.clear();
  1071. for (const ResourceImporter::ImportOption &option : options_general) {
  1072. import_settings_data->defaults[option.option.name] = option.default_value;
  1073. }
  1074. Ref<ConfigFile> config;
  1075. config.instantiate();
  1076. ERR_FAIL_COND(config.is_null());
  1077. Error err = config->load(p_path + ".import");
  1078. print_verbose("Loading import settings:");
  1079. if (err == OK) {
  1080. List<String> keys;
  1081. config->get_section_keys("params", &keys);
  1082. for (const String &key : keys) {
  1083. print_verbose(String(" ") + key + " == " + String(config->get_value("params", key)));
  1084. if (key == "preload") {
  1085. Array preload_configurations = config->get_value("params", key);
  1086. for (int i = 0; i < preload_configurations.size(); i++) {
  1087. Dictionary preload_config = preload_configurations[i];
  1088. Dictionary variation = preload_config.has("variation_opentype") ? preload_config["variation_opentype"].operator Dictionary() : Dictionary();
  1089. double embolden = preload_config.has("variation_embolden") ? preload_config["variation_embolden"].operator double() : 0;
  1090. int face_index = preload_config.has("variation_face_index") ? preload_config["variation_face_index"].operator int() : 0;
  1091. Transform2D transform = preload_config.has("variation_transform") ? preload_config["variation_transform"].operator Transform2D() : Transform2D();
  1092. Vector2i font_size = preload_config.has("size") ? preload_config["size"].operator Vector2i() : Vector2i(16, 0);
  1093. String cfg_name = preload_config.has("name") ? preload_config["name"].operator String() : vformat("Configuration %d", i);
  1094. TreeItem *vars_item = vars_list->create_item(vars_list_root);
  1095. ERR_FAIL_NULL(vars_item);
  1096. vars_item->set_text(0, cfg_name);
  1097. vars_item->set_editable(0, true);
  1098. vars_item->add_button(1, get_editor_theme_icon(SNAME("Remove")), BUTTON_REMOVE_VAR, false, TTR("Remove Variation"));
  1099. vars_item->set_button_color(1, 0, Color(1, 1, 1, 0.75));
  1100. Ref<DynamicFontImportSettingsData> import_variation_data_custom;
  1101. import_variation_data_custom.instantiate();
  1102. ERR_FAIL_COND(import_variation_data_custom.is_null());
  1103. import_variation_data_custom->owner = this;
  1104. for (const ResourceImporter::ImportOption &option : options_variations) {
  1105. import_variation_data_custom->defaults[option.option.name] = option.default_value;
  1106. }
  1107. import_variation_data_custom->fd = font_main;
  1108. import_variation_data_custom->options = options_variations;
  1109. vars_item->set_metadata(0, import_variation_data_custom);
  1110. import_variation_data_custom->set("size", font_size.x);
  1111. import_variation_data_custom->set("outline_size", font_size.y);
  1112. import_variation_data_custom->set("variation_opentype", variation);
  1113. import_variation_data_custom->set("variation_embolden", embolden);
  1114. import_variation_data_custom->set("variation_face_index", face_index);
  1115. import_variation_data_custom->set("variation_transform", transform);
  1116. Array chars = preload_config["chars"];
  1117. for (int j = 0; j < chars.size(); j++) {
  1118. char32_t c = chars[j].operator int();
  1119. import_variation_data_custom->selected_chars.insert(c);
  1120. }
  1121. Array glyphs = preload_config["glyphs"];
  1122. for (int j = 0; j < glyphs.size(); j++) {
  1123. int32_t c = glyphs[j];
  1124. import_variation_data_custom->selected_glyphs.insert(c);
  1125. }
  1126. }
  1127. if (preload_configurations.is_empty()) {
  1128. _variation_add(); // Add default variation.
  1129. }
  1130. vars_list->set_selected(vars_list_root->get_child(0));
  1131. } else {
  1132. Variant value = config->get_value("params", key);
  1133. import_settings_data->defaults[key] = value;
  1134. }
  1135. }
  1136. }
  1137. import_settings_data->fd = font_main;
  1138. import_settings_data->options = options_general;
  1139. inspector_general->edit(import_settings_data.ptr());
  1140. import_settings_data->notify_property_list_changed();
  1141. if (font_preview.is_valid()) {
  1142. font_preview->set_antialiasing((TextServer::FontAntialiasing)import_settings_data->get("antialiasing").operator int());
  1143. font_preview->set_multichannel_signed_distance_field(import_settings_data->get("multichannel_signed_distance_field"));
  1144. font_preview->set_msdf_pixel_range(import_settings_data->get("msdf_pixel_range"));
  1145. font_preview->set_msdf_size(import_settings_data->get("msdf_size"));
  1146. font_preview->set_allow_system_fallback(import_settings_data->get("allow_system_fallback"));
  1147. font_preview->set_force_autohinter(import_settings_data->get("force_autohinter"));
  1148. font_preview->set_modulate_color_glyphs(import_settings_data->get("modulate_color_glyphs"));
  1149. font_preview->set_hinting((TextServer::Hinting)import_settings_data->get("hinting").operator int());
  1150. int font_subpixel_positioning = import_settings_data->get("subpixel_positioning").operator int();
  1151. if (font_subpixel_positioning == 4 /* Auto (Except Pixel Fonts) */) {
  1152. if (is_pixel) {
  1153. font_subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_DISABLED;
  1154. } else {
  1155. font_subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO;
  1156. }
  1157. }
  1158. font_preview->set_subpixel_positioning((TextServer::SubpixelPositioning)font_subpixel_positioning);
  1159. font_preview->set_keep_rounding_remainders(import_settings_data->get("keep_rounding_remainders"));
  1160. }
  1161. font_preview_label->add_theme_font_override(SceneStringName(font), font_preview);
  1162. font_preview_label->add_theme_font_size_override(SceneStringName(font_size), 200 * EDSCALE);
  1163. font_preview_label->queue_redraw();
  1164. _variations_validate();
  1165. popup_centered_ratio();
  1166. set_title(vformat(TTR("Advanced Import Settings for '%s'"), base_path.get_file()));
  1167. }
  1168. DynamicFontImportSettingsDialog *DynamicFontImportSettingsDialog::get_singleton() {
  1169. return singleton;
  1170. }
  1171. DynamicFontImportSettingsDialog::DynamicFontImportSettingsDialog() {
  1172. singleton = this;
  1173. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Rendering", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant()));
  1174. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "antialiasing", PROPERTY_HINT_ENUM, "None,Grayscale,LCD Subpixel"), 1));
  1175. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "generate_mipmaps"), false));
  1176. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "disable_embedded_bitmaps"), true));
  1177. 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));
  1178. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "msdf_pixel_range", PROPERTY_HINT_RANGE, "1,100,1"), 8));
  1179. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "msdf_size", PROPERTY_HINT_RANGE, "1,250,1"), 48));
  1180. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "allow_system_fallback"), true));
  1181. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "force_autohinter"), false));
  1182. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "modulate_color_glyphs"), false));
  1183. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "hinting", PROPERTY_HINT_ENUM, "None,Light,Normal"), 1));
  1184. 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,Auto (Except Pixel Fonts)"), 4));
  1185. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "keep_rounding_remainders"), true));
  1186. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Metadata Overrides", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant()));
  1187. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "language_support"), Dictionary()));
  1188. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "script_support"), Dictionary()));
  1189. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "opentype_features"), Dictionary()));
  1190. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Fallbacks", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant()));
  1191. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::ARRAY, "fallbacks", PROPERTY_HINT_ARRAY_TYPE, MAKE_RESOURCE_TYPE_HINT("Font")), Array()));
  1192. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Compress", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant()));
  1193. options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "compress", PROPERTY_HINT_NONE, ""), false));
  1194. options_text.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "opentype_features"), Dictionary()));
  1195. options_text.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::STRING, "language", PROPERTY_HINT_LOCALE_ID, ""), ""));
  1196. options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "size", PROPERTY_HINT_RANGE, "0,127,1"), 16));
  1197. options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "outline_size", PROPERTY_HINT_RANGE, "0,127,1"), 0));
  1198. options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Variation", PROPERTY_HINT_NONE, "variation", PROPERTY_USAGE_GROUP), Variant()));
  1199. options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "variation_opentype"), Dictionary()));
  1200. options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::FLOAT, "variation_embolden", PROPERTY_HINT_RANGE, "-2,2,0.01"), 0));
  1201. options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "variation_face_index"), 0));
  1202. options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::TRANSFORM2D, "variation_transform"), Transform2D()));
  1203. // Root layout
  1204. VBoxContainer *root_vb = memnew(VBoxContainer);
  1205. add_child(root_vb);
  1206. main_pages = memnew(TabContainer);
  1207. main_pages->set_tab_alignment(TabBar::ALIGNMENT_CENTER);
  1208. main_pages->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1209. main_pages->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1210. main_pages->set_theme_type_variation("TabContainerOdd");
  1211. root_vb->add_child(main_pages);
  1212. label_warn = memnew(Label);
  1213. label_warn->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  1214. label_warn->set_text("");
  1215. root_vb->add_child(label_warn);
  1216. label_warn->hide();
  1217. // Page 1 layout: Rendering Options
  1218. VBoxContainer *page1_vb = memnew(VBoxContainer);
  1219. page1_vb->set_name(TTR("Rendering Options"));
  1220. main_pages->add_child(page1_vb);
  1221. page1_description = memnew(Label);
  1222. page1_description->set_text(TTR("Select font rendering options, fallback font, and metadata override:"));
  1223. page1_description->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1224. page1_vb->add_child(page1_description);
  1225. HSplitContainer *page1_hb = memnew(HSplitContainer);
  1226. page1_hb->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1227. page1_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1228. page1_vb->add_child(page1_hb);
  1229. VBoxContainer *page1_lbl_vb = memnew(VBoxContainer);
  1230. page1_lbl_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1231. page1_lbl_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1232. page1_hb->add_child(page1_lbl_vb);
  1233. font_name_label = memnew(Label);
  1234. font_name_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  1235. font_name_label->set_clip_text(true);
  1236. font_name_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1237. page1_lbl_vb->add_child(font_name_label);
  1238. font_preview_label = memnew(Label);
  1239. font_preview_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  1240. font_preview_label->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
  1241. font_preview_label->set_autowrap_mode(TextServer::AUTOWRAP_ARBITRARY);
  1242. font_preview_label->set_clip_text(true);
  1243. font_preview_label->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1244. font_preview_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1245. page1_lbl_vb->add_child(font_preview_label);
  1246. inspector_general = memnew(EditorInspector);
  1247. inspector_general->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1248. inspector_general->set_custom_minimum_size(Size2(300 * EDSCALE, 250 * EDSCALE));
  1249. page1_hb->add_child(inspector_general);
  1250. inspector_general->connect("property_edited", callable_mp(this, &DynamicFontImportSettingsDialog::_main_prop_changed));
  1251. // Page 2 layout: Configurations
  1252. VBoxContainer *page2_vb = memnew(VBoxContainer);
  1253. page2_vb->set_name(TTR("Pre-render Configurations"));
  1254. main_pages->add_child(page2_vb);
  1255. page2_description = memnew(Label);
  1256. page2_description->set_text(TTR("Add font size, and variation coordinates, and select glyphs to pre-render:"));
  1257. page2_description->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1258. page2_description->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  1259. page2_description->set_custom_minimum_size(Size2(300 * EDSCALE, 1));
  1260. page2_vb->add_child(page2_description);
  1261. HSplitContainer *page2_hb = memnew(HSplitContainer);
  1262. page2_hb->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1263. page2_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1264. page2_vb->add_child(page2_hb);
  1265. VBoxContainer *page2_side_vb = memnew(VBoxContainer);
  1266. page2_hb->add_child(page2_side_vb);
  1267. HBoxContainer *page2_hb_vars = memnew(HBoxContainer);
  1268. page2_side_vb->add_child(page2_hb_vars);
  1269. label_vars = memnew(Label);
  1270. label_vars->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
  1271. label_vars->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1272. label_vars->set_text(TTR("Configuration:"));
  1273. page2_hb_vars->add_child(label_vars);
  1274. add_var = memnew(Button);
  1275. add_var->set_tooltip_text(TTR("Add new font variation configuration."));
  1276. add_var->set_accessibility_name(TTRC("Add Configuration"));
  1277. page2_hb_vars->add_child(add_var);
  1278. add_var->connect(SceneStringName(pressed), callable_mp(this, &DynamicFontImportSettingsDialog::_variation_add));
  1279. vars_list = memnew(Tree);
  1280. vars_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  1281. vars_list->set_custom_minimum_size(Size2(300 * EDSCALE, 0));
  1282. vars_list->set_hide_root(true);
  1283. vars_list->set_columns(2);
  1284. vars_list->set_column_expand(0, true);
  1285. vars_list->set_column_custom_minimum_width(0, 80 * EDSCALE);
  1286. vars_list->set_column_expand(1, false);
  1287. vars_list->set_column_custom_minimum_width(1, 50 * EDSCALE);
  1288. vars_list->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1289. page2_side_vb->add_child(vars_list);
  1290. vars_list->connect(SceneStringName(item_selected), callable_mp(this, &DynamicFontImportSettingsDialog::_variation_selected));
  1291. vars_list->connect("button_clicked", callable_mp(this, &DynamicFontImportSettingsDialog::_variation_remove));
  1292. inspector_vars = memnew(EditorInspector);
  1293. inspector_vars->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1294. page2_side_vb->add_child(inspector_vars);
  1295. inspector_vars->connect("property_edited", callable_mp(this, &DynamicFontImportSettingsDialog::_variation_changed));
  1296. VBoxContainer *preload_pages_vb = memnew(VBoxContainer);
  1297. page2_hb->add_child(preload_pages_vb);
  1298. preload_pages = memnew(TabContainer);
  1299. preload_pages->set_tab_alignment(TabBar::ALIGNMENT_CENTER);
  1300. preload_pages->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1301. preload_pages->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1302. preload_pages_vb->add_child(preload_pages);
  1303. HBoxContainer *gl_hb = memnew(HBoxContainer);
  1304. gl_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1305. preload_pages_vb->add_child(gl_hb);
  1306. label_glyphs = memnew(Label);
  1307. label_glyphs->set_text(vformat(TTR("Preloaded glyphs: %d"), 0));
  1308. label_glyphs->set_custom_minimum_size(Size2(50 * EDSCALE, 0));
  1309. gl_hb->add_child(label_glyphs);
  1310. Button *btn_clear = memnew(Button);
  1311. btn_clear->set_text(TTR("Clear Glyph List"));
  1312. gl_hb->add_child(btn_clear);
  1313. btn_clear->connect(SceneStringName(pressed), callable_mp(this, &DynamicFontImportSettingsDialog::_glyph_clear));
  1314. VBoxContainer *page2_0_vb = memnew(VBoxContainer);
  1315. page2_0_vb->set_name(TTR("Glyphs from the Translations"));
  1316. preload_pages->add_child(page2_0_vb);
  1317. page2_0_description = memnew(Label);
  1318. page2_0_description->set_text(TTR("Select translations to add all required glyphs to pre-render list:"));
  1319. page2_0_description->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1320. page2_0_description->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  1321. page2_0_description->set_custom_minimum_size(Size2(300 * EDSCALE, 1));
  1322. page2_0_vb->add_child(page2_0_description);
  1323. locale_tree = memnew(Tree);
  1324. locale_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  1325. locale_tree->set_columns(1);
  1326. locale_tree->set_hide_root(true);
  1327. locale_tree->set_column_expand(0, true);
  1328. locale_tree->set_column_custom_minimum_width(0, 120 * EDSCALE);
  1329. locale_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1330. page2_0_vb->add_child(locale_tree);
  1331. locale_tree->connect("item_activated", callable_mp(this, &DynamicFontImportSettingsDialog::_locale_edited));
  1332. locale_root = locale_tree->create_item();
  1333. HBoxContainer *locale_hb = memnew(HBoxContainer);
  1334. locale_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1335. page2_0_vb->add_child(locale_hb);
  1336. btn_fill_locales = memnew(Button);
  1337. btn_fill_locales->set_text(TTR("Shape all Strings in the Translations and Add Glyphs"));
  1338. locale_hb->add_child(btn_fill_locales);
  1339. btn_fill_locales->connect(SceneStringName(pressed), callable_mp(this, &DynamicFontImportSettingsDialog::_process_locales));
  1340. // Page 2.1 layout: Text to select glyphs
  1341. VBoxContainer *page2_1_vb = memnew(VBoxContainer);
  1342. page2_1_vb->set_name(TTR("Glyphs from the Text"));
  1343. preload_pages->add_child(page2_1_vb);
  1344. page2_1_description = memnew(Label);
  1345. page2_1_description->set_text(TTR("Enter a text and select OpenType features to shape and add all required glyphs to pre-render list:"));
  1346. page2_1_description->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1347. page2_1_description->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  1348. page2_1_description->set_custom_minimum_size(Size2(300 * EDSCALE, 1));
  1349. page2_1_vb->add_child(page2_1_description);
  1350. HSplitContainer *page2_1_hb = memnew(HSplitContainer);
  1351. page2_1_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1352. page2_1_hb->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1353. page2_1_vb->add_child(page2_1_hb);
  1354. inspector_text = memnew(EditorInspector);
  1355. inspector_text->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1356. inspector_text->set_custom_minimum_size(Size2(300 * EDSCALE, 250 * EDSCALE));
  1357. page2_1_hb->add_child(inspector_text);
  1358. inspector_text->connect("property_edited", callable_mp(this, &DynamicFontImportSettingsDialog::_change_text_opts));
  1359. text_edit = memnew(TextEdit);
  1360. text_edit->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1361. text_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1362. page2_1_hb->add_child(text_edit);
  1363. HBoxContainer *text_hb = memnew(HBoxContainer);
  1364. text_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1365. page2_1_vb->add_child(text_hb);
  1366. btn_fill = memnew(Button);
  1367. btn_fill->set_text(TTR("Shape Text and Add Glyphs"));
  1368. text_hb->add_child(btn_fill);
  1369. btn_fill->connect(SceneStringName(pressed), callable_mp(this, &DynamicFontImportSettingsDialog::_glyph_text_selected));
  1370. // Page 2.2 layout: Character map
  1371. VBoxContainer *page2_2_vb = memnew(VBoxContainer);
  1372. page2_2_vb->set_name(TTR("Glyphs from the Character Map"));
  1373. preload_pages->add_child(page2_2_vb);
  1374. page2_2_description = memnew(Label);
  1375. 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."));
  1376. page2_2_description->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1377. page2_2_description->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  1378. page2_2_description->set_custom_minimum_size(Size2(300 * EDSCALE, 1));
  1379. page2_2_vb->add_child(page2_2_description);
  1380. HSplitContainer *glyphs_split = memnew(HSplitContainer);
  1381. glyphs_split->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1382. glyphs_split->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1383. page2_2_vb->add_child(glyphs_split);
  1384. glyph_table = memnew(Tree);
  1385. glyph_table->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  1386. glyph_table->set_custom_minimum_size(Size2((30 * 16 + 100) * EDSCALE, 0));
  1387. glyph_table->set_columns(17);
  1388. glyph_table->set_column_expand(0, false);
  1389. glyph_table->set_hide_root(true);
  1390. glyph_table->set_allow_reselect(true);
  1391. glyph_table->set_select_mode(Tree::SELECT_SINGLE);
  1392. glyph_table->set_column_titles_visible(true);
  1393. for (int i = 0; i < 16; i++) {
  1394. glyph_table->set_column_title(i + 1, String::num_int64(i, 16));
  1395. }
  1396. glyph_table->add_theme_style_override("selected", glyph_table->get_theme_stylebox(SceneStringName(panel)));
  1397. glyph_table->add_theme_style_override("selected_focus", glyph_table->get_theme_stylebox(SceneStringName(panel)));
  1398. glyph_table->add_theme_constant_override("h_separation", 0);
  1399. glyph_table->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1400. glyph_table->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1401. glyphs_split->add_child(glyph_table);
  1402. glyph_table->connect("item_activated", callable_mp(this, &DynamicFontImportSettingsDialog::_glyph_selected));
  1403. glyph_tree = memnew(Tree);
  1404. glyph_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  1405. glyph_tree->set_custom_minimum_size(Size2(300 * EDSCALE, 0));
  1406. glyph_tree->set_columns(2);
  1407. glyph_tree->set_hide_root(true);
  1408. glyph_tree->set_column_expand(0, false);
  1409. glyph_tree->set_column_expand(1, true);
  1410. glyph_tree->set_column_custom_minimum_width(0, 120 * EDSCALE);
  1411. glyph_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1412. glyph_root = glyph_tree->create_item();
  1413. for (int i = 0; !unicode_ranges[i].name.is_empty(); i++) {
  1414. _add_glyph_range_item(unicode_ranges[i].start, unicode_ranges[i].end, unicode_ranges[i].name);
  1415. }
  1416. glyphs_split->add_child(glyph_tree);
  1417. glyph_tree->connect("item_activated", callable_mp(this, &DynamicFontImportSettingsDialog::_range_edited));
  1418. glyph_tree->connect(SceneStringName(item_selected), callable_mp(this, &DynamicFontImportSettingsDialog::_range_selected));
  1419. // Common
  1420. import_settings_data.instantiate();
  1421. import_settings_data->owner = this;
  1422. set_ok_button_text(TTR("Reimport"));
  1423. set_cancel_button_text(TTR("Close"));
  1424. }