From 2615055987a3a5b353ca3a02aac5daa6c9e9bc02 Mon Sep 17 00:00:00 2001 From: Mounir Tohami <53877170+WhalesState@users.noreply.github.com> Date: Sat, 7 Dec 2024 19:50:34 +0200 Subject: [PATCH] Add TextServer set/get lcd subpixel layout. --- doc/classes/FontFile.xml | 3 + doc/classes/SystemFont.xml | 3 + doc/classes/TextServer.xml | 15 +++ doc/classes/TextServerExtension.xml | 15 +++ .../import/dynamic_font_import_settings.cpp | 16 ++++ modules/text_server_adv/text_server_adv.cpp | 91 +++++++++++-------- modules/text_server_adv/text_server_adv.h | 18 +++- modules/text_server_fb/text_server_fb.cpp | 86 ++++++++++-------- modules/text_server_fb/text_server_fb.h | 18 +++- scene/resources/font.cpp | 66 ++++++++++++-- scene/resources/font.h | 21 ++++- scene/theme/default_theme.cpp | 3 +- scene/theme/default_theme.h | 13 ++- scene/theme/theme_db.cpp | 17 +++- servers/text/text_server_extension.cpp | 24 +++++ servers/text/text_server_extension.h | 16 ++++ servers/text_server.cpp | 14 +++ servers/text_server.h | 14 +++ 18 files changed, 358 insertions(+), 95 deletions(-) diff --git a/doc/classes/FontFile.xml b/doc/classes/FontFile.xml index e7a724cecd46..9bb503649304 100644 --- a/doc/classes/FontFile.xml +++ b/doc/classes/FontFile.xml @@ -634,6 +634,9 @@ If set to [code]true[/code], when aligning glyphs to the pixel boundaries rounding remainders are accumulated to ensure more uniform glyph distribution. This setting has no effect if subpixel positioning is enabled. + + LCD subpixel layout used for font anti-aliasing. See [enum TextServer.FontLCDSubpixelLayout]. + The width of the range around the shape between the minimum and maximum representable signed distance. If using font outlines, [member msdf_pixel_range] must be set to at least [i]twice[/i] the size of the largest font outline. The default [member msdf_pixel_range] value of [code]16[/code] allows outline sizes up to [code]8[/code] to look correct. diff --git a/doc/classes/SystemFont.xml b/doc/classes/SystemFont.xml index b91ae74eae8c..988d268b5797 100644 --- a/doc/classes/SystemFont.xml +++ b/doc/classes/SystemFont.xml @@ -46,6 +46,9 @@ If set to [code]true[/code], when aligning glyphs to the pixel boundaries rounding remainders are accumulated to ensure more uniform glyph distribution. This setting has no effect if subpixel positioning is enabled. + + LCD subpixel layout used for font anti-aliasing. See [enum TextServer.FontLCDSubpixelLayout]. + The width of the range around the shape between the minimum and maximum representable signed distance. If using font outlines, [member msdf_pixel_range] must be set to at least [i]twice[/i] the size of the largest font outline. The default [member msdf_pixel_range] value of [code]16[/code] allows outline sizes up to [code]8[/code] to look correct. diff --git a/doc/classes/TextServer.xml b/doc/classes/TextServer.xml index 730b88eb5798..5a3d6060f2fc 100644 --- a/doc/classes/TextServer.xml +++ b/doc/classes/TextServer.xml @@ -356,6 +356,13 @@ Returns list of language support overrides. + + + + + Returns the LCD subpixel layout used for font anti-aliasing. See [enum TextServer.FontLCDSubpixelLayout]. + + @@ -858,6 +865,14 @@ Adds override for [method font_is_language_supported]. + + + + + + Sets the LCD subpixel layout used for font anti-aliasing. See [enum TextServer.FontLCDSubpixelLayout]. + + diff --git a/doc/classes/TextServerExtension.xml b/doc/classes/TextServerExtension.xml index 1df451705c3d..66acef2c0e0a 100644 --- a/doc/classes/TextServerExtension.xml +++ b/doc/classes/TextServerExtension.xml @@ -373,6 +373,13 @@ Returns list of language support overrides. + + + + + LCD subpixel layout used for font anti-aliasing. See [enum TextServer.FontLCDSubpixelLayout]. + + @@ -942,6 +949,14 @@ Adds override for [method _font_is_language_supported]. + + + + + + LCD subpixel layout used for font anti-aliasing. See [enum TextServer.FontLCDSubpixelLayout]. + + diff --git a/editor/import/dynamic_font_import_settings.cpp b/editor/import/dynamic_font_import_settings.cpp index 19dafb7c42c7..e856f69445ee 100644 --- a/editor/import/dynamic_font_import_settings.cpp +++ b/editor/import/dynamic_font_import_settings.cpp @@ -28,6 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ +/**************************************************************************/ +/* PIXEL ENGINE */ +/* Copyright (c) 2024-present Pixel Engine contributors (see AUTHORS.md). */ +/**************************************************************************/ +/* NOTICE: */ +/* This file contains modifications and additions specific to the Pixel */ +/* Engine project. While these changes are licensed under the MIT license */ +/* for compatibility, we request proper attribution if reused in any */ +/* derivative works, including meta-forks. */ +/**************************************************************************/ + #include "dynamic_font_import_settings.h" #include "core/config/project_settings.h" @@ -474,6 +485,8 @@ void DynamicFontImportSettingsDialog::_main_prop_changed(const String &p_edited_ if (font_preview.is_valid()) { if (p_edited_property == "antialiasing") { font_preview->set_antialiasing((TextServer::FontAntialiasing)import_settings_data->get("antialiasing").operator int()); + } else if (p_edited_property == "lcd_subpixel_layout") { + font_preview->set_lcd_subpixel_layout((TextServer::FontLCDSubpixelLayout)import_settings_data->get("lcd_subpixel_layout").operator int()); } else if (p_edited_property == "generate_mipmaps") { font_preview->set_generate_mipmaps(import_settings_data->get("generate_mipmaps")); } else if (p_edited_property == "disable_embedded_bitmaps") { @@ -953,6 +966,7 @@ void DynamicFontImportSettingsDialog::_re_import() { main_settings["face_index"] = import_settings_data->get("face_index"); main_settings["antialiasing"] = import_settings_data->get("antialiasing"); + main_settings["lcd_subpixel_layout"] = import_settings_data->get("lcd_subpixel_layout"); main_settings["generate_mipmaps"] = import_settings_data->get("generate_mipmaps"); main_settings["disable_embedded_bitmaps"] = import_settings_data->get("disable_embedded_bitmaps"); main_settings["multichannel_signed_distance_field"] = import_settings_data->get("multichannel_signed_distance_field"); @@ -1232,6 +1246,7 @@ void DynamicFontImportSettingsDialog::open_settings(const String &p_path) { if (font_preview.is_valid()) { font_preview->set_antialiasing((TextServer::FontAntialiasing)import_settings_data->get("antialiasing").operator int()); + font_preview->set_lcd_subpixel_layout((TextServer::FontLCDSubpixelLayout)import_settings_data->get("lcd_subpixel_layout").operator int()); 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")); @@ -1263,6 +1278,7 @@ DynamicFontImportSettingsDialog::DynamicFontImportSettingsDialog() { options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::NIL, "Rendering", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_GROUP), Variant())); options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "antialiasing", PROPERTY_HINT_ENUM, "None,Grayscale,LCD Subpixel"), 1)); + options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "lcd_subpixel_layout", PROPERTY_HINT_ENUM, "Disabled,Horizontal RGB,Horizontal BGR,Vertical RGB,Vertical BGR"), 1)); options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "generate_mipmaps"), false)); options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "disable_embedded_bitmaps"), true)); 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)); diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index ebe82c651753..06d90f797135 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -28,6 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ +/**************************************************************************/ +/* PIXEL ENGINE */ +/* Copyright (c) 2024-present Pixel Engine contributors (see AUTHORS.md). */ +/**************************************************************************/ +/* NOTICE: */ +/* This file contains modifications and additions specific to the Pixel */ +/* Engine project. While these changes are licensed under the MIT license */ +/* for compatibility, we request proper attribution if reused in any */ +/* derivative works, including meta-forks. */ +/**************************************************************************/ + #include "text_server_adv.h" #ifdef GDEXTENSION @@ -35,19 +46,15 @@ #include #include -#include #include #include #include using namespace godot; -#define GLOBAL_GET(m_var) ProjectSettings::get_singleton()->get_setting_with_override(m_var) - #elif defined(GODOT_MODULE) // Headers for building as built-in module. -#include "core/config/project_settings.h" #include "core/error/error_macros.h" #include "core/object/worker_thread_pool.h" #include "core/string/print_string.h" @@ -2279,6 +2286,27 @@ TextServer::FontAntialiasing TextServerAdvanced::_font_get_antialiasing(const RI return fd->antialiasing; } +void TextServerAdvanced::_font_set_lcd_subpixel_layout(const RID &p_font_rid, TextServer::FontLCDSubpixelLayout p_lcd_subpixel_layout) { + FontAdvanced *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); + + MutexLock lock(fd->mutex); + if (fd->lcd_subpixel_layout != p_lcd_subpixel_layout) { + if (fd->antialiasing == TextServer::FONT_ANTIALIASING_LCD) { + _font_clear_cache(fd); + } + fd->lcd_subpixel_layout = p_lcd_subpixel_layout; + } +} + +TextServer::FontLCDSubpixelLayout TextServerAdvanced::_font_get_lcd_subpixel_layout(const RID &p_font_rid) const { + FontAdvanced *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, TextServer::FontLCDSubpixelLayout::FONT_LCD_SUBPIXEL_LAYOUT_NONE); + + MutexLock lock(fd->mutex); + return fd->lcd_subpixel_layout; +} + void TextServerAdvanced::_font_set_disable_embedded_bitmaps(const RID &p_font_rid, bool p_disable_embedded_bitmaps) { FontAdvanced *fd = _get_font_data(p_font_rid); ERR_FAIL_NULL(fd); @@ -3046,9 +3074,8 @@ Vector2 TextServerAdvanced::_font_get_glyph_advance(const RID &p_font_rid, int64 int mod = 0; if (fd->antialiasing == FONT_ANTIALIASING_LCD) { - TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get(); - if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { - mod = (layout << 24); + if (fd->lcd_subpixel_layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { + mod = (fd->lcd_subpixel_layout << 24); } } @@ -3106,9 +3133,8 @@ Vector2 TextServerAdvanced::_font_get_glyph_offset(const RID &p_font_rid, const int mod = 0; if (fd->antialiasing == FONT_ANTIALIASING_LCD) { - TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get(); - if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { - mod = (layout << 24); + if (fd->lcd_subpixel_layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { + mod = (fd->lcd_subpixel_layout << 24); } } @@ -3158,9 +3184,8 @@ Vector2 TextServerAdvanced::_font_get_glyph_size(const RID &p_font_rid, const Ve int mod = 0; if (fd->antialiasing == FONT_ANTIALIASING_LCD) { - TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get(); - if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { - mod = (layout << 24); + if (fd->lcd_subpixel_layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { + mod = (fd->lcd_subpixel_layout << 24); } } @@ -3210,9 +3235,8 @@ Rect2 TextServerAdvanced::_font_get_glyph_uv_rect(const RID &p_font_rid, const V int mod = 0; if (fd->antialiasing == FONT_ANTIALIASING_LCD) { - TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get(); - if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { - mod = (layout << 24); + if (fd->lcd_subpixel_layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { + mod = (fd->lcd_subpixel_layout << 24); } } @@ -3252,9 +3276,8 @@ int64_t TextServerAdvanced::_font_get_glyph_texture_idx(const RID &p_font_rid, c int mod = 0; if (fd->antialiasing == FONT_ANTIALIASING_LCD) { - TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get(); - if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { - mod = (layout << 24); + if (fd->lcd_subpixel_layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { + mod = (fd->lcd_subpixel_layout << 24); } } @@ -3294,9 +3317,8 @@ RID TextServerAdvanced::_font_get_glyph_texture_rid(const RID &p_font_rid, const int mod = 0; if (fd->antialiasing == FONT_ANTIALIASING_LCD) { - TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get(); - if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { - mod = (layout << 24); + if (fd->lcd_subpixel_layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { + mod = (fd->lcd_subpixel_layout << 24); } } @@ -3342,9 +3364,8 @@ Size2 TextServerAdvanced::_font_get_glyph_texture_size(const RID &p_font_rid, co int mod = 0; if (fd->antialiasing == FONT_ANTIALIASING_LCD) { - TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get(); - if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { - mod = (layout << 24); + if (fd->lcd_subpixel_layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { + mod = (fd->lcd_subpixel_layout << 24); } } @@ -3770,10 +3791,9 @@ void TextServerAdvanced::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca if (!fd->msdf && ffsd->face) { // LCD layout, bits 24, 25, 26 if (fd->antialiasing == FONT_ANTIALIASING_LCD) { - TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get(); - if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { + if (fd->lcd_subpixel_layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { lcd_aa = true; - index = index | (layout << 24); + index = index | (fd->lcd_subpixel_layout << 24); } } // Subpixel X-shift, bits 27, 28 @@ -3879,10 +3899,9 @@ void TextServerAdvanced::_font_draw_glyph_outline(const RID &p_font_rid, const R if (!fd->msdf && ffsd->face) { // LCD layout, bits 24, 25, 26 if (fd->antialiasing == FONT_ANTIALIASING_LCD) { - TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get(); - if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { + if (fd->lcd_subpixel_layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { lcd_aa = true; - index = index | (layout << 24); + index = index | (fd->lcd_subpixel_layout << 24); } } // Subpixel X-shift, bits 27, 28 @@ -6207,9 +6226,8 @@ void TextServerAdvanced::_shape_run(ShapedTextDataAdvanced *p_sd, int64_t p_star int mod = 0; if (fd->antialiasing == FONT_ANTIALIASING_LCD) { - TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get(); - if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { - mod = (layout << 24); + if (fd->lcd_subpixel_layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { + mod = (fd->lcd_subpixel_layout << 24); } } @@ -7571,15 +7589,10 @@ bool TextServerAdvanced::_is_valid_letter(uint64_t p_unicode) const { return u_isalpha(p_unicode); } -void TextServerAdvanced::_update_settings() { - lcd_subpixel_layout.set((TextServer::FontLCDSubpixelLayout)(int)GLOBAL_GET("gui/theme/lcd_subpixel_layout")); -} - TextServerAdvanced::TextServerAdvanced() { _insert_num_systems_lang(); _insert_feature_sets(); _bmp_create_font_funcs(); - ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &TextServerAdvanced::_update_settings)); } void TextServerAdvanced::_cleanup() { diff --git a/modules/text_server_adv/text_server_adv.h b/modules/text_server_adv/text_server_adv.h index 96db44ab0691..f118a29c7ce7 100644 --- a/modules/text_server_adv/text_server_adv.h +++ b/modules/text_server_adv/text_server_adv.h @@ -28,6 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ +/**************************************************************************/ +/* PIXEL ENGINE */ +/* Copyright (c) 2024-present Pixel Engine contributors (see AUTHORS.md). */ +/**************************************************************************/ +/* NOTICE: */ +/* This file contains modifications and additions specific to the Pixel */ +/* Engine project. While these changes are licensed under the MIT license */ +/* for compatibility, we request proper attribution if reused in any */ +/* derivative works, including meta-forks. */ +/**************************************************************************/ + #ifndef TEXT_SERVER_ADV_H #define TEXT_SERVER_ADV_H @@ -162,9 +173,6 @@ class TextServerAdvanced : public TextServerExtension { HashMap feature_sets; HashMap feature_sets_inv; - SafeNumeric lcd_subpixel_layout{ TextServer::FontLCDSubpixelLayout::FONT_LCD_SUBPIXEL_LAYOUT_NONE }; - void _update_settings(); - void _insert_num_systems_lang(); void _insert_feature_sets(); _FORCE_INLINE_ void _insert_feature(const StringName &p_name, int32_t p_tag, Variant::Type p_vtype = Variant::INT, bool p_hidden = false); @@ -317,6 +325,7 @@ class TextServerAdvanced : public TextServerExtension { Mutex mutex; TextServer::FontAntialiasing antialiasing = TextServer::FONT_ANTIALIASING_GRAY; + TextServer::FontLCDSubpixelLayout lcd_subpixel_layout = TextServer::FontLCDSubpixelLayout::FONT_LCD_SUBPIXEL_LAYOUT_NONE; bool disable_embedded_bitmaps = true; bool mipmaps = false; bool msdf = false; @@ -774,6 +783,9 @@ class TextServerAdvanced : public TextServerExtension { MODBIND2(font_set_antialiasing, const RID &, TextServer::FontAntialiasing); MODBIND1RC(TextServer::FontAntialiasing, font_get_antialiasing, const RID &); + MODBIND2(font_set_lcd_subpixel_layout, const RID &, TextServer::FontLCDSubpixelLayout); + MODBIND1RC(TextServer::FontLCDSubpixelLayout, font_get_lcd_subpixel_layout, const RID &); + MODBIND2(font_set_disable_embedded_bitmaps, const RID &, bool); MODBIND1RC(bool, font_get_disable_embedded_bitmaps, const RID &); diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp index f3bfce60e88f..cd38784bd82e 100644 --- a/modules/text_server_fb/text_server_fb.cpp +++ b/modules/text_server_fb/text_server_fb.cpp @@ -28,6 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ +/**************************************************************************/ +/* PIXEL ENGINE */ +/* Copyright (c) 2024-present Pixel Engine contributors (see AUTHORS.md). */ +/**************************************************************************/ +/* NOTICE: */ +/* This file contains modifications and additions specific to the Pixel */ +/* Engine project. While these changes are licensed under the MIT license */ +/* for compatibility, we request proper attribution if reused in any */ +/* derivative works, including meta-forks. */ +/**************************************************************************/ + #include "text_server_fb.h" #ifdef GDEXTENSION @@ -35,7 +46,6 @@ #include #include -#include #include #include #include @@ -44,12 +54,9 @@ using namespace godot; -#define GLOBAL_GET(m_var) ProjectSettings::get_singleton()->get_setting_with_override(m_var) - #elif defined(GODOT_MODULE) // Headers for building as built-in module. -#include "core/config/project_settings.h" #include "core/error/error_macros.h" #include "core/string/print_string.h" #include "core/string/translation_server.h" @@ -1270,6 +1277,27 @@ TextServer::FontAntialiasing TextServerFallback::_font_get_antialiasing(const RI return fd->antialiasing; } +void TextServerFallback::_font_set_lcd_subpixel_layout(const RID &p_font_rid, TextServer::FontLCDSubpixelLayout p_lcd_subpixel_layout) { + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL(fd); + + MutexLock lock(fd->mutex); + if (fd->lcd_subpixel_layout != p_lcd_subpixel_layout) { + if (fd->antialiasing == TextServer::FONT_ANTIALIASING_LCD) { + _font_clear_cache(fd); + } + fd->lcd_subpixel_layout = p_lcd_subpixel_layout; + } +} + +TextServer::FontLCDSubpixelLayout TextServerFallback::_font_get_lcd_subpixel_layout(const RID &p_font_rid) const { + FontFallback *fd = _get_font_data(p_font_rid); + ERR_FAIL_NULL_V(fd, TextServer::FontLCDSubpixelLayout::FONT_LCD_SUBPIXEL_LAYOUT_NONE); + + MutexLock lock(fd->mutex); + return fd->lcd_subpixel_layout; +} + void TextServerFallback::_font_set_disable_embedded_bitmaps(const RID &p_font_rid, bool p_disable_embedded_bitmaps) { FontFallback *fd = _get_font_data(p_font_rid); ERR_FAIL_NULL(fd); @@ -2023,9 +2051,8 @@ Vector2 TextServerFallback::_font_get_glyph_advance(const RID &p_font_rid, int64 int mod = 0; if (fd->antialiasing == FONT_ANTIALIASING_LCD) { - TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get(); - if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { - mod = (layout << 24); + if (fd->lcd_subpixel_layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { + mod = (fd->lcd_subpixel_layout << 24); } } @@ -2083,9 +2110,8 @@ Vector2 TextServerFallback::_font_get_glyph_offset(const RID &p_font_rid, const int mod = 0; if (fd->antialiasing == FONT_ANTIALIASING_LCD) { - TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get(); - if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { - mod = (layout << 24); + if (fd->lcd_subpixel_layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { + mod = (fd->lcd_subpixel_layout << 24); } } @@ -2135,9 +2161,8 @@ Vector2 TextServerFallback::_font_get_glyph_size(const RID &p_font_rid, const Ve int mod = 0; if (fd->antialiasing == FONT_ANTIALIASING_LCD) { - TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get(); - if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { - mod = (layout << 24); + if (fd->lcd_subpixel_layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { + mod = (fd->lcd_subpixel_layout << 24); } } @@ -2187,9 +2212,8 @@ Rect2 TextServerFallback::_font_get_glyph_uv_rect(const RID &p_font_rid, const V int mod = 0; if (fd->antialiasing == FONT_ANTIALIASING_LCD) { - TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get(); - if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { - mod = (layout << 24); + if (fd->lcd_subpixel_layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { + mod = (fd->lcd_subpixel_layout << 24); } } @@ -2229,9 +2253,8 @@ int64_t TextServerFallback::_font_get_glyph_texture_idx(const RID &p_font_rid, c int mod = 0; if (fd->antialiasing == FONT_ANTIALIASING_LCD) { - TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get(); - if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { - mod = (layout << 24); + if (fd->lcd_subpixel_layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { + mod = (fd->lcd_subpixel_layout << 24); } } @@ -2271,9 +2294,8 @@ RID TextServerFallback::_font_get_glyph_texture_rid(const RID &p_font_rid, const int mod = 0; if (fd->antialiasing == FONT_ANTIALIASING_LCD) { - TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get(); - if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { - mod = (layout << 24); + if (fd->lcd_subpixel_layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { + mod = (fd->lcd_subpixel_layout << 24); } } @@ -2319,9 +2341,8 @@ Size2 TextServerFallback::_font_get_glyph_texture_size(const RID &p_font_rid, co int mod = 0; if (fd->antialiasing == FONT_ANTIALIASING_LCD) { - TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get(); - if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { - mod = (layout << 24); + if (fd->lcd_subpixel_layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { + mod = (fd->lcd_subpixel_layout << 24); } } @@ -2700,10 +2721,9 @@ void TextServerFallback::_font_draw_glyph(const RID &p_font_rid, const RID &p_ca if (!fd->msdf && ffsd->face) { // LCD layout, bits 24, 25, 26 if (fd->antialiasing == FONT_ANTIALIASING_LCD) { - TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get(); - if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { + if (fd->lcd_subpixel_layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { lcd_aa = true; - index = index | (layout << 24); + index = index | (fd->lcd_subpixel_layout << 24); } } // Subpixel X-shift, bits 27, 28 @@ -2809,10 +2829,9 @@ void TextServerFallback::_font_draw_glyph_outline(const RID &p_font_rid, const R if (!fd->msdf && ffsd->face) { // LCD layout, bits 24, 25, 26 if (fd->antialiasing == FONT_ANTIALIASING_LCD) { - TextServer::FontLCDSubpixelLayout layout = lcd_subpixel_layout.get(); - if (layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { + if (fd->lcd_subpixel_layout != FONT_LCD_SUBPIXEL_LAYOUT_NONE) { lcd_aa = true; - index = index | (layout << 24); + index = index | (fd->lcd_subpixel_layout << 24); } } // Subpixel X-shift, bits 27, 28 @@ -4744,13 +4763,8 @@ PackedInt32Array TextServerFallback::_string_get_word_breaks(const String &p_str return ret; } -void TextServerFallback::_update_settings() { - lcd_subpixel_layout.set((TextServer::FontLCDSubpixelLayout)(int)GLOBAL_GET("gui/theme/lcd_subpixel_layout")); -} - TextServerFallback::TextServerFallback() { _insert_feature_sets(); - ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &TextServerFallback::_update_settings)); } void TextServerFallback::_cleanup() { diff --git a/modules/text_server_fb/text_server_fb.h b/modules/text_server_fb/text_server_fb.h index f784a5592887..7060340aba7b 100644 --- a/modules/text_server_fb/text_server_fb.h +++ b/modules/text_server_fb/text_server_fb.h @@ -28,6 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ +/**************************************************************************/ +/* PIXEL ENGINE */ +/* Copyright (c) 2024-present Pixel Engine contributors (see AUTHORS.md). */ +/**************************************************************************/ +/* NOTICE: */ +/* This file contains modifications and additions specific to the Pixel */ +/* Engine project. While these changes are licensed under the MIT license */ +/* for compatibility, we request proper attribution if reused in any */ +/* derivative works, including meta-forks. */ +/**************************************************************************/ + #ifndef TEXT_SERVER_FB_H #define TEXT_SERVER_FB_H @@ -118,9 +129,6 @@ class TextServerFallback : public TextServerExtension { HashMap feature_sets; HashMap feature_sets_inv; - SafeNumeric lcd_subpixel_layout{ TextServer::FontLCDSubpixelLayout::FONT_LCD_SUBPIXEL_LAYOUT_NONE }; - void _update_settings(); - void _insert_feature_sets(); _FORCE_INLINE_ void _insert_feature(const StringName &p_name, int32_t p_tag); @@ -259,6 +267,7 @@ class TextServerFallback : public TextServerExtension { Mutex mutex; TextServer::FontAntialiasing antialiasing = TextServer::FONT_ANTIALIASING_GRAY; + TextServer::FontLCDSubpixelLayout lcd_subpixel_layout = TextServer::FontLCDSubpixelLayout::FONT_LCD_SUBPIXEL_LAYOUT_NONE; bool disable_embedded_bitmaps = true; bool mipmaps = false; bool msdf = false; @@ -633,6 +642,9 @@ class TextServerFallback : public TextServerExtension { MODBIND2(font_set_antialiasing, const RID &, TextServer::FontAntialiasing); MODBIND1RC(TextServer::FontAntialiasing, font_get_antialiasing, const RID &); + MODBIND2(font_set_lcd_subpixel_layout, const RID &, TextServer::FontLCDSubpixelLayout); + MODBIND1RC(TextServer::FontLCDSubpixelLayout, font_get_lcd_subpixel_layout, const RID &); + MODBIND2(font_set_disable_embedded_bitmaps, const RID &, bool); MODBIND1RC(bool, font_get_disable_embedded_bitmaps, const RID &); diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 147a342853ac..29757d46df22 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -28,6 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ +/**************************************************************************/ +/* PIXEL ENGINE */ +/* Copyright (c) 2024-present Pixel Engine contributors (see AUTHORS.md). */ +/**************************************************************************/ +/* NOTICE: */ +/* This file contains modifications and additions specific to the Pixel */ +/* Engine project. While these changes are licensed under the MIT license */ +/* for compatibility, we request proper attribution if reused in any */ +/* derivative works, including meta-forks. */ +/**************************************************************************/ + #include "font.h" #include "font.compat.inc" @@ -595,6 +606,7 @@ _FORCE_INLINE_ void FontFile::_ensure_rid(int p_cache_index, int p_make_linked_f cache.write[p_cache_index] = TS->create_font(); TS->font_set_data_ptr(cache[p_cache_index], data_ptr, data_size); TS->font_set_antialiasing(cache[p_cache_index], antialiasing); + TS->font_set_lcd_subpixel_layout(cache[p_cache_index], lcd_subpixel_layout); TS->font_set_generate_mipmaps(cache[p_cache_index], mipmaps); TS->font_set_disable_embedded_bitmaps(cache[p_cache_index], disable_embedded_bitmaps); TS->font_set_multichannel_signed_distance_field(cache[p_cache_index], msdf); @@ -903,6 +915,9 @@ void FontFile::_bind_methods() { ClassDB::bind_method(D_METHOD("set_antialiasing", "antialiasing"), &FontFile::set_antialiasing); ClassDB::bind_method(D_METHOD("get_antialiasing"), &FontFile::get_antialiasing); + ClassDB::bind_method(D_METHOD("set_lcd_subpixel_layout", "subpixel_layout"), &FontFile::set_lcd_subpixel_layout); + ClassDB::bind_method(D_METHOD("get_lcd_subpixel_layout"), &FontFile::get_lcd_subpixel_layout); + ClassDB::bind_method(D_METHOD("set_disable_embedded_bitmaps", "disable_embedded_bitmaps"), &FontFile::set_disable_embedded_bitmaps); ClassDB::bind_method(D_METHOD("get_disable_embedded_bitmaps"), &FontFile::get_disable_embedded_bitmaps); @@ -1042,6 +1057,7 @@ void FontFile::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "generate_mipmaps", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_generate_mipmaps", "get_generate_mipmaps"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disable_embedded_bitmaps", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_disable_embedded_bitmaps", "get_disable_embedded_bitmaps"); ADD_PROPERTY(PropertyInfo(Variant::INT, "antialiasing", PROPERTY_HINT_ENUM, "None,Grayscale,LCD Subpixel", PROPERTY_USAGE_STORAGE), "set_antialiasing", "get_antialiasing"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "lcd_subpixel_layout", PROPERTY_HINT_ENUM, "Disabled,Horizontal RGB,Horizontal BGR,Vertical RGB,Vertical BGR", PROPERTY_USAGE_STORAGE), "set_lcd_subpixel_layout", "get_lcd_subpixel_layout"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "font_name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_font_name", "get_font_name"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "style_name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_font_style_name", "get_font_style_name"); ADD_PROPERTY(PropertyInfo(Variant::INT, "font_style", PROPERTY_HINT_FLAGS, "Bold,Italic,Fixed Size", PROPERTY_USAGE_STORAGE), "set_font_style", "get_font_style"); @@ -1410,6 +1426,7 @@ void FontFile::reset_state() { cache.clear(); antialiasing = TextServer::FONT_ANTIALIASING_GRAY; + lcd_subpixel_layout = TextServer::FONT_LCD_SUBPIXEL_LAYOUT_NONE; mipmaps = false; disable_embedded_bitmaps = true; msdf = false; @@ -2137,6 +2154,21 @@ TextServer::FontAntialiasing FontFile::get_antialiasing() const { return antialiasing; } +void FontFile::set_lcd_subpixel_layout(TextServer::FontLCDSubpixelLayout p_subpixel_layout) { + if (lcd_subpixel_layout != p_subpixel_layout) { + lcd_subpixel_layout = p_subpixel_layout; + for (int i = 0; i < cache.size(); i++) { + _ensure_rid(i); + TS->font_set_lcd_subpixel_layout(cache[i], lcd_subpixel_layout); + } + emit_changed(); + } +} + +TextServer::FontLCDSubpixelLayout FontFile::get_lcd_subpixel_layout() const { + return lcd_subpixel_layout; +} + void FontFile::set_disable_embedded_bitmaps(bool p_disable_embedded_bitmaps) { if (disable_embedded_bitmaps != p_disable_embedded_bitmaps) { disable_embedded_bitmaps = p_disable_embedded_bitmaps; @@ -2287,9 +2319,9 @@ TextServer::Hinting FontFile::get_hinting() const { return hinting; } -void FontFile::set_subpixel_positioning(TextServer::SubpixelPositioning p_subpixel) { - if (subpixel_positioning != p_subpixel) { - subpixel_positioning = p_subpixel; +void FontFile::set_subpixel_positioning(TextServer::SubpixelPositioning p_subpixel_positioning) { + if (subpixel_positioning != p_subpixel_positioning) { + subpixel_positioning = p_subpixel_positioning; for (int i = 0; i < cache.size(); i++) { _ensure_rid(i); TS->font_set_subpixel_positioning(cache[i], subpixel_positioning); @@ -3089,6 +3121,9 @@ void SystemFont::_bind_methods() { ClassDB::bind_method(D_METHOD("set_antialiasing", "antialiasing"), &SystemFont::set_antialiasing); ClassDB::bind_method(D_METHOD("get_antialiasing"), &SystemFont::get_antialiasing); + ClassDB::bind_method(D_METHOD("set_lcd_subpixel_layout", "subpixel_layout"), &SystemFont::set_lcd_subpixel_layout); + ClassDB::bind_method(D_METHOD("get_lcd_subpixel_layout"), &SystemFont::get_lcd_subpixel_layout); + ClassDB::bind_method(D_METHOD("set_disable_embedded_bitmaps", "disable_embedded_bitmaps"), &SystemFont::set_disable_embedded_bitmaps); ClassDB::bind_method(D_METHOD("get_disable_embedded_bitmaps"), &SystemFont::get_disable_embedded_bitmaps); @@ -3134,7 +3169,8 @@ void SystemFont::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "font_italic"), "set_font_italic", "get_font_italic"); ADD_PROPERTY(PropertyInfo(Variant::INT, "font_weight", PROPERTY_HINT_RANGE, "100,999,25"), "set_font_weight", "get_font_weight"); ADD_PROPERTY(PropertyInfo(Variant::INT, "font_stretch", PROPERTY_HINT_RANGE, "50,200,25"), "set_font_stretch", "get_font_stretch"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "antialiasing", PROPERTY_HINT_ENUM, "None,Grayscale,LCD Subpixel", PROPERTY_USAGE_STORAGE), "set_antialiasing", "get_antialiasing"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "antialiasing", PROPERTY_HINT_ENUM, "None,Grayscale,LCD Subpixel"), "set_antialiasing", "get_antialiasing"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "lcd_subpixel_layout", PROPERTY_HINT_ENUM, "Disabled,Horizontal RGB,Horizontal BGR,Vertical RGB,Vertical BGR"), "set_lcd_subpixel_layout", "get_lcd_subpixel_layout"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "generate_mipmaps"), "set_generate_mipmaps", "get_generate_mipmaps"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disable_embedded_bitmaps"), "set_disable_embedded_bitmaps", "get_disable_embedded_bitmaps"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_system_fallback"), "set_allow_system_fallback", "is_allow_system_fallback"); @@ -3241,6 +3277,7 @@ void SystemFont::_update_base_font() { // Apply font rendering settings. file->set_antialiasing(antialiasing); + file->set_lcd_subpixel_layout(lcd_subpixel_layout); file->set_generate_mipmaps(mipmaps); file->set_disable_embedded_bitmaps(disable_embedded_bitmaps); file->set_force_autohinter(force_autohinter); @@ -3285,6 +3322,7 @@ void SystemFont::reset_state() { weight = 400; stretch = 100; antialiasing = TextServer::FONT_ANTIALIASING_GRAY; + lcd_subpixel_layout = TextServer::FONT_LCD_SUBPIXEL_LAYOUT_NONE; mipmaps = false; disable_embedded_bitmaps = true; force_autohinter = false; @@ -3361,6 +3399,20 @@ TextServer::FontAntialiasing SystemFont::get_antialiasing() const { return antialiasing; } +void SystemFont::set_lcd_subpixel_layout(TextServer::FontLCDSubpixelLayout p_subpixel_layout) { + if (lcd_subpixel_layout != p_subpixel_layout) { + lcd_subpixel_layout = p_subpixel_layout; + if (base_font.is_valid()) { + base_font->set_lcd_subpixel_layout(lcd_subpixel_layout); + } + emit_changed(); + } +} + +TextServer::FontLCDSubpixelLayout SystemFont::get_lcd_subpixel_layout() const { + return lcd_subpixel_layout; +} + void SystemFont::set_disable_embedded_bitmaps(bool p_disable_embedded_bitmaps) { if (disable_embedded_bitmaps != p_disable_embedded_bitmaps) { disable_embedded_bitmaps = p_disable_embedded_bitmaps; @@ -3431,9 +3483,9 @@ TextServer::Hinting SystemFont::get_hinting() const { return hinting; } -void SystemFont::set_subpixel_positioning(TextServer::SubpixelPositioning p_subpixel) { - if (subpixel_positioning != p_subpixel) { - subpixel_positioning = p_subpixel; +void SystemFont::set_subpixel_positioning(TextServer::SubpixelPositioning p_subpixel_positioning) { + if (subpixel_positioning != p_subpixel_positioning) { + subpixel_positioning = p_subpixel_positioning; if (base_font.is_valid()) { base_font->set_subpixel_positioning(subpixel_positioning); } diff --git a/scene/resources/font.h b/scene/resources/font.h index 1a5c79fef3cc..07597a8099cd 100644 --- a/scene/resources/font.h +++ b/scene/resources/font.h @@ -28,6 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ +/**************************************************************************/ +/* PIXEL ENGINE */ +/* Copyright (c) 2024-present Pixel Engine contributors (see AUTHORS.md). */ +/**************************************************************************/ +/* NOTICE: */ +/* This file contains modifications and additions specific to the Pixel */ +/* Engine project. While these changes are licensed under the MIT license */ +/* for compatibility, we request proper attribution if reused in any */ +/* derivative works, including meta-forks. */ +/**************************************************************************/ + #ifndef FONT_H #define FONT_H @@ -186,6 +197,7 @@ class FontFile : public Font { mutable PackedByteArray data; TextServer::FontAntialiasing antialiasing = TextServer::FONT_ANTIALIASING_GRAY; + TextServer::FontLCDSubpixelLayout lcd_subpixel_layout = TextServer::FONT_LCD_SUBPIXEL_LAYOUT_HRGB; bool mipmaps = false; bool disable_embedded_bitmaps = true; bool msdf = false; @@ -248,6 +260,9 @@ class FontFile : public Font { virtual void set_antialiasing(TextServer::FontAntialiasing p_antialiasing); virtual TextServer::FontAntialiasing get_antialiasing() const; + virtual void set_lcd_subpixel_layout(TextServer::FontLCDSubpixelLayout p_subpixel_layout); + virtual TextServer::FontLCDSubpixelLayout get_lcd_subpixel_layout() const; + virtual void set_disable_embedded_bitmaps(bool p_disable_embedded_bitmaps); virtual bool get_disable_embedded_bitmaps() const; @@ -478,6 +493,7 @@ class SystemFont : public Font { int ftr_italic = 0; TextServer::FontAntialiasing antialiasing = TextServer::FONT_ANTIALIASING_GRAY; + TextServer::FontLCDSubpixelLayout lcd_subpixel_layout = TextServer::FONT_LCD_SUBPIXEL_LAYOUT_HRGB; bool mipmaps = false; bool disable_embedded_bitmaps = true; bool force_autohinter = false; @@ -505,6 +521,9 @@ class SystemFont : public Font { virtual void set_antialiasing(TextServer::FontAntialiasing p_antialiasing); virtual TextServer::FontAntialiasing get_antialiasing() const; + virtual void set_lcd_subpixel_layout(TextServer::FontLCDSubpixelLayout p_subpixel_layout); + virtual TextServer::FontLCDSubpixelLayout get_lcd_subpixel_layout() const; + virtual void set_disable_embedded_bitmaps(bool p_disable_embedded_bitmaps); virtual bool get_disable_embedded_bitmaps() const; @@ -520,7 +539,7 @@ class SystemFont : public Font { virtual void set_hinting(TextServer::Hinting p_hinting); virtual TextServer::Hinting get_hinting() const; - virtual void set_subpixel_positioning(TextServer::SubpixelPositioning p_subpixel); + virtual void set_subpixel_positioning(TextServer::SubpixelPositioning p_subpixel_positioning); virtual TextServer::SubpixelPositioning get_subpixel_positioning() const; virtual void set_keep_rounding_remainders(bool p_keep_rounding_remainders); diff --git a/scene/theme/default_theme.cpp b/scene/theme/default_theme.cpp index 2f058478fce4..5510563002ba 100644 --- a/scene/theme/default_theme.cpp +++ b/scene/theme/default_theme.cpp @@ -1300,7 +1300,7 @@ void fill_default_theme(Ref &theme, const Ref &default_font, const default_style = make_flat_stylebox(Color(1, 0.365, 0.365), 4, 4, 4, 4, 0, false, 2); } -void make_default_theme(float p_scale, Ref p_font, TextServer::SubpixelPositioning p_font_subpixel, TextServer::Hinting p_font_hinting, TextServer::FontAntialiasing p_font_antialiasing, bool p_font_msdf, bool p_font_generate_mipmaps) { +void make_default_theme(float p_scale, Ref p_font, TextServer::SubpixelPositioning p_font_subpixel, TextServer::Hinting p_font_hinting, TextServer::FontAntialiasing p_font_antialiasing, TextServer::FontLCDSubpixelLayout p_lcd_subpixel_layout, bool p_font_msdf, bool p_font_generate_mipmaps) { Ref t; t.instantiate(); @@ -1325,6 +1325,7 @@ void make_default_theme(float p_scale, Ref p_font, TextServer::SubpixelPos dynamic_font->set_subpixel_positioning(p_font_subpixel); dynamic_font->set_hinting(p_font_hinting); dynamic_font->set_antialiasing(p_font_antialiasing); + dynamic_font->set_lcd_subpixel_layout(p_lcd_subpixel_layout); dynamic_font->set_multichannel_signed_distance_field(p_font_msdf); dynamic_font->set_generate_mipmaps(p_font_generate_mipmaps); diff --git a/scene/theme/default_theme.h b/scene/theme/default_theme.h index 55fc32a3d3f1..825c1d8e5ce3 100644 --- a/scene/theme/default_theme.h +++ b/scene/theme/default_theme.h @@ -28,12 +28,23 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ +/**************************************************************************/ +/* PIXEL ENGINE */ +/* Copyright (c) 2024-present Pixel Engine contributors (see AUTHORS.md). */ +/**************************************************************************/ +/* NOTICE: */ +/* This file contains modifications and additions specific to the Pixel */ +/* Engine project. While these changes are licensed under the MIT license */ +/* for compatibility, we request proper attribution if reused in any */ +/* derivative works, including meta-forks. */ +/**************************************************************************/ + #ifndef DEFAULT_THEME_H #define DEFAULT_THEME_H #include "scene/resources/theme.h" void fill_default_theme(Ref &theme, const Ref &default_font, const Ref &bold_font, const Ref &bold_italics_font, const Ref &italics_font, Ref &default_icon, Ref &default_style, float p_scale); -void make_default_theme(float p_scale, Ref p_font, TextServer::SubpixelPositioning p_font_subpixel = TextServer::SUBPIXEL_POSITIONING_AUTO, TextServer::Hinting p_font_hinting = TextServer::HINTING_LIGHT, TextServer::FontAntialiasing p_font_antialiased = TextServer::FONT_ANTIALIASING_GRAY, bool p_font_msdf = false, bool p_font_generate_mipmaps = false); +void make_default_theme(float p_scale, Ref p_font, TextServer::SubpixelPositioning p_font_subpixel = TextServer::SUBPIXEL_POSITIONING_AUTO, TextServer::Hinting p_font_hinting = TextServer::HINTING_LIGHT, TextServer::FontAntialiasing p_font_antialiased = TextServer::FONT_ANTIALIASING_GRAY, TextServer::FontLCDSubpixelLayout p_lcd_subpixel_layout = TextServer::FONT_LCD_SUBPIXEL_LAYOUT_HRGB, bool p_font_msdf = false, bool p_font_generate_mipmaps = false); #endif // DEFAULT_THEME_H diff --git a/scene/theme/theme_db.cpp b/scene/theme/theme_db.cpp index c33c31558f92..2817da39ac0b 100644 --- a/scene/theme/theme_db.cpp +++ b/scene/theme/theme_db.cpp @@ -28,6 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ +/**************************************************************************/ +/* PIXEL ENGINE */ +/* Copyright (c) 2024-present Pixel Engine contributors (see AUTHORS.md). */ +/**************************************************************************/ +/* NOTICE: */ +/* This file contains modifications and additions specific to the Pixel */ +/* Engine project. While these changes are licensed under the MIT license */ +/* for compatibility, we request proper attribution if reused in any */ +/* derivative works, including meta-forks. */ +/**************************************************************************/ + #include "theme_db.h" #include "core/config/project_settings.h" @@ -53,15 +64,13 @@ void ThemeDB::initialize_theme() { String project_font_path = GLOBAL_DEF_RST_BASIC(PropertyInfo(Variant::STRING, "gui/theme/custom_font", PROPERTY_HINT_FILE, "*.tres,*.res,*.otf,*.ttf,*.woff,*.woff2,*.fnt,*.font,*.pfb,*.pfm", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED), ""); TextServer::FontAntialiasing font_antialiasing = (TextServer::FontAntialiasing)(int)GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "gui/theme/default_font_antialiasing", PROPERTY_HINT_ENUM, "None,Grayscale,LCD Subpixel", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED), 1); + TextServer::FontLCDSubpixelLayout lcd_subpixel_layout = (TextServer::FontLCDSubpixelLayout)(int)GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "gui/theme/lcd_subpixel_layout", PROPERTY_HINT_ENUM, "Disabled,Horizontal RGB,Horizontal BGR,Vertical RGB,Vertical BGR"), 1); TextServer::Hinting font_hinting = (TextServer::Hinting)(int)GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "gui/theme/default_font_hinting", PROPERTY_HINT_ENUM, "None,Light,Normal", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED), TextServer::HINTING_LIGHT); TextServer::SubpixelPositioning font_subpixel_positioning = (TextServer::SubpixelPositioning)(int)GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "gui/theme/default_font_subpixel_positioning", PROPERTY_HINT_ENUM, "Disabled,Auto,One Half of a Pixel,One Quarter of a Pixel", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED), TextServer::SUBPIXEL_POSITIONING_AUTO); const bool font_msdf = GLOBAL_DEF_RST("gui/theme/default_font_multichannel_signed_distance_field", false); const bool font_generate_mipmaps = GLOBAL_DEF_RST("gui/theme/default_font_generate_mipmaps", false); - GLOBAL_DEF_RST(PropertyInfo(Variant::INT, "gui/theme/lcd_subpixel_layout", PROPERTY_HINT_ENUM, "Disabled,Horizontal RGB,Horizontal BGR,Vertical RGB,Vertical BGR"), 1); - ProjectSettings::get_singleton()->set_restart_if_changed("gui/theme/lcd_subpixel_layout", false); - // Attempt to load custom project theme and font. if (!project_theme_path.is_empty()) { @@ -86,7 +95,7 @@ void ThemeDB::initialize_theme() { // Always generate the default theme to serve as a fallback for all required theme definitions. if (RenderingServer::get_singleton()) { - make_default_theme(default_theme_scale, project_font, font_subpixel_positioning, font_hinting, font_antialiasing, font_msdf, font_generate_mipmaps); + make_default_theme(default_theme_scale, project_font, font_subpixel_positioning, font_hinting, font_antialiasing, lcd_subpixel_layout, font_msdf, font_generate_mipmaps); } _init_default_theme_context(); diff --git a/servers/text/text_server_extension.cpp b/servers/text/text_server_extension.cpp index 40d13d24cf32..18ab767f87de 100644 --- a/servers/text/text_server_extension.cpp +++ b/servers/text/text_server_extension.cpp @@ -28,6 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ +/**************************************************************************/ +/* PIXEL ENGINE */ +/* Copyright (c) 2024-present Pixel Engine contributors (see AUTHORS.md). */ +/**************************************************************************/ +/* NOTICE: */ +/* This file contains modifications and additions specific to the Pixel */ +/* Engine project. While these changes are licensed under the MIT license */ +/* for compatibility, we request proper attribution if reused in any */ +/* derivative works, including meta-forks. */ +/**************************************************************************/ + #include "text_server_extension.h" void TextServerExtension::_bind_methods() { @@ -81,6 +92,9 @@ void TextServerExtension::_bind_methods() { GDVIRTUAL_BIND(_font_set_antialiasing, "font_rid", "antialiasing"); GDVIRTUAL_BIND(_font_get_antialiasing, "font_rid"); + GDVIRTUAL_BIND(_font_set_lcd_subpixel_layout, "font_rid", "subpixel_layout") + GDVIRTUAL_BIND(_font_get_lcd_subpixel_layout, "font_rid") + GDVIRTUAL_BIND(_font_set_disable_embedded_bitmaps, "font_rid", "disable_embedded_bitmaps"); GDVIRTUAL_BIND(_font_get_disable_embedded_bitmaps, "font_rid"); @@ -540,6 +554,16 @@ TextServer::FontAntialiasing TextServerExtension::font_get_antialiasing(const RI return ret; } +void TextServerExtension::font_set_lcd_subpixel_layout(const RID &p_font_rid, TextServer::FontLCDSubpixelLayout p_lcd_subpixel_layout) { + GDVIRTUAL_CALL(_font_set_lcd_subpixel_layout, p_font_rid, p_lcd_subpixel_layout); +} + +TextServer::FontLCDSubpixelLayout TextServerExtension::font_get_lcd_subpixel_layout(const RID &p_font_rid) const { + TextServer::FontLCDSubpixelLayout ret = TextServer::FontLCDSubpixelLayout::FONT_LCD_SUBPIXEL_LAYOUT_NONE; + GDVIRTUAL_CALL(_font_get_lcd_subpixel_layout, p_font_rid, ret); + return ret; +} + void TextServerExtension::font_set_disable_embedded_bitmaps(const RID &p_font_rid, bool p_disable_embedded_bitmaps) { GDVIRTUAL_CALL(_font_set_disable_embedded_bitmaps, p_font_rid, p_disable_embedded_bitmaps); } diff --git a/servers/text/text_server_extension.h b/servers/text/text_server_extension.h index ea0487832cbe..93c346fcfa17 100644 --- a/servers/text/text_server_extension.h +++ b/servers/text/text_server_extension.h @@ -28,6 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ +/**************************************************************************/ +/* PIXEL ENGINE */ +/* Copyright (c) 2024-present Pixel Engine contributors (see AUTHORS.md). */ +/**************************************************************************/ +/* NOTICE: */ +/* This file contains modifications and additions specific to the Pixel */ +/* Engine project. While these changes are licensed under the MIT license */ +/* for compatibility, we request proper attribution if reused in any */ +/* derivative works, including meta-forks. */ +/**************************************************************************/ + #ifndef TEXT_SERVER_EXTENSION_H #define TEXT_SERVER_EXTENSION_H @@ -130,6 +141,11 @@ class TextServerExtension : public TextServer { GDVIRTUAL2(_font_set_antialiasing, RID, TextServer::FontAntialiasing); GDVIRTUAL1RC(TextServer::FontAntialiasing, _font_get_antialiasing, RID); + virtual void font_set_lcd_subpixel_layout(const RID &p_font_rid, TextServer::FontLCDSubpixelLayout p_lcd_subpixel_layout) override; + virtual TextServer::FontLCDSubpixelLayout font_get_lcd_subpixel_layout(const RID &p_font_rid) const override; + GDVIRTUAL2(_font_set_lcd_subpixel_layout, RID, TextServer::FontLCDSubpixelLayout); + GDVIRTUAL1RC(TextServer::FontLCDSubpixelLayout, _font_get_lcd_subpixel_layout, RID); + virtual void font_set_disable_embedded_bitmaps(const RID &p_font_rid, bool p_disable_embedded_bitmaps) override; virtual bool font_get_disable_embedded_bitmaps(const RID &p_font_rid) const override; GDVIRTUAL2(_font_set_disable_embedded_bitmaps, RID, bool); diff --git a/servers/text_server.cpp b/servers/text_server.cpp index c758e25d36c7..037fed9082e1 100644 --- a/servers/text_server.cpp +++ b/servers/text_server.cpp @@ -28,6 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ +/**************************************************************************/ +/* PIXEL ENGINE */ +/* Copyright (c) 2024-present Pixel Engine contributors (see AUTHORS.md). */ +/**************************************************************************/ +/* NOTICE: */ +/* This file contains modifications and additions specific to the Pixel */ +/* Engine project. While these changes are licensed under the MIT license */ +/* for compatibility, we request proper attribution if reused in any */ +/* derivative works, including meta-forks. */ +/**************************************************************************/ + #include "servers/text_server.h" #include "text_server.compat.inc" @@ -237,6 +248,9 @@ void TextServer::_bind_methods() { ClassDB::bind_method(D_METHOD("font_set_antialiasing", "font_rid", "antialiasing"), &TextServer::font_set_antialiasing); ClassDB::bind_method(D_METHOD("font_get_antialiasing", "font_rid"), &TextServer::font_get_antialiasing); + ClassDB::bind_method(D_METHOD("font_set_lcd_subpixel_layout", "font_rid", "lcd_subpixel_layout"), &TextServer::font_set_lcd_subpixel_layout); + ClassDB::bind_method(D_METHOD("font_get_lcd_subpixel_layout", "font_rid"), &TextServer::font_get_lcd_subpixel_layout); + ClassDB::bind_method(D_METHOD("font_set_disable_embedded_bitmaps", "font_rid", "disable_embedded_bitmaps"), &TextServer::font_set_disable_embedded_bitmaps); ClassDB::bind_method(D_METHOD("font_get_disable_embedded_bitmaps", "font_rid"), &TextServer::font_get_disable_embedded_bitmaps); diff --git a/servers/text_server.h b/servers/text_server.h index 53c36e47055e..61b4b3760dd3 100644 --- a/servers/text_server.h +++ b/servers/text_server.h @@ -28,6 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ +/**************************************************************************/ +/* PIXEL ENGINE */ +/* Copyright (c) 2024-present Pixel Engine contributors (see AUTHORS.md). */ +/**************************************************************************/ +/* NOTICE: */ +/* This file contains modifications and additions specific to the Pixel */ +/* Engine project. While these changes are licensed under the MIT license */ +/* for compatibility, we request proper attribution if reused in any */ +/* derivative works, including meta-forks. */ +/**************************************************************************/ + #ifndef TEXT_SERVER_H #define TEXT_SERVER_H @@ -283,6 +294,9 @@ class TextServer : public RefCounted { virtual void font_set_antialiasing(const RID &p_font_rid, FontAntialiasing p_antialiasing) = 0; virtual FontAntialiasing font_get_antialiasing(const RID &p_font_rid) const = 0; + virtual void font_set_lcd_subpixel_layout(const RID &p_font_rid, FontLCDSubpixelLayout p_lcd_subpixel_layout) = 0; + virtual FontLCDSubpixelLayout font_get_lcd_subpixel_layout(const RID &p_font_rid) const = 0; + virtual void font_set_disable_embedded_bitmaps(const RID &p_font_rid, bool p_disable_embedded_bitmaps) = 0; virtual bool font_get_disable_embedded_bitmaps(const RID &p_font_rid) const = 0;