Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 63 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
},
"dependencies": {
"@makeitaquote/utils": "^1.2.1",
"@napi-rs/canvas": ">=1.0.8 <1.0.12",
"@napi-rs/canvas": "^1.0.13",
"@twemoji/parser": "^17.0.2",
"budoux": "^0.9.1",
"cleye": "^2.6.0",
Expand Down
19 changes: 19 additions & 0 deletions src/render/layout.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest'
import { defineTheme } from '../theme/resolve'
import { createCanvas } from './canvasFactory'
import { autoArea, computeLayout, cssFontFamily, fontString, gradientLine } from './layout'

describe('computeLayout · side', () => {
Expand Down Expand Up @@ -196,3 +197,21 @@ describe('cssFontFamily', () => {
expect(cssFontFamily(' Noto Sans JP ,, sans-serif ')).toBe('"Noto Sans JP", sans-serif')
})
})

describe('fontString on a real canvas', () => {
// A ctx.font value the parser rejects is silently ignored, so read it back: any family name a user or the catalogue can supply must stick.
it.each([
'M PLUS Rounded 1c, Noto Sans JP, sans-serif',
'M PLUS 1p',
'DotGothic16',
"O'Brien Sans",
'2nd Custom Font',
'sans-serif',
])('is accepted by ctx.font for %s', (family) => {
const ctx = createCanvas(1, 1).getContext('2d')
ctx.font = '7px serif'
ctx.font = fontString('bold', 32, family, true)
expect(ctx.font).not.toBe('7px serif')
expect(ctx.font).toContain('32px')
})
})
2 changes: 1 addition & 1 deletion src/render/textStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function resolvedWeight(base: FontWeight, bold: boolean | undefined): Fon
/**
* Families whose bold is faked, keyed by family name.
*
* Variable fonts registered through `GlobalFonts` — including the Noto Sans JP this package downloads — expose only their default instance to Skia, so `ctx.font = 'bold …'` measures and draws identically to regular. Detected once per family by measuring both.
* A family registered with only its regular face — common for fonts registered at runtime — has no bold to switch to, so `ctx.font = 'bold …'` measures and draws identically to regular. Detected once per family by measuring both. (Variable fonts such as the Noto Sans JP this package downloads honour their weight axis since `@napi-rs/canvas` 1.0.12, so they detect as real bold.)
*/
const syntheticFamilies = new Map<string, boolean>()

Expand Down
Loading