Adds heuristic for monospace font detection
This commit is contained in:
parent
ac7b6aeff4
commit
8d506212a8
@ -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.defaultWidth = defaultWidth;
|
||||||
properties.widths = glyphsWidths;
|
properties.widths = glyphsWidths;
|
||||||
},
|
},
|
||||||
|
|
||||||
getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
|
getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
|
||||||
var defaultWidth = 0, widths = [];
|
var defaultWidth = 0, widths = [], monospace = false;
|
||||||
var glyphWidths = Metrics[stdFontMap[name] || name];
|
var glyphWidths = Metrics[stdFontMap[name] || name];
|
||||||
if (isNum(glyphWidths)) {
|
if (isNum(glyphWidths)) {
|
||||||
defaultWidth = glyphWidths;
|
defaultWidth = glyphWidths;
|
||||||
|
monospace = true;
|
||||||
} else {
|
} else {
|
||||||
widths = glyphWidths;
|
widths = glyphWidths;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
defaultWidth: defaultWidth,
|
defaultWidth: defaultWidth,
|
||||||
|
monospace: monospace,
|
||||||
widths: widths
|
widths: widths
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -893,6 +913,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var fontNameWoStyle = baseFontName.split('-')[0];
|
var fontNameWoStyle = baseFontName.split('-')[0];
|
||||||
var flags = (serifFonts[fontNameWoStyle] ||
|
var flags = (serifFonts[fontNameWoStyle] ||
|
||||||
(fontNameWoStyle.search(/serif/gi) != -1) ? FontFlags.Serif : 0) |
|
(fontNameWoStyle.search(/serif/gi) != -1) ? FontFlags.Serif : 0) |
|
||||||
|
(metrics.monospace ? FontFlags.FixedPitch : 0) |
|
||||||
(symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
|
(symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
|
||||||
FontFlags.Nonsymbolic);
|
FontFlags.Nonsymbolic);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user