|
133 | 133 | </section> |
134 | 134 | </section> |
135 | 135 |
|
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 | | - |
174 | 136 | <section id="conditional-selectors-for-user-settings" class="level2"> |
175 | 137 | <h2 id="sigil_toc_id_53">Conditional Selectors for user settings</h2> |
176 | 138 |
|
|
0 commit comments