Add tooltip if any in annotations layer
This commit is contained in:
parent
b8c856a53a
commit
20b12d2bda
@ -1533,6 +1533,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
|||||||
this.hasFieldFlag(AnnotationFieldFlag.RADIO) &&
|
this.hasFieldFlag(AnnotationFieldFlag.RADIO) &&
|
||||||
!this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON);
|
!this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON);
|
||||||
this.data.pushButton = this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON);
|
this.data.pushButton = this.hasFieldFlag(AnnotationFieldFlag.PUSHBUTTON);
|
||||||
|
this.data.isTooltipOnly = false;
|
||||||
|
|
||||||
if (this.data.checkBox) {
|
if (this.data.checkBox) {
|
||||||
this._processCheckBox(params);
|
this._processCheckBox(params);
|
||||||
@ -1770,11 +1771,13 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_processPushButton(params) {
|
_processPushButton(params) {
|
||||||
if (!params.dict.has("A")) {
|
if (!params.dict.has("A") && !this.data.alternativeText) {
|
||||||
warn("Push buttons without action dictionaries are not supported");
|
warn("Push buttons without action dictionaries are not supported");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.data.isTooltipOnly = !params.dict.has("A");
|
||||||
|
|
||||||
Catalog.parseDestDictionary({
|
Catalog.parseDestDictionary({
|
||||||
destDict: params.dict,
|
destDict: params.dict,
|
||||||
resultObj: this.data,
|
resultObj: this.data,
|
||||||
|
@ -293,7 +293,8 @@ class LinkAnnotationElement extends AnnotationElement {
|
|||||||
const isRenderable = !!(
|
const isRenderable = !!(
|
||||||
parameters.data.url ||
|
parameters.data.url ||
|
||||||
parameters.data.dest ||
|
parameters.data.dest ||
|
||||||
parameters.data.action
|
parameters.data.action ||
|
||||||
|
parameters.data.isTooltipOnly
|
||||||
);
|
);
|
||||||
super(parameters, isRenderable);
|
super(parameters, isRenderable);
|
||||||
}
|
}
|
||||||
@ -322,8 +323,10 @@ class LinkAnnotationElement extends AnnotationElement {
|
|||||||
});
|
});
|
||||||
} else if (data.action) {
|
} else if (data.action) {
|
||||||
this._bindNamedAction(link, data.action);
|
this._bindNamedAction(link, data.action);
|
||||||
} else {
|
} else if (data.dest) {
|
||||||
this._bindLink(link, data.dest);
|
this._bindLink(link, data.dest);
|
||||||
|
} else {
|
||||||
|
this._bindLink(link, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.container.appendChild(link);
|
this.container.appendChild(link);
|
||||||
@ -420,6 +423,10 @@ class WidgetAnnotationElement extends AnnotationElement {
|
|||||||
*/
|
*/
|
||||||
render() {
|
render() {
|
||||||
// Show only the container for unsupported field types.
|
// Show only the container for unsupported field types.
|
||||||
|
if (this.data.alternativeText) {
|
||||||
|
this.container.title = this.data.alternativeText;
|
||||||
|
}
|
||||||
|
|
||||||
return this.container;
|
return this.container;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -647,6 +654,11 @@ class PushButtonWidgetAnnotationElement extends LinkAnnotationElement {
|
|||||||
// as performing actions on form fields (resetting, submitting, et cetera).
|
// as performing actions on form fields (resetting, submitting, et cetera).
|
||||||
const container = super.render();
|
const container = super.render();
|
||||||
container.className = "buttonWidgetAnnotation pushButton";
|
container.className = "buttonWidgetAnnotation pushButton";
|
||||||
|
|
||||||
|
if (this.data.alternativeText) {
|
||||||
|
container.title = this.data.alternativeText;
|
||||||
|
}
|
||||||
|
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2436,6 +2436,49 @@ describe("annotation", function () {
|
|||||||
})
|
})
|
||||||
.catch(done.fail);
|
.catch(done.fail);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should handle push buttons", function (done) {
|
||||||
|
const buttonWidgetRef = Ref.get(124, 0);
|
||||||
|
buttonWidgetDict.set("Ff", AnnotationFieldFlag.PUSHBUTTON);
|
||||||
|
buttonWidgetDict.set("A", "whatever");
|
||||||
|
|
||||||
|
const xref = new XRefMock([
|
||||||
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
||||||
|
]);
|
||||||
|
|
||||||
|
AnnotationFactory.create(
|
||||||
|
xref,
|
||||||
|
buttonWidgetRef,
|
||||||
|
pdfManagerMock,
|
||||||
|
idFactoryMock
|
||||||
|
).then(({ data }) => {
|
||||||
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||||
|
expect(data.pushButton).toEqual(true);
|
||||||
|
done();
|
||||||
|
}, done.fail);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle push buttons that act as a tooltip only", function (done) {
|
||||||
|
const buttonWidgetRef = Ref.get(124, 0);
|
||||||
|
buttonWidgetDict.set("Ff", AnnotationFieldFlag.PUSHBUTTON);
|
||||||
|
buttonWidgetDict.set("TU", "An alternative text");
|
||||||
|
|
||||||
|
const xref = new XRefMock([
|
||||||
|
{ ref: buttonWidgetRef, data: buttonWidgetDict },
|
||||||
|
]);
|
||||||
|
|
||||||
|
AnnotationFactory.create(
|
||||||
|
xref,
|
||||||
|
buttonWidgetRef,
|
||||||
|
pdfManagerMock,
|
||||||
|
idFactoryMock
|
||||||
|
).then(({ data }) => {
|
||||||
|
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
|
||||||
|
expect(data.pushButton).toEqual(true);
|
||||||
|
expect(data.alternativeText).toEqual("An alternative text");
|
||||||
|
done();
|
||||||
|
}, done.fail);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("ChoiceWidgetAnnotation", function () {
|
describe("ChoiceWidgetAnnotation", function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user