
    jke                     N   d dl mZ d dlmZmZmZ d dlmZ d dlm	Z	 d dl
mZmZmZ d dlmZmZmZ d dlmZ d dlmZ d d	lmZ d d
lZd d
lZd d
lZd d
lZ ej8                  d      Z G d de      Z G d d      Z  G d de       Z! G d de!      Z" G d de!      Z# G d de       Z$y
)    )TTFont)RecordingPenDecomposingRecordingPenRecordingPointPen)ControlBoundsPen)CairoPen)SegmentToPointPenPointToSegmentPenReverseContourPointPen)PerContourOrComponentPenSimpleRecordingPointPenLerpGlyphSet)cycle)wraps)BytesIONzfontTools.varLib.interpolatablec                       e Zd Zd Zd Zy)OverridingDictc                     || _         y Nparent_dict)selfr   s     E/usr/lib/python3/dist-packages/fontTools/varLib/interpolatablePlot.py__init__zOverridingDict.__init__   s
    &    c                      | j                   |   S r   r   )r   keys     r   __missing__zOverridingDict.__missing__"   s    $$r   N)__name__
__module____qualname__r   r    r   r   r   r      s    '%r   r   c                      e Zd ZdZdZdZdZdZdZdZ	dZ
dZd	Zd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&d Z'd!Z(d"Z)d#Z*dDd%Z+d& Z,d' Z-d( Z.d) Z/d* Z0d+ Z1d,d$d$d-d.Z2d,d$d$d-d/Z3d,d,d0d1Z4d,d,d0d2Z5d3d3d4d3d5d$d$d6d7Z6d3d3d$d8d9Z7d3d3d4dd:d;Z8d3d3d4ddd<d=Z9d3d3d4d>d?Z:d3d3d4d$d$d@dAZ;dB Z<dEdCZ=y$)FInterpolatablePloti  i     $      )333333?r(   r(   )皙?r)   r)   )?r*   r*   )皙?r+   r+   )皙?r,   r,      )r   r+   r   ffffff?
   )r         ?r   r.      )r   r*   r   r.      )r'   r   r   r.   )r   r   r'   r.      )r'   r   r'   r.            ?))r'   r   r   )r   r   r'   )r   r'   r   )r'   r'   r   )r'   r   r'   )r   r'   r'   r0   )r   r   r   皙?z#Your font's good! Have a cupcake...)r   r0   r   )r(   r   r(   a  
                          ,@.
                        ,@.@@,.
                  ,@@,.@@@.  @.@@@,.
                ,@@. @@@.     @@. @@,.
        ,@@@.@,.@.              @.  @@@@,.@.@@,.
   ,@@.@.     @@.@@.            @,.    .@' @'  @@,
 ,@@. @.          .@@.@@@.  @@'                  @,
,@.  @@.                                          @,
@.     @,@@,.     ,                             .@@,
@,.       .@,@@,.         .@@,.  ,       .@@,  @, @,
@.                             .@. @ @@,.    ,      @
 @,.@@.     @,.      @@,.      @.           @,.    @'
  @@||@,.  @'@,.       @@,.  @@ @,.        @'@@,  @'
     \\@@@@'  @,.      @'@@@@'   @@,.   @@@' //@@@'
      |||||||| @@,.  @@' |||||||  |@@@|@||  ||
       \\\\\\\  ||@@@||  |||||||  |||||||  //
        |||||||  ||||||  ||||||   ||||||  ||
         \\\\\\  ||||||  ||||||  ||||||  //
          ||||||  |||||  |||||   |||||  ||
           \\\\\  |||||  |||||  |||||  //
            |||||  ||||  |||||  ||||  ||
             \\\\  ||||  ||||  ||||  //
              ||||||||||||||||||||||||
)r   r(   r(   z\_(")_/z
 o
/|\
/ \
z
 o
/O\
/ \
z \o/ Nc                     || _         || _        |xs |D cg c]  }t        |       c}| _        |j	                         D ],  \  }}t        | |      st        d|z        t        | ||       . y c c}w )NzUnknown keyword argument: %s)out	glyphsetsreprnamesitemshasattr	TypeErrorsetattr)r   r8   r9   r;   kwargsgkvs           r   r   zInterpolatablePlot.__init__p   sp    ":	:1tAw:
LLN 	 DAq4# > BCCD!Q	  ;s   A1c                     | S r   r"   r   s    r   	__enter__zInterpolatablePlot.__enter__z   s    r   c                      y r   r"   r   typevalue	tracebacks       r   __exit__zInterpolatablePlot.__exit__}   s    r   c                     t         r   )NotImplementedErrorr   widthheights      r   set_sizezInterpolatablePlot.set_size   s    !!r   c                 .    | xj                   dz  c_         y )Nr'   )page_numberrE   s    r   	show_pagezInterpolatablePlot.show_page   s    Ar   c                 @    | j                   dz  | j                  dz  z   S )Nr-      )rP   padrE   s    r   total_widthzInterpolatablePlot.total_width   s    zzA~1,,r   c                     | j                   | j                  z   | j                   z   | j                  z   | j                   z   d| j                  | j                   dz  z   | j                  z   z  z   | j                   z   S )Nr-   )rX   line_heightrQ   rE   s    r   total_heightzInterpolatablePlot.total_height   s    HHhh  hh	
 4;;A-0@0@@AB hh	
