Gorgon Game Engine
BitmapFont Class Reference

Bitmap fonts provide an easy way to render text on the screen. More...

Inheritance diagram for BitmapFont:
[legend]

Classes

class  GlyphDescriptor
 to be used internally. More...
 
struct  gtog
 
struct  ImportOptions
 Use this structure to specify options for import operations. More...
 

Public Types

enum  DeleteConstants { None, Owned, All }
 
enum  ImportNamingTemplate { Automatic, Alpha, Decimal, Hexadecimal }
 

Public Member Functions

 BitmapFont (BitmapFont &&other)
 
 BitmapFont (const BitmapFont &)=delete
 
 BitmapFont (float baseline=0)
 
 ~BitmapFont ()
 
void AddGlyph (Glyph glyph, const RectangularDrawable &bitmap, Geometry::Pointf offset, float advance)
 Adds a new glyph bitmap to the list. More...
 
void AddGlyph (Glyph glyph, const RectangularDrawable &bitmap, int baseline=0)
 Adds a new glyph bitmap to the list. More...
 
void Adopt (const RectangularDrawable &img)
 This will add the given image to the list of images that will be destroyed with this object. More...
 
void AssumeGlyph (Glyph glyph, const RectangularDrawable &bitmap, Geometry::Pointf offset, float advance)
 Adds a new glyph bitmap to the list. More...
 
void AssumeGlyph (Glyph glyph, const RectangularDrawable &bitmap, int baseline=0)
 Adds a new glyph bitmap to the list. More...
 
void AutoKern (Byte opaquelevel=64, int reduce=1, int capitaloffset=-1)
 Automatically calculates kerning distances between glyphs. More...
 
std::map< Glyph, GlyphDescriptor >::iterator begin ()
 
std::map< Glyph, GlyphDescriptor >::const_iterator begin () const
 
Graphics::Bitmap CreateAtlas (std::vector< Geometry::Bounds > &bounds, bool tight=false) const
 Performs packing without changing the font itself. More...
 
void DetermineDimensions ()
 Searches through the currently registered glyphs to determine dimensions. More...
 
BitmapFont Duplicate ()
 
std::map< Glyph, GlyphDescriptor >::iterator end ()
 
std::map< Glyph, GlyphDescriptor >::const_iterator end () const
 
virtual bool Exists (Glyph g) const override
 Returns true if the glyph exists. More...
 
virtual float GetBaseLine () const override
 Baseline point of glyphs from the top. More...
 
virtual float GetCursorAdvance (Glyph g) const override
 This function should return the number of pixels the cursor should advance after this glyph. More...
 
virtual int GetDigitWidth () const override
 Width of a digit, if digits do not have the same width, maximum should be returned. More...
 
virtual int GetEMSize () const override
 Returns the size of the EM dash. More...
 
virtual const GlyphRendererGetGlyphRenderer () const override
 Returns the glyphrenderer that is used by this text renderer. More...
 
int GetGlyphSpacing () const
 Returns the spacing between glyphs. More...
 
virtual int GetHeight () const override
 Height of glyphs, actual size could be smaller but all glyphs should have the same virtual height. More...
 
const RectangularDrawableGetImage (Glyph g)
 Returns the image that represents a glyph. More...
 
virtual std::pair< int, int > GetLetterHeight (bool asciionly=false) const override
 
virtual float GetLineGap () const override
 This is the default distance between two consecutive lines. More...
 
virtual float GetLineThickness () const override
 Should return the average thickness of a line. More...
 
virtual int GetMaxWidth () const override
 Returns the width of widest glyph. More...
 
virtual Geometry::Size GetSize (const std::string &text) const override
 
virtual Geometry::Size GetSize (const std::string &text, int width) const override
 
virtual Geometry::Size GetSize (Glyph chr) const override
 This function should return the size of the requested glyph. More...
 
virtual int GetUnderlineOffset () const override
 The position of the underline, if it is to be drawn. More...
 
int ImportAtlas (Bitmap &&bmp, Geometry::Size grid={0, 0}, Glyph start=0x20, bool expand=false, ImportOptions options=ImportOptions{})
 Imports the given bitmap as atlas image. More...
 
int ImportAtlas (const Bitmap &bmp, Geometry::Size grid={0, 0}, Glyph start=0x20, bool expand=false, ImportOptions options=ImportOptions{})
 Imports the given bitmap as atlas image. More...
 
