Ion
|
Font is a base class for implementation-specific representations of fonts. More...
#include "font.h"
Classes | |
struct | FontMetrics |
This struct represents the cumulative metrics for the font. More... | |
struct | GlyphGrid |
A grid representing a rendered glyph, with each grid pixel representing pixel coverage in the range (0,1). More... | |
Public Member Functions | |
const std::string & | GetName () const |
Returns the name of the font. More... | |
size_t | GetSizeInPixels () const |
Returns the size of the font in pixels. More... | |
size_t | GetSdfPadding () const |
Returns the padding value used when generating SDF glyphs from the font. More... | |
const FontMetrics & | GetFontMetrics () const |
Returns the FontMetrics for the font. More... | |
const GlyphGrid & | GetGlyphGrid (GlyphIndex glyph_index) const |
Returns the GlyphGrid for the indexed character. More... | |
void | FilterGlyphs (GlyphSet *glyph_set) |
Filter zero-size glyphs from glyph_set . More... | |
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. More... | |
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 . More... | |
virtual const Layout | BuildLayout (const std::string &text, const LayoutOptions &options) const =0 |
Creates a layout as specified by options for a given single- or multi- line string text . More... | |
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. More... | |
virtual void | AddFallbackFont (const FontPtr &fallback)=0 |
Causes this font to use the font fallback as a fallback if a requested glyph is not found. More... | |
const AllocatorPtr & | GetAllocator () const |
Returns the Allocator that was used for the instance. More... | |
const AllocatorPtr & | GetNonNullAllocator () const |
Return our allocator, or the default allocator if the instance was declared on the stack. More... | |
const AllocatorPtr & | GetAllocatorForLifetime (AllocationLifetime lifetime) const |
Convenience function that returns the Allocator to use to allocate an object with a specific lifetime. More... | |
void * | operator new (size_t size) |
The standard no-parameter new operator uses the default Allocator. More... | |
void * | operator new (size_t size, AllocationLifetime lifetime) |
This overloaded version of the new operator uses the AllocationManager's default Allocator for the specified lifetime. More... | |
void * | operator new (size_t size, const AllocatorPtr &allocator) |
This overloaded version of the new operator takes the Allocator to use directly as a parameter. More... | |
void * | operator new (size_t size, const AllocatorPtr &allocator, void *ptr) |
Special operator new for using placement new with Allocatables. More... | |
void * | operator new (size_t size, void *ptr) |
The placement new operator is defined conventionally. More... | |
void | operator delete (void *ptr) |
Define the delete operator to use specialized functions dealing with an Allocator. More... | |
void | operator delete (void *ptr, AllocationLifetime lifetime) |
Windows requires these (or it issues C4291 warnings). More... | |
void | operator delete (void *ptr, const AllocatorPtr &allocator) |
void | operator delete (void *ptr, void *ptr2) |
The placement delete operator does nothing, as usual. More... | |
int | GetRefCount () const |
GetRefCount() is part of the interface necessary for SharedPtr. More... | |
Protected Types | |
typedef base::AllocMap < GlyphIndex, GlyphGrid > | GlyphMap |
Convenience typedef for the map storing GlyphGrid instances. More... | |
Protected Member Functions | |
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. More... | |
~Font () override | |
The destructor is protected because all base::Referent classes must have protected or private destructors. More... | |
GlyphGrid * | GetMutableGlyphGrid (GlyphIndex glyph_index) const |
Non-const version of GetGlyphGrid. More... | |
GlyphGrid * | GetMutableGlyphGridLocked (GlyphIndex glyph_index) const |
Prelocked version of GetMutableGlyphGrid. More... | |
virtual bool | LoadGlyphGrid (GlyphIndex glyph_index, GlyphGrid *glyph_grid) const |
Called by GetGlyphGrid() for missing glyphs. More... | |
const GlyphGrid & | AddGlyph (GlyphIndex glyph_index, const GlyphGrid &glyph) const |
Adds a GlyphGrid to the GlyphMap. More... | |
void | SetFontMetrics (const FontMetrics &metrics) |
Sets FontMetrics. SetFontMetrics() should only ever be called once. More... | |
bool | CacheSdfGrid (GlyphIndex glyph_index, const base::Array2< double > &sdf_pixels) |
Replaces the grid in a glyph with an SDF grid. More... | |
Protected Attributes | |
const size_t | size_in_pixels_ |
Size in pixels. More... | |
Font is a base class for implementation-specific representations of fonts.
It contains font metrics, glyph metrics, and rendered glyph grids.
|
protected |
|
overrideprotected |
The destructor is protected because all base::Referent classes must have protected or private destructors.
|
pure virtual |
Causes this font to use the font fallback
as a fallback if a requested glyph is not found.
This is useful in internationalization cases, as few fonts contain glyphs for enough unicode codepoints to satisfy most languages.
Implemented in ion::text::FreeTypeFont, and ion::text::CoreTextFont.
|
protected |
Adds a GlyphGrid to the GlyphMap.
Definition at line 81 of file font.cc.
References ion::base::IsInvalidReference().
void ion::text::Font::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
.
Since this is not well-defined for all of Unicode, enforces that [start,finish] lies within [1,127], where the character->glyph mapping is simple enough.
Definition at line 137 of file font.cc.
References DCHECK_GE, DCHECK_LE, and GetDefaultGlyphForChar().
|
pure virtual |
Creates a layout as specified by options
for a given single- or multi- line string text
.
Implemented in ion::text::FreeTypeFont, and ion::text::CoreTextFont.
|
protected |
Replaces the grid in a glyph with an SDF grid.
This is used to cache the SDF grid, since it is relatively expensive to compute. Logs an error and returns false on error.
Definition at line 110 of file font.cc.
References ion::port::ERROR, GetMutableGlyphGrid(), ion::text::Font::GlyphGrid::is_sdf, LOG, and ion::text::Font::GlyphGrid::pixels.
Referenced by CacheSdfGrids().
void ion::text::Font::CacheSdfGrids | ( | const GlyphSet & | glyph_set | ) |
Makes sure that the GlyphData for each glyph in glyph_set has an SDF grid cached inside the font.
This assumes that the requested glyphs are available in the font. There is no real need to call this outside of Ion's internal code.
Definition at line 95 of file font.cc.
References CacheSdfGrid(), ion::text::ComputeSdfGrid(), DCHECK, GetMutableGlyphGrid(), GetSdfPadding(), ion::text::Font::GlyphGrid::is_sdf, ion::base::IsInvalidReference(), and ion::text::Font::GlyphGrid::pixels.
void ion::text::Font::FilterGlyphs | ( | GlyphSet * | glyph_set | ) |
Filter zero-size glyphs from glyph_set
.
Definition at line 125 of file font.cc.
References GetMutableGlyphGridLocked(), and ion::text::Font::GlyphGrid::IsZeroSize().
|
inlineinherited |
Returns the Allocator that was used for the instance.
This will be NULL if the instance was declared on the stack or created with normal placement new.
Definition at line 68 of file allocatable.h.
References allocator_.
Referenced by ion::base::DataContainer::CreateAndCopy(), ion::text::DynamicFontImage::FindContainingImageDataIndex(), and ion::text::DynamicFontImage::FindImageDataIndex().
|
inlineinherited |
Convenience function that returns the Allocator to use to allocate an object with a specific lifetime.
Definition at line 78 of file allocatable.h.
References ion::base::Allocator::GetAllocatorForLifetime().
Referenced by ion::text::BasicBuilder::BuildVertexData(), ion::text::OutlineBuilder::BuildVertexData(), ion::gfxutils::ShaderManager::CreateShaderProgram(), ion::text::DynamicFontImage::FindContainingImageDataIndex(), ion::text::DynamicFontImage::FindImageDataIndex(), ion::gfx::Renderer::Renderer(), and ion::gfx::UpdateStateTable().
|
pure virtual |
Returns the index of a glyph corresponding to the given character in the default ("unicode", in practice) charmap of the font.
Note that this is an ill-defined concept, as a character may well require multiple glyphs to render, or require different glyphs in different contexts, and so on. This and AddGlyphsForAsciiCharacterRange are therefore intended as a quick and dirty way to prepopulate a font with glyps so that a static FontImage can be used, and cannot be assumed to work on non-trivial (i.e., non-latin) characters. Returns zero if no glyph available.
Implemented in ion::text::FreeTypeFont, and ion::text::CoreTextFont.
Referenced by AddGlyphsForAsciiCharacterRange().
|
inline |
Returns the FontMetrics for the font.
Definition at line 87 of file font.h.
Referenced by ion::text::ComputeTextSize().
const Font::GlyphGrid & ion::text::Font::GetGlyphGrid | ( | GlyphIndex | glyph_index | ) | const |
Returns the GlyphGrid for the indexed character.
Returns an invalid reference if the index does not refer to a glyph in the font.
Definition at line 49 of file font.cc.
References GetMutableGlyphGrid().
|
protected |
Non-const version of GetGlyphGrid.
Definition at line 55 of file font.cc.
References GetMutableGlyphGridLocked().
Referenced by CacheSdfGrid(), CacheSdfGrids(), and GetGlyphGrid().
|
protected |
Prelocked version of GetMutableGlyphGrid.
Definition at line 60 of file font.cc.
References DCHECK, ion::port::Mutex::IsLocked(), and LoadGlyphGrid().
Referenced by FilterGlyphs(), and GetMutableGlyphGrid().
|
inline |
|
inlineinherited |
Return our allocator, or the default allocator if the instance was declared on the stack.
Definition at line 72 of file allocatable.h.
References allocator_, and ion::base::AllocationManager::GetNonNullAllocator().
|
inlineinherited |
GetRefCount() is part of the interface necessary for SharedPtr.
Definition at line 34 of file shareable.h.
Referenced by ion::base::Notifier::RemoveReceiver().
|
inline |
Returns the padding value used when generating SDF glyphs from the font.
Most SDF glyphs are larger than the original glyph so that the outer edges have a nice distance fall-off. The SDF glyph grids are padded by this many pixels on all sides.
Definition at line 84 of file font.h.
Referenced by CacheSdfGrids(), ion::text::BasicBuilder::UpdateUniforms(), and ion::text::OutlineBuilder::UpdateUniforms().
|
inline |
Returns the size of the font in pixels.
Definition at line 78 of file font.h.
Referenced by ion::text::ComputeTextSize().
|
protectedvirtual |
Called by GetGlyphGrid() for missing glyphs.
Child classes that load glyphs on-demand should override this method to load the result into glyph_grid. Returns true if a glyph was loaded.
Reimplemented in ion::text::FreeTypeFont, and ion::text::CoreTextFont.
Definition at line 77 of file font.cc.
Referenced by GetMutableGlyphGridLocked().
|
inlineinherited |
Define the delete operator to use specialized functions dealing with an Allocator.
Definition at line 109 of file allocatable.h.
|
inlineinherited |
Windows requires these (or it issues C4291 warnings).
Definition at line 112 of file allocatable.h.
|
inlineinherited |
Definition at line 113 of file allocatable.h.
|
inlineinherited |
The placement delete operator does nothing, as usual.
Definition at line 118 of file allocatable.h.
|
inlineinherited |
The standard no-parameter new operator uses the default Allocator.
Definition at line 84 of file allocatable.h.
|
inlineinherited |
This overloaded version of the new operator uses the AllocationManager's default Allocator for the specified lifetime.
Definition at line 88 of file allocatable.h.
|
inlineinherited |
This overloaded version of the new operator takes the Allocator to use directly as a parameter.
If the Allocator pointer is NULL, this uses the default Allocator.
Definition at line 95 of file allocatable.h.
|
inlineinherited |
Special operator new for using placement new with Allocatables.
Definition at line 100 of file allocatable.h.
|
inlineinherited |
The placement new operator is defined conventionally.
Definition at line 105 of file allocatable.h.
|
protected |
Sets FontMetrics. SetFontMetrics() should only ever be called once.
Definition at line 89 of file font.cc.
References DCHECK_EQ, and ion::text::Font::FontMetrics::line_advance_height.
Referenced by ion::text::CoreTextFont::CoreTextFont(), and ion::text::FreeTypeFont::FreeTypeFont().
|
protected |