00001 #ifndef INCLUDED_TTFONT__H_
00002 #define INCLUDED_TTFONT__H_
00003
00004 #include <ft2build.h>
00005 #include FT_FREETYPE_H
00006 #include FT_GLYPH_H
00007
00008 #include <qstring.h>
00009 #include <qmap.h>
00010 #include <qcolor.h>
00011
00012 #include "config.h"
00013
00014 #ifdef HAVE_STDINT_H
00015 #include <stdint.h>
00016 #endif
00017
00018 struct Raster_Map;
00019 class OSDSurface;
00020
00021 enum kTTF_Color {
00022 kTTF_Normal = 0,
00023 kTTF_Outline,
00024 kTTF_Shadow,
00025 };
00026
00027 class TTFFont
00028 {
00029 public:
00030 TTFFont(char *file, int size, float wscale,
00031 float hmult);
00032 ~TTFFont();
00033
00034
00035 void setColor(int color);
00036 void setColor(QColor c, kTTF_Color k = kTTF_Normal);
00037
00038 void setOutline(bool outline) { m_outline = outline; }
00039 void setShadow(int xoff, int yoff) { m_shadowxoff = xoff;
00040 m_shadowyoff = yoff; }
00041
00042 bool isValid(void) { return valid; }
00043
00044 void DrawString(OSDSurface *surface, int x, int y, const QString &text,
00045 int maxx, int maxy, int alphamod = 255,
00046 bool double_size = false);
00047 void CalcWidth(const QString &text, int *width_return);
00048
00049 int SpaceWidth() { return spacewidth; }
00050 int Size() { return loadedfontsize; }
00051
00052 void Reinit(float wscale, float hmult);
00053
00054 private:
00055 void KillFace(void);
00056 void Init(void);
00057
00058 Raster_Map *create_font_raster(int width, int height);
00059 Raster_Map *duplicate_raster(FT_BitmapGlyph bmap);
00060 void clear_raster(Raster_Map *rmap);
00061 void destroy_font_raster(Raster_Map *rmap);
00062 Raster_Map *calc_size(int *width, int *height, const QString &text,
00063 bool double_size = false);
00064 void render_text(Raster_Map *rmap, Raster_Map *rchr, const QString &text,
00065 int *xorblah, int *yor, bool double_size = false);
00066 void merge_text(OSDSurface *surface, Raster_Map *rmap, int offset_x,
00067 int offset_y, int xstart, int ystart, int width,
00068 int height, int alphamod, kTTF_Color k = kTTF_Normal);
00069 bool cache_glyph(unsigned short c);
00070
00071 bool valid;
00072 FT_Library library;
00073 FT_Face face;
00074 QMap<unsigned short, FT_Glyph> glyphs;
00075 QMap<unsigned short, Raster_Map *> glyphs_cached;
00076 int max_descent;
00077 int max_ascent;
00078 int fontsize;
00079 int vid_width;
00080 int vid_height;
00081 bool use_kerning;
00082
00083 int spacewidth;
00084 int m_size;
00085
00086 bool m_outline;
00087 int m_shadowxoff;
00088 int m_shadowyoff;
00089
00090 uint8_t m_color_normal_y;
00091 uint8_t m_color_normal_u;
00092 uint8_t m_color_normal_v;
00093
00094 uint8_t m_color_outline_y;
00095 uint8_t m_color_outline_u;
00096 uint8_t m_color_outline_v;
00097
00098 uint8_t m_color_shadow_y;
00099 uint8_t m_color_shadow_u;
00100 uint8_t m_color_shadow_v;
00101
00102 QString m_file;
00103
00104 int loadedfontsize;
00105 float m_wscale;
00106 float m_hmult;
00107 };
00108
00109 #endif