1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #2124 from yurydelendik/fallback-font

Provides right fallback fonts for text layer
This commit is contained in:
Brendan Dahl 2012-09-17 10:06:42 -07:00
commit 8dc49a3c9b
5 changed files with 31 additions and 15 deletions

View file

@ -596,8 +596,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
(fontObj.bold ? 'bold' : 'normal');
var italic = fontObj.italic ? 'italic' : 'normal';
var serif = fontObj.isSerifFont ? 'serif' : 'sans-serif';
var typeface = '"' + name + '", ' + serif;
var typeface = '"' + name + '", ' + fontObj.fallbackName;
// Some font backends cannot handle fonts below certain size.
// Keeping the font at minimal size and using the fontSizeScale to change
@ -792,7 +791,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
}
if (textSelection)
this.textLayer.appendText(text, font.loadedName, fontSize);
this.textLayer.appendText(text, font.fallbackName, fontSize);
return text;
},
@ -856,7 +855,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
}
if (textSelection)
this.textLayer.appendText(text, font.loadedName, fontSize);
this.textLayer.appendText(text, font.fallbackName, fontSize);
},
nextLineShowText: function CanvasGraphics_nextLineShowText(text) {
this.nextLine();

View file

@ -825,21 +825,41 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
}
}
// Heuristic: detection of monospace font by checking all non-zero widths
var isMonospace = true, firstWidth = defaultWidth;
for (var glyph in glyphsWidths) {
var glyphWidth = glyphsWidths[glyph];
if (!glyphWidth)
continue;
if (!firstWidth) {
firstWidth = glyphWidth;
continue;
}
if (firstWidth != glyphWidth) {
isMonospace = false;
break;
}
}
if (isMonospace)
properties.flags |= FontFlags.FixedPitch;
properties.defaultWidth = defaultWidth;
properties.widths = glyphsWidths;
},
getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
var defaultWidth = 0, widths = [];
var defaultWidth = 0, widths = [], monospace = false;
var glyphWidths = Metrics[stdFontMap[name] || name];
if (isNum(glyphWidths)) {
defaultWidth = glyphWidths;
monospace = true;
} else {
widths = glyphWidths;
}
return {
defaultWidth: defaultWidth,
monospace: monospace,
widths: widths
};
},
@ -893,6 +913,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var fontNameWoStyle = baseFontName.split('-')[0];
var flags = (serifFonts[fontNameWoStyle] ||
(fontNameWoStyle.search(/serif/gi) != -1) ? FontFlags.Serif : 0) |
(metrics.monospace ? FontFlags.FixedPitch : 0) |
(symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
FontFlags.Nonsymbolic);

View file

@ -1522,17 +1522,13 @@ var Font = (function FontClosure() {
names = names.split(/[-,_]/g)[0];
this.isSerifFont = !!(properties.flags & FontFlags.Serif);
this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
var type = properties.type;
this.type = type;
// If the font is to be ignored, register it like an already loaded font
// to avoid the cost of waiting for it be be loaded by the platform.
if (properties.ignore) {
this.loadedName = this.isSerifFont ? 'serif' : 'sans-serif';
this.loading = false;
return;
}
this.fallbackName = this.isMonospace ? 'monospace' :
this.isSerifFont ? 'serif' : 'sans-serif';
this.differences = properties.differences;
this.widths = properties.widths;