Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

annotation bounding and canvas wrapping

Siddharth4b3afcf535d3
diff --git a/src/lib/exporter/annotationRenderer.ts b/src/lib/exporter/annotationRenderer.ts
index af04e193d..06c41217b 100644
--- a/src/lib/exporter/annotationRenderer.ts
+++ b/src/lib/exporter/annotationRenderer.ts
@@ -138,7 +138,12 @@ function renderText(
const style = annotation.style;
ctx.save();
-
+
+ // Clip text to annotation box bounds (matches editor's overflow: hidden)
+ ctx.beginPath();
+ ctx.rect(x, y, width, height);
+ ctx.clip();
+
const fontWeight = style.fontWeight === 'bold' ? 'bold' : 'normal';
const fontStyle = style.fontStyle === 'italic' ? 'italic' : 'normal';
const scaledFontSize = style.fontSize * scaleFactor;
@@ -161,7 +166,27 @@ function renderText(
ctx.textAlign = 'left';
}
- const lines = annotation.content.split('\n');
+ const availableWidth = width - containerPadding * 2;
+ const rawLines = annotation.content.split('\n');
+ const lines: string[] = [];
+ for (const rawLine of rawLines) {
+ if (!rawLine) {
+ lines.push('');
+ continue;
+ }
+ const words = rawLine.split(/(\s+)/);
+ let current = '';
+ for (const word of words) {
+ const test = current + word;
+ if (current && ctx.measureText(test).width > availableWidth) {
+ lines.push(current);
+ current = word.trimStart();
+ } else {
+ current = test;
+ }
+ }
+ if (current) lines.push(current);
+ }
const lineHeight = scaledFontSize * 1.4;
const startY = textY - ((lines.length - 1) * lineHeight) / 2;