Skip to content

Commit 810cc90

Browse files
committed
Correct base line-height
Resolves #166
1 parent db6fa0a commit 810cc90

14 files changed

Lines changed: 22 additions & 134 deletions

css/src/modules/ReadiumCSS-base.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
/* For square-ish fonts (CJK, Indic, etc.), we must apply some compensation in dynamic leading. Default is 1 i.e. no compensation */
2626
--RS__lineHeightCompensation: 1;
2727

28-
/* Dynamic leading based on typeface metrics + font-size setting */
29-
--RS__baseLineHeight: calc((1em + (2ex - 1ch) - ((1rem - 16px) * 0.1667)) * var(--RS__lineHeightCompensation));
28+
--RS__baseLineHeight: calc(1.5 * var(--RS__lineHeightCompensation));
3029
}
3130

3231
/* Set default font for the html doc, so that it can be overridden by the authors’s stylesheet */

docs/CSS08-defaults.md

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ Please note some languages have a specific font-stack (japanese, chinese, hindi,
150150

151151
The default line-height for body copy in case the ebook doesn’t have one declared.
152152

153-
We’re using an algorithm to find the ideal `line-height` for the current font based on its metrics (see details in the next subsection below).
154-
155153
* * *
156154

157155
```
@@ -162,31 +160,6 @@ The compensation factor (integer) the dynamic leading pseudo-algorithm must appl
162160

163161
This variable is redefined by default, in languages and scripts which need compensation due to the characteristics of their average fonts’ metrics.
164162

165-
### Dynamic leading (line-height)
166-
167-
If we don’t provide a base `line-height` and the author hasn’t explicitely set one, then the `normal` value will be applied. On average, it is less than `1.2`, which makes leading quite solid and can quickly become a readability issue with some fonts, especially the ones with a large x-height.
168-
169-
Readium CSS consequently uses an algorithm to find the ideal leading for each font by default (with a fallback value accomodating every script/language it supports).
170-
171-
This algorithm tries to:
172-
173-
1. automagically adjust the `line-height` to the current typeface;
174-
2. adjust this ideal `line-height` it has just computed to the current `font-size` the user has set.
175-
176-
```
177-
calc((1em + (2ex - 1ch) - ((1rem - 16px) * 0.1667)) * var(--RS__lineHeightCompensation))
178-
```
179-
180-
In which, `--RS__lineHeightCompensation` is a factor whose default is `1`. Indeed, the `line-height` is usually 15–20% larger in CJK than in other scripts/languages (factor of `1.167`), but it can also used for square-ish fonts, especially in Indic.
181-
182-
The results we could get for the vast majority of fonts can be described as good in terms of typographic color. Here is Iowan Old Style for instance.
183-
184-
![Comparison of the algorithm using four different font-sizes with the Iowan Old Style typeface. We can notice that the leading applied is solider as font-size increases, which results in a relatively even distribution of typographic color. This is confirmed by the computed values retrieved in the tool ReadiumCSS provides for testing.](assets/dynamic-leading.jpg)
185-
186-
This isn’t a perfect solution though, and this algorithm may be revisited in the future.
187-
188-
See [Further Details](../docs/CSS18-further_details.md) for an extensive explanation.
189-
190163
## Day Mode
191164

192165
The `ReadiumCSS-day_mode.css` stylesheet serves as a default and handles `background-color` and `color` for `:root` and `::selection`.

docs/CSS18-further_details.md

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -130,32 +130,6 @@ An optional primary accentuation `color` you could use for headings or any other
130130

131131
An optional secondary accentuation `color` you could use for any element of your choice.
132132

133-
## Dynamic leading
134-
135-
Readium CSS automagically finds the ideal `line-height` of the current font and `font-size` in use if the author hasn’t set an explicit value.
136-
137-
We’re using the current algorithm in the `calc()` function:
138-
139-
```
140-
(1em + (2ex - 1ch) - ((1rem - 16px) * 0.1667)) * var(--RS__lineHeightCompensation))
141-
```
142-
143-
Therefore, the `line-height` is:
144-
145-
1. `1em` = the size of the `font-size`;
146-
2. `2ex - 1ch` = 2 x-height - 1 character width (`0`), in order to take the typeface’s proportions into account e.g. if the font has a small x-height, leading will be more solid, and vice versa;
147-
3. `1rem - 16px` = the current user’s `font-size` minus the one at `100%` (base `font-size`);
148-
4. `0.1667` = a scale which has been defined from an optimal range ([it is a magic number](https://css-tricks.com/magic-numbers-in-css/) which has been retro-engineered from a set containing hundreds of samples);
149-
5. `var(--RS__lineHeightCompensation)` is a factor (integer) to compensate a less than ideal `line-height`, especially in non-Latin scripts, where fonts tend to be square-ish.
150-
151-
This isn’t a perfect solution though, and this algorithm may be revisited in the future. Indeed, caveats are:
152-
153-
- leading also depends on line-length, which is not addressed in the algorithm itself, line-length must therefore be constrained by other means – we couldn’t rely on the viewport `width` anyway;
154-
- sometimes, the User Agent default `font-size` is not `16px` (e.g. Kindle experimental browser, user setting a larger `font-size`, etc.);
155-
- `0.1667` feels like a magic number, or at least a weird number as it was retrofitted after testing hundreds of typefaces;
156-
- it’s clearly a natural logarithmic function i.e. it increases rapidly and then slows towards a zero rate of change, which will give mediocre results for very large font sizes (e.g. `400%`);
157-
- it doesn’t work ideally for slab serif fonts with a large x-height, thick stroke and medium character width i.e. square-ish metrics – we don’t have any in the default font-stacks so we had to introduce a compensation factor to address this particular issue.
158-
159133
## Conditional Selectors for user settings
160134

161135
User settings are appended on load and won’t have any effect until a user-setting variable is set.

docs/CSS28-migration_guide.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,10 @@ Previously, you had to rely on day, sepia, and night mode to enforce the color o
172172

173173
These decisions are now made to consumers’ discretion, which means they can invert images in their darkest custom themes without having to override ReadiumCSS’ night mode colors for instance, or offer these features to users as they see fit – globally or scoped to a subset of themes – in their app.
174174

175-
**Note you’ll have to take gaiji into account in dark custom themes as inverting them so that they match the color of text can only be done automatically in readiumCSS’ own night mode.**
175+
**Note you’ll have to take gaiji into account in dark custom themes as inverting them so that they match the color of text can only be done automatically in readiumCSS’ own night mode.**
176+
177+
## Removal of Dynamic Leading
178+
179+
Since version `2.0.0-beta.6`, ReadiumCSS is no longer using an algorithm to guess the ideal line-height for each font, and recompute it on font-size change, as it created issues with the new font-size setting implementation.
180+
181+
It simply uses value `1.5` for [accessibility purposes](https://developer.mozilla.org/en-US/docs/Web/CSS/line-height#accessibility), and compensates this value for various languages (e.g. CJK).

docs/ReadiumCSS_docs.epub

-380 KB
Binary file not shown.
-398 KB
Binary file not shown.

docs/ReadiumCSS_docs/OEBPS/Text/Section-008.xhtml

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@
156156

157157
<p>The default line-height for body copy in case the ebook doesn’t have one declared.</p>
158158

159-
<p>We’re using an algorithm to find the ideal <code>line-height</code> for the current font based on its metrics (see details in the next subsection below).</p>
160-
161159
<hr/>
162160

163161
<pre><code>--RS__lineHeightCompensation</code></pre>
@@ -167,37 +165,6 @@
167165
<p>This variable is redefined by default, in languages and scripts which need compensation due to the characteristics of their average fonts’ metrics.</p>
168166
</section>
169167
</section>
170-
171-
<section id="dynamic-leading-line-height" class="level3">
172-
<h3 class="sigil_not_in_toc">Dynamic leading (line-height)</h3>
173-
174-
<p>If we don’t provide a base <code>line-height</code> and the author hasn’t explicitely set one, then the <code>normal</code> value will be applied. On average, it is less than <code>1.2</code>, which makes leading quite solid and can quickly become a readability issue with some fonts, especially the ones with a large x-height.</p>
175-
176-
<p>Readium CSS consequently uses an algorithm to find the ideal leading for each font by default (with a fallback value accomodating every script/language it supports).</p>
177-
178-
<p>This algorithm tries to:</p>
179-
180-
<ol>
181-
<li>automagically adjust the <code>line-height</code> to the current typeface;</li>
182-
183-
<li>adjust this ideal <code>line-height</code> it has just computed to the current <code>font-size</code> the user has set.</li>
184-
</ol>
185-
186-
<pre><code>calc((1em + (2ex - 1ch) - ((1rem - 16px) * 0.1667)) * var(--RS__lineHeightCompensation))</code></pre>
187-
188-
<p>In which, <code>--RS__lineHeightCompensation</code> is a factor whose default is <code>1</code>. Indeed, the <code>line-height</code> is usually 15–20% larger in CJK than in other scripts/languages (factor of <code>1.167</code>), but it can also used for square-ish fonts, especially in Indic.</p>
189-
190-
<p>The results we could get for the vast majority of fonts can be described as good in terms of typographic color. Here is Iowan Old Style for instance.</p>
191-
192-
<figure>
193-
<img src="../Images/dynamic-leading.jpg" alt="Comparison of the algorithm using four different font-sizes with the Iowan Old Style typeface. We can notice that the leading applied is solider as font-size increases, which results in a relatively even distribution of typographic color. This is confirmed by the computed values retrieved in the tool ReadiumCSS provides for testing."/>
194-
195-
</figure>
196-
197-
<p>This isn’t a perfect solution though, and this algorithm may be revisited in the future.</p>
198-
199-
<p>See <a href="../Text/Section-018.xhtml">Further Details</a> for an extensive explanation.</p>
200-
</section>
201168
</section>
202169

203170
<section id="day-mode" class="level2">

docs/ReadiumCSS_docs/OEBPS/Text/Section-018.xhtml

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -133,44 +133,6 @@
133133
</section>
134134
</section>
135135

136-
<section id="dynamic-leading" class="level2">
137-
<h2 id="sigil_toc_id_35">Dynamic leading</h2>
138-
139-
<p>Readium CSS automagically finds the ideal <code>line-height</code> of the current font and <code>font-size</code> in use if the author hasn’t set an explicit value.</p>
140-
141-
<p>We’re using the current algorithm in the <code>calc()</code> function:</p>
142-
143-
<pre><code>(1em + (2ex - 1ch) - ((1rem - 16px) * 0.1667)) * var(--RS__lineHeightCompensation))</code></pre>
144-
145-
<p>Therefore, the <code>line-height</code> is:</p>
146-
147-
<ol>
148-
<li><code>1em</code> = the size of the <code>font-size</code>;</li>
149-
150-
<li><code>2ex - 1ch</code> = 2 x-height - 1 character width (<code>0</code>), in order to take the typeface’s proportions into account e.g. if the font has a small x-height, leading will be more solid, and vice versa;</li>
151-
152-
<li><code>1rem - 16px</code> = the current user’s <code>font-size</code> minus the one at <code>100%</code> (base <code>font-size</code>);</li>
153-
154-
<li><code>0.1667</code> = a scale which has been defined from an optimal range (<a href="https://css-tricks.com/magic-numbers-in-css/">it is a magic number</a> which has been retro-engineered from a set containing hundreds of samples);</li>
155-
156-
<li><code>var(--RS__lineHeightCompensation)</code> is a factor (integer) to compensate a less than ideal <code>line-height</code>, especially in non-Latin scripts, where fonts tend to be square-ish.</li>
157-
</ol>
158-
159-
<p>This isn’t a perfect solution though, and this algorithm may be revisited in the future. Indeed, caveats are:</p>
160-
161-
<ul>
162-
<li>leading also depends on line-length, which is not addressed in the algorithm itself, line-length must therefore be constrained by other means – we couldn’t rely on the viewport <code>width</code> anyway;</li>
163-
164-
<li>sometimes, the User Agent default <code>font-size</code> is not <code>16px</code> (e.g. Kindle experimental browser, user setting a larger <code>font-size</code>, etc.);</li>
165-
166-
<li><code>0.1667</code> feels like a magic number, or at least a weird number as it was retrofitted after testing hundreds of typefaces;</li>
167-
168-
<li>it’s clearly a natural logarithmic function i.e. it increases rapidly and then slows towards a zero rate of change, which will give mediocre results for very large font sizes (e.g. <code>400%</code>);</li>
169-
170-
<li>it doesn’t work ideally for slab serif fonts with a large x-height, thick stroke and medium character width i.e. square-ish metrics – we don’t have any in the default font-stacks so we had to introduce a compensation factor to address this particular issue.</li>
171-
</ul>
172-
</section>
173-
174136
<section id="conditional-selectors-for-user-settings" class="level2">
175137
<h2 id="sigil_toc_id_53">Conditional Selectors for user settings</h2>
176138

docs/ReadiumCSS_docs/OEBPS/Text/Section-028.xhtml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ const sepiaBackground = sepiaMode.sepiaMode.RS__backgroundColor;</code></pre>
208208

209209
<p><strong>Note you’ll have to take gaiji into account in dark custom themes as inverting them so that they match the color of text can only be done automatically in readiumCSS’ own night mode.</strong></p>
210210
</section>
211+
212+
<section id="theming-improvements" class="level2">
213+
<h2 id="sigil_toc_id_211">Removal of Dynamic Leading</h2>
214+
215+
<p>Since version <code>2.0.0-beta.6</code>, ReadiumCSS is no longer using an algorithm to guess the ideal line-height for each font, and recompute it on font-size change, as it created issues with the new font-size setting implementation.</p>
216+
217+
<p>It simply uses value <code>1.5</code> for <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/line-height#accessibility">accessibility purposes</a>, and compensates this value for various languages (e.g. CJK).</p>
218+
</section>
211219
</section>
212220
</body>
213221
</html>

docs/ReadiumCSS_docs/OEBPS/Text/nav.xhtml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,6 @@
505505
<li>
506506
<a href="../Text/Section-018.xhtml#sigil_toc_id_51">The Internal Framework</a>
507507
</li>
508-
<li>
509-
<a href="../Text/Section-018.xhtml#sigil_toc_id_35">Dynamic leading</a>
510-
</li>
511508
<li>
512509
<a href="../Text/Section-018.xhtml#sigil_toc_id_53">Conditional Selectors for user settings</a>
513510
</li>
@@ -744,6 +741,9 @@
744741
<li>
745742
<a href="../Text/Section-028.xhtml#sigil_toc_id_209">Theming Improvements</a>
746743
</li>
744+
<li>
745+
<a href="../Text/Section-028.xhtml#sigil_toc_id_211">Removal of Dynamic Leading</a>
746+
</li>
747747
</ol>
748748
</li>
749749
</ol>

0 commit comments

Comments
 (0)