diff options
Diffstat (limited to 'scene/resources/font.cpp')
-rw-r--r-- | scene/resources/font.cpp | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 2d93113b40..0aae6fd978 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -5,7 +5,7 @@ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2015 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -462,31 +462,16 @@ void Font::draw_halign(RID p_canvas_item, const Point2& p_pos, HAlign p_align,fl void Font::draw(RID p_canvas_item, const Point2& p_pos, const String& p_text, const Color& p_modulate,int p_clip_w) const { - Point2 pos=p_pos; - float ofs=0; - VisualServer *vs = VisualServer::get_singleton(); + Vector2 ofs; for (int i=0;i<p_text.length();i++) { - const Character * c = char_map.getptr(p_text[i]); + int width = get_char_size(p_text[i]).width; - if (!c) - continue; - -// if (p_clip_w>=0 && (ofs+c->rect.size.width)>(p_clip_w)) -// break; //width exceeded - - if (p_clip_w>=0 && (ofs+c->rect.size.width)>p_clip_w) + if (p_clip_w>=0 && (ofs.x+width)>p_clip_w) break; //clip - Point2 cpos=pos; - cpos.x+=ofs+c->h_align; - cpos.y-=ascent; - cpos.y+=c->v_align; - ERR_CONTINUE( c->texture_idx<-1 || c->texture_idx>=textures.size()); - if (c->texture_idx!=-1) - textures[c->texture_idx]->draw_rect_region( p_canvas_item, Rect2( cpos, c->rect.size ), c->rect, p_modulate ); - - ofs+=get_char_size(p_text[i],p_text[i+1]).width; + + ofs.x+=draw_char(p_canvas_item,p_pos+ofs,p_text[i],p_text[i+1],p_modulate); } } @@ -494,8 +479,11 @@ float Font::draw_char(RID p_canvas_item, const Point2& p_pos, const CharType& p_ const Character * c = char_map.getptr(p_char); - if (!c) + if (!c) { + if (fallback.is_valid()) + return fallback->draw_char(p_canvas_item,p_pos,p_char,p_next,p_modulate); return 0; + } Point2 cpos=p_pos; cpos.x+=c->h_align; @@ -508,6 +496,16 @@ 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; +} + +Ref<Font> Font::get_fallback() const{ + + return fallback; +} + void Font::_bind_methods() { ObjectTypeDB::bind_method(_MD("create_from_fnt","path"),&Font::create_from_fnt); @@ -519,7 +517,7 @@ void Font::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_descent"),&Font::get_descent); ObjectTypeDB::bind_method(_MD("add_kerning_pair","char_a","char_b","kerning"),&Font::add_kerning_pair); - ObjectTypeDB::bind_method(_MD("get_kerning_pair"),&Font::get_kerning_pair); + ObjectTypeDB::bind_method(_MD("get_kerning_pair","char_a","char_b"),&Font::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)); @@ -548,6 +546,8 @@ void Font::_bind_methods() { ObjectTypeDB::bind_method(_MD("_set_textures"),&Font::_set_textures); ObjectTypeDB::bind_method(_MD("_get_textures"),&Font::_get_textures); + ObjectTypeDB::bind_method(_MD("set_fallback","fallback"),&Font::set_fallback); + ObjectTypeDB::bind_method(_MD("get_fallback"),&Font::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,6 +556,7 @@ 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") ); } |