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

DynamicFontImage is a derived FontImage that may contain any number of ImageData instances. More...

#include "fontimage.h"

Inheritance diagram for ion::text::DynamicFontImage:
Collaboration diagram for ion::text::DynamicFontImage:

Public Types

enum  Type {
  kStatic,
  kDynamic
}
 

Public Member Functions

 DynamicFontImage (const FontPtr &font, size_t image_size)
 The constructor sets up the DynamicFontImage to use the Font. More...
 
size_t GetImageDataCount () const
 Returns the current count of ImageData instances. More...
 
const ImageDataGetImageData (size_t index) const
 Returns the indexed ImageData instance, or an invalid reference if the index is out of range. More...
 
float GetImageDataUsedAreaFraction (size_t index) const
 Returns the area covered by glyphs in the indexed ImageData, or 0 if the index is out of range. More...
 
void EnableDeferredUpdates (bool enable)
 Sets whether deferred updates are enabled. More...
 
bool AreUpdatesDeferred () const
 Returns whether updates are deferred. More...
 
void ProcessDeferredUpdates ()
 Updates internal texture data with any deferred updates. More...
 
const ImageDataFindImageData (const GlyphSet &glyph_set) override
 Implements this function to find an existing ImageData that already contains all of the glyphs (present in the Font) in glyph_set. More...
 
size_t FindImageDataIndex (const GlyphSet &glyph_set)
 This is the same as FindImageData(), but instead returns the index of the ImageData, or kInvalidIndex if unsuccessful. More...
 
size_t FindContainingImageDataIndex (const GlyphSet &glyph_set)
 Returns the index of an ImageData instance that contains all of the glyphs (present in the Font) in glyph_set, or kInvalidIndex if there are none. More...
 
Type GetType () const
 Returns the type of an instance. More...
 
const FontPtrGetFont ()
 Returns the Font passed to the constructor. More...
 
size_t GetMaxImageSize ()
 Returns the maximum image size passed to the constructor. 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...
 

Static Public Member Functions

static bool HasAllGlyphs (const ImageData &image_data, const GlyphSet &glyph_set)
 Convenience function that returns true if an ImageData instance contains all glyphs in glyph_set. More...
 
static bool HasGlyph (const ImageData &image_data, GlyphIndex glyph_index)
 Convenience function that returns true if an ImageData instance contains a glyph with the given index. More...
 
static bool GetTextureCoords (const ImageData &image_data, GlyphIndex glyph_index, math::Range2f *rectangle)
 Convenience function that sets rectangle to the texture coordinate rectangle to use for the indexed glyph within an ImageData instance. More...
 

Protected Member Functions

 ~DynamicFontImage () override
 

Detailed Description

DynamicFontImage is a derived FontImage that may contain any number of ImageData instances.

New glyphs may be added at any time, modifying an existing ImageData or adding a new one.

New glyphs are added to an image only in empty space so that texture coordinate rectangles for previously-added glyphs remain valid.

Since updates require adding sub-images to Textures, calling FindImageData*() while the DynamicFontImage's texture is being rendered in another thread can cause undefined behavior. To safely update DynamicFontImages on worker threads, enable deferred updates and call ProcessDeferredUpdates() when it is safe to update texture data.

Definition at line 208 of file fontimage.h.

Member Enumeration Documentation

Enumerator
kStatic 
kDynamic 

Definition at line 65 of file fontimage.h.

Constructor & Destructor Documentation

ion::text::DynamicFontImage::DynamicFontImage ( const FontPtr font,
size_t  image_size 
)

The constructor sets up the DynamicFontImage to use the Font.

DynamicFontImage functions.

The image_size value is used as the constant size (in both dimensions) of the image created for each ImageData.

Definition at line 580 of file fontimage.cc.

ion::text::DynamicFontImage::~DynamicFontImage ( )
overrideprotected

Definition at line 585 of file fontimage.cc.

Member Function Documentation

bool ion::text::DynamicFontImage::AreUpdatesDeferred ( ) const
inline

Returns whether updates are deferred.

Definition at line 230 of file fontimage.h.

void ion::text::DynamicFontImage::EnableDeferredUpdates ( bool  enable)
inline

Sets whether deferred updates are enabled.

Definition at line 227 of file fontimage.h.

size_t ion::text::DynamicFontImage::FindContainingImageDataIndex ( const GlyphSet glyph_set)

Returns the index of an ImageData instance that contains all of the glyphs (present in the Font) in glyph_set, or kInvalidIndex if there are none.

