Printer

Printer

new Printer(texture)

文字打印机对象

Source:
Parameters:
Name Type Description
texture Texture

打印机纹理

Members

alignmentFactorX :number

水平对齐系数

Source:
Type:
  • number

alignmentFactorY :number

垂直对齐系数

Source:
Type:
  • number

breakable :boolean

是否可以换行

Source:
Type:
  • boolean

buffer :string

打印的文本缓冲

Source:
Type:
  • string

canvas :HTMLCanvasElement

用来绘制文字的2D画布

Source:
Type:
  • HTMLCanvasElement

colors :Array.<number>

打印文字颜色列表

Source:
Type:

commands :Array.<Object>

打印指令列表

Source:
Type:

content :string

打印的全部文本内容

Source:
Type:
  • string

context :CanvasRenderingContext2D

用来绘制文字的2D图形上下文

Source:
Type:
  • CanvasRenderingContext2D

direction :string

文字打印方向

Source:
Type:
  • string

effects :Array.<Object>

打印文字效果列表

Source:
Type:

fonts :Array.<string>

打印字体列表

Source:
Type:

height :number

当前打印区域高度

Source:
Type:
  • number

horizontal :boolean

是否水平方向打印

Source:
Type:
  • boolean

horizontalAlign :string

水平对齐模式

Source:
Type:
  • string

images :Array.<ImageElement>

图像列表

Source:
Type:

index :number

当前打印的字符索引

Source:
Type:
  • number

letterSpacing :number

字间距

Source:
Type:
  • number

lineHeight :number

当前打印文本行的行高

Source:
Type:
  • number

lineSpacing :number

当前打印文本行的行间距

Source:
Type:
  • number

paddingBottom :number

纹理边距(下)

Source:
Type:
  • number

paddingLeft :number

纹理边距(左)

Source:
Type:
  • number

paddingRight :number

纹理边距(右)

Source:
Type:
  • number

paddingTop :number

纹理边距(上)

Source:
Type:
  • number

printHeight :number

打印区域高度

Source:
Type:
  • number

printWidth :number

打印区域宽度

Source:
Type:
  • number

sizes :Array.<number>

打印字体大小列表

Source:
Type:

styles :Array.<string>

打印样式列表

Source:
Type:

texture :Texture

打印机纹理

Source:
Type:

truncate :boolean

是否对溢出的文字进行截断

Source:
Type:
  • boolean

verticalAlign :string

垂直对齐模式

Source:
Type:
  • string

weights :Array.<string>

打印粗细列表

Source:
Type:

width :number

当前打印区域宽度

Source:
Type:
  • number

wordWrap :boolean

是否自动换行

Source:
Type:
  • boolean

wrapEnd :number

换行包装的结束位置

Source:
Type:
  • number

x :number

当前打印位置X

Source:
Type:
  • number

y :number

当前打印位置Y

Source:
Type:
  • number

Methods

calculatePadding()

计算纹理内边距

Source:

calculateTextPosition()

计算文本位置

Source:

destroy()

销毁

Source:

draw(content)

绘制文本

Source:
Parameters:
Name Type Description
content string

文本内容

drawBuffer()

绘制缓冲字符串

Source:

executeCommands()

执行绘制指令

Source:

getRawX()

获取原生的水平位置

Source:

getRawY()

获取原生的垂直位置

Source:

getScaledLetterSpacing()

获取缩放后的字间距

Source:

getScaledLineSpacing()

获取缩放后的行间距

Source:

getScaledPrintHeight()

获取缩放后的打印高度

Source:

getScaledPrintWidth()

获取缩放后的打印宽度

Source:

getScaledSize()

获取缩放后的字体大小

Source:

loadImage()

加载图像

Source:

matchTag() → {boolean}

匹配富文本标签

Source:
Returns:
Type:
boolean

是否成功匹配标签

measureHeight(string) → {number}

测量字符串像素高度

Source:
Parameters:
Name Type Description
string string

目标字符串

Returns:
Type:
number

measureWidth(string) → {number}

测量字符串像素宽度

Source:
Parameters:
Name Type Description
string string

目标字符串

Returns:
Type:
number

newLine()

换行

Source:

reset() → {Printer}

重置打印机上下文

Source:
Returns:
Type:
Printer

updateFont()

更新打印机字体

Source:

(static) drawText(2D上下文, command, text)

绘制文字

Source:
Parameters:
Name Type Description
2D上下文 CanvasRenderingContext2D
command Object

打印机指令

text string

文本内容

(static) drawTextWithOutline(2D上下文, command, text)

绘制带轮廓线的文字

Source:
Parameters:
Name Type Description
2D上下文 CanvasRenderingContext2D
command Object

打印机指令

text string

文本内容

(static) drawTextWithShadow(2D上下文, command, text)

绘制带阴影的文字

Source:
Parameters:
Name Type Description
2D上下文 CanvasRenderingContext2D
command Object

打印机指令

text string

文本内容

(static) drawTextWithStroke(2D上下文, command, text)

绘制描边的文字

Source:
Parameters:
Name Type Description
2D上下文 CanvasRenderingContext2D
command Object

打印机指令

text string

文本内容

(static) fetchCommand() → {Object}

获取打印机指令

Source:
Returns:
Type:
Object

(static) importFonts(imports) → {Promise}

导入字体

Source:
Parameters:
Name Type Description
imports Array.<string>

导入字体文件ID列表

Returns:
Type:
Promise

(static) initialize() → {Promise}

初始化打印机相关数据

Source:
Returns:
Type:
Promise

(static) loadDefault() → {Promise}

加载默认设置

Source:
Returns:
Type:
Promise

(static) parseEffect(effect) → {Object}

解析文字效果

Source:
Parameters:
Name Type Description
effect Object

文字效果数据对象

Returns:
Type:
Object

解析后的文字效果对象

(static) resetCommands()

重置打印机指令

Source:

(static) restoreTexture()

恢复打印机纹理

Source: