Class 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

class Font ;

Constructors

NameDescription
this Constructs a font from a font file
this Constructs a font from an already existing TTF_Font

Properties

NameTypeDescription
ascent[get] intGets the maximum pixel ascent of all glyphs in this font Ascent is the distance from the top of the glyph to the baseline
descent[get] intGets the maximum pixel descent of all glyphs in this font Descent is the distance from the bottom of the glyph to the baseline
faces[get] longGets the number of faces in this font Faces are sub-fonts that vary slightly from the main font
familyName[get] stringGets the font face family name (Times, Courier, etc.) Returns null if not available
handle[get] derelict.sdl2.ttf.TTF_Font*Returns the raw SDL data of this object
height[get] intGets the maximum pixel height of all glyphs in this font Useful for multiline printing
hinting[set] intSets 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
hinting[get] intGets 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[get] boolChecks 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[set] boolSets 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[get] boolGets 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[get] intGets 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[set] intSets the size of the font's outline Use outline = 0 to disable outlining
outline[get] intGets the size of the font's outline Outline is constant across glyphs in a font
style[set] intSets 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[get] intGets 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[get] stringGets the font face style name (Sans, Serif, etc.) Returns null if not available

Methods

NameDescription
advanceOffset 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 Checks if the font supports the given glyph
maximumOffset 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 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 Gets a rectangle describing the offset of the given glyph Width of the rectangle is width of the glyph
renderGlyphBlended Renders a glyph very slowly but with very high quality See renderTextBlended
renderGlyphShaded Renders a glyph slowly but smoothly See renderTextShaded
renderGlyphSolid Renders a glyph quickly See renderTextSolid
renderTextBlended 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 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 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

TODO

allow for multiline printing