@@ -8,6 +8,8 @@ import {readData} from '../data';
8
8
import TTFReader from 'fonteditor-core/ttf/ttfreader' ;
9
9
import ttf2woff from 'fonteditor-core/ttf/ttf2woff' ;
10
10
import woff2ttf from 'fonteditor-core/ttf/woff2ttf' ;
11
+ import pako from 'pako' ;
12
+ import { fstat } from 'fs' ;
11
13
12
14
describe ( 'ttf 转 woff' , function ( ) {
13
15
@@ -48,3 +50,49 @@ describe('ttf 转 woff', function () {
48
50
assert . equal ( ttf . cmap [ 57400 ] , 16 ) ;
49
51
} ) ;
50
52
} ) ;
53
+
54
+
55
+ describe ( 'ttf 转 woff with deflate' , function ( ) {
56
+
57
+ let woffBuffer = ttf2woff ( readData ( 'baiduHealth.ttf' ) , {
58
+ deflate : pako . deflate
59
+ } ) ;
60
+
61
+ it ( 'test woff format' , function ( ) {
62
+ assert . ok ( woffBuffer . byteLength > 1000 ) ;
63
+ assert . ok ( woffBuffer . byteLength < 10000 ) ;
64
+ } ) ;
65
+ require ( 'fs' ) . writeFileSync ( 'baiduHealth-deflate.woff' , Buffer . from ( woffBuffer ) ) ;
66
+ it ( 'test read woff' , function ( ) {
67
+ let ttfBuffer = woff2ttf ( woffBuffer , {
68
+ inflate : pako . inflate
69
+ } ) ;
70
+ let ttf = new TTFReader ( ) . read ( ttfBuffer ) ;
71
+
72
+ assert . equal ( ttf . version , 1 ) ;
73
+
74
+ assert . equal ( ttf . head . magickNumber , 1594834165 ) ;
75
+ assert . equal ( ttf . head . unitsPerEm , 512 ) ;
76
+
77
+ assert . equal ( ttf . post . format , 2 ) ;
78
+ assert . equal ( ttf . post . underlinePosition , 0 ) ;
79
+ assert . equal ( ttf . post . underlineThickness , 0 ) ;
80
+
81
+ assert . equal ( ttf . hhea . advanceWidthMax , 682 ) ;
82
+ assert . equal ( ttf . hhea . ascent , 480 ) ;
83
+ assert . equal ( ttf . hhea . descent , - 33 ) ;
84
+
85
+ assert . equal ( ttf . maxp . version , 1 ) ;
86
+ assert . equal ( ttf . maxp . numGlyphs , 17 ) ;
87
+
88
+ assert . equal ( ttf . glyf [ 0 ] . advanceWidth , 512 ) ;
89
+ assert . equal ( ttf . glyf [ 0 ] . leftSideBearing , 0 ) ;
90
+ assert . equal ( ttf . glyf [ 0 ] . name , '.notdef' ) ;
91
+ assert . equal ( ttf . glyf [ 3 ] . contours [ 0 ] . length , 31 ) ;
92
+ assert . equal ( ttf . glyf [ 16 ] . compound , true ) ;
93
+ assert . equal ( ttf . glyf [ 16 ] . glyfs . length , 2 ) ;
94
+
95
+ assert . equal ( ttf . cmap [ 0 ] , 1 ) ;
96
+ assert . equal ( ttf . cmap [ 57400 ] , 16 ) ;
97
+ } ) ;
98
+ } ) ;
0 commit comments