Annotation & XFA: Scale the font size in choicelist using zoom factor (bug 1715996)

- this is an accessibility issue which could be painful for some people with visual disabilities.
This commit is contained in:
Calixte Denizet 2021-08-04 14:42:24 +02:00
parent 52ef63f1fe
commit 71a100a4d0
4 changed files with 21 additions and 0 deletions

View File

@ -1293,6 +1293,10 @@ class ChoiceList extends XFAObject {
const style = toStyle(this, "border", "margin");
const ui = this[$getParent]();
const field = ui[$getParent]();
const fontSize = (field.font && field.font.size) || 10;
const optionStyle = {
fontSize: `calc(${fontSize}px * var(--zoom-factor))`,
};
const children = [];
if (field.items.children.length > 0) {
@ -1313,6 +1317,7 @@ class ChoiceList extends XFAObject {
name: "option",
attributes: {
value: values[i] || displayed[i],
style: optionStyle,
},
value: displayed[i],
};

View File

@ -1138,11 +1138,19 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
this.data.fieldValue.length > 0 ? this.data.fieldValue[0] : undefined,
});
let { fontSize } = this.data.defaultAppearanceData;
if (!fontSize) {
fontSize = 9;
}
const fontSizeStyle = `calc(${fontSize}px * var(--zoom-factor))`;
const selectElement = document.createElement("select");
selectElement.disabled = this.data.readOnly;
selectElement.name = this.data.fieldName;
selectElement.setAttribute("id", id);
selectElement.style.fontSize = `${fontSize}px`;
if (!this.data.combo) {
// List boxes have a size and (optionally) multiple selection.
selectElement.size = this.data.options.length;
@ -1156,6 +1164,9 @@ class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement {
const optionElement = document.createElement("option");
optionElement.textContent = option.displayValue;
optionElement.value = option.exportValue;
if (this.data.combo) {
optionElement.style.fontSize = fontSizeStyle;
}
if (this.data.fieldValue.includes(option.exportValue)) {
optionElement.setAttribute("selected", true);
}

View File

@ -203,6 +203,8 @@ class BaseViewer {
this.renderingQueue = options.renderingQueue;
}
this._doc = document.documentElement;
this.scroll = watchScroll(this.container, this._scrollUpdate.bind(this));
this.presentationModeState = PresentationModeState.UNKNOWN;
this._onBeforeDraw = this._onAfterDraw = null;
@ -707,6 +709,8 @@ class BaseViewer {
return;
}
this._doc.style.setProperty("--zoom-factor", newScale);
for (let i = 0, ii = this._pages.length; i < ii; i++) {
this._pages[i].update(newScale);
}

View File

@ -21,6 +21,7 @@
--page-margin: 1px auto -8px;
--page-border: 9px solid transparent;
--spreadHorizontalWrapped-margin-LR: -3.5px;
--zoom-factor: 1;
}
@media screen and (forced-colors: active) {