-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsfnt.js
4183 lines (3580 loc) · 129 KB
/
sfnt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.SFNT = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
"use strict";
var SFNT = require('./SFNT/SFNT');
var formGlobals = require('./formGlobals');
var utils = require('./utils');
var asChars = utils.asChars;
var asGlyphIDs = utils.asGlyphIDs;
var addLabelSubstitution = require("./utils/addLabelSubstitution");
module.exports = {
utils: utils,
build: function (options) {
var sfnt = new SFNT();
var font = sfnt.stub;
var globals = formGlobals(options);
/**
* Font header
*/
font.head = new font.head({
unitsPerEM: globals.quadSize,
xMin: globals.xMin,
yMin: globals.yMin,
xMax: globals.xMax,
yMax: globals.yMax,
});
/**
* Horizontal metrics header table
*/
font.hhea = new font.hhea({
Ascender: globals.quadSize + globals.yMin,
Descender: -(globals.quadSize - globals.yMax),
advanceWidthMax: globals.xMax - globals.xMin,
xMaxExtent: globals.xMax - globals.xMin,
numberOfHMetrics: globals.letters ? 1 + globals.letters.length : 2
});
/**
* Horizontal metrics table
*/
font.hmtx = new font.hmtx(globals, font.hhea.numberOfHMetrics);
/**
* Max profiles - CFF does not use these, which we indicate by
* using a table version 0.5
*/
font.maxp = new font.maxp({
version: 0x00005000,
numGlyphs: globals.letters ? 1 + globals.letters.length : 2
});
/**
* The name table
*
* - to have a font be windows installable, we need strings 1, 2, 3, and 6.
* - to have a font be OSX installable, we need strings 1, 2, 3, 4, 5, and 6.
* - to have a font be webfont-usable, we just need strings 1 and 2.
*
* (OTS may be patched at some point to not even check the name table at
* all, at which point we don't have to bother generating it for webfonts)
*/
font.name = new font.name(globals);
/**
* The OS/2 table
*/
font["OS/2"] = new font["OS/2"]({
// we use version 3, so we can pass Microsoft's "Font Validator"
version: 0x0003,
// we implement part of the basic latin unicode block
// FIXME: this should be based on the globals.letters list
ulUnicodeRange1: 0x00000001,
achVendID: globals.vendorId,
usFirstCharIndex: globals.label ? globals.letters[0].charCodeAt(0) : globals.glyphCode,
usLastCharIndex: globals.glyphCode,
// vertical metrics: see http://typophile.com/node/13081 for how the hell these work.
// (short version: they don't, it's an amazing mess)
sTypoAscender: globals.yMax,
sTypoDescender: globals.yMin,
sTypoLineGap: globals.quadSize - globals.yMax + globals.yMin,
usWinAscent: globals.quadSize + globals.yMin,
usWinDescent: (globals.quadSize - globals.yMax),
// we implement part of the latin1 codepage
// FIXME: this should also be based on the globals.letters list
ulCodePageRange1: 0x00000001,
// we have no break char, but we must point to a "not .notdef" glyphid to
// validate as "legal font". Normally this would be the 'space' glyphid.
usBreakChar: globals.glyphCode,
// We have plain + ligature use, therefore the max length of
// all contexts are simply the length of our substitution label,
// if we have one, or otherwise zero.
usMaxContext: globals.substitutions !== false ? Object.keys(globals.substitutions).length : 0
});
/**
* The post table -- this table should not be necessary for
* webfonts, but for now must be included for the font to be legal.
*/
font.post = new font.post();
/**
* The character map for this font, using a cmap
* format 4 subtable for our implemented glyphs.
*/
font.cmap = new font.cmap({ version: 0 });
font.cmap.addTable({ format: 4, letters: globals.letters });
font.cmap.finalise();
/**
* The CFF table for this font. This is, ironically,
* the actual font, rather than a million different
* bits of metadata *about* the font and its glyphs.
*
* It's also the most complex bit (closely followed
* by the GSUB table for ligature substitution), which
* is why the CFF table isn't actually a struct, but
* a somewhat different bytecode generator.
*
* It works, it just works a little different from
* everything else.
*/
font["CFF "] = new font["CFF "](globals);
/**
* Finally, if there were "substitutions", we need some GSUB
* magic. Note: this stuff is complex. Like, properly, which
* is why it's wrapped by a function, rather than being a simple
* few constructor options. Seriously, GSUB is voodoo black magic.
*/
if(globals.substitutions) {
font.GSUB = new font.GSUB(globals);
addLabelSubstitution(font, globals);
}
// we're done.
return sfnt;
}
};
},{"./SFNT/SFNT":3,"./formGlobals":62,"./utils":76,"./utils/addLabelSubstitution":64}],2:[function(require,module,exports){
var struct = require("../utils").struct;
"use strict";
var DirectoryEntry = function(input) {
if(!this.parse(input)) {
input = input || {};
this.fill(input);
}
};
DirectoryEntry.prototype = new struct("DirectoryEntry", [
["tag", "CHARARRAY", "4-byte identifier"]
, ["checkSum", "ULONG", "sum-as-ULONGs for this table"]
, ["offset", "ULONG", "offset to this table from the beginning of the file"]
, ["length", "ULONG", "length of the table (without padding) in bytes"]
]);
module.exports = DirectoryEntry;
},{"../utils":76}],3:[function(require,module,exports){
var tables = require("./tables");
var SFNTHeader = require("./SFNTHeader");
var DirectoryEntry = require("./DirectoryEntry");
var utils = require('../utils');
var dataBuilding = utils.dataBuilding;
var Mapper = utils.Mapper;
var nodeBuilder = utils.nodeBuilder;
"use strict";
var header = SFNTHeader("CFF");
var SFNT = function(type) {
this.stub = {
BASE: tables.BASE,
"CFF ": tables.CFF,
GDEF: tables.GDEF,
GPOS: tables.GPOS,
GSUB: tables.GSUB,
JSTF: tables.JSTF,
"OS/2": tables.OS_2,
cmap: tables.cmap,
head: tables.head,
hhea: tables.hhea,
hmtx: tables.hmtx,
maxp: tables.maxp,
name: tables.name,
post: tables.post
};
this.header = new header();
this.fontStructs = false;
};
SFNT.prototype = {
toString: function() {
return JSON.stringify(this.toJSON(), false, 2);
},
toJSON: function() {
var self = this,
obj = {};
Object.keys(this.stub).forEach(function(tag) {
if(self.stub[tag].toJSON) {
obj[tag] = self.stub[tag].toJSON();
}
});
return obj;
},
toHTML: function() {
if(!this.fontStructs) {
this.toData();
}
var self = this,
obj = nodeBuilder.create("div"),
font = this.stub,
directory = this.fontStructs.directory,
keys;
obj.setAttribute("class", "SFNT");
obj.appendChild(this.header.toHTML());
var dHTML = nodeBuilder.create("div");
dHTML.setAttribute("class", "Directory");
keys = Object.keys(directory),
keys.forEach(function(tag) {
dHTML.appendChild(directory[tag].toHTML());
});
obj.appendChild(dHTML);
var tHTML = nodeBuilder.create("div");
tHTML.setAttribute("class", "Tables");
keys = Object.keys(font),
keys.forEach(function(tag) {
if (font[tag].toHTML) {
tHTML.appendChild(font[tag].toHTML());
}
});
obj.appendChild(tHTML);
return obj;
},
toDataURL: function() {
return utils.toDataURL("font", this);
},
toData: function() {
var self = this,
tags = {},
dataBlocks = {};
// form data blocks and table directory
Object.keys(this.stub).forEach(function(tag) {
if(self.stub[tag].toData) {
var tagStruct = new DirectoryEntry();
tags[tag] = tagStruct;
tagStruct.tag = tag;
dataBlocks[tag] = self.stub[tag].toData();
tagStruct.length = dataBlocks[tag].length;
while(dataBlocks[tag].length % 4 !== 0) { dataBlocks[tag].push(0); }
tagStruct.checkSum = dataBuilding.computeChecksum(dataBlocks[tag]);
// offset is computed when we actually fix the block locations in the file
}
});
var header = this.header;
header.version = "OTTO";
// fill in the header values that are based on the number of tables
var log2 = function(v) { return (Math.log(v) / Math.log(2)) | 0; }
var numTables = Object.keys(tags).length;
header.numTables = numTables;
var highestPowerOf2 = Math.pow(2, log2(numTables));
var searchRange = 16 * highestPowerOf2;
header.searchRange = searchRange;
header.entrySelector = log2(highestPowerOf2);
header.rangeShift = numTables * 16 - searchRange;
var headerBlock = header.toData();
// optimise table data block ordering, based on the
// "Optimized Table Ordering" section on
// http://www.microsoft.com/typography/otspec140/recom.htm
var sorted = Object.keys(tags).sort(),
offsets = {},
block_offset = headerBlock.length + header.numTables * 16,
dataBlock = [],
preferred = (function getOptimizedTableOrder(sorted) {
var preferred = ["head", "hhea", "maxp", "OS/2", "name", "cmap", "post", "CFF "],
filtered = sorted.filter(function(v) {
return preferred.indexOf(v) === -1;
}),
keys = preferred.concat(filtered);
return keys;
}(sorted));
preferred.forEach(function(tag) {
if(dataBlocks[tag]) {
offsets[tag] = block_offset + dataBlock.length;
dataBlock = dataBlock.concat(dataBlocks[tag]);
}
});
// Then, finalise and write out the directory block:
var directoryBlock = [];
sorted.forEach(function(tag) {
if(tags[tag]) {
tags[tag].offset = offsets[tag];
directoryBlock = directoryBlock.concat(tags[tag].toData());
}
});
// And then assemble the final font data into one "file",
// making sure the checkSumAdjustment value in the <head>
// table is based on the final serialized font data.
var font = headerBlock.concat(directoryBlock).concat(dataBlock);
var checksum = dataBuilding.computeChecksum(font);
var checkSumAdjustment = 0xB1B0AFBA - checksum;
this.stub.head.checkSumAdjustment = checkSumAdjustment;
// the data layout in this font can now be properly mapped,
// if the user wants to call the getMappings() function.
this.fontStructs = {
header: header,
directoryOrder: sorted,
directory: tags,
tableOrder: preferred
};
// return the font with the correct checksumadjustment.
return font.slice(0, offsets["head"] + 8)
.concat(dataBuilding.encoder.ULONG(checkSumAdjustment))
.concat(font.slice(offsets["head"] + 12));
},
getMapper: function() {
if(this.fontStructs === false) return false;
var mapper = new Mapper();
var self = this;
var offset = 0, mark = 0;
this.fontStructs.header.toData(offset, mapper);
offset = mapper.last().end;
mapper.addMapping(mark, {
name: "SFNT header",
length: offset - mark,
structure: self.fontStructs.header.toJSON()
});
this.fontStructs.directoryOrder.forEach(function(tag) {
mark = offset
self.fontStructs.directory[tag].toData(offset, mapper);
offset = mapper.last().end;
mapper.addMapping(mark, {
name: tag + " directory",
length: offset - mark,
structure: self.fontStructs.directory[tag].toJSON()
});
});
this.fontStructs.tableOrder.forEach(function(tag) {
mark = offset;
self.stub[tag].toData(offset, mapper);
offset = mapper.last().end;
mapper.addMapping(mark, {
name: tag + " table",
length: offset - mark,
structure: self.stub[tag].toJSON()
});
while(offset % 4 !== 0) { offset++; }
});
mapper.sort();
return mapper;
}
};
module.exports = SFNT;
},{"../utils":76,"./DirectoryEntry":2,"./SFNTHeader":4,"./tables":5}],4:[function(require,module,exports){
var struct = require("../utils").struct;
"use strict";
module.exports = function(type) {
var SFNTHeader = function(input) {
if(!this.parse(input)) {
input = input || {};
this.fill(input);
}
};
SFNTHeader.prototype = new struct("SFNT header", [
["version", type === "CFF" ? "CHARARRAY" : "FIXED", "either 0x0001000 for TTF, or 'OTTO' for CFF"]
, ["numTables", "USHORT", "number of tables in this font"]
, ["searchRange", "USHORT", "(Maximum power of 2 <= numTables) x 16"]
, ["entrySelector", "USHORT", "Log2(maximum power of 2 <= numTables)"]
, ["rangeShift", "USHORT", "NumTables x 16-searchRange"]
]);
return SFNTHeader;
};
},{"../utils":76}],5:[function(require,module,exports){
"use strict";
module.exports = {
CFF: require("./tables/CFF_"),
cmap: require("./tables/cmap"),
head: require("./tables/head"),
hhea: require("./tables/hhea"),
hmtx: require("./tables/hmtx"),
maxp: require("./tables/maxp"),
name: require("./tables/name"),
OS_2: require("./tables/OS_2"),
post: require("./tables/post"),
GSUB: require("./tables/GSUB"),
GPOS: require("./tables/GPOS"),
GDEF: require("./tables/GDEF"),
JSTF: require("./tables/JSTF"),
BASE: require("./tables/BASE")
};
},{"./tables/BASE":6,"./tables/CFF_":7,"./tables/GDEF":8,"./tables/GPOS":9,"./tables/GSUB":10,"./tables/JSTF":11,"./tables/OS_2":12,"./tables/cmap":24,"./tables/head":52,"./tables/hhea":53,"./tables/hmtx":54,"./tables/maxp":56,"./tables/name":57,"./tables/post":61}],6:[function(require,module,exports){
var utils = require("../../utils");
var struct = utils.struct;
"use strict";
var BASE = function(input) {
if(!this.parse(input)) {
input = input || {};
this.fill(input);
}
};
BASE.prototype = new struct("BASE table", [
//...
]);
module.exports = BASE;
},{"../../utils":76}],7:[function(require,module,exports){
var utils = require("../../utils");
var struct = utils.struct;
var dataBuilding = utils.dataBuilding;
var asHex = utils.asHex;
var CFFHeader = require("./cff/CFFHeader");
var NameIndex = require("./cff/NameIndex");
var StringIndex = require("./cff/StringIndex");
var TopDictIndex = require("./cff/TopDictIndex");
var SubroutineIndex = require("./cff/SubroutineIndex");
var Charset = require("./cff/Charset");
var Encoding = require("./cff/Encoding");
var CharStringIndex = require("./cff/CharStringIndex");
var PrivateDict = require("./cff/PrivateDict");
"use strict";
// Hook up the charset, encoding, charstrings and private dict offsets.
// we need to do this iteratively because setting their values may change
// the sizeOf for the top dict, and thus the offsets *after* the top dict.
// Hurray.
function fixTopDictIndexOffsets(baseSize, topDictIndex, charset, encoding, charStringIndex, privateDict) {
var ch_off, en_off, cs_off, pd_off, o_ch_off, o_en_off, o_cs_off, o_pd_off, base, pd_size = privateDict.sizeOf();
// "old" values
o_ch_off = o_en_off = o_cs_off = o_pd_off = -1;
// "current" values
ch_off = en_off = cs_off = pd_off = 0;
while(ch_off !== o_ch_off && en_off !== o_en_off && cs_off !== o_cs_off && pd_off !== o_pd_off) {
o_ch_off = ch_off; o_en_off = en_off; o_cs_off = cs_off; o_pd_off = pd_off;
base = baseSize + topDictIndex.sizeOf();
ch_off = base;
en_off = ch_off + charset.sizeOf();
cs_off = en_off + encoding.sizeOf();
pd_off = cs_off + charStringIndex.sizeOf();
topDictIndex.set("charset", ch_off);
topDictIndex.set("Encoding", en_off);
topDictIndex.set("CharStrings", cs_off);
topDictIndex.set("Private", [pd_size, pd_off]);
topDictIndex.finalise();
}
}
var CFF = function(input) {
if(!this.parse(input)) {
input = input || {};
this.fill(input);
this.header = new CFFHeader({
major: 1,
minor: 0,
offSize: 1
});
var nameIndex = new NameIndex([
input.postscriptName
]);
this["name index"] = nameIndex;
// because the top dict needs to know about string index values,
// as well as offsets to other bits of the CFF, it gets declared
// last, despite technicaly "living" here in terms of CFF byte layout.
var stringIndex = new StringIndex([
input.fontVersion,
input.fontName,
input.fontFamily
].concat(input.letters));
this["string index"] = stringIndex;
// we break up the charstring such that the initial rmoveto
// and associated coordinates are bound as a global subroutine
var globalSubroutines = new SubroutineIndex();
this["global subroutines"] = globalSubroutines;
// bind user-supplied global subroutines, if we have them.
if (input.subroutines) {
var routines = Object.keys(input.subroutines);
routines.forEach(function(name, pos) {
var code = input.subroutines[name];
globalSubroutines.addItem(code);
});
}
var charset = new Charset(stringIndex, input);
this["charset"] = charset;
var encoding = new Encoding(input);
this["encoding"] = encoding;
var charStringIndex = new CharStringIndex(input.letters, input.charstrings);
this["charstring index"] = charStringIndex;
var privateDict = new PrivateDict({
"BlueValues": [0, 0]
, "FamilyBlues": [0, 0]
, "StdHW": 10
, "StdVW": 10
, "defaultWidthX": input.xMax
, "nominalWidthX": input.xMax
});
this["private dict"] = privateDict;
var topDictIndex = new TopDictIndex({
"version": stringIndex.getStringId(input.fontVersion)
, "FullName": stringIndex.getStringId(input.fontName)
, "FamilyName": stringIndex.getStringId(input.fontFamily)
, "Weight": 389 // CFF-predefined string "Roman"
, "UniqueID": 1 // really this just has to be 'anything'
, "FontBBox": [input.xMin, input.yMin, input.xMax, input.yMax]
, "charset": 0 // placeholder for offset to charset block, from the beginning of the CFF file
, "Encoding": 0 // " " encoding block " "
, "CharStrings": 0 // " " charstrings block " "
, "Private": [0, 0] // sizeof, " " private dict block " "
});
this["top dict index"] = topDictIndex;
var baseSize = this.header.sizeOf() + nameIndex.sizeOf() + stringIndex.sizeOf() + globalSubroutines.sizeOf();
fixTopDictIndexOffsets(baseSize, topDictIndex, charset, encoding, charStringIndex, privateDict);
}
};
CFF.prototype = new struct("CFF ", [
["header", "LITERAL", "the CFF header"]
, ["name index", "LITERAL", "the name index for this font"]
, ["top dict index", "LITERAL", "the global font dict"]
, ["string index", "LITERAL", "the strings used in this font (there are 390 by-spec strings already)"]
, ["global subroutines", "LITERAL", "the global subroutines that all charstrings can use"]
, ["charset", "LITERAL", "the font's character set"]
, ["encoding", "LITERAL", "the encoding information for this font"]
, ["charstring index", "LITERAL", "the charstring definition for all encoded glyphs"]
, ["private dict", "LITERAL", "the private dicts; each dict maps a partial font."]
]);
module.exports = CFF;
},{"../../utils":76,"./cff/CFFHeader":13,"./cff/CharStringIndex":14,"./cff/Charset":15,"./cff/Encoding":17,"./cff/NameIndex":19,"./cff/PrivateDict":20,"./cff/StringIndex":21,"./cff/SubroutineIndex":22,"./cff/TopDictIndex":23}],8:[function(require,module,exports){
var utils = require("../../utils");
var struct = utils.struct;
"use strict";
var GDEF = function(input) {
if(!this.parse(input)) {
input = input || {};
this.fill(input);
}
};
GDEF.prototype = new struct("GDEF table", [
//...
]);
module.exports = GDEF;
},{"../../utils":76}],9:[function(require,module,exports){
var utils = require("../../utils");
var struct = utils.struct;
"use strict";
var GPOS = function(input) {
if(!this.parse(input)) {
input = input || {};
this.fill(input);
}
};
GPOS.prototype = new struct("GPOS table", [
//...
]);
module.exports = GPOS;
},{"../../utils":76}],10:[function(require,module,exports){
var utils = require("../../utils");
var struct = utils.struct;
var ScriptList = require("./common/ScriptList");
var FeatureList = require("./common/FeatureList");
var LookupList = require("./common/LookupList");
var LangSysTable = require("./common/LangSysTable");
"use strict";
var GSUB = function(input) {
this.scripts = new ScriptList();
this.features = new FeatureList();
this.lookups = new LookupList();
if(!this.parse(input)) {
input = input || {};
input.version = input.version || 0x00010000;
input.ScriptListOffset = 10; // scriptlist starts immediately after the GSUB header
this.fill(input);
}
};
GSUB.prototype = new struct("GSUB table", [
// GSUB header is four fields
["version", "FIXED", "Version of the GSUB table; initially set to 0x00010000"]
, ["ScriptListOffset", "OFFSET", "Offset to ScriptList table, from beginning of GSUB table"]
, ["FeatureListOffset", "OFFSET", "Offset to FeatureList table, from beginning of GSUB table"]
, ["LookupListOffset", "OFFSET", "Offset to LookupList table, from beginning of GSUB table"]
// and then the actual data
, ["ScriptList", "LITERAL", "the ScriptList object for this table"]
, ["FeatureList", "LITERAL", "the FeatureList object for this table"]
, ["LookupList", "LITERAL", "the LookupList object for this table"]
]);
GSUB.prototype.addScript = function(options) {
return this.scripts.addScript(options)
};
GSUB.prototype.addFeature = function(options) {
return this.features.addFeature(options);
};
GSUB.prototype.addLookup = function(options) {
return this.lookups.addLookup(options);
};
GSUB.prototype.makeLangSys = function(options) {
return new LangSysTable(options);
}
// finalise in reverse order: first the lookup list,
// then the feature list, then the script list.
GSUB.prototype.finalise = function() {
this.lookups.finalise();
this.LookupList = this.lookups;
this.features.finalise();
this.FeatureList = this.features;
this.scripts.finalise();
this.ScriptList = this.scripts;
this.FeatureListOffset = this.ScriptListOffset + this.ScriptList.toData().length;
this.LookupListOffset = this.FeatureListOffset + this.FeatureList.toData().length;
}
module.exports = GSUB;
},{"../../utils":76,"./common/FeatureList":39,"./common/LangSysTable":46,"./common/LookupList":47,"./common/ScriptList":49}],11:[function(require,module,exports){
var utils = require("../../utils");
var struct = utils.struct;
"use strict";
var JSTF = function(input) {
if(!this.parse(input)) {
input = input || {};
this.fill(input);
}
};
JSTF.prototype = new struct("JSTF table", [
//...
]);
module.exports = JSTF;
},{"../../utils":76}],12:[function(require,module,exports){
var utils = require("../../utils");
var struct = utils.struct;
"use strict";
var OS_2 = function(input) {
if(!this.parse(input)) {
input = input || {};
input.xAvgCharWidth = input.xAvgCharWidth || 0;
input.usWeightClass = input.usWeightClass || 400;
input.usWidthClass = input.usWidthClass || 1;
// standard font = font classification 0 ("Regular")
input.sFamilyClass= input.sFamilyClass || 0;
input.fsType = input.fsType || 0;
// font selection flag: bit 6 (lsb=0) is high, to indicate 'regular font'
input.fsSelection = input.fsSelection || 0x0040;
// we don't really care about the sub/super/strikeout values:
input.ySubscriptXSize = input.ySubscriptXSize || 0;
input.ySubscriptYSize = input.ySubscriptYSize || 0;
input.ySubscriptXOffset = input.ySubscriptXOffset || 0;
input.ySubscriptYOffset = input.ySubscriptYOffset || 0;
input.ySuperscriptXSize = input.ySuperscriptXSize || 0;
input.ySuperscriptYSize = input.ySuperscriptYSize || 0;
input.ySuperscriptXOffset = input.ySuperscriptXOffset || 0;
input.ySuperscriptYOffset = input.ySuperscriptYOffset || 0;
input.yStrikeoutSize = input.yStrikeoutSize || 0;
input.yStrikeoutPosition = input.yStrikeoutPosition || 0;
// Oh look! A trademarked classification system the bytes
// for which cannot be legally set unless you pay HP.
// Why this is part of the OS/2 table instead of its own
// proprietary table I will likely never truly know.
input.bFamilyType = input.bFamilyType || 0;
input.bSerifStyle = input.bSerifStyle || 0;
input.bWeight = input.bWeight || 0;
input.bProportion = input.bProportion || 0;
input.bContrast = input.bContrast || 0;
input.bStrokeVariation = input.bStrokeVariation || 0;
input.bArmStyle = input.bArmStyle || 0;
input.bLetterform = input.bLetterform || 0;
input.bMidline = input.bMidline || 0;
input.bXHeight = input.bXHeight || 0;
input.ulUnicodeRange1 = input.ulUnicodeRange1 || 0;
input.ulUnicodeRange2 = input.ulUnicodeRange2 || 0;
input.ulUnicodeRange3 = input.ulUnicodeRange3 || 0;
input.ulUnicodeRange4 = input.ulUnicodeRange4 || 0;
input.ulCodePageRange1 = input.ulCodePageRange1 || 0;
input.ulCodePageRange2 = input.ulCodePageRange2 || 0;
// We don't care all too much about the next 5 values, but they're
// required for an OS/2 version 2, 3, or 4 table.
input.sxHeight = input.sxHeight || 0;
input.sCapHeight = input.sCapHeight || 0;
input.usDefaultChar = input.usDefaultChar || 0;
this.fill(input);
if(input.version < 2) {
this.unset(["sxHeight","sCapHeight","usDefaultChar","usBreakChar","usMaxContext"]);
}
}
};
OS_2.prototype = new struct("OS/2 table", [
["version", "USHORT", "OS/2 table version"]
, ["xAvgCharWidth", "SHORT", "xAvgCharWidth"]
, ["usWeightClass", "USHORT", "usWeightClass"]
, ["usWidthClass", "USHORT", "usWidthClass"]
, ["fsType", "USHORT", "this value defines embedding/install properties. 0 = no restrictions"]
, ["ySubscriptXSize", "SHORT", ""]
, ["ySubscriptYSize", "SHORT", ""]
, ["ySubscriptXOffset", "SHORT", ""]
, ["ySubscriptYOffset", "SHORT", ""]
, ["ySuperscriptXSize", "SHORT", ""]
, ["ySuperscriptYSize", "SHORT", ""]
, ["ySuperscriptXOffset", "SHORT", ""]
, ["ySuperscriptYOffset", "SHORT", ""]
, ["yStrikeoutSize", "SHORT", ""]
, ["yStrikeoutPosition", "SHORT", ""]
, ["sFamilyClass", "SHORT", "a standard font has font classification 0 (meaning subfamily 'Regular')"]
, ["bFamilyType", "BYTE", ""] // panose classification, byte 1
, ["bSerifStyle", "BYTE", ""] // panose classification, byte 2
, ["bWeight", "BYTE", ""] // panose classification, byte 3
, ["bProportion", "BYTE", ""] // panose classification, byte 4
, ["bContrast", "BYTE", ""] // panose classification, byte 5
, ["bStrokeVariation", "BYTE", ""] // panose classification, byte 6
, ["bArmStyle", "BYTE", ""] // panose classification, byte 7
, ["bLetterform", "BYTE", ""] // panose classification, byte 8
, ["bMidline", "BYTE", ""] // panose classification, byte 9
, ["bXHeight", "BYTE", ""] // panose classification, byte 10
, ["ulUnicodeRange1", "ULONG", ""]
, ["ulUnicodeRange2", "ULONG", ""]
, ["ulUnicodeRange3", "ULONG", ""]
, ["ulUnicodeRange4", "ULONG", ""]
, ["achVendID", "CHARARRAY", "vendor id (http://www.microsoft.com/typography/links/vendorlist.aspx for the 'real' list)"]
, ["fsSelection", "USHORT", "font selection flag: bit 6 (lsb=0) is high, to indicate 'regular font'."]
, ["usFirstCharIndex", "USHORT", "first character to be in this font."]
, ["usLastCharIndex", "USHORT", "last character to be in this font."]
// for information on how to set the vertical metrics for a font, see
// http://typophile.com/node/13081 for how the hell these work (it's quite amazing)
, ["sTypoAscender", "SHORT", "typographic ascender"]
, ["sTypoDescender", "SHORT", "typographic descender"]
, ["sTypoLineGap", "SHORT", "line gap"]
, ["usWinAscent", "USHORT", "usWinAscent"]
, ["usWinDescent", "USHORT", "usWinDescent"]
, ["ulCodePageRange1", "ULONG", ""]
, ["ulCodePageRange2", "ULONG", ""]
// By using the following five records, this becomes an OS/2 version 2, 3, or 4 table, rather than version 1 ---
, ["sxHeight", "SHORT", ""]
, ["sCapHeight", "SHORT", ""]
, ["usDefaultChar", "USHORT", ""]
, ["usBreakChar", "USHORT", ""]
, ["usMaxContext", "USHORT", ""]
]);
module.exports = OS_2;
},{"../../utils":76}],13:[function(require,module,exports){
var utils = require("../../../utils");
var struct = utils.struct;
"use strict";
var CFFHeader = function(input) {
if(!this.parse(input)) {
input = input || {};
input.length = 4;
this.fill(input);
this.setName("CFFHeader");
}
}
CFFHeader.prototype = new struct("CFF header", [
["major", "Card8", "major version"]
, ["minor", "Card8", "minor version"]
, ["length", "Card8", "header length in bytes"]
, ["offSize", "OffSize", "how many bytes for an offset value?"]
]);
module.exports = CFFHeader;
},{"../../../utils":76}],14:[function(require,module,exports){
var INDEX = require("./INDEX");
var dataBuilding = require("../../../utils").dataBuilding;
"use strict";
var encode = dataBuilding.encoder.CHARARRAY;
var CharStringIndex = function(letters, charstrings) {
var self = this;
INDEX.call(this);
this.setName("CharStringIndex");
// The .notdef character - for simplicity,
// this has no outline at all.
this.addItem(dataBuilding.encoder.OPERAND(14));
// Real letters
letters.forEach(function(letter, idx) {
self.addItem(charstrings[letter]);
});
this.finalise();
}
CharStringIndex.prototype = Object.create(INDEX.prototype);
module.exports = CharStringIndex;
},{"../../../utils":76,"./INDEX":18}],15:[function(require,module,exports){
var utils = require("../../../utils");
var struct = utils.struct;
var dataBuilding = utils.dataBuilding;
"use strict";
// FIXME: technically this is only the format0 charset object
var Charset = function(stringIndex, input) {
var glyphs = [];
if(!this.parse(input)) {
input = input || {};
input.format = 0;
input.letters = input.letters || [];
this.fill(input);
input.letters.forEach(function(letter) {
var sid = stringIndex.getStringId(letter);
var SID = dataBuilding.encoder.USHORT(sid);
glyphs = glyphs.concat(SID);
});
this.glyphs = glyphs;
this.setName("Charset");
}
};
Charset.prototype = new struct("CFF charset", [
["format", "BYTE", ""]
, ["glyphs", "LITERAL", "actually a USHORT[]."]
]);
module.exports = Charset;
},{"../../../utils":76}],16:[function(require,module,exports){
var utils = require("../../../utils");
var struct = utils.struct;
var dataBuilding = utils.dataBuilding;
"use strict";
var dictionaryStructure = dataBuilding.encoder.types.map(function(record) {
return [record, "CFF." + record, record];
});
var DICT = function(input) {
if(!this.parse(input)) {
input = input || {};
this.usedFields = Object.keys(input);
this.fill(input);
this.finalise();
}
};
DICT.prototype = new struct("CFF DICT", dictionaryStructure);
DICT.prototype.finalise = function() {
this.use(this.usedFields);
}
module.exports = DICT;
},{"../../../utils":76}],17:[function(require,module,exports){
var utils = require("../../../utils");
var struct = utils.struct;
var dataBuilding = utils.dataBuilding;
"use strict";
// FIXME: technically this is only the format1 Encoding object
var Encoding = function(input) {
var codes = [];
if(!this.parse(input)) {
input = input || {};
input.format = 0;
var codes = input.letters.map(function(v,idx) {
return idx+1;
});
input.nCodes = codes.length;
input.codes = codes;
this.fill(input);
this.setName("Encoding");
}
};
Encoding.prototype = new struct("CFF Encoding", [
["format", "BYTE", "encoding format"]
, ["nCodes", "BYTE", "..."]
, ["codes", "LITERAL", ""]
]);
module.exports = Encoding;
},{"../../../utils":76}],18:[function(require,module,exports){
var utils = require("../../../utils");
var struct = utils.struct;
var dataBuilding = utils.dataBuilding;
"use strict";
var INDEX = function(input) {
this.items = [];
if(!this.parse(input)) {
input = input || {};
input.count = 0;
this.fill(input);
}
}
INDEX.prototype = new struct("CFF INDEX", [
["count", "Card16", "number of stored items"]
, ["offSize", "OffSize", "how many bytes do offset values use in this index"]
, ["offset", "LITERAL", "depending on offSize, this is actually BYTE[], USHORT[], UINT24[] or ULONG[]. Note that offsets are relative to the byte *before* the data block, so the first offset is (almost always) 1, not 0."]
, ["data", "LITERAL", "the data block for this index"]
]);
INDEX.prototype.addItem = function(item) {
this.items.push(item);
this.count++;
this.finalise();