fix: render decoded ink coordinates
This commit is contained in:
@@ -70,6 +70,24 @@ const page: OneNotePageDto = {
|
|||||||
size: 12,
|
size: 12,
|
||||||
layout: {},
|
layout: {},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
kind: 'ink',
|
||||||
|
id: 'ink-1',
|
||||||
|
strokes: [
|
||||||
|
{
|
||||||
|
points: [
|
||||||
|
{ x: 10, y: 20 },
|
||||||
|
{ x: 15, y: 25 },
|
||||||
|
{ x: 30, y: 40 },
|
||||||
|
],
|
||||||
|
width: 2,
|
||||||
|
color: 0xff0000,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
children: [],
|
||||||
|
boundingBox: { x: 10, y: 20, width: 20, height: 20 },
|
||||||
|
layout: {},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
diagnostics: [],
|
diagnostics: [],
|
||||||
};
|
};
|
||||||
@@ -105,6 +123,13 @@ describe('PageReader structured content', () => {
|
|||||||
'https://example.com/'
|
'https://example.com/'
|
||||||
);
|
);
|
||||||
expect(screen.getByRole('table')).toHaveTextContent('AB');
|
expect(screen.getByRole('table')).toHaveTextContent('AB');
|
||||||
|
expect(
|
||||||
|
screen.getByRole('img', { name: '1 handwritten or drawn stroke' })
|
||||||
|
).toHaveAttribute('viewBox', '-60 -50 160 160');
|
||||||
|
expect(document.querySelector('.onenote-ink path')).toHaveAttribute(
|
||||||
|
'd',
|
||||||
|
'M 10 20 L 15 25 30 40'
|
||||||
|
);
|
||||||
await waitFor(() =>
|
await waitFor(() =>
|
||||||
expect(
|
expect(
|
||||||
screen.getByRole('img', { name: 'Embedded diagram' })
|
screen.getByRole('img', { name: 'Embedded diagram' })
|
||||||
|
|||||||
@@ -472,10 +472,10 @@ function InkView({ ink }: { ink: OneNoteInkBlock }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function inkPath(stroke: OneNoteInkStroke): string {
|
function inkPath(stroke: OneNoteInkStroke): string {
|
||||||
const [first, ...deltas] = stroke.points;
|
const [first, ...points] = stroke.points;
|
||||||
if (!first) return '';
|
if (!first) return '';
|
||||||
if (deltas.length === 0) return `M ${first.x} ${first.y} l 0 0`;
|
if (points.length === 0) return `M ${first.x} ${first.y} l 0 0`;
|
||||||
return `M ${first.x} ${first.y} l ${deltas
|
return `M ${first.x} ${first.y} L ${points
|
||||||
.map((point) => `${point.x} ${point.y}`)
|
.map((point) => `${point.x} ${point.y}`)
|
||||||
.join(' ')}`;
|
.join(' ')}`;
|
||||||
}
|
}
|
||||||
@@ -488,21 +488,11 @@ function boundingBoxFromInk(
|
|||||||
let xMax = -Infinity;
|
let xMax = -Infinity;
|
||||||
let yMax = -Infinity;
|
let yMax = -Infinity;
|
||||||
for (const stroke of strokes) {
|
for (const stroke of strokes) {
|
||||||
const [first, ...deltas] = stroke.points;
|
for (const point of stroke.points) {
|
||||||
if (!first) continue;
|
xMin = Math.min(xMin, point.x);
|
||||||
let x = first.x;
|
yMin = Math.min(yMin, point.y);
|
||||||
let y = first.y;
|
xMax = Math.max(xMax, point.x);
|
||||||
xMin = Math.min(xMin, x);
|
yMax = Math.max(yMax, point.y);
|
||||||
yMin = Math.min(yMin, y);
|
|
||||||
xMax = Math.max(xMax, x);
|
|
||||||
yMax = Math.max(yMax, y);
|
|
||||||
for (const delta of deltas) {
|
|
||||||
x += delta.x;
|
|
||||||
y += delta.y;
|
|
||||||
xMin = Math.min(xMin, x);
|
|
||||||
yMin = Math.min(yMin, y);
|
|
||||||
xMax = Math.max(xMax, x);
|
|
||||||
yMax = Math.max(yMax, y);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Number.isFinite(xMin)
|
return Number.isFinite(xMin)
|
||||||
|
|||||||
Reference in New Issue
Block a user