@univerjs-pro/engine-shape 0.20.0 → 0.20.1

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.
@@ -25,13 +25,13 @@ export declare abstract class BaseShapeRenderModel {
25
25
  */
26
26
  getTextRect(rect: IShapeRect, gdRecord: Partial<IGdContext>): IShapeRect;
27
27
  /**
28
- * Compute the actual bounding box of all fillable paths (fill !== 'none').
29
- * For multi-path shapes (e.g. cloudCallout), sub-paths may extend beyond the
30
- * drawing rect. This method returns the real bounding box so that image/gradient
31
- * fills can cover the complete shape area.
28
+ * 计算所有可填充路径(fill !== 'none')的实际包围盒。
32
29
  *
33
- * Coordinate system: same as render() after translate(-width/2, -height/2),
34
- * i.e. (0,0) is at the top-left of the drawing rect.
30
+ * 对于多路径形状(如 cloudCallout 云朵标注),子路径可能超出 drawing rect,
31
+ * 因此需要返回真实的包围盒,使图片/渐变填充能覆盖完整的形状区域。
32
+ *
33
+ * 坐标系:与 render() 中 translate(-width/2, -height/2) 之后的坐标系一致,
34
+ * 即 (0,0) 为 drawing rect 的左上角。
35
35
  */
36
36
  computeFillableBounds(rect: IShapeRect, shapeContext: BaseShapeContext): IShapeRect;
37
37
  /**
@@ -39,16 +39,15 @@ export declare abstract class BaseShapeRenderModel {
39
39
  */
40
40
  render(canvasContext: CanvasRenderingContext2D, rect: IShapeRect, shapeContext: BaseShapeContext, shapeData: IShapeData, renderOption: IShapeRenderParameters): void;
41
41
  /**
42
- * Build just the shape outline path on the canvas context and clip.
43
- * Unlike render(), this does NOT fill or stroke — only builds the path and calls clip().
44
- * Coordinate system: (0,0) is at the top-left, (width,height) at the bottom-right.
42
+ * canvas 上构建形状轮廓路径并执行裁剪(clip)。
43
+ * render() 不同,本方法**不做填充和描边**——仅构建路径并调用 clip()
44
+ * 坐标系:(0,0) 为左上角,(width, height) 为右下角。
45
45
  *
46
- * Only fillable paths (fill !== 'none') participate in the clip region.
47
- * For multi-path shapes (e.g. cloudCallout), some sub-paths may extend beyond the
48
- * drawing rect. The returned IShapeRect reports the actual bounding box of the clip
49
- * so the caller can size the image fill accordingly.
46
+ * 仅可填充路径(fill !== 'none')参与裁剪区域。
47
+ * 对于多路径形状(如 cloudCallout),部分子路径可能超出 drawing rect,
48
+ * 返回的 IShapeRect 报告裁剪区域的实际包围盒,供调用方据此确定图片填充尺寸。
50
49
  *
51
- * @returns The actual bounding rect of the clip region, or false if no clip was built
50
+ * @returns 裁剪区域的实际包围矩形,若无法构建裁剪路径则返回 false
52
51
  */
53
52
  buildClipPath(canvasContext: CanvasRenderingContext2D, rect: IShapeRect, shapeContext: BaseShapeContext): IShapeRect | false;
54
53
  private _getDashType;
@@ -56,19 +55,35 @@ export declare abstract class BaseShapeRenderModel {
56
55
  private _getJoinType;
57
56
  private _getStrokeWidth;
58
57
  /**
59
- * Fill the current path with an image, replicating Excel's picture-fill pipeline:
60
- * image → srcRect (crop) → Stretch / Tile clip to shape path
58
+ * 用图片填充当前路径,复现 Excel 的图片填充管线:
59
+ * image → srcRect(裁剪源图区域)→ Stretch(拉伸)/ Tile(平铺)→ clip to shape path(裁剪到形状路径)
61
60
  *
62
- * Coordinate system: we are already inside a `save/translate(-w/2, -h/2)` block,
63
- * so (0,0) is the top-left of the shape bounding box.
61
+ * 坐标系:已在 `save/translate(-w/2, -h/2)` 块内,(0,0) 为形状包围盒左上角。
64
62
  *
65
- * @param canvasContext Active 2D context
66
- * @param rect Shape bounding rect (width/height in display pixels)
67
- * @param shapeData IBasicShapeData carrying fill configuration
68
- * @param image Pre-loaded HTMLImageElement
69
- * @param fillRule Current path fill rule flag from IShapePath
63
+ * @param canvasContext 当前 2D 画布上下文
64
+ * @param rect 形状包围矩形(display pixels 单位的宽高)
65
+ * @param shapeData 携带填充配置的 IBasicShapeData
66
+ * @param image 已加载的 HTMLImageElement
67
+ * @param fillRule 当前 path 的填充规则标志(来自 IShapePath.fill)
68
+ * @param angle 形状旋转角度(度),用于处理 imageRotateWithShape
69
+ * @param fillBounds 多路径形状的实际可填充包围盒,超出 drawing rect 的部分也需覆盖
70
70
  */
71
71
  private _fillPicture;
72
+ /**
73
+ * 将 OOXML 的"视觉角度"转换为 Canvas 椭圆的参数角度。
74
+ *
75
+ * OOXML 角度表示从中心到椭圆上某点的几何角度(即人眼看到的角度),
76
+ * 而 Canvas ellipse() 使用参数角度:point = (rx·cos(t), ry·sin(t))。
77
+ * 对于非正圆的椭圆,两者不同。OOXML 中 cat2/sat2 公式正是执行此转换来定位
78
+ * moveTo 点和调节手柄,因此传给 Canvas 时必须做同样的转换。
79
+ */
80
+ private _ooxmlAngleToParametric;
81
+ /**
82
+ * 将椭圆弧的基本方向极值点纳入包围盒追踪。
83
+ * 仅包含落在弧段扫过范围内的极值(0°、90°、180°、270° 方向)。
84
+ * 所有角度均为参数角度(Canvas 角度),而非 OOXML 视觉角度。
85
+ */
86
+ private _updateArcCardinalBounds;
72
87
  /**
73
88
  * Create a gradient based on the shape's fill configuration
74
89
  * @param canvasContext The canvas rendering context
@@ -92,10 +107,19 @@ export declare abstract class BaseShapeRenderModel {
92
107
  */
93
108
  private _createAngularGradient;
94
109
  /**
95
- * Create a diamond gradient
96
- * This is approximated using a radial gradient with adjusted parameters
110
+ * Fill the current shape path with a diamond gradient using 4 triangular linear gradients.
111
+ *
112
+ * The rectangle is divided into 4 triangles by its diagonals (top, right, bottom, left).
113
+ * Each triangle is filled with a linear gradient from the center to the corresponding
114
+ * edge midpoint, approximating the Manhattan-distance diamond pattern without any
115
+ * offscreen canvas or per-pixel manipulation.
116
+ *
117
+ * Uses Path2D for triangle clips to avoid destroying the main canvas path
118
+ * (Canvas save/restore does NOT preserve the current path).
119
+ * Triangles are extended by 1px at diagonal edges so they overlap slightly,
120
+ * hiding anti-aliasing seams at the boundaries.
97
121
  */
98
- private _createDiamondGradient;
122
+ private _fillDiamondGradient;
99
123
  /**
100
124
  * Add color stops to a gradient
101
125
  */
@@ -103,23 +127,22 @@ export declare abstract class BaseShapeRenderModel {
103
127
  private _getFillStyle;
104
128
  private _getStrokeStyle;
105
129
  /**
106
- * For modifier fill paths (darkenLess, darken, lighten, lightenLess),
107
- * overlay a semi-transparent black or white fill on top of the current path
108
- * to simulate the OOXML brightness adjustment.
130
+ * 对修饰符填充路径(darkenLess, darken, lighten, lightenLess),
131
+ * 在当前路径上方叠加一层半透明的黑色或白色填充,模拟 OOXML 的明暗调整效果。
109
132
  *
110
- * This matches what solid fill does via ColorUtil._adjust:
111
- * darken → -30% brightness overlay black at 30% opacity
112
- * darkenLess → -12% overlay black at 12% opacity
113
- * lighten → +30% overlay white at 30% opacity
114
- * lightenLess → +12% overlay white at 12% opacity
133
+ * 对齐纯色填充时 ColorUtil._adjust 的处理逻辑:
134
+ * darken 亮度 -30% → 叠加 30% 不透明度的黑色
135
+ * darkenLess → 亮度 -12% 叠加 12% 不透明度的黑色
136
+ * lighten 亮度 +30% 叠加 30% 不透明度的白色
137
+ * lightenLess→ 亮度 +12% 叠加 12% 不透明度的白色
115
138
  */
116
139
  private _applyFillModifierOverlay;
117
140
  private _renderTextBox;
118
141
  private _renderCxnPoints;
119
142
  private _getValueFromGdRecord;
120
143
  /**
121
- * Walk a single path's commands, scaling coordinates and accumulating
122
- * into the provided bounding-box tracker.
144
+ * 遍历单条路径的所有绘图命令,按缩放因子缩放坐标,
145
+ * 并将各点累积到包围盒追踪器中。
123
146
  */
124
147
  private _accumulatePathBounds;
125
148
  /**
@@ -121,8 +121,6 @@ export declare enum ShapeTypeEnum {
121
121
  LeftRightCircularArrow = "leftRightCircularArrow",
122
122
  SwooshArrow = "swooshArrow",
123
123
  LeftRightRibbon = "leftRightRibbon",
124
- TextBox = "textBox",
125
- Circle = "circle",// 特例 圆形其实是椭圆的一种,只不过限定了长宽相等 excel没有circle这个形状,只有ellipse
126
124
  Heptagon = "heptagon",
127
125
  HomePlate = "homePlate",
128
126
  RightArrow = "rightArrow",
@@ -219,7 +217,7 @@ export declare enum ShapeTypeEnum {
219
217
  SmileyFace = "smileyFace",
220
218
  IrregularSeal1 = "irregularSeal1",
221
219
  IrregularSeal2 = "irregularSeal2",
222
- FoldedCorner = "folderCorner",
220
+ FoldedCorner = "foldedCorner",
223
221
  Bevel = "bevel",
224
222
  Donut = "donut",
225
223
  NoSmoking = "noSmoking",