15 #include <unordered_map> 35 std::unordered_map<char32_t, ConstBppImageSptr>
glyphs;
71 static std::shared_ptr<BppFont>
make() {
72 return std::make_shared<BppFont>();
78 static std::shared_ptr<BppFont>
make(
const std::string &path) {
79 return std::make_shared<BppFont>(path);
85 static std::shared_ptr<BppFont>
make(std::istream &is) {
86 return std::make_shared<BppFont>(is);
106 void load(
const std::string &path);
121 void load(std::istream &is);
244 const std::string &text,
258 const std::u32string &text,
267 #endif // #ifndef BPPFONT_HPP static std::shared_ptr< BppFont > make(std::istream &is)
Returns a shared pointer to a new BppFont object constructed using the BppFont(std::istream &) constr...
BppFont(std::istream &is)
Loads glyphs from an input stream.
void add(char32_t gc, const ConstBppImageSptr &img)
Adds or replaces a glyph in the font.
ImageDimensions lineDimensions(const std::string &text, Flags flags=Flags::Zero())
Returns the dimensions of a single-line string without the overhead of rendering the string...
ConstBppImageSptr tryGet(char32_t gc)
Returns the glyph of the specified character code.
std::shared_ptr< BppFont > BppFontSptr
static constexpr Flags AlignRight
Align each line to the right.
std::shared_ptr< const BppImage > ConstBppImageSptr
static constexpr BitFlags Zero()
Makes a bit flags container with all flags cleared.
static constexpr Flags AlignMask
All alignment flags.
static constexpr Flags AlignCenter
Center each line in the resulting image.
Stores the dimensions of an image.
static constexpr Flags FixedWidthPerLine
Compute fixed width individually for each line, so each line may have a different width per glyph...
static constexpr BitFlags Bit(int b)
Makes a bit flags container with a single bit set that is specified by digit number rather than value...
static constexpr Flags FixedWidth
All glyphs rendered with the same width using the maximum width of the glyphs used in the string...
std::shared_ptr< BppImage > BppImageSptr
static std::shared_ptr< BppFont > make()
Returns a shared pointer to a new BppFont object.
duds::general::Spinlock block
Used for thread safety.
virtual ConstBppImageSptr renderGlyph(char32_t gc)
Called to render the requested glyph when it is not present in the glyphs map.
static constexpr Flags VariableHeight
Each line will have the height of its tallest glyph rather than the tallest glyph of the entire strin...
ImageDimensions estimatedMaxCharacterSize()
Returns a somewhat decent estimate of the largest size of a character without actually inspecting all...
A simple spinlock following the lockable and timed lockable concepts so that it can be used with std:...
BppFont(const std::string &path)
Loads glyphs from an image archive in the specified file.
duds::general::BitFlags< struct BppFontRenderingFlags > Flags
Option flags that affect how text is rendered.
void load(const std::string &path)
Loads glyphs from an image archive in the specified file.
General graphics related code.
static constexpr Flags AlignLeft
Align each line to the left.
BppImageSptr render(const std::string &text, Flags flags=AlignLeft)
Renders the given text using this object's font.
std::unordered_map< char32_t, ConstBppImageSptr > glyphs
The glyph images keyed by character.
static std::shared_ptr< BppFont > make(const std::string &path)
Returns a shared pointer to a new BppFont object constructed using the BppFont(const std::string &) c...
Renders strings using a font made of BppImage objects for glyphs.