10 #ifndef BPPFONTPOOL_HPP 11 #define BPPFONTPOOL_HPP 34 std::unordered_map<std::string, FontAndCache>
fonts;
57 const std::string &name,
72 const std::string &name,
90 void addWithoutCache(
const std::string &name,
const std::string &fontpath);
106 void addWithCache(
const std::string &name,
const std::string &fontpath);
115 void alias(
const std::string &existing,
const std::string &newname);
143 template <
class String>
145 const std::string &font,
152 return fc.
fnt->render(str, flags);
153 }
catch (boost::exception &be) {
169 template <
class String>
171 const std::string &font,
179 return fc.
sc->text(str, flags);
181 return fc.
fnt->render(str, flags);
182 }
catch (boost::exception &be) {
191 #endif // #ifndef BPPFONTPOOL_HPP std::shared_ptr< BppStringCache > BppStringCacheSptr
A std::shared_ptr to a BppStringCache object.
std::shared_ptr< BppFont > BppFontSptr
std::shared_ptr< const BppImage > ConstBppImageSptr
void addWithoutCache(const std::string &name, const BppFontSptr &font)
Adds an existing font without a corresponding string cache.
Handles a pool of fonts and their associated string caches to make it easier to use fonts across vari...
void alias(const std::string &existing, const std::string &newname)
Adds a new name for an already added font.
BppFontSptr getFont(const std::string &font) const
Returns a shared pointer to a stored font, or an empty shared pointer if the font is not present...
void getFc(FontAndCache &fc, const std::string &font) const
An internal function to get a FontAndCache struct for the given font.
BppImageSptr render(const std::string &font, const String &str, BppFont::Flags flags=BppFont::AlignLeft) const
Renders text without going through a string cache.
std::unordered_map< std::string, FontAndCache > fonts
The glyph images keyed by character.
boost::error_info< struct Info_String, std::string > String
A string, like one requested for rendering in a specific font.
std::shared_ptr< BppImage > BppImageSptr
ConstBppImageSptr text(const std::string &font, const String &str, BppFont::Flags flags=BppFont::AlignLeft) const
Gets text from a string cache if present, or renders from the font otherwise.
void addWithCache(const std::string &name, const BppFontSptr &font)
Adds an existing font along with a newly created corresponding string cache.
duds::general::Spinlock block
Used for thread safety.
Internal struct to hold a font and its string cache.
void add(const std::string &name, const BppFontSptr &font, const BppStringCacheSptr &cache)
Adds an existing font and string cache pair to the pool.
A simple spinlock following the lockable and timed lockable concepts so that it can be used with std:...
General graphics related code.
static constexpr Flags AlignLeft
Align each line to the left.
boost::error_info< struct Info_FontName, std::string > FontName
The name of the font and is not present in the font pool.
BppStringCacheSptr getStringCache(const std::string &font) const
Returns a shared pointer to a string cache, or an empty shared pointer if the font is not present...