|
DUDS
|
Distributed Update of Data from Something
|
Renders strings using a font made of BppImage objects for glyphs. More...
#include <BppFont.hpp>
Public Types | |
| typedef duds::general::BitFlags< struct BppFontRenderingFlags > | Flags |
| Option flags that affect how text is rendered. More... | |
Public Member Functions | |
| BppFont ()=default | |
| BppFont (const std::string &path) | |
| Loads glyphs from an image archive in the specified file. More... | |
| BppFont (std::istream &is) | |
| Loads glyphs from an input stream. More... | |
| void | add (char32_t gc, const ConstBppImageSptr &img) |
| Adds or replaces a glyph in the font. More... | |
| void | add (char32_t gc, ConstBppImageSptr &&img) |
| Adds or replaces a glyph in the font. More... | |
| ImageDimensions | estimatedMaxCharacterSize () |
| Returns a somewhat decent estimate of the largest size of a character without actually inspecting all characters. More... | |
| const ConstBppImageSptr & | get (char32_t gc) |
| Returns the glyph of the specified character code. More... | |
| 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. More... | |
| ImageDimensions | lineDimensions (const std::u32string &text, Flags flags=Flags::Zero()) |
| Returns the dimensions of a single-line string without the overhead of rendering the string. More... | |
| void | load (const std::string &path) |
| Loads glyphs from an image archive in the specified file. More... | |
| void | load (std::istream &is) |
| Loads glyphs from an input stream. More... | |
| BppImageSptr | render (const std::string &text, Flags flags=AlignLeft) |
| Renders the given text using this object's font. More... | |
| BppImageSptr | render (const std::u32string &text, Flags flags=AlignLeft) |
| Renders the given text using this object's font. More... | |
| ConstBppImageSptr | tryGet (char32_t gc) |
| Returns the glyph of the specified character code. More... | |
Static Public Member Functions | |
| static std::shared_ptr< BppFont > | make () |
| Returns a shared pointer to a new BppFont object. More... | |
| 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 &) constructor. More... | |
| static std::shared_ptr< BppFont > | make (std::istream &is) |
| Returns a shared pointer to a new BppFont object constructed using the BppFont(std::istream &) constructor. More... | |
Static Public Attributes | |
| static constexpr Flags | AlignCenter = Flags::Bit(3) |
| Center each line in the resulting image. More... | |
| static constexpr Flags | AlignLeft = Flags::Zero() |
| Align each line to the left. More... | |
| static constexpr Flags | AlignMask = AlignCenter | AlignRight |
| All alignment flags. More... | |
| static constexpr Flags | AlignRight = Flags::Bit(4) |
| Align each line to the right. More... | |
| static constexpr Flags | FixedWidth = Flags::Bit(0) |
| All glyphs rendered with the same width using the maximum width of the glyphs used in the string. More... | |
| static constexpr Flags | FixedWidthPerLine = Flags::Bit(1) |
| Compute fixed width individually for each line, so each line may have a different width per glyph. More... | |
| static constexpr Flags | VariableHeight = Flags::Bit(2) |
| Each line will have the height of its tallest glyph rather than the tallest glyph of the entire string. More... | |
Protected Member Functions | |
| virtual ConstBppImageSptr | renderGlyph (char32_t gc) |
| Called to render the requested glyph when it is not present in the glyphs map. More... | |
Protected Attributes | |
| duds::general::Spinlock | block |
| Used for thread safety. More... | |
| std::unordered_map< char32_t, ConstBppImageSptr > | glyphs |
| The glyph images keyed by character. More... | |
Renders strings using a font made of BppImage objects for glyphs.
The glyph images may come from a BppImage archive file or stream, may be provided using the add() function, or can be generated in a renderGlyph() function implemented by a derived class. A cache of glyph images is maintained by this base class. The renderGlyph() function is called whenever a glyph is requested but not already in the cache of glyph images.
Definition at line 30 of file BppFont.hpp.
| typedef duds::general::BitFlags<struct BppFontRenderingFlags> duds::ui::graphics::BppFont::Flags |
Option flags that affect how text is rendered.
Definition at line 165 of file BppFont.hpp.
|
default |
|
inline |
Loads glyphs from an image archive in the specified file.
The glyphs from the archive will augment what is already stored in this object, and will replace glyphs if there is a collision.
| path | The path of the archive file to load. |
| ImageArchiveStreamError | Failed to open the file. |
| ImageNotArchiveStreamError | The stream does not have an image archive stream. |
| ImageArchiveStreamTruncatedError | The stream appears to have an incomplete copy of the archive stream. Any images fully read prior to the error will be available. |
| ImageArchiveUnsupportedVersionError | The software does not support the claimed archive version. |
Definition at line 59 of file BppFont.hpp.
|
inline |
Loads glyphs from an input stream.
The glyphs from the archive stream will augment what is already stored in this object, and will replace glyphs if there is a collision.
| is | The input stream that will provide the image archive. |
| ImageNotArchiveStreamError | The stream does not have an image archive stream. |
| ImageArchiveStreamTruncatedError | The stream appears to have an incomplete copy of the archive stream. Any images fully read prior to the error will be available. |
| ImageArchiveUnsupportedVersionError | The software does not support the claimed archive version. |
Definition at line 65 of file BppFont.hpp.
| void duds::ui::graphics::BppFont::add | ( | char32_t | gc, |
| const ConstBppImageSptr & | img | ||
| ) |
Adds or replaces a glyph in the font.
| gc | The character code of the glyph. |
| img | The image to store. |
Definition at line 78 of file BppFont.cpp.
Referenced by make().
| void duds::ui::graphics::BppFont::add | ( | char32_t | gc, |
| ConstBppImageSptr && | img | ||
| ) |
Adds or replaces a glyph in the font.
| gc | The character code of the glyph. |
| img | The image to store. The shared pointer will be moved. |
Definition at line 83 of file BppFont.cpp.
| ImageDimensions duds::ui::graphics::BppFont::estimatedMaxCharacterSize | ( | ) |
Returns a somewhat decent estimate of the largest size of a character without actually inspecting all characters.
If the result is zero, the estimation failed.
Definition at line 115 of file BppFont.cpp.
Referenced by make().
| const ConstBppImageSptr & duds::ui::graphics::BppFont::get | ( | char32_t | gc | ) |
Returns the glyph of the specified character code.
The returned reference is to the internally stored shared pointer rather than a new shared pointer. This makes get() prefered over tryGet() unless it is uncertain if the requested glyph exists in the font.
| gc | The character code of the glyph. |
| GlyphNotFoundError | The glyph is not provided by the font. |
Definition at line 88 of file BppFont.cpp.
| ImageDimensions duds::ui::graphics::BppFont::lineDimensions | ( | const std::string & | text, |
| Flags | flags = Flags::Zero() |
||
| ) |
Returns the dimensions of a single-line string without the overhead of rendering the string.
| text | The text to consider in a UTF-8 string. |
| flags | Either zero, for a potentially variable width, or FixedWidth to produce a width where each glyph is the width of the widest glyph in the text. |
| GlyphNotFoundError | A glyph in text is not provided by the font. |
Definition at line 317 of file BppFont.cpp.
| ImageDimensions duds::ui::graphics::BppFont::lineDimensions | ( | const std::u32string & | text, |
| Flags | flags = Flags::Zero() |
||
| ) |
Returns the dimensions of a single-line string without the overhead of rendering the string.
| text | The text to consider. |
| flags | Either zero, for a potentially variable width, or FixedWidth to produce a width where each glyph is the width of the widest glyph in the text. |
| GlyphNotFoundError | A glyph in text is not provided by the font. |
Definition at line 323 of file BppFont.cpp.
| void duds::ui::graphics::BppFont::load | ( | const std::string & | path | ) |
Loads glyphs from an image archive in the specified file.
The glyphs from the archive will augment what is already stored in this object, and will replace glyphs if there is a collision.
| path | The path of the archive file to load. |
| ImageArchiveStreamError | Failed to open the file. |
| ImageNotArchiveStreamError | The stream does not have an image archive stream. |
| ImageArchiveStreamTruncatedError | The stream appears to have an incomplete copy of the archive stream. Any images fully read prior to the error will be available. |
| ImageArchiveUnsupportedVersionError | The software does not support the claimed archive version. |
Definition at line 40 of file BppFont.cpp.
| void duds::ui::graphics::BppFont::load | ( | std::istream & | is | ) |
Loads glyphs from an input stream.
The glyphs from the archive stream will augment what is already stored in this object, and will replace glyphs if there is a collision.
| is | The input stream that will provide the image archive. |
| ImageNotArchiveStreamError | The stream does not have an image archive stream. |
| ImageArchiveStreamTruncatedError | The stream appears to have an incomplete copy of the archive stream. Any images fully read prior to the error will be available. |
| ImageArchiveUnsupportedVersionError | The software does not support the claimed archive version. |
Definition at line 56 of file BppFont.cpp.
|
inlinestatic |
Returns a shared pointer to a new BppFont object.
Definition at line 71 of file BppFont.hpp.
Referenced by duds::ui::graphics::BppFontPool::addWithCache(), duds::ui::graphics::BppFontPool::addWithoutCache(), and duds::ui::graphics::BppStringCache::make().
|
inlinestatic |
Returns a shared pointer to a new BppFont object constructed using the BppFont(const std::string &) constructor.
Definition at line 78 of file BppFont.hpp.
|
inlinestatic |
Returns a shared pointer to a new BppFont object constructed using the BppFont(std::istream &) constructor.
Definition at line 85 of file BppFont.hpp.
| BppImageSptr duds::ui::graphics::BppFont::render | ( | const std::string & | text, |
| Flags | flags = AlignLeft |
||
| ) |
Renders the given text using this object's font.
The newline character can be used to denote the start of another line. Lines are only made explicitly.
Variable sized glyphs are supported. Glyphs are aligned vertically along their lower edge. This places shorter glyphs lower than taller ones.
| text | The text to render in a UTF-8 string. |
| flags | The option flags. The default is to render varying width, fixed height text with each line aligned to the left. |
| GlyphNotFoundError | A glyph in text is not provided by the font. |
Definition at line 167 of file BppFont.cpp.
| BppImageSptr duds::ui::graphics::BppFont::render | ( | const std::u32string & | text, |
| Flags | flags = AlignLeft |
||
| ) |
Renders the given text using this object's font.
The newline character can be used to denote the start of another line. Lines are only made explicitly.
Variable sized glyphs are supported. Glyphs are aligned vertically along their lower edge. This places shorter glyphs lower than taller ones.
| text | The text to render in a UTF-32 string. |
| flags | The option flags. The default is to render varying width, fixed height text with each line aligned to the left. |
| GlyphNotFoundError | A glyph in text is not provided by the font. |
Definition at line 173 of file BppFont.cpp.
|
protectedvirtual |
Called to render the requested glyph when it is not present in the glyphs map.
The base implementation will return the white square glyph (value 9633, 0x25A1) if the font has it, or it will throw GlyphNotFoundError along with a Character attribute. Implementors should either render the glyph and add it to the glyphs map, or call the base implementation.
| GlyphNotFoundError | The glyph is not provided by the font. |
| gc | The character code of the glyph. |
Definition at line 26 of file BppFont.cpp.
Referenced by get(), lineDimensions(), render(), and tryGet().
| ConstBppImageSptr duds::ui::graphics::BppFont::tryGet | ( | char32_t | gc | ) |
Returns the glyph of the specified character code.
| gc | The character code of the glyph. |
Definition at line 100 of file BppFont.cpp.
Referenced by estimatedMaxCharacterSize(), and make().
|
static |
Center each line in the resulting image.
Definition at line 188 of file BppFont.hpp.
Referenced by render().
|
static |
Align each line to the left.
This is the default.
Definition at line 184 of file BppFont.hpp.
Referenced by duds::ui::menu::renderers::BppMenuRenderer::render(), and duds::ui::graphics::BppStringCache::strings().
|
static |
All alignment flags.
Definition at line 196 of file BppFont.hpp.
|
static |
Align each line to the right.
Definition at line 192 of file BppFont.hpp.
Referenced by render(), and duds::ui::menu::renderers::BppMenuRenderer::render().
|
mutableprotected |
Used for thread safety.
Definition at line 39 of file BppFont.hpp.
Referenced by add(), estimatedMaxCharacterSize(), get(), lineDimensions(), load(), render(), and tryGet().
|
static |
All glyphs rendered with the same width using the maximum width of the glyphs used in the string.
Definition at line 170 of file BppFont.hpp.
Referenced by lineDimensions(), and render().
|
static |
Compute fixed width individually for each line, so each line may have a different width per glyph.
Takes precedence over FixedWidth.
Definition at line 175 of file BppFont.hpp.
Referenced by lineDimensions(), and render().
|
protected |
The glyph images keyed by character.
Definition at line 35 of file BppFont.hpp.
Referenced by add(), estimatedMaxCharacterSize(), get(), lineDimensions(), load(), render(), renderGlyph(), and tryGet().
|
static |
Each line will have the height of its tallest glyph rather than the tallest glyph of the entire string.
Definition at line 180 of file BppFont.hpp.
Referenced by render().