Skip to content

Commit f6973a2

Browse files
author
litherum
committed
[css-fonts-4] Update font matching algorithm with the WG's resolution
w3c#1579
1 parent 452a8e7 commit f6973a2

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

css-fonts-4/Overview.bs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,10 @@ given a font family containing normal and bold faces along with a thin and a hea
446446
Authors who desire finer control over the exact weight values used for a given element
447447
can use numerical values instead of relative weights.
448448

449+
Note: There is a small behavior change between [[CSS-FONTS-3]] and this specification with the animation of the 'font-size' property.
450+
Previously, interpolated values of font-weight were rounded to their closest multiple of 100, and the font-matching algorithm was run on these
451+
rounded values. In this specification, the font-matching algorithm is able to accept any value, so no rounding occurs. The small behavior change is due to the discontinuous nature of the font-matching algorithm.
452+
449453
<h3 id="font-stretch-prop">
450454
Font width: the 'font-stretch' property</h3>
451455

@@ -2141,16 +2145,14 @@ if all font style properties were set to their initial value.
21412145
value of the 'font-synthesis' property.
21422146

21432147

2144-
3. 'font-weight' is matched next. If a font does not have any concept of varying strengths of weights, its weight is mapped according list in the <a href="#font-weight-numeric-values">property definition</a>. If bolder/lighter relative weights are used, the effective weight is calculated based on the inherited weight value, as described in the definition of the 'font-weight'property. If the matching set after performing the steps above includes faces with weight values containing the font-weight desired value, faces with weight values which do not include the desired font-weight value are removed from the matching set. If there is no face which contains the desired value, a weight value is chosen using the rules below:
2148+
3. 'font-weight' is matched next. If a font does not have any concept of varying strengths of weights, its weight is mapped according list in the <a href="#font-weight-numeric-values">property definition</a>. If bolder/lighter relative weights are used, the effective weight is calculated based on the inherited weight value, as described in the definition of the 'font-weight' property. If the matching set after performing the steps above includes faces with weight values containing the font-weight desired value, faces with weight values which do not include the desired font-weight value are removed from the matching set. If there is no face which contains the desired value, a weight value is chosen using the rules below:
21452149

2146-
* If the desired weight is 400, 400 is checked first, 500 is checked second and then the rule for desired weights less than or equal to 500 is used.
2147-
* If the desired weight is 500, 500 is checked first, 400 is checked second and then
2148-
the rule for desired weights less than or equal to 500 is used.
2149-
* If the desired weight is less than or equal to 500, weights below the
2150+
* If the desired weight is inclusively between 400 and 500, weights greater than or equal to the target weight are checked in ascending order until 500 is hit and checked, followed by weights less than the target weight in descending order, followed by weights greater than 500, until a match is found.
2151+
* If the desired weight is less than 400, weights less than or equal to the
21502152
desired weight are checked in descending order followed by
21512153
weights above the desired weight in ascending order until a
21522154
match is found.
2153-
* If the desired weight is greater than 500, weights above the
2155+
* If the desired weight is greater than 500, weights greater than or equal to the
21542156
desired weight are checked in ascending order followed by
21552157
weights below the desired weight in descending order until a
21562158
match is found.
@@ -2160,31 +2162,35 @@ if all font style properties were set to their initial value.
21602162

21612163
<img src="images/styleweight.svg" alt="distance graph">
21622164

2163-
As you can see, because font B contains the minimum oblique value across the entire family, font B would be selected by this algorithm. However, if font B were somehow eliminated from the family, font D would then contain the lowest distance in the family, so it would be selected. If D were eliminated, A would be selected, followed by fonts C and then E.
2165+
As you can see, because font B contains the minimum distance across the entire family, font B would be selected by this algorithm. However, if font B were somehow eliminated from the family, font D would then contain the lowest distance in the family, so it would be selected. If D were eliminated, A would be selected, followed by fonts C and then E.
21642166
</div>
21652167

21662168
<div class="example">
2167-
Similar to the <a href="#ascendingstretch">previous example</a>, here is the conceptual distance graph for an element styled with "font-weight: 500":
2169+
Similar to the <a href="#ascendingstretch">previous example</a>, here is the conceptual distance graph for an element styled with "font-weight: 450":
21682170

2169-
<img src="images/weightmatching.svg" alt="distance graph">
2171+
<img src="images/styleweight450.svg" alt="distance graph">
21702172

2171-
As you can see, because font D contains the minimum oblique value across the entire family, font D would be selected by this algorithm. However, if font D were somehow eliminated from the family, font B would then contain the lowest distance in the family, so it would be selected. If B were eliminated, C would be selected, followed by fonts A and then E.
2173+
As you can see, because font C contains the minimum distance across the entire family, font C would be selected by this algorithm. However, if font C were somehow eliminated from the family, font D would then contain the lowest distance in the family, so it would be selected. If D were also eliminated, B would be selected, followed by fonts A and then E.
21722174
</div>
21732175

2174-
Once the closest matching weight has been determined by this process,
2175-
faces with weights which do not include this determined width are removed from the matching set.
2176+
<div class="example">
2177+
Similar to the <a href="#ascendingstretch">previous example</a>, here is the conceptual distance graph for an element styled with "font-weight: 500":
2178+
2179+
<img src="images/weightmatching.svg" alt="distance graph">
21762180

2181+
As you can see, because font D contains the minimum distance across the entire family, font D would be selected by this algorithm. However, if font D were somehow eliminated from the family, font B would then contain the lowest distance in the family, so it would be selected. If B were eliminated, C would be selected, followed by fonts A and then E.
2182+
</div>
21772183

21782184
<div class="example">
21792185
Similar to the <a href="#ascendingstretch">previous example</a>, here is the conceptual distance graph for an element styled with "font-weight: 300":
21802186

21812187
<img src="images/weightmatching2.svg" alt="distance graph">
21822188

2183-
As you can see, because font B contains the minimum oblique value across the entire family, font B would be selected by this algorithm. However, if font B were somehow eliminated from the family, font A would then contain the lowest distance in the family, so it would be selected. If A were eliminated, C would be selected.
2189+
As you can see, because font B contains the minimum distance across the entire family, font B would be selected by this algorithm. However, if font B were somehow eliminated from the family, font A would then contain the lowest distance in the family, so it would be selected. If A were eliminated, C would be selected.
21842190
</div>
21852191

21862192
Once the closest matching weight has been determined by this process,
2187-
faces with weights which do not include this determined width are removed from the matching set.
2193+
faces with weights which do not include this determined weight are removed from the matching set.
21882194

21892195
4. 'font-size' must be
21902196
matched within a UA-dependent margin of tolerance. (Typically, sizes

css-fonts-4/images/styleweight.svg

Lines changed: 2 additions & 4 deletions
Loading

css-fonts-4/images/weightmatching.svg

Lines changed: 4 additions & 8 deletions
Loading

0 commit comments

Comments
 (0)