mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
[api-minor] Add basic support for RTL text-content in PopupAnnotations (issue 14046)
In order to implement this, we utilize the existing `bidi` function to infer the text-direction of /T and /Contents entries. While this may not be perfect in cases where one PopupAnnotation mixes LTR and RTL languages, it should work well enough in most cases. To avoid having to add *two new* properties in lots of annotations, supplementing the existing `title`/`contents`-properties, this patch instead re-factors the existing code such that the properties are replaced by Objects (containing `str` and `dir`). *Please note:* In order avoid breaking existing third-party implementations, `GENERIC`-builds of the PDF.js library will still provide the old `title`/`contents`-properties on annotations returned by `PDFPageProxy.getAnnotations`.
This commit is contained in:
parent
104e049338
commit
1dcd2f0cd3
8 changed files with 124 additions and 57 deletions
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
|
@ -15,6 +15,7 @@
|
|||
!bug1727053.pdf
|
||||
!issue2391-1.pdf
|
||||
!issue2391-2.pdf
|
||||
!issue14046.pdf
|
||||
!issue3214.pdf
|
||||
!issue4665.pdf
|
||||
!issue4684.pdf
|
||||
|
|
BIN
test/pdfs/issue14046.pdf
Normal file
BIN
test/pdfs/issue14046.pdf
Normal file
Binary file not shown.
|
@ -5929,5 +5929,12 @@
|
|||
"link": true,
|
||||
"forms": true,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "issue14046",
|
||||
"file": "pdfs/issue14046.pdf",
|
||||
"md5": "dbb5d4e284ca9cc3219e04af6ce64e13",
|
||||
"rounds": 1,
|
||||
"type": "eq",
|
||||
"annotations": true
|
||||
}
|
||||
]
|
||||
|
|
|
@ -312,14 +312,14 @@ describe("annotation", function () {
|
|||
const annotation = new Annotation({ dict, ref });
|
||||
annotation.setContents("Foo bar baz");
|
||||
|
||||
expect(annotation.contents).toEqual("Foo bar baz");
|
||||
expect(annotation._contents).toEqual({ str: "Foo bar baz", dir: "ltr" });
|
||||
});
|
||||
|
||||
it("should not set and get invalid contents", function () {
|
||||
const annotation = new Annotation({ dict, ref });
|
||||
annotation.setContents(undefined);
|
||||
|
||||
expect(annotation.contents).toEqual("");
|
||||
expect(annotation._contents).toEqual({ str: "", dir: "ltr" });
|
||||
});
|
||||
|
||||
it("should set and get a valid modification date", function () {
|
||||
|
@ -610,8 +610,8 @@ describe("annotation", function () {
|
|||
);
|
||||
expect(data.inReplyTo).toEqual(annotationRef.toString());
|
||||
expect(data.replyType).toEqual("Group");
|
||||
expect(data.title).toEqual("ParentTitle");
|
||||
expect(data.contents).toEqual("ParentText");
|
||||
expect(data.titleObj).toEqual({ str: "ParentTitle", dir: "ltr" });
|
||||
expect(data.contentsObj).toEqual({ str: "ParentText", dir: "ltr" });
|
||||
expect(data.creationDate).toEqual("D:20180423");
|
||||
expect(data.modificationDate).toEqual("D:20190423");
|
||||
expect(data.color).toEqual(new Uint8ClampedArray([0, 0, 255]));
|
||||
|
@ -665,8 +665,8 @@ describe("annotation", function () {
|
|||
);
|
||||
expect(data.inReplyTo).toEqual(annotationRef.toString());
|
||||
expect(data.replyType).toEqual("R");
|
||||
expect(data.title).toEqual("ReplyTitle");
|
||||
expect(data.contents).toEqual("ReplyText");
|
||||
expect(data.titleObj).toEqual({ str: "ReplyTitle", dir: "ltr" });
|
||||
expect(data.contentsObj).toEqual({ str: "ReplyText", dir: "ltr" });
|
||||
expect(data.creationDate).toEqual("D:20180523");
|
||||
expect(data.modificationDate).toEqual("D:20190523");
|
||||
expect(data.color).toEqual(new Uint8ClampedArray([102, 102, 102]));
|
||||
|
@ -3621,8 +3621,8 @@ describe("annotation", function () {
|
|||
pdfManagerMock,
|
||||
idFactoryMock
|
||||
);
|
||||
expect(data.title).toEqual("Correct Title");
|
||||
expect(data.contents).toEqual("Correct Text");
|
||||
expect(data.titleObj).toEqual({ str: "Correct Title", dir: "ltr" });
|
||||
expect(data.contentsObj).toEqual({ str: "Correct Text", dir: "ltr" });
|
||||
expect(data.modificationDate).toEqual("D:20190423");
|
||||
expect(data.color).toEqual(new Uint8ClampedArray([0, 0, 255]));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue