ScummVM API documentation
Graphics::Font Class Referenceabstract

#include <font.h>

Inheritance diagram for Graphics::Font:
BladeRunner::Font CryOmni3D::CryoExtFont CryOmni3D::CryoFont Graphics::AmigaFont Graphics::BdfFont Graphics::MacFONTFont Graphics::WinFont Groovie::T7GFont MM::BitmapFont MM::XeenFont MutationOfJB::Font Nancy::Font Prince::Font Tetraedge::TeFont2

Public Member Functions

virtual int getFontHeight () const =0
 
virtual Common::String getFontName () const
 
virtual int getFontAscent () const
 
virtual int getFontDescent () const
 
virtual int getFontLeading () const
 
virtual int getMaxCharWidth () const =0
 
virtual int getCharWidth (uint32 chr) const =0
 
virtual int getKerningOffset (uint32 left, uint32 right) const
 
virtual Common::Rect getBoundingBox (uint32 chr) const
 
Common::Rect getBoundingBox (const Common::String &str, int x=0, int y=0, const int w=0, TextAlign align=kTextAlignLeft, int deltax=0, bool useEllipsis=false) const
 
Common::Rect getBoundingBox (const Common::U32String &str, int x=0, int _y=0, const int w=0, TextAlign align=kTextAlignLeft, int deltax=0, bool useEllipsis=false) const
 
virtual void drawChar (Surface *dst, uint32 chr, int x, int y, uint32 color) const =0
 
virtual void drawChar (ManagedSurface *dst, uint32 chr, int x, int y, uint32 color) const
 
void drawString (Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, TextAlign align=kTextAlignLeft, int deltax=0, bool useEllipsis=false) const
 
void drawString (Surface *dst, const Common::U32String &str, int x, int y, int w, uint32 color, TextAlign align=kTextAlignLeft, int deltax=0, bool useEllipsis=false) const
 
void drawString (ManagedSurface *dst, const Common::String &str, int x, int _y, int w, uint32 color, TextAlign align=kTextAlignLeft, int deltax=0, bool useEllipsis=false) const
 
void drawString (ManagedSurface *dst, const Common::U32String &str, int x, int y, int w, uint32 color, TextAlign align=kTextAlignLeft, int deltax=0, bool useEllipsis=false) const
 
int getStringWidth (const Common::String &str) const
 
int getStringWidth (const Common::U32String &str) const
 
int wordWrapText (const Common::String &str, int maxWidth, Common::Array< Common::String > &lines, int initWidth=0, uint32 mode=kWordWrapOnExplicitNewLines) const
 
int wordWrapText (const Common::U32String &str, int maxWidth, Common::Array< Common::U32String > &lines, int initWidth=0, uint32 mode=kWordWrapOnExplicitNewLines) const
 
int wordWrapText (const Common::U32String &str, int maxWidth, Common::Array< Common::U32String > &lines, Common::Array< bool > &lineContinuation, int initWidth=0, uint32 mode=kWordWrapOnExplicitNewLines) const
 
void scaleSingleGlyph (Surface *scaleSurface, int *grayScaleMap, int grayScaleMapSize, int width, int height, int xOffset, int yOffset, int grayLevel, int chr, int srcheight, int srcwidth, float scale) const
 

Detailed Description

Instances of this class represent a distinct font, with a built-in renderer.

Member Function Documentation

◆ getFontHeight()

virtual int Graphics::Font::getFontHeight ( ) const
pure virtual

◆ getFontName()

virtual Common::String Graphics::Font::getFontName ( ) const
inlinevirtual

Returns the font's name, if one is available

◆ getFontAscent()

virtual int Graphics::Font::getFontAscent ( ) const
virtual

Return the ascent of the font.

Returns
Font ascent in pixels. If it is unknown a value of -1 is returned.

Reimplemented in Graphics::MacFONTFont, Graphics::BdfFont, and Graphics::WinFont.

◆ getFontDescent()

virtual int Graphics::Font::getFontDescent ( ) const
virtual

Return the descent of the font.

Returns
Font descent in pixels. If it is unknown a value of -1 is returned.

Reimplemented in Graphics::MacFONTFont.

◆ getFontLeading()

virtual int Graphics::Font::getFontLeading ( ) const
virtual

Return the leading of the font. This is the distance between the descent line and the ascent line below it.

Returns
Font leading in pixels. If it is unknown a value of -1 is returned.

Reimplemented in Graphics::MacFONTFont.

◆ getMaxCharWidth()

virtual int Graphics::Font::getMaxCharWidth ( ) const
pure virtual

◆ getCharWidth()

virtual int Graphics::Font::getCharWidth ( uint32  chr) const
pure virtual

Return the width of a specific character.

Parameters
chrThe character to query the width of.
Returns
The width of the character in pixels.

Implemented in Graphics::MacFONTFont, Graphics::AmigaFont, Tetraedge::TeFont2, MM::XeenFont, Graphics::BdfFont, Graphics::WinFont, BladeRunner::Font, MM::BitmapFont, CryOmni3D::CryoExtFont, Nancy::Font, CryOmni3D::CryoFont, MutationOfJB::Font, Prince::Font, and Groovie::T7GFont.

◆ getKerningOffset()

virtual int Graphics::Font::getKerningOffset ( uint32  left,
uint32  right 
) const
virtual

Query the kerning offset between two characters.

Parameters
leftLeft character. Can be 0.
rightRight character. Can be 0.
Returns
The horizontal displacement.

Reimplemented in Graphics::MacFONTFont, Graphics::AmigaFont, Tetraedge::TeFont2, Nancy::Font, Prince::Font, and MutationOfJB::Font.

◆ getBoundingBox() [1/3]

virtual Common::Rect Graphics::Font::getBoundingBox ( uint32  chr) const
virtual

Calculate the bounding box of a character.

It is assumed that the character shall be drawn at position (0, 0).

The idea here is that the character might be drawn outside the rect (0, 0) to (getCharWidth(chr), getFontHeight()) for some fonts. This is common among TTF fonts.

The default implementation simply returns the rect with a width of getCharWidth(chr) and height of getFontHeight().

Parameters
chrThe character to draw.
Returns
The bounding box of the drawn glyph.

Reimplemented in Tetraedge::TeFont2, CryOmni3D::CryoExtFont, and CryOmni3D::CryoFont.

◆ getBoundingBox() [2/3]

Common::Rect Graphics::Font::getBoundingBox ( const Common::String str,
int  x = 0,
int  y = 0,
const int  w = 0,
TextAlign  align = kTextAlignLeft,
int  deltax = 0,
bool  useEllipsis = false 
) const

Return the bounding box of a string drawn with drawString.

Parameters
strThe drawn string.
xThe x position where to start drawing.
yThe y position where to start drawing.
wWidth of the text area. This can be 0 to allow for obtaining the whole bounding box for a string. Note that this does not work with an align different than kTextAlignLeft or with useEllipsis.
alignText alignment. This can be used to center a string in the given area or to align it to the right.
deltaxOffset to the x starting position of the string.
useEllipsisTry to fit the string in the area by inserting an ellipsis. Note that the default value is false for this argument, unlike for drawString.
Returns
The actual area where the string is drawn.

◆ getBoundingBox() [3/3]

