11var Glyph = {
2+ glyphs : [ ] ,
23 ratio : null ,
34 head : null ,
45 os2 : null ,
5- hmtx : null ,
6-
7- midValue : function ( a , b ) {
8- return a + ( b - a ) / 2 ;
9- } ,
6+ hmtx : null ,
7+ width : null ,
8+ height : null ,
9+ scale : 1.0 ,
1010
1111 splitPath : function ( path ) {
1212 return path . match ( / ( [ a - z ] ) | ( - ? \d + (?: \. \d + ) ? ) / ig) ;
@@ -60,7 +60,6 @@ var Glyph = {
6060 return ;
6161 }
6262
63-
6463 var contour , path , transform ;
6564
6665 for ( var ci = 0 , cl = contours . length ; ci < cl ; ci ++ ) {
@@ -88,14 +87,16 @@ var Glyph = {
8887 var element = canvas [ 0 ] ;
8988 var ctx = element . getContext ( "2d" ) ;
9089 var ratio = Glyph . ratio ;
91- Glyph . width = element . width ;
92- Glyph . height = element . height ;
93-
94- ctx . lineWidth = ratio ;
90+ var width = Glyph . width * Glyph . scale ;
91+ var height = Glyph . height * Glyph . scale ;
92+ ctx . clearRect ( 0 , 0 , width , height ) ;
93+
94+ ctx . lineWidth = ratio / Glyph . scale ;
9595
9696 // Invert axis
97- ctx . translate ( 0 , Glyph . height ) ;
97+ ctx . translate ( 0 , height ) ;
9898 ctx . scale ( 1 / ratio , - ( 1 / ratio ) ) ;
99+ ctx . scale ( Glyph . scale , Glyph . scale ) ;
99100
100101 ctx . translate ( 0 , - Glyph . head . yMin ) ;
101102
@@ -114,7 +115,7 @@ var Glyph = {
114115 var s = ratio * 3 ;
115116
116117 ctx . strokeStyle = "rgba(0,0,0,0.5)" ;
117- ctx . lineWidth = ratio * 1.5 ;
118+ ctx . lineWidth = ( ratio * 1.5 ) / Glyph . scale ;
118119
119120 // origin
120121 ctx . beginPath ( ) ;
@@ -151,5 +152,24 @@ var Glyph = {
151152 //ctx.globalCompositeOperation = "xor";
152153
153154 Glyph . drawSVGContours ( ctx , shape . SVGContours ) ;
155+ } ,
156+ drawAll : function ( ) {
157+ $ . each ( Glyph . glyphs , function ( i , g ) {
158+ Glyph . draw ( $ ( '#glyph-' + g [ 0 ] ) , g [ 1 ] , g [ 0 ] ) ;
159+ } ) ;
160+ } ,
161+ resize : function ( value ) {
162+ Glyph . scale = value / 100 ;
163+
164+ $ . each ( document . getElementsByTagName ( 'canvas' ) , function ( i , canvas ) {
165+ canvas . height = Glyph . height * Glyph . scale ;
166+ canvas . width = Glyph . width * Glyph . scale ;
167+ } ) ;
168+
169+ Glyph . drawAll ( ) ;
154170 }
155- } ;
171+ } ;
172+
173+ $ ( function ( ) {
174+ Glyph . drawAll ( ) ;
175+ } ) ;
0 commit comments