1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-21 23:58:07 +02:00

[api-minor] Annotation -- Don't compute appearance when nothing has changed

* don't set a value in annotationStorage by default:
   - having an undefined when the annotation is rendered for saving/printing means nothing has changed so use normal appearance
   - aims to fix https://bugzilla.mozilla.org/show_bug.cgi?id=1681687
 * change the way to compute font size when this one is null in DA:
   - make fontSize proportional to line height
   - in multiline case, take into account the number of lines for text entered to adapt the font size
This commit is contained in:
Calixte Denizet 2020-12-19 18:12:44 +01:00
parent a8021208ea
commit ea06bb0e36
5 changed files with 81 additions and 40 deletions

View file

@ -1808,7 +1808,7 @@ describe("annotation", function () {
}, done.fail)
.then(appearance => {
expect(appearance).toEqual(
"/Tx BMC q BT /Helv 11 Tf 0 g 1 0 0 1 0 0 Tm" +
"/Tx BMC q BT /Helv 8 Tf 0 g 1 0 0 1 0 0 Tm" +
" 2.00 2.00 Td (test \\(print\\)) Tj ET Q EMC"
);
done();
@ -1848,7 +1848,7 @@ describe("annotation", function () {
"\x30\x53\x30\x93\x30\x6b\x30\x61" +
"\x30\x6f\x4e\x16\x75\x4c\x30\x6e";
expect(appearance).toEqual(
"/Tx BMC q BT /Goth 9 Tf 0 g 1 0 0 1 0 0 Tm" +
"/Tx BMC q BT /Goth 8 Tf 0 g 1 0 0 1 0 0 Tm" +
` 2.00 2.00 Td (${utf16String}) Tj ET Q EMC`
);
done();

View file

@ -16,17 +16,21 @@
import { AnnotationStorage } from "../../src/display/annotation_storage.js";
describe("AnnotationStorage", function () {
describe("GetOrCreateValue", function () {
describe("GetOrDefaultValue", function () {
it("should get and set a new value in the annotation storage", function (done) {
const annotationStorage = new AnnotationStorage();
let value = annotationStorage.getOrCreateValue("123A", {
let value = annotationStorage.getValue("123A", {
value: "hello world",
}).value;
expect(value).toEqual("hello world");
annotationStorage.setValue("123A", {
value: "hello world",
});
// the second argument is the default value to use
// if the key isn't in the storage
value = annotationStorage.getOrCreateValue("123A", {
value = annotationStorage.getValue("123A", {
value: "an other string",
}).value;
expect(value).toEqual("hello world");
@ -50,16 +54,18 @@ describe("AnnotationStorage", function () {
called = true;
};
annotationStorage.onSetModified = callback;
annotationStorage.getOrCreateValue("asdf", { value: "original" });
expect(called).toBe(false);
// not changing value
annotationStorage.setValue("asdf", { value: "original" });
expect(called).toBe(false);
expect(called).toBe(true);
// changing value
annotationStorage.setValue("asdf", { value: "modified" });
expect(called).toBe(true);
// not changing value
called = false;
annotationStorage.setValue("asdf", { value: "modified" });
expect(called).toBe(false);
done();
});
});
@ -72,7 +78,10 @@ describe("AnnotationStorage", function () {
called = true;
};
annotationStorage.onResetModified = callback;
annotationStorage.getOrCreateValue("asdf", { value: "original" });
annotationStorage.setValue("asdf", { value: "original" });
annotationStorage.resetModified();
expect(called).toBe(true);
called = false;
// not changing value
annotationStorage.setValue("asdf", { value: "original" });