@leafer-ui/paint 1.7.0 → 1.9.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 +25 -7
- package/src/Fill.ts +6 -2
- package/src/Shape.ts +12 -11
- 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.9.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.9.0",
|
|
26
|
+
"@leafer-ui/draw": "1.9.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@leafer/interface": "1.
|
|
30
|
-
"@leafer-ui/interface": "1.
|
|
29
|
+
"@leafer/interface": "1.9.0",
|
|
30
|
+
"@leafer-ui/interface": "1.9.0"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/src/Compute.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DataHelper } from '@leafer/core'
|
|
1
|
+
import { DataHelper, isArray, isObject, isString, isUndefined } 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
|
|
|
@@ -11,12 +11,22 @@ export function compute(attrName: IPaintAttr, ui: IUI): void {
|
|
|
11
11
|
const data = ui.__, leafPaints: ILeafPaint[] = []
|
|
12
12
|
|
|
13
13
|
let paints: IPaint[] = data.__input[attrName], isAlphaPixel: boolean, isTransparent: boolean
|
|
14
|
-
if (!(paints
|
|
14
|
+
if (!isArray(paints)) paints = [paints]
|
|
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,12 +44,13 @@ 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
|
|
|
40
51
|
|
|
41
52
|
function getLeafPaint(attrName: string, paint: IPaint, ui: IUI): ILeafPaint {
|
|
42
|
-
if (
|
|
53
|
+
if (!isObject(paint) || paint.visible === false || paint.opacity === 0) return undefined
|
|
43
54
|
|
|
44
55
|
let data: ILeafPaint
|
|
45
56
|
const { boxBounds } = ui.__layout
|
|
@@ -62,11 +73,18 @@ function getLeafPaint(attrName: string, paint: IPaint, ui: IUI): ILeafPaint {
|
|
|
62
73
|
data = { type, style: ColorConvert.string(color, opacity) }
|
|
63
74
|
break
|
|
64
75
|
default:
|
|
65
|
-
if ((paint as IRGB).r
|
|
76
|
+
if (!isUndefined((paint as IRGB).r)) data = { type: 'solid', style: ColorConvert.string(paint) }
|
|
66
77
|
}
|
|
67
78
|
|
|
68
79
|
if (data) {
|
|
69
|
-
|
|
80
|
+
// 描边样式
|
|
81
|
+
if (isString(data.style) && hasTransparent(data.style)) data.isTransparent = true
|
|
82
|
+
if (paint.style) {
|
|
83
|
+
if (paint.style.strokeWidth === 0) return undefined
|
|
84
|
+
data.strokeStyle = paint.style as IStrokeComputedStyle
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (paint.editing) data.editing = paint.editing
|
|
70
88
|
if (paint.blendMode) data.blendMode = paint.blendMode
|
|
71
89
|
}
|
|
72
90
|
|
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
|
+
if (item.scaleFixed === true || (item.scaleFixed === 'zoom-in' && scaleX > 1 && scaleY > 1)) 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/Shape.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IBoundsData, ILeaferCanvas, IRenderOptions, IMatrix } from '@leafer/interface'
|
|
2
|
-
import { BoundsHelper } from '@leafer/core'
|
|
2
|
+
import { BoundsHelper, Matrix } from '@leafer/core'
|
|
3
3
|
|
|
4
4
|
import { IUI, ICachedShape } from '@leafer-ui/interface'
|
|
5
5
|
|
|
@@ -10,7 +10,7 @@ export function shape(ui: IUI, current: ILeaferCanvas, options: IRenderOptions):
|
|
|
10
10
|
const canvas = current.getSameCanvas()
|
|
11
11
|
const nowWorld = ui.__nowWorld
|
|
12
12
|
|
|
13
|
-
let bounds: IBoundsData, fitMatrix: IMatrix, shapeBounds: IBoundsData, worldCanvas: ILeaferCanvas
|
|
13
|
+
let bounds: IBoundsData, matrix: IMatrix, fitMatrix: IMatrix, shapeBounds: IBoundsData, worldCanvas: ILeaferCanvas
|
|
14
14
|
|
|
15
15
|
let { scaleX, scaleY } = nowWorld
|
|
16
16
|
if (scaleX < 0) scaleX = -scaleX
|
|
@@ -39,21 +39,22 @@ export function shape(ui: IUI, current: ILeaferCanvas, options: IRenderOptions):
|
|
|
39
39
|
shapeBounds = getOuterOf(nowWorld, fitMatrix)
|
|
40
40
|
bounds = getByMove(shapeBounds, -fitMatrix.e, -fitMatrix.f)
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
fitMatrix
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
options = { ...options, matrix: fitMatrix.withScale(fitScaleX, fitScaleY) }
|
|
42
|
+
const userMatrix = options.matrix
|
|
43
|
+
if (userMatrix) {
|
|
44
|
+
matrix = new Matrix(fitMatrix) // 仅用于渲染
|
|
45
|
+
matrix.multiply(userMatrix)
|
|
46
|
+
fitScaleX *= userMatrix.scaleX
|
|
47
|
+
fitScaleY *= userMatrix.scaleY
|
|
48
|
+
} else matrix = fitMatrix
|
|
50
49
|
|
|
50
|
+
matrix.withScale(fitScaleX, fitScaleY)
|
|
51
|
+
options = { ...options, matrix }
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
ui.__renderShape(canvas, options)
|
|
54
55
|
|
|
55
56
|
return {
|
|
56
|
-
canvas, matrix
|
|
57
|
+
canvas, matrix, fitMatrix, bounds,
|
|
57
58
|
worldCanvas, shapeBounds, scaleX, scaleY
|
|
58
59
|
}
|
|
59
60
|
}
|
package/src/Stroke.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { ILeaferCanvas } from '@leafer/interface'
|
|
2
|
+
import { LeafHelper, isObject } 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 (isObject(stroke)) {
|
|
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, isObject } 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 (isObject(stroke)) {
|
|
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)
|