16 atlas_size_(
ISize(0, 0)) {}
29 return height_adjustment_;
38 int64_t height_adjustment) {
39 atlas_ = std::move(atlas);
41 height_adjustment_ = height_adjustment;
45 std::shared_ptr<RectanglePacker> rect_packer) {
46 rect_packer_ = std::move(rect_packer);
50 : type_(
type), generation_(initial_generation) {}
67 texture_ = std::move(texture);
75 generation_ = generation;
81 FontAtlasMap::iterator it = font_atlas_map_.find(pair.
scaled_font);
82 FML_DCHECK(it != font_atlas_map_.end());
83 it->second.positions_[pair.
glyph] =
89 const auto& found = font_atlas_map_.find(pair.
scaled_font);
90 if (found == font_atlas_map_.end()) {
93 return found->second.FindGlyphBounds(pair.
glyph);
98 auto [iter, inserted] =
100 return &iter->second;
104 return std::accumulate(font_atlas_map_.begin(), font_atlas_map_.end(), 0,
105 [](
const int a,
const auto&
b) {
106 return a + b.second.positions_.size();
111 const std::function<
bool(
const ScaledFont& scaled_font,
113 const Rect& rect)>& iterator)
const {
119 for (
const auto& font_value : font_atlas_map_) {
120 for (
const auto& glyph_value : font_value.second.positions_) {
122 if (!iterator(font_value.first, glyph_value.first,
123 glyph_value.second.atlas_bounds)) {
133 const auto& found = positions_.find(glyph);
134 if (found == positions_.end()) {
137 return found->second;
142 positions_[glyph] = frame_bounds;
An object that can look up glyph locations within the GlyphAtlas for a particular typeface.
void AppendGlyph(const SubpixelGlyph &glyph, const FrameBounds &frame_bounds)
Append the frame bounds of a glyph to this atlas.
std::optional< FrameBounds > FindGlyphBounds(const SubpixelGlyph &glyph) const
Find the location of a glyph in the atlas.
GlyphAtlasContext(GlyphAtlas::Type type)
std::shared_ptr< RectanglePacker > GetRectPacker() const
Retrieve the previous (if any) rect packer.
void UpdateRectPacker(std::shared_ptr< RectanglePacker > rect_packer)
std::shared_ptr< GlyphAtlas > GetGlyphAtlas() const
Retrieve the current glyph atlas.
const ISize & GetAtlasSize() const
Retrieve the size of the current glyph atlas.
int64_t GetHeightAdjustment() const
A y-coordinate shift that must be applied to glyphs appended to the atlas.
virtual ~GlyphAtlasContext()
void UpdateGlyphAtlas(std::shared_ptr< GlyphAtlas > atlas, ISize size, int64_t height_adjustment_)
Update the context with a newly constructed glyph atlas.
A texture containing the bitmap representation of glyphs in different fonts along with the ability to...
std::optional< FrameBounds > FindFontGlyphBounds(const FontGlyphPair &pair) const
Find the location of a specific font-glyph pair in the atlas.
void SetTexture(std::shared_ptr< Texture > texture)
Set the texture for the glyph atlas.
void SetAtlasGeneration(size_t value)
Update the atlas generation.
FontGlyphAtlas * GetOrCreateFontGlyphAtlas(const ScaledFont &scaled_font)
Obtain an interface for querying the location of glyphs in the atlas for the given font and scale....
Type
Describes how the glyphs are represented in the texture.
size_t GetAtlasGeneration() const
Retrieve the generation id for this glyph atlas.
Type GetType() const
Describes how the glyphs are represented in the texture.
const std::shared_ptr< Texture > & GetTexture() const
Get the texture for the glyph atlas.
GlyphAtlas(Type type, size_t initial_generation)
Create an empty glyph atlas.
size_t IterateGlyphs(const std::function< bool(const ScaledFont &scaled_font, const SubpixelGlyph &glyph, const Rect &rect)> &iterator) const
Iterate of all the glyphs along with their locations in the atlas.
void AddTypefaceGlyphPositionAndBounds(const FontGlyphPair &pair, Rect position, Rect bounds)
Record the location of a specific font-glyph pair within the atlas.
size_t GetGlyphCount() const
Get the number of unique font-glyph pairs in this atlas.
A font along with a glyph in that font rendered at a particular scale and subpixel position.
A font and a scale. Used as a key that represents a typeface within a glyph atlas.
A glyph and its subpixel position.