Repository navigation
Typography: Let variable fonts use any weight in their range - #83141
Jiwoon-Kim wants to merge 2 commits into
Conversation
🤖 PR meta 🤖🏷️ LabelsThis pull request needs exactly one label indicating its type, and has 0.
Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you. |
4bdf36c to
1348882
Compare
`getFontWeightRange()` read each end of a face's `fontWeight` with `parseInt`, so a face declaring `"normal 900"` was skipped and the weight control offered nothing, while the appearance list beside it read that same face correctly through its own parser. WordPress#83128 taught one of the two about the keywords the property accepts; this teaches both from one place. `parseFontWeightValue()` moves to its own module and both callers import it. Nothing about how either reads a range changes otherwise: the keywords are still `normal` and `bold`, `lighter` and `bolder` are still refused as relative to a parent and not allowed on `@font-face`, and a range naming one is still left alone rather than guessed at. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1348882 to
fa3a8dc
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
@t-hamano @juanfra, this is the follow-up to #83128, now that the range parsing is in trunk: when a family is variable, Appearance splits into a Style select and a Weight control that reaches any weight in the range, not only the hundreds. I have rebased the branch, so it is the feature commit plus one more — both controls now read a face's weight range through the same module, which is what taught the weight range the keywords #83128 taught the appearance list. A face declaring Out of scope here, and not a PR yet: the Style select beside it. Checking this branch against Roboto Flex, whose faces declare Would you have a moment to look? It also needs a |
…raft The Font variations panel and the capability controls beside it are one model seen from two sides: the panel edits the axes no CSS property owns, while Style, Weight and Width edit the ones that do, and both read what a family's faces declare. Reviewing them apart means reading the same faces twice and guessing how the halves meet. This merge brings the prototype in so the whole typography surface can be read in one diff and tried in one editor. It carries the weight work of WordPress#83141 with it, deliberately: the panel cannot be judged with one of its three controls missing. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
What?
When the selected font family is variable, the Appearance control splits into a Style select, with the choices it already offers, and a Weight control. As with the font size, the weight is picked from a list, here the hundreds inside the font's range shown with their numbers (
Light (300)), and a toggle next to the Weight label switches to a slider and a number field for any value in the range. Static fonts keep the combined style and weight list.Both controls write the same
fontStyleandfontWeightvalues as Appearance, so nothing changes in what is saved or printed: a weight of 178 isfontWeight: "178"andfont-weight: 178.Why?
Appearance offers fixed combinations such as "Bold Italic". That matches static fonts, which ship one file per style and weight. A variable font draws any weight in its range (
"fontWeight": "100 900"in theme.json), but the control lists only the hundreds, so 178 or 425 can't be chosen, and a saved value that is not a hundred shows as "Default".How?
getFontWeightRange()reads the weight range that a family's faces declare. A family with a range is treated as variable; no new flag is needed.parseFontWeightValue(), a module the appearance list and this control share, so a face declaring"normal 900"is the range 400 to 900 in both. Before, the two had a parser each: Typography: List only the weights inside a variable font's range #83128 taught the appearance list the keywords@font-faceaccepts, and the weight range kept itsparseInt, which readnormalas nothing and left the control with no range to offer.lighterandbolderare relative to a parent, so@font-facedoes not take them and a range naming one is still left alone rather than guessed at.VariableFontAppearanceControlrenders the Style select and a Weight control. The Weight control follows the font size picker: a select with the hundreds inside the range, and a toggle beside the label for a slider and a number field. The number field is separate from the slider becauseRangeControl's own input clamps the value it shows.Custom (178)in the select. A saved weight outside the font's range is kept and shown as it is, with a short note; it only changes when the user sets another. The slider only moves within the range.fontWeightrather than infont-variation-settings.font-variation-settingsis inherited and applied afterfont-weight, so with'wght' 300on a paragraph, a<strong>inside it also renders at 300. It also only reaches fonts that have awghtaxis: a fallback without one, such as a system font drawing a script the web font does not cover, stays at the element'sfont-weight, and faux bold is decided fromfont-weightas well.Not in this PR: other axes. Slant (
fontStyle: oblique <angle>) and width (fontStretch) map to CSS properties and could join Appearance later; axes without one, such asGRAD, would be stored in afontVariationSettingsstyle property and shown in a separate Font variations panel, which a theme can turn on. That model is proposed in #83148 and prototyped in #83159. Also open: whether italic should be offered when a font has no italic face.Testing Instructions
fontWeightis"250 750", plus a static family with"400"and"700"faces, to the active theme'stheme.json.Light (300)toBold (700).font-weight: 178, in the editor and on the front end.Custom (178).fontStyle: normalandfontWeight: 200in that family, for example from the code editor, then select it. The Weight control opens with 200 in the number field, the slider at 250, and a note that 200 is outside the range (250–750). The value stays 200 until another weight is chosen.fontWeightis"normal 900", and set a paragraph to it: the Weight select listsRegular (400)toBlack (900), and the slider runs from 400 to 900.Testing Instructions for Keyboard
Use of AI Tools
AI tools (Claude Code, Claude Opus 5, and Codex) assisted with implementation and testing.