mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Add support for radios printing
This commit is contained in:
parent
eb4d6a0652
commit
538017f7a7
3 changed files with 150 additions and 40 deletions
|
@ -1622,40 +1622,6 @@ describe("annotation", function () {
|
|||
}, done.fail);
|
||||
});
|
||||
|
||||
it("should handle radio buttons with a field value", function (done) {
|
||||
const parentDict = new Dict();
|
||||
parentDict.set("V", Name.get("1"));
|
||||
|
||||
const normalAppearanceStateDict = new Dict();
|
||||
normalAppearanceStateDict.set("2", null);
|
||||
|
||||
const appearanceStatesDict = new Dict();
|
||||
appearanceStatesDict.set("N", normalAppearanceStateDict);
|
||||
|
||||
buttonWidgetDict.set("Ff", AnnotationFieldFlag.RADIO);
|
||||
buttonWidgetDict.set("Parent", parentDict);
|
||||
buttonWidgetDict.set("AP", appearanceStatesDict);
|
||||
|
||||
const buttonWidgetRef = Ref.get(124, 0);
|
||||
const xref = new XRefMock([
|
||||
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
||||
]);
|
||||
|
||||
AnnotationFactory.create(
|
||||
xref,
|
||||
buttonWidgetRef,
|
||||
pdfManagerMock,
|
||||
idFactoryMock
|
||||
).then(({ data }) => {
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
expect(data.checkBox).toEqual(false);
|
||||
expect(data.radioButton).toEqual(true);
|
||||
expect(data.fieldValue).toEqual("1");
|
||||
expect(data.buttonValue).toEqual("2");
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
|
||||
it("should render checkboxes for printing", function (done) {
|
||||
const appearanceStatesDict = new Dict();
|
||||
const exportValueOptionsDict = new Dict();
|
||||
|
@ -1712,6 +1678,40 @@ describe("annotation", function () {
|
|||
}, done.fail);
|
||||
});
|
||||
|
||||
it("should handle radio buttons with a field value", function (done) {
|
||||
const parentDict = new Dict();
|
||||
parentDict.set("V", Name.get("1"));
|
||||
|
||||
const normalAppearanceStateDict = new Dict();
|
||||
normalAppearanceStateDict.set("2", null);
|
||||
|
||||
const appearanceStatesDict = new Dict();
|
||||
appearanceStatesDict.set("N", normalAppearanceStateDict);
|
||||
|
||||
buttonWidgetDict.set("Ff", AnnotationFieldFlag.RADIO);
|
||||
buttonWidgetDict.set("Parent", parentDict);
|
||||
buttonWidgetDict.set("AP", appearanceStatesDict);
|
||||
|
||||
const buttonWidgetRef = Ref.get(124, 0);
|
||||
const xref = new XRefMock([
|
||||
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
||||
]);
|
||||
|
||||
AnnotationFactory.create(
|
||||
xref,
|
||||
buttonWidgetRef,
|
||||
pdfManagerMock,
|
||||
idFactoryMock
|
||||
).then(({ data }) => {
|
||||
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||
expect(data.checkBox).toEqual(false);
|
||||
expect(data.radioButton).toEqual(true);
|
||||
expect(data.fieldValue).toEqual("1");
|
||||
expect(data.buttonValue).toEqual("2");
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
|
||||
it("should handle radio buttons without a field value", function (done) {
|
||||
const normalAppearanceStateDict = new Dict();
|
||||
normalAppearanceStateDict.set("2", null);
|
||||
|
@ -1741,6 +1741,93 @@ describe("annotation", function () {
|
|||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
|
||||
it("should render radio buttons for printing", function (done) {
|
||||
const appearanceStatesDict = new Dict();
|
||||
const exportValueOptionsDict = new Dict();
|
||||
const normalAppearanceDict = new Dict();
|
||||
const checkedAppearanceDict = new Dict();
|
||||
const uncheckedAppearanceDict = new Dict();
|
||||
|
||||
const checkedStream = new StringStream("0.1 0.2 0.3 rg");
|
||||
checkedStream.dict = checkedAppearanceDict;
|
||||
|
||||
const uncheckedStream = new StringStream("0.3 0.2 0.1 rg");
|
||||
uncheckedStream.dict = uncheckedAppearanceDict;
|
||||
|
||||
checkedAppearanceDict.set("BBox", [0, 0, 8, 8]);
|
||||
checkedAppearanceDict.set("FormType", 1);
|
||||
checkedAppearanceDict.set("Matrix", [1, 0, 0, 1, 0, 0]);
|
||||
normalAppearanceDict.set("Checked", checkedStream);
|
||||
normalAppearanceDict.set("Off", uncheckedStream);
|
||||
exportValueOptionsDict.set("Off", 0);
|
||||
exportValueOptionsDict.set("Checked", 1);
|
||||
appearanceStatesDict.set("D", exportValueOptionsDict);
|
||||
appearanceStatesDict.set("N", normalAppearanceDict);
|
||||
|
||||
buttonWidgetDict.set("Ff", AnnotationFieldFlag.RADIO);
|
||||
buttonWidgetDict.set("AP", appearanceStatesDict);
|
||||
|
||||
const buttonWidgetRef = Ref.get(124, 0);
|
||||
const xref = new XRefMock([
|
||||
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
||||
]);
|
||||
const task = new WorkerTask("test print");
|
||||
|
||||
AnnotationFactory.create(
|
||||
xref,
|
||||
buttonWidgetRef,
|
||||
pdfManagerMock,
|
||||
idFactoryMock
|
||||
)
|
||||
.then(annotation => {
|
||||
const annotationStorage = {};
|
||||
annotationStorage[annotation.data.id] = true;
|
||||
return Promise.all([
|
||||
annotation,
|
||||
annotation.getOperatorList(
|
||||
partialEvaluator,
|
||||
task,
|
||||
false,
|
||||
annotationStorage
|
||||
),
|
||||
]);
|
||||
}, done.fail)
|
||||
.then(([annotation, opList]) => {
|
||||
expect(opList.argsArray.length).toEqual(3);
|
||||
expect(opList.fnArray).toEqual([
|
||||
OPS.beginAnnotation,
|
||||
OPS.setFillRGBColor,
|
||||
OPS.endAnnotation,
|
||||
]);
|
||||
expect(opList.argsArray[1]).toEqual(
|
||||
new Uint8ClampedArray([26, 51, 76])
|
||||
);
|
||||
return annotation;
|
||||
}, done.fail)
|
||||
.then(annotation => {
|
||||
const annotationStorage = {};
|
||||
annotationStorage[annotation.data.id] = false;
|
||||
return annotation.getOperatorList(
|
||||
partialEvaluator,
|
||||
task,
|
||||
false,
|
||||
annotationStorage
|
||||
);
|
||||
}, done.fail)
|
||||
.then(opList => {
|
||||
expect(opList.argsArray.length).toEqual(3);
|
||||
expect(opList.fnArray).toEqual([
|
||||
OPS.beginAnnotation,
|
||||
OPS.setFillRGBColor,
|
||||
OPS.endAnnotation,
|
||||
]);
|
||||
expect(opList.argsArray[1]).toEqual(
|
||||
new Uint8ClampedArray([76, 51, 26])
|
||||
);
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
});
|
||||
|
||||
describe("ChoiceWidgetAnnotation", function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue