summaryrefslogtreecommitdiff
path: root/scene/resources/dynamic_font.h
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/dynamic_font.h')
-rw-r--r--scene/resources/dynamic_font.h63
1 files changed, 32 insertions, 31 deletions
diff --git a/scene/resources/dynamic_font.h b/scene/resources/dynamic_font.h
index 2dafd3ce4f..a881e21da8 100644
--- a/scene/resources/dynamic_font.h
+++ b/scene/resources/dynamic_font.h
@@ -31,7 +31,9 @@
#ifndef DYNAMIC_FONT_H
#define DYNAMIC_FONT_H
-#ifdef FREETYPE_ENABLED
+#include "modules/modules_enabled.gen.h"
+#ifdef MODULE_FREETYPE_ENABLED
+
#include "core/io/resource_loader.h"
#include "core/os/mutex.h"
#include "core/os/thread_safe.h"
@@ -45,7 +47,6 @@ class DynamicFontAtSize;
class DynamicFont;
class DynamicFontData : public Resource {
-
GDCLASS(DynamicFontData, Resource);
public:
@@ -54,9 +55,7 @@ public:
struct {
uint32_t size : 16;
uint32_t outline_size : 8;
- uint32_t mipmaps : 1;
- uint32_t filter : 1;
- uint32_t unused : 6;
+ uint32_t unused : 8;
};
uint32_t key;
};
@@ -109,7 +108,6 @@ public:
VARIANT_ENUM_CAST(DynamicFontData::Hinting);
class DynamicFontAtSize : public Reference {
-
GDCLASS(DynamicFontAtSize, Reference);
_THREAD_SAFE_CLASS_
@@ -124,14 +122,13 @@ class DynamicFontAtSize : public Reference {
float rect_margin;
float oversampling;
float scale_color_font;
-
- uint32_t texture_flags;
+ float underline_position;
+ float underline_thickness;
bool valid;
struct CharTexture {
-
- PoolVector<uint8_t> imgdata;
+ Vector<uint8_t> imgdata;
int texture_size;
Vector<int> offsets;
Ref<ImageTexture> texture;
@@ -140,7 +137,6 @@ class DynamicFontAtSize : public Reference {
Vector<CharTexture> textures;
struct Character {
-
bool found;
int texture_idx;
Rect2 rect;
@@ -163,23 +159,23 @@ class DynamicFontAtSize : public Reference {
int y;
};
- const Pair<const Character *, DynamicFontAtSize *> _find_char_with_font(CharType p_char, const Vector<Ref<DynamicFontAtSize> > &p_fallbacks) const;
- Character _make_outline_char(CharType p_char);
+ const Pair<const Character *, DynamicFontAtSize *> _find_char_with_font(char32_t p_char, const Vector<Ref<DynamicFontAtSize>> &p_fallbacks) const;
+ Character _make_outline_char(char32_t p_char);
TexturePosition _find_texture_pos_for_glyph(int p_color_size, Image::Format p_image_format, int p_width, int p_height);
Character _bitmap_to_character(FT_Bitmap bitmap, int yofs, int xofs, float advance);
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;
+ HashMap<char32_t, Character> char_map;
- _FORCE_INLINE_ void _update_char(CharType p_char);
+ _FORCE_INLINE_ void _update_char(char32_t p_char);
friend class DynamicFontData;
Ref<DynamicFontData> font;
DynamicFontData::CacheID id;
- static HashMap<String, Vector<uint8_t> > _fontdata;
+ static HashMap<String, Vector<uint8_t>> _fontdata;
Error _load();
public:
@@ -189,10 +185,13 @@ public:
float get_ascent() const;
float get_descent() const;
+ float get_underline_position() const;
+ float get_underline_thickness() const;
- Size2 get_char_size(CharType p_char, CharType p_next, const Vector<Ref<DynamicFontAtSize> > &p_fallbacks) const;
+ Size2 get_char_size(char32_t p_char, char32_t p_next, const Vector<Ref<DynamicFontAtSize>> &p_fallbacks) const;
+ String get_available_chars() const;
- float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next, const Color &p_modulate, const Vector<Ref<DynamicFontAtSize> > &p_fallbacks, bool p_advance_only = false, bool p_outline = false) const;
+ float draw_char(RID p_canvas_item, const Point2 &p_pos, char32_t p_char, char32_t p_next, const Color &p_modulate, const Vector<Ref<DynamicFontAtSize>> &p_fallbacks, bool p_advance_only = false, bool p_outline = false) const;
void set_texture_flags(uint32_t p_flags);
void update_oversampling();
@@ -204,7 +203,6 @@ public:
///////////////
class DynamicFont : public Font {
-
GDCLASS(DynamicFont, Font);
public:
@@ -220,9 +218,9 @@ private:
Ref<DynamicFontAtSize> data_at_size;
Ref<DynamicFontAtSize> outline_data_at_size;
- Vector<Ref<DynamicFontData> > fallbacks;
- Vector<Ref<DynamicFontAtSize> > fallback_data_at_size;
- Vector<Ref<DynamicFontAtSize> > fallback_outline_data_at_size;
+ Vector<Ref<DynamicFontData>> fallbacks;
+ Vector<Ref<DynamicFontAtSize>> fallback_data_at_size;
+ Vector<Ref<DynamicFontAtSize>> fallback_outline_data_at_size;
DynamicFontData::CacheID cache_id;
DynamicFontData::CacheID outline_cache_id;
@@ -272,22 +270,25 @@ public:
Ref<DynamicFontData> get_fallback(int p_idx) const;
void remove_fallback(int p_idx);
- virtual float get_height() const;
+ virtual float get_height() const override;
- virtual float get_ascent() const;
- virtual float get_descent() const;
+ virtual float get_ascent() const override;
+ virtual float get_descent() const override;
+ virtual float get_underline_position() const override;
+ virtual float get_underline_thickness() const override;
- virtual Size2 get_char_size(CharType p_char, CharType p_next = 0) const;
+ virtual Size2 get_char_size(char32_t p_char, char32_t p_next = 0) const override;
+ String get_available_chars() const;
- virtual bool is_distance_field_hint() const;
+ virtual bool is_distance_field_hint() const override;
- virtual bool has_outline() const;
+ virtual bool has_outline() const override;
- virtual float draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_char, CharType p_next = 0, const Color &p_modulate = Color(1, 1, 1), bool p_outline = false) const;
+ virtual float draw_char(RID p_canvas_item, const Point2 &p_pos, char32_t p_char, char32_t p_next = 0, const Color &p_modulate = Color(1, 1, 1), bool p_outline = false) const override;
SelfList<DynamicFont> font_list;
- static Mutex *dynamic_font_mutex;
+ static Mutex dynamic_font_mutex;
static SelfList<DynamicFont>::List *dynamic_fonts;
static void initialize_dynamic_fonts();
@@ -304,7 +305,7 @@ VARIANT_ENUM_CAST(DynamicFont::SpacingType);
class ResourceFormatLoaderDynamicFont : public ResourceFormatLoader {
public:
- virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;