summaryrefslogtreecommitdiff
path: root/scene/resources/font.h
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/font.h')
-rw-r--r--scene/resources/font.h74
1 files changed, 37 insertions, 37 deletions
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;
-}