pdfkit 0.8.2 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/LICENSE +7 -7
- package/README.md +175 -171
- package/js/{font/data → data}/Courier-Bold.afm +342 -342
- package/js/{font/data → data}/Courier-BoldOblique.afm +342 -342
- package/js/{font/data → data}/Courier-Oblique.afm +342 -342
- package/js/{font/data → data}/Courier.afm +342 -342
- package/js/{font/data → data}/Helvetica-Bold.afm +2827 -2827
- package/js/{font/data → data}/Helvetica-BoldOblique.afm +2827 -2827
- package/js/{font/data → data}/Helvetica-Oblique.afm +3051 -3051
- package/js/{font/data → data}/Helvetica.afm +3051 -3051
- package/js/{font/data → data}/Symbol.afm +213 -213
- package/js/{font/data → data}/Times-Bold.afm +2588 -2588
- package/js/{font/data → data}/Times-BoldItalic.afm +2384 -2384
- package/js/{font/data → data}/Times-Italic.afm +2667 -2667
- package/js/{font/data → data}/Times-Roman.afm +2419 -2419
- package/js/{font/data → data}/ZapfDingbats.afm +225 -225
- package/js/pdfkit.es5.js +5724 -0
- package/js/pdfkit.es5.js.map +1 -0
- package/js/pdfkit.esnext.js +5144 -0
- package/js/pdfkit.esnext.js.map +1 -0
- package/js/pdfkit.js +5112 -0
- package/js/pdfkit.js.map +1 -0
- package/js/pdfkit.standalone.js +68105 -0
- package/js/virtual-fs.js +70 -0
- package/package.json +85 -55
- package/.npmignore +0 -8
- package/Makefile +0 -30
- package/js/data.js +0 -192
- package/js/document.js +0 -247
- package/js/font/afm.js +0 -170
- package/js/font/data/MustRead.html +0 -19
- package/js/font/embedded.js +0 -234
- package/js/font/standard.js +0 -124
- package/js/font.js +0 -75
- package/js/gradient.js +0 -240
- package/js/image/jpeg.js +0 -78
- package/js/image/png.js +0 -158
- package/js/image.js +0 -53
- package/js/line_wrapper.js +0 -252
- package/js/mixins/annotations.js +0 -133
- package/js/mixins/color.js +0 -304
- package/js/mixins/fonts.js +0 -69
- package/js/mixins/images.js +0 -111
- package/js/mixins/text.js +0 -337
- package/js/mixins/vector.js +0 -265
- package/js/object.js +0 -114
- package/js/page.js +0 -170
- package/js/path.js +0 -366
- package/js/reference.js +0 -109
package/js/font/afm.js
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
// Generated by CoffeeScript 1.12.1
|
|
2
|
-
(function() {
|
|
3
|
-
var AFMFont, fs;
|
|
4
|
-
|
|
5
|
-
fs = require('fs');
|
|
6
|
-
|
|
7
|
-
AFMFont = (function() {
|
|
8
|
-
var WIN_ANSI_MAP, characters;
|
|
9
|
-
|
|
10
|
-
AFMFont.open = function(filename) {
|
|
11
|
-
return new AFMFont(fs.readFileSync(filename, 'utf8'));
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
function AFMFont(contents) {
|
|
15
|
-
var e, i;
|
|
16
|
-
this.contents = contents;
|
|
17
|
-
this.attributes = {};
|
|
18
|
-
this.glyphWidths = {};
|
|
19
|
-
this.boundingBoxes = {};
|
|
20
|
-
this.kernPairs = {};
|
|
21
|
-
this.parse();
|
|
22
|
-
this.charWidths = (function() {
|
|
23
|
-
var j, results;
|
|
24
|
-
results = [];
|
|
25
|
-
for (i = j = 0; j <= 255; i = ++j) {
|
|
26
|
-
results.push(this.glyphWidths[characters[i]]);
|
|
27
|
-
}
|
|
28
|
-
return results;
|
|
29
|
-
}).call(this);
|
|
30
|
-
this.bbox = (function() {
|
|
31
|
-
var j, len, ref, results;
|
|
32
|
-
ref = this.attributes['FontBBox'].split(/\s+/);
|
|
33
|
-
results = [];
|
|
34
|
-
for (j = 0, len = ref.length; j < len; j++) {
|
|
35
|
-
e = ref[j];
|
|
36
|
-
results.push(+e);
|
|
37
|
-
}
|
|
38
|
-
return results;
|
|
39
|
-
}).call(this);
|
|
40
|
-
this.ascender = +(this.attributes['Ascender'] || 0);
|
|
41
|
-
this.descender = +(this.attributes['Descender'] || 0);
|
|
42
|
-
this.lineGap = (this.bbox[3] - this.bbox[1]) - (this.ascender - this.descender);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
AFMFont.prototype.parse = function() {
|
|
46
|
-
var a, j, key, len, line, match, name, ref, section, value;
|
|
47
|
-
section = '';
|
|
48
|
-
ref = this.contents.split('\n');
|
|
49
|
-
for (j = 0, len = ref.length; j < len; j++) {
|
|
50
|
-
line = ref[j];
|
|
51
|
-
if (match = line.match(/^Start(\w+)/)) {
|
|
52
|
-
section = match[1];
|
|
53
|
-
continue;
|
|
54
|
-
} else if (match = line.match(/^End(\w+)/)) {
|
|
55
|
-
section = '';
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
switch (section) {
|
|
59
|
-
case 'FontMetrics':
|
|
60
|
-
match = line.match(/(^\w+)\s+(.*)/);
|
|
61
|
-
key = match[1];
|
|
62
|
-
value = match[2];
|
|
63
|
-
if (a = this.attributes[key]) {
|
|
64
|
-
if (!Array.isArray(a)) {
|
|
65
|
-
a = this.attributes[key] = [a];
|
|
66
|
-
}
|
|
67
|
-
a.push(value);
|
|
68
|
-
} else {
|
|
69
|
-
this.attributes[key] = value;
|
|
70
|
-
}
|
|
71
|
-
break;
|
|
72
|
-
case 'CharMetrics':
|
|
73
|
-
if (!/^CH?\s/.test(line)) {
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
name = line.match(/\bN\s+(\.?\w+)\s*;/)[1];
|
|
77
|
-
this.glyphWidths[name] = +line.match(/\bWX\s+(\d+)\s*;/)[1];
|
|
78
|
-
break;
|
|
79
|
-
case 'KernPairs':
|
|
80
|
-
match = line.match(/^KPX\s+(\.?\w+)\s+(\.?\w+)\s+(-?\d+)/);
|
|
81
|
-
if (match) {
|
|
82
|
-
this.kernPairs[match[1] + '\0' + match[2]] = parseInt(match[3]);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
WIN_ANSI_MAP = {
|
|
89
|
-
402: 131,
|
|
90
|
-
8211: 150,
|
|
91
|
-
8212: 151,
|
|
92
|
-
8216: 145,
|
|
93
|
-
8217: 146,
|
|
94
|
-
8218: 130,
|
|
95
|
-
8220: 147,
|
|
96
|
-
8221: 148,
|
|
97
|
-
8222: 132,
|
|
98
|
-
8224: 134,
|
|
99
|
-
8225: 135,
|
|
100
|
-
8226: 149,
|
|
101
|
-
8230: 133,
|
|
102
|
-
8364: 128,
|
|
103
|
-
8240: 137,
|
|
104
|
-
8249: 139,
|
|
105
|
-
8250: 155,
|
|
106
|
-
710: 136,
|
|
107
|
-
8482: 153,
|
|
108
|
-
338: 140,
|
|
109
|
-
339: 156,
|
|
110
|
-
732: 152,
|
|
111
|
-
352: 138,
|
|
112
|
-
353: 154,
|
|
113
|
-
376: 159,
|
|
114
|
-
381: 142,
|
|
115
|
-
382: 158
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
AFMFont.prototype.encodeText = function(text) {
|
|
119
|
-
var char, i, j, ref, res;
|
|
120
|
-
res = [];
|
|
121
|
-
for (i = j = 0, ref = text.length; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
|
|
122
|
-
char = text.charCodeAt(i);
|
|
123
|
-
char = WIN_ANSI_MAP[char] || char;
|
|
124
|
-
res.push(char.toString(16));
|
|
125
|
-
}
|
|
126
|
-
return res;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
AFMFont.prototype.glyphsForString = function(string) {
|
|
130
|
-
var charCode, glyphs, i, j, ref;
|
|
131
|
-
glyphs = [];
|
|
132
|
-
for (i = j = 0, ref = string.length; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
|
|
133
|
-
charCode = string.charCodeAt(i);
|
|
134
|
-
glyphs.push(this.characterToGlyph(charCode));
|
|
135
|
-
}
|
|
136
|
-
return glyphs;
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
AFMFont.prototype.characterToGlyph = function(character) {
|
|
140
|
-
return characters[WIN_ANSI_MAP[character] || character] || '.notdef';
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
AFMFont.prototype.widthOfGlyph = function(glyph) {
|
|
144
|
-
return this.glyphWidths[glyph] || 0;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
AFMFont.prototype.getKernPair = function(left, right) {
|
|
148
|
-
return this.kernPairs[left + '\0' + right] || 0;
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
AFMFont.prototype.advancesForGlyphs = function(glyphs) {
|
|
152
|
-
var advances, index, j, left, len, right;
|
|
153
|
-
advances = [];
|
|
154
|
-
for (index = j = 0, len = glyphs.length; j < len; index = ++j) {
|
|
155
|
-
left = glyphs[index];
|
|
156
|
-
right = glyphs[index + 1];
|
|
157
|
-
advances.push(this.widthOfGlyph(left) + this.getKernPair(left, right));
|
|
158
|
-
}
|
|
159
|
-
return advances;
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
characters = '.notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n\nspace exclam quotedbl numbersign\ndollar percent ampersand quotesingle\nparenleft parenright asterisk plus\ncomma hyphen period slash\nzero one two three\nfour five six seven\neight nine colon semicolon\nless equal greater question\n\nat A B C\nD E F G\nH I J K\nL M N O\nP Q R S\nT U V W\nX Y Z bracketleft\nbackslash bracketright asciicircum underscore\n\ngrave a b c\nd e f g\nh i j k\nl m n o\np q r s\nt u v w\nx y z braceleft\nbar braceright asciitilde .notdef\n\nEuro .notdef quotesinglbase florin\nquotedblbase ellipsis dagger daggerdbl\ncircumflex perthousand Scaron guilsinglleft\nOE .notdef Zcaron .notdef\n.notdef quoteleft quoteright quotedblleft\nquotedblright bullet endash emdash\ntilde trademark scaron guilsinglright\noe .notdef zcaron ydieresis\n\nspace exclamdown cent sterling\ncurrency yen brokenbar section\ndieresis copyright ordfeminine guillemotleft\nlogicalnot hyphen registered macron\ndegree plusminus twosuperior threesuperior\nacute mu paragraph periodcentered\ncedilla onesuperior ordmasculine guillemotright\nonequarter onehalf threequarters questiondown\n\nAgrave Aacute Acircumflex Atilde\nAdieresis Aring AE Ccedilla\nEgrave Eacute Ecircumflex Edieresis\nIgrave Iacute Icircumflex Idieresis\nEth Ntilde Ograve Oacute\nOcircumflex Otilde Odieresis multiply\nOslash Ugrave Uacute Ucircumflex\nUdieresis Yacute Thorn germandbls\n\nagrave aacute acircumflex atilde\nadieresis aring ae ccedilla\negrave eacute ecircumflex edieresis\nigrave iacute icircumflex idieresis\neth ntilde ograve oacute\nocircumflex otilde odieresis divide\noslash ugrave uacute ucircumflex\nudieresis yacute thorn ydieresis'.split(/\s+/);
|
|
163
|
-
|
|
164
|
-
return AFMFont;
|
|
165
|
-
|
|
166
|
-
})();
|
|
167
|
-
|
|
168
|
-
module.exports = AFMFont;
|
|
169
|
-
|
|
170
|
-
}).call(this);
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
<html>
|
|
2
|
-
|
|
3
|
-
<head>
|
|
4
|
-
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
|
|
5
|
-
<meta name="generator" content="Adobe GoLive 4">
|
|
6
|
-
<title>Core 14 AFM Files - ReadMe</title>
|
|
7
|
-
</head>
|
|
8
|
-
|
|
9
|
-
<body bgcolor="white">
|
|
10
|
-
<font color="white">or</font>
|
|
11
|
-
<table border="0" cellpadding="0" cellspacing="2">
|
|
12
|
-
<tr>
|
|
13
|
-
<td width="40"></td>
|
|
14
|
-
<td width="300">This file and the 14 PostScript(R) AFM files it accompanies may be used, copied, and distributed for any purpose and without charge, with or without modification, provided that all copyright notices are retained; that the AFM files are not distributed without this file; that all modifications to this file or any of the AFM files are prominently noted in the modified file(s); and that this paragraph is not modified. Adobe Systems has no responsibility or obligation to support the use of the AFM files. <font color="white">Col</font></td>
|
|
15
|
-
</tr>
|
|
16
|
-
</table>
|
|
17
|
-
</body>
|
|
18
|
-
|
|
19
|
-
</html>
|
package/js/font/embedded.js
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
// Generated by CoffeeScript 1.12.1
|
|
2
|
-
(function() {
|
|
3
|
-
var EmbeddedFont, PDFFont, PDFObject,
|
|
4
|
-
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
5
|
-
hasProp = {}.hasOwnProperty,
|
|
6
|
-
slice = [].slice;
|
|
7
|
-
|
|
8
|
-
PDFFont = require('../font');
|
|
9
|
-
|
|
10
|
-
PDFObject = require('../object');
|
|
11
|
-
|
|
12
|
-
EmbeddedFont = (function(superClass) {
|
|
13
|
-
var toHex;
|
|
14
|
-
|
|
15
|
-
extend(EmbeddedFont, superClass);
|
|
16
|
-
|
|
17
|
-
function EmbeddedFont(document, font, id) {
|
|
18
|
-
this.document = document;
|
|
19
|
-
this.font = font;
|
|
20
|
-
this.id = id;
|
|
21
|
-
this.subset = this.font.createSubset();
|
|
22
|
-
this.unicode = [[0]];
|
|
23
|
-
this.widths = [this.font.getGlyph(0).advanceWidth];
|
|
24
|
-
this.name = this.font.postscriptName;
|
|
25
|
-
this.scale = 1000 / this.font.unitsPerEm;
|
|
26
|
-
this.ascender = this.font.ascent * this.scale;
|
|
27
|
-
this.descender = this.font.descent * this.scale;
|
|
28
|
-
this.lineGap = this.font.lineGap * this.scale;
|
|
29
|
-
this.bbox = this.font.bbox;
|
|
30
|
-
this.layoutCache = Object.create(null);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
EmbeddedFont.prototype.layoutRun = function(text, features) {
|
|
34
|
-
var i, j, key, len, position, ref, run;
|
|
35
|
-
run = this.font.layout(text, features);
|
|
36
|
-
ref = run.positions;
|
|
37
|
-
for (i = j = 0, len = ref.length; j < len; i = ++j) {
|
|
38
|
-
position = ref[i];
|
|
39
|
-
for (key in position) {
|
|
40
|
-
position[key] *= this.scale;
|
|
41
|
-
}
|
|
42
|
-
position.advanceWidth = run.glyphs[i].advanceWidth * this.scale;
|
|
43
|
-
}
|
|
44
|
-
return run;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
EmbeddedFont.prototype.layoutCached = function(text) {
|
|
48
|
-
var cached, run;
|
|
49
|
-
if (cached = this.layoutCache[text]) {
|
|
50
|
-
return cached;
|
|
51
|
-
}
|
|
52
|
-
run = this.layoutRun(text);
|
|
53
|
-
this.layoutCache[text] = run;
|
|
54
|
-
return run;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
EmbeddedFont.prototype.layout = function(text, features, onlyWidth) {
|
|
58
|
-
var advanceWidth, glyphs, index, last, positions, ref, run;
|
|
59
|
-
if (onlyWidth == null) {
|
|
60
|
-
onlyWidth = false;
|
|
61
|
-
}
|
|
62
|
-
if (features) {
|
|
63
|
-
return this.layoutRun(text, features);
|
|
64
|
-
}
|
|
65
|
-
glyphs = onlyWidth ? null : [];
|
|
66
|
-
positions = onlyWidth ? null : [];
|
|
67
|
-
advanceWidth = 0;
|
|
68
|
-
last = 0;
|
|
69
|
-
index = 0;
|
|
70
|
-
while (index <= text.length) {
|
|
71
|
-
if ((index === text.length && last < index) || ((ref = text.charAt(index)) === ' ' || ref === '\t')) {
|
|
72
|
-
run = this.layoutCached(text.slice(last, ++index));
|
|
73
|
-
if (!onlyWidth) {
|
|
74
|
-
glyphs.push.apply(glyphs, run.glyphs);
|
|
75
|
-
positions.push.apply(positions, run.positions);
|
|
76
|
-
}
|
|
77
|
-
advanceWidth += run.advanceWidth;
|
|
78
|
-
last = index;
|
|
79
|
-
} else {
|
|
80
|
-
index++;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
glyphs: glyphs,
|
|
85
|
-
positions: positions,
|
|
86
|
-
advanceWidth: advanceWidth
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
EmbeddedFont.prototype.encode = function(text, features) {
|
|
91
|
-
var base, base1, gid, glyph, glyphs, i, j, len, positions, ref, res;
|
|
92
|
-
ref = this.layout(text, features), glyphs = ref.glyphs, positions = ref.positions;
|
|
93
|
-
res = [];
|
|
94
|
-
for (i = j = 0, len = glyphs.length; j < len; i = ++j) {
|
|
95
|
-
glyph = glyphs[i];
|
|
96
|
-
gid = this.subset.includeGlyph(glyph.id);
|
|
97
|
-
res.push(('0000' + gid.toString(16)).slice(-4));
|
|
98
|
-
if ((base = this.widths)[gid] == null) {
|
|
99
|
-
base[gid] = glyph.advanceWidth * this.scale;
|
|
100
|
-
}
|
|
101
|
-
if ((base1 = this.unicode)[gid] == null) {
|
|
102
|
-
base1[gid] = glyph.codePoints;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return [res, positions];
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
EmbeddedFont.prototype.widthOfString = function(string, size, features) {
|
|
109
|
-
var scale, width;
|
|
110
|
-
width = this.layout(string, features, true).advanceWidth;
|
|
111
|
-
scale = size / 1000;
|
|
112
|
-
return width * scale;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
EmbeddedFont.prototype.embed = function() {
|
|
116
|
-
var bbox, descendantFont, descriptor, familyClass, flags, fontFile, i, isCFF, name, ref, tag;
|
|
117
|
-
isCFF = this.subset.cff != null;
|
|
118
|
-
fontFile = this.document.ref();
|
|
119
|
-
if (isCFF) {
|
|
120
|
-
fontFile.data.Subtype = 'CIDFontType0C';
|
|
121
|
-
}
|
|
122
|
-
this.subset.encodeStream().pipe(fontFile);
|
|
123
|
-
familyClass = (((ref = this.font['OS/2']) != null ? ref.sFamilyClass : void 0) || 0) >> 8;
|
|
124
|
-
flags = 0;
|
|
125
|
-
if (this.font.post.isFixedPitch) {
|
|
126
|
-
flags |= 1 << 0;
|
|
127
|
-
}
|
|
128
|
-
if ((1 <= familyClass && familyClass <= 7)) {
|
|
129
|
-
flags |= 1 << 1;
|
|
130
|
-
}
|
|
131
|
-
flags |= 1 << 2;
|
|
132
|
-
if (familyClass === 10) {
|
|
133
|
-
flags |= 1 << 3;
|
|
134
|
-
}
|
|
135
|
-
if (this.font.head.macStyle.italic) {
|
|
136
|
-
flags |= 1 << 6;
|
|
137
|
-
}
|
|
138
|
-
tag = ((function() {
|
|
139
|
-
var j, results;
|
|
140
|
-
results = [];
|
|
141
|
-
for (i = j = 0; j < 6; i = ++j) {
|
|
142
|
-
results.push(String.fromCharCode(Math.random() * 26 + 65));
|
|
143
|
-
}
|
|
144
|
-
return results;
|
|
145
|
-
})()).join('');
|
|
146
|
-
name = tag + '+' + this.font.postscriptName;
|
|
147
|
-
bbox = this.font.bbox;
|
|
148
|
-
descriptor = this.document.ref({
|
|
149
|
-
Type: 'FontDescriptor',
|
|
150
|
-
FontName: name,
|
|
151
|
-
Flags: flags,
|
|
152
|
-
FontBBox: [bbox.minX * this.scale, bbox.minY * this.scale, bbox.maxX * this.scale, bbox.maxY * this.scale],
|
|
153
|
-
ItalicAngle: this.font.italicAngle,
|
|
154
|
-
Ascent: this.ascender,
|
|
155
|
-
Descent: this.descender,
|
|
156
|
-
CapHeight: (this.font.capHeight || this.font.ascent) * this.scale,
|
|
157
|
-
XHeight: (this.font.xHeight || 0) * this.scale,
|
|
158
|
-
StemV: 0
|
|
159
|
-
});
|
|
160
|
-
if (isCFF) {
|
|
161
|
-
descriptor.data.FontFile3 = fontFile;
|
|
162
|
-
} else {
|
|
163
|
-
descriptor.data.FontFile2 = fontFile;
|
|
164
|
-
}
|
|
165
|
-
descriptor.end();
|
|
166
|
-
descendantFont = this.document.ref({
|
|
167
|
-
Type: 'Font',
|
|
168
|
-
Subtype: isCFF ? 'CIDFontType0' : 'CIDFontType2',
|
|
169
|
-
BaseFont: name,
|
|
170
|
-
CIDSystemInfo: {
|
|
171
|
-
Registry: new String('Adobe'),
|
|
172
|
-
Ordering: new String('Identity'),
|
|
173
|
-
Supplement: 0
|
|
174
|
-
},
|
|
175
|
-
FontDescriptor: descriptor,
|
|
176
|
-
W: [0, this.widths]
|
|
177
|
-
});
|
|
178
|
-
descendantFont.end();
|
|
179
|
-
this.dictionary.data = {
|
|
180
|
-
Type: 'Font',
|
|
181
|
-
Subtype: 'Type0',
|
|
182
|
-
BaseFont: name,
|
|
183
|
-
Encoding: 'Identity-H',
|
|
184
|
-
DescendantFonts: [descendantFont],
|
|
185
|
-
ToUnicode: this.toUnicodeCmap()
|
|
186
|
-
};
|
|
187
|
-
return this.dictionary.end();
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
toHex = function() {
|
|
191
|
-
var code, codePoints, codes;
|
|
192
|
-
codePoints = 1 <= arguments.length ? slice.call(arguments, 0) : [];
|
|
193
|
-
codes = (function() {
|
|
194
|
-
var j, len, results;
|
|
195
|
-
results = [];
|
|
196
|
-
for (j = 0, len = codePoints.length; j < len; j++) {
|
|
197
|
-
code = codePoints[j];
|
|
198
|
-
results.push(('0000' + code.toString(16)).slice(-4));
|
|
199
|
-
}
|
|
200
|
-
return results;
|
|
201
|
-
})();
|
|
202
|
-
return codes.join('');
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
EmbeddedFont.prototype.toUnicodeCmap = function() {
|
|
206
|
-
var cmap, codePoints, encoded, entries, j, k, len, len1, ref, value;
|
|
207
|
-
cmap = this.document.ref();
|
|
208
|
-
entries = [];
|
|
209
|
-
ref = this.unicode;
|
|
210
|
-
for (j = 0, len = ref.length; j < len; j++) {
|
|
211
|
-
codePoints = ref[j];
|
|
212
|
-
encoded = [];
|
|
213
|
-
for (k = 0, len1 = codePoints.length; k < len1; k++) {
|
|
214
|
-
value = codePoints[k];
|
|
215
|
-
if (value > 0xffff) {
|
|
216
|
-
value -= 0x10000;
|
|
217
|
-
encoded.push(toHex(value >>> 10 & 0x3ff | 0xd800));
|
|
218
|
-
value = 0xdc00 | value & 0x3ff;
|
|
219
|
-
}
|
|
220
|
-
encoded.push(toHex(value));
|
|
221
|
-
}
|
|
222
|
-
entries.push("<" + (encoded.join(' ')) + ">");
|
|
223
|
-
}
|
|
224
|
-
cmap.end("/CIDInit /ProcSet findresource begin\n12 dict begin\nbegincmap\n/CIDSystemInfo <<\n /Registry (Adobe)\n /Ordering (UCS)\n /Supplement 0\n>> def\n/CMapName /Adobe-Identity-UCS def\n/CMapType 2 def\n1 begincodespacerange\n<0000><ffff>\nendcodespacerange\n1 beginbfrange\n<0000> <" + (toHex(entries.length - 1)) + "> [" + (entries.join(' ')) + "]\nendbfrange\nendcmap\nCMapName currentdict /CMap defineresource pop\nend\nend");
|
|
225
|
-
return cmap;
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
return EmbeddedFont;
|
|
229
|
-
|
|
230
|
-
})(PDFFont);
|
|
231
|
-
|
|
232
|
-
module.exports = EmbeddedFont;
|
|
233
|
-
|
|
234
|
-
}).call(this);
|
package/js/font/standard.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
// Generated by CoffeeScript 1.12.1
|
|
2
|
-
(function() {
|
|
3
|
-
var AFMFont, PDFFont, StandardFont, fs,
|
|
4
|
-
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
5
|
-
hasProp = {}.hasOwnProperty;
|
|
6
|
-
|
|
7
|
-
AFMFont = require('./afm');
|
|
8
|
-
|
|
9
|
-
PDFFont = require('../font');
|
|
10
|
-
|
|
11
|
-
fs = require('fs');
|
|
12
|
-
|
|
13
|
-
StandardFont = (function(superClass) {
|
|
14
|
-
var STANDARD_FONTS;
|
|
15
|
-
|
|
16
|
-
extend(StandardFont, superClass);
|
|
17
|
-
|
|
18
|
-
function StandardFont(document, name1, id) {
|
|
19
|
-
var ref;
|
|
20
|
-
this.document = document;
|
|
21
|
-
this.name = name1;
|
|
22
|
-
this.id = id;
|
|
23
|
-
this.font = new AFMFont(STANDARD_FONTS[this.name]());
|
|
24
|
-
ref = this.font, this.ascender = ref.ascender, this.descender = ref.descender, this.bbox = ref.bbox, this.lineGap = ref.lineGap;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
StandardFont.prototype.embed = function() {
|
|
28
|
-
this.dictionary.data = {
|
|
29
|
-
Type: 'Font',
|
|
30
|
-
BaseFont: this.name,
|
|
31
|
-
Subtype: 'Type1',
|
|
32
|
-
Encoding: 'WinAnsiEncoding'
|
|
33
|
-
};
|
|
34
|
-
return this.dictionary.end();
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
StandardFont.prototype.encode = function(text) {
|
|
38
|
-
var advances, encoded, glyph, glyphs, i, j, len, positions;
|
|
39
|
-
encoded = this.font.encodeText(text);
|
|
40
|
-
glyphs = this.font.glyphsForString('' + text);
|
|
41
|
-
advances = this.font.advancesForGlyphs(glyphs);
|
|
42
|
-
positions = [];
|
|
43
|
-
for (i = j = 0, len = glyphs.length; j < len; i = ++j) {
|
|
44
|
-
glyph = glyphs[i];
|
|
45
|
-
positions.push({
|
|
46
|
-
xAdvance: advances[i],
|
|
47
|
-
yAdvance: 0,
|
|
48
|
-
xOffset: 0,
|
|
49
|
-
yOffset: 0,
|
|
50
|
-
advanceWidth: this.font.widthOfGlyph(glyph)
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
return [encoded, positions];
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
StandardFont.prototype.widthOfString = function(string, size) {
|
|
57
|
-
var advance, advances, glyphs, j, len, scale, width;
|
|
58
|
-
glyphs = this.font.glyphsForString('' + string);
|
|
59
|
-
advances = this.font.advancesForGlyphs(glyphs);
|
|
60
|
-
width = 0;
|
|
61
|
-
for (j = 0, len = advances.length; j < len; j++) {
|
|
62
|
-
advance = advances[j];
|
|
63
|
-
width += advance;
|
|
64
|
-
}
|
|
65
|
-
scale = size / 1000;
|
|
66
|
-
return width * scale;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
StandardFont.isStandardFont = function(name) {
|
|
70
|
-
return name in STANDARD_FONTS;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
STANDARD_FONTS = {
|
|
74
|
-
"Courier": function() {
|
|
75
|
-
return fs.readFileSync(__dirname + "/../font/data/Courier.afm", 'utf8');
|
|
76
|
-
},
|
|
77
|
-
"Courier-Bold": function() {
|
|
78
|
-
return fs.readFileSync(__dirname + "/../font/data/Courier-Bold.afm", 'utf8');
|
|
79
|
-
},
|
|
80
|
-
"Courier-Oblique": function() {
|
|
81
|
-
return fs.readFileSync(__dirname + "/../font/data/Courier-Oblique.afm", 'utf8');
|
|
82
|
-
},
|
|
83
|
-
"Courier-BoldOblique": function() {
|
|
84
|
-
return fs.readFileSync(__dirname + "/../font/data/Courier-BoldOblique.afm", 'utf8');
|
|
85
|
-
},
|
|
86
|
-
"Helvetica": function() {
|
|
87
|
-
return fs.readFileSync(__dirname + "/../font/data/Helvetica.afm", 'utf8');
|
|
88
|
-
},
|
|
89
|
-
"Helvetica-Bold": function() {
|
|
90
|
-
return fs.readFileSync(__dirname + "/../font/data/Helvetica-Bold.afm", 'utf8');
|
|
91
|
-
},
|
|
92
|
-
"Helvetica-Oblique": function() {
|
|
93
|
-
return fs.readFileSync(__dirname + "/../font/data/Helvetica-Oblique.afm", 'utf8');
|
|
94
|
-
},
|
|
95
|
-
"Helvetica-BoldOblique": function() {
|
|
96
|
-
return fs.readFileSync(__dirname + "/../font/data/Helvetica-BoldOblique.afm", 'utf8');
|
|
97
|
-
},
|
|
98
|
-
"Times-Roman": function() {
|
|
99
|
-
return fs.readFileSync(__dirname + "/../font/data/Times-Roman.afm", 'utf8');
|
|
100
|
-
},
|
|
101
|
-
"Times-Bold": function() {
|
|
102
|
-
return fs.readFileSync(__dirname + "/../font/data/Times-Bold.afm", 'utf8');
|
|
103
|
-
},
|
|
104
|
-
"Times-Italic": function() {
|
|
105
|
-
return fs.readFileSync(__dirname + "/../font/data/Times-Italic.afm", 'utf8');
|
|
106
|
-
},
|
|
107
|
-
"Times-BoldItalic": function() {
|
|
108
|
-
return fs.readFileSync(__dirname + "/../font/data/Times-BoldItalic.afm", 'utf8');
|
|
109
|
-
},
|
|
110
|
-
"Symbol": function() {
|
|
111
|
-
return fs.readFileSync(__dirname + "/../font/data/Symbol.afm", 'utf8');
|
|
112
|
-
},
|
|
113
|
-
"ZapfDingbats": function() {
|
|
114
|
-
return fs.readFileSync(__dirname + "/../font/data/ZapfDingbats.afm", 'utf8');
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
return StandardFont;
|
|
119
|
-
|
|
120
|
-
})(PDFFont);
|
|
121
|
-
|
|
122
|
-
module.exports = StandardFont;
|
|
123
|
-
|
|
124
|
-
}).call(this);
|
package/js/font.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
// Generated by CoffeeScript 1.12.1
|
|
2
|
-
(function() {
|
|
3
|
-
var EmbeddedFont, PDFFont, StandardFont, fontkit;
|
|
4
|
-
|
|
5
|
-
fontkit = require('fontkit');
|
|
6
|
-
|
|
7
|
-
PDFFont = (function() {
|
|
8
|
-
PDFFont.open = function(document, src, family, id) {
|
|
9
|
-
var font;
|
|
10
|
-
if (typeof src === 'string') {
|
|
11
|
-
if (StandardFont.isStandardFont(src)) {
|
|
12
|
-
return new StandardFont(document, src, id);
|
|
13
|
-
}
|
|
14
|
-
font = fontkit.openSync(src, family);
|
|
15
|
-
} else if (Buffer.isBuffer(src)) {
|
|
16
|
-
font = fontkit.create(src, family);
|
|
17
|
-
} else if (src instanceof Uint8Array) {
|
|
18
|
-
font = fontkit.create(new Buffer(src), family);
|
|
19
|
-
} else if (src instanceof ArrayBuffer) {
|
|
20
|
-
font = fontkit.create(new Buffer(new Uint8Array(src)), family);
|
|
21
|
-
}
|
|
22
|
-
if (font == null) {
|
|
23
|
-
throw new Error('Not a supported font format or standard PDF font.');
|
|
24
|
-
}
|
|
25
|
-
return new EmbeddedFont(document, font, id);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
function PDFFont() {
|
|
29
|
-
throw new Error('Cannot construct a PDFFont directly.');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
PDFFont.prototype.encode = function(text) {
|
|
33
|
-
throw new Error('Must be implemented by subclasses');
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
PDFFont.prototype.widthOfString = function(text) {
|
|
37
|
-
throw new Error('Must be implemented by subclasses');
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
PDFFont.prototype.ref = function() {
|
|
41
|
-
return this.dictionary != null ? this.dictionary : this.dictionary = this.document.ref();
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
PDFFont.prototype.finalize = function() {
|
|
45
|
-
if (this.embedded || (this.dictionary == null)) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
this.embed();
|
|
49
|
-
return this.embedded = true;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
PDFFont.prototype.embed = function() {
|
|
53
|
-
throw new Error('Must be implemented by subclasses');
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
PDFFont.prototype.lineHeight = function(size, includeGap) {
|
|
57
|
-
var gap;
|
|
58
|
-
if (includeGap == null) {
|
|
59
|
-
includeGap = false;
|
|
60
|
-
}
|
|
61
|
-
gap = includeGap ? this.lineGap : 0;
|
|
62
|
-
return (this.ascender + gap - this.descender) / 1000 * size;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
return PDFFont;
|
|
66
|
-
|
|
67
|
-
})();
|
|
68
|
-
|
|
69
|
-
module.exports = PDFFont;
|
|
70
|
-
|
|
71
|
-
StandardFont = require('./font/standard');
|
|
72
|
-
|
|
73
|
-
EmbeddedFont = require('./font/embedded');
|
|
74
|
-
|
|
75
|
-
}).call(this);
|