int ImportAtlas (const std::string &filename, Geometry::Size grid={0, 0}, Glyph start=0x20, bool expand=false, ImportOptions options=ImportOptions{})
 Imports the given file as atlas image. See ImportAtlas(Bitmap &&) for details. More...
 
int ImportFolder (const std::string &path, ImportNamingTemplate naming=Automatic, Glyph start=0, std::string prefix="", ImportOptions options=ImportOptions{})
 Imports bitmap font images from a folder with the specified file naming template. More...
 
virtual bool IsASCII () const override
 This function should return true if this font renderer supports only 7-bit ASCII. More...
 
virtual bool IsFixedWidth () const override
 This function should return true if this font is fixed width. More...
 
bool IsOwned (const RectangularDrawable &img) const
 Returns if the given image is owned by this bitmap font. More...
 
virtual Geometry::Pointf KerningDistance (Glyph chr1, Glyph chr2) const override
 This function should return the additional distance between given glyphs. More...
 
BitmapFontoperator= (BitmapFont &&other)
 Moves another bitmap font into this one. More...
 
BitmapFontoperator= (const BitmapFont &)=delete
 
void Pack (bool tight=false, DeleteConstants del=Owned)
 Converts individual glyphs to a single atlas. More...
 
virtual void Prepare (const std::string &) const
 Notifies glyph renderer about a text to be rendered. More...
 
bool Release (RectangularDrawable &img)
 If the given resource is owned by this bitmap font, its ownership will be released. More...
 
void Remove (Glyph g)
 Removes a glyph from the bitmap font. More...
 
virtual void Render (Glyph chr, TextureTarget &target, Geometry::Pointf location, RGBAf color) const override
 This function should render the given character to the target at the specified location and color. More...
 
void SetBaseline (float value)
 Changes the baseline. Might cause problems if the font already has glyphs in it. More...
 
void SetGlyphSpacing (int value)
 Changes the spacing between glyphs. More...
 
void SetHeight (int value)
 Changes the line height of the font. Adding glyphs may override this value. More...
 
void SetKerning (Glyph left, Glyph right, float x)
 
void SetKerning (Glyph left, Glyph right, Geometry::Pointf kern)
 
void SetLineGap (float value)
 Changes the distance between two lines. Non-integer values are not recommended. More...
 
void SetLineThickness (int value)
 Changes the line thickness to the specified value. More...
 
void SetMaxWidth (int value)
 Changes the maximum width for a character. Adding glyphs may override this value. More...
 
void SetUnderlineOffset (int value)
 Changes the underline position to the specified value. More...
 
- Public Member Functions inherited from GlyphRenderer
virtual ~GlyphRenderer ()
 
virtual bool NeedsPrepare () const
 Should return if the glyph renderer requires preparation regarding the text given. More...
 
virtual void Prepare (const std::string &) const
 Notifies glyph renderer about a text to be rendered. More...
 
- Public Member Functions inherited from BasicFont
 BasicFont (const GlyphRenderer &renderer, RGBAf color=1.f, TextAlignment defaultalign=TextAlignment::Left)
 
virtual int GetCharacterIndex (const std::string &text, Geometry::Point location) const override
 Returns the character index of glyph immediately after the given location. This function is Unicode aware. More...
 
virtual int GetCharacterIndex (const std::string &text, int w, Geometry::Point location, bool wrap=true) const override
 Returns the character index of glyph immediately after the given location. This function is Unicode aware. More...
 
RGBAf GetColor () const
 Returns the current text color. More...
 
TextAlignment GetDefaultAlignment () const
 Returns the current default alignment. More...
 
virtual Geometry::Rectangle GetPosition (const std::string &text, int index) const override
 Returns the position of the glyph at the character index. More...
 
virtual Geometry::Rectangle GetPosition (const std::string &text, int w, int index, bool wrap=true) const override
 Returns the position of the glyph at the character index. More...
 
virtual Geometry::Size GetSize (const std::string &text) const override
 Returns the size of the given text. More...
 
virtual Geometry::Size GetSize (const std::string &text, int width) const override
 Returns the size of the given text. More...
 
virtual bool IsReady () const override
 Whether the render can render text. More...
 
void Print (TextureTarget &target, const std::string &text)
 
void Print (TextureTarget &target, const std::string &text, Geometry::Point location) const
 
