TTFont.new: Difference between revisions

From GiderosMobile
Created page with "__NOTOC__ '''Available since:''' Gideros 2011.6<br/> === Description === <br /> Creates a new `TTFont` object.<br /> <br /> Starting from gideros 2017.9, 'text' optional param..."
 
No edit summary
 
(24 intermediate revisions by 5 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
'''Available since:''' Gideros 2011.6<br/>
'''Available since:''' Gideros 2011.6<br/>
'''Class:''' [[TTFont]]<br/>
=== Description ===
=== Description ===
<br />
Creates a new '''TTFont''' object.
Creates a new `TTFont` object.<br />
<syntaxhighlight lang="lua">
<br />
TTFont.new(filename,size,text,filtering,outlineSize)
Starting from gideros 2017.9, 'text' optional parameter can be the empty string, in which case Gideros will automatically cache characters as they are used.
</syntaxhighlight>
Also, 2017.9 allows filename to be a table of several file names and associated size factor.  
 
Two forms are accepted: {"font1.ttf","font2.ttf",..} or {{file="font1.ttf", sizeMult=1},{file="font2.ttf", sizeMult=1.1},...}.
=== Parameters ===
'''filename''': (string) the name of the TTF file to be loaded. OTF files seem to be supported as well<br/>
'''size''': (number) size of the font<br/>
'''text''': (string, optional) if specified, TTFont caches the characters of specified text to speed up the rendering. If instead of specified symbols empty quotes "" are provided, then all font symbols are cached<br/>
'''filtering''': (boolean, default = false) or (positive number, default = 0) whether or not the font texture is filtered '''optional'''<br/>
'''outlineSize''': (number) if set, the font will be rendered with an outline of the given size '''optional'''<br/>
 
Starting from gideros 2017.9, 'text' optional parameter can be an empty string '''""''', in which case Gideros will automatically cache characters as they are used.
 
Also, 2017.9 allows ''filename'' to be a table of several file names and associated size factor.
 
Two forms are accepted:
<syntaxhighlight lang="lua">{"font1.ttf","font2.ttf",..}</syntaxhighlight>
or  
<syntaxhighlight lang="lua">{{file="font1.ttf", sizeMult=1},{file="font2.ttf", sizeMult=1.1},...}</syntaxhighlight>
 
Characters will be looked up in each file in sequence until a glyph is found.
Characters will be looked up in each file in sequence until a glyph is found.
<source lang="lua">
 
= TTFont.new(filenamesizetextfilteringoutlineSize,)
=== Example ===
</source>
<syntaxhighlight lang="lua">
'''filename:''' (string) The name of the TTF file to be loaded ''''''<br/>
local ttf = TTFont.new("fonts/Cabin-Italic-TTF.ttf", 64)
'''size:''' (number) size of the font ''''''<br/>
local tf = TextField.new(ttf, "hello Gideros!")
'''text:''' (string, optional) if specified, TTFont caches the characters of specified text to speed up the rendering ''''''<br/>
tf:setPosition(4*32, 4*32)
'''filtering:''' (boolean, default = false) Whether or not the font texture is filtered '''optional'''<br/>
stage:addChild(tf)
'''outlineSize:''' (number) If set, the font will be rendered with an outline of the given size '''optional'''<br/>
</syntaxhighlight>
 
{{TTFont}}

Latest revision as of 21:37, 8 October 2026

Available since: Gideros 2011.6
Class: TTFont

Description

Creates a new TTFont object.

TTFont.new(filename,size,text,filtering,outlineSize)

Parameters

filename: (string) the name of the TTF file to be loaded. OTF files seem to be supported as well
size: (number) size of the font
text: (string, optional) if specified, TTFont caches the characters of specified text to speed up the rendering. If instead of specified symbols empty quotes "" are provided, then all font symbols are cached
filtering: (boolean, default = false) or (positive number, default = 0) whether or not the font texture is filtered optional
outlineSize: (number) if set, the font will be rendered with an outline of the given size optional

Starting from gideros 2017.9, 'text' optional parameter can be an empty string "", in which case Gideros will automatically cache characters as they are used.

Also, 2017.9 allows filename to be a table of several file names and associated size factor.

Two forms are accepted:

{"font1.ttf","font2.ttf",..}

or

{{file="font1.ttf", sizeMult=1},{file="font2.ttf", sizeMult=1.1},...}

Characters will be looked up in each file in sequence until a glyph is found.

Example

local ttf = TTFont.new("fonts/Cabin-Italic-TTF.ttf", 64)
local tf = TextField.new(ttf, "hello Gideros!")
tf:setPosition(4*32, 4*32)
stage:addChild(tf)