Skip to content

Commit 4b2030e

Browse files
committed
Streamline AFMFont parsing. Do not keep contents in memory
1 parent 715c2e3 commit 4b2030e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/font/afm.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,16 @@ udieresis yacute thorn ydieresis\
103103
`.split(/\s+/);
104104

105105
class AFMFont {
106+
/**
107+
* @param {string} contents
108+
*/
106109
constructor(contents) {
107-
this.contents = contents;
108110
this.attributes = {};
109111
this.glyphWidths = {};
110112
this.boundingBoxes = {};
111113
this.kernPairs = {};
112114

113-
this.parse();
115+
this.parse(contents);
114116

115117
this.bbox = this.attributes['FontBBox'].split(/\s+/).map((e) => +e);
116118
this.ascender = +(this.attributes['Ascender'] || 0);
@@ -121,9 +123,12 @@ class AFMFont {
121123
this.bbox[3] - this.bbox[1] - (this.ascender - this.descender);
122124
}
123125

124-
parse() {
126+
/**
127+
* @param {string} contents
128+
*/
129+
parse(contents) {
125130
let section = '';
126-
for (let line of this.contents.split('\n')) {
131+
for (let line of contents.split('\n')) {
127132
var match;
128133
var a;
129134
if ((match = line.match(/^Start(\w+)/))) {
@@ -168,6 +173,10 @@ class AFMFont {
168173
}
169174
}
170175

176+
/**
177+
* @param {string} text
178+
* @returns
179+
*/
171180
encodeText(text) {
172181
const res = [];
173182
for (let i = 0, len = text.length; i < len; i++) {

0 commit comments

Comments
 (0)