
    jke'K                       d Z ddlmZ ddlZddlZddlZddlmZmZm	Z	m
Z
mZmZmZ ddlmZmZmZmZmZmZmZmZmZ ddlmZmZ ddlmZmZmZmZm Z m!Z!m"Z"  ejF                  e$      Z%eeeege&f   Z'	 	 	 	 	 	 	 	 ddZ(d	d	e(f	 	 	 	 	 	 	 	 	 dd
Z)dde(f	 	 	 	 	 	 	 	 	 ddZ*	 	 	 	 ddZ+	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ,ddZ-	 	 	 	 	 	 ddZ.	 	 	 	 	 	 ddZ/y)zAllows building all the variable fonts of a DesignSpace version 5 by
splitting the document into interpolable sub-space, then into each VF.
    )annotationsN)AnyCallableDictIteratorListTuplecast)	AxisDescriptorAxisMappingDescriptorDesignSpaceDocumentDiscreteAxisDescriptorInstanceDescriptorRuleDescriptorSimpleLocationDictSourceDescriptorVariableFontDescriptor)	StatNamesgetStatNames)ConditionSetRangeRegiongetVFUserRegionlocationInRegionregionInRegionuserRegionToDesignRegionc                    |j                   xs |j                  j                  d      }|j                  xs |j                  j                  d      }| d| dS )zDefault callable to synthesize an instance filename
    when makeNames=True, for instances that don't specify an instance name
    in the designspace. This part of the name generation can be overriden
    because it's not specified by the STAT table.
    en-z.ttf)
familyNamefamilyNamesget	styleName
styleNames)docinstance	statNamesr    r#   s        @/usr/lib/python3/dist-packages/fontTools/designspaceLib/split.pydefaultMakeInstanceFilenamer)   )   sY     $$G	(=(=(A(A$(GJ""Di&:&:&>&>t&DI\9+T**    Tc           	   #  "  K   g }i }| j                   D ]x  }t        |d      r"t        t        |      }|j	                  |       1t        t
        |      }t        |j                  |j                  |j                        ||j                  <   z t        j                  |D cg c]  }|j                   c} }|D ]F  }t        ||      D 	
ci c]  \  }	}
|	j                  |
 }}	}
t        | i ||d|||      }||f H yc c}w c c}
}	w w)a  Split the given DS5 into several interpolable sub-designspaces.
    There are as many interpolable sub-spaces as there are combinations of
    discrete axis values.

    E.g. with axes:
        - italic (discrete) Upright or Italic
        - style (discrete) Sans or Serif
        - weight (continuous) 100 to 900

    There are 4 sub-spaces in which the Weight axis should interpolate:
    (Upright, Sans), (Upright, Serif), (Italic, Sans) and (Italic, Serif).

    The sub-designspaces still include the full axis definitions and STAT data,
    but the rules, sources, variable fonts, instances are trimmed down to only
    keep what falls within the interpolable sub-space.

    Args:
      - ``makeNames``: Whether to compute the instance family and style
        names using the STAT data.
      - ``expandLocations``: Whether to turn all locations into "full"
        locations, including implicit default axis values where missing.
      - ``makeInstanceFilename``: Callable to synthesize an instance filename
        when makeNames=True, for instances that don't specify an instance name
        in the designspace. This part of the name generation can be overridden
        because it's not specified by the STAT table.

    .. versionadded:: 5.0
    valuesTkeepVFs	makeNamesexpandLocationsmakeInstanceFilenameN)axeshasattrr
   r   appendr   r   minimummaximumdefaultname	itertoolsproductr,   zip_extractSubSpace)r%   r/   r0   r1   discreteAxesinterpolableUserRegionaxisvalueCombinationsr,   discreteAxisvaluediscreteUserLocationsubDocs                r(   splitInterpolablerE   6   s,    D L%' 4" .5D%-D051"499- "))L+QDDKK+QR# + (+<'@ 
#e u$ 
  
 ">%>)=>+!5
 #F**+ ,R 
s   BD!D4DD	#,DFc           	   #     K   | j                         D ]N  }t        | |      }t        | |d|||      }i |j                  |j                  |_        |j                  |f P yw)a$  Convert each variable font listed in this document into a standalone
    designspace. This can be used to compile all the variable fonts from a
    format 5 designspace using tools that can only deal with 1 VF at a time.

    Args:
      - ``makeNames``: Whether to compute the instance family and style
        names using the STAT data.
      - ``expandLocations``: Whether to turn all locations into "full"
        locations, including implicit default axis values where missing.
      - ``makeInstanceFilename``: Callable to synthesize an instance filename
        when makeNames=True, for instances that don't specify an instance name
        in the designspace. This part of the name generation can be overridden
        because it's not specified by the STAT table.

    .. versionadded:: 5.0
    Fr-   N)getVariableFontsr   r<   libr8   )r%   r/   r0   r1   vfvfUserRegionvfDocs          r(   splitVariableFontsrL   y   sq     . ""$ &sB/ +!5
 ,uyy+BFF+	gguns   A#A%c                n    i }t        |       D ]$  \  }}t        |      D ]  \  }}d|_        |||<    & |S )zConvert each variable font listed in this document into a standalone
    format 4 designspace. This can be used to compile all the variable fonts
    from a format 5 designspace using tools that only know about format 4.

    .. versionadded:: 5.0
    z4.1)rE   rL   formatVersion)r%   vfs	_locationrD   vfNamerK   s         r(   convert5to4rR      sR     C.s3  	6/7 	 MFE"'ECK	   Jr*   c               V    t               } fd} j                  D ]!  }||j                     }	t        |	t              s$t        |d      s1t        t        |      }|j                  t        |j                  |j                  |j                  |j                  t        |	j                  |j                        |	j                  xs |j                  t        |	j                   |j                         |j"                  D 
cg c]+  \  }
}|	j                  |
cxk  r|	j                   k  rn n|
|f- c}}
d d 
             $ g x|_        }|j                  D ch c]  }|j                   c} j$                  D ]  }t'        fd|j(                  j+                         D              s1t'        fd|j,                  j+                         D              s,t.        j1                  d|j(                  |j,                         t3               }|j5                  |j(                  j+                                |j5                  |j,                  j+                                 j                  D ]  }|j                  |vr||j                     }	|	j                  |j                  k7  s?|	j                  |	j                  |j                  k7  s|	j                   |j                   k7  syt.        j1                  d|j                          |j7                  t9        |j(                  |j,                                t;         |      }t=         j>                  |      |_         j@                  |_          jB                  D ]  }tE         jG                  |jH                        |      s)|jK                  tM        |jN                  |jP                  |jR                  |j                  tU        | ||            |jV                  |jX                  |jZ                  |j\                  |j^                  |j`                  	              |jc                         } jc                         }|||jd                  |_2        |r jg                         D ]  }ti         |      }tk        ||      s|jm                  to        |j                  |jN                  |jp                  D cg c]!  }t        ||j                     t              r|# c}|jr                  
               jt                  D ]  }tE        |jw                         |      s |rty         |jw                               }|jX                  xs |jz                  j}                  d      }|jZ                  xs |j~                  j}                  d      }|j                  t        di d|jN                  xs
  | ||      d|jP                  d|jR                  d|j                  xs | d| dri n|j                  dtU        | ||            d|d|d|j                  xs |j                  d|j                  xs |j                  j}                  d      d|j                  xs |j                  d|jd                  xs |jz                  d|j                  xs |j~                  d|j                  xs |j                  d|j                  xs i d|jr                         |j                  t        di d|jN                  d|jP                  d|jR                  d|j                  dri n|j                  dtU        | ||            d|jX                  d|jZ                  d|j                  d|j                  d|j                  d|jd                  d|j                  d|j                  d|j                  d|jr                           jr                  |_9        |S c c}}
w c c}w c c}w )Nc                B    r| j                        S | j                  S N)getFullDesignLocationdesignLocation)objectr%   r0   s    r(   maybeExpandDesignLocationz3_extractSubSpace.<locals>.maybeExpandDesignLocation   s#    //44(((r*   r5   )
tagr8   
labelNameshiddenr5   r7   r6   mapaxisOrdering
axisLabelsc              3  &   K   | ]  }|v  
 y wrU    .0r?   
subDocAxess     r(   	<genexpr>z#_extractSubSpace.<locals>.<genexpr>   s     O$4:%O   c              3  &   K   | ]  }|v  
 y wrU   ra   rb   s     r(   re   z#_extractSubSpace.<locals>.<genexpr>   s     P$4:%Prf   zPIn axis mapping from input %s, some output axes are not in the variable-font: %szALimiting axis ranges used in <mapping> elements not supported: %s)inputLocationoutputLocation)filenamepathfontr8   rW   	layerNamer    r#   muteKerningmuteInfomutedGlyphNames)r8   rj   axisSubsetsrH   r   rj   rk   rl   r8    userLocationrW   r    r#   postScriptFontNamestyleMapFamilyNamestyleMapStyleNamelocalisedFamilyNamelocalisedStyleNamelocalisedStyleMapFamilyNamelocalisedStyleMapStyleNamerH   ra   )Jr   r2   r8   
isinstancer   r3   r
   r   addAxisrZ   r[   r\   maxr5   r7   minr6   r]   axisMappingsallrh   keysri   LOGGERerrorsetupdater4   r   r   _subsetRulesBasedOnConditionsrulesrulesProcessingLastsourcesr   map_backwardrW   	addSourcer   rj   rk   rl   _filterLocationrm   r    r#   rn   ro   rp   findDefaultrw   rG   r   r   addVariableFontr   rq   rH   	instancesgetFullUserLocationr   r!   r"   r$   addInstancer   rs   rt   ru   styleMapFamilyNamesrv   rx   ry   rz   )r%   
userRegionr.   r/   r0   r1   rD   rY   r?   rangeuserdesignmappingsmappingmappingAxesdesignRegionsource	vfDefault
oldDefaultrI   rJ   
axisSubsetr&   r'   r    r#   rd   s   `   `                     @r(   r<   r<      s    !"F)  499%eU#i(@ -DNN#;;t||<!MM9T\\t||< -1HH(D& ==DAEMMA v "&##: &('F((.4$))4J## "
O'2G2G2L2L2NOOP'2H2H2M2M2OPPLLb%%&&
 e70055787116689HH 	Dyy+tyy)E-MM-%--4<<2O==DLL0WII 	 	!%33&55	
;"
P ,C<L0LIFL!$!8!8F ++ 
 0 01F1F GT[[[[[[. 9& A  !**!,, **".. & 6 6	
	
. ""$I"J!7(2(F(F	% &&( 	B*33LlJ7&&*WW!# /1nn% *)*Z__*EuM '%
 FF		" MM < < <S A:N$S(*F*Fs*KLI!,,O	0E0E0I0I$0OJ **Li.B.B.F.Ft.LI" %.. F+C9E " "	
 "EZL)*E (7H<Q<Q $3"$=h$G$  * ( (0'B'B (4 33 (0'B'B (? 4488>  '/&@&@ '3 22#$ )1(D(D )- ,,'( (0'B'B (, +++, 190T0T 15 44/0 08/R/R 034 !5> " %..! " "	
 (7H<Q<Q $3"$=h$G$  (22 '00 (0'B'B (0'B'B '/&@&@ )1(D(D (0'B'B  190T0T!" 08/R/R#$ !%O<| FJMU 5h%s   0``!&`&c                    i }| D ][  }|j                  d      |j                  d      }}t        ||nt        j                   ||nt        j                        ||d   <   ] |S )Nr5   r6   r8   )r"   r   mathinf)conditionSetc	conditionr5   r6   s        r(   _conditionSetFromr     sj    A! 
	$==3Y]]95M$*G	*G 
)F

 Hr*   c           	     (   g }| D ]	  }t        |j                  g |j                        }|j                  D ]  }t	        |      }g }d}|j                         D ]u  \  }	}