r   Tshow_tolerance	tolerance	kinkinessc          
         | j                  | j                         | j                                | j                  }| j                         d| j                  z  z
  }| j                         d| j                  z  z
  }|x}}	| j	                  d||	d|       |	| j
                  z  }	dd l}
|D ]  }t        j                  j                  |      }|	| j
                  z  }	| j	                  |||	d|       |	| j
                  z  }	|
j                  t        |d      j                               j                         }| j	                  d|z  ||z   |	|	       |	| j
                  z  }	|j                  d
      ret        |      }d|v r|d   nd }|sdD ]E  \  }}|j!                  |      }|| j	                  |d|||z   |	|	       |	| j
                  z  }	G .|j                  d      sAddlm}  ||      }dD ];  \  }}| j	                  |dt'        ||      ||z   |	|	       |	| j
                  z  }	=  | j)                  |||       | j+                          y )NrW   r-   zProblem report for:T)xyboldrP   r   rbzsha1: %srb   rc   rP   z.ttfname))Family name)   r%   r'   )Version)   z: z.glyphs)GSFont))rh   
familyName)VersionMajorversionMajor)VersionMinor_versionMinorr]   )rR   rY   r\   rX   
draw_labelr[   hashlibospathbasenamesha1openread	hexdigestendswithr   getFirstDebugName	glyphsLibrl   getattrdraw_legendrU   )r   filesr^   r_   r`   rX   rP   rQ   rb   rc   rs   file	base_filehttFontrg   whatnameIDsnrl   ffields                         r   add_title_pagez!InterpolatablePlot.add_title_page   si    	d&&($*;*;*=>hh  "Q\1""$q488|3A-ad%P	T (	*D((.I!!!AOOIad%OH!!!AT$-2245??AAOOJNa#g%OH!!!A}}V$)/6)9vf~t* 
.g !227;9$(,a0AGq (  T---
. y),4L$ *KD%
 OO$('!U*;<c'#	 $  )))A*;(	*T 	)Y) 	 	
 	r   c                   t        j                  | j                        }| j                  }| j	                         | j                  z
  | j
                  dz  z
  }| j                         d| j                  z  z
  }|| j                  dz  z   }|| j                  dz  z   }	|r1| j                  d|	||       || j                  | j
                  z   z  }| j                  d|	||       |j                  || j                  dz  z
  |d| j                  z  | j
                          |j                  | j                    |j                          | j                  rD |j                  | j                    |j                  | j                         |j                           |j                   | j"                    |j%                          || j                  | j
                  z   z  }| j                  d|	||       |j                  || j                  dz  z
  |d| j                  z  | j
                         | j                  r) |j                  | j                    |j                          | j                  rD |j                  | j                    |j                  | j                         |j                           |j                   g | j&                  d	   | j(                    |j%                          || j                  | j
                  z   z  }| j                  d
|	||       | j+                  |||| j
                  dz  z   | j,                  | j.                  | j0                         || j                  | j
                  z   z  }| j                  d|	||       | j3                  |||| j
                  dz  z   | j4                  | j6                         || j                  | j
                  z   z  }| j                  d|	||       | j3                  |||| j
                  dz  z   | j8                  | j:                         || j                  | j
                  z   z  }| j                  d|	||       | j=                  ||| j>                  dz  z
  || j
                  dz  z   | j@                         || j                  | j
                  z   z  }| j                  d|	||       | j3                  |||| j
                  dz  z   | j8                  | jB                         || j                  | j
                  z   z  }| j                  d|	||       | j=                  ||| j>                  dz  z
  || j
                  dz  z   | jB                         || j                  | j
                  z   z  }| j                  d|||d       || j                  | j
                  z   z  }|4| j                  d|z  |	||       || j                  | j
                  z   z  }|4| j                  d|z  |	||       || j                  | j
                  z   z  }| j                  d|||d       || j                  | j
                  z   z  }y )Nr-      z,Tolerance: badness; closer to zero the worserf   zUnderweight contoursr.   r5   z/Colored contours: contours with the wrong orderr   zKink artifactr0   )rb   rc   diameterstroke_widthcolorz!Point causing kink in the contour)rb   rc   r   r   z!Suggested new contour start pointz4Contour start point in contours with wrong directionr(   rb   rc   r   z5Contour start point when the first two points overlapz!Contour start point and directionzLegend:T)rb   rc   rP   rd   z!Kink-reporting aggressiveness: %gzError tolerance: %gzParameters:)"cairoContextsurfacerX   r\   r[   rY   rr   	rectangleset_source_rgb
fill_colorfill_preservestroke_colorset_line_widthr   stroke_preserveset_source_rgbaweight_issue_contour_colorfillcontour_colorscontour_alphadraw_circlekink_circle_sizekink_circle_stroke_widthkink_circle_colordraw_dotkink_point_sizekink_point_colorcorrected_start_point_sizecorrected_start_point_color
draw_arrowstart_arrow_lengthwrong_start_point_colorstart_point_color)
r   r^   r_   r`   crrb   rc   rP   xxxxxs
             r   r   zInterpolatablePlot.draw_legend   s(   ]]4<<(HH$((*T-=-=-AA  "Q\1A$((Q,OO>#RW   D,,,,A.#%H
R$((S.(!S488^T=M=MN4??+
Bt001d//0 D;;<
		TXX((((=QV 	 	
 	R$((S.(!S488^T=M=MN??Bt/Bt001d//0 GD//2GD4F4FG
		TXX((((3!5A$""S((**66(( 	 	
 	
TXX((((;sauU$""S(())'' 	 	
 	
TXX((((;sauU$""S((4422 	 	
 	
TXX((((B	 	 	
 	4**S00$""S((..	 	 	
 	
TXX((((C	 	 	
 	$""S((44(( 	 	
 	
TXX((((;sauU4**S00$""S((((	 	 	
 	
TXX((((	Q!5tD	TXX(((( OO3i?	   D,,,,A OO%	1	   D,,,,Aau4H	TXX((((r   r^   show_page_numberc                f   |j                         D ]  \  }}d }g }|D ]h  }d|v r|d   n	|d   |d   f}	|	|k(  r|j                  |       -|r'| j                  ||||       | j                          g }|	}|j                  |       j |sz| j                  ||||       | j                           y )N
master_idxmaster_1_idxmaster_2_idxr   )r<   appendadd_problemrU   )
r   problemsr^   r   glyphglyph_problemslast_masterscurrent_glyph_problemspmasterss
             r   add_problemszInterpolatablePlot.add_problemsZ  s    %-^^%5 	!!E>L%'"# 1 $q( lON+Q~->? 
 l**11!4)$$.'5)9	 %  NN$-/*&&--a0)1* &  *#1%5	 !   ?	!r   c                p  : t        |      t        t        fvr|g}|d   d   :t        d |D              }t	        :fd|D              s+dj                  t        |D ch c]  }|d   	 c}            :t        j                  d:       d|d   v rdnd	}|D cg c]
  }|d   |    }	}:d
k(  r9t        fdt        | j                        D              }
|	j                  d|
       | j                  | j                         | j                                | j                   }| j                   }| j#                  dz   ||| j$                  dd       t'        d |D              }|dk  r:|r8| j#                  d|z  ||| j                         d| j                   z  z
  dd       || j(                  | j                   z   z  }| j#                  :||| j                         d| j                   z  z
  | j$                  dd       || j(                  | j                   z   z  }g }t        |	      D ]  \  }}| j                  |   }| j*                  |   }| j#                  |||| j,                  d       || j(                  | j                   z   z  }|   '|j/                  | j1                  |||||             n| j3                  | j4                  ||       || j6                  | j                   z   z  } t9        d |D              r.| j                   | j:                  z   | j                   z   }| j                   }|| j(                  | j                   z   z  }|| j(                  | j                   z   z  }| j                  |	d      }| j                  |	d      }| j#                  d||| j$                  d       || j(                  | j                   z   z  }t=        ||      }| j1                  |ddig|D cg c]  }|d   dv r| c}z   d ||t'        |             || j6                  | j                   z   z  }t9        d |D              r|| j#                  d||| j$                  d       || j(                  | j                   z   z  }t?              }t?              }tA        tB        |      }tA        tB        |      }|   jE                  |       |   jE                  |       |D ]4  }|d   d k(  s|d   d!   D cg c]  }|jF                  |    }}||_#        6 |D ]  }|d   d"k(  s|jF                  |d#      }|jF                  |d#      }tI               }tK        |d$      } |jM                  |        tI               }!tK        |!d$      } |jM                  |        |d!   }"|d%   rCtI               }#tO        |#      }$|!jM                  |$       |#}!tQ        |!jF                        dz
  |"z
  }"|!jF                  d d }%|!jF                  d&d  }&|!jF                  dd& }'|'|"d  |'d |" z   }'|%|'z   |&z   |!_#        tC               }(tS        |(d      } |jM                  |        tC               })tS        |)d      } |!jM                  |        |(jF                  |_#        |)jF                  |_#        ||jF                  |d#   <   ||jF                  |d#   <    |D ]  }|d   d'k(  s|jF                  |d#      }|jF                  |d#      }tI               }tK        |d$      } |jM                  |        tI               }!tK        |!d$      } |jM                  |        |d(   }|dz   }*|jF                  |*   d   d   }+|!jF                  |*   d   d   },|dz
  tQ        |jF                        dz
  z  dz   }-|jF                  |-   d   d   }.|!jF                  |-   d   d   }/|dz   tQ        |jF                        dz
  z  dz   }0|jF                  |0   d   d   }1|!jF                  |0   d   d   }2tU        |+ }+tU        |, },tU        |. }.tU        |/ }/tU        |1 }1tU        |2 }2tW        |+|.z
        tW        |1|.z
        z  }3tW        |,|/z
        tW        |2|/z
        z  }4|3|4z   dz  }5|.|5|1|.z
  z  z   }+|/|5|2|/z
  z  z   },|jF                  |*   d   |+jX                  |+jZ                  ff|jF                  |*   d   dd  z   |jF                  |*   d   f|jF                  |*<   |!jF                  |*   d   |,jX                  |,jZ                  ff|!jF                  |*   d   dd  z   |!jF                  |*   d   f|!jF                  |*<   tC               }(tS        |(d      } |jM                  |        tC               })tS        |)d      } |!jM                  |        |(jF                  |_#        |)jF                  |_#         tC               }6tC               }7|jF                  D ]'  }8|6jF                  j]                  |8jF                         ) |jF                  D ]'  }8|7jF                  j]                  |8jF                         ) |6jL                  |6_"        |7jL                  |7_"        |6|<   |7|<   	 t=        ||      }| j1                  |dd)id ||t'        |             || j6                  | j                   z   z  }nR| j4                  }9d*|v r| j`                  }9n!d+|v r| jb                  }9nd,|v r| jd                  }9| j3                  |9||       |r^| j#                  tg        | jh                        d| j                         | j(                  z
  | j                         | j$                  d-       y y c c}w c c}w c c}w c c}w # t^        $ r" | j3                  | j4                  ||       Y w xY w).Nr   rI   c              3   &   K   | ]	  }|d      ywrI   Nr"   .0problems     r   	<genexpr>z1InterpolatablePlot.add_problem.<locals>.<genexpr>       DGFOD   c              3   (   K   | ]	  }|k(    y wr   r"   r   ptproblem_types     r   r   z1InterpolatablePlot.add_problem.<locals>.<genexpr>       >"2%>   z, zDrawing %s: %sr   )r   )r   r   missingc              3   4   K   | ]  \  }}|   |  y wr   r"   )r   im	glyphnames      r   r   z1InterpolatablePlot.add_problem.<locals>.<genexpr>  s#       a1Y<;S s   zGlyph name: T)rb   rc   r   alignrd   c              3   @   K   | ]  }|j                  d d        yw)r_   r'   N)get)r   r   s     r   r   z1InterpolatablePlot.add_problem.<locals>.<genexpr>  s     @!k1-@s   r'   ztolerance: %.2fr-   )rb   rc   rP   r   rd   r0   )rb   rc   rP   r   r   rd   )rb   rc   r   r   )rb   rc   c              3   $   K   | ]  }|d v  
 yw))nothingwrong_start_pointcontour_orderkinkunderweight
overweightNr"   r   r   s     r   r   z1InterpolatablePlot.add_problem.<locals>.<genexpr>  s$      
  
   zmidway interpolationmidway)r   r   r   rb   rc   scalec              3   $   K   | ]  }|d v  
 yw))r   r   r   Nr"   r   s     r   r   z1InterpolatablePlot.add_problem.<locals>.<genexpr>  s$      
  
r   zproposed fixglyphsetr   value_2r   contourFreversedr   rJ   fixedr   r   r   )rb   rc   rP   r   r   )5rI   listtuplesetalljoinsortedloginfonext	enumerater9   insertrR   rY   r\   rX   rr   
head_colorminr[   r;   label_colorr   
draw_glyphdraw_emoticonshrugrQ   anyrP   r   r   r   r   drawrJ   r   r	   replayr   lenr
   complexabsrealimagextend
ValueErrorr   r   yaystrrT   );r   r   r   r^   r   problem_typesr   master_keysrB   master_indicessample_glyphrb   rc   r_   scaleswhichr   r   rg   	glyphset1	glyphset2midway_glyphsetr   overriding1overriding2perContourPen1perContourPen2r   fixed_contourswrongContour1wrongContour2points1	converterpoints2proposed_startnew_points2reversedPen	beginPathendPathptssegment1segment2jpt0pt1j_prevpt0_prevpt1_prevj_nextpt0_nextpt1_nextr0r1r_midfixed1fixed2r   emoticonr   s;    `                                                        @r   r   zInterpolatablePlot.add_problem|  s    >$. zH{6*D8DD>>>99VH,UWV_,U%VWL!9l; x{* 1 	
 3>>Q(1+a.>>9$  '7  L !!!\2d&&($*;*;*=>HHHHY&// 	 	
 @x@@	q=^OO!I-&&(1txx<7   	
T((""$q488|3// 	 	
 	
T((!*>!: 	(E:~~j1H::j)DOODA$2B2B#ON!!DHH,,A	".OOHi5AQROS ""4::a"8txx''A	(  
 $
 
 4::%0AA!!DHH,,A!!DHH,,A~a'89I~a'89I OO&!qs   !!DHH,,A*9i@OOO(#$ &y$II  &k   txx''A 
 $
 
 OONa1DOOSVOW!!DHH,,A(3K(3K5{N 6{N i %%n5i %%n5# :6?o59A!Y9O&45,,Q/&N & ,:N(: $ +M6?&99$2$8$89K$LM$2$8$89K$LM 01G 1'5 AI!((3/1G 1'5 AI!((3%,Y%7N z*&7&9&<[&I{3"-),W]]);a)?.)P !(bq 1I%mmBC0G!--"-Cno._n1EEC$-Og$=GM  ,~H 1(D AINN9-+~H 1(D AINN9- +3..M'*2..M'?LN(();<?LN(();<W+MZ $ A96?f,$2$8$89K$LM$2$8$89K$LM 01G 1'5 AI!((3/1G 1'5 AI!((3(A AA!--*1-a0C!--*1-a0C!eGMM(:Q(>?!CF&}}V4Q7:H&}}V4Q7:H!eGMM(:Q(>?!CF&}}V4Q7:H&}}V4Q7:H!3-C!3-C&1H&1H&1H&1H S8^,s8h3F/GGBS8^,s8h3F/GGB"WME"Uh.A%BBC"Uh.A%BBC  a(+88SXX.07==3CA3Fqr3JJa(+(GMM!$  a(+88SXX.07==3CA3Fqr3JJa(+(GMM!$  ,~H 1(D AINN9-+~H 1(D AINN9- +3..M'*2..M'CA9H "^F!^F)// 3##GMM23)// 3##GMM23 --FK --FK%+K	"%+K	"9".{K"H#W%f+    txx''A zzH-++.??m+88x12OOD$$%##%(8(88&&(oo   O	 -V ?vP&Z  9""4::a"89s*   m6m;1n ;n7/n
 
'n54n5r   )r   r   r   F)rb   rc   r   r   rd   rP   rQ   c                8   || j                   }|| j                  }t        j                  | j                        }	|	j                  dt        j                  |rt        j                  nt        j                         |	j                  | j                         |	j                         }
| j                  | j                  z  |
d   z  }|	j                  |       |	j                         }
 |	j                  |  |	j                  |      }|j                   |kD  rD|||j                   z  z  }|	j                  |       |	j                         }
|	j                  |      }|||j                   z
  |z  z   }||
d   z   }|	j                  ||       |	j                  |       y )Nz@cairo:r-   r   )rP   rQ   r   r   r   select_font_faceFONT_SLANT_NORMALFONT_WEIGHT_BOLDFONT_WEIGHT_NORMALset_font_sizer[   font_extentsr   text_extentsmove_to	show_text)r   labelrb   rc   r   r   rd   rP   rQ   r   r8  	font_sizeextentslabel_xlabel_ys                  r   rr   zInterpolatablePlot.draw_label  sa    =JJE>[[F]]4<<(
##&*E""0H0H	

 	))*($$t'7'77,q/I	
#(5!//%(==5 ..IY'??,Looe,G uw}},55l1o%


7G$
Ur   r   c          	        "# t        |      t        t        fvr|g}t        d |D              }|d   d   "t	        d |D              #t        "fd#D              sd"||   }	t               }
|	j                  |
       t        |      }|	j                  |       t        |      }|j                  |       |j                  }|d}|d   |d   z
  }|d	   |d
   z
  }|r+|| j                  |z  }nt        || j                  |z        }|r+|| j                  |z  }nt        || j                  |z        }|d
}t        j                   | j"                        }|j%                  ||       |j%                  | j                  ||z  z
  dz  | j                  ||z  z
  dz         |j'                  ||        |j%                  |d    |d	           | j(                  ra |j*                  | j(                    |j-                  |d   |d
   ||       |j/                  | j0                  |z         |j3                          | j4                  s| j6                  rt9        ||      }|j                  |       | j4                  r."dk7  r) |j*                  | j4                    |j;                          | j6                  rG |j*                  | j6                    |j/                  | j<                  |z         |j?                          |jA                          d#v sd#v rtC        t        |      }|
j                  |       |D ]`  }|d   dv s|jD                  |d      }|j                  t9        ||              |jF                  | jH                    |jK                          b t        #fddD              r_|jM                  t        jN                         |jD                  D ]4  \  }}|s	|d   \  }}|jQ                  ||       |jS                  ||       6  |jF                  | jT                    |j/                  | jV                  |z         |j3                          |jD                  D ]9  \  }}|s	|d d D ])  \  }}|jQ                  ||       |jS                  ||       + ;  |jF                  | jX                    |j/                  | jZ                  |z         |j3                          |jD                  D ]  \  }}|s	|dv r |jP                  |d      |dk(  r?|D ]  \  }}|jS                  ||        |j]                           |jP                  |d     d|dk(  ri |jR                  |d     |j]                           |jP                  |d
      |jR                  |d     |j]                           |jP                  |d     Ҍ  |jF                  | j^                    |j/                  | j`                  |z         |j3                          d }|D ]  }|d   dk(  s|d   }tc        | jd                        }tC        t        |      }|
j                  |       tg        |jD                        D ]b  \  }}||   |k(  rti        |      }|j                  t9        ||              |jF                  g || jj                    |jK                          d  |D ]  }|d   dv r|jm                  d      }||d
k(  rd|v rtC        t        |      }|j                  |       to               }tq        |d      }|jD                  ||n||      j                  |       |jD                  |d      d   }|js                           |j$                  |  |j'                  d
|z  d
|z         | ju                  || jv                  | jx                         |j{                          |dk(  s|jm                  d      s| j|                  }n| j~                  }d }d}|js                          |jD                  D ]O  \  }}|dk(  r|d   }||dk(  r|} n|d   } |||k(  r|js                          t        | }t        |  } t        | |z
        }!|j%                  |j                  |j                         |!r|j                  t        j                  | j                  |j                  z
  | j                  |j                  z
               |j'                  d
|z  d
|z         | j                  ||       n6|j'                  d
|z  d
|z         | ju                  || jv                  |       |j{                          | n
d }|d
z  }R |j{                          |d   d k(  s|jm                  d      }tC        t        |      }|j                  |       to               }tq        |d      }|jD                  ||n||      j                  |       |jD                  |d!      d   }|js                           |j$                  |  |j'                  d
|z  d
|z         |r4| j                  || j                  | j                  | j                  "       n(| ju                  || j                  | j                         |j{                           |S )#Nc              3   ,   K   | ]  }|d    dk(    yw)rI   r   Nr"   r   s     r   r   z0InterpolatablePlot.draw_glyph.<locals>.<genexpr>  s     IWWV_0Is   r   rI   c              3   &   K   | ]	  }|d      ywr   r"   r   s     r   r   z0InterpolatablePlot.draw_glyph.<locals>.<genexpr>  r   r   c              3   (   K   | ]	  }|k(    y wr   r"   r   s     r   r   z0InterpolatablePlot.draw_glyph.<locals>.<genexpr>  r   r   mixed)r   r   r   r   r-   rW   r'   	open_pathr   r   r   )r   r   r   c              3   &   K   | ]  }|v  
 y wr   r"   )r   tr  s     r   r   z0InterpolatablePlot.draw_glyph.<locals>.<genexpr>1  s      
 
s   >   r   
node_countnode_incompatibilityr   )moveTolineToqCurveTocurveTor   r   )r   r   F)r   r   r   rK  	closePath)r   r   rJ   )r   r   r   )NrI   r   r   r   r   r   r   r   r   r   r   boundsrP   r   rQ   r   r   r   	translater   border_colorr   r   r   border_widthstroker   r   r   r   r   r   new_pathr   rJ   r   r   r   set_line_capLINE_CAP_ROUNDr:  line_tooncurve_node_coloroncurve_node_diameteroffcurve_node_coloroffcurve_node_diameternew_sub_pathhandle_colorhandle_widthr   r   r   r   r   r   r   r	   saver   r   r   restorer   r   r   r  r  r  rotatemathatan2r   r   r   r   r   r   r   )$r   r   r   r   r  rb   rc   r   r   r   	recordingdecomposedRecording	boundsPenrP  glyph_widthglyph_heightr   penperContourPenr   r   segmentargsmatchingcolorsr   r   idxpointsr  targetPointfirst_pt	second_ptlengthr   r  s$                                     @@r   r   zInterpolatablePlot.draw_glyph  sW
   >$. zHIII{6*D8DD>>>"L# N	

95h?

&'$X.	""9-!!>!FQi&)+ay6!9,}

[0E4;;#=>}l2E4;;#=>=E]]4<<(
Q
ZZ+--2[[<%//14	
 	
fQiZ&),Bt001LLF1I{LId//%78IIK??d//8R(C&&s+<;#>!!!4??3  "  !!!4#4#45!!$"3"3e";<""$KKMM)\]-J4\HUM]+# 6?&CC+11')2DEGNN8Hb#9:&B&&(G(GHGGI  

 
 OOE001 "5!:!: !Bx1

1a 

1a ! B 7 78d885@AIIK "5!:!: % "I %DAqJJq!$JJq!$%% B 8 89d99EABIIK "5!:!:  44BJJQ(
* $ )1

1a()OO%BJJR)	)BJJQ(OO%BJJQ(BJJQ(OO%BJJR)%( B 1 12d//%78IIK 	Gv/1"9-t223 8 8!   /"+M,?,?"@ JAw{a'  LENN8Hb#9:&B&&BBt/A/ABGGI	    l	Gv"BBkk), ?uzi76J$<$x%M (..}=46F 1&% @I!'''/Xc]fY'"(,,wy/A"B1"EKGGI BLL+.HHQYE	2MM!%!@!@">> " 
 JJL A:W[[%< 22E 88E	%8%>%> )MGT(*#'7 ' +-$,	$(G	{a3h	#*H#5$+Y$7	!$Y%9!:X]]HMMB!II $

$-NNX]]$B$-NNX]]$B!" HHQYE	: OOBeO< HHQYE	: MM ")-)H)H&+ * 
 

?!#HFAS)V 

v&(kk), 8 8! $**=902-fe<	##8+;C#OVV %ll77+;<Q?	k*UAI.$$!%!6!6%)%B%B"44	 %  MM!%!5!5"33 " 
 

Yl	\ r   )rb   rc   r   r   c                P   |j                          |j                  |       |j                  t        j                         |j                  ||       |j                  ||       t        |      dk(  r|dz   } |j                  |  |j                          |j                          y )NrW   r'   )r`  r   rV  r   rW  r:  rX  r   r   rT  ra  )r   r   rb   rc   r   r   s         r   r   zInterpolatablePlot.draw_dot  s}    
	
(#
,,-


1a


1au:?DLEE"
		


r   )rb   rc   r   r   r   c                Z   |j                          |j                  |       |j                  t        j                         |j                  |||dz  ddt        j                  z         t        |      dk(  r|dz   } |j                  |  |j                          |j                          y )Nr-   r   rW   rw  )r`  r   rV  r   LINE_CAP_SQUAREarcrc  pir   r   rT  ra  )r   r   rb   rc   r   r   r   s          r   r   zInterpolatablePlot.draw_circle  s     		
,'
--.
q!X\1a$''k2u:?DLEE"
		


r   r   c                   |j                          t        |      dk(  r|dz   } |j                  |  |j                  | j                  |z   |       |j                  dd       |j                  | j                   | j                   dz         |j                  | j                   | j                  dz         |j                          |j                          |j                          y )NrW   rw  r   r6   )
r`  r   r   rQ  r   r:  rX  
close_pathr   ra  )r   r   rb   rc   r   s        r   r   zInterpolatablePlot.draw_arrow  s    
	u:?DLEE"
T,,q0!4


1a


$$$$$$s*	
 	

$$$##c)	
 	
	


r   )rb   rc   r   rP   rQ   c                D   || j                   }|| j                  }|j                         }t        j                  | j
                        } |j                  |  |j                  | j                         |j                  dt        j                  t        j                         d}d}	|j                         }
|
d   }|
d   }|D ].  }|j                  |      }t        ||j                        }|	|z  }	0 |sy |j!                  ||       t#        ||z  ||	z        }|j!                  |||z  z
  dz  ||	|z  z
  dz         |j%                  ||       |j!                  d|       |D ]7  }|j'                  dd       |j)                  |       |j!                  d|       9 y )Nz@cairo:monospacer   r-   )rP   rQ   
splitlinesr   r   r   r   r7  r[   r3  r4  r6  r8  r9  max	x_advancerQ  r   r   r:  r;  )r   textrb   rc   r   rP   rQ   r   
text_widthtext_heightr8  font_line_heightfont_ascentliner>  r   s                   r   	draw_textzInterpolatablePlot.draw_text  s   =JJE>[[F ]]4<<(5!
))*
 7 79Q9Q	
 
('?"1o 	,Dood+GZ):):;J++K	, 
QEJ&(<=
Z%''1,ve8K/Kq.P	
 	
Q$ 	.DJJq!LLLL,-	.r   c           	      F   | j                  | j                         | j                                | j                  | j                  | j
                  | j
                  | j                  | j                         d| j
                  z  z
  dd       | j                  | j                  | j
                  | j
                  | j                  z   | j                         d| j
                  z  z
  | j                         d| j
                  z  z
  | j                  z
  | j                         y )Nr-   r0   T)rb   rc   r   rP   r   rd   )rb   rc   rP   rQ   r   )rR   rY   r\   rr   no_issues_labelrX   no_issues_label_colorr  cupcaker[   cupcake_colorrE   s    r   draw_cupcakezInterpolatablePlot.draw_cupcake=  s    d&&($*;*;*=>  hhhh,,""$q488|3 	 	
 	LLhhhh)))""$q488|3$$&TXX58H8HH$$ 	 	
