js-draw 1.24.1 → 1.24.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -76,6 +76,17 @@ export default class TextComponent extends AbstractComponent implements Restylea
76
76
  private static getFontHeight;
77
77
  private computeUntransformedBBoxOfPart;
78
78
  private recomputeBBox;
79
+ /**
80
+ * Renders a TextComponent or a TextComponent child onto a `canvas`.
81
+ *
82
+ * `visibleRect` can be provided as a performance optimization. If not the top-level
83
+ * text node, `baseTransform` (specifies the transformation of the parent text component
84
+ * in canvas space) should also be provided.
85
+ *
86
+ * Note that passing a `baseTransform` is preferable to transforming `visibleRect`. At high
87
+ * zoom levels, transforming `visibleRect` by the inverse of the parent transform can lead to
88
+ * inaccuracy due to precision loss.
89
+ */
79
90
  private renderInternal;
80
91
  render(canvas: AbstractRenderer, visibleRect?: Rect2): void;
81
92
  getProportionalRenderingTime(): number;
@@ -154,11 +154,22 @@ class TextComponent extends AbstractComponent_1.default {
154
154
  }
155
155
  this.contentBBox = bbox ?? math_1.Rect2.empty;
156
156
  }
157
- renderInternal(canvas, visibleRect) {
157
+ /**
158
+ * Renders a TextComponent or a TextComponent child onto a `canvas`.
159
+ *
160
+ * `visibleRect` can be provided as a performance optimization. If not the top-level
161
+ * text node, `baseTransform` (specifies the transformation of the parent text component
162
+ * in canvas space) should also be provided.
163
+ *
164
+ * Note that passing a `baseTransform` is preferable to transforming `visibleRect`. At high
165
+ * zoom levels, transforming `visibleRect` by the inverse of the parent transform can lead to
166
+ * inaccuracy due to precision loss.
167
+ */
168
+ renderInternal(canvas, visibleRect, baseTransform = math_1.Mat33.identity) {
158
169
  const cursor = new TextComponent.TextCursor(this.transform, this.style);
159
170
  for (const textObject of this.textObjects) {
160
171
  const { transform, bbox } = cursor.update(textObject);
161
- if (visibleRect && !visibleRect.intersects(bbox)) {
172
+ if (visibleRect && !visibleRect.intersects(bbox.transformedBoundingBox(baseTransform))) {
162
173
  continue;
163
174
  }
164
175
  if (typeof textObject === 'string') {
@@ -166,7 +177,7 @@ class TextComponent extends AbstractComponent_1.default {
166
177
  }
167
178
  else {
168
179
  canvas.pushTransform(transform);
169
- textObject.renderInternal(canvas, visibleRect?.transformedBoundingBox(transform.inverse()));
180
+ textObject.renderInternal(canvas, visibleRect, baseTransform.rightMul(transform));
170
181
  canvas.popTransform();
171
182
  }
172
183
  }
@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  * @internal
7
7
  */
8
8
  exports.default = {
9
- number: '1.24.1',
9
+ number: '1.24.2',
10
10
  };
@@ -76,6 +76,17 @@ export default class TextComponent extends AbstractComponent implements Restylea
76
76
  private static getFontHeight;
77
77
  private computeUntransformedBBoxOfPart;
78
78
  private recomputeBBox;
79
+ /**
80
+ * Renders a TextComponent or a TextComponent child onto a `canvas`.
81
+ *
82
+ * `visibleRect` can be provided as a performance optimization. If not the top-level
83
+ * text node, `baseTransform` (specifies the transformation of the parent text component
84
+ * in canvas space) should also be provided.
85
+ *
86
+ * Note that passing a `baseTransform` is preferable to transforming `visibleRect`. At high
87
+ * zoom levels, transforming `visibleRect` by the inverse of the parent transform can lead to
88
+ * inaccuracy due to precision loss.
89
+ */
79
90
  private renderInternal;
80
91
  render(canvas: AbstractRenderer, visibleRect?: Rect2): void;
81
92
  getProportionalRenderingTime(): number;
@@ -148,11 +148,22 @@ class TextComponent extends AbstractComponent {
148
148
  }
149
149
  this.contentBBox = bbox ?? Rect2.empty;
150
150
  }
151
- renderInternal(canvas, visibleRect) {
151
+ /**
152
+ * Renders a TextComponent or a TextComponent child onto a `canvas`.
153
+ *
154
+ * `visibleRect` can be provided as a performance optimization. If not the top-level
155
+ * text node, `baseTransform` (specifies the transformation of the parent text component
156
+ * in canvas space) should also be provided.
157
+ *
158
+ * Note that passing a `baseTransform` is preferable to transforming `visibleRect`. At high
159
+ * zoom levels, transforming `visibleRect` by the inverse of the parent transform can lead to
160
+ * inaccuracy due to precision loss.
161
+ */
162
+ renderInternal(canvas, visibleRect, baseTransform = Mat33.identity) {
152
163
  const cursor = new TextComponent.TextCursor(this.transform, this.style);
153
164
  for (const textObject of this.textObjects) {
154
165
  const { transform, bbox } = cursor.update(textObject);
155
- if (visibleRect && !visibleRect.intersects(bbox)) {
166
+ if (visibleRect && !visibleRect.intersects(bbox.transformedBoundingBox(baseTransform))) {
156
167
  continue;
157
168
  }
158
169
  if (typeof textObject === 'string') {
@@ -160,7 +171,7 @@ class TextComponent extends AbstractComponent {
160
171
  }
161
172
  else {
162
173
  canvas.pushTransform(transform);
163
- textObject.renderInternal(canvas, visibleRect?.transformedBoundingBox(transform.inverse()));
174
+ textObject.renderInternal(canvas, visibleRect, baseTransform.rightMul(transform));
164
175
  canvas.popTransform();
165
176
  }
166
177
  }
@@ -4,5 +4,5 @@
4
4
  * @internal
5
5
  */
6
6
  export default {
7
- number: '1.24.1',
7
+ number: '1.24.2',
8
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js-draw",
3
- "version": "1.24.1",
3
+ "version": "1.24.2",
4
4
  "description": "Draw pictures using a pen, touchscreen, or mouse! JS-draw is a drawing library for JavaScript and TypeScript. ",
5
5
  "types": "./dist/mjs/lib.d.ts",
6
6
  "main": "./dist/cjs/lib.js",
@@ -64,11 +64,11 @@
64
64
  "postpack": "ts-node tools/copyREADME.ts revert"
65
65
  },
66
66
  "dependencies": {
67
- "@js-draw/math": "^1.24.1",
67
+ "@js-draw/math": "^1.24.2",
68
68
  "@melloware/coloris": "0.22.0"
69
69
  },
70
70
  "devDependencies": {
71
- "@js-draw/build-tool": "^1.24.1",
71
+ "@js-draw/build-tool": "^1.24.2",
72
72
  "@types/jest": "29.5.5",
73
73
  "@types/jsdom": "21.1.3"
74
74
  },
@@ -86,5 +86,5 @@
86
86
  "freehand",
87
87
  "svg"
88
88
  ],
89
- "gitHead": "ef847374748e32d6d96d993a2236a99d9109a32c"
89
+ "gitHead": "32c8db56fc8996c8d485118d1ee37077428344a3"
90
90
  }