Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshot: Set zoom using privileged JS when available #120

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading