@@ -299,7 +299,6 @@ var Font = (function () {
299
299
300
300
// Wrap the CFF data inside an OTF font file
301
301
data = this .convert (name , cff , properties );
302
- writeToFile (data , "/tmp/file." + fontName + "-" + fontCount + ".otf" );
303
302
break ;
304
303
305
304
case "TrueType" :
@@ -373,7 +372,7 @@ var Font = (function () {
373
372
374
373
// length
375
374
var length = data .length ;
376
-
375
+
377
376
// Per spec tables must be 4-bytes align so add padding as needed
378
377
while (data .length & 3 )
379
378
data .push (0x00 );
@@ -435,7 +434,7 @@ var Font = (function () {
435
434
"\x00 \x00 \x00 \x0C " + // start of the table record
436
435
"\x00 \x04 " + // format
437
436
string16 (headerSize ) + // length
438
- "\x00 \x00 " + // languages
437
+ "\x04 \x09 " + // languages
439
438
string16 (segCount2 ) +
440
439
string16 (searchRange ) +
441
440
string16 (searchEntry ) +
@@ -458,7 +457,7 @@ var Font = (function () {
458
457
startCount += string16 (start );
459
458
endCount += string16 (end );
460
459
idDeltas += string16 (delta );
461
- idRangeOffsets += string16 (0 );
460
+ idRangeOffsets += string16 (0 );
462
461
463
462
for (var j = 0 ; j < range .length ; j ++)
464
463
glyphsIds += String .fromCharCode (range [j ]);
@@ -479,10 +478,19 @@ var Font = (function () {
479
478
var ulUnicodeRange3 = 0 ;
480
479
var ulUnicodeRange4 = 0 ;
481
480
482
- var charset = properties .charset ;
481
+ var charset = properties .charset ;
483
482
if (charset && charset .length ) {
483
+ var firstCharIndex = null ;
484
+ var lastCharIndex = 0 ;
485
+
484
486
for (var i = 1 ; i < charset .length ; i ++) {
485
- var position = getUnicodeRangeFor (GlyphsUnicode [charset [i ]]);
487
+ var code = GlyphsUnicode [charset [i ]];
488
+ if (code < firstCharIndex || !firstCharIndex )
489
+ firstCharIndex = code ;
490
+ if (code > lastCharIndex )
491
+ lastCharIndex = code ;
492
+
493
+ var position = getUnicodeRangeFor (code );
486
494
if (position < 32 ) {
487
495
ulUnicodeRange1 |= 1 << position ;
488
496
} else if (position < 64 ) {
@@ -520,8 +528,8 @@ var Font = (function () {
520
528
string32 (ulUnicodeRange4 ) + // ulUnicodeRange4 (Bits 96-127)
521
529
"\x2A \x32 \x31 \x2A " + // achVendID
522
530
"\x00 \x00 " + // fsSelection
523
- string16 (properties .firstChar ) + // usFirstCharIndex
524
- string16 (properties .lastChar ) + // usLastCharIndex
531
+ string16 (firstCharIndex || properties .firstChar ) + // usFirstCharIndex
532
+ string16 (lastCharIndex || properties .lastChar ) + // usLastCharIndex
525
533
"\x00 \x20 " + // sTypoAscender
526
534
"\x00 \x00 " + // sTypeDescender
527
535
"\x00 \x00 " + // sTypoLineGap
@@ -532,7 +540,7 @@ var Font = (function () {
532
540
string16 (properties .xHeight ) + // sxHeight
533
541
string16 (properties .capHeight ) + // sCapHeight
534
542
string16 (0 ) + // usDefaultChar
535
- string16 (0 ) + // usBreakChar
543
+ string16 (firstCharIndex || properties . firstChar ) + // usBreakChar
536
544
"\x00 \x00 " ; // usMaxContext
537
545
};
538
546
@@ -780,7 +788,7 @@ var Font = (function () {
780
788
name = name .slice (0 , name .length - 1 );
781
789
782
790
var strings = [
783
- "Original licence" ,// 0.Copyright
791
+ "Original licence" , // 0.Copyright
784
792
name , // 1.Font family
785
793
"Unknown ", // 2.Font subfamily (font weight)
786
794
" uniqueID ", // 3.Unique ID
@@ -792,14 +800,9 @@ var Font = (function () {
792
800
" Unknown " // 9.Designer
793
801
];
794
802
795
- var platforms = [" \x00 \x01 ", " \x00 \x03 "];
796
- var encodings = [" \x00 \x00 ", " \x00 \x01 "];
797
- var languages = [" \x00 \x00 ", " \x04 \x09 "];
798
-
799
803
// Mac want 1-byte per character strings while Windows want
800
804
// 2-bytes per character, so duplicate the names table
801
805
var stringsUnicode = [];
802
- var names = [strings, stringsUnicode];
803
806
for (var i = 0; i < strings.length; i++) {
804
807
var str = strings[i];
805
808
@@ -809,7 +812,12 @@ var Font = (function () {
809
812
stringsUnicode.push(strUnicode);
810
813
}
811
814
812
- var namesRecordCount = platforms.length * names.length;
815
+ var names = [strings, stringsUnicode];
816
+ var platforms = [" \x00 \x01 ", "\x00 \x03 "];
817
+ var encodings = [" \x00 \x00 ", " \x00 \x01 "];
818
+ var languages = [" \x00 \x00 ", " \x04 \x09 "];
819
+
820
+ var namesRecordCount = strings.length * platforms.length;
813
821
var nameTable =
814
822
" \x00 \x00 " + // format
815
823
string16(namesRecordCount) + // Number of names Record
@@ -818,9 +826,9 @@ var Font = (function () {
818
826
// Build the name records field
819
827
var strOffset = 0;
820
828
for (var i = 0; i < platforms.length; i++) {
821
- var names = strings [i];
822
- for (var j = 0; j < names .length; j++) {
823
- var str = names [j];
829
+ var strs = names [i];
830
+ for (var j = 0; j < strs .length; j++) {
831
+ var str = strs [j];
824
832
var nameRecord =
825
833
platforms[i] + // platform ID
826
834
encodings[i] + // encoding ID
@@ -833,7 +841,8 @@ var Font = (function () {
833
841
}
834
842
}
835
843
836
- return nameTable + strings.join(" ") + stringsUnicode.join(" ");
844
+ nameTable += strings.join(" ") + stringsUnicode.join(" ");
845
+ return nameTable;
837
846
}
838
847
839
848
// Required Tables
@@ -870,13 +879,13 @@ var Font = (function () {
870
879
871
880
/** CMAP */
872
881
var charstrings = font.charstrings;
873
- cmap = createCMapTable(charstrings);
882
+ cmap = createCMapTable(charstrings.slice() );
874
883
createTableEntry(otf, offsets, " cmap ", cmap);
875
884
876
885
/** HEAD */
877
886
head = stringToArray(
878
887
" \x00 \x01 \x00 \x00 " + // Version number
879
- " \x00 \x00 \x50 \x00 " + // fontRevision
888
+ " \x00 \x00 \x10 \x00 " + // fontRevision
880
889
" \x00 \x00 \x00 \x00 " + // checksumAdjustement
881
890
" \x5F \x0F \x3C \xF5 " + // magicNumber
882
891
" \x00 \x00 " + // Flags
@@ -923,7 +932,7 @@ var Font = (function () {
923
932
* while Windows use this data. So be careful if you hack on Linux and
924
933
* have to touch the 'hmtx' table
925
934
*/
926
- hmtx = " \x00 \x8B \x00 \x00 "; // Fake .notdef
935
+ hmtx = " \x00 \x00 \x00 \x00 "; // Fake .notdef
927
936
var width = 0 , lsb = 0 ;
928
937
for (var i = 0 ; i < charstrings .length ; i ++) {
929
938
var charstring = charstrings [i ];
0 commit comments