Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/core/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,8 @@ class Annotation {

const text = [];
const buffer = [];
let firstPositionX = Infinity;
let firstPositionY = Infinity;
let firstPosition = null;
const sink = {
desiredSize: Math.Infinity,
Expand All @@ -1288,7 +1290,8 @@ class Annotation {
if (item.str === undefined) {
continue;
}
firstPosition ||= item.transform.slice(-2);
firstPositionX = Math.min(firstPositionX, item.transform[4]);
firstPositionY = Math.min(firstPositionY, item.transform[5]);
buffer.push(item.str);
if (item.hasEOL) {
text.push(buffer.join("").trimEnd());
Expand All @@ -1309,6 +1312,10 @@ class Annotation {
});
this.reset();

if (firstPositionX !== Infinity) {
firstPosition = [firstPositionX, firstPositionY];
}

if (buffer.length) {
text.push(buffer.join("").trimEnd());
}
Expand Down
4 changes: 3 additions & 1 deletion src/core/default_appearance.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
LINE_FACTOR,
OPS,
shadow,
Util,
warn,
} from "../shared/util.js";
import { ColorSpaceUtils } from "./colorspace_utils.js";
Expand Down Expand Up @@ -145,7 +146,8 @@ class AppearanceStreamEvaluator extends EvaluatorPreprocessor {
result = stack.pop() || result;
break;
case OPS.setTextMatrix:
result.scaleFactor *= Math.hypot(args[0], args[1]);
const tm = Util.transform(this.stateManager.state.ctm, args);
result.scaleFactor *= Math.hypot(tm[0], tm[1]);
break;
case OPS.setFont:
const [fontName, fontSize] = args;
Expand Down
54 changes: 54 additions & 0 deletions test/integration/freetext_editor_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1799,6 +1799,60 @@ describe("FreeText Editor", () => {
});
});

describe("FreeText (open existing generated with Cairo)", () => {
let pages;

beforeEach(async () => {
pages = await loadAndWait(
"issue20504.pdf",
".annotationEditorLayer",
100
);
});

afterEach(async () => {
await closePages(pages);
});

it("must open some existing annotations", async () => {
await Promise.all(
pages.map(async ([browserName, page]) => {
const boxes = [];
for (const num of [48, 49, 50, 51, 52]) {
const id = `${num}R`;
await page.waitForSelector(getAnnotationSelector(id), {
visible: true,
});
const rect = await getRect(page, getAnnotationSelector(id));
boxes.push(rect);
}

await switchToFreeText(page);

for (let i = 0; i < boxes.length; i++) {
const rect = await getRect(
page,
`#pdfjs_internal_editor_${i}-editor`
);

expect(Math.abs(rect.width - boxes[i].width) <= 20)
.withContext(`In ${browserName}`)
.toEqual(true);
expect(Math.abs(rect.height - boxes[i].height) <= 20)
.withContext(`In ${browserName}`)
.toEqual(true);
expect(Math.abs(rect.x - boxes[i].x) <= 20)
.withContext(`In ${browserName}`)
.toEqual(true);
expect(Math.abs(rect.y - boxes[i].y) <= 20)
.withContext(`In ${browserName}`)
.toEqual(true);
}
})
);
});
});

describe("Keyboard shortcuts when the editor layer isn't focused", () => {
let pages;

Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -765,3 +765,4 @@
!two_paragraphs.pdf
!paragraph_and_link.pdf
!issue20225.pdf
!issue20504.pdf
Binary file added test/pdfs/issue20504.pdf
Binary file not shown.