
    \
jaE                     H   d Z ddlmZ dZddgZdZdZ G d d	          Zg a	 dd
l	Z	ddl	m
Z
 ddlmZmZ e	j        j        Ze	j        j        Ze	j        ZeZe	j        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(i Z) e*            +                                ,                                D ]\  Z-Z.e-/                    d          re-e)e.<    dZ0dZ1dZ2dZ3dZ4dZ5d Z6d!Z7d"Z8 G d# d$e	j9                  Z: G d% d&e	j9                  Z; G d' d(e	j9                  Z< G d) d*e	j9                  Z= G d+ d,e	j9                  Z> e	j?        e	j@         e	jA        e           e	jA        e=          e
jB        e
jC                  ZD e	j?        e	j@         e	jA        e           e	jA        e>          e
jB        e
jC                  ZEe
jF         e	jA        e          eDe
jC        e
jB        gejG        _H        e
jF         e	jA        e          eEe
jC        e
jB        gejI        _H        d- ZJ eEeJ          ZKefd.ZLdDd/ZMdEd0ZNeOd1k    r`dd
lPZPePjQ        dd
         d2gk    rd3ZePjQ        dd
         d4gk    ser eRd5            eMd6          ZS eRd7eSz              eRd8 eMd9          z              ed:dd;de6          ga eMd6          eSk    sJ  eMd6d3<          eSk    sJ es ePjT                     ePjQ        dd
         d=gk    r eNd3>          ZUnNePjQ        dd
         d?gk    r eNd3@          ZUn-ePjQ        dd
         d=d?gk    r eNd3d3A          ZUn
 eN            ZU eRdBV                    eU                     er# eRdC eW eN                      z             d
S d
S d
S )Fa	  
Query system Windows fonts with pure Python.

Public domain work by anatoly techtonik <techtonik@gmail.com>
Use MIT License if public domain doesn't make sense for you.



The task: Get monospace font for an application in the order of
preference.

A problem: Font ID in Windows is its name. Windows doesn't provide
any information about filenames they contained in. From two different
files with the same font name you can get only one.

Windows also doesn't have a clear concept of _generic font family_
familiar from CSS specification. Here is how fontquery maps Windows
LOGFONT properties to generic CSS font families:

  serif      -   (LOGFONT.lfPitchAndFamily >> 4) == FF_ROMAN
  sans-serif -   (LOGFONT.lfPitchAndFamily >> 4) == FF_SWISS
  cursive    -   (LOGFONT.lfPitchAndFamily >> 4) == FF_SCRIPT
  fantasy    -   (LOGFONT.lfPitchAndFamily >> 4) == FF_DECORATIVE
  monospace  -   (lf.lfPitchAndFamily & 0b11) == FIXED_PITCH

NOTE: ATM, May 2015, the Microsoft documentation related to monospace
is misleading due to poor wording:
 - FF_MODERN in the description of LOGFONT structure tells
   "Fonts with constant stroke width (monospace), with or without serifs.
    Monospace fonts are usually modern.
    Pica, Elite, and CourierNew are examples.
   "
   
   Stroke width is the 'pen width', not glyph width. It should read

   "Fonts with constant stroke width, with or without serifs.
    Monospace fonts are usually modern, but not all modern are monospace
   "

PYGLET NOTE:
Examination of all fonts in a windows xp machine shows that all fonts
with

  fontentry.vector and fontentry.family != FF_DONTCARE

are rendered fine.


Use cases:
 [x] get the list of all available system font names
 [ ] get the list of all fonts for generic family
 [ ] get the list of all fonts for specific charset
 [ ] check if specific font is available

Considerations:
 - performance of querying all system fonts is not measured
 - Windows doesn't allow to get filenames of the fonts, so if there
   are two fonts with the same name, one will be missing

MSDN:

    If you request a font named Palatino, but no such font is available
on the system, the font mapper will substitute a font that has similar
attributes but a different name.

   [ ] check if font chosen by the system has required family

    To get the appropriate font, call EnumFontFamiliesEx with the
desired font characteristics in the LOGFONT structure, then retrieve the
appropriate typeface name and create the font using CreateFont or
CreateFontIndirect.

    )device_contextF	have_font	font_listz0.3z)https://bitbucket.org/techtonik/fontqueryc                       e Zd ZdZd ZdS )	FontEntryz
    Font classification.
    Level 0:
    - name
    - vector (True if font is vector, False for raster fonts)
    - format: ttf | ...
    c                 L    || _         || _        || _        || _        || _        d S N)namevectorformat	monospacefamily)selfr
   r   r   r   r   s         P/DATA/AppData/hermes/venv/lib/python3.11/site-packages/pyglet/font/win32query.py__init__zFontEntry.__init__   s)    	"    N)__name__
__module____qualname____doc__r    r   r   r   r   y   s-             r   r   N)wintypes)LOGFONTLOGFONTW                              M                        _CHARSET         c                   >    e Zd Zdej        dz  fdej        dz  fgZdS )FONTSIGNATUREsUsbr/   sCsbr)   N)r   r   r   r   DWORD_fields_r   r   r   r2   r2      s5         
!#$	!#$&HHHr   r2   c                   8   e Zd Zdej        fdej        fdej        fdej        fdej        fdej        fdej        fdej        fd	ej        fd
ej        fdej        fdefdefdefdefdefdefdefdefdefdej        fdej        fdej        fdej        fgZ	dS )NEWTEXTMETRICtmHeighttmAscent	tmDescenttmInternalLeadingtmExternalLeadingtmAveCharWidthtmMaxCharWidthtmWeight
tmOverhangtmDigitizedAspectXtmDigitizedAspectY
mFirstChar	mLastCharmDefaultChar
mBreakChartmItalictmUnderlinedtmStruckOuttmPitchAndFamily	tmCharSettmFlags	ntmSizeEMntmCellHeightntmAvgWidthN)
r   r   r   r   LONGTCHARBYTEr5   UINTr6   r   r   r   r8   r8      s         
X]#	X]#	hm$	hm,	hm,	8=)	8=)	X]#	x}%	x}-	x}-	u	e		u	T			T"	d	HN#	hm$	(-(	&1(HHHr   r8   c                   `   e Zd Zdej        fdej        fdej        fdej        fdej        fdej        fdej        fdej        fd	ej        fd
ej        fdej        fdej        fdej        fdej        fdej        fdefdefdefdefdefdej        fdej        fdej        fdej        fgZ	dS )NEWTEXTMETRICWr9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   N)
r   r   r   r   rQ   WCHARrS   r5   rT   r6   r   r   r   rV   rV      s        	X]#	X]#	hm$	hm,	hm,	8=)	8=)	X]#	x}%	x}-	x}-	x~&	hn%	(	x~&	T			T"	d	HN#	hm$	(-(	&1(HHHr   rV   c                       e Zd ZdefdefgZdS )NEWTEXTMETRICEXntmTm
ntmFontSigN)r   r   r   r8   r2   r6   r   r   r   rY   rY     s'         
- 	}%'HHHr   rY   c                       e Zd ZdefdefgZdS )NEWTEXTMETRICEXWrZ   r[   N)r   r   r   rV   r2   r6   r   r   r   r]   r]     s%        	.!	}%'HHHr   r]   c           	      b   | j         }|j        }|dz  rd}d}nd}d}|j        dz  }|j        dz	  }	|t          k    }
|j        }t
                              t          ||||
|	                     t          rd}|t          k    r|dz  }n|t          k    r|d	z  }n|d
z  }|ddddd|         z  z  }|
r|dz  }n|dz  }dgdz  }|j
        rd|d<   |j        rd|d<   |j        rd|d<   |d                    |          z  }|d|j        z  z  }	 t          |d|j        dd|j                   dS )zcallback function to be executed during EnumFontFamiliesEx
       call for each font name. it stores names in global variable
    r/   TttfFunknownr.    zFP zVP z   z%s URT)r   r   r/   zM  zNM  Ir   r   Sr)   z %sz
 CHARSET: z>3z  )contents
lfFaceNamelfPitchAndFamilyFIXED_PITCH	lfCharSetFONTDBappendr   DEBUGVARIABLE_PITCHlfItaliclfUnderlinelfStrikeOutjoinlfWeightprint)logfonttextmetricexfonttypeparamlfr
   r   fmtpitchr   r   charsetinfostyles                 r   _enum_font_namesr   H  s    
	B=D !| $&E A%F +%IlG
MM)D&#y&AABBB OKEMDDn$$EMDDEMD 	CCC00::: 	EMDDEMD	; 	E!H> 	E!H> 	E!H##	O444r}}MNNN1r   c                    t          d          5 }t          dddddddd| ddddd          }g at                              |t          j        |          t          dd          }ddd           n# 1 swxY w Y   t          S )z
    Prepare and call EnumFontFamiliesEx.

    query()
      - return tuple with sorted list of all available system fonts
    query(charset=ANSI_CHARSET)
      - return tuple sorted list of system fonts supporting ANSI charset

    Nr   ra   )r   r   rm   gdi32EnumFontFamiliesExWctypesbyrefenum_font_names)r~   hdcrw   ress       r   queryr     s     
		 $ 1aAq!Q7Aq!QKK''L!! )              8 Ms   AA00A47A4c                 z     t           r|rt                       t           fdt           D                       rdS dS )z
    Return True if font with specified `name` is present. The result
    of querying system font names is cached. Set `refresh` parameter
    to True to purge cache and reload font information.
    c              3   .   K   | ]}|j         k    V  d S r	   r
   ).0fr
   s     r   	<genexpr>zhave_font.<locals>.<genexpr>  s)      
