diff options
Diffstat (limited to 'scene/resources/dynamic_font.cpp')
-rw-r--r-- | scene/resources/dynamic_font.cpp | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index 442151de36..5d2d690084 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -46,7 +46,6 @@ bool DynamicFontData::CacheID::operator<(CacheID right) const { } Ref<DynamicFontAtSize> DynamicFontData::_get_dynamic_font_at_size(CacheID p_cache_id) { - if (size_cache.has(p_cache_id)) { return Ref<DynamicFontAtSize>(size_cache[p_cache_id]); } @@ -65,13 +64,11 @@ Ref<DynamicFontAtSize> DynamicFontData::_get_dynamic_font_at_size(CacheID p_cach } void DynamicFontData::set_font_ptr(const uint8_t *p_font_mem, int p_font_mem_size) { - font_mem = p_font_mem; font_mem_size = p_font_mem_size; } void DynamicFontData::set_font_path(const String &p_path) { - font_path = p_path; } @@ -80,7 +77,6 @@ String DynamicFontData::get_font_path() const { } void DynamicFontData::set_force_autohinter(bool p_force) { - force_autohinter = p_force; } @@ -103,7 +99,6 @@ void DynamicFontData::_bind_methods() { } DynamicFontData::DynamicFontData() { - antialiased = true; force_autohinter = false; hinting = DynamicFontData::HINTING_NORMAL; @@ -118,7 +113,6 @@ DynamicFontData::~DynamicFontData() { HashMap<String, Vector<uint8_t>> DynamicFontAtSize::_fontdata; Error DynamicFontAtSize::_load() { - int error = FT_Init_FreeType(&library); ERR_FAIL_COND_V_MSG(error != 0, ERR_CANT_CREATE, "Error initializing FreeType."); @@ -127,11 +121,9 @@ Error DynamicFontAtSize::_load() { if (OS::get_singleton()->get_name() == "Android" && font->font_mem == nullptr && font->font_path != String()) { // cache font only once for each font->font_path if (_fontdata.has(font->font_path)) { - font->set_font_ptr(_fontdata[font->font_path].ptr(), _fontdata[font->font_path].size()); } else { - FileAccess *f = FileAccess::open(font->font_path, FileAccess::READ); if (!f) { FT_Done_FreeType(library); @@ -149,7 +141,6 @@ Error DynamicFontAtSize::_load() { } if (font->font_mem == nullptr && font->font_path != String()) { - FileAccess *f = FileAccess::open(font->font_path, FileAccess::READ); if (!f) { FT_Done_FreeType(library); @@ -170,7 +161,6 @@ Error DynamicFontAtSize::_load() { fargs.stream = &stream; error = FT_Open_Face(library, &fargs, 0, &face); } else if (font->font_mem) { - memset(&stream, 0, sizeof(FT_StreamRec)); stream.base = (unsigned char *)font->font_mem; stream.size = font->font_mem_size; @@ -192,12 +182,10 @@ Error DynamicFontAtSize::_load() { //error = FT_New_Face( library, src_path.utf8().get_data(),0,&face ); if (error == FT_Err_Unknown_File_Format) { - FT_Done_FreeType(library); ERR_FAIL_V_MSG(ERR_FILE_CANT_OPEN, "Unknown font format."); } else if (error) { - FT_Done_FreeType(library); ERR_FAIL_V_MSG(ERR_FILE_CANT_OPEN, "Error loading font."); } @@ -232,26 +220,21 @@ Error DynamicFontAtSize::_load() { float DynamicFontAtSize::font_oversampling = 1.0; float DynamicFontAtSize::get_height() const { - return ascent + descent; } float DynamicFontAtSize::get_ascent() const { - return ascent; } float DynamicFontAtSize::get_descent() const { - return descent; } float DynamicFontAtSize::get_underline_position() const { - return underline_position; } float DynamicFontAtSize::get_underline_thickness() const { - return underline_thickness; } @@ -260,10 +243,8 @@ const Pair<const DynamicFontAtSize::Character *, DynamicFontAtSize *> DynamicFon ERR_FAIL_COND_V(!chr, (Pair<const Character *, DynamicFontAtSize *>(nullptr, nullptr))); if (!chr->found) { - //not found, try in fallbacks for (int i = 0; i < p_fallbacks.size(); i++) { - DynamicFontAtSize *fb = const_cast<DynamicFontAtSize *>(p_fallbacks[i].ptr()); if (!fb->valid) continue; @@ -288,7 +269,6 @@ const Pair<const DynamicFontAtSize::Character *, DynamicFontAtSize *> DynamicFon } Size2 DynamicFontAtSize::get_char_size(CharType p_char, CharType p_next, const Vector<Ref<DynamicFontAtSize>> &p_fallbacks) const { - if (!valid) return Size2(1, 1); const_cast<DynamicFontAtSize *>(this)->_update_char(p_char); @@ -307,7 +287,6 @@ Size2 DynamicFontAtSize::get_char_size(CharType p_char, CharType p_next, const V } float DynamicFontAtSize::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, bool p_outline) const { - if (!valid) return 0; @@ -358,7 +337,6 @@ float DynamicFontAtSize::draw_char(RID p_canvas_item, const Point2 &p_pos, CharT } unsigned long DynamicFontAtSize::_ft_stream_io(FT_Stream stream, unsigned long offset, unsigned char *buffer, unsigned long count) { - FileAccess *f = (FileAccess *)stream->descriptor.pointer; if (f->get_position() != offset) { @@ -371,7 +349,6 @@ unsigned long DynamicFontAtSize::_ft_stream_io(FT_Stream stream, unsigned long o return f->get_buffer(buffer, count); } void DynamicFontAtSize::_ft_stream_close(FT_Stream stream) { - FileAccess *f = (FileAccess *)stream->descriptor.pointer; f->close(); memdelete(f); @@ -397,7 +374,6 @@ DynamicFontAtSize::TexturePosition DynamicFontAtSize::_find_texture_pos_for_glyp int mh = p_height; for (int i = 0; i < textures.size(); i++) { - const CharTexture &ct = textures[i]; if (ct.texture->get_format() != p_image_format) @@ -410,11 +386,9 @@ DynamicFontAtSize::TexturePosition DynamicFontAtSize::_find_texture_pos_for_glyp ret.x = 0; for (int j = 0; j < ct.texture_size - mw; j++) { - int max_y = 0; for (int k = j; k < j + mw; k++) { - int y = ct.offsets[k]; if (y > max_y) max_y = y; @@ -496,7 +470,6 @@ DynamicFontAtSize::Character DynamicFontAtSize::_bitmap_to_character(FT_Bitmap b for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { - int ofs = ((i + tex_pos.y + rect_margin) * tex.texture_size + j + tex_pos.x + rect_margin) * color_size; ERR_FAIL_COND_V(ofs >= tex.imgdata.size(), Character::not_found()); switch (bitmap.pixel_mode) { @@ -528,7 +501,6 @@ DynamicFontAtSize::Character DynamicFontAtSize::_bitmap_to_character(FT_Bitmap b //blit to image and texture { - Ref<Image> img = memnew(Image(tex.texture_size, tex.texture_size, 0, require_format, tex.imgdata)); if (tex.texture.is_null()) { @@ -591,7 +563,6 @@ cleanup_stroker: } void DynamicFontAtSize::_update_char(CharType p_char) { - if (char_map.has(p_char)) return; @@ -650,7 +621,6 @@ void DynamicFontAtSize::update_oversampling() { } DynamicFontAtSize::DynamicFontAtSize() { - valid = false; rect_margin = 1; ascent = 1; @@ -661,7 +631,6 @@ DynamicFontAtSize::DynamicFontAtSize() { } DynamicFontAtSize::~DynamicFontAtSize() { - if (valid) { FT_Done_FreeType(library); } @@ -672,7 +641,6 @@ DynamicFontAtSize::~DynamicFontAtSize() { ///////////////////////// void DynamicFont::_reload_cache() { - ERR_FAIL_COND(cache_id.size < 1); if (!data.is_valid()) { data_at_size.unref(); @@ -703,7 +671,6 @@ void DynamicFont::_reload_cache() { } void DynamicFont::set_font_data(const Ref<DynamicFontData> &p_data) { - data = p_data; _reload_cache(); @@ -712,12 +679,10 @@ void DynamicFont::set_font_data(const Ref<DynamicFontData> &p_data) { } Ref<DynamicFontData> DynamicFont::get_font_data() const { - return data; } void DynamicFont::set_size(int p_size) { - if (cache_id.size == p_size) return; cache_id.size = p_size; @@ -726,7 +691,6 @@ void DynamicFont::set_size(int p_size) { } int DynamicFont::get_size() const { - return cache_id.size; } @@ -755,31 +719,26 @@ Color DynamicFont::get_outline_color() const { } bool DynamicFontData::is_antialiased() const { - return antialiased; } void DynamicFontData::set_antialiased(bool p_antialiased) { - if (antialiased == p_antialiased) return; antialiased = p_antialiased; } DynamicFontData::Hinting DynamicFontData::get_hinting() const { - return hinting; } void DynamicFontData::set_hinting(Hinting p_hinting) { - if (hinting == p_hinting) return; hinting = p_hinting; } int DynamicFont::get_spacing(int p_type) const { - if (p_type == SPACING_TOP) { return spacing_top; } else if (p_type == SPACING_BOTTOM) { @@ -794,7 +753,6 @@ int DynamicFont::get_spacing(int p_type) const { } void DynamicFont::set_spacing(int p_type, int p_value) { - if (p_type == SPACING_TOP) { spacing_top = p_value; } else if (p_type == SPACING_BOTTOM) { @@ -810,7 +768,6 @@ void DynamicFont::set_spacing(int p_type, int p_value) { } float DynamicFont::get_height() const { - if (!data_at_size.is_valid()) return 1; @@ -818,7 +775,6 @@ float DynamicFont::get_height() const { } float DynamicFont::get_ascent() const { - if (!data_at_size.is_valid()) return 1; @@ -826,7 +782,6 @@ float DynamicFont::get_ascent() const { } float DynamicFont::get_descent() const { - if (!data_at_size.is_valid()) return 1; @@ -834,7 +789,6 @@ float DynamicFont::get_descent() const { } float DynamicFont::get_underline_position() const { - if (!data_at_size.is_valid()) return 2; @@ -842,7 +796,6 @@ float DynamicFont::get_underline_position() const { } float DynamicFont::get_underline_thickness() const { - if (!data_at_size.is_valid()) return 1; @@ -850,7 +803,6 @@ float DynamicFont::get_underline_thickness() const { } Size2 DynamicFont::get_char_size(CharType p_char, CharType p_next) const { - if (!data_at_size.is_valid()) return Size2(1, 1); @@ -864,7 +816,6 @@ Size2 DynamicFont::get_char_size(CharType p_char, CharType p_next) const { } bool DynamicFont::is_distance_field_hint() const { - return false; } @@ -887,7 +838,6 @@ float DynamicFont::draw_char(RID p_canvas_item, const Point2 &p_pos, CharType p_ } void DynamicFont::set_fallback(int p_idx, const Ref<DynamicFontData> &p_data) { - ERR_FAIL_COND(p_data.is_null()); ERR_FAIL_INDEX(p_idx, fallbacks.size()); fallbacks.write[p_idx] = p_data; @@ -895,7 +845,6 @@ void DynamicFont::set_fallback(int p_idx, const Ref<DynamicFontData> &p_data) { } void DynamicFont::add_fallback(const Ref<DynamicFontData> &p_data) { - ERR_FAIL_COND(p_data.is_null()); fallbacks.push_back(p_data); fallback_data_at_size.push_back(fallbacks.write[fallbacks.size() - 1]->_get_dynamic_font_at_size(cache_id)); //const.. @@ -911,13 +860,11 @@ int DynamicFont::get_fallback_count() const { return fallbacks.size(); } Ref<DynamicFontData> DynamicFont::get_fallback(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, fallbacks.size(), Ref<DynamicFontData>()); return fallbacks[p_idx]; } void DynamicFont::remove_fallback(int p_idx) { - ERR_FAIL_INDEX(p_idx, fallbacks.size()); fallbacks.remove(p_idx); fallback_data_at_size.remove(p_idx); @@ -926,7 +873,6 @@ void DynamicFont::remove_fallback(int p_idx) { } bool DynamicFont::_set(const StringName &p_name, const Variant &p_value) { - String str = p_name; if (str.begins_with("fallback/")) { int idx = str.get_slicec('/', 1).to_int(); @@ -952,7 +898,6 @@ bool DynamicFont::_set(const StringName &p_name, const Variant &p_value) { } bool DynamicFont::_get(const StringName &p_name, Variant &r_ret) const { - String str = p_name; if (str.begins_with("fallback/")) { int idx = str.get_slicec('/', 1).to_int(); @@ -969,7 +914,6 @@ bool DynamicFont::_get(const StringName &p_name, Variant &r_ret) const { return false; } void DynamicFont::_get_property_list(List<PropertyInfo> *p_list) const { - for (int i = 0; i < fallbacks.size(); i++) { p_list->push_back(PropertyInfo(Variant::OBJECT, "fallback/" + itos(i), PROPERTY_HINT_RESOURCE_TYPE, "DynamicFontData")); } @@ -978,7 +922,6 @@ void DynamicFont::_get_property_list(List<PropertyInfo> *p_list) const { } void DynamicFont::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_font_data", "data"), &DynamicFont::set_font_data); ClassDB::bind_method(D_METHOD("get_font_data"), &DynamicFont::get_font_data); @@ -1024,7 +967,6 @@ SelfList<DynamicFont>::List *DynamicFont::dynamic_fonts = nullptr; DynamicFont::DynamicFont() : font_list(this) { - valid = false; cache_id.size = 16; outline_cache_id.size = 16; @@ -1053,14 +995,12 @@ void DynamicFont::finish_dynamic_fonts() { } void DynamicFont::update_oversampling() { - Vector<Ref<DynamicFont>> changed; { MutexLock lock(dynamic_font_mutex); SelfList<DynamicFont> *E = dynamic_fonts->first(); while (E) { - if (E->self()->data_at_size.is_valid()) { E->self()->data_at_size->update_oversampling(); @@ -1093,7 +1033,6 @@ void DynamicFont::update_oversampling() { ///////////////////////// RES ResourceFormatLoaderDynamicFont::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - if (r_error) *r_error = ERR_FILE_CANT_OPEN; @@ -1108,18 +1047,15 @@ RES ResourceFormatLoaderDynamicFont::load(const String &p_path, const String &p_ } void ResourceFormatLoaderDynamicFont::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("ttf"); p_extensions->push_back("otf"); } bool ResourceFormatLoaderDynamicFont::handles_type(const String &p_type) const { - return (p_type == "DynamicFontData"); } String ResourceFormatLoaderDynamicFont::get_resource_type(const String &p_path) const { - String el = p_path.get_extension().to_lower(); if (el == "ttf" || el == "otf") return "DynamicFontData"; |