
    Bh4D                        S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSKJr  SSKJrJrJr  SS	KJrJr  S
SKJr  S
SKJrJr  SSKJrJrJrJrJrJrJ r J!r!J"r"J#r#  SSK$J%r%J&r&J$r$J'r'J(r(J)r)J*r*J+r+J,r,  S r-\-" \$R\                  " \'R^                  " 5       \'R`                  5      5         " S S5      r1    SS jr2S r3S r4SS jr5S r6g)zIInterface with external libraries managing fonts installed on the system.    )md5)BytesIO)Path)rmtree)mkdtemp)warn)Element
SubElementtostring)TTFontwoff2   )LOGGER)FILESYSTEM_ENCODINGfetch   )
	CAPS_KEYSEAST_ASIAN_KEYSFONTCONFIG_STRETCHFONTCONFIG_STYLEFONTCONFIG_WEIGHTLIGATURE_KEYSNUMERIC_KEYSPANGO_STRETCHPANGO_STYLEPANGO_VARIANT)	
FROM_UNITSTO_UNITSffi
fontconfiggobjectharfbuzzpangopangoft2unicode_to_char_pc                    [         R                  " U [         R                  5      nUR                  S:  a  g[         R                  " U 5      n[         R
                  " U5      nU[        R                  :X  a  [        S5        g[        S5        g)uF  Check whether the given font_config has fonts.

The default fontconfig configuration file may be missing (particularly
on Windows or macOS, where installation of fontconfig isn't as
standardized as on Linux), resulting in "Fontconfig error: Cannot load
default config file".

Fontconfig tries to retrieve the system fonts as fallback, which may or
may not work, especially on macOS, where fonts can be installed at
various loactions. On Windows (at least since fontconfig 2.13) the
fallback seems to work.

If there’s no default configuration and the system fonts fallback
fails, or if the configuration file exists but doesn’t provide fonts,
output will be ugly.

If you happen to have no fonts and an HTML document without a valid
@font-face, all letters turn into rectangles.

If you happen to have an HTML document with at least one valid
@font-face, all text is styled with that font.

On Windows and macOS we can cause Pango to use native font rendering
instead of rendering fonts with FreeType. But then we must do without
@font-face. Expect other missing features and ugly output.

r   Nz?FontConfig cannot load default config file. Expect ugly output.z6No fonts configured in FontConfig. Expect ugly output.)	r    FcConfigGetFontsFcSetSystemnfontFcConfigGetConfigFilesFcStrListNextr   NULLr   )font_configfontsconfig_filesconfig_files       G/var/www/html/env/lib/python3.13/site-packages/weasyprint/text/fonts.py_check_font_configurationr2      sl    > ''Z5K5KLE{{Q 44[AL**<8KchhNO 	EF    c                   .    \ rS rSrSrSrS rS rS rSr	g)FontConfigurationJ   aw  A Fontconfig font configuration.

Keep a list of fonts, including fonts installed on the system, fonts
installed for the current user, and fonts referenced by cascading
stylesheets.

When created, an instance of this class gathers available fonts. It can
then be given to :class:`weasyprint.HTML` methods or to
:class:`weasyprint.CSS` to find fonts in ``@font-face`` rules.

Nc                    [         R                  " [        R                  " 5       [        R                  5      U l        [         R                  " [        R                  " 5       [        R                  5      U l
        [        R                  " [         R                  " SU R                  5      U R
                  5        [        R                  " U R
                  5        SU l        g)zCreate a Fontconfig font configuration.

See Behdad's blog:
https://mces.blogspot.fr/2015/05/how-to-use-custom-application-fonts.html

PangoFcFontMap *N)r   gcr    FcInitLoadConfigAndFontsFcConfigDestroy_configr$   pango_ft2_font_map_newr!   g_object_unreffont_mappango_fc_font_map_set_configcast_folderselfs    r1   __init__FontConfiguration.__init__X   s     vv//1:3M3MO++-w/E/EG--HH'7	G 	""4<<0 r3   c           	         [        U5      n[        UR                  5       SS9R                  5       nU R                  c  [        [        SS95      U l        U R                  U-  nUR                  5       (       a  g[        R                  " S5      nUS    GH  u  pxUb  US:X  a  M  US	:X  Ga  UR                  5       n	[        R                  " [        R                  " 5       [        R                  5      n
[        R                  " U R                  U
[        R                   5        [        R"                  " U
5        [        R$                  " U
S
U	5        [        R$                  " U
SU	5        [        R                  " S5      n[        R&                  " U R                  X5      nU[        R(                  :X  a  [*        R,                  " SU5        GM;  S H  n[        R.                  " XSU5        [        R0                  " US   5      nU	R3                  5       UR3                  5       :X  d  MX  [        R.                  " USSU5        [        R0                  " US   5      R5                  [6        5      n[        U5      R9                  5       n  O*   [*        R,                  " SU	R5                  5       5        GM   [;        X(5       nSU;   nU(       a  US   OUS   R=                  5       nSSS5         WSS S:X  a  [A        5       nUSS nUS:X  a4  [C        [A        U5      5      nS=Ul"        Ul#        URI                  U5        O&US:X  a   [J        RL                  " [A        U5      U5        URO                  5       nURQ                  U5        Sn[S        S5      n[U        USSS9n[U        US S!S"S#9n[        U5      [U        US5      l+        [U        US$S%US&9nUS'   [U        US5      l+        S(U;   a)  [U        US$S)US&9n[X        US(      nU[U        US*5      l+        S+U;   a2  [U        US$S,US&9n[Z        US+      n[        U5      [U        US-5      l+        S.U;   a)  [U        US$S/US&9n[\        US.      nU[U        US*5      l+        [U        USS0S9n[U        US S!S"S#9n[        U5      [U        US5      l+        UR_                  S1/ 5       Vs0 s H"  nUS   S   Ra                  S2S35      US   S4   _M$     nnUR_                  S5S65      n[c        SGS5U0UD6n U (       a<  [U        US$S7US&9nU Re                  5        H  u  n!n"U! S8U" 3[U        US5      l+        M     UR_                  S95      =n#(       am  [U        US$S:US&9n[U        US;5      n$U# HO  n%[U        U$S:5      n&[U        U&S<5      n'U%Rf                  U%Rh                  4 H  n"S=U"S> 3[U        U'S-5      l+        M     MQ     S?n(S@Rk                  / U(Q[m        USASB9P75      n)[        Rn                  " U R                  U)SC5        [        Rp                  " U R                  [        U5      R                  [6        5      5      n*U*(       a7  [r        Rt                  " [        Rv                  " SDU Rx                  5      5      s  $ [*        R,                  " SEU5        GM     [*        Rz                  " SFUS'   5        g! , (       d  f       GN= f! [>         a$  n[*        R,                  " SUU5         SnAGMl  SnAff = f! [>         a$  n[*        R,                  " SUU5         SnAGM  SnAff = fs  snf )Hz0Add a font face to the Fontconfig configuration.F)usedforsecurityNzweasyprint-)prefixz
FcChar8 **srcinternallocal   fullname   postscriptnamez
FcResult *z(Failed to get matching local font for %r)rM   rN   r   s   filezFailed to load local font %rstringfile_objzFailed to load font at %r (%s)   s   wOF      F   2z%Failed to handle woff font at %r (%s)assign_replacer    matchscan)targettestfileeq)namecompareeditfamily)r\   modefont_family
font_styleslantconstfont_weightweightintfont_stretchwidthfontfont_variant-_r   font_feature_settingsnormalfontfeatures unicode_rangecharsetplusrange0xx)s   <?xml version="1.0"?>s7   <!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">   
zutf-8)encodingTr8   zFailed to load font at %rzFont-face %r cannot be loaded )>strr   encode	hexdigestrB   r   r   existsr   newr9   r    FcPatternCreateFcPatternDestroyFcConfigSubstituter<   FcMatchFontFcDefaultSubstituteFcPatternAddStringFcFontMatchr,   r   debugFcPatternGetStringrO   lowerdecoder   as_urir   read	Exceptionr   r   flavor
flavorDatasaver   
decompressgetvaluewrite_bytesr	   r
   textr   r   r   getreplacefont_featuresitemsstartendjoinr   FcConfigParseAndLoadFromMemoryFcConfigAppFontAddFiler$    pango_fc_font_map_config_changedrA   r?   warning)+rD   rule_descriptorsurl_fetcher
config_keyconfig_digest	font_pathrO   	font_typeurl	font_namepatternresultmatching_patterntagr\   pathrj   	exceptionoutwoff_version_bytettfontexcr`   rootrV   rY   r^   r   integerrulesdescriptorssettingsfeatureskeyvalueunicode_rangesrt   rr   rs   range_headerxml
font_addeds+                                              r1   add_font_faceFontConfiguration.add_font_facel   sy    )*
J--/GQQS<<} =>DLLL=0	 &.u5NI{i:5 G#JJL	&&..0*2M2MO--LL':+A+AC..w7--g{IN--g7H)T.#-#9#9$,,#X #sxx/LL!KSQ :C112BFS::fQi0D (DJJL8"55,gq&B"zz&)4;;<OP"4j//1 : LL!?AQAQAST;,%/F/56(+6*;M;R;R;TD -8v%!)C(,Qq	%(D0!'!6<@@(9C(*d2((<<<>D !!$' $D<(DtWV<EeV&$GD.1)nJtX&+eV(FD.>}.MJtX&+//!%gDI'(8(FG15
4). 00!%hTJ+,<],KL/27|
4',!11!%gDI)*:>*JK15
4).tWV<EeV&$GD.1)nJtX&+ !$$^R8:8 @Ea##C-uQx{:8  : (++,CXNH$S8S{SH!%n4P"*.."2JC9<Qug6FJtX.3 #3!1!5!5o!FF~F!%idK!$/%3M(y9G'9F"/"5"5}7H7H!I;=eAY
6516 "J &4
LF **HvHxw'GHIC
 55dllCN#::c)n334GHJJ@@HH/?A ALL4c:o 6p 	68H8WXa -,  =sIN"  Dc3O8:sU   6[%[&[/B\
)\;
[	[[
\#\\

\8\33\8c                 P    U R                   (       a  [        U R                   SS9  gg)z*Clean a font configuration for a document.T)ignore_errorsN)rB   r   rC   s    r1   __del__FontConfiguration.__del__   s    <<4<<t4 r3   )r<   rB   r?   )
__name__
__module____qualname____firstlineno____doc__rB   rE   r   r   __static_attributes__rz   r3   r1   r5   r5   J   s     
 G(GYR5r3   r5   c                 L   0 nU S:w  a  [        U S:H  5      US'   US:X  a*  [        R                  " 5        H  n	U	 H  n
SX'   M	     M     OBUS:w  a<  U H6  nSnUR                  S5      (       a  SnUSS	 n[        U    H  n
XU
'   M	     M8     US
:X  a  SUS'   OUS:X  a  SUS'   US:w  a  [        U    H  n
SX'   M	     US:w  a  U H  n
SU[
        U
   '   M     US:w  a  US:X  a  SUS'   US:w  a  U H  n
SU[        U
   '   M     US:w  a  UR                  [        U5      5        U$ )zzGet the font features from the different properties in style.

See https://www.w3.org/TR/css-fonts-3/#feature-precedence

autoro   kernnoner   r   zno-rQ   Nsubsubssupersupszhistorical-formshist)	rg   r   values
startswithr   r   r   updatedict)font_kerningfont_variant_ligaturesfont_variant_positionfont_variant_capsfont_variant_numericfont_variant_alternatesfont_variant_east_asianrn   r   keysr   ligature_typer   s                r1   r   r      sq    H v|x78'!((*D !  + 
 8	+3ME''.. -ab 1$]3 % 4 4 % 	'	)H$ ./CHM 0 x''C*+H\#&' ( (* #&88 HV(**C-.H_S)* + (234Or3   c                    [         R                  " [        R                  " 5       [        R                  5      n[        SR                  U S   5      5      u  p#[        R                  " X5        [        U S      n[        R                  " X5        [        U S      n[        R                  " X5        U S   n[        R                  " X5        [        U S   [        -  5      n[        R                  " X5        [         U S      n[        R"                  " X5        U S   S	:w  a?  SR                  S
 U S    5       5      R%                  5       n	[        R&                  " X5        U$ )z/Get font description string out of given style.,ra   rb   rh   re   	font_sizer   font_variation_settingsro   c              3   4   #    U  H  u  pU S U 3v   M     g7f)=Nrz   ).0r   r   s      r1   	<genexpr>'get_font_description.<locals>.<genexpr>R  s$      ., ",se1UG,s   )r   r9   r#   pango_font_description_newpango_font_description_freer%   r   !pango_font_description_set_familyr    pango_font_description_set_styler   "pango_font_description_set_stretch!pango_font_description_set_weightrg   r   (pango_font_description_set_absolute_sizer   "pango_font_description_set_variantr|   %pango_font_description_set_variations)
stylefont_descriptionfamily_pr_   rb   rh   re   r   rk   rO   s
             r1   get_font_descriptionr   A  s7   vv((*E,M,MO(%2F)GHH	++,<GU<01J	**+;H ~!67L	,,-=L&K	++,<JE+&12I	223CO ':!;<L	,,-=L&'83 .+,. ..4fh 	 	334DMr3   c                     [         R                  " SU 5      n[         R                  " S[        R                  " U 5      5      n[        R
                  " X!5      $ )z*Get Harfbuzz face out of given Pango font.zPangoFcFont *r8   )r   rA   r#   pango_font_get_font_mapr$   pango_fc_font_map_get_hb_face)
pango_fontfc_fontfontmaps      r1   get_pango_font_hb_facer   Y  s?    hh
3Ghh)5+H+H+TUG11'CCr3   Nc                    US:X  a  [         R                  " X5      nO3US:X  a  [         R                  " X5      nO[         R                  " U 5      n[        R
                  " S5       n[         R                  " X45      nU[        R                  :X  a  SO"[        R                  " U[        US   5      5      n[         R                  " U5        UsSSS5        $ ! , (       d  f       g= f)u   Get binary data out of given Harfbuzz font or face.

If ``ot_color`` is 'svg', return the SVG color glyph reference. If it’s 'png',
return the PNG color glyph reference. Otherwise, return the whole face blob.

pngsvgzunsigned int *Nr   )r"   hb_ot_color_glyph_reference_pnghb_ot_color_glyph_reference_svghb_face_reference_blobr   r   hb_blob_get_datar,   unpackrg   hb_blob_destroy)	hb_objectot_colorglyphhb_bloblengthhb_datadatas          r1   get_hb_object_datar  `  s     5::9L	U	::9L11)<	!	"f++G<#((*t

7Cq	N0S  )	 
#	"	"s   'A'C
C&c                 L   [         R                  " [        R                  " U 5      [        R                  5      n[        R
                  " U5      [        -  n[        R                  [        R                  -   n[        R                  " X5        [        R                  " U5      X4$ )z*Get key corresponding to given Pango font.)r   r9   r#   pango_font_describer   pango_font_description_get_sizer   PANGO_FONT_MASK_SIZEPANGO_FONT_MASK_GRAVITY#pango_font_description_unset_fieldspango_font_description_hash)r   descriptionr   masks       r1   get_pango_font_keyr  t  sx     &&!!*-u/P/PRK55kBZOI%%(E(EED	--k@,,[9;QQr3   )ro   ro   ro   ro   ro   ro   ro   ro   )NN)7r   hashlibr   ior   pathlibr   shutilr   tempfiler   warningsr   xml.etree.ElementTreer	   r
   r   fontTools.ttLibr   r   loggerr   urlsr   r   	constantsr   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r2   r9   r:   r;   r5   r   r   r   r  r  rz   r3   r1   <module>r$     s    O       ? ? )  -L L L  
+G\ #&&''):+E+EG Hn5 n5b AIDLIQJRCL0D(Rr3   