mirror of
https://github.com/foliojs/pdfkit.git
synced 2025-12-08 20:15:54 +00:00
Streamline AFMFont parsing. Do not keep contents in memory
This commit is contained in:
parent
715c2e39aa
commit
4b2030eedd
@ -103,14 +103,16 @@ udieresis yacute thorn ydieresis\
|
||||
`.split(/\s+/);
|
||||
|
||||
class AFMFont {
|
||||
/**
|
||||
* @param {string} contents
|
||||
*/
|
||||
constructor(contents) {
|
||||
this.contents = contents;
|
||||
this.attributes = {};
|
||||
this.glyphWidths = {};
|
||||
this.boundingBoxes = {};
|
||||
this.kernPairs = {};
|
||||
|
||||
this.parse();
|
||||
this.parse(contents);
|
||||
|
||||
this.bbox = this.attributes['FontBBox'].split(/\s+/).map((e) => +e);
|
||||
this.ascender = +(this.attributes['Ascender'] || 0);
|
||||
@ -121,9 +123,12 @@ class AFMFont {
|
||||
this.bbox[3] - this.bbox[1] - (this.ascender - this.descender);
|
||||
}
|
||||
|
||||
parse() {
|
||||
/**
|
||||
* @param {string} contents
|
||||
*/
|
||||
parse(contents) {
|
||||
let section = '';
|
||||
for (let line of this.contents.split('\n')) {
|
||||
for (let line of contents.split('\n')) {
|
||||
var match;
|
||||
var a;
|
||||
if ((match = line.match(/^Start(\w+)/))) {
|
||||
@ -168,6 +173,10 @@ class AFMFont {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} text
|
||||
* @returns
|
||||
*/
|
||||
encodeText(text) {
|
||||
const res = [];
|
||||
for (let i = 0, len = text.length; i < len; i++) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user