XFA: `measure.pushFont is not a function` — rich text containing <b> or <i> breaks layout
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mozilla/pdf.js
-
other
Difficulty 1/5 Under an hour Newbie friendliness 85/100
mozilla/pdf.js#21645 · 1 comment ·
Maintainers usually reply within 1 day
-
chrome-specific safari-specific upstream
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
addon chrome-specific printing
Difficulty 1/5 Under an hour Newbie friendliness 70/100
mozilla/pdf.js#12278 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
mozilla/pdf.js#22021 · 2 comments ·
Maintainers usually reply within 1 day
Similar issues
-
Design only Leadership Survey SLFS
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
bcgov/digital-journeys#2293 ·
-
Toolkit
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
API Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ProjectSidewalk/SidewalkWebpage#5556 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
jessepollak/home#1454 ·
Maintainers usually reply within 1 day
-
Mend: dependency security vulnerability untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
opensearch-project/OpenSearch-Dashboards#12822 ·
Maintainers usually reply within 1 day