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: Add weight and italics support #202

Merged
merged 22 commits into from
May 8, 2024

Conversation

michaeltaranto
Copy link
Contributor

@michaeltaranto michaeltaranto commented May 8, 2024

Add support for importing metrics for specific weights and italics. While internal font metrics typically do not differ between variants, the xWidthAvg metric is calculated based on the average character width, and this will differ between variants.

Available variants will differ by font, and follow the same variant naming as Google Fonts:

import arial from '@capsizecss/metrics/arial'; 
import arialItalic from '@capsizecss/metrics/arial/italic'; 
import arialBold from '@capsizecss/metrics/arial/700'; 
import arialBoldItalic from '@capsizecss/metrics/arial/700italic'; 

Having metrics for different variants improves visual alignment of fallback fonts when using the createFontStack API from the @capsizecss/core package.

Example usage:

import { createFontStack } from '@capsizecss/core';
import montserrat from '@capsizecss/metrics/montserrat';
import montserrat600 from '@capsizecss/metrics/montserrat/600';
import arial from '@capsizecss/metrics/arial';
import arialBold from '@capsizecss/metrics/arial/700'; 

const regular = createFontStack([
  montserrat,
  arial,
]);

// => {
//   "fontFamily": "Montserrat, \"Montserrat Fallback\", Arial",
//   "fontFaces": [
//     {
//       "@font-face": {
//         "fontFamily": "\"Montserrat Fallback\"",
//         "src": "local('Arial'), local('ArialMT')",
//         "ascentOverride": "85.7923%",
//         "descentOverride": "22.2457%",
//         "lineGapOverride": "0%",
//         "sizeAdjust": "112.8307%"
//       }
//     }
//   ]
// }

const bold = createFontStack(
  [
    montserrat600,
    arialBold,
  ],
  {
    fontFaceProperties: {
      fontWeight: 700
    },
  },
);

// => {
//   "fontFamily": "Montserrat, \"Montserrat Fallback\", Arial",
//   "fontFaces": [
//     {
//       "@font-face": {
//         "fontWeight": 700,
//         "fontFamily": "\"Montserrat Fallback\"",
//         "src": "local('Arial Bold'), local('Arial-BoldMT')",
//         "ascentOverride": "89.3502%",
//         "descentOverride": "23.1683%",
//         "lineGapOverride": "0%",
//         "sizeAdjust": "108.3377%"
//       }
//     }
//   ]
// }

@michaeltaranto michaeltaranto requested a review from a team as a code owner May 8, 2024 01:23
Copy link

changeset-bot bot commented May 8, 2024

🦋 Changeset detected

Latest commit: 7c33fc6

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

This PR includes changesets to release 1 package
Name Type
@capsizecss/metrics Minor

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

Copy link

@askoufis askoufis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some small comments, nothing blocking.

michaeltaranto and others added 2 commits May 8, 2024 13:32
@michaeltaranto michaeltaranto merged commit 452f2a3 into master May 8, 2024
6 checks passed
@michaeltaranto michaeltaranto deleted the add-weight-italic-support branch May 8, 2024 06:29
@seek-oss-ci seek-oss-ci mentioned this pull request May 8, 2024
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.

2 participants