@leafer-ui/text 1.0.0-rc.7 → 1.0.0-rc.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/TextConvert.ts +40 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/text",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.8",
|
|
4
4
|
"description": "@leafer-ui/text",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer-ui/core": "1.0.0-rc.
|
|
25
|
+
"@leafer-ui/core": "1.0.0-rc.8"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@leafer/interface": "1.0.0-rc.
|
|
29
|
-
"@leafer-ui/interface": "1.0.0-rc.
|
|
28
|
+
"@leafer/interface": "1.0.0-rc.8",
|
|
29
|
+
"@leafer-ui/interface": "1.0.0-rc.8"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/TextConvert.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Platform, Direction4 } from '@leafer/core'
|
|
2
2
|
|
|
3
3
|
import { ITextConvertModule, ITextData, ITextDrawData } from '@leafer-ui/interface'
|
|
4
4
|
|
|
@@ -9,6 +9,8 @@ import { clipText } from './TextClip'
|
|
|
9
9
|
import { decorationText } from './TextDecoration'
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
const { top, right, bottom, left } = Direction4
|
|
13
|
+
|
|
12
14
|
export const TextConvert: ITextConvertModule = {
|
|
13
15
|
|
|
14
16
|
getDrawData(content: string, style: ITextData): ITextDrawData {
|
|
@@ -20,17 +22,16 @@ export const TextConvert: ITextConvertModule = {
|
|
|
20
22
|
let width = style.__getInput('width') || 0
|
|
21
23
|
let height = style.__getInput('height') || 0
|
|
22
24
|
|
|
23
|
-
const { textDecoration, __font, padding } = style
|
|
25
|
+
const { textDecoration, __font, __padding: padding } = style
|
|
24
26
|
|
|
25
27
|
if (padding) {
|
|
26
|
-
const [top, right, bottom, left] = MathHelper.fourNumber(padding)
|
|
27
28
|
if (width) {
|
|
28
|
-
x = left
|
|
29
|
-
width -= (right + left)
|
|
29
|
+
x = padding[left]
|
|
30
|
+
width -= (padding[right] + padding[left])
|
|
30
31
|
}
|
|
31
32
|
if (height) {
|
|
32
|
-
y = top
|
|
33
|
-
height -= (top + bottom)
|
|
33
|
+
y = padding[top]
|
|
34
|
+
height -= (padding[top] + padding[bottom])
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
|
|
@@ -43,6 +44,8 @@ export const TextConvert: ITextConvertModule = {
|
|
|
43
44
|
|
|
44
45
|
createRows(drawData, content, style) // set rows, paraNumber
|
|
45
46
|
|
|
47
|
+
if (padding) padAutoText(padding, drawData, style, width, height)
|
|
48
|
+
|
|
46
49
|
layoutText(drawData, style) // set bounds
|
|
47
50
|
|
|
48
51
|
layoutChar(drawData, style, width, height) // set char.x
|
|
@@ -55,4 +58,34 @@ export const TextConvert: ITextConvertModule = {
|
|
|
55
58
|
|
|
56
59
|
}
|
|
57
60
|
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
function padAutoText(padding: number[], drawData: ITextDrawData, style: ITextData, width: number, height: number): void {
|
|
65
|
+
if (!width) {
|
|
66
|
+
switch (style.textAlign) {
|
|
67
|
+
case 'left':
|
|
68
|
+
offsetText(drawData, 'x', padding[left])
|
|
69
|
+
break
|
|
70
|
+
case 'right':
|
|
71
|
+
offsetText(drawData, 'x', -padding[right])
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!height) {
|
|
76
|
+
switch (style.verticalAlign) {
|
|
77
|
+
case 'top':
|
|
78
|
+
offsetText(drawData, 'y', padding[top])
|
|
79
|
+
break
|
|
80
|
+
case 'bottom':
|
|
81
|
+
offsetText(drawData, 'y', -padding[bottom])
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
function offsetText(drawData: ITextDrawData, attrName: 'x' | 'y', value: number): void {
|
|
88
|
+
const { bounds, rows } = drawData
|
|
89
|
+
bounds[attrName] += value
|
|
90
|
+
for (let i = 0; i < rows.length; i++) rows[i][attrName] += value
|
|
58
91
|
}
|