r   c                 B    | j                  |||| j                         y )Nr   )r  emoticon_color)r   r1  rb   rc   s       r   r   z InterpolatablePlot.draw_emoticonS  s    x11D1DEr   r   )r   r   )>r   r    r!   rP   rQ   rX   r[   rT   r   r   rR  rS  r   r   r   rY  rZ  r[  r\  r^  r_  r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r   r   r   r  r   rF   rL   rR   rU   rY   r\   r   r   r   r   rr   r   r   r   r   r  r  r   r"   r   r   r$   r$   &   s   EF
CKK J!K"LL J"LL)*#LL"2!#,&O%"&WNM!/;O'!MG2 #NEK
J
 C "-	
 (,tt<| -1DD F)P 8<d  !F 6:Dx|	 
*X EFRV GR !"Qi" 
 AY! #$q	 & $%$t $.L
,Fr   r$   c                   ^     e Zd Z eej
                         fd       Zd Zd Z fdZ xZ	S )InterpolatablePostscriptLikec                 $    t        |   |i | y r   superr   r   rm  r@   	__class__s      r   r   z%InterpolatablePostscriptLike.__init__X      $)&)r   c                 8    | j                   j                          y r   )r   finishrH   s       r   rL   z%InterpolatablePostscriptLike.__exit__\  s    r   c                 <    | j                   j                  ||       y r   )r   rR   rO   s      r   rR   z%InterpolatablePostscriptLike.set_size_  s    eV,r   c                 V    t         |           | j                  j                          y r   )r  rU   r   r   r  s    r   rU   z&InterpolatablePostscriptLike.show_pageb  s     r   )
