Only draw glyphs on canvas if they are in the font or the font file is missing.
This commit is contained in:
parent
c53581f4e5
commit
ff87f3fb86
@ -191,7 +191,7 @@ function getFontType(type, subtype) {
|
|||||||
|
|
||||||
var Glyph = (function GlyphClosure() {
|
var Glyph = (function GlyphClosure() {
|
||||||
function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
|
function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
|
||||||
isSpace) {
|
isSpace, isInFont) {
|
||||||
this.fontChar = fontChar;
|
this.fontChar = fontChar;
|
||||||
this.unicode = unicode;
|
this.unicode = unicode;
|
||||||
this.accent = accent;
|
this.accent = accent;
|
||||||
@ -199,17 +199,20 @@ var Glyph = (function GlyphClosure() {
|
|||||||
this.vmetric = vmetric;
|
this.vmetric = vmetric;
|
||||||
this.operatorListId = operatorListId;
|
this.operatorListId = operatorListId;
|
||||||
this.isSpace = isSpace;
|
this.isSpace = isSpace;
|
||||||
|
this.isInFont = isInFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
|
Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
|
||||||
vmetric, operatorListId, isSpace) {
|
vmetric, operatorListId, isSpace,
|
||||||
|
isInFont) {
|
||||||
return this.fontChar === fontChar &&
|
return this.fontChar === fontChar &&
|
||||||
this.unicode === unicode &&
|
this.unicode === unicode &&
|
||||||
this.accent === accent &&
|
this.accent === accent &&
|
||||||
this.width === width &&
|
this.width === width &&
|
||||||
this.vmetric === vmetric &&
|
this.vmetric === vmetric &&
|
||||||
this.operatorListId === operatorListId &&
|
this.operatorListId === operatorListId &&
|
||||||
this.isSpace === isSpace;
|
this.isSpace === isSpace &&
|
||||||
|
this.isInFont === isInFont;
|
||||||
};
|
};
|
||||||
|
|
||||||
return Glyph;
|
return Glyph;
|
||||||
@ -468,6 +471,7 @@ var Font = (function FontClosure() {
|
|||||||
this.loadedName = properties.loadedName;
|
this.loadedName = properties.loadedName;
|
||||||
this.isType3Font = properties.isType3Font;
|
this.isType3Font = properties.isType3Font;
|
||||||
this.sizes = [];
|
this.sizes = [];
|
||||||
|
this.missingFile = false;
|
||||||
|
|
||||||
this.glyphCache = Object.create(null);
|
this.glyphCache = Object.create(null);
|
||||||
|
|
||||||
@ -2807,6 +2811,7 @@ var Font = (function FontClosure() {
|
|||||||
unicode = String.fromCharCode(unicode);
|
unicode = String.fromCharCode(unicode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isInFont = charcode in this.toFontChar;
|
||||||
// First try the toFontChar map, if it's not there then try falling
|
// First try the toFontChar map, if it's not there then try falling
|
||||||
// back to the char code.
|
// back to the char code.
|
||||||
fontCharCode = this.toFontChar[charcode] || charcode;
|
fontCharCode = this.toFontChar[charcode] || charcode;
|
||||||
@ -2821,6 +2826,7 @@ var Font = (function FontClosure() {
|
|||||||
|
|
||||||
var accent = null;
|
var accent = null;
|
||||||
if (this.seacMap && this.seacMap[charcode]) {
|
if (this.seacMap && this.seacMap[charcode]) {
|
||||||
|
isInFont = true;
|
||||||
var seac = this.seacMap[charcode];
|
var seac = this.seacMap[charcode];
|
||||||
fontCharCode = seac.baseFontCharCode;
|
fontCharCode = seac.baseFontCharCode;
|
||||||
accent = {
|
accent = {
|
||||||
@ -2834,9 +2840,9 @@ var Font = (function FontClosure() {
|
|||||||
var glyph = this.glyphCache[charcode];
|
var glyph = this.glyphCache[charcode];
|
||||||
if (!glyph ||
|
if (!glyph ||
|
||||||
!glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
|
!glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
|
||||||
operatorListId, isSpace)) {
|
operatorListId, isSpace, isInFont)) {
|
||||||
glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
|
glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
|
||||||
operatorListId, isSpace);
|
operatorListId, isSpace, isInFont);
|
||||||
this.glyphCache[charcode] = glyph;
|
this.glyphCache[charcode] = glyph;
|
||||||
}
|
}
|
||||||
return glyph;
|
return glyph;
|
||||||
|
@ -1501,6 +1501,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only attempt to draw the glyph if it is actually in the embedded font
|
||||||
|
// file or if there isn't a font file so the fallback font is shown.
|
||||||
|
if (glyph.isInFont || font.missingFile) {
|
||||||
if (simpleFillText && !accent) {
|
if (simpleFillText && !accent) {
|
||||||
// common case
|
// common case
|
||||||
ctx.fillText(character, scaledX, scaledY);
|
ctx.fillText(character, scaledX, scaledY);
|
||||||
@ -1512,6 +1515,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
|
this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var charWidth = width * widthAdvanceScale + spacing * fontDirection;
|
var charWidth = width * widthAdvanceScale + spacing * fontDirection;
|
||||||
x += charWidth;
|
x += charWidth;
|
||||||
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -166,6 +166,7 @@
|
|||||||
!issue5010.pdf
|
!issue5010.pdf
|
||||||
!issue4934.pdf
|
!issue4934.pdf
|
||||||
!issue4650.pdf
|
!issue4650.pdf
|
||||||
|
!issue6721_reduced.pdf
|
||||||
!issue3025.pdf
|
!issue3025.pdf
|
||||||
!issue2099-1.pdf
|
!issue2099-1.pdf
|
||||||
!issue3371.pdf
|
!issue3371.pdf
|
||||||
|
BIN
test/pdfs/issue6721_reduced.pdf
Normal file
BIN
test/pdfs/issue6721_reduced.pdf
Normal file
Binary file not shown.
@ -543,6 +543,15 @@
|
|||||||
"lastPage": 1,
|
"lastPage": 1,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
},
|
},
|
||||||
|
{ "id": "issue6721_reduced",
|
||||||
|
"file": "pdfs/issue6721_reduced.pdf",
|
||||||
|
"md5": "719aa66d8081a15e3ba6032ed4279237",
|
||||||
|
"rounds": 1,
|
||||||
|
"link": false,
|
||||||
|
"firstPage": 1,
|
||||||
|
"lastPage": 1,
|
||||||
|
"type": "eq"
|
||||||
|
},
|
||||||
{ "id": "issue5010",
|
{ "id": "issue5010",
|
||||||
"file": "pdfs/issue5010.pdf",
|
"file": "pdfs/issue5010.pdf",
|
||||||
"md5": "419f4b13403a0871c463ec69d96e342c",
|
"md5": "419f4b13403a0871c463ec69d96e342c",
|
||||||
|
Loading…
Reference in New Issue
Block a user