50 #include <unordered_map>
52 #include <cugl/math/CUSize.h>
53 #include <cugl/math/CURect.h>
54 #include <cugl/renderer/CUTexture.h>
55 #include <cugl/renderer/CUVertex.h>
56 #include <SDL/SDL_ttf.h>
99 #pragma mark Inner Classes
136 NORMAL = TTF_STYLE_NORMAL,
138 BOLD = TTF_STYLE_BOLD,
140 ITALIC = TTF_STYLE_ITALIC,
144 STRIKE = TTF_STYLE_STRIKETHROUGH
159 NORMAL = TTF_HINTING_NORMAL,
165 LIGHT = TTF_HINTING_LIGHT,
171 MONO = TTF_HINTING_MONO,
176 NONE = TTF_HINTING_NONE
266 std::unordered_map<Uint32, std::unordered_map<Uint32, Uint32> >
_kernmap;
275 #pragma mark Constructors
311 bool init(
const std::string& file,
int size);
325 bool init(
const char* file,
int size) {
326 return init(std::string(file),size);
331 #pragma mark Static Constructors
344 static std::shared_ptr<Font>
alloc(
const std::string& file,
int size) {
345 std::shared_ptr<Font> result = std::make_shared<Font>();
346 return (result->init(file,size) ? result :
nullptr);
361 static std::shared_ptr<Font>
alloc(
const char* file,
int size) {
362 std::shared_ptr<Font> result = std::make_shared<Font>();
363 return (result->init(file,size) ? result :
nullptr);
367 #pragma mark Attributes
507 bool hasString(
const std::string& text)
const;
525 #pragma mark Settings
608 #pragma mark Measurements
637 const Metrics
getMetrics(Uint32 thechar)
const;
671 unsigned int getKerning(Uint32 a, Uint32 b)
const;
696 Size getSize(
const std::string& text,
bool utf8=
true)
const;
722 return getSize(std::string(text), utf8);
804 #pragma mark Atlas Support
829 return result && (
getAtlas() !=
nullptr);
853 return result && (
getAtlas() !=
nullptr);
877 return result && (
getAtlas() !=
nullptr);
952 const std::shared_ptr<Texture>&
getAtlas();
965 #pragma mark Rendering
999 std::shared_ptr<Texture>
getQuads(
const std::string& text,
const Vec2& origin,
1000 std::vector<Vertex2>& vertices,
bool utf8=
true);
1034 std::vector<Vertex2>& vertices,
bool utf8=
true) {
1035 return getQuads(std::string(text),origin,vertices,utf8);
1074 std::shared_ptr<Texture>
getQuads(
const std::string& text,
const Vec2& origin,
const Rect& rect,
1075 std::vector<Vertex2>& vertices,
bool utf8=
true);
1114 std::vector<Vertex2>& vertices,
bool utf8=
true) {
1115 return getQuads(std::string(text),origin,rect,vertices,utf8);
1138 std::shared_ptr<Texture>
getQuad(Uint32 thechar,
Vec2& offset, std::vector<Vertex2>& vertices);
1164 std::shared_ptr<Texture>
getQuad(Uint32 thechar,
Vec2& offset,
const Rect& rect,
1165 std::vector<Vertex2>& vertices);
1169 #pragma mark Rendering Internals
1202 std::vector<Vertex2>& vertices,
bool utf8);
1238 std::vector<Vertex2>& vertices,
bool utf8);
1259 bool getAtlasQuad(Uint32 thechar,
Vec2& offset,
const Rect& rect, std::vector<Vertex2>& vertices);
1283 std::vector<Vertex2>& vertices);
1388 #pragma mark Atlas Preparation
1463 std::vector< std::vector<Uint32> >
planAtlas(
int width,
int height);
1470 void layoutAtlas(
const std::vector< std::vector<Uint32> >& rectangle);
1496 #pragma mark Style Bit-Wise Operators
1504 return static_cast<int>(value);
std::shared_ptr< Texture > getQuads(const char *text, const Vec2 &origin, const Rect &rect, std::vector< Vertex2 > &vertices, bool utf8=true)
Definition: CUFont.h:1113
void getAtlasQuads(const std::string &text, const Vec2 &origin, const Rect &rect, std::vector< Vertex2 > &vertices, bool utf8)
Size getSizeASCII(const std::string &text) const
unsigned int _fontAscent
Definition: CUFont.h:240
Style _style
Definition: CUFont.h:250
bool buildAtlasAsync(const char *charset)
Definition: CUFont.h:939
void setHinting(Hinting hinting)
bool hasString(const std::string &text) const
std::shared_ptr< Texture > getQuads(const char *text, const Vec2 &origin, std::vector< Vertex2 > &vertices, bool utf8=true)
Definition: CUFont.h:1033
Resolution getResolution() const
Definition: CUFont.h:588
Style getStyle() const
Definition: CUFont.h:536
SDL_Surface * allocSurface(int width, int height)
Font::Style operator^(Font::Style lhs, Font::Style rhs)
Definition: CUFont.h:1531
int advance
Definition: CUFont.h:120
void computeAtlasSize(int *width, int *height)
bool hasAtlas() const
Definition: CUFont.h:962
int getAscent() const
Definition: CUFont.h:416
std::shared_ptr< Texture > getRenderedQuads(const std::string &text, const Vec2 &origin, const Rect &rect, std::vector< Vertex2 > &vertices, bool utf8)
const Metrics getMetrics(char thechar) const
Definition: CUFont.h:619
Font::Style operator|(Font::Style lhs, Font::Style rhs)
Definition: CUFont.h:1512
Font::Style operator~(Font::Style lhs)
Definition: CUFont.h:1540
~Font()
Definition: CUFont.h:287
bool getAtlasQuad(Uint32 thechar, Vec2 &offset, const Rect &rect, std::vector< Vertex2 > &vertices)
int getHeight() const
Definition: CUFont.h:397
std::unordered_map< Uint32, std::unordered_map< Uint32, Uint32 > > _kernmap
Definition: CUFont.h:266
std::shared_ptr< Texture > getQuads(const std::string &text, const Vec2 &origin, std::vector< Vertex2 > &vertices, bool utf8=true)
static std::shared_ptr< Font > alloc(const std::string &file, int size)
Definition: CUFont.h:344
void setResolution(Resolution resolution)
Definition: CUFont.h:603
void setKerning(bool kerning)
Rect getInternalBounds(const char *text, bool utf8=true) const
Definition: CUFont.h:799
bool usesKerning() const
Definition: CUFont.h:450
Hinting _hints
Definition: CUFont.h:252
Size getSize(const std::string &text, bool utf8=true) const
void prepareAtlasKerning()
int maxx
Definition: CUFont.h:114
Rect getInternalBoundsUTF8(const std::string &text) const
bool buildAtlas(const std::string &charset)
Definition: CUFont.h:851
const std::shared_ptr< Texture > & getAtlas()
Rect getInternalBounds(const std::string &text, bool utf8=true) const
unsigned int _fontLineSkip
Definition: CUFont.h:242
std::shared_ptr< Texture > getQuad(Uint32 thechar, Vec2 &offset, std::vector< Vertex2 > &vertices)
int getDescent() const
Definition: CUFont.h:407
void setStyle(Style style)
int miny
Definition: CUFont.h:116
int computeKerning(Uint32 a, Uint32 b) const
int _size
Definition: CUFont.h:229
int getLineSkip() const
Definition: CUFont.h:426
unsigned int _fontDescent
Definition: CUFont.h:238
bool buildAtlas(const char *charset)
Definition: CUFont.h:875
const std::string & getStyleName() const
Definition: CUFont.h:386
std::vector< Uint32 > _glyphset
Definition: CUFont.h:260
static std::shared_ptr< Font > alloc(const char *file, int size)
Definition: CUFont.h:361
TTF_Font * _data
Definition: CUFont.h:232
void layoutAtlas(const std::vector< std::vector< Uint32 > > &rectangle)
unsigned int _fontHeight
Definition: CUFont.h:236
bool hasString(const char *text) const
Definition: CUFont.h:520
bool generateSurface(int width, int height)
std::shared_ptr< Texture > getRenderedQuad(Uint32 thechar, Vec2 &offset, const Rect &rect, std::vector< Vertex2 > &vertices)
Font::Style operator&(Font::Style lhs, Font::Style rhs)
Definition: CUFont.h:1521
bool hasGlyph(char a) const
Definition: CUFont.h:474
SDL_Surface * _surface
Definition: CUFont.h:270
bool _useKerning
Definition: CUFont.h:246
unsigned int getKerning(char a, char b) const
Definition: CUFont.h:651
bool isFixedWidth() const
Definition: CUFont.h:439
int maxy
Definition: CUFont.h:118
int minx
Definition: CUFont.h:112
bool init(const char *file, int size)
Definition: CUFont.h:325
const std::string & getName() const
Definition: CUFont.h:376
std::string _name
Definition: CUFont.h:225
int operator*(Font::Style value)
Definition: CUFont.h:1503
Size getSize(const char *text, bool utf8=true) const
Definition: CUFont.h:721
bool buildAtlas()
Definition: CUFont.h:827
Rect getInternalBoundsASCII(const std::string &text) const
Style
Definition: CUFont.h:134
Hinting getHinting() const
Definition: CUFont.h:562
std::vector< std::vector< Uint32 > > planAtlas(int width, int height)
std::string _stylename
Definition: CUFont.h:227
Resolution _render
Definition: CUFont.h:254
Size getSizeUTF8(const std::string &text) const
bool _hasAtlas
Definition: CUFont.h:258
Definition: CUAnimationNode.h:52
Hinting
Definition: CUFont.h:154
std::unordered_map< Uint32, Rect > _glyphmap
Definition: CUFont.h:262
bool _fixedWidth
Definition: CUFont.h:244
Resolution
Definition: CUFont.h:187
Metrics computeMetrics(Uint32 thechar) const
bool init(const std::string &file, int size)
std::shared_ptr< Texture > _texture
Definition: CUFont.h:268
std::unordered_map< Uint32, Metrics > _glyphsize
Definition: CUFont.h:264