mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 09:20:06 +02:00
Revert "Remove the unused Font.prototype.spaceWidth
getter (PR 13424 follow-up)"
This reverts commit 4aee67227e
.
This commit is contained in:
parent
7ffa9a283d
commit
f9d63201eb
1 changed files with 38 additions and 0 deletions
|
@ -3293,6 +3293,44 @@ class Font {
|
||||||
return builder.toArray();
|
return builder.toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get spaceWidth() {
|
||||||
|
// trying to estimate space character width
|
||||||
|
const possibleSpaceReplacements = ["space", "minus", "one", "i", "I"];
|
||||||
|
let width;
|
||||||
|
for (const glyphName of possibleSpaceReplacements) {
|
||||||
|
// if possible, getting width by glyph name
|
||||||
|
if (glyphName in this.widths) {
|
||||||
|
width = this.widths[glyphName];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const glyphsUnicodeMap = getGlyphsUnicode();
|
||||||
|
const glyphUnicode = glyphsUnicodeMap[glyphName];
|
||||||
|
// finding the charcode via unicodeToCID map
|
||||||
|
let charcode = 0;
|
||||||
|
if (this.composite && this.cMap.contains(glyphUnicode)) {
|
||||||
|
charcode = this.cMap.lookup(glyphUnicode);
|
||||||
|
|
||||||
|
if (typeof charcode === "string") {
|
||||||
|
charcode = convertCidString(glyphUnicode, charcode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ... via toUnicode map
|
||||||
|
if (!charcode && this.toUnicode) {
|
||||||
|
charcode = this.toUnicode.charCodeOf(glyphUnicode);
|
||||||
|
}
|
||||||
|
// setting it to unicode if negative or undefined
|
||||||
|
if (charcode <= 0) {
|
||||||
|
charcode = glyphUnicode;
|
||||||
|
}
|
||||||
|
// trying to get width via charcode
|
||||||
|
width = this.widths[charcode];
|
||||||
|
if (width) {
|
||||||
|
break; // the non-zero width found
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return shadow(this, "spaceWidth", width || this.defaultWidth);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue