Libraries.Game.Graphics.Fonts.FontRasterizer Documentation

The FontRasterizer class is used to rasterize characters. This means creating a character's outline, filling it in, and saving the drawable for display, scaled to the desired size.

Example Code

use Libraries.Game.Graphics.Fonts.all
use Libraries.Game.Game
use Libraries.Game.Graphics.Color
use Libraries.System.File

class Main is Game
    action Main
        StartGame()
    end

    action CreateGame
        FontFileReader fileReader
        File file
        // This is the working directory for fonts on Mac
        file:SetWorkingDirectory("/Library/Fonts")
        file:SetPath("Arial.ttf")
        fileReader:Load(file)
        TrueTypeFileInformation fileInformation = fileReader:GetFileInformation()
        FontRasterizer fontRasterizer
        Color color
        BezierCurveGlyphPoints glyphOutline = fileReader:GetCharacterGlyphPoints("a")
        FontDrawable fontDrawable = fontRasterizer:DrawGlyph(glyphOutline, 0, 0, color, fileInformation) 
    end
end

Inherits from: Libraries.Language.Object

Actions Documentation

CalculateScaledCoordinate(integer coordinate, integer pixelSize, integer emSize)

This action calculates and returns a scaled coordinate position of a coordinate, based on the font and screen size.

Parameters

  • integer coordinate: The coordinate to scale.
  • integer pixelSize: The font size.
  • integer emSize: The size of the EM Square.

Return

integer: Returns the scaled coordinate position of a coordinate.

Example

use Libraries.Game.Graphics.Fonts.all
use Libraries.Game.Game

class Main is Game
    action Main
        StartGame()
    end

    action CreateGame
        FontRasterizer rasterizer
        output rasterizer:CalculateScaledCoordinate(10000, 12, 2048)
    end
end

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

DrawGlyph(Libraries.Game.Graphics.Fonts.BezierCurveGlyphPoints outline, integer offsetx, integer offsety, Libraries.Game.Graphics.Color color, Libraries.Game.Graphics.Fonts.TrueTypeFileInformation information)

This action creates a pixel map of the character so that it may be drawn to the screen. It returns a FontDrawable which contains this pixel map, as well as information pertaining to the glyph.

Parameters

Return

Libraries.Game.Graphics.Fonts.FontDrawable: Returns a FontDrawable of the character, including its pixelmap.

Example

use Libraries.Game.Graphics.Fonts.all
use Libraries.Game.Game
use Libraries.Game.Graphics.Color
use Libraries.System.File

class Main is Game
    action Main
        StartGame()
    end

    action CreateGame
        FontFileReader fileReader
        File file
        // This is the working directory for fonts on Mac
        file:SetWorkingDirectory("/Library/Fonts")
        file:SetPath("Arial.ttf")
        fileReader:Load(file)
        TrueTypeFileInformation fileInformation = fileReader:GetFileInformation()
        FontRasterizer fontRasterizer
        Color color
        BezierCurveGlyphPoints glyphOutline = fileReader:GetCharacterGlyphPoints("a")
        FontDrawable fontDrawable = fontRasterizer:DrawGlyph(glyphOutline, 0, 0, color, fileInformation) 
    end
end

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

GetEmSize()

This action returns the EM size of the font.

Return

integer: Returns the EM size of the font.

Example

use Libraries.Game.Graphics.Fonts.all
use Libraries.Game.Game

class Main is Game
    action Main
        StartGame()
    end

    action CreateGame
        FontRasterizer fontRasterizer
        output fontRasterizer:GetEmSize()
    end
end

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

GetMaxXSize()

This action returns the maximum distance between two points of the glyph, on the x-axis.

Return

integer: Returns the maximum distance between two points of the glyph, on the x-axis.

Example

use Libraries.Game.Graphics.Fonts.all
use Libraries.Game.Game

class Main is Game
    action Main
        StartGame()
    end

    action CreateGame
        FontRasterizer fontRasterizer
        output fontRasterizer:GetMaxXSize()
    end
end

GetMaxYSize()

This action returns the maximum distance between two points of the glyph, on the y-axis.

Return

integer: Returns the maximum distance between two points of the glyph, on the y-axis.

Example

use Libraries.Game.Graphics.Fonts.all
use Libraries.Game.Game

class Main is Game
    action Main
        StartGame()
    end

    action CreateGame
        FontRasterizer fontRasterizer
        output fontRasterizer:GetMaxYSize()
    end
end

GetSize()

This action returns the pixel size of the glyph.

Return

integer: Returns the pixel size of the glyph.

Example

use Libraries.Game.Graphics.Fonts.all
use Libraries.Game.Game

class Main is Game
    action Main
        StartGame()
    end
    
    action CreateGame
        FontRasterizer fontRasterizer
        output fontRasterizer:GetSize()
    end
end

GetXDotsPerInch()

This action returns the dots per inch along the x-axis of the display.

Return

integer: Returns the dots per inch along the x-axis.

Example

use Libraries.Game.Graphics.Fonts.all
use Libraries.Game.Game

class Main is Game
    action Main
        StartGame()
    end
    
    action CreateGame
        FontRasterizer fontRasterizer
        output fontRasterizer:GetXDotsPerInch()
    end
end

GetYDotsPerInch()

This action returns the dots per inch along the y-axis of the display.

Return

integer: Returns the dots per inch along the y-axis.

Example

use Libraries.Game.Graphics.Fonts.all
use Libraries.Game.Game

class Main is Game
    action Main
        StartGame()
    end
    
    action CreateGame
        FontRasterizer fontRasterizer
        output fontRasterizer:GetYDotsPerInch()
    end
end

SetEmSize(integer emSize)

This action sets the EM size of the font.

Parameters

  • integer emSize: EM size of the font.

Example

use Libraries.Game.Graphics.Fonts.all
use Libraries.Game.Game

class Main is Game
    action Main
        StartGame()
    end

    action CreateGame
        FontRasterizer fontRasterizer
        fontRasterizer:SetEmSize(2048)
    end
end

SetMaxXSize(integer maxSizeX)

This action sets the maximum distance between two points of the glyph, on the x-axis.

Parameters

  • integer maxSizeX: The maximum distance between two points of the glyph, on the x-axis.

Example

use Libraries.Game.Graphics.Fonts.all
use Libraries.Game.Game

class Main is Game
    action Main
        StartGame()
    end

    action CreateGame
        FontRasterizer fontRasterizer
        fontRasterizer:SetMaxXSize(48)
    end
end

SetMaxYSize(integer maxSizeY)

This action sets the maximum distance between two points of the glyph, on the y-axis.

Parameters

  • integer maxSizeY: The maximum distance between two points of the glyph, on the y-axis.

Example

use Libraries.Game.Graphics.Fonts.all
use Libraries.Game.Game

class Main is Game
    action Main
        StartGame()
    end

    action CreateGame
        FontRasterizer fontRasterizer
        fontRasterizer:SetMaxYSize(48)
    end
end

SetPointSize(integer pointSize)

This action sets the point size used for the glyph, such as 12 point font.

Parameters

  • integer pointSize: The point size of the font.

Example

use Libraries.Game.Graphics.Fonts.all
use Libraries.Game.Game

class Main is Game
    action Main
        StartGame()
    end

    action CreateGame()
        FontRasterizer fontRasterizer
        fontRasterizer:SetPointSize(12)
    end
end

SetSize(integer size)

This action sets the pixel size, maximum distance between two points on the x-axis and maximum distance between two points on the y-axis for a glyph.

Parameters

  • integer size: The pixel size of the glyph, also used to calculate the maximum distance between two points on both axes.

Example

use Libraries.Game.Graphics.Fonts.all
use Libraries.Game.Game

class Main is Game
    action Main
        StartGame()
    end

    action CreateGame
        FontRasterizer fontRasterizer
        fontRasterizer:SetSize(14)
    end
end

SetXDotsPerInch(integer xDPI)

This action sets the dots per inch along the x-axis of the display.

Parameters

  • integer xDPI: The dots per inch along the x-axis.

Example

use Libraries.Game.Graphics.Fonts.all
use Libraries.Game.Game

class Main is Game
    action Main
        StartGame()
    end

    action CreateGame
        FontRasterizer fontRasterizer
        fontRasterizer:SetXDotsPerInch(96)
    end
end

SetYDotsPerInch(integer yDPI)

This action sets the dots per inch along the y-axis of the display.

Parameters

  • integer yDPI: The dots per inch along the y-axis.

Example

use Libraries.Game.Graphics.Fonts.all
use Libraries.Game.Game

class Main is Game
    action Main
        StartGame()
    end

    action CreateGame
        FontRasterizer fontRasterizer
        fontRasterizer:SetYDotsPerInch(96)
    end
end