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

Summary

Actions Summary Table

ActionsDescription
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.
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
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.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
GetEmSize()This action returns the EM size of the font.
GetHashCode()This action gets the hash code for an object.
GetMaxXSize()This action returns the maximum distance between two points of the glyph, on the x-axis.
GetMaxYSize()This action returns the maximum distance between two points of the glyph, on the y-axis.
GetSize()This action returns the pixel size of the glyph.
GetXDotsPerInch()This action returns the dots per inch along the x-axis of the display.
GetYDotsPerInch()This action returns the dots per inch along the y-axis of the display.
SetEmSize(integer emSize)This action sets the EM size of the font.
SetMaxXSize(integer maxSizeX)This action sets the maximum distance between two points of the glyph, on the x-axis.
SetMaxYSize(integer maxSizeY)This action sets the maximum distance between two points of the glyph, on the y-axis.
SetPointSize(integer pointSize)This action sets the point size used for the glyph, such as 12 point font.
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.
SetXDotsPerInch(integer xDPI)This action sets the dots per inch along the x-axis of the display.
SetYDotsPerInch(integer yDPI)This action sets the dots per inch along the y-axis of the display.

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.

Example Code

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

Parameters

Return

integer: Returns the scaled coordinate position of a coordinate.

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.

Example Code

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

Parameters

Return

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

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.

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

Parameters

Return

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

Equals(Libraries.Language.Object object)

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

Example Code

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

Parameters

Return

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

GetEmSize()

This action returns the EM size of the font.

Example Code

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

Return

integer: Returns the EM size of the font.

GetHashCode()

This action gets the hash code for an object.

Example Code

Object o
        integer hash = o:GetHashCode()

Return

integer: The integer hash code of the object.

GetMaxXSize()

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

Example Code

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

Return

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

GetMaxYSize()

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

Example Code

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

Return

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

GetSize()

This action returns the pixel size of the glyph.

Example Code

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

Return

integer: Returns the pixel size of the glyph.

GetXDotsPerInch()

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

Example Code

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

Return

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

GetYDotsPerInch()

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

Example Code

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

Return

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

SetEmSize(integer emSize)

This action sets the EM size of the font.

Example Code

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

Parameters

SetMaxXSize(integer maxSizeX)

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

Example Code

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

Parameters

SetMaxYSize(integer maxSizeY)

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

Example Code

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

Parameters

SetPointSize(integer pointSize)

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

Example Code

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

Parameters

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.

Example Code

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

Parameters

SetXDotsPerInch(integer xDPI)

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

Example Code

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

Parameters

SetYDotsPerInch(integer yDPI)

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

Example Code

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

Parameters