Skip to content

Commit

Permalink
EPUB appearance: Add 'Use original font' option (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbeJellinek authored and dstillman committed Jul 31, 2024
1 parent 0ab09bc commit e08ceaa
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
18 changes: 17 additions & 1 deletion src/common/components/view-popup/epub-appearance-popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ function EPUBAppearancePopup({ params, onChange, onClose }) {
}

function handleChange(event) {
params[event.target.name] = parseFloat(event.target.value);
if (event.target.type === 'checkbox') {
params[event.target.name] = event.target.checked;
}
else {
params[event.target.name] = parseFloat(event.target.value);
}
onChange(params);
}

Expand Down Expand Up @@ -91,6 +96,17 @@ function EPUBAppearancePopup({ params, onChange, onClose }) {
onClick={() => handleRevert('letterSpacing')}
><IconRevert/></button>
</div>

<div className="checkbox-row">
<input
type="checkbox"
id="use-original-font"
name="useOriginalFont"
checked={params.useOriginalFont}
onChange={handleChange}
/>
<label htmlFor="use-original-font"><FormattedMessage id="pdfReader.epubAppearance.useOriginalFont"/></label>
</div>
</div>
</div>
);
Expand Down
7 changes: 7 additions & 0 deletions src/common/stylesheets/components/_view-popup.scss
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@
}
}

.checkbox-row {
display: flex;
align-items: center;
gap: 4px 8px;
padding-block: 8px;
}

.hidden {
visibility: hidden;
}
Expand Down
1 change: 1 addition & 0 deletions src/dom/epub/defines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ export const DEFAULT_EPUB_APPEARANCE: EPUBAppearance = Object.freeze({
lineHeight: 1.2,
wordSpacing: 0,
letterSpacing: 0,
useOriginalFont: false,
});
2 changes: 2 additions & 0 deletions src/dom/epub/epub-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ class EPUBView extends DOMView<EPUBViewState, EPUBViewData> {
this._iframeDocument.documentElement.style.setProperty('--content-line-height-adjust', String(appearance.lineHeight));
this._iframeDocument.documentElement.style.setProperty('--content-word-spacing-adjust', String(appearance.wordSpacing));
this._iframeDocument.documentElement.style.setProperty('--content-letter-spacing-adjust', String(appearance.letterSpacing));
this._iframeDocument.documentElement.classList.toggle('use-original-font', appearance.useOriginalFont);
this._handleViewUpdate();
}

Expand Down Expand Up @@ -1112,6 +1113,7 @@ export interface EPUBAppearance {
lineHeight: number;
wordSpacing: number;
letterSpacing: number;
useOriginalFont: boolean;
}

export interface EPUBViewData {
Expand Down
10 changes: 7 additions & 3 deletions src/dom/epub/stylesheets/_content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ replaced-body {
background: transparent !important;
color: inherit !important;

font-family: var(--content-font-family, "Georgia"), serif;
:root:not(.use-original-font) & {
font-family: var(--content-font-family, "Georgia", serif);
}
font-size: inherit !important;
line-height: var(--content-line-height) !important;
word-spacing: var(--content-word-spacing) !important;
Expand Down Expand Up @@ -143,9 +145,11 @@ replaced-body {
--content-line-height-compensation: 1.167;
}

p {
p, [role="paragraph"] {
// Really enforce some of our formatting choices on body paragraphs
font-family: var(--content-font-family, "Georgia"), serif !important;
:root:not(.use-original-font) & {
font-family: var(--content-font-family, "Georgia", serif);
}
line-height: var(--content-line-height) !important;
word-spacing: var(--content-word-spacing) !important;
letter-spacing: var(--content-letter-spacing) !important;
Expand Down
1 change: 1 addition & 0 deletions src/en-us.strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export default {
'pdfReader.epubAppearance.lineHeight': 'Line height',
'pdfReader.epubAppearance.wordSpacing': 'Word spacing',
'pdfReader.epubAppearance.letterSpacing': 'Letter spacing',
'pdfReader.epubAppearance.useOriginalFont': 'Use original font',
'pdfReader.epubAppearance.lineHeight.revert': 'Use default line height',
'pdfReader.epubAppearance.wordSpacing.revert': 'Use default word spacing',
'pdfReader.epubAppearance.letterSpacing.revert': 'Use default letter spacing',
Expand Down

0 comments on commit e08ceaa

Please sign in to comment.