Files
genoffice/apps/docs/tests/poppins-font-metrics.test.ts
T
merrick-2002andGenOffice 9f971edafa Sync snapshot (2026-09-02) (#181)
- Docs: DOCX rendering and pagination fidelity (page borders, VML pictures, header/footer images, cross-page tables, anchored floats, character-unit indents, CJK typography)
- Docs: more reliable PDF export for huge documents; AI rewrites keep the replaced content's formatting
- Sheets: merge workbooks; Excel-standard keyboard shortcuts; PDF export with header/footer variants and pictures
- Sheets: rendering, conditional formatting, chart and formula fidelity fixes; right-to-left sheet support
- Slides: WordArt text warp, improved text layout and font substitution; AI table edits keep formatting

Co-authored-by: GenOffice <merrick-2002@users.noreply.github.com>
2026-09-03 00:12:17 +08:00

39 lines
1.5 KiB
TypeScript

/**
* Contract of the bundled Poppins subsets (fonts/README.md): Word downloads
* the real M365 cloud face and lays out with a 1.5em line box and Poppins'
* own advances (probe 2026-09-01). A regenerated woff2 that normalizes either
* would silently shift Poppins documents' line breaks and page count vs Word.
*/
import { join } from 'node:path'
import { describe, expect, it } from 'vitest'
import { advanceEm, readWoff2 } from './helpers/woff2-metrics'
const FONTS = join(__dirname, '../src/renderer/fonts')
const regular = readWoff2(join(FONTS, 'GenOfficePoppins-Regular-subset.woff2'))
const bold = readWoff2(join(FONTS, 'GenOfficePoppins-Bold-subset.woff2'))
describe('GenOffice Poppins (real-metric M365 cloud face)', () => {
it('keeps the upstream 1.5em hhea line box', () => {
for (const font of [regular, bold]) {
const hhea = font.tables.get('hhea')!
const ascent = hhea.readInt16BE(4)
const descent = hhea.readInt16BE(6)
const lineGap = hhea.readInt16BE(8)
expect((ascent - descent + lineGap) / font.unitsPerEm).toBe(1.5)
}
})
it('keeps upstream advances (space/digits, per weight)', () => {
expect(advanceEm(regular, 0x20)).toBe(0.267)
expect(advanceEm(regular, 0x30)).toBe(0.628)
expect(advanceEm(bold, 0x20)).toBe(0.212)
expect(advanceEm(bold, 0x30)).toBe(0.652)
})
it('covers Latin letters and typographic punctuation', () => {
for (const cp of [0x41, 0x7a, 0xe9, 0x201c, 0x2014, 0x20ac]) {
expect(regular.cmap.get(cp), `U+${cp.toString(16)}`).toBeDefined()
}
})
})