
    ]Mh'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j#        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*d0dZ+d1d!Z,d2d%Z-d3d)Z.d4d,Z/dS )5zAllows 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userRegionToDesignRegiondocr   instancer   	statNamesr   returnstrc                    |j         p|j                            d          }|j        p|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)r   r   r   r%   r(   s        ^/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/fontTools/designspaceLib/split.pydefaultMakeInstanceFilenamer+   )   sW     $G	(=(A(A$(G(GJ"Di&:&>&>t&D&DI**9****    T	makeNamesboolexpandLocationsmakeInstanceFilenameMakeInstanceFilenameCallable8Iterator[Tuple[SimpleLocationDict, DesignSpaceDocument]]c           	   #    K   g }i }| j         D ]z}t          |d          r+t          t          |          }|                    |           =t          t
          |          }t          |j        |j        |j	                  ||j
        <   {t          j        d |D              }|D ];}d t          ||          D             }	t          | i ||	d|||          }
|	|
fV  <dS )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
    valuesc                    g | ]	}|j         
S  )r4   .0axiss     r*   
<listcomp>z%splitInterpolable.<locals>.<listcomp>h   s    +Q+Q+QDDK+Q+Q+Qr,   c                $    i | ]\  }}|j         |S r6   name)r8   discreteAxisvalues      r*   
<dictcomp>z%splitInterpolable.<locals>.<dictcomp>j   s1      
  
  
#e u 
  
  
r,   TkeepVFsr-   r/   r0   N)axeshasattrr
   r   appendr   r   minimummaximumdefaultr=   	itertoolsproductzip_extractSubSpace)r   r-   r/   r0   discreteAxesinterpolableUserRegionr9   valueCombinationsr4   discreteUserLocationsubDocs              r*   splitInterpolablerR   6   sC     D L%'  4"" 	 .55D%%%%--D051 1"49--
 ")+Q+QL+Q+Q+QR# + + 
  
'*<'@'@ 
  
  
 ">%>)=>+!5
 
 
 #F*****+ +r,   F)Iterator[Tuple[str, DesignSpaceDocument]]c           	   #     K   |                                  D ]G}t          | |          }t          | |d|||          }i |j        |j        |_        |j        |fV  HdS )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
    FrA   N)getVariableFontsr   rL   libr=   )r   r-   r/   r0   vfvfUserRegionvfDocs          r*   splitVariableFontsrZ   y   s      . ""$$  &sB// +!5
 
 
 ,uy+BF+	gun r,   Dict[str, DesignSpaceDocument]c                v    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)rR   rZ   formatVersion)r   vfs	_locationrQ   vfNamerY   s         r*   convert5to4ra      s_     C.s33    	6/77 	  	 MFE"'ECKK	  Jr,   
userRegionr   rB   c               H    t                      } fd} j        D ]}|j                 t          t                    rt          |d          rt          t          |          }|                    t          |j	        |j        |j
        |j        t          j        |j                  j        p|j        t          j        |j                  fd|j        D             d d 
  
                   g x|_        }	d |j        D              j        D ]}
t'          fd|
j                                        D                       s6t'          fd|
j                                        D                       s't.                              d|
j        |
j                   t3                      }|                    |
j                                                   |                    |
j                                                    j        D ]q}|j        |vr|j                 j        |j        k    s'j        j        |j        k    sj        |j        k    r!t.                              d	|j                   qr|	                    t9          |
j        |
j        
                     t;                     }t=           j        |          |_         j         |_          j!        D ]}tE           #                    |j$                            s+|%                    tM          |j'        |j(        |j)        |j        tU           ||                    |j+        |j,        |j-        |j.        |j/        |j0                             |1                                } 1                                }|||j2        |_2        |r} 3                                D ]h}ti           |          }tk          |          rF|6                    to          |j        |j'        fd|j8        D             |j9                             i j:        D ]@}tE          |;                                         s'|rcty           |;                                         }|j,        p|j=        >                    d          }|j-        p|j?        >                    d          }|@                    t          d i d|j'        p | ||          d|j(        d|j)        d|j        p| d| dri n|jB        dtU           ||                    d|d|d|jC        p|jC        d|jD        p|jE        >                    d          d|jF        p|jF        d|j2        p|j=        d|jG        p|j?        d|jH        p|jE        d|jI        pi d|j9                   |@                    t          d i d|j'        d|j(        d|j)        d|j        dri n|jB        dtU           ||                    d|j,        d|j-        d|jC        d|jD        d|jF        d|j2        d|jG        d|jH        d|jI        d|j9                   B j9        |_9        |S )!Nc                @    r|                                S | j        S N)getFullDesignLocationdesignLocation)objectr   r/   s    r*   maybeExpandDesignLocationz3_extractSubSpace.<locals>.maybeExpandDesignLocation   s(     	)//444((r,   rF   c                R    g | ]#\  }}j         |cxk    rj        k    n n||f$S r6   )rF   rG   )r8   userdesignranges      r*   r:   z$_extractSubSpace.<locals>.<listcomp>   sQ       (D& =DAAAAEMAAAAA vAAAr,   )
