Font

Fonts are contexts for displaying strings Fonts describe how each character in the string looks and how they are spaced Each font includes a collection of supported glyphs and general information TODO: allow for multiline printing

Constructors

this
this(string file, int psize, int index = 0)

Constructs a font from a font file

this
this(TTF_Font* alreadyExisting)

Constructs a font from an already existing TTF_Font

Destructor

~this
~this()

Ensures that SDL_TTF can dispose of this font

Members

Functions

advanceOffset
int advanceOffset(char glyph)

Gets the advance offset of the glyph The advance offset is the distance the pen must be shifted after drawing a glyph Controls spacing between glyphs on an individual basis

isProvided
bool isProvided(char glyph)

Checks if the font supports the given glyph

maximumOffset
iVector maximumOffset(char glyph)

Gets the maximum offset of the glyph Returns the top right corner of the rectangle in which the glyph is inscribed in Cartesian coordinates

minimumOffset
iVector minimumOffset(char glyph)

Gets the minimum offset of the glyph Returns the bottom left corner of the rectangle in which the glyph is inscribed in Cartesian coordinates

offset
iRectangle offset(char glyph)

Gets a rectangle describing the offset of the given glyph Width of the rectangle is width of the glyph

renderGlyphBlended
Surface renderGlyphBlended(char glyph, Color color = Color(0, 0, 0))

Renders a glyph very slowly but with very high quality See renderTextBlended

renderGlyphShaded
Surface renderGlyphShaded(char glyph, Color foreground, Color background)

Renders a glyph slowly but smoothly See renderTextShaded

renderGlyphSolid
Surface renderGlyphSolid(char glyph, Color color = Color(0, 0, 0))

Renders a glyph quickly See renderTextSolid

renderTextBlended
Surface renderTextBlended(string text, Color color = Color(0, 0, 0), Encoding T = Encoding.UTF8)

Renders the text in high quality on a 32-bit ARGB surface, using alpha blending to dither the font with the given color The surface has alpha transparency Renders about as slowly as the Shaded render method, but blits more slowly than Solid and Shaded

renderTextShaded
Surface renderTextShaded(string text, Color foreground, Color background, Encoding T = Encoding.UTF8)

Renders the text with a given color on an 8-bit palettized surface with a given background color Text is smooth but renders slowly Surface blits as fast as the Solid render method once it is made

renderTextSolid
Surface renderTextSolid(string text, Color color = Color(0, 0, 0), Encoding T = Encoding.UTF8)

Renders the text on an 8-bit palettized surface with the given color Background is transparent Text is less smooth than other render options This is the fastest rendering speed, and color can be changed without having to render again

Properties

ascent
int ascent [@property getter]

Gets the maximum pixel ascent of all glyphs in this font Ascent is the distance from the top of the glyph to the baseline

descent
int descent [@property getter]

Gets the maximum pixel descent of all glyphs in this font Descent is the distance from the bottom of the glyph to the baseline

faces
long faces [@property getter]

Gets the number of faces in this font Faces are sub-fonts that vary slightly from the main font

familyName
string familyName [@property getter]

Gets the font face family name (Times, Courier, etc.) Returns null if not available

handle
TTF_Font* handle [@property getter]

Returns the raw SDL data of this object

height
int height [@property getter]

Gets the maximum pixel height of all glyphs in this font Useful for multiline printing

hinting
int hinting [@property setter]

Sets the font's hinting type Type is taken as a value matching one of the following: TTF_HINTING_NORMAL TTF_HINTING_LIGHT TTF_HINTING_MONO TTF_HINTING_NONE Hinting type is how the font is programmed to map onto the pixels on a screen Note: the method flushes the internal cache of glyphs in the font, even if there is no change in hinting It may be useful to first check the font's hinting type

hinting
int hinting [@property getter]

Gets the font's hinting type Type is returned as a value matching one of the following: TTF_HINTING_NORMAL TTF_HINTING_LIGHT TTF_HINTING_MONO TTF_HINTING_NONE Type defaults to TTF_HINTING_NORMAL if no type has been set Hinting type is how the font is programmed to map onto the pixels on a screen

isFixedWidth
bool isFixedWidth [@property getter]

Checks if the current font face of this font is fixed-width Fixed-width fonts are monospace - each character is the same length The pixel length of a string of fixed-width characters is the width of the characters times the amount of characters

kerning
bool kerning [@property setter]

Sets the font's kerning setting Default for newly created fonts is true Kerning setting determines whether the spacing between individual characters is adjusted for a more pleasing result

kerning
bool kerning [@property getter]

Gets the font's kerning setting Default for a newly created fonts is true Kerning setting determines whether the spacing between individual characters is adjusted for a more pleasing result

lineSkip
int lineSkip [@property getter]

Gets the recommended pixel height of a line of text in this font This represents the distance from the baseline to the top of the line Line skip should be larger than height in most cases

outline
int outline [@property setter]

Sets the size of the font's outline Use outline = 0 to disable outlining

outline
int outline [@property getter]

Gets the size of the font's outline Outline is constant across glyphs in a font

style
int style [@property setter]

Sets the style (bold, italic, etc.) of this font Style should be inputted as a bitmask composed of: TTF_STYLE_BOLD TTF_STYLE_ITALIC TTF_STYLE_UNDERLINE TTF_STYLE_STRIKETHROUGH If the style is normal, use TTF_STYLE_NORMAL For multiple styles, use a bitwise OR operator (TTF_STYLE_BOLD|TTF_STYLE_ITALIC means both bold and italic, etc.)

style
int style [@property getter]

Gets the style (bold, italic, etc.) of this font Style is returned as a bitmask composed of: TTF_STYLE_BOLD TTF_STYLE_ITALIC TTF_STYLE_UNDERLINE TTF_STYLE_STRIKETHROUGH If the style is normal, the value returned will be TTF_STYLE_NORMAL Otherwise, use bitwise and operations to get individual values (style&TTF_STYLE_BOLD returns whether the font is bold, etc.)

styleName
string styleName [@property getter]

Gets the font face style name (Sans, Serif, etc.) Returns null if not available

Meta