Common::Rect Graphics::Font::getBoundingBox ( const Common::U32String str,
int  x = 0,
int  _y = 0,
const int  w = 0,
TextAlign  align = kTextAlignLeft,
int  deltax = 0,
bool  useEllipsis = false 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ drawChar()

virtual void Graphics::Font::drawChar ( Surface dst,
uint32  chr,
int  x,
int  y,
uint32  color 
) const
pure virtual

Draw a character at a specific point on the surface.

Note that the point describes the top left edge point where to draw the character. This can be different from the top left edge point of the character's bounding box. For example, TTF fonts sometimes move characters like 't' by one (or more) pixels to the left to create better visual results. To query the actual bounding box of a character, use getBoundingBox.

See also
getBoundingBox

The Font implementation should take care of not drawing outside of the specified surface.

Parameters
dstThe surface to draw on.
chrThe character to draw.
xThe x coordinate where to draw the character.
yThe y coordinate where to draw the character.
colorThe color of the character.

Implemented in Graphics::MacFONTFont, Graphics::AmigaFont, Tetraedge::TeFont2, MM::XeenFont, Graphics::BdfFont, Graphics::WinFont, MM::BitmapFont, BladeRunner::Font, CryOmni3D::CryoExtFont, CryOmni3D::CryoFont, Nancy::Font, MutationOfJB::Font, Prince::Font, Groovie::T7GFont, and MM::MM1::Gfx::BitmapFont.

◆ drawString() [1/4]

void Graphics::Font::drawString ( Surface dst,
const Common::String str,
int  x,
int  y,
int  w,
uint32  color,
TextAlign  align = kTextAlignLeft,
int  deltax = 0,
bool  useEllipsis = false 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Draw the given str string to the given dst surface.

Parameters
dstThe surface on which to draw the string.
strThe string to draw.
xThe x position where to start drawing.
yThe y position where to start drawing.
wWidth of the text area.
colorThe color with which to draw the string.
alignText alignment. This can be used to center the string in the given area or to align it to the right.
deltaxOffset to the x starting position of the string.
useEllipsisUse ellipsis if needed to fit the string in the area.

◆ drawString() [2/4]

void Graphics::Font::drawString ( Surface dst,
const Common::U32String str,
int  x,
int  y,
int  w,
uint32  color,
TextAlign  align = kTextAlignLeft,
int  deltax = 0,
bool  useEllipsis = false 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ drawString() [3/4]

void Graphics::Font::drawString ( ManagedSurface dst,
const Common::String str,
int  x,
int  _y,
int  w,
uint32  color,
TextAlign  align = kTextAlignLeft,
int  deltax = 0,
bool  useEllipsis = false 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ drawString() [4/4]

void Graphics::Font::drawString ( ManagedSurface dst,
const Common::U32String str,
int  x,
int  y,
int  w,
uint32  color,
TextAlign  align = kTextAlignLeft,
int  deltax = 0,
bool  useEllipsis = false 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ getStringWidth() [1/2]

int Graphics::Font::getStringWidth ( const Common::String str) const

Compute and return the width of the string str when rendered using this font.

This describes the logical width of the string when drawn at (0, 0). This can be different from the actual bounding box of the string. Use getBoundingBox when you need the bounding box of a drawn string.

See also
getBoundingBox
drawChar

◆ getStringWidth() [2/2]

int Graphics::Font::getStringWidth ( const Common::U32String str) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ wordWrapText() [1/3]

int Graphics::Font::wordWrapText ( const Common::String str,
int  maxWidth,
Common::Array< Common::String > &  lines,
int  initWidth = 0,
uint32  mode = kWordWrapOnExplicitNewLines 
) const

Word-wrap a text (that can contain newline characters) so that no text line is wider than maxWidth pixels.

If necessary, additional line breaks are generated, preferably between words, where whitespace is. The resulting lines are appended to the lines string list. This returns the maximal width of any of the new lines (i.e. a value that is smaller or equal to maxWidth).

Parameters
strThe string to word-wrap.
maxWidthMaximum width that a line can have.
linesThe string list to which the text lines from str are appended.
initWidthStarting width of the first line, for partially filled lines (optional).
modeWrapping mode. A bitfield of WordWrapMode values.
Returns
The maximal width of any of the lines added to lines.

◆ wordWrapText() [2/3]

int Graphics::Font::wordWrapText ( const Common::U32String str,
int  maxWidth,
Common::Array< Common::U32String > &  lines,
int  initWidth = 0,
uint32  mode = kWordWrapOnExplicitNewLines 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ wordWrapText() [3/3]

int Graphics::Font::wordWrapText ( const Common::U32String str,
int  maxWidth,
Common::Array< Common::U32String > &  lines,
Common::Array< bool > &  lineContinuation,
int  initWidth = 0,
uint32  mode = kWordWrapOnExplicitNewLines 
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Word-wrap a text, and returns in lineCountination a list of lines where a word has been splitted into the next line.

Parameters
lineContinuationBool list. If the ith element of the list is true, then the ith line in lines contains a splitted word.

◆ scaleSingleGlyph()

void Graphics::Font::scaleSingleGlyph ( Surface scaleSurface,
int *  grayScaleMap,
int  grayScaleMapSize,
int  width,
int  height,
int  xOffset,
int  yOffset,
int  grayLevel,
int  chr,
int  srcheight,
int  srcwidth,
float  scale 
) const

Scales the single gylph at chr the given the scale and the pointer grayScaleMap to the grayscale array. It fills scaleSurface surface and then we draw the character on scaleSurface surface. The scaleSUrface is magnified to grayScale array and then we change the scaleSurface using the grayScale array and grayLevel.

Parameters
grayScaleMapThe pointer to the grayScale array.
grayScaleMapSizeThe size of the grayScale array.
scaleSurfaceThe surface to where character is scaled and drawn.
widthThe width of the bouding box for scaled glyph.
heightThe height of the bounding box for scaled glyph.
grayLevelThe graylevel is the threshold value above which the pixel is considered
chrThe character to scale.
xOffsetThe x offset of the bounding box for scaled glyph.
yOffsetThe y offset of the bounding box for scaled glyph.
srcheightThe height of the source glyph.
srcwidthThe width of the source glyph bounding box.
scaleThe scale factor that is equal to newSize / srcSize of initializeScaling.

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