void Print (TextureTarget &target, const std::string &text, Geometry::Point location, int w) const
 
void Print (TextureTarget &target, const std::string &text, Geometry::Point location, int w, RGBAf color) const
 
void Print (TextureTarget &target, const std::string &text, Geometry::Point location, int w, TextAlignment align_override) const
 
void Print (TextureTarget &target, const std::string &text, Geometry::Point location, int w, TextAlignment align_override, RGBAf color) const
 
void Print (TextureTarget &target, const std::string &text, Geometry::Point location, RGBAf color) const
 
void Print (TextureTarget &target, const std::string &text, Geometry::Pointf location) const
 Prints the given text to the target. More...
 
void Print (TextureTarget &target, const std::string &text, int x, int y) const
 
void Print (TextureTarget &target, const std::string &text, int x, int y, int w) const
 
void Print (TextureTarget &target, const std::string &text, int x, int y, int w, RGBAf color) const
 
void Print (TextureTarget &target, const std::string &text, int x, int y, int w, TextAlignment align_override) const
 
void Print (TextureTarget &target, const std::string &text, int x, int y, int w, TextAlignment align_override, RGBAf color) const
 
void Print (TextureTarget &target, const std::string &text, int x, int y, RGBAf color) const
 
void Print (TextureTarget &target, const std::string &text, RGBAf color) const
 
void PrintNoWrap (TextureTarget &target, const std::string &text, Geometry::Point location, int w, RGBAf color) const
 
void PrintNoWrap (TextureTarget &target, const std::string &text, Geometry::Point location, int w, TextAlignment align_override, RGBAf color) const
 
void PrintNoWrap (TextureTarget &target, const std::string &text, int x, int y, int w, RGBAf color) const
 
void PrintNoWrap (TextureTarget &target, const std::string &text, int x, int y, int w, TextAlignment align_override, RGBAf color) const
 
void SetColor (RGBAf value)
 Changes the the color of the text. Color can only be overridden through BasicFont interface. More...
 
void SetDefaultAlignment (TextAlignment value)
 Changes the default alignment. It is possible to override default alignment through TextRenderer interface. More...
 
- Public Member Functions inherited from TextRenderer
virtual ~TextRenderer ()
 
void Print (TextureTarget &target, const std::string &text)
 
void Print (TextureTarget &target, const std::string &text, Geometry::Point location) const
 
void Print (TextureTarget &target, const std::string &text, Geometry::Point location, int w) const
 
void Print (TextureTarget &target, const std::string &text, Geometry::Point location, int w, TextAlignment align_override) const
 
void Print (TextureTarget &target, const std::string &text, Geometry::Pointf location) const
 Prints the given text to the target. More...
 
void Print (TextureTarget &target, const std::string &text, int x, int y) const
 
void Print (TextureTarget &target, const std::string &text, int x, int y, int w) const
 
void Print (TextureTarget &target, const std::string &text, int x, int y, int w, TextAlignment align_override) const
 
void PrintNoWrap (TextureTarget &target, const std::string &text, Geometry::Point location, int w) const
 
void PrintNoWrap (TextureTarget &target, const std::string &text, Geometry::Point location, int w, TextAlignment align_override) const
 
void PrintNoWrap (TextureTarget &target, const std::string &text, int x, int y, int w) const
 
void PrintNoWrap (TextureTarget &target, const std::string &text, int x, int y, int w, TextAlignment align_override) const
 

Protected Attributes

float baseline
 
Containers::Collection< const RectangularDrawabledestroylist
 
int digw
 
std::map< Glyph, GlyphDescriptorglyphmap
 
int height
 
bool isascii
 
int isfixedw
 
std::map< gtog, Geometry::Pointfkerning
 
float linegap
 
int linethickness
 
int maxwidth
 
int spacing
 
int underlinepos
 
- Protected Attributes inherited from BasicFont
RGBAf color
 Color of this renderer, can be overridden. More...
 
TextAlignment defaultalign
 Default alignment if none is specified. More...
 

Additional Inherited Members

- Protected Member Functions inherited from BasicFont
virtual void print (TextureTarget &target, const std::string &text, Geometry::Point location) const override
 
virtual void print (TextureTarget &target, const std::string &text, Geometry::Point location, RGBAf color) const
 
virtual void print (TextureTarget &target, const std::string &text, Geometry::Rectangle location) const override
 
