Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics, unpack: Calculate and expose the xWidthAvg metric #122

Merged
merged 11 commits into from Jan 30, 2023

Conversation

michaeltaranto
Copy link
Contributor

@michaeltaranto michaeltaranto commented Jan 23, 2023

Calculate the average width of lowercase characters and expose as xWidthAvg. This value facilitates calculating better font fall backs, as it enables calculating the size-adjust CSS property (see the createFontStack PR).

Why a custom metric?

There is a built-in value called xAvgCharWidth in the OS/2 table, however the definition of its value has changed over time and is currently the average of all glyphs from a font file. Instead, we calculate an average width of the glyphs based on their frequency of occurrence. From testing this has proved to be quite effective.

The category field

The category field exists on every Google Font and describes the font style, e.g. “serif”, ”sans-serif”, etc. We are exposing this (as well as populating it manually for system fonts), as frameworks like NextJS are using it to select which system font to fallback to.

Notes

  • Align the FontMetrics type from core with shape of metrics from metrics package.
  • Updates to the latest Google Fonts
  • Add sections with links to metrics and unpack from top level readme

@michaeltaranto michaeltaranto requested a review from a team as a code owner January 23, 2023 22:48
@changeset-bot
Copy link

changeset-bot bot commented Jan 23, 2023

🦋 Changeset detected

Latest commit: f74ddec

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@capsizecss/metrics Minor
@capsizecss/unpack Minor
@capsizecss/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

pnpm-lock.yaml Show resolved Hide resolved
.changeset/loud-rules-warn.md Outdated Show resolved Hide resolved
packages/unpack/README.md Outdated Show resolved Hide resolved
packages/unpack/src/index.ts Outdated Show resolved Hide resolved
michaeltaranto and others added 5 commits January 30, 2023 09:43
Co-authored-by: Adam Skoufis <askoufis@users.noreply.github.com>
Co-authored-by: Adam Skoufis <askoufis@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants