Difference between revisions of "Lua:Class:Font"

From Cheat Engine
Jump to navigation Jump to search
(Major overhaul of the post.)
 
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''Font Class''': (Inheritance: ''[[Lua:Class:Object|Object]]'')
+
{{Class|'''class''' Font ''':''' CustomFont}}
  
===Related global functions===
+
The Font class represents a font object used by GUI controls and drawing surfaces.
createFont(): Returns a font object (default initialized based on the main ce window)
+
 
 +
A Font inherits from CustomFont, CanvasHelper, and Object. Font objects can be created with [[Lua:createFont|createFont]] and can also be accessed through properties such as Control.Font or Canvas.Font.
 +
 
 +
===Inheritance===
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Class
 +
!align="left"|Inherits From
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|Font
 +
|CustomFont
 +
|Represents a configurable font object.
 +
|-
 +
|CustomFont
 +
|CanvasHelper
 +
|Base class for font handling.
 +
|-
 +
|CanvasHelper
 +
|[[Lua:Class:Object|Object]]
 +
|Base class for canvas-related helper objects.
 +
|}
 +
 
 +
===Related Function===
 +
{{CodeBox|'''function''' createFont() ''':''' Font}}
 +
 
 +
Returns a new Font object. The created font is initialized based on the main Cheat Engine window.
  
 
===Properties===
 
===Properties===
  Name: string
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
  Size: integer
+
!align="left"|Property
  Height: integer
+
!align="left"|Type
  Orientation: integer
+
!style="width: 80%;background-color:white;" align="left"|Description
  Pitch: string - 'fpDefault', 'fpVariable', 'fpFixed'
+
|-
  Color: integer
+
|Name
  CharSet: integer
+
|String
  Quality: string - 'fqDefault', 'fqDraft', 'fqProof', 'fqNonAntialiased', 'fqAntialiased', 'fqCleartype', 'fqCleartypeNatural'
+
|The font name.
  Style: string set - ['fsBold', 'fsItalic', 'fsStrikeOut', 'fsUnderline']
+
|-
 +
|Size
 +
|Integer
 +
|The font size.
 +
|-
 +
|Height
 +
|Integer
 +
|The font height.
 +
|-
 +
|Orientation
 +
|Integer
 +
|The font orientation.
 +
|-
 +
|Pitch
 +
|String
 +
|The font pitch. See [[#Pitch Values|Pitch Values]].
 +
|-
 +
|Color
 +
|Integer
 +
|The font color.
 +
|-
 +
|CharSet
 +
|Integer
 +
|The font character set.
 +
|-
 +
|Quality
 +
|String
 +
|The font quality. See [[#Quality Values|Quality Values]].
 +
|-
 +
|Style
 +
|String set
 +
|The font style set. See [[#Style Values|Style Values]].
 +
|}
  
 
===Methods===
 
===Methods===
  assign(font): Copies the contents of the font given as parameter to this font  
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Method
 +
!align="left"|Return Type
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|getName()
 +
|String
 +
|Gets the font name of the font.
 +
|-
 +
|setName(name)
 +
|void
 +
|Sets the font name of the font.
 +
|-
 +
|getSize()
 +
|Integer
 +
|Gets the size of the font.
 +
|-
 +
|setSize(size)
 +
|void
 +
|Sets the size of the font.
 +
|-
 +
|getColor()
 +
|Integer
 +
|Gets the color of the font.
 +
|-
 +
|setColor(color)
 +
|void
 +
|Sets the color of the font.
 +
|-
 +
|assign(font)
 +
|void
 +
|Copies the contents of the given font to this font.
 +
|}
  
 +
===Pitch Values===
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Value
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|fpDefault
 +
|Default font pitch.
 +
|-
 +
|fpVariable
 +
|Variable-width font pitch.
 +
|-
 +
|fpFixed
 +
|Fixed-width font pitch.
 +
|}
 +
 +
===Quality Values===
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Value
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|fqDefault
 +
|Default font quality.
 +
|-
 +
|fqDraft
 +
|Draft font quality.
 +
|-
 +
|fqProof
 +
|Proof font quality.
 +
|-
 +
|fqNonAntialiased
 +
|Non-antialiased font quality.
 +
|-
 +
|fqAntialiased
 +
|Antialiased font quality.
 +
|-
 +
|fqCleartype
 +
|ClearType font quality.
 +
|-
 +
|fqCleartypeNatural
 +
|Natural ClearType font quality.
 +
|}
 +
 +
===Style Values===
 +
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 +
!align="left"|Value
 +
!style="width: 80%;background-color:white;" align="left"|Description
 +
|-
 +
|fsBold
 +
|Bold text.
 +
|-
 +
|fsItalic
 +
|Italic text.
 +
|-
 +
|fsStrikeOut
 +
|Strikeout text.
 +
|-
 +
|fsUnderline
 +
|Underlined text.
 +
|}
 +
 +
===Examples===
 +
 +
====Create a Font object====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
local font = createFont()
 +
 +
print(font.Name)
 +
</syntaxhighlight>
 +
 +
====Set font properties====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
local font = createFont()
 +
 +
font.Name = "Consolas"
 +
font.Size = 12
 +
font.Color = 0x0000FF
 +
font.Style = "[fsBold]"
 +
</syntaxhighlight>
 +
 +
====Use getter and setter methods====
 +
<syntaxhighlight lang="lua" line highlight="1,3,4,6">
 +
local font = createFont()
 +
 +
font.setName("Consolas")
 +
font.setSize(14)
 +
 +
print(font.getName())
 +
print(font.getSize())
 +
</syntaxhighlight>
 +
 +
====Set font pitch and quality====
 +
<syntaxhighlight lang="lua" line highlight="1">
 +
local font = createFont()
 +
 +
font.Name = "Consolas"
 +
font.Pitch = "fpFixed"
 +
font.Quality = "fqCleartype"
 +
</syntaxhighlight>
 +
 +
====Assign a font to a label====
 +
<syntaxhighlight lang="lua" line highlight="4">
 +
local form = createForm()
 +
local label = createLabel(form)
 +
 +
local font = createFont()
 +
font.Name = "Consolas"
 +
font.Size = 14
 +
font.Style = "[fsBold]"
 +
font.Color = 0x0000FF
 +
 +
label.Font.assign(font)
 +
label.Caption = "Styled label"
 +
</syntaxhighlight>
 +
 +
====Copy one font to another====
 +
<syntaxhighlight lang="lua" line highlight="1,7,13">
 +
local sourceFont = createFont()
 +
sourceFont.Name = "Consolas"
 +
sourceFont.Size = 12
 +
sourceFont.Style = "[fsBold]"
 +
sourceFont.Color = 0x0000FF
 +
 +
local targetFont = createFont()
 +
targetFont.assign(sourceFont)
 +
 +
print(targetFont.Name)
 +
print(targetFont.Size)
 +
 +
sourceFont.destroy()
 +
targetFont.destroy()
 +
</syntaxhighlight>
 +
 +
====Use a font with Canvas text====
 +
<syntaxhighlight lang="lua" line highlight="8">
 +
local form = createForm()
 +
form.Width = 300
 +
form.Height = 160
 +
 +
form.OnPaint = function(sender)
 +
  local canvas = sender.Canvas
 +
 +
  canvas.Font.Name = "Consolas"
 +
  canvas.Font.Size = 14
 +
  canvas.Font.Color = 0x0000FF
 +
  canvas.Font.Style = "[fsBold]"
 +
 +
  canvas.textOut(20, 40, "Canvas text")
 +
end
 +
 +
form.show()
 +
</syntaxhighlight>
 +
 +
====Restore a control font====
 +
<syntaxhighlight lang="lua" line highlight="1,4,10">
 +
local oldFont = createFont()
 +
oldFont.assign(MainForm.Font)
 +
 +
MainForm.Font.Name = "Consolas"
 +
MainForm.Font.Size = 12
 +
MainForm.Font.Style = "[fsBold]"
 +
 +
sleep(1000)
 +
 +
MainForm.Font.assign(oldFont)
 +
oldFont.destroy()
 +
</syntaxhighlight>
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
 +
 +
{{Forms}}

Latest revision as of 19:58, 25 June 2026

{} Class

class Font : CustomFont

The Font class represents a font object used by GUI controls and drawing surfaces.

A Font inherits from CustomFont, CanvasHelper, and Object. Font objects can be created with createFont and can also be accessed through properties such as Control.Font or Canvas.Font.

Inheritance[edit]

Class Inherits From Description
Font CustomFont Represents a configurable font object.
CustomFont CanvasHelper Base class for font handling.
CanvasHelper Object Base class for canvas-related helper objects.

Related Function[edit]

<> Lua API Reference

function createFont() : Font

Returns a new Font object. The created font is initialized based on the main Cheat Engine window.

Properties[edit]

Property Type Description
Name String The font name.
Size Integer The font size.
Height Integer The font height.
Orientation Integer The font orientation.
Pitch String The font pitch. See Pitch Values.
Color Integer The font color.
CharSet Integer The font character set.
Quality String The font quality. See Quality Values.
Style String set The font style set. See Style Values.

Methods[edit]

Method Return Type Description
getName() String Gets the font name of the font.
setName(name) void Sets the font name of the font.
getSize() Integer Gets the size of the font.
setSize(size) void Sets the size of the font.
getColor() Integer Gets the color of the font.
setColor(color) void Sets the color of the font.
assign(font) void Copies the contents of the given font to this font.

Pitch Values[edit]

Value Description
fpDefault Default font pitch.
fpVariable Variable-width font pitch.
fpFixed Fixed-width font pitch.

Quality Values[edit]

Value Description
fqDefault Default font quality.
fqDraft Draft font quality.
fqProof Proof font quality.
fqNonAntialiased Non-antialiased font quality.
fqAntialiased Antialiased font quality.
fqCleartype ClearType font quality.
fqCleartypeNatural Natural ClearType font quality.

Style Values[edit]

Value Description
fsBold Bold text.
fsItalic Italic text.
fsStrikeOut Strikeout text.
fsUnderline Underlined text.

Examples[edit]

Create a Font object[edit]

1 local font = createFont()
2 
3 print(font.Name)

Set font properties[edit]

1 local font = createFont()
2 
3 font.Name = "Consolas"
4 font.Size = 12
5 font.Color = 0x0000FF
6 font.Style = "[fsBold]"

Use getter and setter methods[edit]

1 local font = createFont()
2 
3 font.setName("Consolas")
4 font.setSize(14)
5 
6 print(font.getName())
7 print(font.getSize())

Set font pitch and quality[edit]

1 local font = createFont()
2 
3 font.Name = "Consolas"
4 font.Pitch = "fpFixed"
5 font.Quality = "fqCleartype"

Assign a font to a label[edit]

 1 local form = createForm()
 2 local label = createLabel(form)
 3 
 4 local font = createFont()
 5 font.Name = "Consolas"
 6 font.Size = 14
 7 font.Style = "[fsBold]"
 8 font.Color = 0x0000FF
 9 
10 label.Font.assign(font)
11 label.Caption = "Styled label"

Copy one font to another[edit]

 1 local sourceFont = createFont()
 2 sourceFont.Name = "Consolas"
 3 sourceFont.Size = 12
 4 sourceFont.Style = "[fsBold]"
 5 sourceFont.Color = 0x0000FF
 6 
 7 local targetFont = createFont()
 8 targetFont.assign(sourceFont)
 9 
10 print(targetFont.Name)
11 print(targetFont.Size)
12 
13 sourceFont.destroy()
14 targetFont.destroy()

Use a font with Canvas text[edit]

 1 local form = createForm()
 2 form.Width = 300
 3 form.Height = 160
 4 
 5 form.OnPaint = function(sender)
 6   local canvas = sender.Canvas
 7 
 8   canvas.Font.Name = "Consolas"
 9   canvas.Font.Size = 14
10   canvas.Font.Color = 0x0000FF
11   canvas.Font.Style = "[fsBold]"
12 
13   canvas.textOut(20, 40, "Canvas text")
14 end
15 
16 form.show()

Restore a control font[edit]

 1 local oldFont = createFont()
 2 oldFont.assign(MainForm.Font)
 3 
 4 MainForm.Font.Name = "Consolas"
 5 MainForm.Font.Size = 12
 6 MainForm.Font.Style = "[fsBold]"
 7 
 8 sleep(1000)
 9 
10 MainForm.Font.assign(oldFont)
11 oldFont.destroy()

Main Pages

Core Lua documentation entry points

Lua
Script Engine

Form Related Classes