FontFaceHandle.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef ROCKETCOREFONTFACEHANDLE_H
00029 #define ROCKETCOREFONTFACEHANDLE_H
00030
00031 #include <Rocket/Core/ReferenceCountable.h>
00032 #include "UnicodeRange.h"
00033 #include <Rocket/Core/Font.h>
00034 #include <Rocket/Core/FontEffect.h>
00035 #include <Rocket/Core/FontGlyph.h>
00036 #include <Rocket/Core/Geometry.h>
00037 #include <Rocket/Core/String.h>
00038 #include <Rocket/Core/Texture.h>
00039 #include <ft2build.h>
00040 #include FT_FREETYPE_H
00041
00042 namespace Rocket {
00043 namespace Core {
00044
00045 class FontFaceLayer;
00046
00051 class FontFaceHandle : public ReferenceCountable
00052 {
00053 public:
00054 FontFaceHandle();
00055 virtual ~FontFaceHandle();
00056
00062 bool Initialise(FT_Face ft_face, const String& charset, int size);
00063
00066 int GetCharacterWidth() const;
00067
00070 int GetSize() const;
00073 int GetXHeight() const;
00076 int GetLineHeight() const;
00077
00080 int GetBaseline() const;
00081
00084 const FontGlyphMap& GetGlyphs() const;
00085
00090 int GetStringWidth(const WString& string, word prior_character = 0) const;
00091
00095 int GenerateLayerConfiguration(FontEffectMap& font_effects);
00101 bool GenerateLayerTexture(const byte*& texture_data, Vector2i& texture_dimensions, int layer_id, int texture_id);
00102
00109 int GenerateString(GeometryList& geometry, const WString& string, const Vector2f& position, const Colourb& colour, int layer_configuration = 0) const;
00116 void GenerateLine(Geometry* geometry, const Vector2f& position, int width, Font::Line height, const Colourb& colour) const;
00117
00120 const String& GetRawCharset() const;
00123 const UnicodeRangeList& GetCharset() const;
00124
00125 protected:
00127 virtual void OnReferenceDeactivate();
00128
00129 private:
00130 void GenerateMetrics(FT_Face ft_face);
00131
00132 void BuildGlyphMap(FT_Face ft_face, const UnicodeRange& unicode_range);
00133 void BuildGlyph(FontGlyph& glyph, FT_GlyphSlot ft_glyph);
00134
00135 void BuildKerning(FT_Face ft_face);
00136 int GetKerning(word lhs, word rhs) const;
00137
00138
00139 FontFaceLayer* GenerateLayer(FontEffect* font_effect);
00140
00141 typedef std::map< word, int > GlyphKerningMap;
00142 typedef std::map< word, GlyphKerningMap > FontKerningMap;
00143
00144 FontGlyphMap glyphs;
00145 FontKerningMap kerning;
00146
00147 typedef std::map< const FontEffect*, FontFaceLayer* > FontLayerMap;
00148 typedef std::map< String, FontFaceLayer* > FontLayerCache;
00149 typedef std::vector< FontFaceLayer* > LayerConfiguration;
00150 typedef std::vector< LayerConfiguration > LayerConfigurationList;
00151
00152
00153 FontFaceLayer* base_layer;
00154 FontLayerMap layers;
00155
00156
00157 FontLayerCache layer_cache;
00158
00159
00160
00161 LayerConfigurationList layer_configurations;
00162
00163
00164 int average_advance;
00165
00166 int size;
00167 int x_height;
00168 int line_height;
00169 int baseline;
00170
00171 float underline_position;
00172 float underline_thickness;
00173
00174 String raw_charset;
00175 UnicodeRangeList charset;
00176 };
00177
00178 }
00179 }
00180
00181 #endif