|	|vrt        |
t        t        f      r|
||	   v r)d},|
||	   v r4||	   j                  |
      }|*|j                  |	|j                  |j                  d       td}w |r|j                  j                  |        |j                  s|j                  |        |S )N)r8   conditionSetssubsFT)r8   r5   r6   )r   r8   r   r   r   itemsr{   floatintintersectionr4   r5   r6   )r   r   newRulesrulenewRuleconditionsetcsnewConditionsetdiscardConditionsetselectionNameselectionValuer   s               r(   r   r     sC   $ &(H )%"0"499#
 !.. #	>L"<0B46O"'1=1C1C1E 7-~ *nucl;%M):: /3+ &M)::')-'8'E'En'U'3+22,9/;/C/C/;/C/C!" 37/;7< '%%,,_=G#	>H   OOG$S)%V Or*   c                    |j                         D ci c]  \  }}|| v rt        | |   t              r||! c}}S c c}}w rU   )r   r{   r   )r   locationr8   rB   s       r(   r   r     sI     $>>+D%:*Z-=u"E 	e  s   $<)r%   r   r&   r   r'   r   returnstr)
r%   r   r/   boolr0   r   r1   MakeInstanceFilenameCallabler   z8Iterator[Tuple[SimpleLocationDict, DesignSpaceDocument]])
r%   r   r/   r   r0   r   r1   r   r   z)Iterator[Tuple[str, DesignSpaceDocument]])r%   r   r   zDict[str, DesignSpaceDocument])r%   r   r   r   r.   r   r/   r   r0   r   r1   r   r   r   )r   zList[Dict[str, Any]]r   r   )r   List[RuleDescriptor]r   r   r   r   )r   r   r   Dict[str, float]r   r   )0__doc__
__future__r   r9   loggingr   typingr   r   r   r   r   r	   r
   fontTools.designspaceLibr   r   r   r   r   r   r   r   r   "fontTools.designspaceLib.statNamesr   r   fontTools.designspaceLib.typesr   r   r   r   r   r   r   	getLogger__name__r   r   r   r)   rE   rL   rR   r<   r   r   r   ra   r*   r(   <module>r      s   #    C C C
 
 
 G   
		8	$',i8#=  

+	
+(:
+GP
+
+  9T	@+	@+@+ @+ 7	@+
 >@+J !9T	"	"" " 7	"
 /"J	#"U	UU 	U
 U U 7U Up>>/5>>B r*   