mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 17:55:37 +02:00
SVG: Don't render missing glyphs
This bug is similar to the canvas bug of #6721.
I found this bug when I tried to run pdf2svg on a SVG file, and the generated
SVG could not be viewed in Chrome due to a SVG/XML parsing error:
"PCDATA invalid Char value 3"
Reduced test case:
- 1229507/pcdatainvalidchar.pdf
- expected: "hardware performance"
- Actual SVG source: "hardware\x03performance"
(where "\x03" is a non-printable character, and invalid XML).
In terms of rendering, this bug is similar to #6721, where an unexpected glyph
appeared in the canvas renderer. This was fixed by #7023, which skips over
missing glyphs. This commit follows a similar logic.
The test case from #6721 can be used here too:
- https://github.com/mozilla/pdf.js/files/52205/issue6721_reduced.pdf
expected: "Issue 6721"
actual (before this patch): "Issue ààà6721"
This commit is contained in:
parent
ba5dbc9632
commit
f07ce2bbc2
1 changed files with 10 additions and 2 deletions
|
@ -742,15 +742,23 @@ SVGGraphics = (function SVGGraphicsClosure() {
|
||||||
x += -glyph * fontSize * 0.001;
|
x += -glyph * fontSize * 0.001;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
current.xcoords.push(current.x + x * textHScale);
|
|
||||||
|
|
||||||
var width = glyph.width;
|
var width = glyph.width;
|
||||||
var character = glyph.fontChar;
|
var character = glyph.fontChar;
|
||||||
var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
|
var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
|
||||||
var charWidth = width * widthAdvanceScale + spacing * fontDirection;
|
var charWidth = width * widthAdvanceScale + spacing * fontDirection;
|
||||||
x += charWidth;
|
|
||||||
|
|
||||||
|
if (!glyph.isInFont && !font.missingFile) {
|
||||||
|
x += charWidth;
|
||||||
|
// TODO: To assist with text selection, we should replace the missing
|
||||||
|
// character with a space character if charWidth is not zero.
|
||||||
|
// But we cannot just do "character = ' '", because the ' ' character
|
||||||
|
// might actually map to a different glyph.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
current.xcoords.push(current.x + x * textHScale);
|
||||||
current.tspan.textContent += character;
|
current.tspan.textContent += character;
|
||||||
|
x += charWidth;
|
||||||
}
|
}
|
||||||
if (vertical) {
|
if (vertical) {
|
||||||
current.y -= x * textHScale;
|
current.y -= x * textHScale;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue