@@ -299,6 +299,7 @@ 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" );
302
303
break ;
303
304
304
305
case "TrueType" :
@@ -485,9 +486,9 @@ var Font = (function () {
485
486
486
487
for (var i = 1 ; i < charset .length ; i ++) {
487
488
var code = GlyphsUnicode [charset [i ]];
488
- if (code < firstCharIndex || !firstCharIndex )
489
+ if (firstCharIndex > code || !firstCharIndex )
489
490
firstCharIndex = code ;
490
- if (code > lastCharIndex )
491
+ if (lastCharIndex < code )
491
492
lastCharIndex = code ;
492
493
493
494
var position = getUnicodeRangeFor (code );
@@ -509,7 +510,7 @@ var Font = (function () {
509
510
"\x02 \x24 " + // xAvgCharWidth
510
511
"\x01 \xF4 " + // usWeightClass
511
512
"\x00 \x05 " + // usWidthClass
512
- "\x00 \x00 " + // fstype
513
+ "\x00 \x02 " + // fstype
513
514
"\x02 \x8A " + // ySubscriptXSize
514
515
"\x02 \xBB " + // ySubscriptYSize
515
516
"\x00 \x00 " + // ySubscriptXOffset
@@ -521,41 +522,41 @@ var Font = (function () {
521
522
"\x00 \x31 " + // yStrikeOutSize
522
523
"\x01 \x02 " + // yStrikeOutPosition
523
524
"\x00 \x00 " + // sFamilyClass
524
- "\x02 \x00 \x06 \x03 \x00 \x00 \x00 \x00 \x00 \x00 " + // Panose
525
+ "\x00 \x00 \x06 " + String .fromCharCode (properties .fixedPitch ? 0x09 : 0x00 ) +
526
+ "\x00 \x00 \x00 \x00 \x00 \x00 " + // Panose
525
527
string32 (ulUnicodeRange1 ) + // ulUnicodeRange1 (Bits 0-31)
526
528
string32 (ulUnicodeRange2 ) + // ulUnicodeRange2 (Bits 32-63)
527
529
string32 (ulUnicodeRange3 ) + // ulUnicodeRange3 (Bits 64-95)
528
530
string32 (ulUnicodeRange4 ) + // ulUnicodeRange4 (Bits 96-127)
529
531
"\x2A \x32 \x31 \x2A " + // achVendID
530
- " \x00 \x00 " + // fsSelection
532
+ string16 ( properties . italicAngle ? 1 : 0 ) + // fsSelection
531
533
string16 (firstCharIndex || properties .firstChar ) + // usFirstCharIndex
532
534
string16 (lastCharIndex || properties .lastChar ) + // usLastCharIndex
533
- " \x00 \x20 " + // sTypoAscender
534
- " \x00 \x00 " + // sTypeDescender
535
- "\x00 \x00 " + // sTypoLineGap
535
+ string16 ( properties . ascent ) + // sTypoAscender
536
+ string16 ( properties . descent ) + // sTypoDescender
537
+ "\x00 \x64 " + // sTypoLineGap (7%-10% of the unitsPerEM value)
536
538
string16 (properties .ascent ) + // usWinAscent
537
- string16 (properties .descent ) + // usWinDescent
539
+ string16 (- properties .descent ) + // usWinDescent
538
540
"\x00 \x00 \x00 \x00 " + // ulCodePageRange1 (Bits 0-31)
539
541
"\x00 \x00 \x00 \x00 " + // ulCodePageRange2 (Bits 32-63)
540
542
string16 (properties .xHeight ) + // sxHeight
541
543
string16 (properties .capHeight ) + // sCapHeight
542
544
string16 (0 ) + // usDefaultChar
543
545
string16 (firstCharIndex || properties .firstChar ) + // usBreakChar
544
- "\x00 \x00 " ; // usMaxContext
546
+ "\x00 \x03 " ; // usMaxContext
545
547
};
546
548
547
549
function createPostTable (properties ) {
548
- TODO ("Fill with real values from the font dict" );
549
-
550
- return "\x00 \x03 \x00 \x00 " + // Version number
551
- string32 (properties .italicAngle ) + // italicAngle
552
- "\x00 \x00 " + // underlinePosition
553
- "\x00 \x00 " + // underlineThickness
554
- "\x00 \x00 \x00 \x00 " + // isFixedPitch
555
- "\x00 \x00 \x00 \x00 " + // minMemType42
556
- "\x00 \x00 \x00 \x00 " + // maxMemType42
557
- "\x00 \x00 \x00 \x00 " + // minMemType1
558
- "\x00 \x00 \x00 \x00 " ; // maxMemType1
550
+ var angle = Math .floor (properties .italicAngle * (Math .pow (2 , 16 )));
551
+ return "\x00 \x03 \x00 \x00 " + // Version number
552
+ string32 (angle ) + // italicAngle
553
+ "\x00 \x00 " + // underlinePosition
554
+ "\x00 \x00 " + // underlineThickness
555
+ string32 (properties .fixedPitch ) + // isFixedPitch
556
+ "\x00 \x00 \x00 \x00 " + // minMemType42
557
+ "\x00 \x00 \x00 \x00 " + // maxMemType42
558
+ "\x00 \x00 \x00 \x00 " + // minMemType1
559
+ "\x00 \x00 \x00 \x00 " ; // maxMemType1
559
560
};
560
561
561
562
constructor .prototype = {
@@ -844,6 +845,14 @@ var Font = (function () {
844
845
nameTable += strings.join(" ") + stringsUnicode.join(" ");
845
846
return nameTable;
846
847
}
848
+
849
+ function isFixedPitch(glyphs) {
850
+ for (var i = 0; i < glyphs.length - 1; i++) {
851
+ if (glyphs[i] != glyphs[i+1])
852
+ return false;
853
+ }
854
+ return true;
855
+ };
847
856
848
857
// Required Tables
849
858
var CFF =
@@ -874,11 +883,12 @@ var Font = (function () {
874
883
createTableEntry(otf, offsets, " CFF ", CFF);
875
884
876
885
/** OS/2 */
886
+ var charstrings = font.charstrings;
887
+ properties.fixedPitch = isFixedPitch(charstrings);
877
888
OS2 = stringToArray(createOS2Table(properties));
878
889
createTableEntry(otf, offsets, " OS /2 ", OS2);
879
890
880
891
/** CMAP */
881
- var charstrings = font.charstrings;
882
892
cmap = createCMapTable(charstrings.slice());
883
893
createTableEntry(otf, offsets, " cmap ", cmap);
884
894
@@ -893,10 +903,10 @@ var Font = (function () {
893
903
" \x00 \x00 \x00 \x00 \x9e \x0b \x7e \x27 " + // creation date
894
904
" \x00 \x00 \x00 \x00 \x9e \x0b \x7e \x27 " + // modifification date
895
905
" \x00 \x00 " + // xMin
896
- " \x00 \x00 " + // yMin
897
- " \x00 \x00 " + // xMax
898
- " \x00 \x00 " + // yMax
899
- string16(properties.italicAngle ? 1 : 0) + // macStyle
906
+ string16(properties.descent) + // yMin
907
+ " \x0F \xFF " + // xMax
908
+ string16(properties.ascent) + // yMax
909
+ string16(properties.italicAngle ? 2 : 0) + // macStyle
900
910
" \x00 \x11 " + // lowestRecPPEM
901
911
" \x00 \x00 " + // fontDirectionHint
902
912
" \x00 \x00 " + // indexToLocFormat
@@ -910,12 +920,12 @@ var Font = (function () {
910
920
string16(properties.ascent) + // Typographic Ascent
911
921
string16(properties.descent) + // Typographic Descent
912
922
" \x00 \x00 " + // Line Gap
913
- " \xFF \xFF " + // advanceWidthMax
923
+ " \x00 \xFF " + // advanceWidthMax
914
924
" \x00 \x00 " + // minLeftSidebearing
915
925
" \x00 \x00 " + // minRightSidebearing
916
926
" \x00 \x00 " + // xMaxExtent
917
- " \x00 \x00 " + // caretSlopeRise
918
- string16(properties.italicAngle) + // caretSlopeRun
927
+ string16(properties.capHeight) + // caretSlopeRise
928
+ string16(Math.tan( properties.italicAngle) * properties.xHeight ) + // caretSlopeRun
919
929
" \x00 \x00 " + // caretOffset
920
930
" \x00 \x00 " + // -reserved-
921
931
" \x00 \x00 " + // -reserved-
@@ -933,10 +943,8 @@ var Font = (function () {
933
943
* have to touch the 'hmtx' table
934
944
*/
935
945
hmtx = " \x00 \x00 \x00 \x00 "; // Fake .notdef
936
- var width = 0 , lsb = 0 ;
937
946
for (var i = 0 ; i < charstrings .length ; i ++) {
938
- var charstring = charstrings [i ];
939
- hmtx += string16 (charstring .width ) + string16 (0 );
947
+ hmtx += string16 (charstrings [i ].width ) + string16 (0 );
940
948
}
941
949
hmtx = stringToArray (hmtx );
942
950
createTableEntry (otf , offsets , "hmtx" , hmtx );
0 commit comments