virtual void print (TextureTarget &target, const std::string &text, Geometry::Rectangle location, RGBAf color) const
 
virtual void print (TextureTarget &target, const std::string &text, Geometry::Rectangle location, TextAlignment align) const override
 Should print the given text to the specified location and color. More...
 
virtual void print (TextureTarget &target, const std::string &text, Geometry::Rectangle location, TextAlignment align, RGBAf color) const
 
virtual void printnowrap (TextureTarget &target, const std::string &text, Geometry::Rectangle location) const override
 Should print the given text to the specified location and color. More...
 
virtual void printnowrap (TextureTarget &target, const std::string &text, Geometry::Rectangle location, RGBAf color) const
 
virtual void printnowrap (TextureTarget &target, const std::string &text, Geometry::Rectangle location, TextAlignment align) const override
 Should print the given text to the specified location and color. More...
 
virtual void printnowrap (TextureTarget &target, const std::string &text, Geometry::Rectangle location, TextAlignment align, RGBAf color) const
 

Detailed Description

Bitmap fonts provide an easy way to render text on the screen.

It is a GlyphRenderer but also acts as TextRenderer for convenience. If control over TextRenderer is required, it is best to use BitmapFont to construct a new TextRenderer and use the TextRenderer to render the text instead of using BitmapFont itself for the task.

Member Enumeration Documentation

◆ DeleteConstants

Enumerator
None 
Owned 
All 

◆ ImportNamingTemplate

Enumerator
Automatic 

Filenames will be examined to determine the template.

When this is set and prefix is empty, prefix is also tried to be determined

Alpha 

Characters are the filenames, not recommended as some symbols will not be accepted as filename.

Decimal 

Decimal code of the character is used as filename.

Hexadecimal 

Hexadecimal code of the character is used as filename.

Constructor & Destructor Documentation

◆ BitmapFont() [1/3]

BitmapFont ( float  baseline = 0)
explicit

◆ BitmapFont() [2/3]

BitmapFont ( const BitmapFont )
delete

◆ BitmapFont() [3/3]

◆ ~BitmapFont()

Member Function Documentation

◆ AddGlyph() [1/2]

void AddGlyph ( Glyph  glyph,
const RectangularDrawable bitmap,
Geometry::Pointf  offset,
float  advance 
)

Adds a new glyph bitmap to the list.

If a previous one exists, it will be replaced. Ownership of bitmap is not transferred.

References BitmapFont::baseline, BitmapFont::digw, RectangularDrawable::GetSize(), BitmapFont::glyphmap, BitmapFont::height, BitmapFont::isascii, BitmapFont::isfixedw, and BitmapFont::maxwidth.

◆ AddGlyph() [2/2]

void AddGlyph ( Glyph  glyph,
const RectangularDrawable bitmap,
int  baseline = 0 
)

Adds a new glyph bitmap to the list.

If a previous one exists, it will be replaced. Ownership of bitmap is not transferred. TODO: better baseline handling

References BitmapFont::baseline, RectangularDrawable::GetWidth(), and BitmapFont::spacing.

◆ Adopt()

void Adopt ( const RectangularDrawable img)

This will add the given image to the list of images that will be destroyed with this object.

References BitmapFont::destroylist.

◆ AssumeGlyph() [1/2]

void AssumeGlyph ( Glyph  glyph,
const RectangularDrawable bitmap,
Geometry::Pointf  offset,
float  advance 
)

Adds a new glyph bitmap to the list.

If a previous one exists, it will be replaced. Ownership of bitmap is not transferred.

References BitmapFont::AddGlyph(), and BitmapFont::destroylist.

◆ AssumeGlyph() [2/2]

void AssumeGlyph ( Glyph  glyph,
const RectangularDrawable bitmap,
int  baseline = 0 
)

Adds a new glyph bitmap to the list.

If a previous one exists, it will be replaced. Ownership of bitmap is not transferred.

References BitmapFont::AddGlyph(), BitmapFont::baseline, and BitmapFont::destroylist.

◆ AutoKern()

void AutoKern ( Byte  opaquelevel = 64,
int  reduce = 1,
int  capitaloffset = -1 
)

Automatically calculates kerning distances between glyphs.

This operation might take a while depending on the number of glyphs that are loaded. This function uses glyph spacing. This function is optimized for pixel fonts without fractional alpha. Glyphs should be bitmaps for this function to work properly. Additionally, this function either needs the Y-offset of capital letters, or the letter A should be present. This data will be used to determine accent symbols which should not be kerned. A value of -1 means use A to determine. If A is not present or the value is 0, this feature is disabled. The function takes glyph offsets into account. However, x offsets can cause issues.

References BitmapFont::GetHeight(), BitmapFont::glyphmap, BitmapFont::height, Gorgon::Graphics::internal::isspace(), Gorgon::Graphics::internal::isspaced(), BitmapFont::SetKerning(), and BitmapFont::spacing.

◆ begin() [1/2]

std::map<Glyph, GlyphDescriptor>::iterator begin ( )

References BitmapFont::glyphmap.

◆ begin() [2/2]

std::map<Glyph, GlyphDescriptor>::const_iterator begin ( ) const

References BitmapFont::glyphmap.

◆ CreateAtlas()

Graphics::Bitmap CreateAtlas ( std::vector< Geometry::Bounds > &  bounds,
bool  tight = false 
) const

Performs packing without changing the font itself.

References Collection< T_ >::Add(), Bitmap::CreateLinearAtlas(), BitmapFont::glyphmap, Bitmap::None, Gorgon::swap(), and Bitmap::Zero.

◆ DetermineDimensions()

void DetermineDimensions ( )

Searches through the currently registered glyphs to determine dimensions.

This function will calculate following values: height, max width, underline offset. Baseline is set to 0.7 * height if it is 0.

References BitmapFont::baseline, BitmapFont::glyphmap, BitmapFont::height, BitmapFont::isfixedw, BitmapFont::linegap, BitmapFont::linethickness, BitmapFont::maxwidth, and BitmapFont::underlinepos.

◆ Duplicate()

BitmapFont Duplicate ( )

◆ end() [1/2]

std::map<Glyph, GlyphDescriptor>::iterator end ( )

References BitmapFont::glyphmap.

◆ end() [2/2]

std::map<Glyph, GlyphDescriptor>::const_iterator end ( ) const

References BitmapFont::glyphmap.

◆ Exists()

virtual bool Exists ( Glyph  g) const
overridevirtual

Returns true if the glyph exists.

Implements GlyphRenderer.

References BitmapFont::glyphmap.

◆ GetBaseLine()

virtual float GetBaseLine ( ) const
overridevirtual

Baseline point of glyphs from the top.

Implements GlyphRenderer.

References BitmapFont::baseline.

◆ GetCursorAdvance()

float GetCursorAdvance ( Glyph  g) const
overridevirtual

This function should return the number of pixels the cursor should advance after this glyph.

This value will be added to kerning distance.

Implements GlyphRenderer.

References BitmapFont::GetSize(), BitmapFont::glyphmap, Gorgon::Graphics::internal::isnewline(), Gorgon::Graphics::internal::isspace(), BitmapFont::spacing, and basic_Size< T_ >::Width.

◆ GetDigitWidth()

virtual int GetDigitWidth ( ) const
overridevirtual

Width of a digit, if digits do not have the same width, maximum should be returned.

For practical reasons, this function is expected to consider arabic numerals.

Implements GlyphRenderer.

References BitmapFont::digw.

◆ GetEMSize()

virtual int GetEMSize ( ) const
overridevirtual

Returns the size of the EM dash.

Implements GlyphRenderer.

References BitmapFont::Exists(), BitmapFont::GetHeight(), BitmapFont::GetSize(), and basic_Size< T_ >::Width.

◆ GetGlyphRenderer()

virtual const GlyphRenderer& GetGlyphRenderer ( ) const
overridevirtual

Returns the glyphrenderer that is used by this text renderer.

It might be the text renderer itself. It is only safe to call this function if IsReady function has returned true.

Reimplemented from BasicFont.

◆ GetGlyphSpacing()

int GetGlyphSpacing ( ) const

Returns the spacing between glyphs.

References BitmapFont::spacing.

◆ GetHeight()

virtual int GetHeight ( ) const
overridevirtual

Height of glyphs, actual size could be smaller but all glyphs should have the same virtual height.

When drawn on the same y position, all glyphs should line up. Renderer can change actual draw location to compensate.

Implements GlyphRenderer.

References BitmapFont::height.

◆ GetImage()

const RectangularDrawable* GetImage ( Glyph  g)

Returns the image that represents a glyph.

