Merge pull request #11773 from Snuffleupagus/Font-exportData-1
[api-minor] Change `Font.exportData` to use an explicit white-list of exportable properties, and stop exporting internal/unused properties
This commit is contained in:
commit
0400109b87
@ -1761,7 +1761,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
fontFamily: font.fallbackName,
|
fontFamily: font.fallbackName,
|
||||||
ascent: font.ascent,
|
ascent: font.ascent,
|
||||||
descent: font.descent,
|
descent: font.descent,
|
||||||
vertical: !!font.vertical,
|
vertical: font.vertical,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
textContentItem.fontName = font.loadedName;
|
textContentItem.fontName = font.loadedName;
|
||||||
|
@ -87,6 +87,43 @@ var PDF_GLYPH_SPACE_UNITS = 1000;
|
|||||||
// custom one. Windows just refuses to draw glyphs with seac operators.
|
// custom one. Windows just refuses to draw glyphs with seac operators.
|
||||||
var SEAC_ANALYSIS_ENABLED = true;
|
var SEAC_ANALYSIS_ENABLED = true;
|
||||||
|
|
||||||
|
const EXPORT_DATA_PROPERTIES = [
|
||||||
|
"ascent",
|
||||||
|
"bbox",
|
||||||
|
"black",
|
||||||
|
"bold",
|
||||||
|
"cMap",
|
||||||
|
"charProcOperatorList",
|
||||||
|
"composite",
|
||||||
|
"data",
|
||||||
|
"defaultEncoding",
|
||||||
|
"defaultVMetrics",
|
||||||
|
"defaultWidth",
|
||||||
|
"descent",
|
||||||
|
"differences",
|
||||||
|
"fallbackName",
|
||||||
|
"fontMatrix",
|
||||||
|
"fontType",
|
||||||
|
"isMonospace",
|
||||||
|
"isSerifFont",
|
||||||
|
"isSymbolicFont",
|
||||||
|
"isType3Font",
|
||||||
|
"italic",
|
||||||
|
"loadedName",
|
||||||
|
"mimetype",
|
||||||
|
"missingFile",
|
||||||
|
"name",
|
||||||
|
"remeasure",
|
||||||
|
"seacMap",
|
||||||
|
"subtype",
|
||||||
|
"toFontChar",
|
||||||
|
"toUnicode",
|
||||||
|
"type",
|
||||||
|
"vertical",
|
||||||
|
"vmetrics",
|
||||||
|
"widths",
|
||||||
|
];
|
||||||
|
|
||||||
var FontFlags = {
|
var FontFlags = {
|
||||||
FixedPitch: 1,
|
FixedPitch: 1,
|
||||||
Serif: 2,
|
Serif: 2,
|
||||||
@ -570,7 +607,7 @@ var Font = (function FontClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.cidEncoding = properties.cidEncoding;
|
this.cidEncoding = properties.cidEncoding;
|
||||||
this.vertical = properties.vertical;
|
this.vertical = !!properties.vertical;
|
||||||
if (this.vertical) {
|
if (this.vertical) {
|
||||||
this.vmetrics = properties.vmetrics;
|
this.vmetrics = properties.vmetrics;
|
||||||
this.defaultVMetrics = properties.defaultVMetrics;
|
this.defaultVMetrics = properties.defaultVMetrics;
|
||||||
@ -1258,12 +1295,14 @@ var Font = (function FontClosure() {
|
|||||||
return shadow(this, "renderer", renderer);
|
return shadow(this, "renderer", renderer);
|
||||||
},
|
},
|
||||||
|
|
||||||
exportData: function Font_exportData() {
|
exportData() {
|
||||||
// TODO remove enumerating of the properties, e.g. hardcode exact names.
|
const data = Object.create(null);
|
||||||
var data = {};
|
let property, value;
|
||||||
for (var i in this) {
|
for (property of EXPORT_DATA_PROPERTIES) {
|
||||||
if (this.hasOwnProperty(i)) {
|
value = this[property];
|
||||||
data[i] = this[i];
|
// Ignore properties that haven't been explicitly set.
|
||||||
|
if (value !== undefined) {
|
||||||
|
data[property] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
@ -3119,10 +3158,6 @@ var Font = (function FontClosure() {
|
|||||||
},
|
},
|
||||||
|
|
||||||
get spaceWidth() {
|
get spaceWidth() {
|
||||||
if ("_shadowWidth" in this) {
|
|
||||||
return this._shadowWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
// trying to estimate space character width
|
// trying to estimate space character width
|
||||||
var possibleSpaceReplacements = ["space", "minus", "one", "i", "I"];
|
var possibleSpaceReplacements = ["space", "minus", "one", "i", "I"];
|
||||||
var width;
|
var width;
|
||||||
@ -3137,10 +3172,8 @@ var Font = (function FontClosure() {
|
|||||||
var glyphUnicode = glyphsUnicodeMap[glyphName];
|
var glyphUnicode = glyphsUnicodeMap[glyphName];
|
||||||
// finding the charcode via unicodeToCID map
|
// finding the charcode via unicodeToCID map
|
||||||
var charcode = 0;
|
var charcode = 0;
|
||||||
if (this.composite) {
|
if (this.composite && this.cMap.contains(glyphUnicode)) {
|
||||||
if (this.cMap.contains(glyphUnicode)) {
|
charcode = this.cMap.lookup(glyphUnicode);
|
||||||
charcode = this.cMap.lookup(glyphUnicode);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// ... via toUnicode map
|
// ... via toUnicode map
|
||||||
if (!charcode && this.toUnicode) {
|
if (!charcode && this.toUnicode) {
|
||||||
@ -3157,10 +3190,7 @@ var Font = (function FontClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
width = width || this.defaultWidth;
|
width = width || this.defaultWidth;
|
||||||
// Do not shadow the property here. See discussion:
|
return shadow(this, "spaceWidth", width);
|
||||||
// https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
|
|
||||||
this._shadowWidth = width;
|
|
||||||
return width;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
charToGlyph: function Font_charToGlyph(charcode, isSpace) {
|
charToGlyph: function Font_charToGlyph(charcode, isSpace) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user