Skip to content

Commit

Permalink
fix(troika-three-text): use sTypoAscender/Descender from OS/2 font ta…
Browse files Browse the repository at this point in the history
…ble if available

This matches the CSS spec
  • Loading branch information
lojjic committed Mar 14, 2022
1 parent 7af402e commit f5c244c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/troika-three-text/src/FontParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,26 @@ function parserFactory(Typr, woff2otf) {
return glyphIds
}

function firstNum(...args) {
for (let i = 0; i < args.length; i++) {
if (typeof args[i] === 'number') {
return args[i]
}
}
}

function wrapFontObj(typrFont) {
const glyphMap = Object.create(null)

const os2 = typrFont['OS/2']
const hhea = typrFont.hhea
const unitsPerEm = typrFont.head.unitsPerEm
const ascender = firstNum(os2 && os2.sTypoAscender, hhea && hhea.ascender, unitsPerEm)

const fontObj = {
unitsPerEm: typrFont.head.unitsPerEm,
ascender: typrFont.hhea.ascender,
descender: typrFont.hhea.descender,
unitsPerEm,
ascender,
descender: firstNum(os2 && os2.sTypoDescender, hhea && hhea.descender, 0),
forEachGlyph(text, fontSize, letterSpacing, callback) {
let glyphX = 0
const fontScale = 1 / fontObj.unitsPerEm * fontSize
Expand Down

0 comments on commit f5c244c

Please sign in to comment.