From 6590cc32f2e1d5a42f3fef1070bf278519a7f31b Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 14 Jan 2020 15:28:37 +0100 Subject: [PATCH] Extract the subroutine bias computation into a helper function in `src/core/font_renderer.js` --- src/core/font_renderer.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/core/font_renderer.js b/src/core/font_renderer.js index df6dadb81..acb733c1c 100644 --- a/src/core/font_renderer.js +++ b/src/core/font_renderer.js @@ -39,6 +39,17 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { return (data[offset] << 8) | data[offset + 1]; } + function getSubroutineBias(subrs) { + const numSubrs = subrs.length; + let bias = 32768; + if (numSubrs < 1240) { + bias = 107; + } else if (numSubrs < 33900) { + bias = 1131; + } + return bias; + } + function parseCmap(data, start, end) { var offset = getUshort(data, start + 2) === 1 @@ -422,9 +433,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { subrs = fontDict.privateDict.subrsIndex.objects; } if (subrs) { - let numSubrs = subrs.length; // Add subroutine bias. - n += numSubrs < 1240 ? 107 : numSubrs < 33900 ? 1131 : 32768; + n += getSubroutineBias(subrs); subrCode = subrs[n]; } } else { @@ -804,18 +814,8 @@ var FontRendererFactory = (function FontRendererFactoryClosure() { this.cmap = cmap; this.glyphNameMap = glyphNameMap || getGlyphsUnicode(); - this.gsubrsBias = - this.gsubrs.length < 1240 - ? 107 - : this.gsubrs.length < 33900 - ? 1131 - : 32768; - this.subrsBias = - this.subrs.length < 1240 - ? 107 - : this.subrs.length < 33900 - ? 1131 - : 32768; + this.gsubrsBias = getSubroutineBias(this.gsubrs); + this.subrsBias = getSubroutineBias(this.subrs); this.isCFFCIDFont = cffInfo.isCFFCIDFont; this.fdSelect = cffInfo.fdSelect;