r   r    r!   r   r$   r   rL   rR   rU   __classcell__r  s   @r   r  r  W  s5    
&&'* (*-! !r   r  c                       e Zd Zd Zy)InterpolatablePSc                 z    t        j                  | j                  | j                  | j                        | _        | S r   )r   	PSSurfacer8   rP   rQ   r   rE   s    r   rF   zInterpolatablePS.__enter__h  s'    txxT[[Ir   Nr   r    r!   rF   r"   r   r   r  r  g  s    r   r  c                       e Zd Zd Zy)InterpolatablePDFc                 "   t        j                  | j                  | j                  | j                        | _        | j
                  j                  t         j                  d       | j
                  j                  t         j                  d       | S )Nzfonttools varLib.interpolatable )	r   
PDFSurfacer8   rP   rQ   r   set_metadataPDF_METADATA_CREATORPDF_METADATA_CREATE_DATErE   s    r   rF   zInterpolatablePDF.__enter__n  sc    ''$**dkkJ!!&&(I	
 	!!%"@"@"Er   Nr  r"   r   r   r  r  m  s    r   r  c                   d     e Zd Z eej
                         fd       Zd Zd Zd Z fdZ	 xZ
S )InterpolatableSVGc                 $    t        |   |i | y r   r  r  s      r   r   zInterpolatableSVG.__init__x  r  r   c                     d | _         | S r   )r   rE   s    r   rF   zInterpolatableSVG.__enter__|  s    r   c                 >    | j                   | j                          y y r   )r   rU   rH   s       r   rL   zInterpolatableSVG.__exit__  s    <<#NN $r   c                 n    t               | _        t        j                  | j                  ||      | _        y r   )r   sinkr   
SVGSurfacer   rO   s      r   rR   zInterpolatableSVG.set_size  s%    I	''		5&Ar   c                     t         |           | j                  j                          | j                  j                  | j                  j                                d | _        y r   )r  rU   r   r  r8   r   r  getvaluer  s    r   rU   zInterpolatableSVG.show_page  sB    		**,-r   )r   r    r!   r   r$   r   rF   rL   rR   rU   r  r  s   @r   r  r  w  s;    
&&'* (*B r   r  )%fontTools.ttLibr   fontTools.pens.recordingPenr   r   r   fontTools.pens.boundsPenr   fontTools.pens.cairoPenr   fontTools.pens.pointPenr	   r
   r   fontTools.varLib.interpolatabler   r   r   	itertoolsr   	functoolsr   ior   r   rc  rt   logging	getLoggerr   dictr   r$   r  r  r  r  r"   r   r   <module>r     s    " 
 6 , 
 
      	 g9:%T %nF nFb!!#5 ! 3 4 * r   