Merge pull request #12108 from calixteman/radio
Add support for radios printing
This commit is contained in:
commit
5a66c56eca
@ -1078,16 +1078,19 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
|||||||
if (!isDict(appearanceStates)) {
|
if (!isDict(appearanceStates)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const normalAppearanceState = appearanceStates.get("N");
|
const normalAppearance = appearanceStates.get("N");
|
||||||
if (!isDict(normalAppearanceState)) {
|
if (!isDict(normalAppearance)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (const key of normalAppearanceState.getKeys()) {
|
for (const key of normalAppearance.getKeys()) {
|
||||||
if (key !== "Off") {
|
if (key !== "Off") {
|
||||||
this.data.buttonValue = key;
|
this.data.buttonValue = key;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.checkedAppearance = normalAppearance.get(this.data.buttonValue);
|
||||||
|
this.uncheckedAppearance = normalAppearance.get("Off") || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
_processPushButton(params) {
|
_processPushButton(params) {
|
||||||
|
@ -586,15 +586,35 @@ class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement {
|
|||||||
*/
|
*/
|
||||||
render() {
|
render() {
|
||||||
this.container.className = "buttonWidgetAnnotation radioButton";
|
this.container.className = "buttonWidgetAnnotation radioButton";
|
||||||
|
const storage = this.annotationStorage;
|
||||||
|
const data = this.data;
|
||||||
|
const id = data.id;
|
||||||
|
const value = storage.getOrCreateValue(
|
||||||
|
id,
|
||||||
|
data.fieldValue === data.buttonValue
|
||||||
|
);
|
||||||
|
|
||||||
const element = document.createElement("input");
|
const element = document.createElement("input");
|
||||||
element.disabled = this.data.readOnly;
|
element.disabled = data.readOnly;
|
||||||
element.type = "radio";
|
element.type = "radio";
|
||||||
element.name = this.data.fieldName;
|
element.name = data.fieldName;
|
||||||
if (this.data.fieldValue === this.data.buttonValue) {
|
if (value) {
|
||||||
element.setAttribute("checked", true);
|
element.setAttribute("checked", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
element.addEventListener("change", function (event) {
|
||||||
|
const name = event.target.name;
|
||||||
|
for (const radio of document.getElementsByName(name)) {
|
||||||
|
if (radio !== event.target) {
|
||||||
|
storage.setValue(
|
||||||
|
radio.parentNode.getAttribute("data-annotation-id"),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
storage.setValue(id, event.target.checked);
|
||||||
|
});
|
||||||
|
|
||||||
this.container.appendChild(element);
|
this.container.appendChild(element);
|
||||||
return this.container;
|
return this.container;
|
||||||
}
|
}
|
||||||
|
@ -1622,6 +1622,92 @@ describe("annotation", function () {
|
|||||||
}, done.fail);
|
}, done.fail);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should render checkboxes 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("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);
|
||||||
|
});
|
||||||
|
|
||||||
it("should handle radio buttons with a field value", function (done) {
|
it("should handle radio buttons with a field value", function (done) {
|
||||||
const parentDict = new Dict();
|
const parentDict = new Dict();
|
||||||
parentDict.set("V", Name.get("1"));
|
parentDict.set("V", Name.get("1"));
|
||||||
@ -1656,62 +1742,6 @@ describe("annotation", function () {
|
|||||||
}, done.fail);
|
}, done.fail);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should render checkboxes for printing", function (done) {
|
|
||||||
const appearanceStatesDict = new Dict();
|
|
||||||
const exportValueOptionsDict = new Dict();
|
|
||||||
const normalAppearanceDict = new Dict();
|
|
||||||
const checkedAppearanceDict = new Dict();
|
|
||||||
|
|
||||||
const stream = new StringStream("0.1 0.2 0.3 rg");
|
|
||||||
stream.dict = checkedAppearanceDict;
|
|
||||||
|
|
||||||
checkedAppearanceDict.set("BBox", [0, 0, 8, 8]);
|
|
||||||
checkedAppearanceDict.set("FormType", 1);
|
|
||||||
checkedAppearanceDict.set("Matrix", [1, 0, 0, 1, 0, 0]);
|
|
||||||
normalAppearanceDict.set("Checked", stream);
|
|
||||||
exportValueOptionsDict.set("Off", 0);
|
|
||||||
exportValueOptionsDict.set("Checked", 1);
|
|
||||||
appearanceStatesDict.set("D", exportValueOptionsDict);
|
|
||||||
appearanceStatesDict.set("N", normalAppearanceDict);
|
|
||||||
|
|
||||||
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 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([26, 51, 76])
|
|
||||||
);
|
|
||||||
done();
|
|
||||||
}, done.fail);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should handle radio buttons without a field value", function (done) {
|
it("should handle radio buttons without a field value", function (done) {
|
||||||
const normalAppearanceStateDict = new Dict();
|
const normalAppearanceStateDict = new Dict();
|
||||||
normalAppearanceStateDict.set("2", null);
|
normalAppearanceStateDict.set("2", null);
|
||||||
@ -1741,6 +1771,93 @@ describe("annotation", function () {
|
|||||||
done();
|
done();
|
||||||
}, done.fail);
|
}, 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 () {
|
describe("ChoiceWidgetAnnotation", function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user