@leafer-ui/text 1.9.12 → 1.10.0
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/CharLayout.ts +24 -8
- package/src/TextConvert.ts +6 -6
- package/src/TextRows.ts +2 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/text",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
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/core": "1.
|
|
25
|
+
"@leafer/core": "1.10.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@leafer/interface": "1.
|
|
29
|
-
"@leafer-ui/interface": "1.
|
|
28
|
+
"@leafer/interface": "1.10.0",
|
|
29
|
+
"@leafer-ui/interface": "1.10.0"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/CharLayout.ts
CHANGED
|
@@ -9,14 +9,24 @@ export function layoutChar(drawData: ITextDrawData, style: ITextData, width: num
|
|
|
9
9
|
|
|
10
10
|
const { rows } = drawData
|
|
11
11
|
const { textAlign, paraIndent, letterSpacing } = style
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
const justifyLast = width && textAlign.includes('both') // 最后一行是否两端对齐
|
|
14
|
+
const justify = justifyLast || (width && textAlign.includes('justify')) // 是否两端对齐文本
|
|
15
|
+
const justifyLetter = justify && textAlign.includes('letter') // 英文是否通过加大字符间距两端对齐
|
|
16
|
+
|
|
17
|
+
let charX: number, remainingWidth: number, addWordWidth: number, addLetterWidth: number, indentWidth: number, mode: number, wordChar: ITextCharData, wordsLength: number, isLastWord: boolean, canJustify: boolean
|
|
13
18
|
|
|
14
19
|
rows.forEach(row => {
|
|
15
20
|
if (row.words) {
|
|
16
21
|
|
|
17
22
|
indentWidth = paraIndent && row.paraStart ? paraIndent : 0, wordsLength = row.words.length
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
if (justify) {
|
|
24
|
+
canJustify = !row.paraEnd || justifyLast
|
|
25
|
+
remainingWidth = width - row.width - indentWidth
|
|
26
|
+
if (justifyLetter) addLetterWidth = remainingWidth / (row.words.reduce((total, item) => total + item.data.length, 0) - 1) // remainingWidth / (lettersLength - 1)
|
|
27
|
+
else addWordWidth = wordsLength > 1 ? remainingWidth / (wordsLength - 1) : 0
|
|
28
|
+
}
|
|
29
|
+
mode = (letterSpacing || row.isOverflow || justifyLetter) ? CharMode : (addWordWidth ? WordMode : TextMode)
|
|
20
30
|
if (row.isOverflow && !letterSpacing) row.textMode = true
|
|
21
31
|
|
|
22
32
|
if (mode === TextMode) {
|
|
@@ -40,13 +50,18 @@ export function layoutChar(drawData: ITextDrawData, style: ITextData, width: num
|
|
|
40
50
|
|
|
41
51
|
} else {
|
|
42
52
|
|
|
43
|
-
charX = toChar(word.data, charX, row.data, row.isOverflow)
|
|
53
|
+
charX = toChar(word.data, charX, row.data, row.isOverflow, canJustify && addLetterWidth)
|
|
44
54
|
|
|
45
55
|
}
|
|
46
56
|
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
57
|
+
if (canJustify) {
|
|
58
|
+
isLastWord = index === wordsLength - 1
|
|
59
|
+
|
|
60
|
+
if (addWordWidth) {
|
|
61
|
+
if (!isLastWord) charX += addWordWidth, row.width += addWordWidth
|
|
62
|
+
} else if (addLetterWidth) {
|
|
63
|
+
row.width += addLetterWidth * (word.data.length - (isLastWord ? 1 : 0))
|
|
64
|
+
}
|
|
50
65
|
}
|
|
51
66
|
|
|
52
67
|
})
|
|
@@ -75,13 +90,14 @@ function toWordChar(data: ITextCharData[], charX: number, wordChar: ITextCharDat
|
|
|
75
90
|
return charX
|
|
76
91
|
}
|
|
77
92
|
|
|
78
|
-
function toChar(data: ITextCharData[], charX: number, rowData: ITextCharData[], isOverflow?: boolean): number {
|
|
93
|
+
function toChar(data: ITextCharData[], charX: number, rowData: ITextCharData[], isOverflow?: boolean, addLetterWidth?: number): number {
|
|
79
94
|
data.forEach(char => {
|
|
80
95
|
if (isOverflow || char.char !== ' ') {
|
|
81
96
|
char.x = charX
|
|
82
97
|
rowData.push(char)
|
|
83
98
|
}
|
|
84
99
|
charX += char.width
|
|
100
|
+
addLetterWidth && (charX += addLetterWidth)
|
|
85
101
|
})
|
|
86
102
|
return charX
|
|
87
103
|
}
|
package/src/TextConvert.ts
CHANGED
|
@@ -20,13 +20,13 @@ export function getDrawData(content: string | number, style: ITextData): ITextDr
|
|
|
20
20
|
let width = style.__getInput('width') || 0
|
|
21
21
|
let height = style.__getInput('height') || 0
|
|
22
22
|
|
|
23
|
-
const {
|
|
23
|
+
const { __padding: padding } = style
|
|
24
24
|
|
|
25
25
|
if (padding) {
|
|
26
|
-
if (width) x = padding[left], width -= (padding[right] + padding[left])
|
|
26
|
+
if (width) x = padding[left], width -= (padding[right] + padding[left]), !width && (width = 0.01) // 防止变为自动宽度
|
|
27
27
|
else if (!style.autoSizeAlign) x = padding[left]
|
|
28
28
|
|
|
29
|
-
if (height) y = padding[top], height -= (padding[top] + padding[bottom])
|
|
29
|
+
if (height) y = padding[top], height -= (padding[top] + padding[bottom]), !height && (height = 0.01)
|
|
30
30
|
else if (!style.autoSizeAlign) y = padding[top]
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -34,7 +34,7 @@ export function getDrawData(content: string | number, style: ITextData): ITextDr
|
|
|
34
34
|
bounds: { x, y, width, height },
|
|
35
35
|
rows: [],
|
|
36
36
|
paraNumber: 0,
|
|
37
|
-
font: Platform.canvas.font = __font
|
|
37
|
+
font: Platform.canvas.font = style.__font
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
createRows(drawData, content, style) // set rows, paraNumber
|
|
@@ -43,11 +43,11 @@ export function getDrawData(content: string | number, style: ITextData): ITextDr
|
|
|
43
43
|
|
|
44
44
|
layoutText(drawData, style) // set bounds
|
|
45
45
|
|
|
46
|
-
layoutChar(drawData, style, width, height) // set char.x
|
|
46
|
+
if (style.__isCharMode) layoutChar(drawData, style, width, height) // set char.x
|
|
47
47
|
|
|
48
48
|
if (drawData.overflow) clipText(drawData, style, x, width)
|
|
49
49
|
|
|
50
|
-
if (textDecoration !== 'none') decorationText(drawData, style)
|
|
50
|
+
if (style.textDecoration !== 'none') decorationText(drawData, style)
|
|
51
51
|
|
|
52
52
|
return drawData
|
|
53
53
|
|
package/src/TextRows.ts
CHANGED
|
@@ -22,11 +22,9 @@ export function createRows(drawData: ITextDrawData, content: string, style: ITex
|
|
|
22
22
|
findMaxWidth = !bounds.width && !style.autoSizeAlign
|
|
23
23
|
|
|
24
24
|
const { __letterSpacing, paraIndent, textCase } = style
|
|
25
|
-
const { canvas } = Platform
|
|
26
|
-
const { width, height } = bounds
|
|
27
|
-
const charMode = width || height || __letterSpacing || (textCase !== 'none')
|
|
25
|
+
const { canvas } = Platform, { width } = bounds
|
|
28
26
|
|
|
29
|
-
if (
|
|
27
|
+
if (style.__isCharMode) {
|
|
30
28
|
|
|
31
29
|
const wrap = style.textWrap !== 'none'
|
|
32
30
|
const breakAll = style.textWrap === 'break'
|