2020-12-27 15:30:33 +02:00
/**************************************************************************/
2022-02-14 14:00:03 +01:00
/* dynamic_font_import_settings.cpp */
2020-12-27 15:30:33 +02:00
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
2022-02-14 14:00:03 +01:00
# include "dynamic_font_import_settings.h"
2020-12-27 15:30:33 +02:00
2025-01-21 16:55:42 +01:00
# include "unicode_ranges.inc"
2022-11-09 14:45:21 +02:00
# include "core/config/project_settings.h"
2024-12-21 01:11:43 +08:00
# include "core/string/translation.h"
2022-02-12 02:46:22 +01:00
# include "editor/editor_file_system.h"
# include "editor/editor_inspector.h"
# include "editor/editor_locale_dialog.h"
2020-12-27 15:30:33 +02:00
# include "editor/editor_node.h"
2023-08-13 02:33:39 +02:00
# include "editor/editor_string_names.h"
2023-04-07 18:59:49 +02:00
# include "editor/gui/editor_file_dialog.h"
2024-01-15 13:14:55 +01:00
# include "editor/themes/editor_scale.h"
2024-12-21 01:11:43 +08:00
# include "scene/gui/split_container.h"
2020-12-27 15:30:33 +02:00
/*************************************************************************/
/* Settings data */
/*************************************************************************/
2022-05-09 12:47:10 +03:00
bool DynamicFontImportSettingsData : : _set ( const StringName & p_name , const Variant & p_value ) {
if ( defaults . has ( p_name ) & & defaults [ p_name ] = = p_value ) {
settings . erase ( p_name ) ;
} else {
settings [ p_name ] = p_value ;
2020-12-27 15:30:33 +02:00
}
2022-05-09 12:47:10 +03:00
return true ;
}
2020-12-27 15:30:33 +02:00
2022-05-09 12:47:10 +03:00
bool DynamicFontImportSettingsData : : _get ( const StringName & p_name , Variant & r_ret ) const {
if ( settings . has ( p_name ) ) {
r_ret = settings [ p_name ] ;
return true ;
}
if ( defaults . has ( p_name ) ) {
r_ret = defaults [ p_name ] ;
return true ;
2020-12-27 15:30:33 +02:00
}
2022-05-09 12:47:10 +03:00
return false ;
}
2020-12-27 15:30:33 +02:00
2022-05-09 12:47:10 +03:00
void DynamicFontImportSettingsData : : _get_property_list ( List < PropertyInfo > * p_list ) const {
for ( const List < ResourceImporter : : ImportOption > : : Element * E = options . front ( ) ; E ; E = E - > next ( ) ) {
if ( owner & & owner - > import_settings_data . is_valid ( ) ) {
2025-06-19 15:05:52 +03:00
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 " ) ) {
2022-05-09 12:47:10 +03:00
continue ;
}
if ( ! owner - > import_settings_data - > get ( " multichannel_signed_distance_field " ) & & ( E - > get ( ) . option . name = = " msdf_pixel_range " | | E - > get ( ) . option . name = = " msdf_size " ) ) {
continue ;
2020-12-27 15:30:33 +02:00
}
}
2022-05-09 12:47:10 +03:00
p_list - > push_back ( E - > get ( ) . option ) ;
2020-12-27 15:30:33 +02:00
}
2022-05-09 12:47:10 +03:00
}
Ref < FontFile > DynamicFontImportSettingsData : : get_font ( ) const {
return fd ;
}
2020-12-27 15:30:33 +02:00
/*************************************************************************/
/* Glyph ranges */
/*************************************************************************/
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : _add_glyph_range_item ( int32_t p_start , int32_t p_end , const String & p_name ) {
2020-12-27 15:30:33 +02:00
const int page_size = 512 ;
int pages = ( p_end - p_start ) / page_size ;
int remain = ( p_end - p_start ) % page_size ;
int32_t start = p_start ;
for ( int i = 0 ; i < pages ; i + + ) {
TreeItem * item = glyph_tree - > create_item ( glyph_root ) ;
ERR_FAIL_NULL ( item ) ;
2022-01-22 21:10:30 +01:00
item - > set_cell_mode ( 0 , TreeItem : : CELL_MODE_CHECK ) ;
2020-12-27 15:30:33 +02:00
item - > set_text ( 0 , _pad_zeros ( String : : num_int64 ( start , 16 ) ) + " - " + _pad_zeros ( String : : num_int64 ( start + page_size , 16 ) ) ) ;
item - > set_text ( 1 , p_name ) ;
item - > set_metadata ( 0 , Vector2i ( start , start + page_size ) ) ;
start + = page_size ;
}
if ( remain > 0 ) {
TreeItem * item = glyph_tree - > create_item ( glyph_root ) ;
ERR_FAIL_NULL ( item ) ;
2022-01-22 21:10:30 +01:00
item - > set_cell_mode ( 0 , TreeItem : : CELL_MODE_CHECK ) ;
2020-12-27 15:30:33 +02:00
item - > set_text ( 0 , _pad_zeros ( String : : num_int64 ( start , 16 ) ) + " - " + _pad_zeros ( String : : num_int64 ( p_end , 16 ) ) ) ;
item - > set_text ( 1 , p_name ) ;
item - > set_metadata ( 0 , Vector2i ( start , p_end ) ) ;
}
}
/*************************************************************************/
/* Page 1 callbacks: Rendering Options */
/*************************************************************************/
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : _main_prop_changed ( const String & p_edited_property ) {
2020-12-27 15:30:33 +02:00
// Update font preview.
2022-05-09 12:47:10 +03:00
if ( font_preview . is_valid ( ) ) {
2022-08-12 14:03:28 +03:00
if ( p_edited_property = = " antialiasing " ) {
font_preview - > set_antialiasing ( ( TextServer : : FontAntialiasing ) import_settings_data - > get ( " antialiasing " ) . operator int ( ) ) ;
2025-02-07 11:16:46 +02:00
_variations_validate ( ) ;
2022-05-09 12:47:10 +03:00
} else if ( p_edited_property = = " generate_mipmaps " ) {
font_preview - > set_generate_mipmaps ( import_settings_data - > get ( " generate_mipmaps " ) ) ;
2024-03-11 13:42:16 +02:00
} else if ( p_edited_property = = " disable_embedded_bitmaps " ) {
font_preview - > set_disable_embedded_bitmaps ( import_settings_data - > get ( " disable_embedded_bitmaps " ) ) ;
2022-05-09 12:47:10 +03:00
} else if ( p_edited_property = = " multichannel_signed_distance_field " ) {
font_preview - > set_multichannel_signed_distance_field ( import_settings_data - > get ( " multichannel_signed_distance_field " ) ) ;
_variation_selected ( ) ;
_variations_validate ( ) ;
} else if ( p_edited_property = = " msdf_pixel_range " ) {
font_preview - > set_msdf_pixel_range ( import_settings_data - > get ( " msdf_pixel_range " ) ) ;
} else if ( p_edited_property = = " msdf_size " ) {
font_preview - > set_msdf_size ( import_settings_data - > get ( " msdf_size " ) ) ;
2022-11-21 15:04:01 +02:00
} else if ( p_edited_property = = " allow_system_fallback " ) {
font_preview - > set_allow_system_fallback ( import_settings_data - > get ( " allow_system_fallback " ) ) ;
2022-05-09 12:47:10 +03:00
} else if ( p_edited_property = = " force_autohinter " ) {
font_preview - > set_force_autohinter ( import_settings_data - > get ( " force_autohinter " ) ) ;
2025-04-01 13:36:10 +03:00
} else if ( p_edited_property = = " modulate_color_glyphs " ) {
font_preview - > set_modulate_color_glyphs ( import_settings_data - > get ( " modulate_color_glyphs " ) ) ;
2022-05-09 12:47:10 +03:00
} else if ( p_edited_property = = " hinting " ) {
font_preview - > set_hinting ( ( TextServer : : Hinting ) import_settings_data - > get ( " hinting " ) . operator int ( ) ) ;
} else if ( p_edited_property = = " subpixel_positioning " ) {
2025-02-07 11:16:46 +02:00
int font_subpixel_positioning = import_settings_data - > get ( " subpixel_positioning " ) . operator int ( ) ;
if ( font_subpixel_positioning = = 4 /* Auto (Except Pixel Fonts) */ ) {
if ( is_pixel ) {
font_subpixel_positioning = TextServer : : SUBPIXEL_POSITIONING_DISABLED ;
} else {
font_subpixel_positioning = TextServer : : SUBPIXEL_POSITIONING_AUTO ;
}
}
font_preview - > set_subpixel_positioning ( ( TextServer : : SubpixelPositioning ) font_subpixel_positioning ) ;
_variations_validate ( ) ;
2024-10-30 11:14:11 +02:00
} else if ( p_edited_property = = " keep_rounding_remainders " ) {
font_preview - > set_keep_rounding_remainders ( import_settings_data - > get ( " keep_rounding_remainders " ) ) ;
2025-06-19 15:05:52 +03:00
} else if ( p_edited_property = = " oversampling " ) {
font_preview - > set_oversampling ( import_settings_data - > get ( " oversampling " ) ) ;
2020-12-27 15:30:33 +02:00
}
}
2022-05-09 12:47:10 +03:00
2024-05-14 15:57:29 +02:00
font_preview_label - > add_theme_font_override ( SceneStringName ( font ) , font_preview ) ;
font_preview_label - > add_theme_font_size_override ( SceneStringName ( font_size ) , 200 * EDSCALE ) ;
2022-08-13 23:21:24 +02:00
font_preview_label - > queue_redraw ( ) ;
2020-12-27 15:30:33 +02:00
}
/*************************************************************************/
/* Page 2 callbacks: Configurations */
/*************************************************************************/
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : _variation_add ( ) {
2020-12-27 15:30:33 +02:00
TreeItem * vars_item = vars_list - > create_item ( vars_list_root ) ;
ERR_FAIL_NULL ( vars_item ) ;
2022-11-03 19:15:12 +01:00
vars_item - > set_text ( 0 , TTR ( " New Configuration " ) ) ;
2020-12-27 15:30:33 +02:00
vars_item - > set_editable ( 0 , true ) ;
2023-08-13 02:33:39 +02:00
vars_item - > add_button ( 1 , get_editor_theme_icon ( SNAME ( " Remove " ) ) , BUTTON_REMOVE_VAR , false , TTR ( " Remove Variation " ) ) ;
2020-12-27 15:30:33 +02:00
vars_item - > set_button_color ( 1 , 0 , Color ( 1 , 1 , 1 , 0.75 ) ) ;
Ref < DynamicFontImportSettingsData > import_variation_data ;
import_variation_data . instantiate ( ) ;
import_variation_data - > owner = this ;
2024-07-26 11:52:26 +02:00
ERR_FAIL_COND ( import_variation_data . is_null ( ) ) ;
2020-12-27 15:30:33 +02:00
2025-02-03 14:16:27 +08:00
for ( const ResourceImporter : : ImportOption & option : options_variations ) {
import_variation_data - > defaults [ option . option . name ] = option . default_value ;
2020-12-27 15:30:33 +02:00
}
import_variation_data - > options = options_variations ;
inspector_vars - > edit ( import_variation_data . ptr ( ) ) ;
import_variation_data - > notify_property_list_changed ( ) ;
2022-05-09 12:47:10 +03:00
import_variation_data - > fd = font_main ;
2020-12-27 15:30:33 +02:00
vars_item - > set_metadata ( 0 , import_variation_data ) ;
_variations_validate ( ) ;
}
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : _variation_selected ( ) {
2020-12-27 15:30:33 +02:00
TreeItem * vars_item = vars_list - > get_selected ( ) ;
if ( vars_item ) {
Ref < DynamicFontImportSettingsData > import_variation_data = vars_item - > get_metadata ( 0 ) ;
2024-07-26 11:52:26 +02:00
ERR_FAIL_COND ( import_variation_data . is_null ( ) ) ;
2020-12-27 15:30:33 +02:00
inspector_vars - > edit ( import_variation_data . ptr ( ) ) ;
import_variation_data - > notify_property_list_changed ( ) ;
2022-05-09 12:47:10 +03:00
2023-02-09 17:01:32 +08:00
label_glyphs - > set_text ( vformat ( TTR ( " Preloaded glyphs: %d " ) , import_variation_data - > selected_glyphs . size ( ) ) ) ;
2022-05-09 12:47:10 +03:00
_range_selected ( ) ;
_change_text_opts ( ) ;
2022-11-09 14:45:21 +02:00
btn_fill - > set_disabled ( false ) ;
btn_fill_locales - > set_disabled ( false ) ;
} else {
btn_fill - > set_disabled ( true ) ;
btn_fill_locales - > set_disabled ( true ) ;
2020-12-27 15:30:33 +02:00
}
}
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : _variation_remove ( Object * p_item , int p_column , int p_id , MouseButton p_button ) {
2021-09-18 09:33:18 +02:00
if ( p_button ! = MouseButton : : LEFT ) {
return ;
}
2020-12-27 15:30:33 +02:00
TreeItem * vars_item = ( TreeItem * ) p_item ;
ERR_FAIL_NULL ( vars_item ) ;
inspector_vars - > edit ( nullptr ) ;
vars_list_root - > remove_child ( vars_item ) ;
memdelete ( vars_item ) ;
if ( vars_list_root - > get_first_child ( ) ) {
Ref < DynamicFontImportSettingsData > import_variation_data = vars_list_root - > get_first_child ( ) - > get_metadata ( 0 ) ;
inspector_vars - > edit ( import_variation_data . ptr ( ) ) ;
import_variation_data - > notify_property_list_changed ( ) ;
}
_variations_validate ( ) ;
2022-11-09 14:45:21 +02:00
vars_item = vars_list - > get_selected ( ) ;
if ( vars_item ) {
btn_fill - > set_disabled ( false ) ;
btn_fill_locales - > set_disabled ( false ) ;
} else {
btn_fill - > set_disabled ( true ) ;
btn_fill_locales - > set_disabled ( true ) ;
}
2020-12-27 15:30:33 +02:00
}
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : _variation_changed ( const String & p_edited_property ) {
2020-12-27 15:30:33 +02:00
_variations_validate ( ) ;
}
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : _variations_validate ( ) {
2020-12-27 15:30:33 +02:00
String warn ;
if ( ! vars_list_root - > get_first_child ( ) ) {
2022-02-21 19:30:16 +01:00
warn = TTR ( " Warning: There are no configurations specified, no glyphs will be pre-rendered. " ) ;
2020-12-27 15:30:33 +02:00
}
for ( TreeItem * vars_item_a = vars_list_root - > get_first_child ( ) ; vars_item_a ; vars_item_a = vars_item_a - > get_next ( ) ) {
Ref < DynamicFontImportSettingsData > import_variation_data_a = vars_item_a - > get_metadata ( 0 ) ;
2024-07-26 11:52:26 +02:00
ERR_FAIL_COND ( import_variation_data_a . is_null ( ) ) ;
2020-12-27 15:30:33 +02:00
for ( TreeItem * vars_item_b = vars_list_root - > get_first_child ( ) ; vars_item_b ; vars_item_b = vars_item_b - > get_next ( ) ) {
if ( vars_item_b ! = vars_item_a ) {
bool match = true ;
2022-05-13 15:04:37 +02:00
for ( const KeyValue < StringName , Variant > & E : import_variation_data_a - > settings ) {
2020-12-27 15:30:33 +02:00
Ref < DynamicFontImportSettingsData > import_variation_data_b = vars_item_b - > get_metadata ( 0 ) ;
2024-07-26 11:52:26 +02:00
ERR_FAIL_COND ( import_variation_data_b . is_null ( ) ) ;
2022-05-13 15:04:37 +02:00
match = match & & ( import_variation_data_b - > settings [ E . key ] = = E . value ) ;
2020-12-27 15:30:33 +02:00
}
if ( match ) {
2022-02-21 19:30:16 +01:00
warn = TTR ( " Warning: Multiple configurations have identical settings. Duplicates will be ignored. " ) ;
2020-12-27 15:30:33 +02:00
break ;
}
}
}
}
2022-08-12 14:03:28 +03:00
if ( ( TextServer : : FontAntialiasing ) ( int ) import_settings_data - > get ( " antialiasing " ) = = TextServer : : FONT_ANTIALIASING_LCD ) {
2022-11-03 18:37:21 +01:00
warn + = " \n " + TTR ( " Note: LCD Subpixel antialiasing is selected, each of the glyphs will be pre-rendered for all supported subpixel layouts (5x). " ) ;
2022-08-12 14:03:28 +03:00
}
2025-02-07 11:16:46 +02:00
int font_subpixel_positioning = import_settings_data - > get ( " subpixel_positioning " ) . operator int ( ) ;
if ( font_subpixel_positioning = = 4 /* Auto (Except Pixel Fonts) */ ) {
if ( is_pixel ) {
font_subpixel_positioning = TextServer : : SUBPIXEL_POSITIONING_DISABLED ;
} else {
font_subpixel_positioning = TextServer : : SUBPIXEL_POSITIONING_AUTO ;
}
}
if ( ( TextServer : : SubpixelPositioning ) font_subpixel_positioning ! = TextServer : : SUBPIXEL_POSITIONING_DISABLED ) {
2022-11-03 18:37:21 +01:00
warn + = " \n " + TTR ( " Note: Subpixel positioning is selected, each of the glyphs might be pre-rendered for multiple subpixel offsets (up to 4x). " ) ;
2022-08-12 14:03:28 +03:00
}
2020-12-27 15:30:33 +02:00
if ( warn . is_empty ( ) ) {
label_warn - > set_text ( " " ) ;
label_warn - > hide ( ) ;
} else {
label_warn - > set_text ( warn ) ;
label_warn - > show ( ) ;
}
}
/*************************************************************************/
2022-05-09 12:47:10 +03:00
/* Page 2.1 callbacks: Text to select glyphs */
2020-12-27 15:30:33 +02:00
/*************************************************************************/
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : _change_text_opts ( ) {
2022-05-09 12:47:10 +03:00
Ref < DynamicFontImportSettingsData > import_variation_data ;
TreeItem * vars_item = vars_list - > get_selected ( ) ;
if ( vars_item ) {
import_variation_data = vars_item - > get_metadata ( 0 ) ;
2020-12-27 15:30:33 +02:00
}
2022-05-09 12:47:10 +03:00
if ( import_variation_data . is_null ( ) ) {
return ;
}
Ref < FontVariation > font_main_text ;
font_main_text . instantiate ( ) ;
font_main_text - > set_base_font ( font_main ) ;
font_main_text - > set_opentype_features ( text_settings_data - > get ( " opentype_features " ) ) ;
font_main_text - > set_variation_opentype ( import_variation_data - > get ( " variation_opentype " ) ) ;
font_main_text - > set_variation_embolden ( import_variation_data - > get ( " variation_embolden " ) ) ;
font_main_text - > set_variation_face_index ( import_variation_data - > get ( " variation_face_index " ) ) ;
font_main_text - > set_variation_transform ( import_variation_data - > get ( " variation_transform " ) ) ;
2024-05-14 15:57:29 +02:00
text_edit - > add_theme_font_override ( SceneStringName ( font ) , font_main_text ) ;
2020-12-27 15:30:33 +02:00
}
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : _glyph_update_lbl ( ) {
2022-11-09 14:45:21 +02:00
Ref < DynamicFontImportSettingsData > import_variation_data ;
TreeItem * vars_item = vars_list - > get_selected ( ) ;
if ( vars_item ) {
import_variation_data = vars_item - > get_metadata ( 0 ) ;
}
if ( import_variation_data . is_null ( ) ) {
return ;
}
int linked_glyphs = 0 ;
for ( const char32_t & c : import_variation_data - > selected_chars ) {
if ( import_variation_data - > selected_glyphs . has ( font_main - > get_glyph_index ( 16 , c ) ) ) {
linked_glyphs + + ;
}
}
int unlinked_glyphs = import_variation_data - > selected_glyphs . size ( ) - linked_glyphs ;
2023-02-09 17:01:32 +08:00
label_glyphs - > set_text ( vformat ( TTR ( " Preloaded glyphs: %d " ) , unlinked_glyphs + import_variation_data - > selected_chars . size ( ) ) ) ;
2022-11-09 14:45:21 +02:00
}
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : _glyph_clear ( ) {
2022-05-09 12:47:10 +03:00
Ref < DynamicFontImportSettingsData > import_variation_data ;
TreeItem * vars_item = vars_list - > get_selected ( ) ;
if ( vars_item ) {
import_variation_data = vars_item - > get_metadata ( 0 ) ;
}
if ( import_variation_data . is_null ( ) ) {
return ;
}
import_variation_data - > selected_glyphs . clear ( ) ;
2022-11-09 14:45:21 +02:00
_glyph_update_lbl ( ) ;
2020-12-27 15:30:33 +02:00
_range_selected ( ) ;
}
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : _glyph_text_selected ( ) {
2022-05-09 12:47:10 +03:00
Ref < DynamicFontImportSettingsData > import_variation_data ;
2020-12-27 15:30:33 +02:00
2022-05-09 12:47:10 +03:00
TreeItem * vars_item = vars_list - > get_selected ( ) ;
if ( vars_item ) {
import_variation_data = vars_item - > get_metadata ( 0 ) ;
}
if ( import_variation_data . is_null ( ) ) {
return ;
}
2020-12-27 15:30:33 +02:00
RID text_rid = TS - > create_shaped_text ( ) ;
if ( text_rid . is_valid ( ) ) {
2022-05-09 12:47:10 +03:00
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 " ) ) ;
2020-12-27 15:30:33 +02:00
TS - > shaped_text_shape ( text_rid ) ;
2021-08-28 00:19:51 +03:00
const Glyph * gl = TS - > shaped_text_get_glyphs ( text_rid ) ;
const int gl_size = TS - > shaped_text_get_glyph_count ( text_rid ) ;
2020-12-27 15:30:33 +02:00
2021-08-28 00:19:51 +03:00
for ( int i = 0 ; i < gl_size ; i + + ) {
2020-12-27 15:30:33 +02:00
if ( gl [ i ] . font_rid . is_valid ( ) & & gl [ i ] . index ! = 0 ) {
2022-05-09 12:47:10 +03:00
import_variation_data - > selected_glyphs . insert ( gl [ i ] . index ) ;
2020-12-27 15:30:33 +02:00
}
}
2022-02-13 14:41:29 +02:00
TS - > free_rid ( text_rid ) ;
2022-11-09 14:45:21 +02:00
_glyph_update_lbl ( ) ;
2020-12-27 15:30:33 +02:00
}
_range_selected ( ) ;
}
/*************************************************************************/
2022-05-09 12:47:10 +03:00
/* Page 2.2 callbacks: Character map */
2020-12-27 15:30:33 +02:00
/*************************************************************************/
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : _glyph_selected ( ) {
2022-05-09 12:47:10 +03:00
Ref < DynamicFontImportSettingsData > import_variation_data ;
TreeItem * vars_item = vars_list - > get_selected ( ) ;
if ( vars_item ) {
import_variation_data = vars_item - > get_metadata ( 0 ) ;
}
if ( import_variation_data . is_null ( ) ) {
return ;
}
2020-12-27 15:30:33 +02:00
TreeItem * item = glyph_table - > get_selected ( ) ;
ERR_FAIL_NULL ( item ) ;
2023-08-13 02:33:39 +02:00
Color scol = glyph_table - > get_theme_color ( SNAME ( " box_selection_fill_color " ) , EditorStringName ( Editor ) ) ;
Color fcol = glyph_table - > get_theme_color ( SNAME ( " font_selected_color " ) , EditorStringName ( Editor ) ) ;
2020-12-27 15:30:33 +02:00
scol . a = 1.f ;
int32_t c = item - > get_metadata ( glyph_table - > get_selected_column ( ) ) ;
if ( font_main - > has_char ( c ) ) {
if ( _char_update ( c ) ) {
item - > set_custom_color ( glyph_table - > get_selected_column ( ) , fcol ) ;
item - > set_custom_bg_color ( glyph_table - > get_selected_column ( ) , scol ) ;
} else {
item - > clear_custom_color ( glyph_table - > get_selected_column ( ) ) ;
item - > clear_custom_bg_color ( glyph_table - > get_selected_column ( ) ) ;
}
}
2022-11-09 14:45:21 +02:00
_glyph_update_lbl ( ) ;
2022-01-22 21:10:30 +01:00
item = glyph_tree - > get_selected ( ) ;
ERR_FAIL_NULL ( item ) ;
Vector2i range = item - > get_metadata ( 0 ) ;
int total_chars = range . y - range . x ;
int selected_count = 0 ;
for ( int i = range . x ; i < range . y ; i + + ) {
if ( ! font_main - > has_char ( i ) ) {
total_chars - - ;
}
2022-05-09 12:47:10 +03:00
if ( import_variation_data - > selected_chars . has ( i ) ) {
2022-01-22 21:10:30 +01:00
selected_count + + ;
}
}
if ( selected_count = = total_chars ) {
item - > set_checked ( 0 , true ) ;
} else if ( selected_count > 0 ) {
item - > set_indeterminate ( 0 , true ) ;
} else {
item - > set_checked ( 0 , false ) ;
}
2020-12-27 15:30:33 +02:00
}
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : _range_edited ( ) {
2020-12-27 15:30:33 +02:00
TreeItem * item = glyph_tree - > get_selected ( ) ;
ERR_FAIL_NULL ( item ) ;
Vector2i range = item - > get_metadata ( 0 ) ;
_range_update ( range . x , range . y ) ;
}
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : _range_selected ( ) {
2020-12-27 15:30:33 +02:00
TreeItem * item = glyph_tree - > get_selected ( ) ;
if ( item ) {
Vector2i range = item - > get_metadata ( 0 ) ;
_edit_range ( range . x , range . y ) ;
}
}
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : _edit_range ( int32_t p_start , int32_t p_end ) {
2022-05-09 12:47:10 +03:00
Ref < DynamicFontImportSettingsData > import_variation_data ;
TreeItem * vars_item = vars_list - > get_selected ( ) ;
if ( vars_item ) {
import_variation_data = vars_item - > get_metadata ( 0 ) ;
}
if ( import_variation_data . is_null ( ) ) {
return ;
}
2020-12-27 15:30:33 +02:00
glyph_table - > clear ( ) ;
TreeItem * root = glyph_table - > create_item ( ) ;
ERR_FAIL_NULL ( root ) ;
2023-08-13 02:33:39 +02:00
Color scol = glyph_table - > get_theme_color ( SNAME ( " box_selection_fill_color " ) , EditorStringName ( Editor ) ) ;
Color fcol = glyph_table - > get_theme_color ( SNAME ( " font_selected_color " ) , EditorStringName ( Editor ) ) ;
2020-12-27 15:30:33 +02:00
scol . a = 1.f ;
TreeItem * item = nullptr ;
int col = 0 ;
2022-05-09 12:47:10 +03:00
Ref < Font > font_main_big = font_main - > duplicate ( ) ;
2020-12-27 15:30:33 +02:00
for ( int32_t c = p_start ; c < = p_end ; c + + ) {
if ( col = = 0 ) {
item = glyph_table - > create_item ( root ) ;
ERR_FAIL_NULL ( item ) ;
item - > set_text ( 0 , _pad_zeros ( String : : num_int64 ( c , 16 ) ) ) ;
2021-11-24 20:58:47 -06:00
item - > set_text_alignment ( 0 , HORIZONTAL_ALIGNMENT_LEFT ) ;
2020-12-27 15:30:33 +02:00
item - > set_selectable ( 0 , false ) ;
2023-08-13 02:33:39 +02:00
item - > set_custom_bg_color ( 0 , glyph_table - > get_theme_color ( SNAME ( " dark_color_3 " ) , EditorStringName ( Editor ) ) ) ;
2020-12-27 15:30:33 +02:00
}
if ( font_main - > has_char ( c ) ) {
item - > set_text ( col + 1 , String : : chr ( c ) ) ;
item - > set_custom_color ( col + 1 , Color ( 1 , 1 , 1 ) ) ;
2022-05-09 12:47:10 +03:00
if ( import_variation_data - > selected_chars . has ( c ) | | import_variation_data - > selected_glyphs . has ( font_main - > get_glyph_index ( 16 , c ) ) ) {
2020-12-27 15:30:33 +02:00
item - > set_custom_color ( col + 1 , fcol ) ;
item - > set_custom_bg_color ( col + 1 , scol ) ;
} else {
item - > clear_custom_color ( col + 1 ) ;
item - > clear_custom_bg_color ( col + 1 ) ;
}
} else {
2023-08-13 02:33:39 +02:00
item - > set_custom_bg_color ( col + 1 , glyph_table - > get_theme_color ( SNAME ( " dark_color_2 " ) , EditorStringName ( Editor ) ) ) ;
2020-12-27 15:30:33 +02:00
}
item - > set_metadata ( col + 1 , c ) ;
2021-11-24 20:58:47 -06:00
item - > set_text_alignment ( col + 1 , HORIZONTAL_ALIGNMENT_CENTER ) ;
2020-12-27 15:30:33 +02:00
item - > set_selectable ( col + 1 , true ) ;
2022-05-09 12:47:10 +03:00
item - > set_custom_font ( col + 1 , font_main_big ) ;
2024-05-14 15:57:29 +02:00
item - > set_custom_font_size ( col + 1 , get_theme_font_size ( SceneStringName ( font_size ) ) * 2 ) ;
2020-12-27 15:30:33 +02:00
col + + ;
if ( col = = 16 ) {
col = 0 ;
}
}
2022-11-09 14:45:21 +02:00
_glyph_update_lbl ( ) ;
2020-12-27 15:30:33 +02:00
}
2023-10-06 02:00:36 -05:00
bool DynamicFontImportSettingsDialog : : _char_update ( int32_t p_char ) {
2022-05-09 12:47:10 +03:00
Ref < DynamicFontImportSettingsData > import_variation_data ;
TreeItem * vars_item = vars_list - > get_selected ( ) ;
if ( vars_item ) {
import_variation_data = vars_item - > get_metadata ( 0 ) ;
}
if ( import_variation_data . is_null ( ) ) {
2020-12-27 15:30:33 +02:00
return false ;
2022-05-09 12:47:10 +03:00
}
if ( import_variation_data - > selected_chars . has ( p_char ) ) {
import_variation_data - > selected_chars . erase ( p_char ) ;
return false ;
2023-05-30 12:47:50 +03:00
} else if ( font_main . is_valid ( ) & & import_variation_data - > selected_glyphs . has ( font_main - > get_glyph_index ( 16 , p_char ) ) ) {
2022-05-09 12:47:10 +03:00
import_variation_data - > selected_glyphs . erase ( font_main - > get_glyph_index ( 16 , p_char ) ) ;
2020-12-27 15:30:33 +02:00
return false ;
} else {
2022-05-09 12:47:10 +03:00
import_variation_data - > selected_chars . insert ( p_char ) ;
2020-12-27 15:30:33 +02:00
return true ;
}
}
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : _range_update ( int32_t p_start , int32_t p_end ) {
2022-05-09 12:47:10 +03:00
Ref < DynamicFontImportSettingsData > import_variation_data ;
TreeItem * vars_item = vars_list - > get_selected ( ) ;
if ( vars_item ) {
import_variation_data = vars_item - > get_metadata ( 0 ) ;
}
if ( import_variation_data . is_null ( ) ) {
return ;
}
2020-12-27 15:30:33 +02:00
bool all_selected = true ;
for ( int32_t i = p_start ; i < = p_end ; i + + ) {
if ( font_main - > has_char ( i ) ) {
2022-05-09 12:47:10 +03:00
if ( font_main . is_valid ( ) ) {
all_selected = all_selected & & ( import_variation_data - > selected_chars . has ( i ) | | import_variation_data - > selected_glyphs . has ( font_main - > get_glyph_index ( 16 , i ) ) ) ;
2020-12-27 15:30:33 +02:00
} else {
2022-05-09 12:47:10 +03:00
all_selected = all_selected & & import_variation_data - > selected_chars . has ( i ) ;
2020-12-27 15:30:33 +02:00
}
}
}
for ( int32_t i = p_start ; i < = p_end ; i + + ) {
if ( font_main - > has_char ( i ) ) {
if ( ! all_selected ) {
2022-05-09 12:47:10 +03:00
import_variation_data - > selected_chars . insert ( i ) ;
2020-12-27 15:30:33 +02:00
} else {
2022-05-09 12:47:10 +03:00
import_variation_data - > selected_chars . erase ( i ) ;
if ( font_main . is_valid ( ) ) {
import_variation_data - > selected_glyphs . erase ( font_main - > get_glyph_index ( 16 , i ) ) ;
2020-12-27 15:30:33 +02:00
}
}
}
}
_edit_range ( p_start , p_end ) ;
2022-01-22 21:10:30 +01:00
TreeItem * item = glyph_tree - > get_selected ( ) ;
ERR_FAIL_NULL ( item ) ;
item - > set_checked ( 0 , ! all_selected ) ;
2020-12-27 15:30:33 +02:00
}
/*************************************************************************/
/* Common */
/*************************************************************************/
2023-10-06 02:00:36 -05:00
DynamicFontImportSettingsDialog * DynamicFontImportSettingsDialog : : singleton = nullptr ;
2020-12-27 15:30:33 +02:00
2023-10-06 02:00:36 -05:00
String DynamicFontImportSettingsDialog : : _pad_zeros ( const String & p_hex ) const {
2020-12-27 15:30:33 +02:00
int len = CLAMP ( 5 - p_hex . length ( ) , 0 , 5 ) ;
return String ( " 0 " ) . repeat ( len ) + p_hex ;
}
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : _notification ( int p_what ) {
2022-02-15 21:44:22 -05:00
switch ( p_what ) {
case NOTIFICATION_READY : {
2024-05-14 14:28:18 +02:00
connect ( SceneStringName ( confirmed ) , callable_mp ( this , & DynamicFontImportSettingsDialog : : _re_import ) ) ;
2022-02-15 21:44:22 -05:00
} break ;
case NOTIFICATION_THEME_CHANGED : {
2024-10-09 15:21:47 -07:00
add_var - > set_button_icon ( get_editor_theme_icon ( SNAME ( " Add " ) ) ) ;
2024-05-14 15:57:29 +02:00
label_warn - > add_theme_color_override ( SceneStringName ( font_color ) , get_theme_color ( SNAME ( " warning_color " ) , EditorStringName ( Editor ) ) ) ;
2022-02-15 21:44:22 -05:00
} break ;
2020-12-27 15:30:33 +02:00
}
}
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : _re_import ( ) {
2022-05-13 15:04:37 +02:00
HashMap < StringName , Variant > main_settings ;
2020-12-27 15:30:33 +02:00
2022-06-07 11:35:59 +03:00
main_settings [ " face_index " ] = import_settings_data - > get ( " face_index " ) ;
2022-08-12 14:03:28 +03:00
main_settings [ " antialiasing " ] = import_settings_data - > get ( " antialiasing " ) ;
2022-04-19 13:27:18 +03:00
main_settings [ " generate_mipmaps " ] = import_settings_data - > get ( " generate_mipmaps " ) ;
2024-03-11 13:42:16 +02:00
main_settings [ " disable_embedded_bitmaps " ] = import_settings_data - > get ( " disable_embedded_bitmaps " ) ;
2020-12-27 15:30:33 +02:00
main_settings [ " multichannel_signed_distance_field " ] = import_settings_data - > get ( " multichannel_signed_distance_field " ) ;
main_settings [ " msdf_pixel_range " ] = import_settings_data - > get ( " msdf_pixel_range " ) ;
main_settings [ " msdf_size " ] = import_settings_data - > get ( " msdf_size " ) ;
2022-11-21 15:04:01 +02:00
main_settings [ " allow_system_fallback " ] = import_settings_data - > get ( " allow_system_fallback " ) ;
2020-12-27 15:30:33 +02:00
main_settings [ " force_autohinter " ] = import_settings_data - > get ( " force_autohinter " ) ;
2025-04-01 13:36:10 +03:00
main_settings [ " modulate_color_glyphs " ] = import_settings_data - > get ( " modulate_color_glyphs " ) ;
2020-12-27 15:30:33 +02:00
main_settings [ " hinting " ] = import_settings_data - > get ( " hinting " ) ;
2022-01-10 10:13:22 +02:00
main_settings [ " subpixel_positioning " ] = import_settings_data - > get ( " subpixel_positioning " ) ;
2024-10-30 11:14:11 +02:00
main_settings [ " keep_rounding_remainders " ] = import_settings_data - > get ( " keep_rounding_remainders " ) ;
2025-06-19 15:05:52 +03:00
main_settings [ " oversampling " ] = import_settings_data - > get ( " oversampling " ) ;
2022-05-09 12:47:10 +03:00
main_settings [ " fallbacks " ] = import_settings_data - > get ( " fallbacks " ) ;
2020-12-27 15:30:33 +02:00
main_settings [ " compress " ] = import_settings_data - > get ( " compress " ) ;
2022-05-09 12:47:10 +03:00
Array configurations ;
2020-12-27 15:30:33 +02:00
for ( TreeItem * vars_item = vars_list_root - > get_first_child ( ) ; vars_item ; vars_item = vars_item - > get_next ( ) ) {
Ref < DynamicFontImportSettingsData > import_variation_data = vars_item - > get_metadata ( 0 ) ;
2024-07-26 11:52:26 +02:00
ERR_FAIL_COND ( import_variation_data . is_null ( ) ) ;
2020-12-27 15:30:33 +02:00
2022-05-09 12:47:10 +03:00
Dictionary preload_config ;
preload_config [ " name " ] = vars_item - > get_text ( 0 ) ;
2022-12-12 22:14:15 +02:00
Size2i conf_size = Vector2i ( 16 , 0 ) ;
2022-05-13 15:04:37 +02:00
for ( const KeyValue < StringName , Variant > & E : import_variation_data - > settings ) {
2022-12-12 22:14:15 +02:00
if ( E . key = = " size " ) {
conf_size . x = E . value ;
}
if ( E . key = = " outline_size " ) {
conf_size . y = E . value ;
} else {
preload_config [ E . key ] = E . value ;
}
2020-12-27 15:30:33 +02:00
}
2022-12-12 22:14:15 +02:00
preload_config [ " size " ] = conf_size ;
2022-05-09 12:47:10 +03:00
Array chars ;
for ( const char32_t & E : import_variation_data - > selected_chars ) {
chars . push_back ( E ) ;
2020-12-27 15:30:33 +02:00
}
2022-05-09 12:47:10 +03:00
preload_config [ " chars " ] = chars ;
2020-12-27 15:30:33 +02:00
2022-05-09 12:47:10 +03:00
Array glyphs ;
for ( const int32_t & E : import_variation_data - > selected_glyphs ) {
glyphs . push_back ( E ) ;
2020-12-27 15:30:33 +02:00
}
2022-05-09 12:47:10 +03:00
preload_config [ " glyphs " ] = glyphs ;
2020-12-27 15:30:33 +02:00
2022-05-09 12:47:10 +03:00
configurations . push_back ( preload_config ) ;
2021-11-18 23:36:22 +02:00
}
2022-05-09 12:47:10 +03:00
main_settings [ " preload " ] = configurations ;
main_settings [ " language_support " ] = import_settings_data - > get ( " language_support " ) ;
main_settings [ " script_support " ] = import_settings_data - > get ( " script_support " ) ;
main_settings [ " opentype_features " ] = import_settings_data - > get ( " opentype_features " ) ;
2021-11-18 23:36:22 +02:00
2020-12-27 15:30:33 +02:00
if ( OS : : get_singleton ( ) - > is_stdout_verbose ( ) ) {
print_line ( " Import settings: " ) ;
2022-05-13 15:04:37 +02:00
for ( const KeyValue < StringName , Variant > & E : main_settings ) {
print_line ( String ( " " ) + String ( E . key ) . utf8 ( ) . get_data ( ) + " == " + String ( E . value ) . utf8 ( ) . get_data ( ) ) ;
2020-12-27 15:30:33 +02:00
}
}
EditorFileSystem : : get_singleton ( ) - > reimport_file_with_custom_parameters ( base_path , " font_data_dynamic " , main_settings ) ;
}
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : _locale_edited ( ) {
2022-11-09 14:45:21 +02:00
TreeItem * item = locale_tree - > get_selected ( ) ;
ERR_FAIL_NULL ( item ) ;
item - > set_checked ( 0 , ! item - > is_checked ( 0 ) ) ;
}
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : _process_locales ( ) {
2022-11-09 14:45:21 +02:00
Ref < DynamicFontImportSettingsData > import_variation_data ;
TreeItem * vars_item = vars_list - > get_selected ( ) ;
if ( vars_item ) {
import_variation_data = vars_item - > get_metadata ( 0 ) ;
}
if ( import_variation_data . is_null ( ) ) {
return ;
}
for ( int i = 0 ; i < locale_root - > get_child_count ( ) ; i + + ) {
TreeItem * item = locale_root - > get_child ( i ) ;
if ( item ) {
if ( item - > is_checked ( 0 ) ) {
String locale = item - > get_text ( 0 ) ;
Ref < Translation > tr = ResourceLoader : : load ( locale ) ;
if ( tr . is_valid ( ) ) {
Vector < String > messages = tr - > get_translated_message_list ( ) ;
for ( const String & E : messages ) {
RID text_rid = TS - > create_shaped_text ( ) ;
if ( text_rid . is_valid ( ) ) {
TS - > shaped_text_add_string ( text_rid , E , font_main - > get_rids ( ) , 16 , Dictionary ( ) , tr - > get_locale ( ) ) ;
TS - > shaped_text_shape ( text_rid ) ;
const Glyph * gl = TS - > shaped_text_get_glyphs ( text_rid ) ;
const int gl_size = TS - > shaped_text_get_glyph_count ( text_rid ) ;
for ( int j = 0 ; j < gl_size ; j + + ) {
if ( gl [ j ] . font_rid . is_valid ( ) & & gl [ j ] . index ! = 0 ) {
import_variation_data - > selected_glyphs . insert ( gl [ j ] . index ) ;
}
}
TS - > free_rid ( text_rid ) ;
}
}
}
}
}
}
_glyph_update_lbl ( ) ;
_range_selected ( ) ;
}
2023-10-06 02:00:36 -05:00
void DynamicFontImportSettingsDialog : : open_settings ( const String & p_path ) {
2020-12-27 15:30:33 +02:00
// Load base font data.
2022-11-21 15:04:01 +02:00
Vector < uint8_t > font_data = FileAccess : : get_file_as_bytes ( p_path ) ;
2020-12-27 15:30:33 +02:00
2022-11-09 14:45:21 +02:00
// Load project locale list.
locale_tree - > clear ( ) ;
locale_root = locale_tree - > create_item ( ) ;
ERR_FAIL_NULL ( locale_root ) ;
Vector < String > translations = GLOBAL_GET ( " internationalization/locale/translations " ) ;
for ( const String & E : translations ) {
TreeItem * item = locale_tree - > create_item ( locale_root ) ;
ERR_FAIL_NULL ( item ) ;
item - > set_cell_mode ( 0 , TreeItem : : CELL_MODE_CHECK ) ;
item - > set_text ( 0 , E ) ;
}
2020-12-27 15:30:33 +02:00
// Load font for preview.
font_preview . instantiate ( ) ;
2022-09-29 12:53:28 +03:00
font_preview - > set_data ( font_data ) ;
2020-12-27 15:30:33 +02:00
2025-02-07 11:16:46 +02:00
Array rids = font_preview - > get_rids ( ) ;
if ( ! rids . is_empty ( ) ) {
PackedInt32Array glyphs = TS - > font_get_supported_glyphs ( rids [ 0 ] ) ;
is_pixel = true ;
for ( int32_t gl : glyphs ) {
Dictionary ct = TS - > font_get_glyph_contours ( rids [ 0 ] , 16 , gl ) ;
PackedInt32Array contours = ct [ " contours " ] ;
PackedVector3Array points = ct [ " points " ] ;
int prev_start = 0 ;
for ( int i = 0 ; i < contours . size ( ) ; i + + ) {
for ( int j = prev_start ; j < = contours [ i ] ; j + + ) {
int next_point = ( j < contours [ i ] ) ? ( j + 1 ) : prev_start ;
2025-04-26 10:05:07 -05:00
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 ) ) ) {
2025-02-07 11:16:46 +02:00
is_pixel = false ;
break ;
}
}
prev_start = contours [ i ] + 1 ;
if ( ! is_pixel ) {
break ;
}
}
if ( ! is_pixel ) {
break ;
}
}
}
2022-05-09 12:47:10 +03:00
String font_name = vformat ( " %s (%s) " , font_preview - > get_font_name ( ) , font_preview - > get_font_style_name ( ) ) ;
2020-12-27 15:30:33 +02:00
String sample ;
static const String sample_base = U " 12漢字ԱբΑ α А б Α α אבا بܐܒހށआআਆઆଆஆఆಆആආกิກິༀကႠა한글ሀ ᎣᐁᚁᚠᜀᜠᝀᝠកᠠᤁᥐAb😀 " ;
for ( int i = 0 ; i < sample_base . length ( ) ; i + + ) {
2022-05-09 12:47:10 +03:00
if ( font_preview - > has_char ( sample_base [ i ] ) ) {
2020-12-27 15:30:33 +02:00
sample + = sample_base [ i ] ;
}
}
if ( sample . is_empty ( ) ) {
2022-05-09 12:47:10 +03:00
sample = font_preview - > get_supported_chars ( ) . substr ( 0 , 6 ) ;
2020-12-27 15:30:33 +02:00
}
font_preview_label - > set_text ( sample ) ;
2023-08-13 02:33:39 +02:00
Ref < Font > bold_font = get_theme_font ( SNAME ( " bold " ) , EditorStringName ( EditorFonts ) ) ;
2023-05-30 12:47:50 +03:00
if ( bold_font . is_valid ( ) ) {
2022-05-09 12:47:10 +03:00
font_name_label - > add_theme_font_override ( " bold_font " , bold_font ) ;
}
font_name_label - > set_text ( font_name ) ;
2020-12-27 15:30:33 +02:00
2022-05-09 12:47:10 +03:00
// Load second copy of font with MSDF disabled for the glyph table and metadata extraction.
2020-12-27 15:30:33 +02:00
font_main . instantiate ( ) ;
2022-09-29 12:53:28 +03:00
font_main - > set_data ( font_data ) ;
2022-05-09 12:47:10 +03:00
font_main - > set_multichannel_signed_distance_field ( false ) ;
2024-05-14 15:57:29 +02:00
text_edit - > add_theme_font_override ( SceneStringName ( font ) , font_main ) ;
2020-12-27 15:30:33 +02:00
base_path = p_path ;
inspector_vars - > edit ( nullptr ) ;
2022-07-26 10:28:44 +08:00
inspector_text - > edit ( nullptr ) ;
2020-12-27 15:30:33 +02:00
inspector_general - > edit ( nullptr ) ;
2022-05-09 12:47:10 +03:00
text_settings_data . instantiate ( ) ;
2024-07-26 11:52:26 +02:00
ERR_FAIL_COND ( text_settings_data . is_null ( ) ) ;
2022-05-09 12:47:10 +03:00
text_settings_data - > owner = this ;
2025-02-03 14:16:27 +08:00
for ( const ResourceImporter : : ImportOption & option : options_text ) {
text_settings_data - > defaults [ option . option . name ] = option . default_value ;
2022-05-09 12:47:10 +03:00
}
text_settings_data - > fd = font_main ;
text_settings_data - > options = options_text ;
inspector_text - > edit ( text_settings_data . ptr ( ) ) ;
2024-05-14 15:57:29 +02:00
int gww = get_theme_font ( SceneStringName ( font ) ) - > get_string_size ( " 00000 " ) . x + 50 ;
2020-12-27 15:30:33 +02:00
glyph_table - > set_column_custom_minimum_width ( 0 , gww ) ;
glyph_table - > clear ( ) ;
vars_list - > clear ( ) ;
2022-11-09 14:45:21 +02:00
glyph_tree - > set_selected ( glyph_root - > get_child ( 0 ) ) ;
2020-12-27 15:30:33 +02:00
vars_list_root = vars_list - > create_item ( ) ;
2022-09-22 08:20:40 +03:00
import_settings_data - > settings . clear ( ) ;
2020-12-27 15:30:33 +02:00
import_settings_data - > defaults . clear ( ) ;
2025-02-03 14:16:27 +08:00
for ( const ResourceImporter : : ImportOption & option : options_general ) {
import_settings_data - > defaults [ option . option . name ] = option . default_value ;
2020-12-27 15:30:33 +02:00
}
Ref < ConfigFile > config ;
config . instantiate ( ) ;
2024-07-26 11:52:26 +02:00
ERR_FAIL_COND ( config . is_null ( ) ) ;
2020-12-27 15:30:33 +02:00
Error err = config - > load ( p_path + " .import " ) ;
print_verbose ( " Loading import settings: " ) ;
if ( err = = OK ) {
2025-04-23 23:32:05 -04:00
Vector < String > keys = config - > get_section_keys ( " params " ) ;
2025-02-03 14:16:27 +08:00
for ( const String & key : keys ) {
2020-12-27 15:30:33 +02:00
print_verbose ( String ( " " ) + key + " == " + String ( config - > get_value ( " params " , key ) ) ) ;
2022-05-09 12:47:10 +03:00
if ( key = = " preload " ) {
Array preload_configurations = config - > get_value ( " params " , key ) ;
for ( int i = 0 ; i < preload_configurations . size ( ) ; i + + ) {
Dictionary preload_config = preload_configurations [ i ] ;
Dictionary variation = preload_config . has ( " variation_opentype " ) ? preload_config [ " variation_opentype " ] . operator Dictionary ( ) : Dictionary ( ) ;
double embolden = preload_config . has ( " variation_embolden " ) ? preload_config [ " variation_embolden " ] . operator double ( ) : 0 ;
int face_index = preload_config . has ( " variation_face_index " ) ? preload_config [ " variation_face_index " ] . operator int ( ) : 0 ;
Transform2D transform = preload_config . has ( " variation_transform " ) ? preload_config [ " variation_transform " ] . operator Transform2D ( ) : Transform2D ( ) ;
2022-09-29 12:53:28 +03:00
Vector2i font_size = preload_config . has ( " size " ) ? preload_config [ " size " ] . operator Vector2i ( ) : Vector2i ( 16 , 0 ) ;
2022-05-09 12:47:10 +03:00
String cfg_name = preload_config . has ( " name " ) ? preload_config [ " name " ] . operator String ( ) : vformat ( " Configuration %d " , i ) ;
2020-12-27 15:30:33 +02:00
TreeItem * vars_item = vars_list - > create_item ( vars_list_root ) ;
ERR_FAIL_NULL ( vars_item ) ;
2022-05-09 12:47:10 +03:00
vars_item - > set_text ( 0 , cfg_name ) ;
2020-12-27 15:30:33 +02:00
vars_item - > set_editable ( 0 , true ) ;
2023-08-13 02:33:39 +02:00
vars_item - > add_button ( 1 , get_editor_theme_icon ( SNAME ( " Remove " ) ) , BUTTON_REMOVE_VAR , false , TTR ( " Remove Variation " ) ) ;
2020-12-27 15:30:33 +02:00
vars_item - > set_button_color ( 1 , 0 , Color ( 1 , 1 , 1 , 0.75 ) ) ;
Ref < DynamicFontImportSettingsData > import_variation_data_custom ;
import_variation_data_custom . instantiate ( ) ;
2024-07-26 11:52:26 +02:00
ERR_FAIL_COND ( import_variation_data_custom . is_null ( ) ) ;
2020-12-27 15:30:33 +02:00
2022-05-09 12:47:10 +03:00
import_variation_data_custom - > owner = this ;
2025-02-03 14:16:27 +08:00
for ( const ResourceImporter : : ImportOption & option : options_variations ) {
import_variation_data_custom - > defaults [ option . option . name ] = option . default_value ;
2020-12-27 15:30:33 +02:00
}
2022-05-09 12:47:10 +03:00
import_variation_data_custom - > fd = font_main ;
2020-12-27 15:30:33 +02:00
2022-05-09 12:47:10 +03:00
import_variation_data_custom - > options = options_variations ;
2020-12-27 15:30:33 +02:00
vars_item - > set_metadata ( 0 , import_variation_data_custom ) ;
2022-05-09 12:47:10 +03:00
2022-09-29 12:53:28 +03:00
import_variation_data_custom - > set ( " size " , font_size . x ) ;
import_variation_data_custom - > set ( " outline_size " , font_size . y ) ;
2022-05-09 12:47:10 +03:00
import_variation_data_custom - > set ( " variation_opentype " , variation ) ;
import_variation_data_custom - > set ( " variation_embolden " , embolden ) ;
import_variation_data_custom - > set ( " variation_face_index " , face_index ) ;
import_variation_data_custom - > set ( " variation_transform " , transform ) ;
Array chars = preload_config [ " chars " ] ;
for ( int j = 0 ; j < chars . size ( ) ; j + + ) {
char32_t c = chars [ j ] . operator int ( ) ;
import_variation_data_custom - > selected_chars . insert ( c ) ;
2020-12-27 15:30:33 +02:00
}
2022-05-09 12:47:10 +03:00
Array glyphs = preload_config [ " glyphs " ] ;
for ( int j = 0 ; j < glyphs . size ( ) ; j + + ) {
int32_t c = glyphs [ j ] ;
import_variation_data_custom - > selected_glyphs . insert ( c ) ;
2021-11-18 23:36:22 +02:00
}
}
2022-11-09 14:45:21 +02:00
if ( preload_configurations . is_empty ( ) ) {
_variation_add ( ) ; // Add default variation.
}
vars_list - > set_selected ( vars_list_root - > get_child ( 0 ) ) ;
2020-12-27 15:30:33 +02:00
} else {
Variant value = config - > get_value ( " params " , key ) ;
import_settings_data - > defaults [ key ] = value ;
}
}
}
2022-05-09 12:47:10 +03:00
import_settings_data - > fd = font_main ;
2020-12-27 15:30:33 +02:00
import_settings_data - > options = options_general ;
inspector_general - > edit ( import_settings_data . ptr ( ) ) ;
import_settings_data - > notify_property_list_changed ( ) ;
2022-05-09 12:47:10 +03:00
if ( font_preview . is_valid ( ) ) {
2022-08-12 14:03:28 +03:00
font_preview - > set_antialiasing ( ( TextServer : : FontAntialiasing ) import_settings_data - > get ( " antialiasing " ) . operator int ( ) ) ;
2022-05-09 12:47:10 +03:00
font_preview - > set_multichannel_signed_distance_field ( import_settings_data - > get ( " multichannel_signed_distance_field " ) ) ;
font_preview - > set_msdf_pixel_range ( import_settings_data - > get ( " msdf_pixel_range " ) ) ;
font_preview - > set_msdf_size ( import_settings_data - > get ( " msdf_size " ) ) ;
2022-11-21 15:04:01 +02:00
font_preview - > set_allow_system_fallback ( import_settings_data - > get ( " allow_system_fallback " ) ) ;
2022-05-09 12:47:10 +03:00
font_preview - > set_force_autohinter ( import_settings_data - > get ( " force_autohinter " ) ) ;
2025-04-01 13:36:10 +03:00
font_preview - > set_modulate_color_glyphs ( import_settings_data - > get ( " modulate_color_glyphs " ) ) ;
2022-05-09 12:47:10 +03:00
font_preview - > set_hinting ( ( TextServer : : Hinting ) import_settings_data - > get ( " hinting " ) . operator int ( ) ) ;
2025-02-07 11:16:46 +02:00
int font_subpixel_positioning = import_settings_data - > get ( " subpixel_positioning " ) . operator int ( ) ;
if ( font_subpixel_positioning = = 4 /* Auto (Except Pixel Fonts) */ ) {
if ( is_pixel ) {
font_subpixel_positioning = TextServer : : SUBPIXEL_POSITIONING_DISABLED ;
} else {
font_subpixel_positioning = TextServer : : SUBPIXEL_POSITIONING_AUTO ;
}
}
font_preview - > set_subpixel_positioning ( ( TextServer : : SubpixelPositioning ) font_subpixel_positioning ) ;
2024-10-30 11:14:11 +02:00
font_preview - > set_keep_rounding_remainders ( import_settings_data - > get ( " keep_rounding_remainders " ) ) ;
2025-06-19 15:05:52 +03:00
font_preview - > set_oversampling ( import_settings_data - > get ( " oversampling " ) ) ;
2020-12-27 15:30:33 +02:00
}
2024-05-14 15:57:29 +02:00
font_preview_label - > add_theme_font_override ( SceneStringName ( font ) , font_preview ) ;
font_preview_label - > add_theme_font_size_override ( SceneStringName ( font_size ) , 200 * EDSCALE ) ;
2022-08-13 23:21:24 +02:00
font_preview_label - > queue_redraw ( ) ;
2020-12-27 15:30:33 +02:00
_variations_validate ( ) ;
popup_centered_ratio ( ) ;
set_title ( vformat ( TTR ( " Advanced Import Settings for '%s' " ) , base_path . get_file ( ) ) ) ;
}
2023-10-06 02:00:36 -05:00
DynamicFontImportSettingsDialog * DynamicFontImportSettingsDialog : : get_singleton ( ) {
2020-12-27 15:30:33 +02:00
return singleton ;
}
2023-10-06 02:00:36 -05:00
DynamicFontImportSettingsDialog : : DynamicFontImportSettingsDialog ( ) {
2020-12-27 15:30:33 +02:00
singleton = this ;
2022-05-09 12:47:10 +03:00
options_general . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : NIL , " Rendering " , PROPERTY_HINT_NONE , " " , PROPERTY_USAGE_GROUP ) , Variant ( ) ) ) ;
2022-11-03 18:37:21 +01:00
options_general . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : INT , " antialiasing " , PROPERTY_HINT_ENUM , " None,Grayscale,LCD Subpixel " ) , 1 ) ) ;
2022-04-19 13:27:18 +03:00
options_general . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : BOOL , " generate_mipmaps " ) , false ) ) ;
2024-03-11 13:42:16 +02:00
options_general . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : BOOL , " disable_embedded_bitmaps " ) , true ) ) ;
2020-12-27 15:30:33 +02:00
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 ) ) ;
options_general . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : INT , " msdf_pixel_range " , PROPERTY_HINT_RANGE , " 1,100,1 " ) , 8 ) ) ;
options_general . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : INT , " msdf_size " , PROPERTY_HINT_RANGE , " 1,250,1 " ) , 48 ) ) ;
2022-11-21 15:04:01 +02:00
options_general . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : BOOL , " allow_system_fallback " ) , true ) ) ;
2020-12-27 15:30:33 +02:00
options_general . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : BOOL , " force_autohinter " ) , false ) ) ;
2025-04-01 13:36:10 +03:00
options_general . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : BOOL , " modulate_color_glyphs " ) , false ) ) ;
2020-12-27 15:30:33 +02:00
options_general . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : INT , " hinting " , PROPERTY_HINT_ENUM , " None,Light,Normal " ) , 1 ) ) ;
2025-02-07 11:16:46 +02:00
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 ) ) ;
2024-10-30 11:14:11 +02:00
options_general . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : BOOL , " keep_rounding_remainders " ) , true ) ) ;
2025-06-19 15:05:52 +03:00
options_general . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : FLOAT , " oversampling " , PROPERTY_HINT_RANGE , " 0,10,0.1 " ) , 0.0 ) ) ;
2020-12-27 15:30:33 +02:00
2022-05-09 12:47:10 +03:00
options_general . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : NIL , " Metadata Overrides " , PROPERTY_HINT_NONE , " " , PROPERTY_USAGE_GROUP ) , Variant ( ) ) ) ;
options_general . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : DICTIONARY , " language_support " ) , Dictionary ( ) ) ) ;
options_general . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : DICTIONARY , " script_support " ) , Dictionary ( ) ) ) ;
options_general . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : DICTIONARY , " opentype_features " ) , Dictionary ( ) ) ) ;
2020-12-27 15:30:33 +02:00
2022-05-09 12:47:10 +03:00
options_general . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : NIL , " Fallbacks " , PROPERTY_HINT_NONE , " " , PROPERTY_USAGE_GROUP ) , Variant ( ) ) ) ;
2022-11-22 16:10:41 +01:00
options_general . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : ARRAY , " fallbacks " , PROPERTY_HINT_ARRAY_TYPE , MAKE_RESOURCE_TYPE_HINT ( " Font " ) ) , Array ( ) ) ) ;
2021-11-18 23:36:22 +02:00
2022-05-09 12:47:10 +03:00
options_general . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : NIL , " Compress " , PROPERTY_HINT_NONE , " " , PROPERTY_USAGE_GROUP ) , Variant ( ) ) ) ;
options_general . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : BOOL , " compress " , PROPERTY_HINT_NONE , " " ) , false ) ) ;
2021-11-18 23:36:22 +02:00
2022-05-09 12:47:10 +03:00
options_text . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : DICTIONARY , " opentype_features " ) , Dictionary ( ) ) ) ;
options_text . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : STRING , " language " , PROPERTY_HINT_LOCALE_ID , " " ) , " " ) ) ;
2021-11-18 23:36:22 +02:00
2022-05-09 12:47:10 +03:00
options_variations . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : INT , " size " , PROPERTY_HINT_RANGE , " 0,127,1 " ) , 16 ) ) ;
options_variations . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : INT , " outline_size " , PROPERTY_HINT_RANGE , " 0,127,1 " ) , 0 ) ) ;
options_variations . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : NIL , " Variation " , PROPERTY_HINT_NONE , " variation " , PROPERTY_USAGE_GROUP ) , Variant ( ) ) ) ;
options_variations . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : DICTIONARY , " variation_opentype " ) , Dictionary ( ) ) ) ;
options_variations . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : FLOAT , " variation_embolden " , PROPERTY_HINT_RANGE , " -2,2,0.01 " ) , 0 ) ) ;
options_variations . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : INT , " variation_face_index " ) , 0 ) ) ;
options_variations . push_back ( ResourceImporter : : ImportOption ( PropertyInfo ( Variant : : TRANSFORM2D , " variation_transform " ) , Transform2D ( ) ) ) ;
2021-11-18 23:36:22 +02:00
2020-12-27 15:30:33 +02:00
// Root layout
VBoxContainer * root_vb = memnew ( VBoxContainer ) ;
add_child ( root_vb ) ;
main_pages = memnew ( TabContainer ) ;
2022-03-07 11:32:49 -03:00
main_pages - > set_tab_alignment ( TabBar : : ALIGNMENT_CENTER ) ;
2020-12-27 15:30:33 +02:00
main_pages - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
main_pages - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2022-05-26 21:12:09 -05:00
main_pages - > set_theme_type_variation ( " TabContainerOdd " ) ;
2020-12-27 15:30:33 +02:00
root_vb - > add_child ( main_pages ) ;
label_warn = memnew ( Label ) ;
2025-04-22 11:57:16 +03:00
label_warn - > set_focus_mode ( Control : : FOCUS_ACCESSIBILITY ) ;
2021-11-24 20:58:47 -06:00
label_warn - > set_horizontal_alignment ( HORIZONTAL_ALIGNMENT_CENTER ) ;
2020-12-27 15:30:33 +02:00
label_warn - > set_text ( " " ) ;
root_vb - > add_child ( label_warn ) ;
label_warn - > hide ( ) ;
// Page 1 layout: Rendering Options
VBoxContainer * page1_vb = memnew ( VBoxContainer ) ;
2022-03-17 22:45:33 -05:00
page1_vb - > set_name ( TTR ( " Rendering Options " ) ) ;
2020-12-27 15:30:33 +02:00
main_pages - > add_child ( page1_vb ) ;
page1_description = memnew ( Label ) ;
2025-04-22 11:57:16 +03:00
page1_description - > set_focus_mode ( Control : : FOCUS_ACCESSIBILITY ) ;
2022-05-09 12:47:10 +03:00
page1_description - > set_text ( TTR ( " Select font rendering options, fallback font, and metadata override: " ) ) ;
2020-12-27 15:30:33 +02:00
page1_description - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
page1_vb - > add_child ( page1_description ) ;
HSplitContainer * page1_hb = memnew ( HSplitContainer ) ;
page1_hb - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
page1_hb - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
page1_vb - > add_child ( page1_hb ) ;
2022-05-09 12:47:10 +03:00
VBoxContainer * page1_lbl_vb = memnew ( VBoxContainer ) ;
page1_lbl_vb - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
page1_lbl_vb - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
page1_hb - > add_child ( page1_lbl_vb ) ;
font_name_label = memnew ( Label ) ;
2025-04-22 11:57:16 +03:00
font_name_label - > set_focus_mode ( Control : : FOCUS_ACCESSIBILITY ) ;
2022-05-09 12:47:10 +03:00
font_name_label - > set_horizontal_alignment ( HORIZONTAL_ALIGNMENT_CENTER ) ;
font_name_label - > set_clip_text ( true ) ;
font_name_label - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
page1_lbl_vb - > add_child ( font_name_label ) ;
2020-12-27 15:30:33 +02:00
font_preview_label = memnew ( Label ) ;
2021-11-24 20:58:47 -06:00
font_preview_label - > set_horizontal_alignment ( HORIZONTAL_ALIGNMENT_CENTER ) ;
font_preview_label - > set_vertical_alignment ( VERTICAL_ALIGNMENT_CENTER ) ;
2022-06-15 11:01:45 +03:00
font_preview_label - > set_autowrap_mode ( TextServer : : AUTOWRAP_ARBITRARY ) ;
2020-12-27 15:30:33 +02:00
font_preview_label - > set_clip_text ( true ) ;
font_preview_label - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
font_preview_label - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2022-05-09 12:47:10 +03:00
page1_lbl_vb - > add_child ( font_preview_label ) ;
2020-12-27 15:30:33 +02:00
inspector_general = memnew ( EditorInspector ) ;
inspector_general - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
inspector_general - > set_custom_minimum_size ( Size2 ( 300 * EDSCALE , 250 * EDSCALE ) ) ;
page1_hb - > add_child ( inspector_general ) ;
2023-10-06 02:00:36 -05:00
inspector_general - > connect ( " property_edited " , callable_mp ( this , & DynamicFontImportSettingsDialog : : _main_prop_changed ) ) ;
2020-12-27 15:30:33 +02:00
// Page 2 layout: Configurations
VBoxContainer * page2_vb = memnew ( VBoxContainer ) ;
2022-11-03 19:15:12 +01:00
page2_vb - > set_name ( TTR ( " Pre-render Configurations " ) ) ;
2020-12-27 15:30:33 +02:00
main_pages - > add_child ( page2_vb ) ;
page2_description = memnew ( Label ) ;
2025-04-22 11:57:16 +03:00
page2_description - > set_focus_mode ( Control : : FOCUS_ACCESSIBILITY ) ;
2022-05-09 12:47:10 +03:00
page2_description - > set_text ( TTR ( " Add font size, and variation coordinates, and select glyphs to pre-render: " ) ) ;
2020-12-27 15:30:33 +02:00
page2_description - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2022-06-15 11:01:45 +03:00
page2_description - > set_autowrap_mode ( TextServer : : AUTOWRAP_WORD_SMART ) ;
2023-12-14 10:41:22 +08:00
page2_description - > set_custom_minimum_size ( Size2 ( 300 * EDSCALE , 1 ) ) ;
2020-12-27 15:30:33 +02:00
page2_vb - > add_child ( page2_description ) ;
HSplitContainer * page2_hb = memnew ( HSplitContainer ) ;
page2_hb - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
page2_hb - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
page2_vb - > add_child ( page2_hb ) ;
VBoxContainer * page2_side_vb = memnew ( VBoxContainer ) ;
page2_hb - > add_child ( page2_side_vb ) ;
HBoxContainer * page2_hb_vars = memnew ( HBoxContainer ) ;
page2_side_vb - > add_child ( page2_hb_vars ) ;
label_vars = memnew ( Label ) ;
2021-11-24 20:58:47 -06:00
label_vars - > set_horizontal_alignment ( HORIZONTAL_ALIGNMENT_CENTER ) ;
2020-12-27 15:30:33 +02:00
label_vars - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
label_vars - > set_text ( TTR ( " Configuration: " ) ) ;
2023-10-19 18:05:19 +02:00
page2_hb_vars - > add_child ( label_vars ) ;
2020-12-27 15:30:33 +02:00
add_var = memnew ( Button ) ;
2025-03-21 09:55:22 +02:00
add_var - > set_tooltip_text ( TTR ( " Add new font variation configuration. " ) ) ;
2023-10-19 18:05:19 +02:00
page2_hb_vars - > add_child ( add_var ) ;
2024-05-14 09:40:21 +02:00
add_var - > connect ( SceneStringName ( pressed ) , callable_mp ( this , & DynamicFontImportSettingsDialog : : _variation_add ) ) ;
2020-12-27 15:30:33 +02:00
vars_list = memnew ( Tree ) ;
2024-03-17 16:28:18 +08:00
vars_list - > set_auto_translate_mode ( AUTO_TRANSLATE_MODE_DISABLED ) ;
2025-06-12 07:55:29 +03:00
vars_list - > set_accessibility_name ( TTRC ( " Configuration: " ) ) ;
2020-12-27 15:30:33 +02:00
vars_list - > set_custom_minimum_size ( Size2 ( 300 * EDSCALE , 0 ) ) ;
vars_list - > set_hide_root ( true ) ;
vars_list - > set_columns ( 2 ) ;
vars_list - > set_column_expand ( 0 , true ) ;
vars_list - > set_column_custom_minimum_width ( 0 , 80 * EDSCALE ) ;
vars_list - > set_column_expand ( 1 , false ) ;
vars_list - > set_column_custom_minimum_width ( 1 , 50 * EDSCALE ) ;
2023-10-19 18:05:19 +02:00
vars_list - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
page2_side_vb - > add_child ( vars_list ) ;
2024-05-14 14:21:31 +02:00
vars_list - > connect ( SceneStringName ( item_selected ) , callable_mp ( this , & DynamicFontImportSettingsDialog : : _variation_selected ) ) ;
2023-10-06 02:00:36 -05:00
vars_list - > connect ( " button_clicked " , callable_mp ( this , & DynamicFontImportSettingsDialog : : _variation_remove ) ) ;
2020-12-27 15:30:33 +02:00
inspector_vars = memnew ( EditorInspector ) ;
inspector_vars - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2022-05-09 12:47:10 +03:00
page2_side_vb - > add_child ( inspector_vars ) ;
2023-10-06 02:00:36 -05:00
inspector_vars - > connect ( " property_edited " , callable_mp ( this , & DynamicFontImportSettingsDialog : : _variation_changed ) ) ;
2020-12-27 15:30:33 +02:00
2022-11-09 14:45:21 +02:00
VBoxContainer * preload_pages_vb = memnew ( VBoxContainer ) ;
page2_hb - > add_child ( preload_pages_vb ) ;
2022-05-09 12:47:10 +03:00
preload_pages = memnew ( TabContainer ) ;
preload_pages - > set_tab_alignment ( TabBar : : ALIGNMENT_CENTER ) ;
preload_pages - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
preload_pages - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2022-11-09 14:45:21 +02:00
preload_pages_vb - > add_child ( preload_pages ) ;
HBoxContainer * gl_hb = memnew ( HBoxContainer ) ;
gl_hb - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2023-10-19 18:05:19 +02:00
preload_pages_vb - > add_child ( gl_hb ) ;
2022-11-09 14:45:21 +02:00
label_glyphs = memnew ( Label ) ;
2025-04-22 11:57:16 +03:00
label_glyphs - > set_focus_mode ( Control : : FOCUS_ACCESSIBILITY ) ;
2023-02-09 17:01:32 +08:00
label_glyphs - > set_text ( vformat ( TTR ( " Preloaded glyphs: %d " ) , 0 ) ) ;
2022-11-09 14:45:21 +02:00
label_glyphs - > set_custom_minimum_size ( Size2 ( 50 * EDSCALE , 0 ) ) ;
2023-10-19 18:05:19 +02:00
gl_hb - > add_child ( label_glyphs ) ;
2022-11-09 14:45:21 +02:00
Button * btn_clear = memnew ( Button ) ;
btn_clear - > set_text ( TTR ( " Clear Glyph List " ) ) ;
2023-10-19 18:05:19 +02:00
gl_hb - > add_child ( btn_clear ) ;
2024-05-14 09:40:21 +02:00
btn_clear - > connect ( SceneStringName ( pressed ) , callable_mp ( this , & DynamicFontImportSettingsDialog : : _glyph_clear ) ) ;
2022-11-09 14:45:21 +02:00
VBoxContainer * page2_0_vb = memnew ( VBoxContainer ) ;
page2_0_vb - > set_name ( TTR ( " Glyphs from the Translations " ) ) ;
preload_pages - > add_child ( page2_0_vb ) ;
page2_0_description = memnew ( Label ) ;
2025-04-22 11:57:16 +03:00
page2_0_description - > set_focus_mode ( Control : : FOCUS_ACCESSIBILITY ) ;
2022-11-09 14:45:21 +02:00
page2_0_description - > set_text ( TTR ( " Select translations to add all required glyphs to pre-render list: " ) ) ;
page2_0_description - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
page2_0_description - > set_autowrap_mode ( TextServer : : AUTOWRAP_WORD_SMART ) ;
2023-12-14 10:41:22 +08:00
page2_0_description - > set_custom_minimum_size ( Size2 ( 300 * EDSCALE , 1 ) ) ;
2022-11-09 14:45:21 +02:00
page2_0_vb - > add_child ( page2_0_description ) ;
locale_tree = memnew ( Tree ) ;
2024-03-17 16:28:18 +08:00
locale_tree - > set_auto_translate_mode ( AUTO_TRANSLATE_MODE_DISABLED ) ;
2022-11-09 14:45:21 +02:00
locale_tree - > set_columns ( 1 ) ;
locale_tree - > set_hide_root ( true ) ;
locale_tree - > set_column_expand ( 0 , true ) ;
locale_tree - > set_column_custom_minimum_width ( 0 , 120 * EDSCALE ) ;
locale_tree - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2023-10-19 18:05:19 +02:00
page2_0_vb - > add_child ( locale_tree ) ;
2023-10-06 02:00:36 -05:00
locale_tree - > connect ( " item_activated " , callable_mp ( this , & DynamicFontImportSettingsDialog : : _locale_edited ) ) ;
2023-10-19 18:05:19 +02:00
2022-11-09 14:45:21 +02:00
locale_root = locale_tree - > create_item ( ) ;
HBoxContainer * locale_hb = memnew ( HBoxContainer ) ;
locale_hb - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2023-10-19 18:05:19 +02:00
page2_0_vb - > add_child ( locale_hb ) ;
2022-11-09 14:45:21 +02:00
btn_fill_locales = memnew ( Button ) ;
btn_fill_locales - > set_text ( TTR ( " Shape all Strings in the Translations and Add Glyphs " ) ) ;
2023-10-19 18:05:19 +02:00
locale_hb - > add_child ( btn_fill_locales ) ;
2024-05-14 09:40:21 +02:00
btn_fill_locales - > connect ( SceneStringName ( pressed ) , callable_mp ( this , & DynamicFontImportSettingsDialog : : _process_locales ) ) ;
2020-12-27 15:30:33 +02:00
2022-05-09 12:47:10 +03:00
// Page 2.1 layout: Text to select glyphs
VBoxContainer * page2_1_vb = memnew ( VBoxContainer ) ;
page2_1_vb - > set_name ( TTR ( " Glyphs from the Text " ) ) ;
preload_pages - > add_child ( page2_1_vb ) ;
2020-12-27 15:30:33 +02:00
2022-05-09 12:47:10 +03:00
page2_1_description = memnew ( Label ) ;
2025-04-22 11:57:16 +03:00
page2_1_description - > set_focus_mode ( Control : : FOCUS_ACCESSIBILITY ) ;
2022-11-09 14:45:21 +02:00
page2_1_description - > set_text ( TTR ( " Enter a text and select OpenType features to shape and add all required glyphs to pre-render list: " ) ) ;
2022-05-09 12:47:10 +03:00
page2_1_description - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
page2_1_description - > set_autowrap_mode ( TextServer : : AUTOWRAP_WORD_SMART ) ;
2023-12-14 10:41:22 +08:00
page2_1_description - > set_custom_minimum_size ( Size2 ( 300 * EDSCALE , 1 ) ) ;
2022-05-09 12:47:10 +03:00
page2_1_vb - > add_child ( page2_1_description ) ;
2020-12-27 15:30:33 +02:00
2022-05-09 12:47:10 +03:00
HSplitContainer * page2_1_hb = memnew ( HSplitContainer ) ;
page2_1_hb - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
page2_1_hb - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2023-10-19 18:05:19 +02:00
page2_1_vb - > add_child ( page2_1_hb ) ;
2020-12-27 15:30:33 +02:00
2022-05-09 12:47:10 +03:00
inspector_text = memnew ( EditorInspector ) ;
2020-12-27 15:30:33 +02:00
2022-05-09 12:47:10 +03:00
inspector_text - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
inspector_text - > set_custom_minimum_size ( Size2 ( 300 * EDSCALE , 250 * EDSCALE ) ) ;
page2_1_hb - > add_child ( inspector_text ) ;
2023-10-06 02:00:36 -05:00
inspector_text - > connect ( " property_edited " , callable_mp ( this , & DynamicFontImportSettingsDialog : : _change_text_opts ) ) ;
2020-12-27 15:30:33 +02:00
text_edit = memnew ( TextEdit ) ;
text_edit - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
text_edit - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2023-10-19 18:05:19 +02:00
page2_1_hb - > add_child ( text_edit ) ;
2020-12-27 15:30:33 +02:00
HBoxContainer * text_hb = memnew ( HBoxContainer ) ;
text_hb - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2023-10-19 18:05:19 +02:00
page2_1_vb - > add_child ( text_hb ) ;
2020-12-27 15:30:33 +02:00
2022-11-09 14:45:21 +02:00
btn_fill = memnew ( Button ) ;
2022-11-03 19:15:12 +01:00
btn_fill - > set_text ( TTR ( " Shape Text and Add Glyphs " ) ) ;
2023-10-19 18:05:19 +02:00
text_hb - > add_child ( btn_fill ) ;
2024-05-14 09:40:21 +02:00
btn_fill - > connect ( SceneStringName ( pressed ) , callable_mp ( this , & DynamicFontImportSettingsDialog : : _glyph_text_selected ) ) ;
2020-12-27 15:30:33 +02:00
2022-05-09 12:47:10 +03:00
// Page 2.2 layout: Character map
VBoxContainer * page2_2_vb = memnew ( VBoxContainer ) ;
page2_2_vb - > set_name ( TTR ( " Glyphs from the Character Map " ) ) ;
preload_pages - > add_child ( page2_2_vb ) ;
2020-12-27 15:30:33 +02:00
2022-05-09 12:47:10 +03:00
page2_2_description = memnew ( Label ) ;
2025-04-22 11:57:16 +03:00
page2_2_description - > set_focus_mode ( Control : : FOCUS_ACCESSIBILITY ) ;
2022-05-09 12:47:10 +03:00
page2_2_description - > set_text ( TTR ( " Add or remove glyphs from the character map to pre-render list: \n Note: 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. " ) ) ;
page2_2_description - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
page2_2_description - > set_autowrap_mode ( TextServer : : AUTOWRAP_WORD_SMART ) ;
2023-12-14 10:41:22 +08:00
page2_2_description - > set_custom_minimum_size ( Size2 ( 300 * EDSCALE , 1 ) ) ;
2022-05-09 12:47:10 +03:00
page2_2_vb - > add_child ( page2_2_description ) ;
2020-12-27 15:30:33 +02:00
HSplitContainer * glyphs_split = memnew ( HSplitContainer ) ;
glyphs_split - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
glyphs_split - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2022-05-09 12:47:10 +03:00
page2_2_vb - > add_child ( glyphs_split ) ;
2020-12-27 15:30:33 +02:00
glyph_table = memnew ( Tree ) ;
2024-03-17 16:28:18 +08:00
glyph_table - > set_auto_translate_mode ( AUTO_TRANSLATE_MODE_DISABLED ) ;
2020-12-27 15:30:33 +02:00
glyph_table - > set_custom_minimum_size ( Size2 ( ( 30 * 16 + 100 ) * EDSCALE , 0 ) ) ;
glyph_table - > set_columns ( 17 ) ;
glyph_table - > set_column_expand ( 0 , false ) ;
glyph_table - > set_hide_root ( true ) ;
glyph_table - > set_allow_reselect ( true ) ;
glyph_table - > set_select_mode ( Tree : : SELECT_SINGLE ) ;
glyph_table - > set_column_titles_visible ( true ) ;
for ( int i = 0 ; i < 16 ; i + + ) {
glyph_table - > set_column_title ( i + 1 , String : : num_int64 ( i , 16 ) ) ;
}
2024-05-14 15:50:53 +02:00
glyph_table - > add_theme_style_override ( " selected " , glyph_table - > get_theme_stylebox ( SceneStringName ( panel ) ) ) ;
glyph_table - > add_theme_style_override ( " selected_focus " , glyph_table - > get_theme_stylebox ( SceneStringName ( panel ) ) ) ;
2022-04-14 16:20:28 -05:00
glyph_table - > add_theme_constant_override ( " h_separation " , 0 ) ;
2020-12-27 15:30:33 +02:00
glyph_table - > set_h_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
glyph_table - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2023-10-19 18:05:19 +02:00
glyphs_split - > add_child ( glyph_table ) ;
2023-10-06 02:00:36 -05:00
glyph_table - > connect ( " item_activated " , callable_mp ( this , & DynamicFontImportSettingsDialog : : _glyph_selected ) ) ;
2020-12-27 15:30:33 +02:00
glyph_tree = memnew ( Tree ) ;
2024-03-17 16:28:18 +08:00
glyph_tree - > set_auto_translate_mode ( AUTO_TRANSLATE_MODE_DISABLED ) ;
2020-12-27 15:30:33 +02:00
glyph_tree - > set_custom_minimum_size ( Size2 ( 300 * EDSCALE , 0 ) ) ;
2021-09-22 16:55:39 +03:00
glyph_tree - > set_columns ( 2 ) ;
2020-12-27 15:30:33 +02:00
glyph_tree - > set_hide_root ( true ) ;
glyph_tree - > set_column_expand ( 0 , false ) ;
glyph_tree - > set_column_expand ( 1 , true ) ;
glyph_tree - > set_column_custom_minimum_width ( 0 , 120 * EDSCALE ) ;
glyph_tree - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
glyph_root = glyph_tree - > create_item ( ) ;
2021-12-09 03:42:46 -06:00
for ( int i = 0 ; ! unicode_ranges [ i ] . name . is_empty ( ) ; i + + ) {
2020-12-27 15:30:33 +02:00
_add_glyph_range_item ( unicode_ranges [ i ] . start , unicode_ranges [ i ] . end , unicode_ranges [ i ] . name ) ;
}
2023-10-19 18:05:19 +02:00
glyphs_split - > add_child ( glyph_tree ) ;
2023-10-06 02:00:36 -05:00
glyph_tree - > connect ( " item_activated " , callable_mp ( this , & DynamicFontImportSettingsDialog : : _range_edited ) ) ;
2024-05-14 14:21:31 +02:00
glyph_tree - > connect ( SceneStringName ( item_selected ) , callable_mp ( this , & DynamicFontImportSettingsDialog : : _range_selected ) ) ;
2020-12-27 15:30:33 +02:00
// Common
import_settings_data . instantiate ( ) ;
import_settings_data - > owner = this ;
2022-07-07 19:31:19 -05:00
set_ok_button_text ( TTR ( " Reimport " ) ) ;
set_cancel_button_text ( TTR ( " Close " ) ) ;
2020-12-27 15:30:33 +02:00
}