`widthOfString`/`heightOfString` not accurate?

オープン
#1,460 コメント 0 件 リアクション 7 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript
領域
tooling

調査の方向性

リンクされている pdfkit-bugs の再現コードをクローンし、npm install && npm start を実行して、Helvetica と Inter について報告された境界を比較します。負の行間での幅と高さの挙動に焦点を当てます。返された寸法がレンダリングされたテキスト領域と一致するかを明らかにするか、制限事項と期待される挙動を文書化できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
JavaScript
スター
10.7k
フォーク
1.2k
平均マージ
21時間 41分
マージ済み PR(30日)
27

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

foliojs/pdfkit のほかの issue

foliojs/pdfkit の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。