Ion
|
This represents a single CoreText font. More...
#include "coretextfont.h"
Public Member Functions | |
CoreTextFont (const std::string &name, size_t size_in_pixels, size_t sdf_padding, const void *data, size_t data_size) | |
Constructs an instance using the given name. More... | |
std::string | GetCTFontName () const |
Returns the name of the backing system font. More... | |
GlyphIndex | GetDefaultGlyphForChar (CharIndex char_index) const override |
Font overrides. More... | |
const Layout | BuildLayout (const std::string &text, const LayoutOptions &options) const override |
Creates a layout as specified by options for a given single- or multi- line string text . More... | |
void | AddFallbackFont (const FontPtr &fallback) override |
Causes this font to use the font fallback as a fallback if a requested glyph is not found. More... | |
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... | |
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... | |
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... | |
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 | |
~CoreTextFont () override | |
bool | LoadGlyphGrid (GlyphIndex glyph_index, GlyphGrid *glyph_grid) const override |
Called by GetGlyphGrid() for missing glyphs. More... | |
GlyphGrid * | GetMutableGlyphGrid (GlyphIndex glyph_index) const |
Non-const version of GetGlyphGrid. More... | |
GlyphGrid * | GetMutableGlyphGridLocked (GlyphIndex glyph_index) const |
Prelocked version of GetMutableGlyphGrid. 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... | |
This represents a single CoreText font.
However, when asked to render characters not in the CoreText font, it will fall back to other system CoreText fonts, and therefore can be used to render characters supported by any font in the OS.
Definition at line 34 of file coretextfont.h.
|
protectedinherited |
ion::text::CoreTextFont::CoreTextFont | ( | const std::string & | name, |
size_t | size_in_pixels, | ||
size_t | sdf_padding, | ||
const void * | data, | ||
size_t | data_size | ||
) |
Constructs an instance using the given name.
If data
is non-NULL and data_size
non-zero, data
will be read as TrueType data of length data_size
to build the font. Otherwise the OS will be asked to build a font with the given name
. This will try to match the name, or fall back to the a default system font. For a list of available fonts see (for example) iosfonts.com.
Definition at line 554 of file coretextfont.mm.
References ion::text::Font::SetFontMetrics().
|
overrideprotected |
Definition at line 562 of file coretextfont.mm.
|
overridevirtual |
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.
Implements ion::text::Font.
Definition at line 582 of file coretextfont.mm.
|
protectedinherited |
Adds a GlyphGrid to the GlyphMap.
Definition at line 81 of file font.cc.
References ion::base::IsInvalidReference().
|
inherited |
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 ion::text::Font::GetDefaultGlyphForChar().
|
overridevirtual |
Creates a layout as specified by options
for a given single- or multi- line string text
.
Implements ion::text::Font.
Definition at line 573 of file coretextfont.mm.
|
protectedinherited |
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, ion::text::Font::GetMutableGlyphGrid(), ion::text::Font::GlyphGrid::is_sdf, LOG, and ion::text::Font::GlyphGrid::pixels.
Referenced by ion::text::Font::CacheSdfGrids().
|
inherited |
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 ion::text::Font::CacheSdfGrid(), ion::text::ComputeSdfGrid(), DCHECK, ion::text::Font::GetMutableGlyphGrid(), ion::text::Font::GetSdfPadding(), ion::text::Font::GlyphGrid::is_sdf, ion::base::IsInvalidReference(), and ion::text::Font::GlyphGrid::pixels.
|
inherited |
Filter zero-size glyphs from glyph_set
.
Definition at line 125 of file font.cc.
References ion::text::Font::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().
std::string ion::text::CoreTextFont::GetCTFontName | ( | ) | const |
Returns the name of the backing system font.
This can be used to check what font the system used when trying to match the name
parameter used in the CoreTextFont constructor.
Definition at line 578 of file coretextfont.mm.
|
overridevirtual |
|
inlineinherited |
Returns the FontMetrics for the font.
Definition at line 87 of file font.h.
Referenced by ion::text::ComputeTextSize().
|
inherited |
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 ion::text::Font::GetMutableGlyphGrid().
|
protectedinherited |
Non-const version of GetGlyphGrid.
Definition at line 55 of file font.cc.
References ion::text::Font::GetMutableGlyphGridLocked().
Referenced by ion::text::Font::CacheSdfGrid(), ion::text::Font::CacheSdfGrids(), and ion::text::Font::GetGlyphGrid().
|
protectedinherited |
Prelocked version of GetMutableGlyphGrid.
Definition at line 60 of file font.cc.
References DCHECK, ion::port::Mutex::IsLocked(), and ion::text::Font::LoadGlyphGrid().
Referenced by ion::text::Font::FilterGlyphs(), and ion::text::Font::GetMutableGlyphGrid().
|
inlineinherited |
|
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().
|
inlineinherited |
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 ion::text::Font::CacheSdfGrids(), ion::text::BasicBuilder::UpdateUniforms(), and ion::text::OutlineBuilder::UpdateUniforms().
|
inlineinherited |
Returns the size of the font in pixels.
Definition at line 78 of file font.h.
Referenced by ion::text::ComputeTextSize().
|
overrideprotectedvirtual |
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 from ion::text::Font.
Definition at line 564 of file coretextfont.mm.
|
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.
|
protectedinherited |
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 CoreTextFont(), and ion::text::FreeTypeFont::FreeTypeFont().
|
protectedinherited |