From 7b165e8ac27c8c6f979bf6e2da32a9a58836da08 Mon Sep 17 00:00:00 2001 From: Zher Huei Lee Date: Tue, 2 Aug 2016 08:01:51 +0100 Subject: Added texture mipmaps and filtering to DynamicFont --- scene/resources/dynamic_font.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'scene/resources/dynamic_font.h') diff --git a/scene/resources/dynamic_font.h b/scene/resources/dynamic_font.h index 9ad1b4edbf..c43dcd37f9 100644 --- a/scene/resources/dynamic_font.h +++ b/scene/resources/dynamic_font.h @@ -59,7 +59,7 @@ class DynamicFontData : public Resource { friend class DynamicFont; - Ref _get_dynamic_font_at_size(int p_size); + Ref _get_dynamic_font_at_size(int p_size, uint32_t p_texture_flags=0); protected: static void _bind_methods(); @@ -90,6 +90,8 @@ class DynamicFontAtSize : public Reference { int linegap; int rect_margin; + uint32_t texture_flags; + bool valid; struct CharTexture { @@ -145,7 +147,7 @@ public: float draw_char(RID p_canvas_item, const Point2& p_pos, CharType p_char,CharType p_next,const Color& p_modulate,const Vector >& p_fallbacks) const; - + void set_texture_flags(uint32_t p_flags); DynamicFontAtSize(); ~DynamicFontAtSize(); @@ -157,7 +159,7 @@ class DynamicFont : public Font { OBJ_TYPE( DynamicFont, Font ); - Ref data; + Ref data; Ref data_at_size; Vector< Ref > fallbacks; @@ -166,9 +168,14 @@ class DynamicFont : public Font { int size; bool valid; + bool use_mipmaps; + bool use_filter; + uint32_t texture_flags; protected: + void _update_texture_flags(); + bool _set(const StringName& p_name, const Variant& p_value); bool _get(const StringName& p_name,Variant &r_ret) const; void _get_property_list( List *p_list) const; @@ -183,6 +190,11 @@ public: void set_size(int p_size); int get_size() const; + bool get_use_mipmaps() const; + void set_use_mipmaps(bool p_enable); + + bool get_use_filter() const; + void set_use_filter(bool p_enable); void add_fallback(const Ref& p_data); void set_fallback(int p_idx,const Ref& p_data); -- cgit v1.2.3 From af6ef01c692311410c084b0bf4f3fe2f4d46786d Mon Sep 17 00:00:00 2001 From: Zher Huei Lee Date: Tue, 2 Aug 2016 11:05:20 +0100 Subject: Added extra spacing support for DynamicFont Side effect is that label min-size will now take into account kerning. --- scene/resources/dynamic_font.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'scene/resources/dynamic_font.h') diff --git a/scene/resources/dynamic_font.h b/scene/resources/dynamic_font.h index c43dcd37f9..899973f22f 100644 --- a/scene/resources/dynamic_font.h +++ b/scene/resources/dynamic_font.h @@ -159,6 +159,17 @@ class DynamicFont : public Font { OBJ_TYPE( DynamicFont, Font ); +public: + + enum SpacingType{ + SPACING_TOP, + SPACING_BOTTOM, + SPACING_CHAR, + SPACING_SPACE + }; + +private: + Ref data; Ref data_at_size; @@ -168,6 +179,10 @@ class DynamicFont : public Font { int size; bool valid; + int spacing_top; + int spacing_bottom; + int spacing_char; + int spacing_space; bool use_mipmaps; bool use_filter; uint32_t texture_flags; @@ -196,6 +211,9 @@ public: bool get_use_filter() const; void set_use_filter(bool p_enable); + int get_spacing(int p_type) const; + void set_spacing(int p_type, int p_value); + void add_fallback(const Ref& p_data); void set_fallback(int p_idx,const Ref& p_data); int get_fallback_count() const; -- cgit v1.2.3 From 0de7860511fe56f06d039c51ff463c7a1146b7e1 Mon Sep 17 00:00:00 2001 From: Zher Huei Lee Date: Tue, 2 Aug 2016 15:00:32 +0100 Subject: DynamicFont caches now accounts for texture flags CacheID added for future-proofing --- scene/resources/dynamic_font.h | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'scene/resources/dynamic_font.h') diff --git a/scene/resources/dynamic_font.h b/scene/resources/dynamic_font.h index 899973f22f..4ae58ab0dd 100644 --- a/scene/resources/dynamic_font.h +++ b/scene/resources/dynamic_font.h @@ -45,21 +45,32 @@ class DynamicFontData : public Resource { OBJ_TYPE(DynamicFontData,Resource); +public: + + struct CacheID{ + + int size; + bool mipmaps; + bool filter; + + bool operator< (CacheID right) const; + CacheID() { size=16; mipmaps=false; filter=false; } + }; +private: const uint8_t *font_mem; int font_mem_size; bool force_autohinter; String font_path; - Map size_cache; + Map size_cache; friend class DynamicFontAtSize; friend class DynamicFont; - - Ref _get_dynamic_font_at_size(int p_size, uint32_t p_texture_flags=0); + Ref _get_dynamic_font_at_size(CacheID p_cache); protected: static void _bind_methods(); @@ -126,7 +137,7 @@ class DynamicFontAtSize : public Reference { friend class DynamicFontData; Ref font; - int size; + DynamicFontData::CacheID id; @@ -177,19 +188,16 @@ private: Vector< Ref > fallback_data_at_size; - int size; + DynamicFontData::CacheID cache_id; bool valid; int spacing_top; int spacing_bottom; int spacing_char; int spacing_space; - bool use_mipmaps; - bool use_filter; - uint32_t texture_flags; protected: - void _update_texture_flags(); + void _reload_cache(); bool _set(const StringName& p_name, const Variant& p_value); bool _get(const StringName& p_name,Variant &r_ret) const; -- cgit v1.2.3