Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

XFA: `measure.pushFont is not a function` — rich text containing <b> or <i> breaks layout

Open Beginner friendly
#22,023 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript
Domain
frontend

Research direction

Start in src/core/xfa/text.js, comparing TextMeasure with the pushFont callers in src/core/xfa/xhtml.js. Reproduce with enableXfa and rich text containing or , then verify that layout completes and pages are built without the missing-method error.

Written by the indexing model from the issue text.

Description

src/core/xfa/xhtml.js calls measure.pushFont(...) in two places:

// class B, line ~375
[$pushGlyphs](measure) {
  measure.pushFont({ weight: "bold" });
  super[$pushGlyphs](measure);
  measure.popFont();
}

// class I, line ~466
[$pushGlyphs](measure) {
  measure.pushFont({ posture: "italic" });
  super[$pushGlyphs](measure);
  measure.popFont();
}

TextMeasure in src/core/xfa/text.js defines pushData, popFont, addPara, addString and compute. There is no pushFont on it, nor on FontSelector.

So any XFA document whose rich text contains <b> or <i> throws TypeError: measure.pushFont is not a function during layout.

Why it is hard to recognise

XFAFactory._createPages catches the error and only warns, so no pages are built and getDocument rejects with:

UnknownErrorException: Cannot read properties of undefined (reading 'length')

which names neither bold text nor the missing method. A document differing from a working one by a single <b> fails with a message that points nowhere near the cause.

Reproduction

Load any dynamic XFA document (enableXfa: true) whose rich text contains a <b> or <i> element, for example an exData of contentType="text/html" holding:

<body xmlns="http://www.w3.org/1999/xhtml"><p><b>Important:</b> text</p></body>

Confirmed on master today; originally found on 4.6.82.

Suggested fix

Add to TextMeasure:

pushFont(xfaFont) {
  this.fontSelector.pushData(
    xfaFont,
    { top: NaN, bottom: NaN, left: NaN, right: NaN },
    null
  );
}

The margin has to be an object of NaNs rather than null, because FontSelector.pushData tests isNaN(margin[side]). That is exactly what XhtmlObject[$pushGlyphs] already passes on the path that works.

Dominant language
JavaScript
Stars
53.9k
Forks
10.7k
Avg merge
20h 26m
Merged PRs (30d)
122

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mozilla/pdf.js

All issues in mozilla/pdf.js

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.