Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ion::text::CoreTextFont Class Reference

This represents a single CoreText font. More...

#include "coretextfont.h"

Inheritance diagram for ion::text::CoreTextFont:
Collaboration diagram for ion::text::CoreTextFont:

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 FontMetricsGetFontMetrics () const
 Returns the FontMetrics for the font. More...
 
const GlyphGridGetGlyphGrid (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...
 
GlyphGridGetMutableGlyphGrid (GlyphIndex glyph_index) const
 Non-const version of GetGlyphGrid. More...
 
GlyphGridGetMutableGlyphGridLocked (GlyphIndex glyph_index) const
 Prelocked version of GetMutableGlyphGrid. More...
 
const GlyphGridAddGlyph (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...
 

Detailed Description

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.

Member Typedef Documentation

Convenience typedef for the map storing GlyphGrid instances.

Definition at line 134 of file font.h.

Constructor & Destructor Documentation

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().

ion::text::CoreTextFont::~CoreTextFont ( )
overrideprotected

Definition at line 562 of file coretextfont.mm.

Member Function Documentation

void ion::text::CoreTextFont::AddFallbackFont ( const FontPtr fallback)
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.

const Font::GlyphGrid & ion::text::Font::AddGlyph ( GlyphIndex  glyph_index,
const GlyphGrid glyph 
) const
protectedinherited

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 
)
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().

const Layout ion::text::CoreTextFont::BuildLayout ( const std::string &  text,
const LayoutOptions options 
) const
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.

bool ion::text::Font::CacheSdfGrid ( GlyphIndex  glyph_index,
const base::Array2< double > &  sdf_pixels 
)
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().

void ion::text::Font::CacheSdfGrids ( const GlyphSet glyph_set)
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.

void ion::text::Font::FilterGlyphs ( GlyphSet glyph_set)
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().

const AllocatorPtr& ion::base::Allocatable::GetAllocator ( ) const
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().

const AllocatorPtr& ion::base::Allocatable::GetAllocatorForLifetime ( AllocationLifetime  lifetime) const
inlineinherited
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.

GlyphIndex ion::text::CoreTextFont::GetDefaultGlyphForChar ( CharIndex  char_index) const
overridevirtual

Font overrides.

Implements ion::text::Font.

Definition at line 569 of file coretextfont.mm.

const FontMetrics& ion::text::Font::GetFontMetrics ( ) const
inlineinherited

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
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().

Font::GlyphGrid * ion::text::Font::GetMutableGlyphGrid ( GlyphIndex  glyph_index) const
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().

Font::GlyphGrid * ion::text::Font::GetMutableGlyphGridLocked ( GlyphIndex  glyph_index) const
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().

const std::string& ion::text::Font::GetName ( ) const
inlineinherited

Returns the name of the font.

Definition at line 75 of file font.h.

const AllocatorPtr& ion::base::Allocatable::GetNonNullAllocator ( ) const
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().

int ion::base::Shareable::GetRefCount ( ) const
inlineinherited

GetRefCount() is part of the interface necessary for SharedPtr.

Definition at line 34 of file shareable.h.

Referenced by ion::base::Notifier::RemoveReceiver().

size_t ion::text::Font::GetSdfPadding ( ) const
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().

size_t ion::text::Font::GetSizeInPixels ( ) const
inlineinherited

Returns the size of the font in pixels.

Definition at line 78 of file font.h.

Referenced by ion::text::ComputeTextSize().

bool ion::text::CoreTextFont::LoadGlyphGrid ( GlyphIndex  glyph_index,
GlyphGrid glyph_grid 
) const
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.

void ion::base::Allocatable::operator delete ( void *  ptr)
inlineinherited

Define the delete operator to use specialized functions dealing with an Allocator.

Definition at line 109 of file allocatable.h.

void ion::base::Allocatable::operator delete ( void *  ptr,
AllocationLifetime  lifetime 
)
inlineinherited

Windows requires these (or it issues C4291 warnings).

Definition at line 112 of file allocatable.h.

void ion::base::Allocatable::operator delete ( void *  ptr,
const AllocatorPtr allocator 
)
inlineinherited

Definition at line 113 of file allocatable.h.

void ion::base::Allocatable::operator delete ( void *  ptr,
void *  ptr2 
)
inlineinherited

The placement delete operator does nothing, as usual.

Definition at line 118 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size)
inlineinherited

The standard no-parameter new operator uses the default Allocator.

Definition at line 84 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
AllocationLifetime  lifetime 
)
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.

void* ion::base::Allocatable::operator new ( size_t  size,
const AllocatorPtr allocator 
)
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.

void* ion::base::Allocatable::operator new ( size_t  size,
const AllocatorPtr allocator,
void *  ptr 
)
inlineinherited

Special operator new for using placement new with Allocatables.

Definition at line 100 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
void *  ptr 
)
inlineinherited

The placement new operator is defined conventionally.

Definition at line 105 of file allocatable.h.

void ion::text::Font::SetFontMetrics ( const FontMetrics metrics)
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().

Member Data Documentation

const size_t ion::text::Font::size_in_pixels_
protectedinherited

Size in pixels.

Definition at line 169 of file font.h.


The documentation for this class was generated from the following files: