Difference between revisions of "CompositeFont.new"

From GiderosMobile
(made it more clear to use curly braces)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
+
'''Available since:''' Gideros 2019.1<br/>
'''<translate>Available since</translate>:''' Gideros 2019.1<br/>
+
'''Class:''' [[CompositeFont]]<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/CompositeFont|CompositeFont]]<br/>
 
  
=== <translate>Description</translate> ===
+
=== Description ===
Creates a new [[Special:MyLanguage/CompositeFont|CompositeFont]] object.
+
Creates a new '''CompositeFont''' object.
 +
<syntaxhighlight lang="lua">
 +
CompositeFont.new(definition)
 +
</syntaxhighlight>
  
 
Each layer of the composited font is defined by a table. The following fields are possible:
 
Each layer of the composited font is defined by a table. The following fields are possible:
* font: The font object to use for this layer (mandatory)
+
* '''font''': the font object to use for this layer (mandatory)
* color: The color to use when rendering this layer
+
* '''color''': the color to use when rendering this layer
* alpha: The alpha value to use with the color
+
* '''alpha''': the alpha value to use with the color (since Gideros 2023.9 if you pass a color you '''MUST''' pass its alpha as well)
* x: The X offset to apply
+
* '''x''': the X offset to apply (can be a negative value)
* y: The Y offset to apply
+
* '''y''': the Y offset to apply (can be a negative value)
 +
* '''name''': a name for this layer ('''since 2021.9''')
  
 
'''Note''': TTFont without any character list specification aren't supported in composite fonts.
 
'''Note''': TTFont without any character list specification aren't supported in composite fonts.
  
<source lang="lua">
+
=== Parameters ===
CompositeFont.new{definition} -- * please notice the curly braces instead of the parenthesis *
+
'''definition''': (table) a list of layer definition tables<br/>
</source>
 
  
'''Note 2''': CompositeFont uses curly braces '''{ }''' instead of parentheses ( ).
+
=== Example ===
 
+
'''Drawing a black outline''':
=== <translate>Parameters</translate> ===
+
<syntaxhighlight lang="lua">
'''definition''': (table) <translate>A list of layer definition tables</translate><br/>
+
local str = "My Composite Font text"
 +
local nf = TTFont.new("fonts/Tahoma.ttf", 32, str, true) --Normal
 +
local of = TTFont.new("fonts/Tahoma.ttf", 32, str, true, 3) --Outlined
 +
local cf= CompositeFont.new{ -- *** PLEASE NOTICE THE CURLY BRACES { } INSTEAD OF ( ) ***
 +
{ font=of, color=0x0, alpha=1, }, -- draw outline in black
 +
{ font=nf, x=1, y=2, }, -- draw normal text with an offset
 +
}
 +
local tf = TextField.new(cf, str)
 +
tf:setTextColor(0xff0000)
 +
tf:setPosition(16, 64)
 +
stage:addChild(tf)
 +
</syntaxhighlight>
  
 
{{CompositeFont}}
 
{{CompositeFont}}

Latest revision as of 03:17, 29 November 2024

Available since: Gideros 2019.1
Class: CompositeFont

Description

Creates a new CompositeFont object.

CompositeFont.new(definition)

Each layer of the composited font is defined by a table. The following fields are possible:

  • font: the font object to use for this layer (mandatory)
  • color: the color to use when rendering this layer
  • alpha: the alpha value to use with the color (since Gideros 2023.9 if you pass a color you MUST pass its alpha as well)
  • x: the X offset to apply (can be a negative value)
  • y: the Y offset to apply (can be a negative value)
  • name: a name for this layer (since 2021.9)

Note: TTFont without any character list specification aren't supported in composite fonts.

Parameters

definition: (table) a list of layer definition tables

Example

Drawing a black outline:

local str = "My Composite Font text"
local nf = TTFont.new("fonts/Tahoma.ttf", 32, str, true) --Normal
local of = TTFont.new("fonts/Tahoma.ttf", 32, str, true, 3) --Outlined
local cf= CompositeFont.new{ -- *** PLEASE NOTICE THE CURLY BRACES { } INSTEAD OF ( ) ***
	{ font=of, color=0x0, alpha=1, }, -- draw outline in black
	{ font=nf, x=1, y=2, }, -- draw normal text with an offset
}
local tf = TextField.new(cf, str)
tf:setTextColor(0xff0000)
tf:setPosition(16, 64)
stage:addChild(tf)