| 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 | |
| 31 | #include "dynamic_font_import_settings.h" |
| 32 | |
| 33 | #include "unicode_ranges.inc" |
| 34 | |
| 35 | #include "core/config/project_settings.h" |
| 36 | #include "core/string/translation.h" |
| 37 | #include "editor/editor_node.h" |
| 38 | #include "editor/editor_string_names.h" |
| 39 | #include "editor/file_system/editor_file_system.h" |
| 40 | #include "editor/gui/editor_file_dialog.h" |
| 41 | #include "editor/inspector/editor_inspector.h" |
| 42 | #include "editor/settings/editor_settings.h" |
| 43 | #include "editor/themes/editor_scale.h" |
| 44 | #include "editor/translations/editor_locale_dialog.h" |
| 45 | #include "scene/gui/split_container.h" |
| 46 | |
| 47 | /*************************************************************************/ |
| 48 | /* Settings data */ |
| 49 | /*************************************************************************/ |
| 50 | |
| 51 | bool DynamicFontImportSettingsData::_set(const StringName &p_name, const Variant &p_value) { |
| 52 | if (defaults.has(p_name) && defaults[p_name] == p_value) { |
| 53 | settings.erase(p_name); |
| 54 | } else { |
| 55 | settings[p_name] = p_value; |
| 56 | } |
| 57 | return true; |
| 58 | } |
| 59 | |
| 60 | bool DynamicFontImportSettingsData::_get(const StringName &p_name, Variant &r_ret) const { |
| 61 | if (settings.has(p_name)) { |
| 62 | r_ret = settings[p_name]; |
| 63 | return true; |
| 64 | } |
| 65 | if (defaults.has(p_name)) { |
| 66 | r_ret = defaults[p_name]; |
| 67 | return true; |
| 68 | } |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | void DynamicFontImportSettingsData::_get_property_list(List<PropertyInfo> *p_list) const { |
| 73 | for (const List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) { |
| 74 | if (owner && owner->import_settings_data.is_valid()) { |
| 75 | 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")) { |
| 76 | continue; |
| 77 | } |
| 78 | if (!owner->import_settings_data->get("multichannel_signed_distance_field") && (E->get().option.name == "msdf_pixel_range" || E->get().option.name == "msdf_size")) { |
| 79 | continue; |
| 80 | } |
| 81 | } |
| 82 | p_list->push_back(E->get().option); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | Ref<FontFile> DynamicFontImportSettingsData::get_font() const { |
| 87 | return fd; |
| 88 | } |
| 89 | |
| 90 | /*************************************************************************/ |
| 91 | /* Glyph ranges */ |
| 92 | /*************************************************************************/ |
| 93 | |
| 94 | void DynamicFontImportSettingsDialog::_add_glyph_range_item(int32_t p_start, int32_t p_end, const String &p_name) { |
| 95 | const int page_size = 512; |
| 96 | int pages = (p_end - p_start) / page_size; |
| 97 | int remain = (p_end - p_start) % page_size; |
| 98 | |
| 99 | int32_t start = p_start; |
| 100 | for (int i = 0; i < pages; i++) { |
| 101 | TreeItem *item = glyph_tree->create_item(glyph_root); |
| 102 | ERR_FAIL_NULL(item); |
| 103 | item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); |
| 104 | item->set_text(0, p_name + " (" + _pad_zeros(String::num_int64(start, 16)) + "-" + _pad_zeros(String::num_int64(start + page_size, 16)) + ")"); |
| 105 | item->set_metadata(0, Vector2i(start, start + page_size)); |
| 106 | start += page_size; |
| 107 | } |
| 108 | if (remain > 0) { |
| 109 | TreeItem *item = glyph_tree->create_item(glyph_root); |
| 110 | ERR_FAIL_NULL(item); |
| 111 | item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); |
| 112 | item->set_text(0, p_name + " (" + _pad_zeros(String::num_int64(start, 16)) + "-" + _pad_zeros(String::num_int64(p_end, 16)) + ")"); |
| 113 | item->set_metadata(0, Vector2i(start, p_end)); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /*************************************************************************/ |
| 118 | /* Page 1 callbacks: Rendering Options */ |
| 119 | /*************************************************************************/ |
| 120 | |
| 121 | void DynamicFontImportSettingsDialog::_main_prop_changed(const String &p_edited_property) { |
| 122 | // Update font preview. |
| 123 | |
| 124 | if (font_preview.is_valid()) { |
| 125 | if (p_edited_property == "antialiasing") { |
| 126 | font_preview->set_antialiasing((TextServer::FontAntialiasing)import_settings_data->get("antialiasing").operator int()); |
| 127 | _variations_validate(); |
| 128 | } else if (p_edited_property == "generate_mipmaps") { |
| 129 | font_preview->set_generate_mipmaps(import_settings_data->get("generate_mipmaps")); |
| 130 | } else if (p_edited_property == "disable_embedded_bitmaps") { |
| 131 | font_preview->set_disable_embedded_bitmaps(import_settings_data->get("disable_embedded_bitmaps")); |
| 132 | } else if (p_edited_property == "multichannel_signed_distance_field") { |
| 133 | font_preview->set_multichannel_signed_distance_field(import_settings_data->get("multichannel_signed_distance_field")); |
| 134 | _variation_selected(); |
| 135 | _variations_validate(); |
| 136 | } else if (p_edited_property == "msdf_pixel_range") { |
| 137 | font_preview->set_msdf_pixel_range(import_settings_data->get("msdf_pixel_range")); |
| 138 | } else if (p_edited_property == "msdf_size") { |
| 139 | font_preview->set_msdf_size(import_settings_data->get("msdf_size")); |
| 140 | } else if (p_edited_property == "allow_system_fallback") { |
| 141 | font_preview->set_allow_system_fallback(import_settings_data->get("allow_system_fallback")); |
| 142 | } else if (p_edited_property == "force_autohinter") { |
| 143 | font_preview->set_force_autohinter(import_settings_data->get("force_autohinter")); |
| 144 | } else if (p_edited_property == "modulate_color_glyphs") { |
| 145 | font_preview->set_modulate_color_glyphs(import_settings_data->get("modulate_color_glyphs")); |
| 146 | } else if (p_edited_property == "hinting") { |
| 147 | font_preview->set_hinting((TextServer::Hinting)import_settings_data->get("hinting").operator int()); |
| 148 | } else if (p_edited_property == "subpixel_positioning") { |
| 149 | int font_subpixel_positioning = import_settings_data->get("subpixel_positioning").operator int(); |
| 150 | if (font_subpixel_positioning == 4 /* Auto (Except Pixel Fonts) */) { |
| 151 | if (is_pixel) { |
| 152 | font_subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_DISABLED; |
| 153 | } else { |
| 154 | font_subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO; |
| 155 | } |
| 156 | } |
| 157 | font_preview->set_subpixel_positioning((TextServer::SubpixelPositioning)font_subpixel_positioning); |
| 158 | _variations_validate(); |
| 159 | } else if (p_edited_property == "keep_rounding_remainders") { |
| 160 | font_preview->set_keep_rounding_remainders(import_settings_data->get("keep_rounding_remainders")); |
| 161 | } else if (p_edited_property == "oversampling") { |
| 162 | font_preview->set_oversampling(import_settings_data->get("oversampling")); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | font_preview_label->add_theme_font_override(SceneStringName(font), font_preview); |
| 167 | font_preview_label->add_theme_font_size_override(SceneStringName(font_size), 200 * EDSCALE); |
| 168 | font_preview_label->queue_redraw(); |
| 169 | } |
| 170 | |
| 171 | /*************************************************************************/ |
| 172 | /* Page 2 callbacks: Configurations */ |
| 173 | /*************************************************************************/ |
| 174 | |
| 175 | void DynamicFontImportSettingsDialog::_variation_add() { |
| 176 | TreeItem *vars_item = vars_list->create_item(vars_list_root); |
| 177 | ERR_FAIL_NULL(vars_item); |
| 178 | |
| 179 | vars_item->set_text(0, TTR("New Configuration")); |
| 180 | vars_item->set_editable(0, true); |
| 181 | vars_item->add_button(1, get_editor_theme_icon(SNAME("Remove")), BUTTON_REMOVE_VAR, false, TTR("Remove Variation")); |
| 182 | vars_item->set_button_color(1, 0, Color(1, 1, 1, 0.75)); |
| 183 | |
| 184 | Ref<DynamicFontImportSettingsData> import_variation_data; |
| 185 | import_variation_data.instantiate(); |
| 186 | import_variation_data->owner = this; |
| 187 | ERR_FAIL_COND(import_variation_data.is_null()); |
| 188 | |
| 189 | for (const ResourceImporter::ImportOption &option : options_variations) { |
| 190 | import_variation_data->defaults[option.option.name] = option.default_value; |
| 191 | } |
| 192 | |
| 193 | import_variation_data->options = options_variations; |
| 194 | inspector_vars->edit(import_variation_data.ptr()); |
| 195 | import_variation_data->notify_property_list_changed(); |
| 196 | import_variation_data->fd = font_main; |
| 197 | |
| 198 | vars_item->set_metadata(0, import_variation_data); |
| 199 | |
| 200 | _variations_validate(); |
| 201 | } |
| 202 | |
| 203 | void DynamicFontImportSettingsDialog::_variation_selected() { |
| 204 | TreeItem *vars_item = vars_list->get_selected(); |
| 205 | if (vars_item) { |
| 206 | Ref<DynamicFontImportSettingsData> import_variation_data = vars_item->get_metadata(0); |
| 207 | ERR_FAIL_COND(import_variation_data.is_null()); |
| 208 | |
| 209 | inspector_vars->edit(import_variation_data.ptr()); |
| 210 | import_variation_data->notify_property_list_changed(); |
| 211 | |
| 212 | label_glyphs->set_text(vformat(TTR("Preloaded glyphs: %d"), import_variation_data->selected_glyphs.size())); |
| 213 | _range_selected(); |
| 214 | _change_text_opts(); |
| 215 | |
| 216 | btn_fill->set_disabled(false); |
| 217 | btn_fill_locales->set_disabled(false); |
| 218 | } else { |
| 219 | btn_fill->set_disabled(true); |
| 220 | btn_fill_locales->set_disabled(true); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | void DynamicFontImportSettingsDialog::_variation_remove(Object *p_item, int p_column, int p_id, MouseButton p_button) { |
| 225 | if (p_button != MouseButton::LEFT) { |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | TreeItem *vars_item = (TreeItem *)p_item; |
| 230 | ERR_FAIL_NULL(vars_item); |
| 231 | |
| 232 | inspector_vars->edit(nullptr); |
| 233 | |
| 234 | vars_list_root->remove_child(vars_item); |
| 235 | memdelete(vars_item); |
| 236 | |
| 237 | if (vars_list_root->get_first_child()) { |
| 238 | Ref<DynamicFontImportSettingsData> import_variation_data = vars_list_root->get_first_child()->get_metadata(0); |
| 239 | inspector_vars->edit(import_variation_data.ptr()); |
| 240 | import_variation_data->notify_property_list_changed(); |
| 241 | } |
| 242 | |
| 243 | _variations_validate(); |
| 244 | |
| 245 | vars_item = vars_list->get_selected(); |
| 246 | if (vars_item) { |
| 247 | btn_fill->set_disabled(false); |
| 248 | btn_fill_locales->set_disabled(false); |
| 249 | } else { |
| 250 | btn_fill->set_disabled(true); |
| 251 | btn_fill_locales->set_disabled(true); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | void DynamicFontImportSettingsDialog::_variation_changed(const String &p_edited_property) { |
| 256 | _variations_validate(); |
| 257 | } |
| 258 | |
| 259 | void DynamicFontImportSettingsDialog::_variations_validate() { |
| 260 | String warn; |
| 261 | if (!vars_list_root->get_first_child()) { |
| 262 | warn = TTR("Warning: There are no configurations specified, no glyphs will be pre-rendered."); |
| 263 | } |
| 264 | for (TreeItem *vars_item_a = vars_list_root->get_first_child(); vars_item_a; vars_item_a = vars_item_a->get_next()) { |
| 265 | Ref<DynamicFontImportSettingsData> import_variation_data_a = vars_item_a->get_metadata(0); |
| 266 | ERR_FAIL_COND(import_variation_data_a.is_null()); |
| 267 | |
| 268 | for (TreeItem *vars_item_b = vars_list_root->get_first_child(); vars_item_b; vars_item_b = vars_item_b->get_next()) { |
| 269 | if (vars_item_b != vars_item_a) { |
| 270 | bool match = true; |
| 271 | for (const KeyValue<StringName, Variant> &E : import_variation_data_a->settings) { |
| 272 | Ref<DynamicFontImportSettingsData> import_variation_data_b = vars_item_b->get_metadata(0); |
| 273 | ERR_FAIL_COND(import_variation_data_b.is_null()); |
| 274 | match = match && (import_variation_data_b->settings[E.key] == E.value); |
| 275 | } |
| 276 | if (match) { |
| 277 | warn = TTR("Warning: Multiple configurations have identical settings. Duplicates will be ignored."); |
| 278 | break; |
| 279 | } |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | if ((TextServer::FontAntialiasing)(int)import_settings_data->get("antialiasing") == TextServer::FONT_ANTIALIASING_LCD) { |
| 284 | warn += "\n" + TTR("Note: LCD Subpixel antialiasing is selected, each of the glyphs will be pre-rendered for all supported subpixel layouts (5x)."); |
| 285 | } |
| 286 | int font_subpixel_positioning = import_settings_data->get("subpixel_positioning").operator int(); |
| 287 | if (font_subpixel_positioning == 4 /* Auto (Except Pixel Fonts) */) { |
| 288 | if (is_pixel) { |
| 289 | font_subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_DISABLED; |
| 290 | } else { |
| 291 | font_subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO; |
| 292 | } |
| 293 | } |
| 294 | if ((TextServer::SubpixelPositioning)font_subpixel_positioning != TextServer::SUBPIXEL_POSITIONING_DISABLED) { |
| 295 | warn += "\n" + TTR("Note: Subpixel positioning is selected, each of the glyphs might be pre-rendered for multiple subpixel offsets (up to 4x)."); |
| 296 | } |
| 297 | if (warn.is_empty()) { |
| 298 | label_warn->set_text(""); |
| 299 | label_warn->hide(); |
| 300 | } else { |
| 301 | label_warn->set_text(warn); |
| 302 | label_warn->show(); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | /*************************************************************************/ |
| 307 | /* Page 2.1 callbacks: Text to select glyphs */ |
| 308 | /*************************************************************************/ |
| 309 | |
| 310 | void DynamicFontImportSettingsDialog::_change_text_opts() { |
| 311 | Ref<DynamicFontImportSettingsData> import_variation_data; |
| 312 | |
| 313 | TreeItem *vars_item = vars_list->get_selected(); |
| 314 | if (vars_item) { |
| 315 | import_variation_data = vars_item->get_metadata(0); |
| 316 | } |
| 317 | if (import_variation_data.is_null()) { |
| 318 | return; |
| 319 | } |
| 320 | |
| 321 | Ref<FontVariation> font_main_text; |
| 322 | font_main_text.instantiate(); |
| 323 | font_main_text->set_base_font(font_main); |
| 324 | font_main_text->set_opentype_features(text_settings_data->get("opentype_features")); |
| 325 | font_main_text->set_variation_opentype(import_variation_data->get("variation_opentype")); |
| 326 | font_main_text->set_variation_embolden(import_variation_data->get("variation_embolden")); |
| 327 | font_main_text->set_variation_face_index(import_variation_data->get("variation_face_index")); |
| 328 | font_main_text->set_variation_transform(import_variation_data->get("variation_transform")); |
| 329 | |
| 330 | text_edit->add_theme_font_override(SceneStringName(font), font_main_text); |
| 331 | } |
| 332 | |
| 333 | void DynamicFontImportSettingsDialog::_glyph_update_lbl() { |
| 334 | Ref<DynamicFontImportSettingsData> import_variation_data; |
| 335 | |
| 336 | TreeItem *vars_item = vars_list->get_selected(); |
| 337 | if (vars_item) { |
| 338 | import_variation_data = vars_item->get_metadata(0); |
| 339 | } |
| 340 | if (import_variation_data.is_null()) { |
| 341 | return; |
| 342 | } |
| 343 | |
| 344 | int linked_glyphs = 0; |
| 345 | for (const char32_t &c : import_variation_data->selected_chars) { |
| 346 | if (import_variation_data->selected_glyphs.has(font_main->get_glyph_index(16, c))) { |
| 347 | linked_glyphs++; |
| 348 | } |
| 349 | } |
| 350 | int unlinked_glyphs = import_variation_data->selected_glyphs.size() - linked_glyphs; |
| 351 | label_glyphs->set_text(vformat(TTR("Preloaded glyphs: %d"), unlinked_glyphs + import_variation_data->selected_chars.size())); |
| 352 | } |
| 353 | |
| 354 | void DynamicFontImportSettingsDialog::_glyph_clear() { |
| 355 | Ref<DynamicFontImportSettingsData> import_variation_data; |
| 356 | |
| 357 | TreeItem *vars_item = vars_list->get_selected(); |
| 358 | if (vars_item) { |
| 359 | import_variation_data = vars_item->get_metadata(0); |
| 360 | } |
| 361 | if (import_variation_data.is_null()) { |
| 362 | return; |
| 363 | } |
| 364 | |
| 365 | import_variation_data->selected_glyphs.clear(); |
| 366 | _glyph_update_lbl(); |
| 367 | _range_selected(); |
| 368 | } |
| 369 | |
| 370 | void DynamicFontImportSettingsDialog::_glyph_text_selected() { |
| 371 | Ref<DynamicFontImportSettingsData> import_variation_data; |
| 372 | |
| 373 | TreeItem *vars_item = vars_list->get_selected(); |
| 374 | if (vars_item) { |
| 375 | import_variation_data = vars_item->get_metadata(0); |
| 376 | } |
| 377 | if (import_variation_data.is_null()) { |
| 378 | return; |
| 379 | } |
| 380 | RID text_rid = TS->create_shaped_text(); |
| 381 | if (text_rid.is_valid()) { |
| 382 | 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")); |
| 383 | TS->shaped_text_shape(text_rid); |
| 384 | const Glyph *gl = TS->shaped_text_get_glyphs(text_rid); |
| 385 | const int gl_size = TS->shaped_text_get_glyph_count(text_rid); |
| 386 | |
| 387 | for (int i = 0; i < gl_size; i++) { |
| 388 | if (gl[i].font_rid.is_valid() && gl[i].index != 0) { |
| 389 | import_variation_data->selected_glyphs.insert(gl[i].index); |
| 390 | } |
| 391 | } |
| 392 | TS->free_rid(text_rid); |
| 393 | _glyph_update_lbl(); |
| 394 | } |
| 395 | _range_selected(); |
| 396 | } |
| 397 | |
| 398 | /*************************************************************************/ |
| 399 | /* Page 2.2 callbacks: Character map */ |
| 400 | /*************************************************************************/ |
| 401 | |
| 402 | void DynamicFontImportSettingsDialog::_glyph_selected() { |
| 403 | Ref<DynamicFontImportSettingsData> import_variation_data; |
| 404 | |
| 405 | TreeItem *vars_item = vars_list->get_selected(); |
| 406 | if (vars_item) { |
| 407 | import_variation_data = vars_item->get_metadata(0); |
| 408 | } |
| 409 | if (import_variation_data.is_null()) { |
| 410 | return; |
| 411 | } |
| 412 | |
| 413 | TreeItem *item = glyph_table->get_selected(); |
| 414 | ERR_FAIL_NULL(item); |
| 415 | |
| 416 | Color scol = glyph_table->get_theme_color(SNAME("box_selection_fill_color"), EditorStringName(Editor)); |
| 417 | Color fcol = glyph_table->get_theme_color(SNAME("font_selected_color"), EditorStringName(Editor)); |
| 418 | scol.a = 1.f; |
| 419 | |
| 420 | int32_t c = item->get_metadata(glyph_table->get_selected_column()); |
| 421 | if (font_main->has_char(c)) { |
| 422 | if (_char_update(c)) { |
| 423 | item->set_custom_color(glyph_table->get_selected_column(), fcol); |
| 424 | item->set_custom_bg_color(glyph_table->get_selected_column(), scol); |
| 425 | } else { |
| 426 | item->clear_custom_color(glyph_table->get_selected_column()); |
| 427 | item->clear_custom_bg_color(glyph_table->get_selected_column()); |
| 428 | } |
| 429 | } |
| 430 | _glyph_update_lbl(); |
| 431 | |
| 432 | item = glyph_tree->get_selected(); |
| 433 | ERR_FAIL_NULL(item); |
| 434 | Vector2i range = item->get_metadata(0); |
| 435 | |
| 436 | int total_chars = range.y - range.x; |
| 437 | int selected_count = 0; |
| 438 | for (int i = range.x; i < range.y; i++) { |
| 439 | if (!font_main->has_char(i)) { |
| 440 | total_chars--; |
| 441 | } |
| 442 | |
| 443 | if (import_variation_data->selected_chars.has(i)) { |
| 444 | selected_count++; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | if (selected_count == total_chars) { |
| 449 | item->set_checked(0, true); |
| 450 | } else if (selected_count > 0) { |
| 451 | item->set_indeterminate(0, true); |
| 452 | } else { |
| 453 | item->set_checked(0, false); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | void DynamicFontImportSettingsDialog::_range_edited() { |
| 458 | TreeItem *item = glyph_tree->get_selected(); |
| 459 | ERR_FAIL_NULL(item); |
| 460 | Vector2i range = item->get_metadata(0); |
| 461 | _range_update(range.x, range.y); |
| 462 | } |
| 463 | |
| 464 | void DynamicFontImportSettingsDialog::_range_selected() { |
| 465 | TreeItem *item = glyph_tree->get_selected(); |
| 466 | if (item) { |
| 467 | Vector2i range = item->get_metadata(0); |
| 468 | _edit_range(range.x, range.y); |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | void DynamicFontImportSettingsDialog::_edit_range(int32_t p_start, int32_t p_end) { |
| 473 | Ref<DynamicFontImportSettingsData> import_variation_data; |
| 474 | |
| 475 | TreeItem *vars_item = vars_list->get_selected(); |
| 476 | if (vars_item) { |
| 477 | import_variation_data = vars_item->get_metadata(0); |
| 478 | } |
| 479 | if (import_variation_data.is_null()) { |
| 480 | return; |
| 481 | } |
| 482 | |
| 483 | glyph_table->clear(); |
| 484 | |
| 485 | TreeItem *root = glyph_table->create_item(); |
| 486 | ERR_FAIL_NULL(root); |
| 487 | |
| 488 | Color scol = glyph_table->get_theme_color(SNAME("box_selection_fill_color"), EditorStringName(Editor)); |
| 489 | Color fcol = glyph_table->get_theme_color(SNAME("font_selected_color"), EditorStringName(Editor)); |
| 490 | scol.a = 1.f; |
| 491 | |
| 492 | TreeItem *item = nullptr; |
| 493 | int col = 0; |
| 494 | |
| 495 | Ref<Font> font_main_big = font_main->duplicate(); |
| 496 | |
| 497 | for (int32_t c = p_start; c <= p_end; c++) { |
| 498 | if (col == 0) { |
| 499 | item = glyph_table->create_item(root); |
| 500 | ERR_FAIL_NULL(item); |
| 501 | item->set_text(0, _pad_zeros(String::num_int64(c, 16))); |
| 502 | item->set_text_alignment(0, HORIZONTAL_ALIGNMENT_LEFT); |
| 503 | item->set_text_overrun_behavior(0, TextServer::OVERRUN_NO_TRIMMING); |
| 504 | item->set_selectable(0, false); |
| 505 | item->set_custom_bg_color(0, glyph_table->get_theme_color(SNAME("dark_color_3"), EditorStringName(Editor))); |
| 506 | } |
| 507 | if (c != 0 && font_main->has_char(c)) { |
| 508 | item->set_text(col + 1, String::chr(c)); |
| 509 | item->set_custom_color(col + 1, Color(1, 1, 1)); |
| 510 | if (import_variation_data->selected_chars.has(c) || import_variation_data->selected_glyphs.has(font_main->get_glyph_index(16, c))) { |
| 511 | item->set_custom_color(col + 1, fcol); |
| 512 | item->set_custom_bg_color(col + 1, scol); |
| 513 | } else { |
| 514 | item->clear_custom_color(col + 1); |
| 515 | item->clear_custom_bg_color(col + 1); |
| 516 | } |
| 517 | } else { |
| 518 | item->set_custom_bg_color(col + 1, glyph_table->get_theme_color(SNAME("dark_color_2"), EditorStringName(Editor))); |
| 519 | } |
| 520 | item->set_metadata(col + 1, c); |
| 521 | item->set_text_alignment(col + 1, HORIZONTAL_ALIGNMENT_CENTER); |
| 522 | item->set_selectable(col + 1, true); |
| 523 | |
| 524 | item->set_custom_font(col + 1, font_main_big); |
| 525 | item->set_custom_font_size(col + 1, get_theme_font_size(SceneStringName(font_size)) * 2); |
| 526 | |
| 527 | col++; |
| 528 | if (col == 16) { |
| 529 | col = 0; |
| 530 | } |
| 531 | } |
| 532 | _glyph_update_lbl(); |
| 533 | } |
| 534 | |
| 535 | bool DynamicFontImportSettingsDialog::_char_update(int32_t p_char) { |
| 536 | Ref<DynamicFontImportSettingsData> import_variation_data; |
| 537 | |
| 538 | TreeItem *vars_item = vars_list->get_selected(); |
| 539 | if (vars_item) { |
| 540 | import_variation_data = vars_item->get_metadata(0); |
| 541 | } |
| 542 | if (import_variation_data.is_null()) { |
| 543 | return false; |
| 544 | } |
| 545 | |
| 546 | if (import_variation_data->selected_chars.has(p_char)) { |
| 547 | import_variation_data->selected_chars.erase(p_char); |
| 548 | return false; |
| 549 | } else if (font_main.is_valid() && import_variation_data->selected_glyphs.has(font_main->get_glyph_index(16, p_char))) { |
| 550 | import_variation_data->selected_glyphs.erase(font_main->get_glyph_index(16, p_char)); |
| 551 | return false; |
| 552 | } else { |
| 553 | import_variation_data->selected_chars.insert(p_char); |
| 554 | return true; |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | void DynamicFontImportSettingsDialog::_range_update(int32_t p_start, int32_t p_end) { |
| 559 | Ref<DynamicFontImportSettingsData> import_variation_data; |
| 560 | |
| 561 | TreeItem *vars_item = vars_list->get_selected(); |
| 562 | if (vars_item) { |
| 563 | import_variation_data = vars_item->get_metadata(0); |
| 564 | } |
| 565 | if (import_variation_data.is_null()) { |
| 566 | return; |
| 567 | } |
| 568 | |
| 569 | bool all_selected = true; |
| 570 | for (int32_t i = p_start; i <= p_end; i++) { |
| 571 | if (font_main->has_char(i)) { |
| 572 | if (font_main.is_valid()) { |
| 573 | all_selected = all_selected && (import_variation_data->selected_chars.has(i) || import_variation_data->selected_glyphs.has(font_main->get_glyph_index(16, i))); |
| 574 | } else { |
| 575 | all_selected = all_selected && import_variation_data->selected_chars.has(i); |
| 576 | } |
| 577 | } |
| 578 | } |
| 579 | for (int32_t i = p_start; i <= p_end; i++) { |
| 580 | if (font_main->has_char(i)) { |
| 581 | if (!all_selected) { |
| 582 | import_variation_data->selected_chars.insert(i); |
| 583 | } else { |
| 584 | import_variation_data->selected_chars.erase(i); |
| 585 | if (font_main.is_valid()) { |
| 586 | import_variation_data->selected_glyphs.erase(font_main->get_glyph_index(16, i)); |
| 587 | } |
| 588 | } |
| 589 | } |
| 590 | } |
| 591 | _edit_range(p_start, p_end); |
| 592 | |
| 593 | TreeItem *item = glyph_tree->get_selected(); |
| 594 | ERR_FAIL_NULL(item); |
| 595 | item->set_checked(0, !all_selected); |
| 596 | } |
| 597 | |
| 598 | /*************************************************************************/ |
| 599 | /* Common */ |
| 600 | /*************************************************************************/ |
| 601 | |
| 602 | DynamicFontImportSettingsDialog *DynamicFontImportSettingsDialog::singleton = nullptr; |
| 603 | |
| 604 | String DynamicFontImportSettingsDialog::_pad_zeros(const String &p_hex) const { |
| 605 | int len = CLAMP(5 - p_hex.length(), 0, 5); |
| 606 | return String("0").repeat(len) + p_hex; |
| 607 | } |
| 608 | |
| 609 | void DynamicFontImportSettingsDialog::_notification(int p_what) { |
| 610 | switch (p_what) { |
| 611 | case NOTIFICATION_READY: { |
| 612 | connect(SceneStringName(confirmed), callable_mp(this, &DynamicFontImportSettingsDialog::_re_import)); |
| 613 | } break; |
| 614 | |
| 615 | case NOTIFICATION_THEME_CHANGED: { |
| 616 | const String theme_style = EDITOR_GET("interface/theme/style"); |
| 617 | const String type_variation = theme_style == "Classic" ? "TabContainerOdd" : "TabContainerInner"; |
| 618 | main_pages->set_theme_type_variation(type_variation); |
| 619 | preload_pages->set_theme_type_variation(type_variation); |
| 620 | |
| 621 | add_var->set_button_icon(get_editor_theme_icon(SNAME("Add"))); |
| 622 | label_warn->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("warning_color"), EditorStringName(Editor))); |
| 623 | glyph_tree->add_theme_color_override(SNAME("font_disabled_color"), glyph_tree->get_theme_color(SceneStringName(font_color))); |
| 624 | } break; |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | void DynamicFontImportSettingsDialog::_re_import() { |
| 629 | HashMap<StringName, Variant> main_settings; |
| 630 | |
| 631 | main_settings["face_index"] = import_settings_data->get("face_index"); |
| 632 | main_settings["antialiasing"] = import_settings_data->get("antialiasing"); |
| 633 | main_settings["generate_mipmaps"] = import_settings_data->get("generate_mipmaps"); |
| 634 | main_settings["disable_embedded_bitmaps"] = import_settings_data->get("disable_embedded_bitmaps"); |
| 635 | main_settings["multichannel_signed_distance_field"] = import_settings_data->get("multichannel_signed_distance_field"); |
| 636 | main_settings["msdf_pixel_range"] = import_settings_data->get("msdf_pixel_range"); |
| 637 | main_settings["msdf_size"] = import_settings_data->get("msdf_size"); |
| 638 | main_settings["allow_system_fallback"] = import_settings_data->get("allow_system_fallback"); |
| 639 | main_settings["force_autohinter"] = import_settings_data->get("force_autohinter"); |
| 640 | main_settings["modulate_color_glyphs"] = import_settings_data->get("modulate_color_glyphs"); |
| 641 | main_settings["hinting"] = import_settings_data->get("hinting"); |
| 642 | main_settings["subpixel_positioning"] = import_settings_data->get("subpixel_positioning"); |
| 643 | main_settings["keep_rounding_remainders"] = import_settings_data->get("keep_rounding_remainders"); |
| 644 | main_settings["oversampling"] = import_settings_data->get("oversampling"); |
| 645 | main_settings["fallbacks"] = import_settings_data->get("fallbacks"); |
| 646 | main_settings["compress"] = import_settings_data->get("compress"); |
| 647 | |
| 648 | Array configurations; |
| 649 | for (TreeItem *vars_item = vars_list_root->get_first_child(); vars_item; vars_item = vars_item->get_next()) { |
| 650 | Ref<DynamicFontImportSettingsData> import_variation_data = vars_item->get_metadata(0); |
| 651 | ERR_FAIL_COND(import_variation_data.is_null()); |
| 652 | |
| 653 | Dictionary preload_config; |
| 654 | preload_config["name"] = vars_item->get_text(0); |
| 655 | |
| 656 | Size2i conf_size = Vector2i(16, 0); |
| 657 | for (const KeyValue<StringName, Variant> &E : import_variation_data->settings) { |
| 658 | if (E.key == "size") { |
| 659 | conf_size.x = E.value; |
| 660 | } |
| 661 | if (E.key == "outline_size") { |
| 662 | conf_size.y = E.value; |
| 663 | } else { |
| 664 | preload_config[E.key] = E.value; |
| 665 | } |
| 666 | } |
| 667 | preload_config["size"] = conf_size; |
| 668 | |
| 669 | Array chars; |
| 670 | for (const char32_t &E : import_variation_data->selected_chars) { |
| 671 | chars.push_back(E); |
| 672 | } |
| 673 | preload_config["chars"] = chars; |
| 674 | |
| 675 | Array glyphs; |
| 676 | for (const int32_t &E : import_variation_data->selected_glyphs) { |
| 677 | glyphs.push_back(E); |
| 678 | } |
| 679 | preload_config["glyphs"] = glyphs; |
| 680 | |
| 681 | configurations.push_back(preload_config); |
| 682 | } |
| 683 | main_settings["preload"] = configurations; |
| 684 | main_settings["language_support"] = import_settings_data->get("language_support"); |
| 685 | main_settings["script_support"] = import_settings_data->get("script_support"); |
| 686 | main_settings["opentype_features"] = import_settings_data->get("opentype_features"); |
| 687 | |
| 688 | if (OS::get_singleton()->is_stdout_verbose()) { |
| 689 | print_line("Import settings:"); |
| 690 | for (const KeyValue<StringName, Variant> &E : main_settings) { |
| 691 | print_line(String(" ") + String(E.key).utf8().get_data() + " == " + String(E.value).utf8().get_data()); |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | EditorFileSystem::get_singleton()->reimport_file_with_custom_parameters(base_path, "font_data_dynamic", main_settings); |
| 696 | } |
| 697 | |
| 698 | void DynamicFontImportSettingsDialog::_locale_edited() { |
| 699 | TreeItem *item = locale_tree->get_selected(); |
| 700 | ERR_FAIL_NULL(item); |
| 701 | item->set_checked(0, !item->is_checked(0)); |
| 702 | } |
| 703 | |
| 704 | void DynamicFontImportSettingsDialog::_process_locales() { |
| 705 | Ref<DynamicFontImportSettingsData> import_variation_data; |
| 706 | |
| 707 | TreeItem *vars_item = vars_list->get_selected(); |
| 708 | if (vars_item) { |
| 709 | import_variation_data = vars_item->get_metadata(0); |
| 710 | } |
| 711 | if (import_variation_data.is_null()) { |
| 712 | return; |
| 713 | } |
| 714 | |
| 715 | for (int i = 0; i < locale_root->get_child_count(); i++) { |
| 716 | TreeItem *item = locale_root->get_child(i); |
| 717 | if (item) { |
| 718 | if (item->is_checked(0)) { |
| 719 | String locale = item->get_text(0); |
| 720 | Ref<Translation> tr = ResourceLoader::load(locale); |
| 721 | if (tr.is_valid()) { |
| 722 | Vector<String> messages = tr->get_translated_message_list(); |
| 723 | for (const String &E : messages) { |
| 724 | RID text_rid = TS->create_shaped_text(); |
| 725 | if (text_rid.is_valid()) { |
| 726 | TS->shaped_text_add_string(text_rid, E, font_main->get_rids(), 16, Dictionary(), tr->get_locale()); |
| 727 | TS->shaped_text_shape(text_rid); |
| 728 | const Glyph *gl = TS->shaped_text_get_glyphs(text_rid); |
| 729 | const int gl_size = TS->shaped_text_get_glyph_count(text_rid); |
| 730 | |
| 731 | for (int j = 0; j < gl_size; j++) { |
| 732 | if (gl[j].font_rid.is_valid() && gl[j].index != 0) { |
| 733 | import_variation_data->selected_glyphs.insert(gl[j].index); |
| 734 | } |
| 735 | } |
| 736 | TS->free_rid(text_rid); |
| 737 | } |
| 738 | } |
| 739 | } |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | _glyph_update_lbl(); |
| 745 | _range_selected(); |
| 746 | } |
| 747 | |
| 748 | void DynamicFontImportSettingsDialog::open_settings(const String &p_path) { |
| 749 | // Load base font data. |
| 750 | Vector<uint8_t> font_data = FileAccess::get_file_as_bytes(p_path); |
| 751 | |
| 752 | // Load project locale list. |
| 753 | locale_tree->clear(); |
| 754 | locale_root = locale_tree->create_item(); |
| 755 | ERR_FAIL_NULL(locale_root); |
| 756 | |
| 757 | Vector<String> translations = GLOBAL_GET("internationalization/locale/translations"); |
| 758 | for (const String &E : translations) { |
| 759 | TreeItem *item = locale_tree->create_item(locale_root); |
| 760 | ERR_FAIL_NULL(item); |
| 761 | item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); |
| 762 | item->set_text(0, E); |
| 763 | } |
| 764 | |
| 765 | // Load font for preview. |
| 766 | font_preview.instantiate(); |
| 767 | font_preview->set_data(font_data); |
| 768 | |
| 769 | Array rids = font_preview->get_rids(); |
| 770 | if (!rids.is_empty()) { |
| 771 | PackedInt32Array glyphs = TS->font_get_supported_glyphs(rids[0]); |
| 772 | is_pixel = true; |
| 773 | for (int32_t gl : glyphs) { |
| 774 | Dictionary ct = TS->font_get_glyph_contours(rids[0], 16, gl); |
| 775 | PackedInt32Array contours = ct["contours"]; |
| 776 | PackedVector3Array points = ct["points"]; |
| 777 | int prev_start = 0; |
| 778 | for (int i = 0; i < contours.size(); i++) { |
| 779 | for (int j = prev_start; j <= contours[i]; j++) { |
| 780 | int next_point = (j < contours[i]) ? (j + 1) : prev_start; |
| 781 | if ((points[j].z != (real_t)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))) { |
| 782 | is_pixel = false; |
| 783 | break; |
| 784 | } |
| 785 | } |
| 786 | prev_start = contours[i] + 1; |
| 787 | if (!is_pixel) { |
| 788 | break; |
| 789 | } |
| 790 | } |
| 791 | if (!is_pixel) { |
| 792 | break; |
| 793 | } |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | String font_name = vformat("%s (%s)", font_preview->get_font_name(), font_preview->get_font_style_name()); |
| 798 | String sample; |
| 799 | static const String sample_base = U"12漢字ԱբΑαАбΑαאבابܐܒހށआআਆઆଆஆఆಆആආกิກິༀကႠა한글ሀᎣᐁᚁᚠᜀᜠᝀᝠកᠠᤁᥐAb😀"; |
| 800 | for (int i = 0; i < sample_base.length(); i++) { |
| 801 | if (font_preview->has_char(sample_base[i])) { |
| 802 | sample += sample_base[i]; |
| 803 | } |
| 804 | } |
| 805 | if (sample.is_empty()) { |
| 806 | sample = font_preview->get_supported_chars().substr(0, 6); |
| 807 | } |
| 808 | font_preview_label->set_text(sample); |
| 809 | |
| 810 | Ref<Font> bold_font = get_theme_font(SNAME("bold"), EditorStringName(EditorFonts)); |
| 811 | if (bold_font.is_valid()) { |
| 812 | font_name_label->add_theme_font_override("bold_font", bold_font); |
| 813 | } |
| 814 | font_name_label->set_text(font_name); |
| 815 | |
| 816 | // Load second copy of font with MSDF disabled for the glyph table and metadata extraction. |
| 817 | font_main.instantiate(); |
| 818 | font_main->set_data(font_data); |
| 819 | font_main->set_multichannel_signed_distance_field(false); |
| 820 | |
| 821 | text_edit->add_theme_font_override(SceneStringName(font), font_main); |
| 822 | |
| 823 | base_path = p_path; |
| 824 | |
| 825 | inspector_vars->edit(nullptr); |
| 826 | inspector_text->edit(nullptr); |
| 827 | inspector_general->edit(nullptr); |
| 828 | |
| 829 | text_settings_data.instantiate(); |
| 830 | ERR_FAIL_COND(text_settings_data.is_null()); |
| 831 | |
| 832 | text_settings_data->owner = this; |
| 833 | |
| 834 | for (const ResourceImporter::ImportOption &option : options_text) { |
| 835 | text_settings_data->defaults[option.option.name] = option.default_value; |
| 836 | } |
| 837 | |
| 838 | text_settings_data->fd = font_main; |
| 839 | text_settings_data->options = options_text; |
| 840 | |
| 841 | inspector_text->edit(text_settings_data.ptr()); |
| 842 | glyph_table->clear(); |
| 843 | vars_list->clear(); |
| 844 | |
| 845 | glyph_tree->set_selected(glyph_root->get_child(0)); |
| 846 | |
| 847 | vars_list_root = vars_list->create_item(); |
| 848 | |
| 849 | import_settings_data->settings.clear(); |
| 850 | import_settings_data->defaults.clear(); |
| 851 | for (const ResourceImporter::ImportOption &option : options_general) { |
| 852 | import_settings_data->defaults[option.option.name] = option.default_value; |
| 853 | } |
| 854 | |
| 855 | Ref<ConfigFile> config; |
| 856 | config.instantiate(); |
| 857 | ERR_FAIL_COND(config.is_null()); |
| 858 | |
| 859 | Error err = config->load(p_path + ".import"); |
| 860 | print_verbose("Loading import settings:"); |
| 861 | if (err == OK) { |
| 862 | Vector<String> keys = config->get_section_keys("params"); |
| 863 | for (const String &key : keys) { |
| 864 | print_verbose(String(" ") + key + " == " + String(config->get_value("params", key))); |
| 865 | if (key == "preload") { |
| 866 | Array preload_configurations = config->get_value("params", key); |
| 867 | for (int i = 0; i < preload_configurations.size(); i++) { |
| 868 | Dictionary preload_config = preload_configurations[i]; |
| 869 | |
| 870 | Dictionary variation = preload_config.has("variation_opentype") ? preload_config["variation_opentype"].operator Dictionary() : Dictionary(); |
| 871 | double embolden = preload_config.has("variation_embolden") ? preload_config["variation_embolden"].operator double() : 0; |
| 872 | int face_index = preload_config.has("variation_face_index") ? preload_config["variation_face_index"].operator int() : 0; |
| 873 | Transform2D transform = preload_config.has("variation_transform") ? preload_config["variation_transform"].operator Transform2D() : Transform2D(); |
| 874 | Vector2i font_size = preload_config.has("size") ? preload_config["size"].operator Vector2i() : Vector2i(16, 0); |
| 875 | String cfg_name = preload_config.has("name") ? preload_config["name"].operator String() : vformat("Configuration %d", i); |
| 876 | |
| 877 | TreeItem *vars_item = vars_list->create_item(vars_list_root); |
| 878 | ERR_FAIL_NULL(vars_item); |
| 879 | |
| 880 | vars_item->set_text(0, cfg_name); |
| 881 | vars_item->set_editable(0, true); |
| 882 | vars_item->add_button(1, get_editor_theme_icon(SNAME("Remove")), BUTTON_REMOVE_VAR, false, TTR("Remove Variation")); |
| 883 | vars_item->set_button_color(1, 0, Color(1, 1, 1, 0.75)); |
| 884 | |
| 885 | Ref<DynamicFontImportSettingsData> import_variation_data_custom; |
| 886 | import_variation_data_custom.instantiate(); |
| 887 | ERR_FAIL_COND(import_variation_data_custom.is_null()); |
| 888 | |
| 889 | import_variation_data_custom->owner = this; |
| 890 | for (const ResourceImporter::ImportOption &option : options_variations) { |
| 891 | import_variation_data_custom->defaults[option.option.name] = option.default_value; |
| 892 | } |
| 893 | |
| 894 | import_variation_data_custom->fd = font_main; |
| 895 | |
| 896 | import_variation_data_custom->options = options_variations; |
| 897 | vars_item->set_metadata(0, import_variation_data_custom); |
| 898 | |
| 899 | import_variation_data_custom->set("size", font_size.x); |
| 900 | import_variation_data_custom->set("outline_size", font_size.y); |
| 901 | import_variation_data_custom->set("variation_opentype", variation); |
| 902 | import_variation_data_custom->set("variation_embolden", embolden); |
| 903 | import_variation_data_custom->set("variation_face_index", face_index); |
| 904 | import_variation_data_custom->set("variation_transform", transform); |
| 905 | |
| 906 | Array chars = preload_config["chars"]; |
| 907 | for (int j = 0; j < chars.size(); j++) { |
| 908 | char32_t c = chars[j].operator int(); |
| 909 | import_variation_data_custom->selected_chars.insert(c); |
| 910 | } |
| 911 | |
| 912 | Array glyphs = preload_config["glyphs"]; |
| 913 | for (int j = 0; j < glyphs.size(); j++) { |
| 914 | int32_t c = glyphs[j]; |
| 915 | import_variation_data_custom->selected_glyphs.insert(c); |
| 916 | } |
| 917 | } |
| 918 | if (preload_configurations.is_empty()) { |
| 919 | _variation_add(); // Add default variation. |
| 920 | } |
| 921 | vars_list->set_selected(vars_list_root->get_child(0)); |
| 922 | } else { |
| 923 | Variant value = config->get_value("params", key); |
| 924 | import_settings_data->defaults[key] = value; |
| 925 | } |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | import_settings_data->fd = font_main; |
| 930 | import_settings_data->options = options_general; |
| 931 | inspector_general->edit(import_settings_data.ptr()); |
| 932 | import_settings_data->notify_property_list_changed(); |
| 933 | |
| 934 | if (font_preview.is_valid()) { |
| 935 | font_preview->set_antialiasing((TextServer::FontAntialiasing)import_settings_data->get("antialiasing").operator int()); |
| 936 | font_preview->set_multichannel_signed_distance_field(import_settings_data->get("multichannel_signed_distance_field")); |
| 937 | font_preview->set_msdf_pixel_range(import_settings_data->get("msdf_pixel_range")); |
| 938 | font_preview->set_msdf_size(import_settings_data->get("msdf_size")); |
| 939 | font_preview->set_allow_system_fallback(import_settings_data->get("allow_system_fallback")); |
| 940 | font_preview->set_force_autohinter(import_settings_data->get("force_autohinter")); |
| 941 | font_preview->set_modulate_color_glyphs(import_settings_data->get("modulate_color_glyphs")); |
| 942 | font_preview->set_hinting((TextServer::Hinting)import_settings_data->get("hinting").operator int()); |
| 943 | int font_subpixel_positioning = import_settings_data->get("subpixel_positioning").operator int(); |
| 944 | if (font_subpixel_positioning == 4 /* Auto (Except Pixel Fonts) */) { |
| 945 | if (is_pixel) { |
| 946 | font_subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_DISABLED; |
| 947 | } else { |
| 948 | font_subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO; |
| 949 | } |
| 950 | } |
| 951 | font_preview->set_subpixel_positioning((TextServer::SubpixelPositioning)font_subpixel_positioning); |
| 952 | font_preview->set_keep_rounding_remainders(import_settings_data->get("keep_rounding_remainders")); |
| 953 | font_preview->set_oversampling(import_settings_data->get("oversampling")); |
| 954 | } |
| 955 | font_preview_label->add_theme_font_override(SceneStringName(font), font_preview); |
| 956 | font_preview_label->add_theme_font_size_override(SceneStringName(font_size), 200 * EDSCALE); |
| 957 | font_preview_label->queue_redraw(); |
| 958 | |
| 959 | _variations_validate(); |
| 960 | |
| 961 | popup_centered_ratio(); |
| 962 | |
| 963 | set_title(vformat(TTR("Advanced Import Settings for '%s'"), base_path.get_file())); |
| 964 | } |
| 965 | |
| 966 | DynamicFontImportSettingsDialog *DynamicFontImportSettingsDialog::get_singleton() { |
| 967 | return singleton; |
| 968 | } |
| 969 | |
| 970 | DynamicFontImportSettingsDialog::DynamicFontImportSettingsDialog() { |
| 971 | singleton = this; |
| 972 | |
| 973 | options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Rendering", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant())); |
| 974 | |
| 975 | options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "antialiasing", PROPERTY_HINT_ENUM, "None,Grayscale,LCD Subpixel"), 1)); |
| 976 | options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "generate_mipmaps"), false)); |
| 977 | options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "disable_embedded_bitmaps"), true)); |
| 978 | 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)); |
| 979 | options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "msdf_pixel_range", PROPERTY_HINT_RANGE, "1,100,1"), 8)); |
| 980 | options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "msdf_size", PROPERTY_HINT_RANGE, "1,250,1"), 48)); |
| 981 | options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "allow_system_fallback"), true)); |
| 982 | options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "force_autohinter"), false)); |
| 983 | options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "modulate_color_glyphs"), false)); |
| 984 | options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "hinting", PROPERTY_HINT_ENUM, "None,Light,Normal"), 1)); |
| 985 | 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)); |
| 986 | options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "keep_rounding_remainders"), true)); |
| 987 | options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::FLOAT, "oversampling", PROPERTY_HINT_RANGE, "0,10,0.1"), 0.0)); |
| 988 | |
| 989 | options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Metadata Overrides", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant())); |
| 990 | options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "language_support"), Dictionary())); |
| 991 | options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "script_support"), Dictionary())); |
| 992 | options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "opentype_features"), Dictionary())); |
| 993 | |
| 994 | options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Fallbacks", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant())); |
| 995 | options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::ARRAY, "fallbacks", PROPERTY_HINT_ARRAY_TYPE, MAKE_RESOURCE_TYPE_HINT("Font")), Array())); |
| 996 | |
| 997 | options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Compress", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant())); |
| 998 | options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "compress", PROPERTY_HINT_NONE, ""), false)); |
| 999 | |
| 1000 | options_text.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "opentype_features"), Dictionary())); |
| 1001 | options_text.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::STRING, "language", PROPERTY_HINT_LOCALE_ID, ""), "")); |
| 1002 | |
| 1003 | options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "size", PROPERTY_HINT_RANGE, "0,127,1"), 16)); |
| 1004 | options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "outline_size", PROPERTY_HINT_RANGE, "0,127,1"), 0)); |
| 1005 | options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Variation", PROPERTY_HINT_NONE, "variation", PROPERTY_USAGE_GROUP), Variant())); |
| 1006 | options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::DICTIONARY, "variation_opentype"), Dictionary())); |
| 1007 | options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::FLOAT, "variation_embolden", PROPERTY_HINT_RANGE, "-2,2,0.01"), 0)); |
| 1008 | options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "variation_face_index"), 0)); |
| 1009 | options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::TRANSFORM2D, "variation_transform"), Transform2D())); |
| 1010 | |
| 1011 | // Root layout |
| 1012 | |
| 1013 | VBoxContainer *root_vb = memnew(VBoxContainer); |
| 1014 | add_child(root_vb); |
| 1015 | |
| 1016 | main_pages = memnew(TabContainer); |
| 1017 | main_pages->set_tab_alignment(TabBar::ALIGNMENT_CENTER); |
| 1018 | main_pages->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1019 | main_pages->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1020 | root_vb->add_child(main_pages); |
| 1021 | |
| 1022 | label_warn = memnew(Label); |
| 1023 | label_warn->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 1024 | label_warn->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); |
| 1025 | label_warn->set_text(""); |
| 1026 | root_vb->add_child(label_warn); |
| 1027 | label_warn->hide(); |
| 1028 | |
| 1029 | // Page 1 layout: Rendering Options |
| 1030 | |
| 1031 | VBoxContainer *page1_vb = memnew(VBoxContainer); |
| 1032 | page1_vb->set_name(TTR("Rendering Options")); |
| 1033 | main_pages->add_child(page1_vb); |
| 1034 | |
| 1035 | page1_description = memnew(Label); |
| 1036 | page1_description->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 1037 | page1_description->set_text(TTR("Select font rendering options, fallback font, and metadata override:")); |
| 1038 | page1_description->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1039 | page1_vb->add_child(page1_description); |
| 1040 | |
| 1041 | HSplitContainer *page1_hb = memnew(HSplitContainer); |
| 1042 | page1_hb->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1043 | page1_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1044 | page1_vb->add_child(page1_hb); |
| 1045 | |
| 1046 | VBoxContainer *page1_lbl_vb = memnew(VBoxContainer); |
| 1047 | page1_lbl_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1048 | page1_lbl_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1049 | page1_hb->add_child(page1_lbl_vb); |
| 1050 | |
| 1051 | font_name_label = memnew(Label); |
| 1052 | font_name_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 1053 | font_name_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); |
| 1054 | font_name_label->set_clip_text(true); |
| 1055 | font_name_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1056 | page1_lbl_vb->add_child(font_name_label); |
| 1057 | |
| 1058 | font_preview_label = memnew(Label); |
| 1059 | font_preview_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); |
| 1060 | font_preview_label->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER); |
| 1061 | font_preview_label->set_autowrap_mode(TextServer::AUTOWRAP_ARBITRARY); |
| 1062 | font_preview_label->set_clip_text(true); |
| 1063 | font_preview_label->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1064 | font_preview_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1065 | page1_lbl_vb->add_child(font_preview_label); |
| 1066 | |
| 1067 | inspector_general = memnew(EditorInspector); |
| 1068 | inspector_general->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1069 | inspector_general->set_custom_minimum_size(Size2(300 * EDSCALE, 250 * EDSCALE)); |
| 1070 | inspector_general->set_theme_type_variation("ScrollContainerSecondary"); |
| 1071 | page1_hb->add_child(inspector_general); |
| 1072 | inspector_general->connect("property_edited", callable_mp(this, &DynamicFontImportSettingsDialog::_main_prop_changed)); |
| 1073 | |
| 1074 | // Page 2 layout: Configurations |
| 1075 | VBoxContainer *page2_vb = memnew(VBoxContainer); |
| 1076 | page2_vb->set_name(TTR("Pre-render Configurations")); |
| 1077 | main_pages->add_child(page2_vb); |
| 1078 | |
| 1079 | page2_description = memnew(Label); |
| 1080 | page2_description->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 1081 | page2_description->set_text(TTR("Add font size, and variation coordinates, and select glyphs to pre-render:")); |
| 1082 | page2_description->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1083 | page2_description->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART); |
| 1084 | page2_description->set_custom_minimum_size(Size2(300 * EDSCALE, 1)); |
| 1085 | page2_vb->add_child(page2_description); |
| 1086 | |
| 1087 | HSplitContainer *page2_hb = memnew(HSplitContainer); |
| 1088 | page2_hb->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1089 | page2_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1090 | page2_vb->add_child(page2_hb); |
| 1091 | |
| 1092 | VBoxContainer *page2_side_vb = memnew(VBoxContainer); |
| 1093 | page2_hb->add_child(page2_side_vb); |
| 1094 | |
| 1095 | HBoxContainer *page2_hb_vars = memnew(HBoxContainer); |
| 1096 | page2_side_vb->add_child(page2_hb_vars); |
| 1097 | |
| 1098 | label_vars = memnew(Label); |
| 1099 | label_vars->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); |
| 1100 | label_vars->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1101 | label_vars->set_text(TTR("Configuration:")); |
| 1102 | page2_hb_vars->add_child(label_vars); |
| 1103 | |
| 1104 | add_var = memnew(Button); |
| 1105 | add_var->set_tooltip_text(TTR("Add new font variation configuration.")); |
| 1106 | page2_hb_vars->add_child(add_var); |
| 1107 | add_var->connect(SceneStringName(pressed), callable_mp(this, &DynamicFontImportSettingsDialog::_variation_add)); |
| 1108 | |
| 1109 | vars_list = memnew(Tree); |
| 1110 | vars_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); |
| 1111 | vars_list->set_accessibility_name(TTRC("Configuration:")); |
| 1112 | vars_list->set_custom_minimum_size(Size2(300 * EDSCALE, 0)); |
| 1113 | vars_list->set_hide_root(true); |
| 1114 | vars_list->set_columns(2); |
| 1115 | vars_list->set_column_expand(0, true); |
| 1116 | vars_list->set_column_custom_minimum_width(0, 80 * EDSCALE); |
| 1117 | vars_list->set_column_expand(1, false); |
| 1118 | vars_list->set_column_custom_minimum_width(1, 50 * EDSCALE); |
| 1119 | vars_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1120 | vars_list->set_theme_type_variation("TreeSecondary"); |
| 1121 | page2_side_vb->add_child(vars_list); |
| 1122 | vars_list->connect(SceneStringName(item_selected), callable_mp(this, &DynamicFontImportSettingsDialog::_variation_selected)); |
| 1123 | vars_list->connect("button_clicked", callable_mp(this, &DynamicFontImportSettingsDialog::_variation_remove)); |
| 1124 | |
| 1125 | inspector_vars = memnew(EditorInspector); |
| 1126 | inspector_vars->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1127 | inspector_vars->set_theme_type_variation("ScrollContainerSecondary"); |
| 1128 | page2_side_vb->add_child(inspector_vars); |
| 1129 | inspector_vars->connect("property_edited", callable_mp(this, &DynamicFontImportSettingsDialog::_variation_changed)); |
| 1130 | |
| 1131 | VBoxContainer *preload_pages_vb = memnew(VBoxContainer); |
| 1132 | page2_hb->add_child(preload_pages_vb); |
| 1133 | |
| 1134 | preload_pages = memnew(TabContainer); |
| 1135 | preload_pages->set_tab_alignment(TabBar::ALIGNMENT_CENTER); |
| 1136 | preload_pages->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1137 | preload_pages->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1138 | preload_pages_vb->add_child(preload_pages); |
| 1139 | |
| 1140 | HBoxContainer *gl_hb = memnew(HBoxContainer); |
| 1141 | gl_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1142 | preload_pages_vb->add_child(gl_hb); |
| 1143 | |
| 1144 | label_glyphs = memnew(Label); |
| 1145 | label_glyphs->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 1146 | label_glyphs->set_text(vformat(TTR("Preloaded glyphs: %d"), 0)); |
| 1147 | label_glyphs->set_custom_minimum_size(Size2(50 * EDSCALE, 0)); |
| 1148 | gl_hb->add_child(label_glyphs); |
| 1149 | |
| 1150 | Button *btn_clear = memnew(Button); |
| 1151 | btn_clear->set_text(TTR("Clear Glyph List")); |
| 1152 | gl_hb->add_child(btn_clear); |
| 1153 | btn_clear->connect(SceneStringName(pressed), callable_mp(this, &DynamicFontImportSettingsDialog::_glyph_clear)); |
| 1154 | |
| 1155 | VBoxContainer *page2_0_vb = memnew(VBoxContainer); |
| 1156 | page2_0_vb->set_name(TTR("Glyphs from the Translations")); |
| 1157 | preload_pages->add_child(page2_0_vb); |
| 1158 | |
| 1159 | page2_0_description = memnew(Label); |
| 1160 | page2_0_description->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 1161 | page2_0_description->set_text(TTR("Select translations to add all required glyphs to pre-render list:")); |
| 1162 | page2_0_description->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1163 | page2_0_description->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART); |
| 1164 | page2_0_description->set_custom_minimum_size(Size2(300 * EDSCALE, 1)); |
| 1165 | page2_0_vb->add_child(page2_0_description); |
| 1166 | |
| 1167 | locale_tree = memnew(Tree); |
| 1168 | locale_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); |
| 1169 | locale_tree->set_columns(1); |
| 1170 | locale_tree->set_hide_root(true); |
| 1171 | locale_tree->set_column_expand(0, true); |
| 1172 | locale_tree->set_column_custom_minimum_width(0, 120 * EDSCALE); |
| 1173 | locale_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1174 | locale_tree->set_theme_type_variation("TreeSecondary"); |
| 1175 | page2_0_vb->add_child(locale_tree); |
| 1176 | locale_tree->connect("item_activated", callable_mp(this, &DynamicFontImportSettingsDialog::_locale_edited)); |
| 1177 | |
| 1178 | locale_root = locale_tree->create_item(); |
| 1179 | |
| 1180 | HBoxContainer *locale_hb = memnew(HBoxContainer); |
| 1181 | locale_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1182 | page2_0_vb->add_child(locale_hb); |
| 1183 | |
| 1184 | btn_fill_locales = memnew(Button); |
| 1185 | btn_fill_locales->set_text(TTR("Shape all Strings in the Translations and Add Glyphs")); |
| 1186 | locale_hb->add_child(btn_fill_locales); |
| 1187 | btn_fill_locales->connect(SceneStringName(pressed), callable_mp(this, &DynamicFontImportSettingsDialog::_process_locales)); |
| 1188 | |
| 1189 | // Page 2.1 layout: Text to select glyphs |
| 1190 | VBoxContainer *page2_1_vb = memnew(VBoxContainer); |
| 1191 | page2_1_vb->set_name(TTR("Glyphs from the Text")); |
| 1192 | preload_pages->add_child(page2_1_vb); |
| 1193 | |
| 1194 | page2_1_description = memnew(Label); |
| 1195 | page2_1_description->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 1196 | page2_1_description->set_text(TTR("Enter a text and select OpenType features to shape and add all required glyphs to pre-render list:")); |
| 1197 | page2_1_description->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1198 | page2_1_description->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART); |
| 1199 | page2_1_description->set_custom_minimum_size(Size2(300 * EDSCALE, 1)); |
| 1200 | page2_1_vb->add_child(page2_1_description); |
| 1201 | |
| 1202 | HSplitContainer *page2_1_hb = memnew(HSplitContainer); |
| 1203 | page2_1_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1204 | page2_1_hb->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1205 | page2_1_vb->add_child(page2_1_hb); |
| 1206 | |
| 1207 | inspector_text = memnew(EditorInspector); |
| 1208 | inspector_text->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1209 | inspector_text->set_custom_minimum_size(Size2(300 * EDSCALE, 250 * EDSCALE)); |
| 1210 | inspector_text->set_theme_type_variation("ScrollContainerSecondary"); |
| 1211 | page2_1_hb->add_child(inspector_text); |
| 1212 | inspector_text->connect("property_edited", callable_mp(this, &DynamicFontImportSettingsDialog::_change_text_opts)); |
| 1213 | |
| 1214 | text_edit = memnew(TextEdit); |
| 1215 | text_edit->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1216 | text_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1217 | page2_1_hb->add_child(text_edit); |
| 1218 | |
| 1219 | HBoxContainer *text_hb = memnew(HBoxContainer); |
| 1220 | text_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1221 | page2_1_vb->add_child(text_hb); |
| 1222 | |
| 1223 | btn_fill = memnew(Button); |
| 1224 | btn_fill->set_text(TTR("Shape Text and Add Glyphs")); |
| 1225 | text_hb->add_child(btn_fill); |
| 1226 | btn_fill->connect(SceneStringName(pressed), callable_mp(this, &DynamicFontImportSettingsDialog::_glyph_text_selected)); |
| 1227 | |
| 1228 | // Page 2.2 layout: Character map |
| 1229 | VBoxContainer *page2_2_vb = memnew(VBoxContainer); |
| 1230 | page2_2_vb->set_name(TTR("Glyphs from the Character Map")); |
| 1231 | preload_pages->add_child(page2_2_vb); |
| 1232 | |
| 1233 | page2_2_description = memnew(Label); |
| 1234 | page2_2_description->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 1235 | 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.")); |
| 1236 | page2_2_description->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1237 | page2_2_description->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART); |
| 1238 | page2_2_description->set_custom_minimum_size(Size2(300 * EDSCALE, 1)); |
| 1239 | page2_2_vb->add_child(page2_2_description); |
| 1240 | |
| 1241 | HSplitContainer *glyphs_split = memnew(HSplitContainer); |
| 1242 | glyphs_split->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1243 | glyphs_split->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1244 | page2_2_vb->add_child(glyphs_split); |
| 1245 | |
| 1246 | glyph_table = memnew(Tree); |
| 1247 | glyph_table->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); |
| 1248 | glyph_table->set_custom_minimum_size(Size2((30 * 16 + 100) * EDSCALE, 0)); |
| 1249 | glyph_table->set_theme_type_variation("TreeTable"); |
| 1250 | glyph_table->set_columns(17); |
| 1251 | glyph_table->set_column_expand(0, false); |
| 1252 | glyph_table->set_hide_root(true); |
| 1253 | glyph_table->set_hide_folding(true); |
| 1254 | glyph_table->set_allow_reselect(true); |
| 1255 | glyph_table->set_select_mode(Tree::SELECT_SINGLE); |
| 1256 | glyph_table->set_column_titles_visible(true); |
| 1257 | for (int i = 0; i < 16; i++) { |
| 1258 | glyph_table->set_column_title(i + 1, String::num_int64(i, 16)); |
| 1259 | } |
| 1260 | glyph_table->add_theme_style_override("selected", glyph_table->get_theme_stylebox(SceneStringName(panel))); |
| 1261 | glyph_table->add_theme_style_override("selected_focus", glyph_table->get_theme_stylebox(SceneStringName(panel))); |
| 1262 | glyph_table->add_theme_constant_override("h_separation", 0); |
| 1263 | glyph_table->set_theme_type_variation("TreeSecondary"); |
| 1264 | glyph_table->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1265 | glyph_table->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1266 | glyphs_split->add_child(glyph_table); |
| 1267 | glyph_table->connect("item_activated", callable_mp(this, &DynamicFontImportSettingsDialog::_glyph_selected)); |
| 1268 | |
| 1269 | glyph_tree = memnew(Tree); |
| 1270 | glyph_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); |
| 1271 | glyph_tree->set_custom_minimum_size(Size2(300 * EDSCALE, 0)); |
| 1272 | glyph_tree->set_columns(1); |
| 1273 | glyph_tree->set_hide_root(true); |
| 1274 | glyph_tree->set_column_expand(0, true); |
| 1275 | glyph_tree->set_hide_folding(true); |
| 1276 | glyph_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1277 | glyph_tree->set_theme_type_variation("TreeSecondary"); |
| 1278 | glyph_root = glyph_tree->create_item(); |
| 1279 | for (int i = 0; !unicode_ranges[i].name.is_empty(); i++) { |
| 1280 | _add_glyph_range_item(unicode_ranges[i].start, unicode_ranges[i].end, unicode_ranges[i].name); |
| 1281 | } |
| 1282 | glyphs_split->add_child(glyph_tree); |
| 1283 | glyph_tree->connect("item_activated", callable_mp(this, &DynamicFontImportSettingsDialog::_range_edited)); |
| 1284 | glyph_tree->connect(SceneStringName(item_selected), callable_mp(this, &DynamicFontImportSettingsDialog::_range_selected)); |
| 1285 | |
| 1286 | // Common |
| 1287 | |
| 1288 | import_settings_data.instantiate(); |
| 1289 | import_settings_data->owner = this; |
| 1290 | |
| 1291 | set_ok_button_text(TTR("Reimport")); |
| 1292 | set_cancel_button_text(TTR("Close")); |
| 1293 | } |