Skip to content

Commit 2258ea4

Browse files
agorischekCopilot
andauthored
Temporary: measure line pitch on macOS WebKit (delete after)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent e7a32e2 commit 2258ea4

4 files changed

Lines changed: 64 additions & 0 deletions

File tree

‎.github/workflows/zz-diag.yml‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Diagnostic (temporary)
2+
on:
3+
push:
4+
branches: [diag/macos-line-pitch]
5+
permissions:
6+
contents: read
7+
jobs:
8+
measure:
9+
strategy:
10+
matrix:
11+
os: [macos-latest, ubuntu-latest]
12+
runs-on: ${{ matrix.os }}
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-node@v4
16+
with:
17+
node-version: 22
18+
- run: npm init -y >/dev/null && npm install --no-save playwright@1.64.1
19+
working-directory: diag
20+
- run: npx playwright install --with-deps webkit chromium
21+
working-directory: diag
22+
- run: node diag.mjs
23+
working-directory: diag

‎diag/diag.mjs‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {readFileSync} from 'node:fs'
2+
import {webkit, chromium} from 'playwright'
3+
const fonts = JSON.parse(readFileSync(new URL('./fonts.json', import.meta.url), 'utf8'))
4+
const faces = Object.entries(fonts).map(([k, b]) => `@font-face{font-family:'S-${k}';src:url(data:font/woff2;base64,${b}) format('woff2');font-weight:400 700}`).join('\n')
5+
const label = `--pk-label-line: round(up, 1lh, 1px);--pk-label-room: calc(var(--pk-label-line) - round(down, 1cap, 0.015625px) - 1px);--pk-label-above: round(down, calc(var(--pk-label-room) / 2), 0.015625px);text-box: trim-both cap alphabetic;box-sizing: border-box;min-height: var(--pk-label-line);padding-block: var(--pk-label-above) calc(var(--pk-label-room) - var(--pk-label-above));`
6+
const variants = {
7+
plain: '',
8+
label,
9+
lbcBlock: '-webkit-line-box-contain: block;',
10+
labelLbcBlock: label + '-webkit-line-box-contain: block;',
11+
labelLbcBlockInline: label + '-webkit-line-box-contain: block inline;',
12+
labelLbcBlockGlyphs: label + '-webkit-line-box-contain: block glyphs;',
13+
labelLbcBlockReplaced: label + '-webkit-line-box-contain: block replaced;',
14+
labelSpanLh0: label + '|span',
15+
}
16+
const text = 'Eb cd ef gh ij kl mn op qr st uv'
17+
const page = `<!doctype html><html><head><style>${faces}\nbody{margin:0}div.t{display:block;width:90px;line-height:1.5}span.in{line-height:0}</style></head><body><div id=root></div>
18+
<script>
19+
const variants=${JSON.stringify(variants)}, fams=${JSON.stringify(Object.keys(fonts))};
20+
(async()=>{for(const f of fams){await document.fonts.load('12px "S-'+f+'"')}
21+
const out=[];
22+
for(const f of fams)for(const size of [12,13,14,16])for(const [name,css] of Object.entries(variants)){
23+
const el=document.createElement('div');el.className='t';const [c,mode]=css.split('|');el.style.cssText=c+';font-family:"S-'+f+'";font-size:'+size+'px';
24+
if(mode==='span'){const s=document.createElement('span');s.className='in';s.textContent=${JSON.stringify(text)};el.append(s)}else el.textContent=${JSON.stringify(text)};
25+
document.getElementById('root').append(el);
26+
const r=document.createRange();r.selectNodeContents(el);const lines=new Set([...r.getClientRects()].map(x=>Math.round(x.top*64)/64)).size;
27+
out.push({f,size,name,lh:getComputedStyle(el).lineHeight,lines,h:el.getBoundingClientRect().height});el.remove()}
28+
document.title='done';window.__out=out})()
29+
</script></body></html>`
30+
for (const [name, type] of [['webkit', webkit], ['chromium', chromium]]) {
31+
const browser = await type.launch()
32+
const p = await browser.newPage()
33+
await p.setContent(page)
34+
await p.waitForFunction(() => document.title === 'done')
35+
const out = await p.evaluate(() => window.__out)
36+
console.log(`== ${name} ${process.platform} supports lbc: ${await p.evaluate(() => CSS.supports('-webkit-line-box-contain', 'block'))}`)
37+
for (const o of out) console.log(`${o.f} ${o.size}px lh=${o.lh} ${o.name.padEnd(22)} lines=${o.lines} h=${o.h.toFixed(5)}`)
38+
await browser.close()
39+
}

‎diag/fonts.json‎

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

‎diag/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"type":"module"}

0 commit comments

Comments
 (0)