Merge pull request #13868 from calixteman/zoom_select

Annotation & XFA: Scale the font size in choicelist using zoom factor (bug 1715996)
This commit is contained in:
Jonas Jenwald 2021-08-05 10:45:13 +02:00 committed by GitHub
commit 4ad65c8b9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 style = toStyle(this, "border", "margin");
const ui = this[$getParent](); const ui = this[$getParent]();
const field = ui[$getParent](); const field = ui[$getParent]();
const fontSize = (field.font && field.font.size) || 10;
const optionStyle = {
fontSize: `calc(${fontSize}px * var(--zoom-factor))`,
};
const children = []; const children = [];
if (field.items.children.length > 0) { if (field.items.children.length > 0) {
@ -1313,6 +1317,7 @@ class ChoiceList extends XFAObject {
name: "option", name: "option",
attributes: { attributes: {
value: values[i] || displayed[i], value: values[i] || displayed[i],
style: optionStyle,
}, },
value: displayed[i], value: displayed[i],
}; };

View File

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

View File

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

View File

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