diff options
Diffstat (limited to 'scene/resources/dynamic_font.h')
-rw-r--r-- | scene/resources/dynamic_font.h | 99 |
1 files changed, 59 insertions, 40 deletions
diff --git a/scene/resources/dynamic_font.h b/scene/resources/dynamic_font.h index ba7249a7b7..1a46e1e468 100644 --- a/scene/resources/dynamic_font.h +++ b/scene/resources/dynamic_font.h @@ -1,10 +1,14 @@ -#ifndef DYNAMICFONT_H -#define DYNAMICFONT_H +#ifndef DYNAMIC_FONT_H +#define DYNAMIC_FONT_H -#include "font.h" -#include "stb_truetype.h" +#ifdef FREETYPE_ENABLED +#include "scene/resources/font.h" +#include "os/thread_safe.h" #include "io/resource_loader.h" +#include <ft2build.h> +#include FT_FREETYPE_H + class DynamicFontAtSize; class DynamicFont; @@ -13,39 +17,16 @@ class DynamicFontData : public Resource { OBJ_TYPE(DynamicFontData,Resource); - bool valid; - - DVector<uint8_t> font_data; - DVector<uint8_t>::Read fr; - const uint8_t* last_data_ptr; - struct KerningPairKey { - - union { - struct { - uint32_t A,B; - }; - - uint64_t pair; - }; - - _FORCE_INLINE_ bool operator<(const KerningPairKey& p_r) const { return pair<p_r.pair; } - }; - - Map<KerningPairKey,int> kerning_map; + const uint8_t *font_mem; + int font_mem_size; + bool force_autohinter; + String font_path; Map<int,DynamicFontAtSize*> size_cache; -friend class DynamicFontAtSize; - - stbtt_fontinfo info; - int ascent; - int descent; - int linegap; - - void lock(); - void unlock(); + friend class DynamicFontAtSize; friend class DynamicFont; @@ -53,7 +34,10 @@ friend class DynamicFont; Ref<DynamicFontAtSize> _get_dynamic_font_at_size(int p_size); public: - void set_font_data(const DVector<uint8_t>& p_font); + void set_font_ptr(const uint8_t* p_font_mem,int p_font_mem_size); + void set_font_path(const String& p_path); + void set_force_autohinter(bool p_force); + DynamicFontData(); ~DynamicFontData(); }; @@ -61,11 +45,21 @@ public: class DynamicFontAtSize : public Reference { - OBJ_TYPE(DynamicFontAtSize,Reference); + OBJ_TYPE(DynamicFontAtSize,Reference) + + _THREAD_SAFE_CLASS_ + FT_Library library; /* handle to library */ + FT_Face face; /* handle to face object */ + FT_StreamRec stream; + int ascent; + int descent; + int linegap; int rect_margin; + bool valid; + struct CharTexture { DVector<uint8_t> imgdata; @@ -78,6 +72,7 @@ class DynamicFontAtSize : public Reference { struct Character { + bool found; int texture_idx; Rect2 rect; float v_align; @@ -88,6 +83,8 @@ class DynamicFontAtSize : public Reference { }; + static unsigned long _ft_stream_io(FT_Stream stream, unsigned long offset, unsigned char* buffer, unsigned long count ); + static void _ft_stream_close(FT_Stream stream); HashMap< CharType, Character > char_map; @@ -95,21 +92,26 @@ class DynamicFontAtSize : public Reference { friend class DynamicFontData; Ref<DynamicFontData> font; - float scale; int size; + + + Error _load(); protected: + + public: + float get_height() const; float get_ascent() const; float get_descent() const; - Size2 get_char_size(CharType p_char,CharType p_next=0) const; + Size2 get_char_size(CharType p_char,CharType p_next,const Vector<Ref<DynamicFontAtSize> >& p_fallbacks) const; - float draw_char(RID p_canvas_item, const Point2& p_pos, const CharType& p_char,const CharType& p_next=0,const Color& p_modulate=Color(1,1,1)) const; + float draw_char(RID p_canvas_item, const Point2& p_pos, const CharType& p_char,const CharType& p_next,const Color& p_modulate,const Vector<Ref<DynamicFontAtSize> >& p_fallbacks) const; @@ -123,13 +125,22 @@ class DynamicFont : public Font { OBJ_TYPE( DynamicFont, Font ); - Ref<DynamicFontData> data; + Ref<DynamicFontData> data; Ref<DynamicFontAtSize> data_at_size; - int size; + Vector< Ref<DynamicFontData> > fallbacks; + Vector< Ref<DynamicFontAtSize> > fallback_data_at_size; + + + int size; + bool valid; protected: + 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<PropertyInfo> *p_list) const; + static void _bind_methods(); public: @@ -140,6 +151,13 @@ public: void set_size(int p_size); int get_size() const; + + void add_fallback(const Ref<DynamicFontData>& p_data); + void set_fallback(int p_idx,const Ref<DynamicFontData>& p_data); + int get_fallback_count() const; + Ref<DynamicFontData> get_fallback(int p_idx) const; + void remove_fallback(int p_idx); + virtual float get_height() const; virtual float get_ascent() const; @@ -171,5 +189,6 @@ public: }; +#endif -#endif // DYNAMICFONT_H +#endif |