 |
CUGL 1.3
Cornell University Game Library
|
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);
802 #pragma mark Atlas Support
827 return result && (
getAtlas() !=
nullptr);
851 return result && (
getAtlas() !=
nullptr);
875 return result && (
getAtlas() !=
nullptr);
950 const std::shared_ptr<Texture>&
getAtlas();
963 #pragma mark Rendering
997 std::shared_ptr<Texture>
getQuads(
const std::string& text,
const Vec2& origin,
998 std::vector<Vertex2>& vertices,
bool utf8=
true);
1032 std::vector<Vertex2>& vertices,
bool utf8=
true) {
1033 return getQuads(std::string(text),origin,vertices,utf8);
1072 std::shared_ptr<Texture>
getQuads(
const std::string& text,
const Vec2& origin,
const Rect& rect,
1073 std::vector<Vertex2>& vertices,
bool utf8=
true);
1112 std::vector<Vertex2>& vertices,
bool utf8=
true) {
1113 return getQuads(std::string(text),origin,rect,vertices,utf8);
1136 std::shared_ptr<Texture>
getQuad(Uint32 thechar,
Vec2& offset, std::vector<Vertex2>& vertices);
1162 std::shared_ptr<Texture>
getQuad(Uint32 thechar,
Vec2& offset,
const Rect& rect,
1163 std::vector<Vertex2>& vertices);
1167 #pragma mark Rendering Internals
1200 std::vector<Vertex2>& vertices,
bool utf8);
1236 std::vector<Vertex2>& vertices,
bool utf8);
1257 bool getAtlasQuad(Uint32 thechar,
Vec2& offset,
const Rect& rect, std::vector<Vertex2>& vertices);
1281 std::vector<Vertex2>& vertices);
1384 #pragma mark Atlas Preparation
1459 std::vector< std::vector<Uint32> >
planAtlas(
int width,
int height);
1466 void layoutAtlas(
const std::vector< std::vector<Uint32> >& rectangle);
1492 #pragma mark Style Bit-Wise Operators
1500 return static_cast<int>(value);
1509 return static_cast<Font::Style>((*lhs) | (*rhs));
1518 return static_cast<Font::Style>((*lhs) & (*rhs));
1528 return static_cast<Font::Style>((*lhs) ^ (*rhs));
1537 return static_cast<Font::Style>(~(*lhs));
bool init(const std::string &file, int size)
Hinting
Definition: CUFont.h:154
int getAscent() const
Definition: CUFont.h:416
void computeAtlasSize(int *width, int *height)
Rect getInternalBoundsUTF8(const std::string &text) const
int _size
Definition: CUFont.h:229
bool _hasAtlas
Definition: CUFont.h:258
void setKerning(bool kerning)
bool buildAtlasAsync(const char *charset)
Definition: CUFont.h:937
bool hasString(const char *text) const
Definition: CUFont.h:520
bool getAtlasQuad(Uint32 thechar, Vec2 &offset, const Rect &rect, std::vector< Vertex2 > &vertices)
TTF_Font * _data
Definition: CUFont.h:232
std::shared_ptr< Texture > getQuad(Uint32 thechar, Vec2 &offset, std::vector< Vertex2 > &vertices)
int minx
Definition: CUFont.h:112
bool isFixedWidth() const
Definition: CUFont.h:439
const std::shared_ptr< Texture > & getAtlas()
Hinting _hints
Definition: CUFont.h:252
unsigned int _fontLineSkip
Definition: CUFont.h:242
void prepareAtlasKerning()
Rect getInternalBounds(const char *text, bool utf8=true) const
Definition: CUFont.h:797
static std::shared_ptr< Font > alloc(const char *file, int size)
Definition: CUFont.h:361
void setStyle(Style style)
int computeKerning(Uint32 a, Uint32 b) const
Size getSize(const char *text, bool utf8=true) const
Definition: CUFont.h:721
const Metrics getMetrics(char thechar) const
Definition: CUFont.h:619
bool _fixedWidth
Definition: CUFont.h:244
std::shared_ptr< Texture > getQuads(const char *text, const Vec2 &origin, const Rect &rect, std::vector< Vertex2 > &vertices, bool utf8=true)
Definition: CUFont.h:1111
Rect getInternalBoundsASCII(const std::string &text) const
Metrics computeMetrics(Uint32 thechar) const
std::shared_ptr< Texture > getQuads(const char *text, const Vec2 &origin, std::vector< Vertex2 > &vertices, bool utf8=true)
Definition: CUFont.h:1031
int miny
Definition: CUFont.h:116
int getLineSkip() const
Definition: CUFont.h:426
bool buildAtlas()
Definition: CUFont.h:825
bool buildAtlas(const std::string &charset)
Definition: CUFont.h:849
std::unordered_map< Uint32, Metrics > _glyphsize
Definition: CUFont.h:264
int getDescent() const
Definition: CUFont.h:407
~Font()
Definition: CUFont.h:287
SDL_Surface * _surface
Definition: CUFont.h:270
int getHeight() const
Definition: CUFont.h:397
Size getSizeUTF8(const std::string &text) const
std::string _stylename
Definition: CUFont.h:227
std::shared_ptr< Texture > getRenderedQuad(Uint32 thechar, Vec2 &offset, const Rect &rect, std::vector< Vertex2 > &vertices)
Style getStyle() const
Definition: CUFont.h:536
Resolution
Definition: CUFont.h:187
std::shared_ptr< Texture > getQuads(const std::string &text, const Vec2 &origin, std::vector< Vertex2 > &vertices, bool utf8=true)
bool hasGlyph(char a) const
Definition: CUFont.h:474
bool _useKerning
Definition: CUFont.h:246
int maxx
Definition: CUFont.h:114
bool buildAtlas(const char *charset)
Definition: CUFont.h:873
bool usesKerning() const
Definition: CUFont.h:450
Resolution _render
Definition: CUFont.h:254
unsigned int _fontAscent
Definition: CUFont.h:240
bool hasAtlas() const
Definition: CUFont.h:960
int advance
Definition: CUFont.h:120
const std::string & getName() const
Definition: CUFont.h:376
Hinting getHinting() const
Definition: CUFont.h:562
unsigned int _fontDescent
Definition: CUFont.h:238
const std::string & getStyleName() const
Definition: CUFont.h:386
std::shared_ptr< Texture > getRenderedQuads(const std::string &text, const Vec2 &origin, const Rect &rect, std::vector< Vertex2 > &vertices, bool utf8)
SDL_Surface * allocSurface(int width, int height)
std::shared_ptr< Texture > _texture
Definition: CUFont.h:268
static std::shared_ptr< Font > alloc(const std::string &file, int size)
Definition: CUFont.h:344
Rect getInternalBounds(const std::string &text, bool utf8=true) const
unsigned int _fontHeight
Definition: CUFont.h:236
int maxy
Definition: CUFont.h:118
std::vector< std::vector< Uint32 > > planAtlas(int width, int height)
unsigned int getKerning(char a, char b) const
Definition: CUFont.h:651
bool hasString(const std::string &text) const
bool init(const char *file, int size)
Definition: CUFont.h:325
void setResolution(Resolution resolution)
Definition: CUFont.h:603
Resolution getResolution() const
Definition: CUFont.h:588
std::vector< Uint32 > _glyphset
Definition: CUFont.h:260
std::unordered_map< Uint32, std::unordered_map< Uint32, Uint32 > > _kernmap
Definition: CUFont.h:266
Style _style
Definition: CUFont.h:250
Style
Definition: CUFont.h:134
std::unordered_map< Uint32, Rect > _glyphmap
Definition: CUFont.h:262
void getAtlasQuads(const std::string &text, const Vec2 &origin, const Rect &rect, std::vector< Vertex2 > &vertices, bool utf8)
bool generateSurface(int width, int height)
void setHinting(Hinting hinting)
Size getSizeASCII(const std::string &text) const
Size getSize(const std::string &text, bool utf8=true) const
std::string _name
Definition: CUFont.h:225
void layoutAtlas(const std::vector< std::vector< Uint32 > > &rectangle)