diff options
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/default_theme/default_theme.cpp | 18 | ||||
-rw-r--r-- | scene/resources/font.cpp | 239 | ||||
-rw-r--r-- | scene/resources/font.h | 74 |
3 files changed, 187 insertions, 144 deletions
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 005a46c0bc..727c8eee29 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -87,10 +87,10 @@ static Ref<Shader> make_shader(const char*vertex_code,const char*fragment_code,c return shader; } -static Ref<Font> make_font(int p_height,int p_ascent, int p_valign, int p_charcount, const int *p_chars,const Ref<Texture> &p_texture) { +static Ref<BitmapFont> make_font(int p_height,int p_ascent, int p_valign, int p_charcount, const int *p_chars,const Ref<Texture> &p_texture) { - Ref<Font> font( memnew( Font ) ); + Ref<BitmapFont> font( memnew( BitmapFont ) ); font->add_texture( p_texture ); for (int i=0;i<p_charcount;i++) { @@ -117,10 +117,10 @@ static Ref<Font> make_font(int p_height,int p_ascent, int p_valign, int p_charco return font; } -static Ref<Font> make_font2(int p_height,int p_ascent, int p_charcount, const int *p_char_rects,int p_kerning_count,const int *p_kernings,int p_w, int p_h, const unsigned char *p_img) { +static Ref<BitmapFont> make_font2(int p_height,int p_ascent, int p_charcount, const int *p_char_rects,int p_kerning_count,const int *p_kernings,int p_w, int p_h, const unsigned char *p_img) { - Ref<Font> font( memnew( Font ) ); + Ref<BitmapFont> font( memnew( BitmapFont ) ); DVector<uint8_t> img; img.resize(p_w*p_h*2); @@ -187,10 +187,10 @@ void make_default_theme() { Ref<Theme> t( memnew( Theme ) ); - //Ref<Font> default_font = make_font(_bi_font_normal_height,_bi_font_normal_ascent,_bi_font_normal_valign,_bi_font_normal_charcount,_bi_font_normal_characters,make_icon(font_normal_png)); - Ref<Font> default_font=make_font2(_builtin_normal_font_height,_builtin_normal_font_ascent,_builtin_normal_font_charcount,&_builtin_normal_font_charrects[0][0],_builtin_normal_font_kerning_pair_count,&_builtin_normal_font_kerning_pairs[0][0],_builtin_normal_font_img_width,_builtin_normal_font_img_height,_builtin_normal_font_img_data); - Ref<Font> source_font=make_font2(_builtin_source_font_height,_builtin_source_font_ascent,_builtin_source_font_charcount,&_builtin_source_font_charrects[0][0],_builtin_source_font_kerning_pair_count,&_builtin_source_font_kerning_pairs[0][0],_builtin_source_font_img_width,_builtin_source_font_img_height,_builtin_source_font_img_data); - Ref<Font> large_font=make_font2(_builtin_large_font_height,_builtin_large_font_ascent,_builtin_large_font_charcount,&_builtin_large_font_charrects[0][0],_builtin_large_font_kerning_pair_count,&_builtin_large_font_kerning_pairs[0][0],_builtin_large_font_img_width,_builtin_large_font_img_height,_builtin_large_font_img_data); + //Ref<BitmapFont> default_font = make_font(_bi_font_normal_height,_bi_font_normal_ascent,_bi_font_normal_valign,_bi_font_normal_charcount,_bi_font_normal_characters,make_icon(font_normal_png)); + Ref<BitmapFont> default_font=make_font2(_builtin_normal_font_height,_builtin_normal_font_ascent,_builtin_normal_font_charcount,&_builtin_normal_font_charrects[0][0],_builtin_normal_font_kerning_pair_count,&_builtin_normal_font_kerning_pairs[0][0],_builtin_normal_font_img_width,_builtin_normal_font_img_height,_builtin_normal_font_img_data); + Ref<BitmapFont> source_font=make_font2(_builtin_source_font_height,_builtin_source_font_ascent,_builtin_source_font_charcount,&_builtin_source_font_charrects[0][0],_builtin_source_font_kerning_pair_count,&_builtin_source_font_kerning_pairs[0][0],_builtin_source_font_img_width,_builtin_source_font_img_height,_builtin_source_font_img_data); + Ref<BitmapFont> large_font=make_font2(_builtin_large_font_height,_builtin_large_font_ascent,_builtin_large_font_charcount,&_builtin_large_font_charrects[0][0],_builtin_large_font_kerning_pair_count,&_builtin_large_font_kerning_pairs[0][0],_builtin_large_font_img_width,_builtin_large_font_img_height,_builtin_large_font_img_data); // Font Colors @@ -939,7 +939,7 @@ void make_default_theme() { style->set_default_margin( Margin(),8); } - Ref<Font> f = make_default_font(); + Ref<BitmapFont> f = make_default_font(); Theme::set_default( t ); Theme::set_default_icon( texture ); Theme::set_default_style( style ); diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index ef5b7a3eb0..0d8d224037 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -31,7 +31,67 @@ #include "core/os/file_access.h" #include "core/io/resource_loader.h" -void Font::_set_chars(const DVector<int>& p_chars) { + + +void Font::draw_halign(RID p_canvas_item, const Point2& p_pos, HAlign p_align,float p_width,const String& p_text,const Color& p_modulate) const { + + float length=get_string_size(p_text).width; + if (length>=p_width) { + draw(p_canvas_item,p_pos,p_text,p_modulate,p_width); + return; + } + + float ofs; + switch(p_align) { + case HALIGN_LEFT: { + ofs=0; + } break; + case HALIGN_CENTER: { + ofs = Math::floor( (p_width-length) / 2.0 ); + } break; + case HALIGN_RIGHT: { + ofs=p_width-length; + } break; + } + draw(p_canvas_item,p_pos+Point2(ofs,0),p_text,p_modulate,p_width); +} + +void Font::draw(RID p_canvas_item, const Point2& p_pos, const String& p_text, const Color& p_modulate,int p_clip_w) const { + + Vector2 ofs; + + for (int i=0;i<p_text.length();i++) { + + int width = get_char_size(p_text[i]).width; + + if (p_clip_w>=0 && (ofs.x+width)>p_clip_w) + break; //clip + + ofs.x+=draw_char(p_canvas_item,p_pos+ofs,p_text[i],p_text[i+1],p_modulate); + } +} + +void Font::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("draw","canvas_item","pos","string","modulate","clip_w"),&Font::draw,DEFVAL(Color(1,1,1)),DEFVAL(-1)); + ObjectTypeDB::bind_method(_MD("get_ascent"),&Font::get_ascent); + ObjectTypeDB::bind_method(_MD("get_descent"),&Font::get_descent); + ObjectTypeDB::bind_method(_MD("get_height"),&Font::get_height); + ObjectTypeDB::bind_method(_MD("is_distance_field_hint"),&Font::is_distance_field_hint); + ObjectTypeDB::bind_method(_MD("get_string_size","string"),&Font::get_string_size); + ObjectTypeDB::bind_method(_MD("draw_char","canvas_item","pos","char","next","modulate"),&Font::draw_char,DEFVAL(-1),DEFVAL(Color(1,1,1))); + +} + + +Font::Font() { + + +} + +///////////////////////////////////////////////////////////////// + +void BitmapFont::_set_chars(const DVector<int>& p_chars) { int len = p_chars.size(); //char 1 charsize 1 texture, 4 rect, 2 align, advance 1 @@ -50,7 +110,7 @@ void Font::_set_chars(const DVector<int>& p_chars) { } -DVector<int> Font::_get_chars() const { +DVector<int> BitmapFont::_get_chars() const { DVector<int> chars; @@ -74,7 +134,7 @@ DVector<int> Font::_get_chars() const { return chars; } -void Font::_set_kernings(const DVector<int>& p_kernings) { +void BitmapFont::_set_kernings(const DVector<int>& p_kernings) { int len=p_kernings.size(); ERR_FAIL_COND(len%3); @@ -89,7 +149,7 @@ void Font::_set_kernings(const DVector<int>& p_kernings) { } } -DVector<int> Font::_get_kernings() const { +DVector<int> BitmapFont::_get_kernings() const { DVector<int> kernings; @@ -104,7 +164,7 @@ DVector<int> Font::_get_kernings() const { } -void Font::_set_textures(const Vector<Variant> & p_textures) { +void BitmapFont::_set_textures(const Vector<Variant> & p_textures) { for(int i=0;i<p_textures.size();i++) { Ref<Texture> tex = p_textures[i]; @@ -114,7 +174,7 @@ void Font::_set_textures(const Vector<Variant> & p_textures) { } -Vector<Variant> Font::_get_textures() const { +Vector<Variant> BitmapFont::_get_textures() const { Vector<Variant> rtextures; for(int i=0;i<textures.size();i++) @@ -122,7 +182,7 @@ Vector<Variant> Font::_get_textures() const { return rtextures; } -Error Font::create_from_fnt(const String& p_string) { +Error BitmapFont::create_from_fnt(const String& p_string) { //fnt format used by angelcode bmfont //http://www.angelcode.com/products/bmfont/ @@ -271,51 +331,51 @@ Error Font::create_from_fnt(const String& p_string) { -void Font::set_height(float p_height) { +void BitmapFont::set_height(float p_height) { height=p_height; } -float Font::get_height() const{ +float BitmapFont::get_height() const{ return height; } -void Font::set_ascent(float p_ascent){ +void BitmapFont::set_ascent(float p_ascent){ ascent=p_ascent; } -float Font::get_ascent() const { +float BitmapFont::get_ascent() const { return ascent; } -float Font::get_descent() const { +float BitmapFont::get_descent() const { return height-ascent; } -void Font::add_texture(const Ref<Texture>& p_texture) { +void BitmapFont::add_texture(const Ref<Texture>& p_texture) { ERR_FAIL_COND( p_texture.is_null()); textures.push_back( p_texture ); } -int Font::get_texture_count() const { +int BitmapFont::get_texture_count() const { return textures.size(); }; -Ref<Texture> Font::get_texture(int p_idx) const { +Ref<Texture> BitmapFont::get_texture(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, textures.size(), Ref<Texture>()); return textures[p_idx]; }; -int Font::get_character_count() const { +int BitmapFont::get_character_count() const { return char_map.size(); }; -Vector<CharType> Font::get_char_keys() const { +Vector<CharType> BitmapFont::get_char_keys() const { Vector<CharType> chars; chars.resize(char_map.size()); @@ -329,7 +389,7 @@ Vector<CharType> Font::get_char_keys() const { return chars; }; -Font::Character Font::get_character(CharType p_char) const { +BitmapFont::Character BitmapFont::get_character(CharType p_char) const { if (!char_map.has(p_char)) { ERR_FAIL_V(Character()); @@ -338,7 +398,7 @@ Font::Character Font::get_character(CharType p_char) const { return char_map[p_char]; }; -void Font::add_char(CharType p_char, int p_texture_idx, const Rect2& p_rect, const Size2& p_align, float p_advance) { +void BitmapFont::add_char(CharType p_char, int p_texture_idx, const Rect2& p_rect, const Size2& p_align, float p_advance) { if (p_advance<0) p_advance=p_rect.size.width; @@ -353,7 +413,7 @@ void Font::add_char(CharType p_char, int p_texture_idx, const Rect2& p_rect, con char_map[p_char]=c; } -void Font::add_kerning_pair(CharType p_A,CharType p_B,int p_kerning) { +void BitmapFont::add_kerning_pair(CharType p_A,CharType p_B,int p_kerning) { KerningPairKey kpk; @@ -369,10 +429,10 @@ void Font::add_kerning_pair(CharType p_A,CharType p_B,int p_kerning) { } } -Vector<Font::KerningPairKey> Font::get_kerning_pair_keys() const { +Vector<BitmapFont::KerningPairKey> BitmapFont::get_kerning_pair_keys() const { - Vector<Font::KerningPairKey> ret; + Vector<BitmapFont::KerningPairKey> ret; ret.resize(kerning_map.size()); int i=0; @@ -385,7 +445,7 @@ Vector<Font::KerningPairKey> Font::get_kerning_pair_keys() const { } -int Font::get_kerning_pair(CharType p_A,CharType p_B) const { +int BitmapFont::get_kerning_pair(CharType p_A,CharType p_B) const { KerningPairKey kpk; kpk.A=p_A; @@ -398,19 +458,19 @@ int Font::get_kerning_pair(CharType p_A,CharType p_B) const { return 0; } -void Font::set_distance_field_hint(bool p_distance_field) { +void BitmapFont::set_distance_field_hint(bool p_distance_field) { distance_field_hint=p_distance_field; emit_changed(); } -bool Font::is_distance_field_hint() const{ +bool BitmapFont::is_distance_field_hint() const{ return distance_field_hint; } -void Font::clear() { +void BitmapFont::clear() { height=1; ascent=0; @@ -426,7 +486,7 @@ Size2 Font::get_string_size(const String& p_string) const { int l = p_string.length(); if (l==0) - return Size2(0,height); + return Size2(0,get_height()); const CharType *sptr = &p_string[0]; for (int i=0;i<l;i++) { @@ -434,48 +494,19 @@ Size2 Font::get_string_size(const String& p_string) const { w+=get_char_size(sptr[i],sptr[i+1]).width; } - return Size2(w,height); + return Size2(w,get_height()); } +void BitmapFont::set_fallback(const Ref<BitmapFont> &p_fallback) { -void Font::draw_halign(RID p_canvas_item, const Point2& p_pos, HAlign p_align,float p_width,const String& p_text,const Color& p_modulate) const { - - float length=get_string_size(p_text).width; - if (length>=p_width) { - draw(p_canvas_item,p_pos,p_text,p_modulate,p_width); - return; - } - - float ofs; - switch(p_align) { - case HALIGN_LEFT: { - ofs=0; - } break; - case HALIGN_CENTER: { - ofs = Math::floor( (p_width-length) / 2.0 ); - } break; - case HALIGN_RIGHT: { - ofs=p_width-length; - } break; - } - draw(p_canvas_item,p_pos+Point2(ofs,0),p_text,p_modulate,p_width); + fallback=p_fallback; } -void Font::draw(RID p_canvas_item, const Point2& p_pos, const String& p_text, const Color& p_modulate,int p_clip_w) const { +Ref<BitmapFont> BitmapFont::get_fallback() const{ - Vector2 ofs; - - for (int i=0;i<p_text.length();i++) { - - int width = get_char_size(p_text[i]).width; - - if (p_clip_w>=0 && (ofs.x+width)>p_clip_w) - break; //clip - - ofs.x+=draw_char(p_canvas_item,p_pos+ofs,p_text[i],p_text[i+1],p_modulate); - } + return fallback; } -float Font::draw_char(RID p_canvas_item, const Point2& p_pos, const CharType& p_char,const CharType& p_next,const Color& p_modulate) const { +float BitmapFont::draw_char(RID p_canvas_item, const Point2& p_pos, const CharType& p_char,const CharType& p_next,const Color& p_modulate) const { const Character * c = char_map.getptr(p_char); @@ -496,58 +527,70 @@ float Font::draw_char(RID p_canvas_item, const Point2& p_pos, const CharType& p_ return get_char_size(p_char,p_next).width; } -void Font::set_fallback(const Ref<Font> &p_fallback) { - fallback=p_fallback; -} +Size2 BitmapFont::get_char_size(CharType p_char,CharType p_next) const { -Ref<Font> Font::get_fallback() const{ + const Character * c = char_map.getptr(p_char); - return fallback; + if (!c) { + if (fallback.is_valid()) + return fallback->get_char_size(p_char,p_next); + return Size2(); + } + + Size2 ret(c->advance,c->rect.size.y); + + if (p_next) { + + KerningPairKey kpk; + kpk.A=p_char; + kpk.B=p_next; + + const Map<KerningPairKey,int>::Element *E=kerning_map.find(kpk); + if (E) { + + ret.width-=E->get(); + } + } + + return ret; } -void Font::_bind_methods() { +void BitmapFont::_bind_methods() { - ObjectTypeDB::bind_method(_MD("create_from_fnt","path"),&Font::create_from_fnt); - ObjectTypeDB::bind_method(_MD("set_height","px"),&Font::set_height); - ObjectTypeDB::bind_method(_MD("get_height"),&Font::get_height); + ObjectTypeDB::bind_method(_MD("create_from_fnt","path"),&BitmapFont::create_from_fnt); + ObjectTypeDB::bind_method(_MD("set_height","px"),&BitmapFont::set_height); - ObjectTypeDB::bind_method(_MD("set_ascent","px"),&Font::set_ascent); - ObjectTypeDB::bind_method(_MD("get_ascent"),&Font::get_ascent); - ObjectTypeDB::bind_method(_MD("get_descent"),&Font::get_descent); + ObjectTypeDB::bind_method(_MD("set_ascent","px"),&BitmapFont::set_ascent); - ObjectTypeDB::bind_method(_MD("add_kerning_pair","char_a","char_b","kerning"),&Font::add_kerning_pair); - ObjectTypeDB::bind_method(_MD("get_kerning_pair","char_a","char_b"),&Font::get_kerning_pair); + ObjectTypeDB::bind_method(_MD("add_kerning_pair","char_a","char_b","kerning"),&BitmapFont::add_kerning_pair); + ObjectTypeDB::bind_method(_MD("get_kerning_pair","char_a","char_b"),&BitmapFont::get_kerning_pair); - ObjectTypeDB::bind_method(_MD("add_texture","texture:Texture"),&Font::add_texture); - ObjectTypeDB::bind_method(_MD("add_char","character","texture","rect","align","advance"),&Font::add_char,DEFVAL(Point2()),DEFVAL(-1)); + ObjectTypeDB::bind_method(_MD("add_texture","texture:Texture"),&BitmapFont::add_texture); + ObjectTypeDB::bind_method(_MD("add_char","character","texture","rect","align","advance"),&BitmapFont::add_char,DEFVAL(Point2()),DEFVAL(-1)); - ObjectTypeDB::bind_method(_MD("get_texture_count"),&Font::get_texture_count); - ObjectTypeDB::bind_method(_MD("get_texture:Texture","idx"),&Font::get_texture); + ObjectTypeDB::bind_method(_MD("get_texture_count"),&BitmapFont::get_texture_count); + ObjectTypeDB::bind_method(_MD("get_texture:Texture","idx"),&BitmapFont::get_texture); - ObjectTypeDB::bind_method(_MD("get_char_size","char","next"),&Font::get_char_size,DEFVAL(0)); - ObjectTypeDB::bind_method(_MD("get_string_size","string"),&Font::get_string_size); + ObjectTypeDB::bind_method(_MD("get_char_size","char","next"),&BitmapFont::get_char_size,DEFVAL(0)); - ObjectTypeDB::bind_method(_MD("set_distance_field_hint","enable"),&Font::set_distance_field_hint); - ObjectTypeDB::bind_method(_MD("is_distance_field_hint"),&Font::is_distance_field_hint); + ObjectTypeDB::bind_method(_MD("set_distance_field_hint","enable"),&BitmapFont::set_distance_field_hint); - ObjectTypeDB::bind_method(_MD("clear"),&Font::clear); + ObjectTypeDB::bind_method(_MD("clear"),&BitmapFont::clear); - ObjectTypeDB::bind_method(_MD("draw","canvas_item","pos","string","modulate","clip_w"),&Font::draw,DEFVAL(Color(1,1,1)),DEFVAL(-1)); - ObjectTypeDB::bind_method(_MD("draw_char","canvas_item","pos","char","next","modulate"),&Font::draw_char,DEFVAL(-1),DEFVAL(Color(1,1,1))); - ObjectTypeDB::bind_method(_MD("_set_chars"),&Font::_set_chars); - ObjectTypeDB::bind_method(_MD("_get_chars"),&Font::_get_chars); + ObjectTypeDB::bind_method(_MD("_set_chars"),&BitmapFont::_set_chars); + ObjectTypeDB::bind_method(_MD("_get_chars"),&BitmapFont::_get_chars); - ObjectTypeDB::bind_method(_MD("_set_kernings"),&Font::_set_kernings); - ObjectTypeDB::bind_method(_MD("_get_kernings"),&Font::_get_kernings); + ObjectTypeDB::bind_method(_MD("_set_kernings"),&BitmapFont::_set_kernings); + ObjectTypeDB::bind_method(_MD("_get_kernings"),&BitmapFont::_get_kernings); - ObjectTypeDB::bind_method(_MD("_set_textures"),&Font::_set_textures); - ObjectTypeDB::bind_method(_MD("_get_textures"),&Font::_get_textures); + ObjectTypeDB::bind_method(_MD("_set_textures"),&BitmapFont::_set_textures); + ObjectTypeDB::bind_method(_MD("_get_textures"),&BitmapFont::_get_textures); - ObjectTypeDB::bind_method(_MD("set_fallback","fallback"),&Font::set_fallback); - ObjectTypeDB::bind_method(_MD("get_fallback"),&Font::get_fallback); + ObjectTypeDB::bind_method(_MD("set_fallback","fallback"),&BitmapFont::set_fallback); + ObjectTypeDB::bind_method(_MD("get_fallback"),&BitmapFont::get_fallback); ADD_PROPERTY( PropertyInfo( Variant::ARRAY, "textures", PROPERTY_HINT_NONE,"", PROPERTY_USAGE_NOEDITOR ), _SCS("_set_textures"), _SCS("_get_textures") ); ADD_PROPERTY( PropertyInfo( Variant::INT_ARRAY, "chars", PROPERTY_HINT_NONE,"", PROPERTY_USAGE_NOEDITOR ), _SCS("_set_chars"), _SCS("_get_chars") ); @@ -556,11 +599,11 @@ void Font::_bind_methods() { ADD_PROPERTY( PropertyInfo( Variant::REAL, "height", PROPERTY_HINT_RANGE,"-1024,1024,1" ), _SCS("set_height"), _SCS("get_height") ); ADD_PROPERTY( PropertyInfo( Variant::REAL, "ascent", PROPERTY_HINT_RANGE,"-1024,1024,1" ), _SCS("set_ascent"), _SCS("get_ascent") ); ADD_PROPERTY( PropertyInfo( Variant::BOOL, "distance_field" ), _SCS("set_distance_field_hint"), _SCS("is_distance_field_hint") ); - ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "fallback", PROPERTY_HINT_RESOURCE_TYPE,"Font" ), _SCS("set_fallback"), _SCS("get_fallback") ); + ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "fallback", PROPERTY_HINT_RESOURCE_TYPE,"BitmapFont" ), _SCS("set_fallback"), _SCS("get_fallback") ); } -Font::Font() { +BitmapFont::BitmapFont() { clear(); @@ -569,7 +612,7 @@ Font::Font() { } -Font::~Font() { +BitmapFont::~BitmapFont() { clear(); } diff --git a/scene/resources/font.h b/scene/resources/font.h index 03b1ec5191..91f4874932 100644 --- a/scene/resources/font.h +++ b/scene/resources/font.h @@ -35,9 +35,40 @@ /** @author Juan Linietsky <reduzio@gmail.com> */ + + class Font : public Resource { OBJ_TYPE( Font, Resource ); + +protected: + + static void _bind_methods(); + +public: + + virtual float get_height() const=0; + + virtual float get_ascent() const=0; + virtual float get_descent() const=0; + + virtual Size2 get_char_size(CharType p_char,CharType p_next=0) const=0; + Size2 get_string_size(const String& p_string) const; + + virtual bool is_distance_field_hint() const=0; + + void draw(RID p_canvas_item, const Point2& p_pos, const String& p_text,const Color& p_modulate=Color(1,1,1),int p_clip_w=-1) const; + void draw_halign(RID p_canvas_item, const Point2& p_pos, HAlign p_align,float p_width,const String& p_text,const Color& p_modulate=Color(1,1,1)) const; + virtual 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=0; + + Font(); + +}; + + +class BitmapFont : public Font { + + OBJ_TYPE( BitmapFont, Font ); RES_BASE_EXTENSION("fnt"); Vector< Ref<Texture> > textures; @@ -84,7 +115,7 @@ private: void _set_textures(const Vector<Variant> & p_textures); Vector<Variant> _get_textures() const; - Ref<Font> fallback; + Ref<BitmapFont> fallback; protected: static void _bind_methods(); @@ -114,54 +145,23 @@ public: int get_kerning_pair(CharType p_A,CharType p_B) const; Vector<KerningPairKey> get_kerning_pair_keys() const; - inline Size2 get_char_size(CharType p_char,CharType p_next=0) const; - Size2 get_string_size(const String& p_string) const; - + Size2 get_char_size(CharType p_char,CharType p_next=0) const; - void set_fallback(const Ref<Font> &p_fallback); - Ref<Font> get_fallback() const; + void set_fallback(const Ref<BitmapFont> &p_fallback); + Ref<BitmapFont> get_fallback() const; void clear(); void set_distance_field_hint(bool p_distance_field); bool is_distance_field_hint() const; - void draw(RID p_canvas_item, const Point2& p_pos, const String& p_text,const Color& p_modulate=Color(1,1,1),int p_clip_w=-1) const; - void draw_halign(RID p_canvas_item, const Point2& p_pos, HAlign p_align,float p_width,const String& p_text,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=0,const Color& p_modulate=Color(1,1,1)) const; - Font(); - ~Font(); + BitmapFont(); + ~BitmapFont(); }; -Size2 Font::get_char_size(CharType p_char,CharType p_next) const { - - const Character * c = char_map.getptr(p_char); - - if (!c) { - if (fallback.is_valid()) - return fallback->get_char_size(p_char,p_next); - return Size2(); - } - - Size2 ret(c->advance,c->rect.size.y); - - if (p_next) { - - KerningPairKey kpk; - kpk.A=p_char; - kpk.B=p_next; - - const Map<KerningPairKey,int>::Element *E=kerning_map.find(kpk); - if (E) { - - ret.width-=E->get(); - } - } - - return ret; -} |