6 #ifndef TB_FONT_RENDERER_H
7 #define TB_FONT_RENDERER_H
10 #include "tb_bitmap_fragment.h"
11 #include "tb_renderer.h"
12 #include "tb_tempbuffer.h"
13 #include "tb_linklist.h"
14 #include "tb_font_desc.h"
15 #include "utf8/utf8.h"
27 TBFontGlyphData() : data8(
nullptr), data32(
nullptr), w(0), h(0), stride(0), rgb(
false) {}
41 int16_t advance, x, y;
66 virtual void GetGlyphMetrics(
TBGlyphMetrics *metrics, UCS4 cp) = 0;
103 #ifdef TB_RUNTIME_DEBUG_INFO
149 bool RenderGlyphs(
const char *glyph_str,
int glyph_str_len = TB_ALL_TO_TERMINATION);
170 void DrawString(
int x,
int y,
const TBColor &color,
const char *str,
int len = TB_ALL_TO_TERMINATION);
174 int GetStringWidth(
const char *str,
int len = TB_ALL_TO_TERMINATION);
176 #ifdef TB_RUNTIME_DEBUG_INFO
185 TBID GetHashId(UCS4 cp)
const;
186 TBFontGlyph *GetGlyph(UCS4 cp,
bool render_if_needed);
218 TBFontInfo(
const TBStr & filename,
const TBStr & name) : m_filename(filename), m_name(name), m_id(name) {}
245 void RemoveRenderer(
TBFontRenderer *renderer) { m_font_renderers.Remove(renderer); }
249 TBFontInfo *
AddFontInfo(
const char *filename,
const char *name);
255 bool HasFontFace(
const TBFontDescription &font_desc)
const;
260 TBFontFace *
GetFontFace(
const TBFontDescription &font_desc);
270 TBFontDescription GetDefaultFontDescription()
const {
return m_default_font_desc; }
285 #endif // TB_FONT_RENDERER_H
TBFontGlyph * GetGlyph(const TBID &hash_id, UCS4 cp)
Get the glyph or nullptr if it is not in the cache.
Definition: tb_font_renderer.cpp:139
TBLinkListOf is a double linked linklist.
Definition: tb_linklist.h:122
bool has_rgb
if true, drawing should ignore text color.
Definition: tb_font_renderer.h:82
TBBitmapFragmentManager manages loading bitmaps of arbitrary size, pack as many of them into as few T...
Definition: tb_bitmap_fragment.h:177
int16_t ascent
Ascent. See TBFontFace::GetAscent()
Definition: tb_font_renderer.h:49
TBFontFace * GetFontFace(const TBFontDescription &font_desc)
Get a loaded font matching the description, or the default font if there is no exact match...
Definition: tb_font_renderer.cpp:466
TBHashTableOf is a TBHashTable with the given class type as content.
Definition: tb_hashtable.h:112
TBFontFace represents a loaded font that can measure and render strings.
Definition: tb_font_renderer.h:142
TBFontGlyphData is rendering info used during glyph rendering by TBFontRenderer.
Definition: tb_font_renderer.h:24
void DrawString(int x, int y, const TBColor &color, const char *str, int len=TB_ALL_TO_TERMINATION)
Draw string at position x, y (marks the upper left corner of the text).
Definition: tb_font_renderer.cpp:366
int16_t height
Height. See TBFontFace::GetHeight()
Definition: tb_font_renderer.h:51
TBFontDescription GetFontDescription() const
Get the font description that was used to create this font.
Definition: tb_font_renderer.h:163
virtual void OnContextRestored()
Called when the context has been restored again, and new TBBitmaps can be created again...
Definition: tb_font_renderer.cpp:232
virtual TBFontFace * Create(TBFontManager *font_manager, const TBStr &filename, const TBFontDescription &font_desc)=0
Open the given font file with this renderer and return a new TBFontFace with it.
TBFontEffect applies an effect on each glyph that is rendered in a TBFontFace.
Definition: tb_font_renderer.h:119
TBFontInfo * GetFontInfo(const TBID &id) const
Get TBFontInfo for the given font id, or nullptr if there is no match.
Definition: tb_font_renderer.cpp:456
TBRendererListener is a listener for TBRenderer.
Definition: tb_renderer.h:19
void SetBlurRadius(int blur_radius)
Set blur radius.
Definition: tb_font_renderer.cpp:48
TBFontGlyphCache * GetGlyphCache()
Return the glyph cache used for fonts created by this font manager.
Definition: tb_font_renderer.h:273
TBID is a wrapper for a uint32_t to be used as ID.
Definition: tb_id.h:18
TBID GetID() const
Get the font ID that can be used to create this font from a TBFontDescription (See TBFontDescription:...
Definition: tb_font_renderer.h:214
TBBitmapFragment represents a sub part of a TBBitmap.
Definition: tb_bitmap_fragment.h:140
TBGlyphMetrics metrics
The glyph metrics.
Definition: tb_font_renderer.h:80
int GetStringWidth(const char *str, int len=TB_ALL_TO_TERMINATION)
Measure the width of the given string.
Definition: tb_font_renderer.cpp:404
TBFontEffect * GetEffect()
Get the effect object, so the effect can be changed.
Definition: tb_font_renderer.h:167
int GetAscent() const
Get the vertical distance (positive) from the horizontal baseline to the highest character coordinate...
Definition: tb_font_renderer.h:153
TBStr is a simple string class.
Definition: tb_str.h:62
TBBitmapFragment * frag
The bitmap fragment, or nullptr if missing.
Definition: tb_font_renderer.h:81
bool HasFontFace(const TBFontDescription &font_desc) const
Return true if there is a font loaded that match the given font description.
Definition: tb_font_renderer.cpp:461
int GetDescent() const
Get the vertical distance (positive) from the horizontal baseline to the lowest character coordinate ...
Definition: tb_font_renderer.h:157
TBFontFace * CreateFontFace(const TBFontDescription &font_desc)
Create and add a font with the given description.
Definition: tb_font_renderer.cpp:475
bool RendersInRGB() const
Returns true if the result is in RGB and should not be painted using the color parameter given to Dra...
Definition: tb_font_renderer.h:130
int16_t descent
Descent. See TBFontFace::GetDescent()
Definition: tb_font_renderer.h:50
TBLinkListAutoDeleteOf is a double linked linklist that deletes all links on destruction.
Definition: tb_linklist.h:194
void AddRenderer(TBFontRenderer *renderer)
Add a renderer so fonts supported by the renderer can be created.
Definition: tb_font_renderer.h:244
Definition: tb_linklist.h:83
void SetDefaultFontDescription(const TBFontDescription &font_desc)
Set the default font description.
Definition: tb_font_renderer.h:269
TBColor contains a 32bit color.
Definition: tb_color.h:21
TBFontGlyph holds glyph metrics and bitmap fragment.
Definition: tb_font_renderer.h:74
int GetHeight() const
Get height of the font in pixels.
Definition: tb_font_renderer.h:160
TBFontRenderer renders glyphs from a font file.
Definition: tb_font_renderer.h:55
virtual void OnContextLost()
Called when the context has been lost and all TBBitmaps need to be deleted.
Definition: tb_font_renderer.cpp:227
TBFontDescription describes a font.
Definition: tb_font_desc.h:18
TBFontInfo provides information about a font file associated with a font id.
Definition: tb_font_renderer.h:203
const TBStr & GetName() const
Get the font name.
Definition: tb_font_renderer.h:210
TBFontMetrics contains metrics for a font face.
Definition: tb_font_renderer.h:45
TBGlyphMetrics contains metrics for a font glyph.
Definition: tb_font_renderer.h:37
const TBStr & GetFilename() const
Get the font filename.
Definition: tb_font_renderer.h:207
TBFontInfo * AddFontInfo(const char *filename, const char *name)
Add TBFontInfo for the given font filename, so it can be loaded and identified using the font id in a...
Definition: tb_font_renderer.cpp:445
TBBitmapFragment * CreateFragment(TBFontGlyph *glyph, int w, int h, int stride, uint32_t *data)
Create a bitmap fragment for the given glyph and render data.
Definition: tb_font_renderer.cpp:164
TBFontManager creates and owns font faces (TBFontFace) which are looked up from TBFontDescription usi...
Definition: tb_font_renderer.h:236
bool RenderGlyphs(const char *glyph_str, int glyph_str_len=TB_ALL_TO_TERMINATION)
Render all glyphs needed to display the string.
Definition: tb_font_renderer.cpp:270
TBFontGlyphCache caches glyphs for font faces.
Definition: tb_font_renderer.h:87
TBFontGlyph * CreateAndCacheGlyph(const TBID &hash_id, UCS4 cp)
Create the glyph and put it in the cache.
Definition: tb_font_renderer.cpp:154
void SetBackgroundFont(TBFontFace *font, const TBColor &col, int xofs, int yofs)
Set a background font which will always be rendered behind this one when calling DrawString.
Definition: tb_font_renderer.cpp:262
TBTempBuffer manages a buffer that will be deleted on destruction.
Definition: tb_tempbuffer.h:18