Appearance
@jtopo/core / FontInfo
Class: FontInfo
cavnas 设置字体只能通过一个 font 属性,
该类可以对font属性里的属性做细化操作,可以单独设置字体、字号、粗体、斜体
js
// 例如:
let fontInfo = new FontInfo('normal normal 10px sans-arial');
fontInfo.setFamily('arial');
fontInfo.setSize('15px');
fontInfo.setBold('bold');
fontInfo.setItalic('normal');
// 粗体、斜体切换
fontInfo.toogleBold();
fontInfo.toogleItalic();
node.setStyles({
font: fontInfo.toStyleFont() //->"bold normal 15px arial"
});Table of contents
Constructors
Properties
Methods
Constructors
constructor
new FontInfo(fontStr)
Parameters
| Name | Type |
|---|---|
fontStr | string |
Properties
boldWeight
boldWeight: string = 'normal'
family
family: string = 'sans-serif'
italicWeight
italicWeight: string = 'normal'
size
size: string = Config.DefaultFontSize
Methods
getFontWeight
getFontWeight(): string
获取字体权重
Returns
string
setBold
setBold(bold): void
设置加粗
Parameters
| Name | Type | Description |
|---|---|---|
bold | string | 加粗 |
Returns
void
setFamily
setFamily(family): void
设置字体
Parameters
| Name | Type | Description |
|---|---|---|
family | string | 字体 |
Returns
void
setItalic
setItalic(italic): void
设置斜体
Parameters
| Name | Type | Description |
|---|---|---|
italic | string | 斜体 |
Returns
void
setSize
setSize(size): void
设置字体大小
Parameters
| Name | Type | Description |
|---|---|---|
size | string | 字体大小 |
Returns
void
setWeight
setWeight(weight): void
设置字体权重 setFontWeight('bold')、setFontWeight('italic') setFontWeight('bold normal')、setFontWeight('normal italic')、setFontWeight('bold italic')
Parameters
| Name | Type | Description |
|---|---|---|
weight | string | 字体权重 |
Returns
void
toStyleFont
toStyleFont(): string
转换为符合canvas的样式字符串
Returns
string
toogleBold
toogleBold(): void
切换加粗
Returns
void
toogleItalic
toogleItalic(): void
切换斜体
Returns
void