References BitmapFont::glyphmap.

◆ GetLetterHeight()

std::pair< int, int > GetLetterHeight ( bool  asciionly = false) const
overridevirtual
See also
Gorgon::Graphics::GlyphRenderer::GetLetterHeight. This function may produce incorrect values if the bitmap data for the used letters are not present.

Implements GlyphRenderer.

References BitmapFont::GetHeight(), and BitmapFont::glyphmap.

◆ GetLineGap()

virtual float GetLineGap ( ) const
overridevirtual

This is the default distance between two consecutive lines.

This distance can be modified by text renderers

Implements GlyphRenderer.

References BitmapFont::linegap.

◆ GetLineThickness()

virtual float GetLineThickness ( ) const
overridevirtual

Should return the average thickness of a line.

This information can be used to construct underline and strike through.

Implements GlyphRenderer.

References BitmapFont::linethickness.

◆ GetMaxWidth()

virtual int GetMaxWidth ( ) const
overridevirtual

Returns the width of widest glyph.

Implements GlyphRenderer.

References BitmapFont::maxwidth.

◆ GetSize() [1/3]

Geometry::Size GetSize
override

◆ GetSize() [2/3]

Geometry::Size GetSize
override

◆ GetSize() [3/3]

Geometry::Size GetSize ( Glyph  chr) const
overridevirtual

This function should return the size of the requested glyph.

If it does not exists, 0x0 should be returned

Implements GlyphRenderer.

References BitmapFont::glyphmap, Gorgon::Graphics::internal::isnewline(), and Gorgon::Graphics::internal::isspace().

◆ GetUnderlineOffset()

virtual int GetUnderlineOffset ( ) const
overridevirtual

The position of the underline, if it is to be drawn.

Implements GlyphRenderer.

References BitmapFont::underlinepos.

◆ ImportAtlas() [1/3]

int ImportAtlas ( Bitmap &&  bmp,
Geometry::Size  grid = {0, 0},
Glyph  start = 0x20,
bool  expand = false,
ImportOptions  options = ImportOptions{} 
)

Imports the given bitmap as atlas image.

The bitmap data will be copied out of the given bitmap. If grid is not specified or specified as zero size, glyph locations will be determined automatically. This automatic detection requires glyphs to be arranged in lines and there must be at least 1px space between the lines and the glyphs. If saved, atlas images packed loosely by bitmap font will work with ImportAtlas function. However, packing algorithm of FreeType produces atlases with variable line height, making it impossible to determine glyph locations. packing options can be used to control the final result of glyphs. If you intend to save this font as a resource, you need to set expand to true. Space characters cannot be detected in automatic mode, thus they will be skipped. However, renderer has default space widths generated from font height.

Automatic detection can fail for double quotes and any other glyphs that are horizontally separate. Using ImportAtlas with automatic detection is difficult. you may need to modify atlas images to suit the function. Make sure there is at least 1px space between rows and glyphs are ordered as they should.

References RGBA::A, BitmapFont::AddGlyph(), Gorgon::Graphics::Alpha, basic_Size< T_ >::Area(), BitmapFont::AutoKern(), BitmapFont::ImportOptions::automatickerning, BitmapFont::ImportOptions::automatickerningreduction, BitmapFont::ImportOptions::baseline, BitmapFont::ImportOptions::converttoalpha, BitmapFont::destroylist, BitmapFont::ImportOptions::estimatebaseline, BitmapFont::glyphmap, basic_Size< T_ >::Height, BitmapFont::height, Gorgon::Graphics::internal::isspace(), BitmapFont::linegap, BitmapFont::linethickness, BitmapFont::maxwidth, Gorgon::No, BitmapFont::ImportOptions::pack, BitmapFont::Pack(), BitmapFont::ImportOptions::prepare, BitmapFont::ImportOptions::spacing, BitmapFont::spacing, BitmapFont::ImportOptions::trim, and basic_Size< T_ >::Width.

◆ ImportAtlas() [2/3]

int ImportAtlas ( const Bitmap bmp,
Geometry::Size  grid = {0, 0},
Glyph  start = 0x20,
bool  expand = false,
ImportOptions  options = ImportOptions{} 
)

Imports the given bitmap as atlas image.

The given bitmap will be duplicated. See ImportAtlas(Bitmap &&) for details.

◆ ImportAtlas() [3/3]

int ImportAtlas ( const std::string &  filename,
Geometry::Size  grid = {0, 0},
Glyph  start = 0x20,
bool  expand = false,
ImportOptions  options = ImportOptions{} 
)

Imports the given file as atlas image. See ImportAtlas(Bitmap &&) for details.

◆ ImportFolder()

int ImportFolder ( const std::string &  path,
ImportNamingTemplate  naming = Automatic,
Glyph  start = 0,
std::string  prefix = "",
ImportOptions  options = ImportOptions{} 
)

Imports bitmap font images from a folder with the specified file naming template.

Automatic detection will only work if there is a single bitmap font set in the folder. If baseline is set to a negative value, it would be calculated as 70% of the font height. Only png files are considered for import. If converttoalpha is set, then the images read will be converted to alpha only images. Import will import separate images, you may use Pack function to pack them to an image atlas. If prepare is set, the imported images will be prepared and font will be ready to be used. As of now, this function cannot deal with animated fonts. start parameter can be used for adjusting numeric offset. If template naming is automatic and the value is left as 0, it will be determined automatically so that the imported images will be matched with printable characters. Any files that start with . and _ is ignored, unless it is the name of the file. This function will return the number of images imported. Imported images will be destroyed by this object. Automatic conversion can cause issues with suffixes, however, if naming is set, any additional text after the number or character is ignored. This function calculates the line thickness using trimmed height of the underscore. If trimming is not set, this functionality will not work. Additionally, this function will set underline position to halfway between baseline and bottom. If estimatebaseline is set, then the baseline position is a simple estimate instead of a search. The search will look at A to find the lowest pixel to declare it baseline. Returns number of glyphs that are imported.

References RGBA::A, Hashmap< K_, T_, KeyFn, M_, C_ >::Add(), BitmapFont::AddGlyph(), BitmapFont::Alpha, Gorgon::Graphics::Alpha, BitmapFont::AutoKern(), BitmapFont::Automatic, BitmapFont::ImportOptions::automatickerning, BitmapFont::ImportOptions::automatickerningreduction, BitmapFont::ImportOptions::baseline, BitmapFont::baseline, Bitmap::Clear(), BitmapFont::ImportOptions::converttoalpha, BitmapFont::Decimal, BitmapFont::destroylist, BitmapFont::ImportOptions::estimatebaseline, Bitmap::ForPixels(), Gorgon::String::From(), Gorgon::Graphics::GetAlphaIndex(), Gorgon::Filesystem::GetBasename(), Gorgon::Filesystem::GetExtension(), Bitmap::GetHeight(), Bitmap::GetMode(), Hashmap< K_, T_, KeyFn, M_, C_ >::GetSize(), Bitmap::GetWidth(), BitmapFont::glyphmap, BitmapFont::height, BitmapFont::Hexadecimal, Gorgon::Filesystem::IsFile(), Iterator::IsValid(), Gorgon::Filesystem::Join(), Hashmap< K_, T_, KeyFn, M_, C_ >::Last(), BitmapFont::linegap, BitmapFont::linethickness, BitmapFont::maxwidth, Iterator::Next(), Gorgon::No, BitmapFont::ImportOptions::pack, BitmapFont::Pack(), Bitmap::Prepare(), BitmapFont::ImportOptions::prepare, Bitmap::Resize(), BitmapFont::ImportOptions::spacing, BitmapFont::spacing, basic_Margin< T_ >::Top, Bitmap::Trim(), BitmapFont::ImportOptions::trim, and BitmapFont::underlinepos.

◆ IsASCII()

virtual bool IsASCII ( ) const
overridevirtual

This function should return true if this font renderer supports only 7-bit ASCII.

Implements GlyphRenderer.

References BitmapFont::isascii.

◆ IsFixedWidth()

virtual bool IsFixedWidth ( ) const
overridevirtual

This function should return true if this font is fixed width.

This will suppress calls to GetSize function.

Implements GlyphRenderer.

References BitmapFont::isfixedw.

◆ IsOwned()

bool IsOwned ( const RectangularDrawable img) const

Returns if the given image is owned by this bitmap font.

References BitmapFont::destroylist.

◆ KerningDistance()

virtual Geometry::Pointf KerningDistance ( Glyph  left,
Glyph  right 
) const
overridevirtual

This function should return the additional distance between given glyphs.

