`widthOfString`/`heightOfString` not accurate?

Aperta
#1,460 0 commenti 7 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript
Ambito
tooling

Direzione di ricerca

Clona la riproduzione collegata di pdfkit-bugs, esegui npm install && npm start e confronta i bounds riportati per Helvetica e Inter. Concentrati sul comportamento di larghezza e altezza con un'interlinea negativa; il lavoro è concluso quando viene stabilito se le dimensioni restituite corrispondono all'area di testo renderizzata oppure vengono documentati il limite e il comportamento previsto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug Report

Description of the problem

If I call height/widthOfString and draw a rect+stroke with the dimensions returned, I would expect the rect to encompass the text. But that isn't the behavior I'm seeing.

Here are the issues I'm seeing:

  1. With Helvetica, the box is too wide (wider than the pdf) and too tall:
image
  1. With Inter SemiBold, the height looks just about right:
image
  1. But as soon as I give the Inter text a negative line gap, the height is wrong:
image

My goal is to measure the size of text and choose the largest font size that will fill a given area. If I can't compute that area the task is impossible.

Is there a better way of getting the area of the rendered text?

Code sample

code that demonstrates these issues: https://github.com/altano/pdfkit-bugs/tree/main

Just clone, npm install && npm start

Your environment

  • pdfkit version: v0.13.0
  • Node version: v18.16.0
  • Browser version (if applicable): n/a
  • Operating System: macOS 13.4.1
Lingua principale
JavaScript
Stelle
10.7k
Fork
1.2k
Merge medio
22h 55m
PR unite (30g)
25

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di foliojs/pdfkit

Tutte le issue di foliojs/pdfkit

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.