Definition at line 662 of file fontimage.cc.

References ion::base::Allocatable::GetAllocator(), ion::base::Allocatable::GetAllocatorForLifetime(), ion::text::FontImage::GetFont(), ion::base::kInvalidIndex, and ion::base::kShortTerm.

const FontImage::ImageData & ion::text::DynamicFontImage::FindImageData ( const GlyphSet glyph_set)
overridevirtual

Implements this function to find an existing ImageData that already contains all of the glyphs (present in the Font) in glyph_set.

If there is no such ImageData, it then tries to add the necessary glyphs to an existing ImageData instance. If that doesn't work, it tries to add them all to a new ImageData instance. If none of these is successful (or if there were no valid glyphs to add), this returns an invalid reference.

Implements ion::text::FontImage.

Definition at line 618 of file fontimage.cc.

References FindImageDataIndex(), and GetImageData().

size_t ion::text::DynamicFontImage::FindImageDataIndex ( const GlyphSet glyph_set)

This is the same as FindImageData(), but instead returns the index of the ImageData, or kInvalidIndex if unsuccessful.

Definition at line 623 of file fontimage.cc.

References ion::base::Allocatable::GetAllocator(), ion::base::Allocatable::GetAllocatorForLifetime(), ion::text::FontImage::GetFont(), ion::base::kInvalidIndex, and ion::base::kShortTerm.

Referenced by FindImageData().

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(), FindContainingImageDataIndex(), and FindImageDataIndex().

const AllocatorPtr& ion::base::Allocatable::GetAllocatorForLifetime ( AllocationLifetime  lifetime) const
inlineinherited
const FontPtr& ion::text::FontImage::GetFont ( )
inlineinherited

Returns the Font passed to the constructor.

Definition at line 88 of file fontimage.h.

Referenced by FindContainingImageDataIndex(), and FindImageDataIndex().

const FontImage::ImageData & ion::text::DynamicFontImage::GetImageData ( size_t  index) const

Returns the indexed ImageData instance, or an invalid reference if the index is out of range.

Definition at line 591 of file fontimage.cc.

Referenced by FindImageData().

size_t ion::text::DynamicFontImage::GetImageDataCount ( ) const

Returns the current count of ImageData instances.

Definition at line 587 of file fontimage.cc.

float ion::text::DynamicFontImage::GetImageDataUsedAreaFraction ( size_t  index) const

Returns the area covered by glyphs in the indexed ImageData, or 0 if the index is out of range.

This is useful primarily for testing.

Definition at line 598 of file fontimage.cc.

size_t ion::text::FontImage::GetMaxImageSize ( )
inlineinherited

Returns the maximum image size passed to the constructor.

Definition at line 91 of file fontimage.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().

bool ion::text::FontImage::GetTextureCoords ( const ImageData image_data,
GlyphIndex  glyph_index,
math::Range2f rectangle 
)
staticinherited

Convenience function that sets rectangle to the texture coordinate rectangle to use for the indexed glyph within an ImageData instance.

Returns false if the glyph is not in the ImageData.

Definition at line 452 of file fontimage.cc.

References ion::base::IsInvalidReference(), and ion::text::FontImage::ImageData::texture_rectangle_map.

Referenced by ion::text::Builder::StoreGlyphVertices().

Type ion::text::FontImage::GetType ( ) const
inlineinherited

Returns the type of an instance.

Definition at line 85 of file fontimage.h.

static bool ion::text::FontImage::HasAllGlyphs ( const ImageData image_data,
const GlyphSet glyph_set 
)
inlinestaticinherited

Convenience function that returns true if an ImageData instance contains all glyphs in glyph_set.

Definition at line 101 of file fontimage.h.

References ion::text::FontImage::ImageData::glyph_set, and ion::base::IsInvalidReference().

static bool ion::text::FontImage::HasGlyph ( const ImageData image_data,
GlyphIndex  glyph_index 
)
inlinestaticinherited

Convenience function that returns true if an ImageData instance contains a glyph with the given index.

Definition at line 111 of file fontimage.h.

References ion::text::FontImage::ImageData::glyph_set, and ion::base::IsInvalidReference().

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::DynamicFontImage::ProcessDeferredUpdates ( )

Updates internal texture data with any deferred updates.

The caller must ensure that the DynamicFontImage's Textures are not being rendered when this is called.

Definition at line 604 of file fontimage.cc.


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