@leafer-ui/paint 1.6.7 → 1.8.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 +5 -5
- package/src/Compute.ts +17 -2
- package/src/Fill.ts +6 -2
- package/src/Stroke.ts +9 -5
- package/src/StrokeText.ts +16 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer-ui/paint",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "@leafer-ui/paint",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leafer/core": "1.
|
|
26
|
-
"@leafer-ui/draw": "1.
|
|
25
|
+
"@leafer/core": "1.8.0",
|
|
26
|
+
"@leafer-ui/draw": "1.8.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "1.
|
|
30
|
-
"@leafer-ui/interface": "1.
|
|
29
|
+
"@leafer/interface": "1.8.0",
|
|
30
|
+
"@leafer-ui/interface": "1.8.0"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/src/Compute.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DataHelper } from '@leafer/core'
|
|
2
2
|
|
|
3
|
-
import { IUI, IPaint, ILeafPaint, IRGB, IBooleanMap, IObject, IPaintAttr } from '@leafer-ui/interface'
|
|
3
|
+
import { IUI, IPaint, ILeafPaint, IRGB, IBooleanMap, IObject, IPaintAttr, IStrokeComputedStyle } from '@leafer-ui/interface'
|
|
4
4
|
import { ColorConvert, PaintImage, PaintGradient } from '@leafer-ui/draw'
|
|
5
5
|
|
|
6
6
|
|
|
@@ -15,8 +15,18 @@ export function compute(attrName: IPaintAttr, ui: IUI): void {
|
|
|
15
15
|
|
|
16
16
|
recycleMap = PaintImage.recycleImage(attrName, data)
|
|
17
17
|
|
|
18
|
+
let maxChildStrokeWidth: number
|
|
19
|
+
|
|
18
20
|
for (let i = 0, len = paints.length, item: ILeafPaint; i < len; i++) {
|
|
19
|
-
(item = getLeafPaint(attrName, paints[i], ui))
|
|
21
|
+
if (item = getLeafPaint(attrName, paints[i], ui)) {
|
|
22
|
+
leafPaints.push(item)
|
|
23
|
+
|
|
24
|
+
// 检测多个子描边样式和宽度
|
|
25
|
+
if (item.strokeStyle) {
|
|
26
|
+
maxChildStrokeWidth || (maxChildStrokeWidth = 1)
|
|
27
|
+
if (item.strokeStyle.strokeWidth) maxChildStrokeWidth = Math.max(maxChildStrokeWidth, item.strokeStyle.strokeWidth as number)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
20
30
|
}
|
|
21
31
|
|
|
22
32
|
(data as IObject)['_' + attrName] = leafPaints.length ? leafPaints : undefined
|
|
@@ -34,6 +44,7 @@ export function compute(attrName: IPaintAttr, ui: IUI): void {
|
|
|
34
44
|
} else {
|
|
35
45
|
stintSet(data, '__isAlphaPixelStroke', isAlphaPixel)
|
|
36
46
|
stintSet(data, '__isTransparentStroke', isTransparent)
|
|
47
|
+
stintSet(data, '__hasMultiStrokeStyle', maxChildStrokeWidth)
|
|
37
48
|
}
|
|
38
49
|
}
|
|
39
50
|
|
|
@@ -67,6 +78,10 @@ function getLeafPaint(attrName: string, paint: IPaint, ui: IUI): ILeafPaint {
|
|
|
67
78
|
|
|
68
79
|
if (data) {
|
|
69
80
|
if (typeof data.style === 'string' && hasTransparent(data.style)) data.isTransparent = true
|
|
81
|
+
if (paint.style) {
|
|
82
|
+
if (paint.style.strokeWidth === 0) return undefined
|
|
83
|
+
data.strokeStyle = paint.style as IStrokeComputedStyle
|
|
84
|
+
}
|
|
70
85
|
if (paint.blendMode) data.blendMode = paint.blendMode
|
|
71
86
|
}
|
|
72
87
|
|
package/src/Fill.ts
CHANGED
|
@@ -30,10 +30,14 @@ export function fills(fills: ILeafPaint[], ui: IUI, canvas: ILeaferCanvas): void
|
|
|
30
30
|
|
|
31
31
|
canvas.fillStyle = item.style
|
|
32
32
|
|
|
33
|
-
if (item.transform) {
|
|
33
|
+
if (item.transform || item.scaleFixed) {
|
|
34
34
|
|
|
35
35
|
canvas.save()
|
|
36
|
-
canvas.transform(item.transform)
|
|
36
|
+
if (item.transform) canvas.transform(item.transform)
|
|
37
|
+
if (item.scaleFixed) {
|
|
38
|
+
const { scaleX, scaleY } = ui.getRenderScaleData(true)
|
|
39
|
+
canvas.scale(1 / scaleX, 1 / scaleY)
|
|
40
|
+
}
|
|
37
41
|
if (item.blendMode) canvas.blendMode = item.blendMode
|
|
38
42
|
fillPathOrText(ui, canvas)
|
|
39
43
|
canvas.restore()
|
package/src/Stroke.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { ILeaferCanvas } from '@leafer/interface'
|
|
2
|
+
import { LeafHelper } from "@leafer/core"
|
|
2
3
|
|
|
3
4
|
import { IUI, ILeafPaint } from '@leafer-ui/interface'
|
|
4
5
|
import { Paint } from '@leafer-ui/draw'
|
|
5
6
|
|
|
6
|
-
import { strokeText, drawStrokesStyle
|
|
7
|
+
import { strokeText, drawStrokesStyle } from './StrokeText'
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
export function stroke(stroke: string, ui: IUI, canvas: ILeaferCanvas): void {
|
|
@@ -39,11 +40,14 @@ export function strokes(strokes: ILeafPaint[], ui: IUI, canvas: ILeaferCanvas):
|
|
|
39
40
|
|
|
40
41
|
function drawCenter(stroke: string | ILeafPaint[], strokeWidthScale: number, ui: IUI, canvas: ILeaferCanvas) {
|
|
41
42
|
const data = ui.__
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
if (typeof stroke === 'object') {
|
|
44
|
+
drawStrokesStyle(stroke, strokeWidthScale, false, ui, canvas)
|
|
45
|
+
} else {
|
|
46
|
+
canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data)
|
|
47
|
+
canvas.stroke()
|
|
48
|
+
}
|
|
44
49
|
|
|
45
50
|
if (data.__useArrow) Paint.strokeArrow(stroke, ui, canvas)
|
|
46
|
-
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
function drawInside(stroke: string | ILeafPaint[], ui: IUI, canvas: ILeaferCanvas) {
|
|
@@ -70,7 +74,7 @@ function drawOutside(stroke: string | ILeafPaint[], ui: IUI, canvas: ILeaferCanv
|
|
|
70
74
|
out.clipUI(data)
|
|
71
75
|
out.clearWorld(renderBounds)
|
|
72
76
|
|
|
73
|
-
|
|
77
|
+
LeafHelper.copyCanvasByWorld(ui, canvas, out)
|
|
74
78
|
|
|
75
79
|
out.recycle(ui.__nowWorld)
|
|
76
80
|
}
|
package/src/StrokeText.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ILeaferCanvas } from '@leafer/interface'
|
|
2
|
-
import {
|
|
2
|
+
import { LeafHelper } from "@leafer/core"
|
|
3
3
|
|
|
4
4
|
import { IUI, ITextRowData, ILeafPaint, IStrokeAlign, ILeafStrokePaint } from '@leafer-ui/interface'
|
|
5
5
|
import { PaintImage } from "@leafer-ui/draw"
|
|
@@ -23,8 +23,12 @@ export function strokeText(stroke: string | ILeafPaint[], ui: IUI, canvas: ILeaf
|
|
|
23
23
|
|
|
24
24
|
function drawCenter(stroke: string | ILeafPaint[], strokeWidthScale: number, ui: IUI, canvas: ILeaferCanvas): void {
|
|
25
25
|
const data = ui.__
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
if (typeof stroke === 'object') {
|
|
27
|
+
drawStrokesStyle(stroke, strokeWidthScale, true, ui, canvas)
|
|
28
|
+
} else {
|
|
29
|
+
canvas.setStroke(stroke, data.__strokeWidth * strokeWidthScale, data)
|
|
30
|
+
drawTextStroke(ui, canvas)
|
|
31
|
+
}
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
function drawAlign(stroke: string | ILeafPaint[], align: IStrokeAlign, ui: IUI, canvas: ILeaferCanvas): void {
|
|
@@ -36,18 +40,12 @@ function drawAlign(stroke: string | ILeafPaint[], align: IStrokeAlign, ui: IUI,
|
|
|
36
40
|
fillText(ui, out)
|
|
37
41
|
out.blendMode = 'normal'
|
|
38
42
|
|
|
39
|
-
|
|
43
|
+
LeafHelper.copyCanvasByWorld(ui, canvas, out)
|
|
40
44
|
|
|
41
45
|
out.recycle(ui.__nowWorld)
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
|
|
45
|
-
export function copyWorld(canvas: ILeaferCanvas, out: ILeaferCanvas, ui: IUI): void {
|
|
46
|
-
if (ui.__worldFlipped || Platform.fullImageShadow) canvas.copyWorldByReset(out, ui.__nowWorld)
|
|
47
|
-
else canvas.copyWorldToInner(out, ui.__nowWorld, ui.__layout.renderBounds)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
49
|
export function drawTextStroke(ui: IUI, canvas: ILeaferCanvas): void {
|
|
52
50
|
|
|
53
51
|
let row: ITextRowData, data = ui.__.__textDrawData
|
|
@@ -67,15 +65,21 @@ export function drawTextStroke(ui: IUI, canvas: ILeaferCanvas): void {
|
|
|
67
65
|
|
|
68
66
|
}
|
|
69
67
|
|
|
70
|
-
export function drawStrokesStyle(strokes: ILeafStrokePaint[], isText: boolean, ui: IUI, canvas: ILeaferCanvas): void {
|
|
68
|
+
export function drawStrokesStyle(strokes: ILeafStrokePaint[], strokeWidthScale: number, isText: boolean, ui: IUI, canvas: ILeaferCanvas): void {
|
|
71
69
|
let item: ILeafStrokePaint
|
|
70
|
+
const data = ui.__, { __hasMultiStrokeStyle } = data
|
|
71
|
+
__hasMultiStrokeStyle || canvas.setStroke(undefined, data.__strokeWidth * strokeWidthScale, data)
|
|
72
|
+
|
|
72
73
|
for (let i = 0, len = strokes.length; i < len; i++) {
|
|
73
74
|
item = strokes[i]
|
|
74
75
|
|
|
75
76
|
if (item.image && PaintImage.checkImage(ui, canvas, item, false)) continue
|
|
76
77
|
|
|
77
78
|
if (item.style) {
|
|
78
|
-
|
|
79
|
+
if (__hasMultiStrokeStyle) {
|
|
80
|
+
const { strokeStyle } = item
|
|
81
|
+
strokeStyle ? canvas.setStroke(item.style, data.__getRealStrokeWidth(strokeStyle) * strokeWidthScale, data, strokeStyle) : canvas.setStroke(item.style, data.__strokeWidth * strokeWidthScale, data)
|
|
82
|
+
} else canvas.strokeStyle = item.style
|
|
79
83
|
|
|
80
84
|
if (item.blendMode) {
|
|
81
85
|
canvas.saveBlendMode(item.blendMode)
|