ÿþ/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *  
  
 t y p e f a c e . j s ,   v e r s i o n   0 . 1 5   |   t y p e f a c e j s . n e o c r a c y . o r g  
  
 C o p y r i g h t   ( c )   2 0 0 8   -   2 0 0 9 ,   D a v i d   C h e s t e r   d a v i d c h e s t e r @ g m x . n e t    
  
 P e r m i s s i o n   i s   h e r e b y   g r a n t e d ,   f r e e   o f   c h a r g e ,   t o   a n y   p e r s o n  
 o b t a i n i n g   a   c o p y   o f   t h i s   s o f t w a r e   a n d   a s s o c i a t e d   d o c u m e n t a t i o n  
 f i l e s   ( t h e   " S o f t w a r e " ) ,   t o   d e a l   i n   t h e   S o f t w a r e   w i t h o u t  
 r e s t r i c t i o n ,   i n c l u d i n g   w i t h o u t   l i m i t a t i o n   t h e   r i g h t s   t o   u s e ,  
 c o p y ,   m o d i f y ,   m e r g e ,   p u b l i s h ,   d i s t r i b u t e ,   s u b l i c e n s e ,   a n d / o r   s e l l  
 c o p i e s   o f   t h e   S o f t w a r e ,   a n d   t o   p e r m i t   p e r s o n s   t o   w h o m   t h e  
 S o f t w a r e   i s   f u r n i s h e d   t o   d o   s o ,   s u b j e c t   t o   t h e   f o l l o w i n g  
 c o n d i t i o n s :  
  
 T h e   a b o v e   c o p y r i g h t   n o t i c e   a n d   t h i s   p e r m i s s i o n   n o t i c e   s h a l l   b e  
 i n c l u d e d   i n   a l l   c o p i e s   o r   s u b s t a n t i a l   p o r t i o n s   o f   t h e   S o f t w a r e .  
  
 T H E   S O F T W A R E   I S   P R O V I D E D   " A S   I S " ,   W I T H O U T   W A R R A N T Y   O F   A N Y   K I N D ,  
 E X P R E S S   O R   I M P L I E D ,   I N C L U D I N G   B U T   N O T   L I M I T E D   T O   T H E   W A R R A N T I E S  
 O F   M E R C H A N T A B I L I T Y ,   F I T N E S S   F O R   A   P A R T I C U L A R   P U R P O S E   A N D  
 N O N I N F R I N G E M E N T .   I N   N O   E V E N T   S H A L L   T H E   A U T H O R S   O R   C O P Y R I G H T  
 H O L D E R S   B E   L I A B L E   F O R   A N Y   C L A I M ,   D A M A G E S   O R   O T H E R   L I A B I L I T Y ,  
 W H E T H E R   I N   A N   A C T I O N   O F   C O N T R A C T ,   T O R T   O R   O T H E R W I S E ,   A R I S I N G  
 F R O M ,   O U T   O F   O R   I N   C O N N E C T I O N   W I T H   T H E   S O F T W A R E   O R   T H E   U S E   O R  
 O T H E R   D E A L I N G S   I N   T H E   S O F T W A R E .  
  
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /  
  
 ( f u n c t i o n ( )   {  
  
 v a r   _ t y p e f a c e _ j s   =   {  
  
 	 f a c e s :   { } ,  
  
 	 l o a d F a c e :   f u n c t i o n ( t y p e f a c e D a t a )   {  
  
 	 	 v a r   f a m i l y N a m e   =   t y p e f a c e D a t a . f a m i l y N a m e . t o L o w e r C a s e ( ) ;  
 	 	  
 	 	 i f   ( ! t h i s . f a c e s [ f a m i l y N a m e ] )   {  
 	 	 	 t h i s . f a c e s [ f a m i l y N a m e ]   =   { } ;  
 	 	 }  
 	 	 i f   ( ! t h i s . f a c e s [ f a m i l y N a m e ] [ t y p e f a c e D a t a . c s s F o n t W e i g h t ] )   {  
 	 	 	 t h i s . f a c e s [ f a m i l y N a m e ] [ t y p e f a c e D a t a . c s s F o n t W e i g h t ]   =   { } ;  
 	 	 }  
  
 	 	 v a r   f a c e   =   t h i s . f a c e s [ f a m i l y N a m e ] [ t y p e f a c e D a t a . c s s F o n t W e i g h t ] [ t y p e f a c e D a t a . c s s F o n t S t y l e ]   =   t y p e f a c e D a t a ;  
 	 	 f a c e . l o a d e d   =   t r u e ;  
 	 } ,  
  
 	 l o g :   f u n c t i o n ( m e s s a g e )   {  
 	 	  
 	 	 i f   ( t h i s . q u i e t )   {  
 	 	 	 r e t u r n ;  
 	 	 }  
 	 	  
 	 	 m e s s a g e   =   " t y p e f a c e . j s :   "   +   m e s s a g e ;  
 	 	  
 	 	 i f   ( t h i s . c u s t o m L o g F n )   {  
 	 	 	 t h i s . c u s t o m L o g F n ( m e s s a g e ) ;  
  
 	 	 }   e l s e   i f   ( w i n d o w . c o n s o l e   & &   w i n d o w . c o n s o l e . l o g )   {  
 	 	 	 w i n d o w . c o n s o l e . l o g ( m e s s a g e ) ;  
 	 	 }  
 	 	  
 	 } ,  
 	  
 	 p i x e l s F r o m P o i n t s :   f u n c t i o n ( f a c e ,   s t y l e ,   p o i n t s ,   d i m e n s i o n )   {  
 	 	 v a r   p i x e l s   =   p o i n t s   *   p a r s e I n t ( s t y l e . f o n t S i z e )   *   7 2   /   ( f a c e . r e s o l u t i o n   *   1 0 0 ) ;  
 	 	 i f   ( d i m e n s i o n   = =   ' h o r i z o n t a l '   & &   s t y l e . f o n t S t r e t c h P e r c e n t )   {  
 	 	 	 p i x e l s   * =   s t y l e . f o n t S t r e t c h P e r c e n t ;  
 	 	 }  
 	 	 r e t u r n   p i x e l s ;  
 	 } ,  
  
 	 p o i n t s F r o m P i x e l s :   f u n c t i o n ( f a c e ,   s t y l e ,   p i x e l s ,   d i m e n s i o n )   {  
 	 	 v a r   p o i n t s   =   p i x e l s   *   f a c e . r e s o l u t i o n   /   ( p a r s e I n t ( s t y l e . f o n t S i z e )   *   7 2   /   1 0 0 ) ;  
 	 	 i f   ( d i m e n s i o n   = =   ' h o r i z o n t a l '   & &   s t y l e . f o n t S t r e t c h P r e c e n t )   {  
 	 	 	 p o i n t s   * =   s t y l e . f o n t S t r e t c h P e r c e n t ;  
 	 	 }  
 	 	 r e t u r n   p o i n t s ;  
 	 } ,  
  
 	 c s s F o n t W e i g h t M a p :   {  
 	 	 n o r m a l :   ' n o r m a l ' ,  
 	 	 b o l d :   ' b o l d ' ,  
 	 	 4 0 0 :   ' n o r m a l ' ,  
 	 	 7 0 0 :   ' b o l d '  
 	 } ,  
  
 	 c s s F o n t S t r e t c h M a p :   {  
 	 	 ' u l t r a - c o n d e n s e d ' :   0 . 5 5 ,  
 	 	 ' e x t r a - c o n d e n s e d ' :   0 . 7 7 ,  
 	 	 ' c o n d e n s e d ' :   0 . 8 5 ,  
 	 	 ' s e m i - c o n d e n s e d ' :   0 . 9 3 ,  
 	 	 ' n o r m a l ' :   1 ,  
 	 	 ' s e m i - e x p a n d e d ' :   1 . 0 7 ,  
 	 	 ' e x p a n d e d ' :   1 . 1 5 ,  
 	 	 ' e x t r a - e x p a n d e d ' :   1 . 2 3 ,  
 	 	 ' u l t r a - e x p a n d e d ' :   1 . 4 5 ,  
 	 	 ' d e f a u l t ' :   1  
 	 } ,  
 	  
 	 f a l l b a c k C h a r a c t e r :   ' . ' ,  
  
 	 c o n f i g u r e :   f u n c t i o n ( a r g s )   {  
 	 	 v a r   c o n f i g u r a b l e O p t i o n N a m e s   =   [   ' c u s t o m L o g F n ' ,     ' c u s t o m C l a s s N a m e R e g e x ' ,   ' c u s t o m T y p e f a c e E l e m e n t s L i s t ' ,   ' q u i e t ' ,   ' v e r b o s e ' ,   ' d i s a b l e S e l e c t i o n '   ] ;  
 	 	  
 	 	 f o r   ( v a r   i   =   0 ;   i   <   c o n f i g u r a b l e O p t i o n N a m e s . l e n g t h ;   i + + )   {  
 	 	 	 v a r   o p t i o n N a m e   =   c o n f i g u r a b l e O p t i o n N a m e s [ i ] ;  
 	 	 	 i f   ( a r g s [ o p t i o n N a m e ] )   {  
 	 	 	 	 i f   ( o p t i o n N a m e   = =   ' c u s t o m L o g F n ' )   {  
 	 	 	 	 	 i f   ( t y p e o f   a r g s [ o p t i o n N a m e ]   ! =   ' f u n c t i o n ' )   {  
 	 	 	 	 	 	 t h r o w   " c u s t o m L o g F n   i s   n o t   a   f u n c t i o n " ;  
 	 	 	 	 	 }   e l s e   {  
 	 	 	 	 	 	 t h i s . c u s t o m L o g F n   =   a r g s . c u s t o m L o g F n ;  
 	 	 	 	 	 }  
 	 	 	 	 }   e l s e   {  
 	 	 	 	 	 t h i s [ o p t i o n N a m e ]   =   a r g s [ o p t i o n N a m e ] ;  
 	 	 	 	 }  
 	 	 	 }  
 	 	 }  
 	 } ,  
  
 	 g e t T e x t E x t e n t s :   f u n c t i o n ( f a c e ,   s t y l e ,   t e x t )   {  
 	 	 v a r   e x t e n t X   =   0 ;  
 	 	 v a r   e x t e n t Y   =   0 ;  
 	 	 v a r   h o r i z o n t a l A d v a n c e ;  
 	  
 	 	 v a r   t e x t L e n g t h   =   t e x t . l e n g t h ;  
 	 	 f o r   ( v a r   i   =   0 ;   i   <   t e x t L e n g t h ;   i + + )   {  
 	 	 	 v a r   g l y p h   =   f a c e . g l y p h s [ t e x t . c h a r A t ( i ) ]   ?   f a c e . g l y p h s [ t e x t . c h a r A t ( i ) ]   :   f a c e . g l y p h s [ t h i s . f a l l b a c k C h a r a c t e r ] ;  
 	 	 	 v a r   l e t t e r S p a c i n g A d j u s t m e n t   =   t h i s . p o i n t s F r o m P i x e l s ( f a c e ,   s t y l e ,   s t y l e . l e t t e r S p a c i n g ) ;  
  
 	 	 	 / /   i f   w e ' r e   o n   t h e   l a s t   c h a r a c t e r ,   g o   w i t h   t h e   g l y p h   e x t e n t   i f   t h a t ' s   m o r e   t h a n   t h e   h o r i z o n t a l   a d v a n c e  
 	 	 	 e x t e n t X   + =   i   +   1   = =   t e x t L e n g t h   ?   M a t h . m a x ( g l y p h . x _ m a x ,   g l y p h . h a )   :   g l y p h . h a ;  
 	 	 	 e x t e n t X   + =   l e t t e r S p a c i n g A d j u s t m e n t ;  
  
 	 	 	 h o r i z o n t a l A d v a n c e   + =   g l y p h . h a   +   l e t t e r S p a c i n g A d j u s t m e n t ;  
 	 	 }  
 	 	 r e t u r n   {    
 	 	 	 x :   e x t e n t X ,    
 	 	 	 y :   e x t e n t Y ,  
 	 	 	 h a :   h o r i z o n t a l A d v a n c e  
 	 	 	  
 	 	 } ;  
 	 } ,  
  
 	 p i x e l s F r o m C s s A m o u n t :   f u n c t i o n ( c s s A m o u n t ,   d e f a u l t V a l u e ,   e l e m e n t )   {  
  
 	 	 v a r   m a t c h e s   =   u n d e f i n e d ;  
  
 	 	 i f   ( c s s A m o u n t   = =   ' n o r m a l ' )   {  
 	 	 	 r e t u r n   d e f a u l t V a l u e ;  
  
 	 	 }   e l s e   i f   ( m a t c h e s   =   c s s A m o u n t . m a t c h ( / ( [ \ - \ d + \ . ] + ) p x / ) )   {  
 	 	 	 r e t u r n   m a t c h e s [ 1 ] ;  
  
 	 	 }   e l s e   {  
 	 	 	 / /   t h a n k s   t o   D e a n   E d w a r d s   f o r   t h i s   v e r y   s n e a k y   w a y   t o   g e t   I E   t o   c o n v e r t    
 	 	 	 / /   r e l a t i v e   v a l u e s   t o   p i x e l   v a l u e s  
 	 	 	  
 	 	 	 v a r   p i x e l A m o u n t ;  
 	 	 	  
 	 	 	 v a r   l e f t I n l i n e S t y l e   =   e l e m e n t . s t y l e . l e f t ;  
 	 	 	 v a r   l e f t R u n t i m e S t y l e   =   e l e m e n t . r u n t i m e S t y l e . l e f t ;  
  
 	 	 	 e l e m e n t . r u n t i m e S t y l e . l e f t   =   e l e m e n t . c u r r e n t S t y l e . l e f t ;  
  
 	 	 	 i f   ( ! c s s A m o u n t . m a t c h ( / \ d ( p x | p t ) $ / ) )   {  
 	 	 	 	 e l e m e n t . s t y l e . l e f t   =   ' 1 e m ' ;  
 	 	 	 }   e l s e   {  
 	 	 	 	 e l e m e n t . s t y l e . l e f t   =   c s s A m o u n t   | |   0 ;  
 	 	 	 }  
  
 	 	 	 p i x e l A m o u n t   =   e l e m e n t . s t y l e . p i x e l L e f t ;  
 	 	  
 	 	 	 e l e m e n t . s t y l e . l e f t   =   l e f t I n l i n e S t y l e ;  
 	 	 	 e l e m e n t . r u n t i m e S t y l e . l e f t   =   l e f t R u n t i m e S t y l e ;  
 	 	 	  
 	 	 	 r e t u r n   p i x e l A m o u n t   | |   d e f a u l t V a l u e ;  
 	 	 }  
 	 } ,  
  
 	 c a p i t a l i z e T e x t :   f u n c t i o n ( t e x t )   {  
 	 	 r e t u r n   t e x t . r e p l a c e ( / ( ^ | \ s ) [ a - z ] / g ,   f u n c t i o n ( m a t c h )   {   r e t u r n   m a t c h . t o U p p e r C a s e ( )   }   ) ;    
 	 } ,  
  
 	 g e t E l e m e n t S t y l e :   f u n c t i o n ( e )   {  
 	 	 i f   ( w i n d o w . g e t C o m p u t e d S t y l e )   {  
 	 	 	 r e t u r n   w i n d o w . g e t C o m p u t e d S t y l e ( e ,   ' ' ) ;  
 	 	  
 	 	 }   e l s e   i f   ( e . c u r r e n t S t y l e )   {  
 	 	 	 r e t u r n   e . c u r r e n t S t y l e ;  
 	 	 }  
 	 } ,  
  
 	 g e t R e n d e r e d T e x t :   f u n c t i o n ( e )   {  
  
 	 	 v a r   b r o w s e r S t y l e   =   t h i s . g e t E l e m e n t S t y l e ( e . p a r e n t N o d e ) ;  
  
 	 	 v a r   i n l i n e S t y l e A t t r i b u t e   =   e . p a r e n t N o d e . g e t A t t r i b u t e ( ' s t y l e ' ) ;  
 	 	 i f   ( i n l i n e S t y l e A t t r i b u t e   & &   t y p e o f ( i n l i n e S t y l e A t t r i b u t e )   = =   ' o b j e c t ' )   {  
 	 	 	 i n l i n e S t y l e A t t r i b u t e   =   i n l i n e S t y l e A t t r i b u t e . c s s T e x t ;  
 	 	 }  
  
 	 	 i f   ( i n l i n e S t y l e A t t r i b u t e )   {  
  
 	 	 	 v a r   i n l i n e S t y l e D e c l a r a t i o n s   =   i n l i n e S t y l e A t t r i b u t e . s p l i t ( / \ s * \ ; \ s * / ) ;  
  
 	 	 	 v a r   i n l i n e S t y l e   =   { } ;  
 	 	 	 f o r   ( v a r   i   =   0 ;   i   <   i n l i n e S t y l e D e c l a r a t i o n s . l e n g t h ;   i + + )   {  
 	 	 	 	 v a r   d e c l a r a t i o n   =   i n l i n e S t y l e D e c l a r a t i o n s [ i ] ;  
 	 	 	 	 v a r   d e c l a r a t i o n O p e r a n d s   =   d e c l a r a t i o n . s p l i t ( / \ s * \ : \ s * / ) ;  
 	 	 	 	 i n l i n e S t y l e [ d e c l a r a t i o n O p e r a n d s [ 0 ] ]   =   d e c l a r a t i o n O p e r a n d s [ 1 ] ;  
 	 	 	 }  
 	 	 }  
  
 	 	 v a r   s t y l e   =   {    
 	 	 	 c o l o r :   b r o w s e r S t y l e . c o l o r ,    
 	 	 	 f o n t F a m i l y :   b r o w s e r S t y l e . f o n t F a m i l y . s p l i t ( / \ s * , \ s * / ) [ 0 ] . r e p l a c e ( / ( ^ " | ^ ' | ' $ | " $ ) / g ,   ' ' ) . t o L o w e r C a s e ( ) ,    
 	 	 	 f o n t S i z e :   t h i s . p i x e l s F r o m C s s A m o u n t ( b r o w s e r S t y l e . f o n t S i z e ,   1 2 ,   e . p a r e n t N o d e ) ,  
 	 	 	 f o n t W e i g h t :   t h i s . c s s F o n t W e i g h t M a p [ b r o w s e r S t y l e . f o n t W e i g h t ] ,  
 	 	 	 f o n t S t y l e :   b r o w s e r S t y l e . f o n t S t y l e   ?   b r o w s e r S t y l e . f o n t S t y l e   :   ' n o r m a l ' ,  
 	 	 	 f o n t S t r e t c h P e r c e n t :   t h i s . c s s F o n t S t r e t c h M a p [ i n l i n e S t y l e   & &   i n l i n e S t y l e [ ' f o n t - s t r e t c h ' ]   ?   i n l i n e S t y l e [ ' f o n t - s t r e t c h ' ]   :   ' d e f a u l t ' ] ,  
 	 	 	 t e x t D e c o r a t i o n :   b r o w s e r S t y l e . t e x t D e c o r a t i o n ,  
 	 	 	 l i n e H e i g h t :   t h i s . p i x e l s F r o m C s s A m o u n t ( b r o w s e r S t y l e . l i n e H e i g h t ,   ' n o r m a l ' ,   e . p a r e n t N o d e ) ,  
 	 	 	 l e t t e r S p a c i n g :   t h i s . p i x e l s F r o m C s s A m o u n t ( b r o w s e r S t y l e . l e t t e r S p a c i n g ,   0 ,   e . p a r e n t N o d e ) ,  
 	 	 	 t e x t T r a n s f o r m :   b r o w s e r S t y l e . t e x t T r a n s f o r m  
 	 	 } ;  
  
 	 	 v a r   f a c e ;  
 	 	 i f   (  
 	 	 	 t h i s . f a c e s [ s t y l e . f o n t F a m i l y ]      
 	 	 	 & &   t h i s . f a c e s [ s t y l e . f o n t F a m i l y ] [ s t y l e . f o n t W e i g h t ]  
 	 	 )   {  
 	 	 	 f a c e   =   t h i s . f a c e s [ s t y l e . f o n t F a m i l y ] [ s t y l e . f o n t W e i g h t ] [ s t y l e . f o n t S t y l e ] ;  
 	 	 }  
  
 	 	 v a r   t e x t   =   e . n o d e V a l u e ;  
 	 	  
 	 	 i f   (  
 	 	 	 e . p r e v i o u s S i b l i n g    
 	 	 	 & &   e . p r e v i o u s S i b l i n g . n o d e T y p e   = =   1    
 	 	 	 & &   e . p r e v i o u s S i b l i n g . t a g N a m e   ! =   ' B R '    
 	 	 	 & &   t h i s . g e t E l e m e n t S t y l e ( e . p r e v i o u s S i b l i n g ) . d i s p l a y . m a t c h ( / i n l i n e / )  
 	 	 )   {  
 	 	 	 t e x t   =   t e x t . r e p l a c e ( / ^ \ s + / ,   '   ' ) ;  
 	 	 }   e l s e   {  
 	 	 	 t e x t   =   t e x t . r e p l a c e ( / ^ \ s + / ,   ' ' ) ;  
 	 	 }  
 	 	  
 	 	 i f   (  
 	 	 	 e . n e x t S i b l i n g    
 	 	 	 & &   e . n e x t S i b l i n g . n o d e T y p e   = =   1    
 	 	 	 & &   e . n e x t S i b l i n g . t a g N a m e   ! =   ' B R '    
 	 	 	 & &   t h i s . g e t E l e m e n t S t y l e ( e . n e x t S i b l i n g ) . d i s p l a y . m a t c h ( / i n l i n e / )  
 	 	 )   {  
 	 	 	 t e x t   =   t e x t . r e p l a c e ( / \ s + $ / ,   '   ' ) ;  
 	 	 }   e l s e   {  
 	 	 	 t e x t   =   t e x t . r e p l a c e ( / \ s + $ / ,   ' ' ) ;  
 	 	 }  
 	 	  
 	 	 t e x t   =   t e x t . r e p l a c e ( / \ s + / g ,   '   ' ) ;  
 	  
 	 	 i f   ( s t y l e . t e x t T r a n s f o r m   & &   s t y l e . t e x t T r a n s f o r m   ! =   ' n o n e ' )   {  
 	 	 	 s w i t c h   ( s t y l e . t e x t T r a n s f o r m )   {  
 	 	 	 	 c a s e   ' c a p i t a l i z e ' :  
 	 	 	 	 	 t e x t   =   t h i s . c a p i t a l i z e T e x t ( t e x t ) ;  
 	 	 	 	 	 b r e a k ;  
 	 	 	 	 c a s e   ' u p p e r c a s e ' :  
 	 	 	 	 	 t e x t   =   t e x t . t o U p p e r C a s e ( ) ;  
 	 	 	 	 	 b r e a k ;  
 	 	 	 	 c a s e   ' l o w e r c a s e ' :  
 	 	 	 	 	 t e x t   =   t e x t . t o L o w e r C a s e ( ) ;  
 	 	 	 	 	 b r e a k ;  
 	 	 	 }  
 	 	 }  
  
 	 	 i f   ( ! f a c e )   {  
 	 	 	 v a r   e x c e r p t L e n g t h   =   1 2 ;  
 	 	 	 v a r   t e x t E x c e r p t   =   t e x t . s u b s t r i n g ( 0 ,   e x c e r p t L e n g t h ) ;  
 	 	 	 i f   ( t e x t . l e n g t h   >   e x c e r p t L e n g t h )   {  
 	 	 	 	 t e x t E x c e r p t   + =   ' . . . ' ;  
 	 	 	 }  
 	 	  
 	 	 	 v a r   f o n t D e s c r i p t i o n   =   s t y l e . f o n t F a m i l y ;  
 	 	 	 i f   ( s t y l e . f o n t W e i g h t   ! =   ' n o r m a l ' )   f o n t D e s c r i p t i o n   + =   '   '   +   s t y l e . f o n t W e i g h t ;  
 	 	 	 i f   ( s t y l e . f o n t S t y l e   ! =   ' n o r m a l ' )   f o n t D e s c r i p t i o n   + =   '   '   +   s t y l e . f o n t S t y l e ;  
 	 	  
 	 	 	 t h i s . l o g ( " c o u l d n ' t   f i n d   t y p e f a c e   f o n t :   "   +   f o n t D e s c r i p t i o n   +   '   f o r   t e x t   " '   +   t e x t E x c e r p t   +   ' " ' ) ;  
 	 	 	 r e t u r n ;  
 	 	 }  
 	  
 	 	 v a r   w o r d s   =   t e x t . s p l i t ( / \ b ( ? = \ w ) / ) ;  
  
 	 	 v a r   c o n t a i n e r S p a n   =   d o c u m e n t . c r e a t e E l e m e n t ( ' s p a n ' ) ;  
 	 	 c o n t a i n e r S p a n . c l a s s N a m e   =   ' t y p e f a c e - j s - v e c t o r - c o n t a i n e r ' ;  
 	 	  
 	 	 v a r   w o r d s L e n g t h   =   w o r d s . l e n g t h ;  
 	 	 f o r   ( v a r   i   =   0 ;   i   <   w o r d s L e n g t h ;   i + + )   {  
 	 	 	 v a r   w o r d   =   w o r d s [ i ] ;  
 	 	 	  
 	 	 	 v a r   v e c t o r   =   t h i s . r e n d e r W o r d ( f a c e ,   s t y l e ,   w o r d ) ;  
 	 	 	  
 	 	 	 i f   ( v e c t o r )   {  
 	 	 	 	 c o n t a i n e r S p a n . a p p e n d C h i l d ( v e c t o r . e l e m e n t ) ;  
  
 	 	 	 	 i f   ( ! t h i s . d i s a b l e S e l e c t i o n )   {  
 	 	 	 	 	 v a r   s e l e c t a b l e S p a n   =   d o c u m e n t . c r e a t e E l e m e n t ( ' s p a n ' ) ;  
 	 	 	 	 	 s e l e c t a b l e S p a n . c l a s s N a m e   =   ' t y p e f a c e - j s - s e l e c t e d - t e x t ' ;  
  
 	 	 	 	 	 v a r   w o r d N o d e   =   d o c u m e n t . c r e a t e T e x t N o d e ( w o r d ) ;  
 	 	 	 	 	 s e l e c t a b l e S p a n . a p p e n d C h i l d ( w o r d N o d e ) ;  
  
 	 	 	 	 	 i f   ( t h i s . v e c t o r B a c k e n d   ! =   ' v m l ' )   {  
 	 	 	 	 	 	 s e l e c t a b l e S p a n . s t y l e . m a r g i n L e f t   =   - 1   *   ( v e c t o r . w i d t h   +   1 )   +   ' p x ' ;  
 	 	 	 	 	 }  
 	 	 	 	 	 s e l e c t a b l e S p a n . t a r g e t W i d t h   =   v e c t o r . w i d t h ;  
 	 	 	 	 	 / / s e l e c t a b l e S p a n . s t y l e . l i n e H e i g h t   =   1   +   ' p x ' ;  
  
 	 	 	 	 	 i f   ( t h i s . v e c t o r B a c k e n d   = =   ' v m l ' )   {  
 	 	 	 	 	 	 v e c t o r . e l e m e n t . a p p e n d C h i l d ( s e l e c t a b l e S p a n ) ;  
 	 	 	 	 	 }   e l s e   {  
 	 	 	 	 	 	 c o n t a i n e r S p a n . a p p e n d C h i l d ( s e l e c t a b l e S p a n ) ;  
 	 	 	 	 	 }  
 	 	 	 	 }  
 	 	 	 }  
 	 	 }  
  
 	 	 r e t u r n   c o n t a i n e r S p a n ;  
 	 } ,  
  
 	 r e n d e r D o c u m e n t :   f u n c t i o n ( c a l l b a c k )   {    
 	 	  
 	 	 i f   ( ! c a l l b a c k )  
 	 	 	 c a l l b a c k   =   f u n c t i o n ( e )   {   e . s t y l e . v i s i b i l i t y   =   ' v i s i b l e '   } ;  
  
 	 	 v a r   e l e m e n t s   =   d o c u m e n t . g e t E l e m e n t s B y T a g N a m e ( ' * ' ) ;  
 	 	  
 	 	 v a r   e l e m e n t s L e n g t h   =   e l e m e n t s . l e n g t h ;  
 	 	 f o r   ( v a r   i   =   0 ;   i   <   e l e m e n t s . l e n g t h ;   i + + )   {  
 	 	 	 i f   ( e l e m e n t s [ i ] . c l a s s N a m e . m a t c h ( / ( ^ | \ s ) t y p e f a c e - j s ( \ s | $ ) / )   | |   e l e m e n t s [ i ] . t a g N a m e . m a t c h ( / ^ ( H 1 | H 2 | H 3 | H 4 | H 5 | H 6 ) $ / ) )   {  
 	 	 	 	 t h i s . r e p l a c e T e x t ( e l e m e n t s [ i ] ) ;  
 	 	 	 	 i f   ( t y p e o f   c a l l b a c k   = =   ' f u n c t i o n ' )   {  
 	 	 	 	 	 c a l l b a c k ( e l e m e n t s [ i ] ) ;  
 	 	 	 	 }  
 	 	 	 }  
 	 	 }  
  
 	 	 i f   ( t h i s . v e c t o r B a c k e n d   = =   ' v m l ' )   {  
 	 	 	 / /   l a m e l y   w o r k   a r o u n d   I E ' s   q u i r k y   l e a v i n g   o f f   f i n a l   d y n a m i c   s h a p e s  
 	 	 	 v a r   d u m m y S h a p e   =   d o c u m e n t . c r e a t e E l e m e n t ( ' v : s h a p e ' ) ;  
 	 	 	 d u m m y S h a p e . s t y l e . d i s p l a y   =   ' n o n e ' ;  
 	 	 	 d o c u m e n t . b o d y . a p p e n d C h i l d ( d u m m y S h a p e ) ;  
 	 	 }  
 	 } ,  
  
 	 r e p l a c e T e x t :   f u n c t i o n ( e )   {  
  
 	 	 v a r   c h i l d N o d e s   =   [ ] ;  
 	 	 v a r   c h i l d N o d e s L e n g t h   =   e . c h i l d N o d e s . l e n g t h ;  
  
 	 	 f o r   ( v a r   i   =   0 ;   i   <   c h i l d N o d e s L e n g t h ;   i + + )   {  
 	 	 	 t h i s . r e p l a c e T e x t ( e . c h i l d N o d e s [ i ] ) ;  
 	 	 }  
  
 	 	 i f   ( e . n o d e T y p e   = =   3   & &   e . n o d e V a l u e . m a t c h ( / \ S / ) )   {  
 	 	 	 v a r   p a r e n t N o d e   =   e . p a r e n t N o d e ;  
  
 	 	 	 i f   ( p a r e n t N o d e . c l a s s N a m e   = =   ' t y p e f a c e - j s - s e l e c t e d - t e x t ' )   {  
 	 	 	 	 r e t u r n ;  
 	 	 	 }  
  
 	 	 	 v a r   r e n d e r e d T e x t   =   t h i s . g e t R e n d e r e d T e x t ( e ) ;  
 	 	 	  
 	 	 	 i f   (  
 	 	 	 	 p a r e n t N o d e . t a g N a m e   = =   ' A '    
 	 	 	 	 & &   t h i s . v e c t o r B a c k e n d   = =   ' v m l '  
 	 	 	 	 & &   t h i s . g e t E l e m e n t S t y l e ( p a r e n t N o d e ) . d i s p l a y   = =   ' i n l i n e '  
 	 	 	 )   {  
 	 	 	 	 / /   s o m e t h i n g   o f   a   h a c k ,   u s e   i n l i n e - b l o c k   t o   g e t   I E   t o   a c c e p t   c l i c k s   i n   w h i t e s p a c e   r e g i o n s  
 	 	 	 	 p a r e n t N o d e . s t y l e . d i s p l a y   =   ' i n l i n e - b l o c k ' ;  
 	 	 	 	 p a r e n t N o d e . s t y l e . c u r s o r   =   ' p o i n t e r ' ;  
 	 	 	 }  
  
 	 	 	 i f   ( t h i s . g e t E l e m e n t S t y l e ( p a r e n t N o d e ) . d i s p l a y   = =   ' i n l i n e ' )   {  
 	 	 	 	 p a r e n t N o d e . s t y l e . d i s p l a y   =   ' i n l i n e - b l o c k ' ;  
 	 	 	 }  
  
 	 	 	 i f   ( r e n d e r e d T e x t )   { 	  
 	 	 	 	 i f   ( p a r e n t N o d e . r e p l a c e C h i l d )   {  
 	 	 	 	 	 p a r e n t N o d e . r e p l a c e C h i l d ( r e n d e r e d T e x t ,   e ) ;  
 	 	 	 	 }   e l s e   {  
 	 	 	 	 	 p a r e n t N o d e . i n s e r t B e f o r e ( r e n d e r e d T e x t ,   e ) ;  
 	 	 	 	 	 p a r e n t N o d e . r e m o v e C h i l d ( e ) ;  
 	 	 	 	 }  
 	 	 	 	 i f   ( t h i s . v e c t o r B a c k e n d   = =   ' v m l ' )   {  
 	 	 	 	 	 r e n d e r e d T e x t . i n n e r H T M L   =   r e n d e r e d T e x t . i n n e r H T M L ;  
 	 	 	 	 }  
  
 	 	 	 	 v a r   c h i l d N o d e s L e n g t h   =   r e n d e r e d T e x t . c h i l d N o d e s . l e n g t h  
 	 	 	 	 f o r   ( v a r   i ;   i   <   c h i l d N o d e s L e n g t h ;   i + + )   {  
 	 	 	 	 	  
 	 	 	 	 	 / /   d o   o u r   b e s t   t o   l i n e   u p   s e l e c t a b l e   t e x t   w i t h   r e n d e r e d   t e x t  
  
 	 	 	 	 	 v a r   e   =   r e n d e r e d T e x t . c h i l d N o d e s [ i ] ;  
 	 	 	 	 	 i f   ( e . h a s C h i l d N o d e s ( )   & &   ! e . t a r g e t W i d t h )   {  
 	 	 	 	 	 	 e   =   e . c h i l d N o d e s [ 0 ] ;  
 	 	 	 	 	 }  
 	 	 	 	 	  
 	 	 	 	 	 i f   ( e   & &   e . t a r g e t W i d t h )   {  
 	 	 	 	 	 	 v a r   l e t t e r S p a c i n g C o u n t   =   e . i n n e r H T M L . l e n g t h ;  
 	 	 	 	 	 	 v a r   w o r d S p a c e D e l t a   =   e . t a r g e t W i d t h   -   e . o f f s e t W i d t h ;  
 	 	 	 	 	 	 v a r   l e t t e r S p a c i n g   =   w o r d S p a c e D e l t a   /   ( l e t t e r S p a c i n g C o u n t   | |   1 ) ;  
  
 	 	 	 	 	 	 i f   ( t h i s . v e c t o r B a c k e n d   = =   ' v m l ' )   {  
 	 	 	 	 	 	 	 l e t t e r S p a c i n g   =   M a t h . c e i l ( l e t t e r S p a c i n g ) ;  
 	 	 	 	 	 	 }  
  
 	 	 	 	 	 	 e . s t y l e . l e t t e r S p a c i n g   =   l e t t e r S p a c i n g   +   ' p x ' ;  
 	 	 	 	 	 	 e . s t y l e . w i d t h   =   e . t a r g e t W i d t h   +   ' p x ' ;  
 	 	 	 	 	 }  
 	 	 	 	 }  
 	 	 	 }  
 	 	 }  
 	 } ,  
  
 	 a p p l y E l e m e n t V e r t i c a l M e t r i c s :   f u n c t i o n ( f a c e ,   s t y l e ,   e )   {  
  
 	 	 i f   ( s t y l e . l i n e H e i g h t   = =   ' n o r m a l ' )   {  
 	 	 	 s t y l e . l i n e H e i g h t   =   t h i s . p i x e l s F r o m P o i n t s ( f a c e ,   s t y l e ,   f a c e . l i n e H e i g h t ) ;  
 	 	 }  
  
 	 	 v a r   c s s L i n e H e i g h t A d j u s t m e n t   =   s t y l e . l i n e H e i g h t   -   t h i s . p i x e l s F r o m P o i n t s ( f a c e ,   s t y l e ,   f a c e . l i n e H e i g h t ) ;  
  
 	 	 e . s t y l e . m a r g i n T o p   =   M a t h . r o u n d (   c s s L i n e H e i g h t A d j u s t m e n t   /   2   )   +   ' p x ' ;  
 	 	 e . s t y l e . m a r g i n B o t t o m   =   M a t h . r o u n d (   c s s L i n e H e i g h t A d j u s t m e n t   /   2 )   +   ' p x ' ;  
 	  
 	 } ,  
  
 	 v e c t o r B a c k e n d s :   {  
  
 	 	 c a n v a s :   {  
  
 	 	 	 _ i n i t i a l i z e S u r f a c e :   f u n c t i o n ( f a c e ,   s t y l e ,   t e x t )   {  
  
 	 	 	 	 v a r   e x t e n t s   =   t h i s . g e t T e x t E x t e n t s ( f a c e ,   s t y l e ,   t e x t ) ;  
  
 	 	 	 	 v a r   c a n v a s   =   d o c u m e n t . c r e a t e E l e m e n t ( ' c a n v a s ' ) ;  
 	 	 	 	 i f   ( t h i s . d i s a b l e S e l e c t i o n )   {  
 	 	 	 	 	 c a n v a s . i n n e r H T M L   =   t e x t ;  
 	 	 	 	 }  
  
 	 	 	 	 c a n v a s . h e i g h t   =   M a t h . r o u n d ( t h i s . p i x e l s F r o m P o i n t s ( f a c e ,   s t y l e ,   f a c e . l i n e H e i g h t ) ) ;  
 	 	 	 	 c a n v a s . w i d t h   =   M a t h . r o u n d ( t h i s . p i x e l s F r o m P o i n t s ( f a c e ,   s t y l e ,   e x t e n t s . x ,   ' h o r i z o n t a l ' ) ) ;  
 	  
 	 	 	 	 t h i s . a p p l y E l e m e n t V e r t i c a l M e t r i c s ( f a c e ,   s t y l e ,   c a n v a s ) ;  
  
 	 	 	 	 i f   ( e x t e n t s . x   >   e x t e n t s . h a )    
 	 	 	 	 	 c a n v a s . s t y l e . m a r g i n R i g h t   =   M a t h . r o u n d ( t h i s . p i x e l s F r o m P o i n t s ( f a c e ,   s t y l e ,   e x t e n t s . x   -   e x t e n t s . h a ,   ' h o r i z o n t a l ' ) )   +   ' p x ' ;  
  
 	 	 	 	 v a r   c t x   =   c a n v a s . g e t C o n t e x t ( ' 2 d ' ) ;  
  
 	 	 	 	 v a r   p o i n t S c a l e   =   t h i s . p i x e l s F r o m P o i n t s ( f a c e ,   s t y l e ,   1 ) ;  
 	 	 	 	 c t x . s c a l e ( p o i n t S c a l e   *   s t y l e . f o n t S t r e t c h P e r c e n t ,   - 1   *   p o i n t S c a l e ) ;  
 	 	 	 	 c t x . t r a n s l a t e ( 0 ,   - 1   *   f a c e . a s c e n d e r ) ;  
 	 	 	 	 c t x . f i l l S t y l e   =   s t y l e . c o l o r ;  
  
 	 	 	 	 r e t u r n   {   c o n t e x t :   c t x ,   c a n v a s :   c a n v a s   } ;  
 	 	 	 } ,  
  
 	 	 	 _ r e n d e r G l y p h :   f u n c t i o n ( c t x ,   f a c e ,   c h a r ,   s t y l e )   {  
  
 	 	 	 	 v a r   g l y p h   =   f a c e . g l y p h s [ c h a r ] ;  
  
 	 	 	 	 i f   ( ! g l y p h )   {  
 	 	 	 	 	 / / t h i s . l o g . e r r o r ( " g l y p h   n o t   d e f i n e d :   "   +   c h a r ) ;  
 	 	 	 	 	 r e t u r n   t h i s . r e n d e r G l y p h ( c t x ,   f a c e ,   t h i s . f a l l b a c k C h a r a c t e r ,   s t y l e ) ;  
 	 	 	 	 }  
  
 	 	 	 	 i f   ( g l y p h . o )   {  
  
 	 	 	 	 	 v a r   o u t l i n e ;  
 	 	 	 	 	 i f   ( g l y p h . c a c h e d _ o u t l i n e )   {  
 	 	 	 	 	 	 o u t l i n e   =   g l y p h . c a c h e d _ o u t l i n e ;  
 	 	 	 	 	 }   e l s e   {  
 	 	 	 	 	 	 o u t l i n e   =   g l y p h . o . s p l i t ( '   ' ) ;  
 	 	 	 	 	 	 g l y p h . c a c h e d _ o u t l i n e   =   o u t l i n e ;  
 	 	 	 	 	 }  
  
 	 	 	 	 	 v a r   o u t l i n e L e n g t h   =   o u t l i n e . l e n g t h ;  
 	 	 	 	 	 f o r   ( v a r   i   =   0 ;   i   <   o u t l i n e L e n g t h ;   )   {  
  
 	 	 	 	 	 	 v a r   a c t i o n   =   o u t l i n e [ i + + ] ;  
  
 	 	 	 	 	 	 s w i t c h ( a c t i o n )   {  
 	 	 	 	 	 	 	 c a s e   ' m ' :  
 	 	 	 	 	 	 	 	 c t x . m o v e T o ( o u t l i n e [ i + + ] ,   o u t l i n e [ i + + ] ) ;  
 	 	 	 	 	 	 	 	 b r e a k ;  
 	 	 	 	 	 	 	 c a s e   ' l ' :  
 	 	 	 	 	 	 	 	 c t x . l i n e T o ( o u t l i n e [ i + + ] ,   o u t l i n e [ i + + ] ) ;  
 	 	 	 	 	 	 	 	 b r e a k ;  
  
 	 	 	 	 	 	 	 c a s e   ' q ' :  
 	 	 	 	 	 	 	 	 v a r   c p x   =   o u t l i n e [ i + + ] ;  
 	 	 	 	 	 	 	 	 v a r   c p y   =   o u t l i n e [ i + + ] ;  
 	 	 	 	 	 	 	 	 c t x . q u a d r a t i c C u r v e T o ( o u t l i n e [ i + + ] ,   o u t l i n e [ i + + ] ,   c p x ,   c p y ) ;  
 	 	 	 	 	 	 	 	 b r e a k ;  
  
 	 	 	 	 	 	 	 c a s e   ' b ' :  
 	 	 	 	 	 	 	 	 v a r   x   =   o u t l i n e [ i + + ] ;  
 	 	 	 	 	 	 	 	 v a r   y   =   o u t l i n e [ i + + ] ;  
 	 	 	 	 	 	 	 	 c t x . b e z i e r C u r v e T o ( o u t l i n e [ i + + ] ,   o u t l i n e [ i + + ] ,   o u t l i n e [ i + + ] ,   o u t l i n e [ i + + ] ,   x ,   y ) ;  
 	 	 	 	 	 	 	 	 b r e a k ;  
 	 	 	 	 	 	 }  
 	 	 	 	 	 } 	 	 	 	 	  
 	 	 	 	 }  
 	 	 	 	 i f   ( g l y p h . h a )   {  
 	 	 	 	 	 v a r   l e t t e r S p a c i n g P o i n t s   =    
 	 	 	 	 	 	 s t y l e . l e t t e r S p a c i n g   & &   s t y l e . l e t t e r S p a c i n g   ! =   ' n o r m a l '   ?    
 	 	 	 	 	 	 	 t h i s . p o i n t s F r o m P i x e l s ( f a c e ,   s t y l e ,   s t y l e . l e t t e r S p a c i n g )   :    
 	 	 	 	 	 	 	 0 ;  
  
 	 	 	 	 	 c t x . t r a n s l a t e ( g l y p h . h a   +   l e t t e r S p a c i n g P o i n t s ,   0 ) ;  
 	 	 	 	 }  
 	 	 	 } ,  
  
 	 	 	 _ r e n d e r W o r d :   f u n c t i o n ( f a c e ,   s t y l e ,   t e x t )   {  
 	 	 	 	 v a r   s u r f a c e   =   t h i s . i n i t i a l i z e S u r f a c e ( f a c e ,   s t y l e ,   t e x t ) ;  
 	 	 	 	 v a r   c t x   =   s u r f a c e . c o n t e x t ;  
 	 	 	 	 v a r   c a n v a s   =   s u r f a c e . c a n v a s ;  
 	 	 	 	 c t x . b e g i n P a t h ( ) ;  
 	 	 	 	 c t x . s a v e ( ) ;  
  
 	 	 	 	 v a r   c h a r s   =   t e x t . s p l i t ( ' ' ) ;  
 	 	 	 	 v a r   c h a r s L e n g t h   =   c h a r s . l e n g t h ;  
 	 	 	 	 f o r   ( v a r   i   =   0 ;   i   <   c h a r s L e n g t h ;   i + + )   {  
 	 	 	 	 	 t h i s . r e n d e r G l y p h ( c t x ,   f a c e ,   c h a r s [ i ] ,   s t y l e ) ;  
 	 	 	 	 }  
  
 	 	 	 	 c t x . f i l l ( ) ;  
  
 	 	 	 	 i f   ( s t y l e . t e x t D e c o r a t i o n   = =   ' u n d e r l i n e ' )   {  
  
 	 	 	 	 	 c t x . b e g i n P a t h ( ) ;  
 	 	 	 	 	 c t x . m o v e T o ( 0 ,   f a c e . u n d e r l i n e P o s i t i o n ) ;  
 	 	 	 	 	 c t x . r e s t o r e ( ) ;  
 	 	 	 	 	 c t x . l i n e T o ( 0 ,   f a c e . u n d e r l i n e P o s i t i o n ) ;  
 	 	 	 	 	 c t x . s t r o k e S t y l e   =   s t y l e . c o l o r ;  
 	 	 	 	 	 c t x . l i n e W i d t h   =   f a c e . u n d e r l i n e T h i c k n e s s ;  
 	 	 	 	 	 c t x . s t r o k e ( ) ;  
 	 	 	 	 }  
  
 	 	 	 	 r e t u r n   {   e l e m e n t :   c t x . c a n v a s ,   w i d t h :   M a t h . f l o o r ( c a n v a s . w i d t h )   } ;  
 	 	 	  
 	 	 	 }  
 	 	 } ,  
  
 	 	 v m l :   {  
  
 	 	 	 _ i n i t i a l i z e S u r f a c e :   f u n c t i o n ( f a c e ,   s t y l e ,   t e x t )   {  
  
 	 	 	 	 v a r   s h a p e   =   d o c u m e n t . c r e a t e E l e m e n t ( ' v : s h a p e ' ) ;  
  
 	 	 	 	 v a r   e x t e n t s   =   t h i s . g e t T e x t E x t e n t s ( f a c e ,   s t y l e ,   t e x t ) ;  
 	 	 	 	  
 	 	 	 	 s h a p e . s t y l e . w i d t h   =   s h a p e . s t y l e . h e i g h t   =   s t y l e . f o n t S i z e   +   ' p x ' ;    
 	 	 	 	 s h a p e . s t y l e . m a r g i n L e f t   =   ' - 1 p x ' ;   / /   t h i s   s e e m s   s u s p e c t . . .  
  
 	 	 	 	 i f   ( e x t e n t s . x   >   e x t e n t s . h a )   {  
 	 	 	 	 	 s h a p e . s t y l e . m a r g i n R i g h t   =   t h i s . p i x e l s F r o m P o i n t s ( f a c e ,   s t y l e ,   e x t e n t s . x   -   e x t e n t s . h a ,   ' h o r i z o n t a l ' )   +   ' p x ' ;  
 	 	 	 	 }  
  
 	 	 	 	 t h i s . a p p l y E l e m e n t V e r t i c a l M e t r i c s ( f a c e ,   s t y l e ,   s h a p e ) ;  
  
 	 	 	 	 v a r   r e s o l u t i o n S c a l e   =   f a c e . r e s o l u t i o n   *   1 0 0   /   7 2 ;  
 	 	 	 	 s h a p e . c o o r d s i z e   =   ( r e s o l u t i o n S c a l e   /   s t y l e . f o n t S t r e t c h P e r c e n t )   +   " , "   +   r e s o l u t i o n S c a l e ;  
 	 	 	 	  
 	 	 	 	 s h a p e . c o o r d o r i g i n   =   ' 0 , '   +   f a c e . a s c e n d e r ;  
 	 	 	 	 s h a p e . s t y l e . f l i p   =   ' y ' ;  
  
 	 	 	 	 s h a p e . f i l l C o l o r   =   s t y l e . c o l o r ;  
 	 	 	 	 s h a p e . s t r o k e d   =   f a l s e ;  
  
 	 	 	 	 s h a p e . p a t h   =   ' h h   m   0 , '   +   f a c e . a s c e n d e r   +   '   l   0 , '   +   f a c e . d e s c e n d e r   +   '   ' ;  
  
 	 	 	 	 r e t u r n   s h a p e ;  
 	 	 	 } ,  
  
 	 	 	 _ r e n d e r G l y p h :   f u n c t i o n ( s h a p e ,   f a c e ,   c h a r ,   o f f s e t X ,   s t y l e ,   v m l S e g m e n t s )   {  
  
 	 	 	 	 v a r   g l y p h   =   f a c e . g l y p h s [ c h a r ] ;  
  
 	 	 	 	 i f   ( ! g l y p h )   {  
 	 	 	 	 	 t h i s . l o g ( " g l y p h   n o t   d e f i n e d :   "   +   c h a r ) ;  
 	 	 	 	 	 t h i s . r e n d e r G l y p h ( s h a p e ,   f a c e ,   t h i s . f a l l b a c k C h a r a c t e r ,   o f f s e t X ,   s t y l e ) ;  
 	 	 	 	 	 r e t u r n ;  
 	 	 	 	 }  
 	 	 	 	  
 	 	 	 	 v m l S e g m e n t s . p u s h ( ' m ' ) ;  
  
 	 	 	 	 i f   ( g l y p h . o )   {  
 	 	 	 	 	  
 	 	 	 	 	 v a r   o u t l i n e ,   o u t l i n e L e n g t h ;  
 	 	 	 	 	  
 	 	 	 	 	 i f   ( g l y p h . c a c h e d _ o u t l i n e )   {  
 	 	 	 	 	 	 o u t l i n e   =   g l y p h . c a c h e d _ o u t l i n e ;  
 	 	 	 	 	 	 o u t l i n e L e n g t h   =   o u t l i n e . l e n g t h ;  
 	 	 	 	 	 }   e l s e   {  
 	 	 	 	 	 	 o u t l i n e   =   g l y p h . o . s p l i t ( '   ' ) ;  
 	 	 	 	 	 	 o u t l i n e L e n g t h   =   o u t l i n e . l e n g t h ;  
  
 	 	 	 	 	 	 f o r   ( v a r   i   =   0 ;   i   <   o u t l i n e L e n g t h ; )   {  
  
 	 	 	 	 	 	 	 s w i t c h ( o u t l i n e [ i + + ] )   {  
 	 	 	 	 	 	 	 	 c a s e   ' q ' :  
 	 	 	 	 	 	 	 	 	 o u t l i n e [ i ]   =   M a t h . r o u n d ( o u t l i n e [ i + + ] ) ;  
 	 	 	 	 	 	 	 	 	 o u t l i n e [ i ]   =   M a t h . r o u n d ( o u t l i n e [ i + + ] ) ;  
 	 	 	 	 	 	 	 	 c a s e   ' m ' :  
 	 	 	 	 	 	 	 	 c a s e   ' l ' :  
 	 	 	 	 	 	 	 	 	 o u t l i n e [ i ]   =   M a t h . r o u n d ( o u t l i n e [ i + + ] ) ;  
 	 	 	 	 	 	 	 	 	 o u t l i n e [ i ]   =   M a t h . r o u n d ( o u t l i n e [ i + + ] ) ;  
 	 	 	 	 	 	 	 	 	 b r e a k ;  
 	 	 	 	 	 	 	 }    
 	 	 	 	 	 	 } 	  
  
 	 	 	 	 	 	 g l y p h . c a c h e d _ o u t l i n e   =   o u t l i n e ;  
 	 	 	 	 	 }  
  
 	 	 	 	 	 v a r   p r e v X ,   p r e v Y ;  
 	 	 	 	 	  
 	 	 	 	 	 f o r   ( v a r   i   =   0 ;   i   <   o u t l i n e L e n g t h ; )   {  
  
 	 	 	 	 	 	 v a r   a c t i o n   =   o u t l i n e [ i + + ] ;  
  
 	 	 	 	 	 	 v a r   x   =   M a t h . r o u n d ( o u t l i n e [ i + + ] )   +   o f f s e t X ;  
 	 	 	 	 	 	 v a r   y   =   M a t h . r o u n d ( o u t l i n e [ i + + ] ) ;  
 	  
 	 	 	 	 	 	 s w i t c h ( a c t i o n )   {  
 	 	 	 	 	 	 	 c a s e   ' m ' :  
 	 	 	 	 	 	 	 	 v m l S e g m e n t s . p u s h ( ' x m   ' ,   x ,   ' , ' ,   y ) ;  
 	 	 	 	 	 	 	 	 b r e a k ;  
 	  
 	 	 	 	 	 	 	 c a s e   ' l ' :  
 	 	 	 	 	 	 	 	 v m l S e g m e n t s . p u s h ( ' l   ' ,   x ,   ' , ' ,   y ) ;  
 	 	 	 	 	 	 	 	 b r e a k ;  
  
 	 	 	 	 	 	 	 c a s e   ' q ' :  
 	 	 	 	 	 	 	 	 v a r   c p x   =   o u t l i n e [ i + + ]   +   o f f s e t X ;  
 	 	 	 	 	 	 	 	 v a r   c p y   =   o u t l i n e [ i + + ] ;  
  
 	 	 	 	 	 	 	 	 v a r   c p 1 x   =   M a t h . r o u n d ( p r e v X   +   2 . 0   /   3 . 0   *   ( c p x   -   p r e v X ) ) ;  
 	 	 	 	 	 	 	 	 v a r   c p 1 y   =   M a t h . r o u n d ( p r e v Y   +   2 . 0   /   3 . 0   *   ( c p y   -   p r e v Y ) ) ;  
  
 	 	 	 	 	 	 	 	 v a r   c p 2 x   =   M a t h . r o u n d ( c p 1 x   +   ( x   -   p r e v X )   /   3 . 0 ) ;  
 	 	 	 	 	 	 	 	 v a r   c p 2 y   =   M a t h . r o u n d ( c p 1 y   +   ( y   -   p r e v Y )   /   3 . 0 ) ;  
 	 	 	 	 	 	 	 	  
 	 	 	 	 	 	 	 	 v m l S e g m e n t s . p u s h ( ' c   ' ,   c p 1 x ,   ' , ' ,   c p 1 y ,   ' , ' ,   c p 2 x ,   ' , ' ,   c p 2 y ,   ' , ' ,   x ,   ' , ' ,   y ) ;  
 	 	 	 	 	 	 	 	 b r e a k ;  
  
 	 	 	 	 	 	 	 c a s e   ' b ' :  
 	 	 	 	 	 	 	 	 v a r   c p 1 x   =   M a t h . r o u n d ( o u t l i n e [ i + + ] )   +   o f f s e t X ;  
 	 	 	 	 	 	 	 	 v a r   c p 1 y   =   o u t l i n e [ i + + ] ;  
  
 	 	 	 	 	 	 	 	 v a r   c p 2 x   =   M a t h . r o u n d ( o u t l i n e [ i + + ] )   +   o f f s e t X ;  
 	 	 	 	 	 	 	 	 v a r   c p 2 y   =   o u t l i n e [ i + + ] ;  
  
 	 	 	 	 	 	 	 	 v m l S e g m e n t s . p u s h ( ' c   ' ,   c p 1 x ,   ' , ' ,   c p 1 y ,   ' , ' ,   c p 2 x ,   ' , ' ,   c p 2 y ,   ' , ' ,   x ,   ' , ' ,   y ) ;  
 	 	 	 	 	 	 	 	 b r e a k ;  
 	 	 	 	 	 	 }  
  
 	 	 	 	 	 	 p r e v X   =   x ;  
 	 	 	 	 	 	 p r e v Y   =   y ;  
 	 	 	 	 	 } 	 	 	 	 	  
 	 	 	 	 }  
  
 	 	 	 	 v m l S e g m e n t s . p u s h ( ' x   e ' ) ;  
 	 	 	 	 r e t u r n   v m l S e g m e n t s ;  
 	 	 	 } ,  
  
 	 	 	 _ r e n d e r W o r d :   f u n c t i o n ( f a c e ,   s t y l e ,   t e x t )   {  
 	 	 	 	 v a r   o f f s e t X   =   0 ;  
 	 	 	 	 v a r   s h a p e   =   t h i s . i n i t i a l i z e S u r f a c e ( f a c e ,   s t y l e ,   t e x t ) ;  
 	 	  
 	 	 	 	 v a r   l e t t e r S p a c i n g P o i n t s   =    
 	 	 	 	 	 s t y l e . l e t t e r S p a c i n g   & &   s t y l e . l e t t e r S p a c i n g   ! =   ' n o r m a l '   ?    
 	 	 	 	 	 	 t h i s . p o i n t s F r o m P i x e l s ( f a c e ,   s t y l e ,   s t y l e . l e t t e r S p a c i n g )   :    
 	 	 	 	 	 	 0 ;  
  
 	 	 	 	 l e t t e r S p a c i n g P o i n t s   =   M a t h . r o u n d ( l e t t e r S p a c i n g P o i n t s ) ;  
 	 	 	 	 v a r   c h a r s   =   t e x t . s p l i t ( ' ' ) ;  
 	 	 	 	 v a r   v m l S e g m e n t s   =   [ ] ;  
 	 	 	 	 f o r   ( v a r   i   =   0 ;   i   <   c h a r s . l e n g t h ;   i + + )   {  
 	 	 	 	 	 v a r   c h a r   =   c h a r s [ i ] ;  
 	 	 	 	 	 v m l S e g m e n t s   =   t h i s . r e n d e r G l y p h ( s h a p e ,   f a c e ,   c h a r ,   o f f s e t X ,   s t y l e ,   v m l S e g m e n t s ) ;  
 	 	 	 	 	 o f f s e t X   + =   f a c e . g l y p h s [ c h a r ] . h a   +   l e t t e r S p a c i n g P o i n t s   ; 	  
 	 	 	 	 }  
  
 	 	 	 	 i f   ( s t y l e . t e x t D e c o r a t i o n   = =   ' u n d e r l i n e ' )   {  
 	 	 	 	 	 v a r   p o s Y   =   f a c e . u n d e r l i n e P o s i t i o n   -   ( f a c e . u n d e r l i n e T h i c k n e s s   /   2 ) ;  
 	 	 	 	 	 v m l S e g m e n t s . p u s h ( ' x m   ' ,   0 ,   ' , ' ,   p o s Y ) ;  
 	 	 	 	 	 v m l S e g m e n t s . p u s h ( ' l   ' ,   o f f s e t X ,   ' , ' ,   p o s Y ) ;  
 	 	 	 	 	 v m l S e g m e n t s . p u s h ( ' l   ' ,   o f f s e t X ,   ' , ' ,   p o s Y   +   f a c e . u n d e r l i n e T h i c k n e s s ) ;  
 	 	 	 	 	 v m l S e g m e n t s . p u s h ( ' l   ' ,   0 ,   ' , ' ,   p o s Y   +   f a c e . u n d e r l i n e T h i c k n e s s ) ;  
 	 	 	 	 	 v m l S e g m e n t s . p u s h ( ' l   ' ,   0 ,   ' , ' ,   p o s Y ) ;  
 	 	 	 	 	 v m l S e g m e n t s . p u s h ( ' x   e ' ) ;  
 	 	 	 	 }  
  
 	 	 	 	 / /   m a k e   s u r e   t o   p r e s e r v e   t r a i l i n g   w h i t e s p a c e  
 	 	 	 	 s h a p e . p a t h   + =   v m l S e g m e n t s . j o i n ( ' ' )   +   ' m   '   +   o f f s e t X   +   '   0   l   '   +   o f f s e t X   +   '   '   +   f a c e . a s c e n d e r ;  
 	 	 	 	  
 	 	 	 	 r e t u r n   {  
 	 	 	 	 	 e l e m e n t :   s h a p e ,  
 	 	 	 	 	 w i d t h :   M a t h . f l o o r ( t h i s . p i x e l s F r o m P o i n t s ( f a c e ,   s t y l e ,   o f f s e t X ,   ' h o r i z o n t a l ' ) )  
 	 	 	 	 } ;  
 	 	 	 }  
  
 	 	 }  
  
 	 } ,  
  
 	 s e t V e c t o r B a c k e n d :   f u n c t i o n ( b a c k e n d )   {  
  
 	 	 t h i s . v e c t o r B a c k e n d   =   b a c k e n d ;  
 	 	 v a r   b a c k e n d F u n c t i o n s   =   [ ' r e n d e r W o r d ' ,   ' i n i t i a l i z e S u r f a c e ' ,   ' r e n d e r G l y p h ' ] ;  
  
 	 	 f o r   ( v a r   i   =   0 ;   i   <   b a c k e n d F u n c t i o n s . l e n g t h ;   i + + )   {  
 	 	 	 v a r   b a c k e n d F u n c t i o n   =   b a c k e n d F u n c t i o n s [ i ] ;  
 	 	 	 t h i s [ b a c k e n d F u n c t i o n ]   =   t h i s . v e c t o r B a c k e n d s [ b a c k e n d ] [ ' _ '   +   b a c k e n d F u n c t i o n ] ;  
 	 	 }  
 	 } ,  
 	  
 	 i n i t i a l i z e :   f u n c t i o n ( )   {  
  
 	 	 / /   q u i t   i f   t h i s   f u n c t i o n   h a s   a l r e a d y   b e e n   c a l l e d  
 	 	 i f   ( a r g u m e n t s . c a l l e e . d o n e )   r e t u r n ;    
 	 	  
 	 	 / /   f l a g   t h i s   f u n c t i o n   s o   w e   d o n ' t   d o   t h e   s a m e   t h i n g   t w i c e  
 	 	 a r g u m e n t s . c a l l e e . d o n e   =   t r u e ;  
  
 	 	 / /   k i l l   t h e   t i m e r  
 	 	 i f   ( w i n d o w . _ t y p e f a c e T i m e r )   c l e a r I n t e r v a l ( _ t y p e f a c e T i m e r ) ;  
  
 	 	 t h i s . r e n d e r D o c u m e n t (   f u n c t i o n ( e )   {   e . s t y l e . v i s i b i l i t y   =   ' v i s i b l e '   }   ) ;  
  
 	 }  
 	  
 } ;  
  
 / /   I E   w o n ' t   a c c e p t   r e a l   s e l e c t o r s . . .  
 v a r   t y p e f a c e S e l e c t o r s   =   [ ' . t y p e f a c e - j s ' ,   ' h 1 ' ,   ' h 2 ' ,   ' h 3 ' ,   ' h 4 ' ,   ' h 5 ' ,   ' h 6 ' ] ;  
  
 i f   ( d o c u m e n t . c r e a t e S t y l e S h e e t )   {    
  
 	 v a r   s t y l e S h e e t   =   d o c u m e n t . c r e a t e S t y l e S h e e t ( ) ;  
 	 f o r   ( v a r   i   =   0 ;   i   <   t y p e f a c e S e l e c t o r s . l e n g t h ;   i + + )   {  
 	 	 v a r   s e l e c t o r   =   t y p e f a c e S e l e c t o r s [ i ] ;  
 	 	 s t y l e S h e e t . a d d R u l e ( s e l e c t o r ,   ' v i s i b i l i t y :   h i d d e n ' ) ;  
 	 }  
  
 	 s t y l e S h e e t . a d d R u l e (  
 	 	 ' . t y p e f a c e - j s - s e l e c t e d - t e x t ' ,    
 	 	 ' - m s - f i l t e r :   \  
 	 	 	 " C h r o m a ( c o l o r = b l a c k )   \  
 	 	 	 p r o g i d : D X I m a g e T r a n s f o r m . M i c r o s o f t . M a s k F i l t e r ( C o l o r = w h i t e )   \  
 	 	 	 p r o g i d : D X I m a g e T r a n s f o r m . M i c r o s o f t . M a s k F i l t e r ( C o l o r = b l u e )   \  
 	 	 	 a l p h a ( o p a c i t y = 3 0 ) "   ! i m p o r t a n t ;   \  
 	 	 c o l o r :   b l a c k ;   \  
 	 	 f o n t - f a m i l y :   M o d e r n ;   \  
 	 	 p o s i t i o n :   a b s o l u t e ;   \  
 	 	 w h i t e - s p a c e :   p r e ;   \  
 	 	 f i l t e r :   a l p h a ( o p a c i t y = 0 )   ! i m p o r t a n t ; '  
 	 ) ;  
  
 	 s t y l e S h e e t . a d d R u l e (  
 	 	 ' . t y p e f a c e - j s - v e c t o r - c o n t a i n e r ' ,  
 	 	 ' p o s i t i o n :   r e l a t i v e '  
 	 ) ;  
  
 }   e l s e   i f   ( d o c u m e n t . s t y l e S h e e t s )   {  
  
 	 i f   ( ! d o c u m e n t . s t y l e S h e e t s . l e n g t h )   {   ( f u n c t i o n ( )   {  
 	 	 / /   c r e a t e   a   s t y l e s h e e t   i f   w e   n e e d   t o  
 	 	 v a r   s t y l e S h e e t   =   d o c u m e n t . c r e a t e E l e m e n t ( ' s t y l e ' ) ;  
 	 	 s t y l e S h e e t . t y p e   =   ' t e x t / c s s ' ;  
 	 	 d o c u m e n t . g e t E l e m e n t s B y T a g N a m e ( ' h e a d ' ) [ 0 ] . a p p e n d C h i l d ( s t y l e S h e e t ) ;  
 	 } ) ( )   }  
  
 	 v a r   s t y l e S h e e t   =   d o c u m e n t . s t y l e S h e e t s [ 0 ] ;  
 	 d o c u m e n t . s t y l e S h e e t s [ 0 ] . i n s e r t R u l e ( t y p e f a c e S e l e c t o r s . j o i n ( ' , ' )   +   '   {   v i s i b i l i t y :   h i d d e n ;   } ' ,   s t y l e S h e e t . c s s R u l e s . l e n g t h ) ;    
  
 	 d o c u m e n t . s t y l e S h e e t s [ 0 ] . i n s e r t R u l e (  
 	 	 ' . t y p e f a c e - j s - s e l e c t e d - t e x t   {   \  
 	 	 	 c o l o r :   r g b a ( 1 2 8 ,   1 2 8 ,   1 2 8 ,   0 ) ;   \  
 	 	 	 o p a c i t y :   0 . 3 0 ;   \  
 	 	 	 p o s i t i o n :   a b s o l u t e ;   \  
 	 	 	 f o n t - f a m i l y :   A r i a l ,   s a n s - s e r i f ;   \  
 	 	 	 w h i t e - s p a c e :   p r e   \  
 	 	 } ' ,    
 	 	 s t y l e S h e e t . c s s R u l e s . l e n g t h  
 	 ) ;  
  
 	 t r y   {    
 	 	 / /   s e t   s e l e c t i o n   s t y l e   f o r   M o z i l l a   /   F i r e f o x  
 	 	 d o c u m e n t . s t y l e S h e e t s [ 0 ] . i n s e r t R u l e (  
 	 	 	 ' . t y p e f a c e - j s - s e l e c t e d - t e x t : : - m o z - s e l e c t i o n   {   b a c k g r o u n d :   b l u e ;   } ' ,    
 	 	 	 s t y l e S h e e t . c s s R u l e s . l e n g t h  
 	 	 ) ;    
  
 	 }   c a t c h ( e )   { } ;  
  
 	 t r y   {    
 	 	 / /   s e t   s t y l e s   f o r   b r o w s e r s   w i t h   C S S 3   s e l e c t o r s   ( S a f a r i ,   C h r o m e )  
 	 	 d o c u m e n t . s t y l e S h e e t s [ 0 ] . i n s e r t R u l e (  
 	 	 	 ' . t y p e f a c e - j s - s e l e c t e d - t e x t : : s e l e c t i o n   {   b a c k g r o u n d :   b l u e ;   } ' ,    
 	 	 	 s t y l e S h e e t . c s s R u l e s . l e n g t h  
 	 	 ) ;    
  
 	 }   c a t c h ( e )   { } ;  
  
 	 / /   m o s t   u n f o r t u n a t e l y ,   s n i f f   f o r   W e b K i t ' s   q u i r k y   s e l e c t i o n   b e h a v i o r  
 	 i f   ( / W e b K i t / i . t e s t ( n a v i g a t o r . u s e r A g e n t ) )   {  
 	 	 d o c u m e n t . s t y l e S h e e t s [ 0 ] . i n s e r t R u l e (  
 	 	 	 ' . t y p e f a c e - j s - v e c t o r - c o n t a i n e r   {   p o s i t i o n :   r e l a t i v e   } ' ,  
 	 	 	 s t y l e S h e e t . c s s R u l e s . l e n g t h  
 	 	 ) ;  
 	 }  
  
 }  
  
 v a r   b a c k e n d   =     w i n d o w . C a n v a s R e n d e r i n g C o n t e x t 2 D   | |   d o c u m e n t . c r e a t e E l e m e n t ( ' c a n v a s ' ) . g e t C o n t e x t   ?   ' c a n v a s '   :   ! ! ( w i n d o w . a t t a c h E v e n t   & &   ! w i n d o w . o p e r a )   ?   ' v m l '   :   n u l l ;  
  
 i f   ( b a c k e n d   = =   ' v m l ' )   {  
  
 	 d o c u m e n t . n a m e s p a c e s . a d d ( " v " , " u r n : s c h e m a s - m i c r o s o f t - c o m : v m l " , " # d e f a u l t # V M L " ) ;  
  
 	 v a r   s t y l e S h e e t   =   d o c u m e n t . c r e a t e S t y l e S h e e t ( ) ;  
 	 s t y l e S h e e t . a d d R u l e ( ' v \ \ : s h a p e ' ,   " d i s p l a y :   i n l i n e - b l o c k ; " ) ;  
 }  
  
 _ t y p e f a c e _ j s . s e t V e c t o r B a c k e n d ( b a c k e n d ) ;  
 w i n d o w . _ t y p e f a c e _ j s   =   _ t y p e f a c e _ j s ;  
 	  
 i f   ( / W e b K i t / i . t e s t ( n a v i g a t o r . u s e r A g e n t ) )   {  
  
 	 v a r   _ t y p e f a c e T i m e r   =   s e t I n t e r v a l ( f u n c t i o n ( )   {  
 	 	 i f   ( / l o a d e d | c o m p l e t e / . t e s t ( d o c u m e n t . r e a d y S t a t e ) )   {  
 	 	 	 _ t y p e f a c e _ j s . i n i t i a l i z e ( ) ;    
 	 	 }  
 	 } ,   1 0 ) ;  
 }  
  
 i f   ( d o c u m e n t . a d d E v e n t L i s t e n e r )   {  
 	 w i n d o w . a d d E v e n t L i s t e n e r ( ' D O M C o n t e n t L o a d e d ' ,   f u n c t i o n ( )   {   _ t y p e f a c e _ j s . i n i t i a l i z e ( )   } ,   f a l s e ) ;  
 }    
  
 / * @ c c _ o n   @ * /  
 / * @ i f   ( @ _ w i n 3 2 )  
  
 d o c u m e n t . w r i t e ( " < s c r i p t   i d = _ _ i e _ o n l o a d _ t y p e f a c e   d e f e r   s r c = / / : > < \ / s c r i p t > " ) ;  
 v a r   s c r i p t   =   d o c u m e n t . g e t E l e m e n t B y I d ( " _ _ i e _ o n l o a d _ t y p e f a c e " ) ;  
 s c r i p t . o n r e a d y s t a t e c h a n g e   =   f u n c t i o n ( )   {  
 	 i f   ( t h i s . r e a d y S t a t e   = =   " c o m p l e t e " )   {  
 	 	 _ t y p e f a c e _ j s . i n i t i a l i z e ( ) ;    
 	 }  
 } ;  
  
 / * @ e n d   @ * /  
  
 t r y   {   c o n s o l e . l o g ( ' i n i t i a l i z i n g   t y p e f a c e . j s ' )   }   c a t c h ( e )   { } ;  
  
 } ) ( ) ; 
