35 : pixels(width, height), is_sdf(false) {}
38 return pixels.GetWidth() * pixels.GetHeight() == 0;
41 Font::Font(
const std::string&
name,
size_t size_in_pixels,
size_t sdf_padding)
44 sdf_padding_(sdf_padding),
45 glyph_grid_map_(*this) {}
52 mutable_grid ? *mutable_grid : base::InvalidReference<Font::GlyphGrid>();
65 const auto& it = glyph_grid_map_.find(glyph_index);
66 if (it == glyph_grid_map_.end()) {
69 glyph_grid_map_[glyph_index] = glyph;
70 return &glyph_grid_map_[glyph_index];
86 return glyph_grid_map_[glyph_index] = glyph;
92 font_metrics_ = metrics;
99 for (
auto it = glyph_set.cbegin(); it != glyph_set.cend(); ++it) {
103 if (!glyph_grid->
is_sdf) {
114 LOG(
ERROR) <<
"Invalid glyph passed to SetSdfGrid";
115 }
else if (grid->
is_sdf) {
116 LOG(
ERROR) <<
"Grid is already an SDF grid";
118 grid->
pixels = sdf_pixels;
127 for (
auto it = glyph_set->begin(); it != glyph_set->end();) {
130 glyph_set->erase(it++);
141 DCHECK_GE(start, static_cast<CharIndex>(1));
142 DCHECK_LE(finish, static_cast<CharIndex>(127));
143 for (
auto i = start; i <= finish; ++i) {
146 glyphs->insert(glyph_index);
bool IsInvalidReference(const T &value)
IsInvalidReference() returns true if a passed const reference of type T has an address of InvalidRefe...
bool CacheSdfGrid(GlyphIndex glyph_index, const base::Array2< double > &sdf_pixels)
Replaces the grid in a glyph with an SDF grid.
size_t GetSdfPadding() const
Returns the padding value used when generating SDF glyphs from the font.
const size_t size_in_pixels_
Size in pixels.
void SetFontMetrics(const FontMetrics &metrics)
Sets FontMetrics. SetFontMetrics() should only ever be called once.
const GlyphGrid & GetGlyphGrid(GlyphIndex glyph_index) const
Returns the GlyphGrid for the indexed character.
float line_advance_height
Nominal font-wide line-advance height, in pixels.
#define LOG(severity)
Logs the streamed message unconditionally with a severity of severity.
bool is_sdf
When a Font is set up for rendering, the pixels are replaced with a signed-distance field (SDF)...
bool IsLocked()
Returns whether the Mutex is currently locked. Does not block.
uint32 CharIndex
Typedef for a Unicode index of a character.
void FilterGlyphs(GlyphSet *glyph_set)
Filter zero-size glyphs from glyph_set.
A LockGuard locks a mutex when created, and unlocks it when destroyed.
virtual GlyphIndex GetDefaultGlyphForChar(CharIndex char_index) const =0
Returns the index of a glyph corresponding to the given character in the default ("unicode", in practice) charmap of the font.
bool IsZeroSize() const
Returns true if glyph x- or y-size is zero.
base::Array2< double > pixels
~Font() override
The destructor is protected because all base::Referent classes must have protected or private destruc...
#define DCHECK_GE(val1, val2)
const GlyphGrid & AddGlyph(GlyphIndex glyph_index, const GlyphGrid &glyph) const
Adds a GlyphGrid to the GlyphMap.
void AddGlyphsForAsciiCharacterRange(ion::text::CharIndex start, ion::text::CharIndex finish, ion::text::GlyphSet *glyphs)
For each character in [start,finish] adds the default glyph from font to glyphs.
Copyright 2016 Google Inc.
#define DCHECK_EQ(val1, val2)
#define DCHECK_LE(val1, val2)
void CacheSdfGrids(const GlyphSet &glyph_set)
Makes sure that the GlyphData for each glyph in glyph_set has an SDF grid cached inside the font...
GlyphGrid * GetMutableGlyphGrid(GlyphIndex glyph_index) const
Non-const version of GetGlyphGrid.
const Grid ComputeSdfGrid(const Grid &image_grid, size_t padding)
Public SDF utility functions.
virtual bool LoadGlyphGrid(GlyphIndex glyph_index, GlyphGrid *glyph_grid) const
Called by GetGlyphGrid() for missing glyphs.
GlyphGrid * GetMutableGlyphGridLocked(GlyphIndex glyph_index) const
Prelocked version of GetMutableGlyphGrid.
A grid representing a rendered glyph, with each grid pixel representing pixel coverage in the range (...
This struct represents the cumulative metrics for the font.
Font(const std::string &name, size_t size_in_pixels, size_t sdf_padding)
The constructor is protected because this is an abstract base class.