@leafer-ui/image 1.9.3 → 1.9.5

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.
Files changed (2) hide show
  1. package/package.json +5 -5
  2. package/src/pattern.ts +18 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer-ui/image",
3
- "version": "1.9.3",
3
+ "version": "1.9.5",
4
4
  "description": "@leafer-ui/image",
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.9.3",
26
- "@leafer-ui/draw": "1.9.3"
25
+ "@leafer/core": "1.9.5",
26
+ "@leafer-ui/draw": "1.9.5"
27
27
  },
28
28
  "devDependencies": {
29
- "@leafer/interface": "1.9.3",
30
- "@leafer-ui/interface": "1.9.3"
29
+ "@leafer/interface": "1.9.5",
30
+ "@leafer-ui/interface": "1.9.5"
31
31
  }
32
32
  }
package/src/pattern.ts CHANGED
@@ -4,7 +4,7 @@ import { IUI, ILeafPaint, IMatrixData } from '@leafer-ui/interface'
4
4
 
5
5
 
6
6
  const { get, scale, copy } = MatrixHelper
7
- const { floor, max, abs } = Math
7
+ const { floor, ceil, max, abs } = Math
8
8
 
9
9
  export function createPattern(ui: IUI, paint: ILeafPaint, pixelRatio: number): boolean {
10
10
  let { scaleX, scaleY } = ui.getRenderScaleData(true, paint.scaleFixed)
@@ -18,9 +18,6 @@ export function createPattern(ui: IUI, paint: ILeafPaint, pixelRatio: number): b
18
18
  scaleX *= pixelRatio
19
19
  scaleY *= pixelRatio
20
20
 
21
- const xGap = gap && (gap.x * scaleX)
22
- const yGap = gap && (gap.y * scaleY)
23
-
24
21
  if (sx) {
25
22
  sx = abs(sx) // maybe -1
26
23
  sy = abs(sy)
@@ -42,7 +39,10 @@ export function createPattern(ui: IUI, paint: ILeafPaint, pixelRatio: number): b
42
39
 
43
40
  let maxSize = Platform.image.maxPatternSize
44
41
 
45
- if (!image.isSVG) {
42
+ if (image.isSVG) {
43
+ const ws = width / image.width
44
+ if (ws > 1) imageScale = ws / ceil(ws) // fix: svg按整数倍放大,避免产生加深线条
45
+ } else {
46
46
  const imageSize = image.width * image.height
47
47
  if (maxSize > imageSize) maxSize = imageSize
48
48
  }
@@ -61,20 +61,28 @@ export function createPattern(ui: IUI, paint: ILeafPaint, pixelRatio: number): b
61
61
  scaleY /= sy
62
62
  }
63
63
 
64
+ // 间距
65
+ const xGap = gap && (gap.x * scaleX)
66
+ const yGap = gap && (gap.y * scaleY)
67
+
64
68
  if (transform || scaleX !== 1 || scaleY !== 1) {
69
+
70
+ // 缩放至floor画布宽高的状态
71
+ const canvasWidth = width + (xGap || 0)
72
+ const canvasHeight = height + (yGap || 0)
73
+ scaleX /= canvasWidth / max(floor(canvasWidth), 1)
74
+ scaleY /= canvasHeight / max(floor(canvasHeight), 1)
75
+
65
76
  if (!imageMatrix) {
66
77
  imageMatrix = get()
67
78
  if (transform) copy(imageMatrix, transform)
68
79
  }
80
+
69
81
  scale(imageMatrix, 1 / scaleX, 1 / scaleY)
70
- }
71
82
 
72
- if (imageMatrix) {
73
- const canvasWidth = width + (xGap || 0), canvasHeight = height + (yGap || 0)
74
- scale(imageMatrix, canvasWidth / max(floor(canvasWidth), 1), canvasHeight / max(floor(canvasHeight), 1)) // 缩放至floor画布宽高的状态
75
83
  }
76
84
 
77
- const canvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap)
85
+ const canvas = image.getCanvas(width, height, data.opacity, data.filters, xGap, yGap, ui.leafer && ui.leafer.config.smooth)
78
86
  const pattern = image.getPattern(canvas, repeat || (Platform.origin.noRepeat || 'no-repeat'), imageMatrix, paint)
79
87
 
80
88
  paint.style = pattern