*
*a16T>
*
*
*
*
*
*r   TF)rm   r   any)r
   refreshs   ` r   r   r     sL      W 

*
*
*
*6
*
*
*** tur   c                     t           st                       t           }| rd |D             }|rd |D             }t          d |D                       S )z+Return list of system installed font names.c                      g | ]}|j         	|S r   )r   r   r   s     r   
<listcomp>zfont_list.<locals>.<listcomp>  s    ...qQX....r   c                      g | ]}|j         	|S r   )r   r   s     r   r   zfont_list.<locals>.<listcomp>  s    111qQ[1111r   c                     g | ]	}|j         
S r   r   r   s     r   r   zfont_list.<locals>.<listcomp>  s    )))a16)))r   )rm   r   sorted)vector_onlymonospace_onlyfontss      r   r   r     sm      E /..E... 211E111))5)))***r   __main__debugTtestzRunning tests..ArialzHave font "Arial"? %szHave font "missing-one"? %szmissing-onestubra   )r   r   )r   mono)r   )r   r   
z	Total: %s)F)FF)Xr   "pyglet.libs.win32.context_managersr   ro   __all____version____url__r   rm   r   r   pyglet.libs.win32r   r   windlluser32r   c_charCHARrR   c_ubyterS   ANSI_CHARSETARABIC_CHARSETBALTIC_CHARSETCHINESEBIG5_CHARSETDEFAULT_CHARSETEASTEUROPE_CHARSETGB2312_CHARSETGREEK_CHARSETHANGUL_CHARSETHEBREW_CHARSETJOHAB_CHARSETMAC_CHARSETOEM_CHARSETRUSSIAN_CHARSETSHIFTJIS_CHARSETSYMBOL_CHARSETTHAI_CHARSETTURKISH_CHARSETVIETNAMESE_CHARSETCHARSET_NAMESlocalscopyitemsr
   valueendswithDEFAULT_PITCHrk   rp   FF_DONTCAREFF_ROMANFF_SWISS	FF_MODERN	FF_SCRIPTFF_DECORATIVE	Structurer2   r8   rV   rY   r]   WINFUNCTYPEc_intPOINTERr5   LPARAMFONTENUMPROCFONTENUMPROCWHDCEnumFontFamiliesExAargtypesr   r   r   r   r   r   r   sysargvrv   
test_arialexitr   rt   lenr   r   r   <module>r      s  FH HR > = = = = =
$
5       $ 

        / / / / / / / /		 }~       VXX]]__**,, $ $MT5}}Z   $#e  		& & & & &F$ & & &( ( ( ( (F$ ( ( (:( ( ( ( (V% ( ( (6' ' ' ' 'f& ' ' '' ' ' ' 'v' ' ' ' "v!
LFN7FN?##N O	 	 #"
LFN8FN#$$NO  LFN7ON&  " LFN8ON&  "F F FR  - 011 " ) ) ) )\   + + + +  zJJJ
x|y  
x|x5   Yw''
%
2333+ii.F.FFGGG)FE2ui@@A	'""j0000	'4000J>>>> 	CHJJJ
x|z!!	d+++	!""&	!	!	...	!""(F+	+	+	d4@@@		E$))E

 .kCC		,,,-----? <. .r   