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

Variable fonts #495

Open
controversial opened this issue Jun 30, 2022 · 2 comments
Open

Variable fonts #495

controversial opened this issue Jun 30, 2022 · 2 comments

Comments

@controversial
Copy link

controversial commented Jun 30, 2022

How can I register and use a variable font?

If I register

GlobalFonts.registerFromPath(path.join(fontsDir, 'RobotoMono-VariableFont.woff2'), 'Roboto Mono');

and try to render different font weights (100–900) by something like:

for (let i = 1; i <= 9; i++) {
  ctx.font = `${i * 100} 45px Roboto Mono`;
  ctx.fillText(`${i * 100}: Jackdaws love my big sphinx of quartz`, 30, i * 65);
}

I get the following result:

result

Weights 100–500 are rendered at 400, and 600–900 are rendered at 700.

I would expect to see an even gradient from 100–700 as the weight specified in ctx.font changes.

@yisibl yisibl added the help wanted Extra attention is needed label Aug 12, 2022
@yisibl
Copy link
Collaborator

yisibl commented Aug 13, 2022

In CSS you need to register a new variable font with @font-face, and adjusting the variable axis directly with font-weight doesn't work either.

However, the variable axis can be controlled directly through the low-level property font-variation-setting.

As far as I know, skr-canvas does not currently support variable fonts. The primary goal in skr-canvas should be to find an implementation that corresponds to font-variation-setting in order to control the variable axis.

Here is some information for reference.

@yisibl yisibl added feature request and removed help wanted Extra attention is needed labels Aug 13, 2022
@yisibl
Copy link
Collaborator

yisibl commented Feb 27, 2024

As far as I know, there is no other canvas library in Node.js that supports variable fonts except canvaskit(fontVariations). If skr-canvas supports variable fonts, it will be very competitive.

@Brooooooklyn Can this be our goal for 2024?

canvaskit-wasm/types/index.d.ts

export interface TextStyle {
  backgroundColor?: InputColor
  color?: InputColor
  decoration?: number
  decorationColor?: InputColor
  decorationThickness?: number
  decorationStyle?: DecorationStyle
  fontFamilies?: string[]
  fontFeatures?: TextFontFeatures[]
  fontSize?: number
  fontStyle?: FontStyle
  fontVariations?: TextFontVariations[]
  foregroundColor?: InputColor
  heightMultiplier?: number
  halfLeading?: boolean
  letterSpacing?: number
  locale?: string
  shadows?: TextShadow[]
  textBaseline?: TextBaseline
  wordSpacing?: number
}
 
export interface TextFontFeatures {
  name: string
  value: number
}
 
export interface TextFontVariations {
  axis: string
  value: number
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants