Stop calling Font.charsToGlyphs, in src/core/annotation.js, with unused arguments

As can be seen in `src/core/fonts.js`, this method only accepts *one* parameter, hence it's somewhat difficult to understand what the Annotation-code is actually attempting to do here.
The only possible explanation that I can imagine, is that the intention was initially to call `Font.charToGlyph` *directly* instead. However, note that that'd would not actually have been correct, since that'd ignore one level of font-caching (see `this.charsCache`). Hence the unused arguments are removed, in `src/core/annotation.js`, and the `Font.charToGlyph` method is now marked as "private" as intended.
This commit is contained in:
Jonas Jenwald 2020-10-29 14:05:42 +01:00
parent bf870bd2ac
commit 8540b4cc76
2 changed files with 9 additions and 6 deletions

View File

@ -1326,7 +1326,7 @@ class WidgetAnnotation extends Annotation {
_computeFontSize(font, fontName, fontSize, height) {
if (fontSize === null || fontSize === 0) {
const em = font.charsToGlyphs("M", true)[0].width / 1000;
const em = font.charsToGlyphs("M")[0].width / 1000;
// According to https://en.wikipedia.org/wiki/Em_(typography)
// an average cap height should be 70% of 1em
const capHeight = 0.7 * em;
@ -1597,7 +1597,7 @@ class TextWidgetAnnotation extends WidgetAnnotation {
}
const scale = fontSize / 1000;
const whitespace = font.charsToGlyphs(" ", true)[0].width * scale;
const whitespace = font.charsToGlyphs(" ")[0].width * scale;
const chunks = [];
let lastSpacePos = -1,
@ -1618,7 +1618,7 @@ class TextWidgetAnnotation extends WidgetAnnotation {
lastSpacePos = i;
}
} else {
const charWidth = font.charsToGlyphs(character, false)[0].width * scale;
const charWidth = font.charsToGlyphs(character)[0].width * scale;
if (currentWidth + charWidth > width) {
// We must break to the last white position (if available)
if (lastSpacePos !== -1) {

View File

@ -3208,7 +3208,10 @@ var Font = (function FontClosure() {
return shadow(this, "spaceWidth", width);
},
charToGlyph: function Font_charToGlyph(charcode, isSpace) {
/**
* @private
*/
_charToGlyph(charcode, isSpace = false) {
var fontCharCode, width, operatorListId;
var widthCode = charcode;
@ -3332,13 +3335,13 @@ var Font = (function FontClosure() {
i += length;
// Space is char with code 0x20 and length 1 in multiple-byte codes.
var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
glyph = this.charToGlyph(charcode, isSpace);
glyph = this._charToGlyph(charcode, isSpace);
glyphs.push(glyph);
}
} else {
for (i = 0, ii = chars.length; i < ii; ++i) {
charcode = chars.charCodeAt(i);
glyph = this.charToGlyph(charcode, charcode === 0x20);
glyph = this._charToGlyph(charcode, charcode === 0x20);
glyphs.push(glyph);
}
}