@leafer-ui/text 1.0.0-rc.2 → 1.0.0-rc.4
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 +5 -3
- package/src/TextLayout.ts +16 -10
- package/src/TextRows.ts +14 -3
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.4",
|
|
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.4"
|
|
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.4",
|
|
29
|
+
"@leafer-ui/interface": "1.0.0-rc.4"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/TextConvert.ts
CHANGED
|
@@ -16,9 +16,11 @@ export const TextConvert: ITextConvertModule = {
|
|
|
16
16
|
if (typeof content !== 'string') content = String(content)
|
|
17
17
|
|
|
18
18
|
let x = 0, y = 0
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
|
|
20
|
+
let width = style.__getInput('width') || 0
|
|
21
|
+
let height = style.__getInput('height') || 0
|
|
22
|
+
|
|
23
|
+
const { textDecoration, textOverflow, __font, padding } = style
|
|
22
24
|
|
|
23
25
|
if (padding) {
|
|
24
26
|
const [top, right, bottom, left] = MathHelper.fourNumber(padding)
|
package/src/TextLayout.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { ITextData, ITextDrawData, ITextRowData } from '@leafer-ui/interface'
|
|
|
4
4
|
export function layoutText(drawData: ITextDrawData, style: ITextData): void {
|
|
5
5
|
|
|
6
6
|
const { rows, bounds } = drawData
|
|
7
|
-
const { __lineHeight, __baseLine, textAlign, verticalAlign, paraSpacing, textOverflow } = style
|
|
7
|
+
const { __lineHeight, __baseLine, __letterSpacing, textAlign, verticalAlign, paraSpacing, textOverflow } = style
|
|
8
8
|
|
|
9
9
|
let { x, y, width, height } = bounds, realHeight = __lineHeight * rows.length + (paraSpacing ? paraSpacing * (drawData.paraNumber - 1) : 0)
|
|
10
10
|
let starY: number = __baseLine
|
|
@@ -27,7 +27,7 @@ export function layoutText(drawData: ITextDrawData, style: ITextData): void {
|
|
|
27
27
|
|
|
28
28
|
// textAlign
|
|
29
29
|
|
|
30
|
-
let row: ITextRowData
|
|
30
|
+
let row: ITextRowData, rowX: number, rowWidth: number
|
|
31
31
|
|
|
32
32
|
for (let i = 0, len = rows.length; i < len; i++) {
|
|
33
33
|
row = rows[i]
|
|
@@ -52,16 +52,22 @@ export function layoutText(drawData: ITextDrawData, style: ITextData): void {
|
|
|
52
52
|
drawData.overflow = i + 1
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
55
|
+
rowX = row.x
|
|
56
|
+
rowWidth = row.width
|
|
57
|
+
|
|
58
|
+
if (__letterSpacing < 0) { // letterSpacing < 0, like -20% -100%
|
|
59
|
+
if (row.width < 0) {
|
|
60
|
+
rowWidth = -row.width + style.fontSize + __letterSpacing
|
|
61
|
+
rowX -= rowWidth
|
|
62
|
+
rowWidth += style.fontSize
|
|
63
|
+
} else {
|
|
64
|
+
rowWidth -= __letterSpacing
|
|
65
|
+
}
|
|
63
66
|
}
|
|
64
67
|
|
|
68
|
+
if (rowX < bounds.x) bounds.x = rowX
|
|
69
|
+
if (rowWidth > bounds.width) bounds.width = rowWidth
|
|
70
|
+
|
|
65
71
|
}
|
|
66
72
|
|
|
67
73
|
bounds.y = y
|
package/src/TextRows.ts
CHANGED
|
@@ -11,7 +11,7 @@ const { trimRight } = TextRowHelper
|
|
|
11
11
|
const { Letter, Single, Before, After, Symbol, Break } = CharType
|
|
12
12
|
|
|
13
13
|
let word: ITextWordData, row: ITextRowData, wordWidth: number, rowWidth: number, realWidth: number
|
|
14
|
-
let char: string, charWidth: number, charType: CharType, lastCharType: CharType, langBreak: boolean, afterBreak: boolean, paraStart: boolean
|
|
14
|
+
let char: string, charWidth: number, startCharSize: number, charSize: number, charType: CharType, lastCharType: CharType, langBreak: boolean, afterBreak: boolean, paraStart: boolean
|
|
15
15
|
let textDrawData: ITextDrawData, rows: ITextRowData[] = [], bounds: IBoundsData
|
|
16
16
|
|
|
17
17
|
export function createRows(drawData: ITextDrawData, content: string, style: ITextData): void {
|
|
@@ -29,7 +29,7 @@ export function createRows(drawData: ITextDrawData, content: string, style: ITex
|
|
|
29
29
|
|
|
30
30
|
paraStart = true
|
|
31
31
|
lastCharType = null
|
|
32
|
-
wordWidth = rowWidth = 0
|
|
32
|
+
startCharSize = charWidth = charSize = wordWidth = rowWidth = 0
|
|
33
33
|
word = { data: [] }, row = { words: [] }
|
|
34
34
|
|
|
35
35
|
for (let i = 0, len = content.length; i < len; i++) {
|
|
@@ -51,7 +51,10 @@ export function createRows(drawData: ITextDrawData, content: string, style: ITex
|
|
|
51
51
|
if (charType === Letter && textCase !== 'none') char = getTextCase(char, textCase, !wordWidth)
|
|
52
52
|
|
|
53
53
|
charWidth = canvas.measureText(char).width
|
|
54
|
-
if (__letterSpacing)
|
|
54
|
+
if (__letterSpacing) {
|
|
55
|
+
if (__letterSpacing < 0) charSize = charWidth
|
|
56
|
+
charWidth += __letterSpacing
|
|
57
|
+
}
|
|
55
58
|
|
|
56
59
|
langBreak = (charType === Single && (lastCharType === Single || lastCharType === Letter)) || (lastCharType === Single && charType !== After) // break U字 文字 or 字U 字( 字* exclude 字。
|
|
57
60
|
afterBreak = ((charType === Before || charType === Single) && (lastCharType === Symbol || lastCharType === After)) // split >( =文 。哈 ;文
|
|
@@ -121,6 +124,7 @@ export function createRows(drawData: ITextDrawData, content: string, style: ITex
|
|
|
121
124
|
|
|
122
125
|
|
|
123
126
|
function addChar(char: string, width: number): void {
|
|
127
|
+
if (charSize && !startCharSize) startCharSize = charSize
|
|
124
128
|
word.data.push({ char, width })
|
|
125
129
|
wordWidth += width
|
|
126
130
|
}
|
|
@@ -139,6 +143,13 @@ function addRow(): void {
|
|
|
139
143
|
row.paraStart = true
|
|
140
144
|
paraStart = false
|
|
141
145
|
}
|
|
146
|
+
|
|
147
|
+
if (charSize) { // letterSpacing < 0, like -20% -100%
|
|
148
|
+
row.startCharSize = startCharSize
|
|
149
|
+
row.endCharSize = charSize
|
|
150
|
+
startCharSize = 0
|
|
151
|
+
}
|
|
152
|
+
|
|
142
153
|
row.width = rowWidth
|
|
143
154
|
if (bounds.width) trimRight(row)
|
|
144
155
|
rows.push(row)
|