Skip to content

Commit

Permalink
Snapshot: Set zoom using privileged JS when available
Browse files Browse the repository at this point in the history
  • Loading branch information
AbeJellinek committed Apr 17, 2024
1 parent 1e124aa commit f26a86a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
8 changes: 7 additions & 1 deletion src/common/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Reader {
this._onIframeTab = options.onIframeTab;
// Only used on Zotero client, sets text/plain and text/html values from Note Markdown and Note HTML translators
this._onSetDataTransferAnnotations = options.onSetDataTransferAnnotations;
this._onSetZoom = options.onSetZoom;

this._localizedStrings = options.localizedStrings;

Expand Down Expand Up @@ -736,6 +737,10 @@ class Reader {
this._keyboardManager.handleViewKeyUp(event);
};

let onSetZoom = (iframe, zoom) => {
this._onSetZoom(iframe, zoom);
};

let data;
if (this._type === 'pdf') {
data = this._data;
Expand Down Expand Up @@ -811,7 +816,8 @@ class Reader {
});
} else if (this._type === 'snapshot') {
view = new SnapshotView({
...common
...common,
onSetZoom
});
}

Expand Down
1 change: 1 addition & 0 deletions src/dom/common/dom-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,7 @@ export type DOMViewOptions<State extends DOMViewState, Data> = {
onSetAnnotationPopup: (params?: AnnotationPopupParams<WADMAnnotation> | null) => void;
onSetOverlayPopup: (params?: OverlayPopupParams) => void;
onSetFindState: (state?: FindState) => void;
onSetZoom?: (iframe: HTMLIFrameElement, zoom: number) => void;
onOpenViewContextMenu: (params: { x: number, y: number }) => void;
onOpenAnnotationContextMenu: (params: { ids: string[], x: number, y: number, view: boolean }) => void;
onFocus: () => void;
Expand Down
24 changes: 15 additions & 9 deletions src/dom/snapshot/snapshot-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,17 +438,23 @@ class SnapshotView extends DOMView<SnapshotViewState, SnapshotViewData> {

private _setScale(scale: number) {
this._scale = scale;
if (scale == 1) {
this._iframeDocument.documentElement.style.fontSize = '';
return;

if (this._options.onSetZoom) {
this._options.onSetZoom(this._iframe, scale);
}
else {
if (scale == 1) {
this._iframeDocument.documentElement.style.fontSize = '';
return;
}

// Calculate the default root font size, then multiply by scale.
// Can't just set font-size to an em value -- the page itself might set a font-size on <html>, and we need to
// scale relative to that.
this._iframeDocument.documentElement.style.fontSize = '';
let defaultSize = parseFloat(getComputedStyle(this._iframeDocument.documentElement).fontSize);
this._iframeDocument.documentElement.style.fontSize = (defaultSize * scale) + 'px';
// Calculate the default root font size, then multiply by scale.
// Can't just set font-size to an em value -- the page itself might set a font-size on <html>, and we need to
// scale relative to that.
this._iframeDocument.documentElement.style.fontSize = '';
let defaultSize = parseFloat(getComputedStyle(this._iframeDocument.documentElement).fontSize);
this._iframeDocument.documentElement.style.fontSize = (defaultSize * scale) + 'px';
}
}

override navigate(location: NavLocation, options: NavigateOptions = {}) {
Expand Down

0 comments on commit f26a86a

Please sign in to comment.