tagr=   
labelNameshiddenrF   rH   rG   mapaxisOrdering
axisLabelsc                    h | ]	}|j         
S r6   r<   r7   s     r*   	<setcomp>z#_extractSubSpace.<locals>.<setcomp>   s    444$)444r,   c              3      K   | ]}|v V  	d S re   r6   r8   r9   
subDocAxess     r*   	<genexpr>z#_extractSubSpace.<locals>.<genexpr>   s(      OO$4:%OOOOOOr,   c              3      K   | ]}|v V  	d S re   r6   rw   s     r*   ry   z#_extractSubSpace.<locals>.<genexpr>   s(      PP$4:%PPPPPPr,   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fontr=   rg   	layerNamer%   r(   muteKerningmuteInfomutedGlyphNamesc                T    g | ]$}t          |j                 t                    "|%S r6   )
isinstancer=   r   )r8   
axisSubsetrb   s     r*   r:   z$_extractSubSpace.<locals>.<listcomp>:  s@     % % % *)*Z_*EuMM%&% % %r,   )r=   r}   axisSubsetsrV   r#   r}   r~   r   r=    userLocationrg   r%   r(   postScriptFontNamestyleMapFamilyNamestyleMapStyleNamelocalisedFamilyNamelocalisedStyleNamelocalisedStyleMapFamilyNamelocalisedStyleMapStyleNamerV   r6   )Jr   rC   r=   r   r   rD   r
   r   addAxisrn   ro   rp   maxrF   rH   minrG   rq   axisMappingsallr{   keysr|   LOGGERerrorsetupdaterE   r   r   _subsetRulesBasedOnConditionsrulesrulesProcessingLastsourcesr   map_backwardrg   	addSourcer   r}   r~   r   _filterLocationr   r%   r(   r   r   r   findDefaultr   rU   r   r   addVariableFontr   r   rV   	instancesgetFullUserLocationr   r&   r'   r)   addInstancer   r   r   r   styleMapFamilyNamesr   r   r   r   )r   rb   rB   r-   r/   r0   rQ   ri   r9   mappingsmappingmappingAxesdesignRegionsource	vfDefault
oldDefaultrW   rX   r   r   r%   r(   rm   rx   s   ``  `                 @@r*   rL   rL      sk    !""F) ) ) ) ) )   49%eU## 	i(@(@ 	 --DNN#;t|<<!M9T\t|<<   ,0H   "&##    , &('F(44444J# "
 "
OOOO'2G2L2L2N2NOOOOO 	PPPP'2H2M2M2O2OPPPPP 	LLb%&  
 ee705577888716688999H 	 	Dy++ty)E--M-%-4<2O2O=DL00WI    1 	!%3&5  	
 	
 	
 	
 ,C<<L0LIIFL!$!8F + 
 
 0 01F G GTT 	[[[. 9 9& A A    !*!, *". & 6  	
 	
 	
 	
& ""$$I""J!7(2(F	%  &&(( 	 	B*333LlJ77 &&*W!#% % % %.0n% % %
 F	 	 	   M < < < <S A A:NN 	 8	$S(*F*Fs*K*KLLI!,O	0E0I0I$0O0OJ *Li.B.F.Ft.L.LI"   %. F++C9EE " "	
 "EZ*E*E)*E*E (7!QH<Q $3"$=$=h$G$G$ $ $  *z (i (0'B (4 3 (0'B (? 488>>  '/&@ '3 2#$ )1(D )- ,'( (0'B (, ++, 190T 15 4/0 08/R 034 !5   > "   %..! " "	
 (7!QH<Q $3"$=$=h$G$G$ $ $  (22 '00 (0'B'B (0'B'B '/&@&@ )1(D(D (0'B'B  190T0T!" 08/R/R#$ !%   . FJMr,   conditionSetList[Dict[str, Any]]r   c                    i }| D ]b}|                     d          |                     d          }}t          ||nt          j         ||nt          j                  ||d         <   c|S )NrF   rG   r=   )r'   r   mathinf)r   c	conditionrF   rG   s        r*   _conditionSetFromr     sx    A! 
 
	$==33Y]]95M5M$*GG	*GG 
  
)F
 Hr,   r   List[RuleDescriptor]r   c           	     (   g }| D ]}t          |j        g |j                  }|j        D ]}t	          |          }g }d}|                                D ]\  }	}
|	|vr
t          |
t          t          f          r|
||	         v r1d}4|
||	         v r?||	         	                    |
          }|$|
                    |	|j        |j        d           d}|s|j        
                    |           |j        r|
                    |           |S )N)r=   conditionSetssubsFT)r=   rF   rG   )r   r=   r   r   r   itemsr   floatintintersectionrE   rF   rG   )r   r   newRulesrulenewRuleconditionsetcsnewConditionsetdiscardConditionsetselectionNameselectionValuer   s               r*   r   r     s|   $ &(H )% )%"0"49#
 #
 #
 !. #	> #	>L"<00B46O"'1=1C1C1E1E 7 7-~ **nucl;; 7%M)::: /3++ &M):::')-'8'E'En'U'U'3+22,9/;/C/;/C!" !"    37//& >%,,_===  	%OOG$$$Or,   locationDict[str, float]c                D      fd|                                 D             S )Nc                Z    i | ]'\  }}|v 	t          |         t                    $||(S r6   )r   r   )r8   r=   r?   rb   s      r*   r@   z#_filterLocation.<locals>.<dictcomp>  sH       D%:*Z-=u"E"E 	er,   )r   )rb   r   s   ` r*   r   r     s8       #>>++   r,   )r   r   r   r   r   r   r    r!   )
r   r   r-   r.   r/   r.   r0   r1   r    r2   )
r   r   r-   r.   r/   r.   r0   r1   r    rS   )r   r   r    r[   )r   r   rb   r   rB   r.   r-   r.   r/   r.   r0   r1   r    r   )r   r   r    r   )r   r   r   r   r    r   )rb   r   r   r   r    r   )0__doc__
__future__r   rI   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!   r1   r+   rR   rZ   ra   rL   r   r   r   r6   r,   r*   <module>r      s`    # " " " " "       C C C C C C C C C C C C C C C C C C
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 G F F F F F F F                  
	8	$	$',i8#=  

+ 
+ 
+ 
+  9T	@+ @+ @+ @+ @+J !9T	" " " " "J   "U U U Up   > > > >B     r,   