Returned value could be (in most cases it is) negative. Left and right are visual locations, they will not be reverted for right to left rendering.

Implements GlyphRenderer.

References BitmapFont::kerning.

◆ operator=() [1/2]

◆ operator=() [2/2]

BitmapFont& operator= ( const BitmapFont )
delete

◆ Pack()

void Pack ( bool  tight = false,
DeleteConstants  del = Owned 
)

Converts individual glyphs to a single atlas.

Only the glyphs that are registered as bitmaps can be packed. This function will automatically detect types and act accordingly. If the ownership of the packed images belong to the font and del parameter is set to owned, owned images that are created either by import or a previous pack will be destroyed. If it is set to all, all images that took part in packing will be destroyed If tight packing is set, glyphs will be placed next to each other, saving space. However, if resized, they will have artifacts.

References Collection< T_ >::Add(), BitmapFont::All, BitmapFont::destroylist, Collection< T_ >::FindLocation(), BitmapFont::glyphmap, Bitmap::None, BitmapFont::None, and Bitmap::Zero.

◆ Prepare()

virtual void Prepare

Notifies glyph renderer about a text to be rendered.

If renderers require modification to their internal structures, they should mark them

◆ Release()

bool Release ( RectangularDrawable img)

If the given resource is owned by this bitmap font, its ownership will be released.

References BitmapFont::destroylist.

◆ Remove()

void Remove ( Glyph  g)

Removes a glyph from the bitmap font.

If this glyph is created by font object and this glyph is the last user of that resource, it will be destroyed. Use Release to prevent this from happening.

References BitmapFont::destroylist, and BitmapFont::glyphmap.

◆ Render()

void Render ( Glyph  chr,
TextureTarget target,
Geometry::Pointf  location,
RGBAf  color 
) const
overridevirtual

This function should render the given character to the target at the specified location and color.

If chr does not exists, this function should perform no action. location and color can be modified as per the needs of renderer. If the kerning returns integers location will always be an integer. Additionally, text renderers will place glyphs on 0 y position from the top. It is glyph renderer's task to ensure baseline of glyphs to line up.

Implements GlyphRenderer.

References BasicFont::color, BitmapFont::glyphmap, Gorgon::Graphics::internal::isnewline(), and Gorgon::Graphics::internal::isspace().

◆ SetBaseline()

void SetBaseline ( float  value)

Changes the baseline. Might cause problems if the font already has glyphs in it.

References BitmapFont::baseline.

◆ SetGlyphSpacing()

void SetGlyphSpacing ( int  value)

Changes the spacing between glyphs.

References BitmapFont::spacing.

◆ SetHeight()

void SetHeight ( int  value)

Changes the line height of the font. Adding glyphs may override this value.

References BitmapFont::height.

◆ SetKerning() [1/2]

void SetKerning ( Glyph  left,
Glyph  right,
float  x 
)

References BitmapFont::kerning.

◆ SetKerning() [2/2]

void SetKerning ( Glyph  left,
Glyph  right,
Geometry::Pointf  kern 
)

References BitmapFont::kerning.

◆ SetLineGap()

void SetLineGap ( float  value)

Changes the distance between two lines. Non-integer values are not recommended.

References BitmapFont::linegap.

◆ SetLineThickness()

void SetLineThickness ( int  value)

Changes the line thickness to the specified value.

References BitmapFont::linethickness.

◆ SetMaxWidth()

void SetMaxWidth ( int  value)

Changes the maximum width for a character. Adding glyphs may override this value.

References BitmapFont::maxwidth.

◆ SetUnderlineOffset()

void SetUnderlineOffset ( int  value)

Changes the underline position to the specified value.

References BitmapFont::underlinepos.

Member Data Documentation

◆ baseline

float baseline
protected

◆ destroylist

Containers::Collection<const RectangularDrawable> destroylist
protected

◆ digw

int digw
protected

◆ glyphmap

std::map<Glyph, GlyphDescriptor> glyphmap
protected

◆ height

int height
protected

◆ isascii

bool isascii
protected

◆ isfixedw

int isfixedw
protected

◆ kerning

std::map<gtog, Geometry::Pointf> kerning
protected

◆ linegap

float linegap
protected

◆ linethickness

int linethickness
protected

◆ maxwidth

int maxwidth
protected

◆ spacing

int spacing
protected

◆ underlinepos

int underlinepos
protected

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