
    -Phh)                       U d Z ddlmZ ddlZddlmZ ddlmZ ddlZ	ddl
ZddlmZ ddlmZ ddlmZ er*ddlmZ dd	lmZ dd
lmZ ddlmZ eeeeeef         Zded<    e	j        d            ej        e          Z ee           j!        Z"dZ#dZ$ddddddZ%dddZ&d>dZ'd>dZ(ddd?d)Z)d@d.Z*	 	 	 	 	 	 	 	 	 dAdBd=Z+dS )Cz6Build a PNG card for each page meant for social media.    )annotationsN)Path)TYPE_CHECKING)pyplot)logging)	TypeAlias)Figure)Text)BuildEnvironmentr   
PltObjectsaggK      T)enablesite_url
site_title
page_titledescription)r   r   returnintc                     dS )Ni9   r       _/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinxext/opengraph/socialcards.py_set_page_title_line_widthr   4   s    3r   c                     dS )Ni  r   r   r   r   _set_description_line_widthr   8   s    4r   )	html_logoconfig_socialdict[str, bool | str]	site_namestrr   r   url_text	page_pathsrcdir
str | Pathoutdirenvr   r   
str | Noner   c                  t          j        ||z   |z   t          |           z                                   d                                          dd         }
t          d          }d|                    dd           d|
 d	}t          |          |z  }|                    d
d
           ||z  }|                                r||z  S i }| 	                    d          x}rt          |          |z  |d<   n|	rt          |          |	z  |d<   | 	                    d          x}rt          |          |z  |d<   nt          t                    j        dz  |d<   dD ]}|	                    |          }|s|j                                        dk    r t                              d|           d||<   |                                s t                              d|           d||<   d}|D ]}| 	                    |          x}r|||<   	 |j        }n# t"          $ r t%          di |}Y nw xY wt'          ||||||          }||_        ||z  S )a!  Create a social preview card according to page metadata.

    This uses page metadata and calls a render function to generate the image.
    It also passes configuration through to the rendering function.
    If Matplotlib objects are present in the `app` environment, it reuses them.
    F)usedforsecurityN   z_images/social_previewssummary_/_z.pngT)exist_okparentsimage
image_miniz_static/sphinx-logo-shadow.png)r3   r2   z.svgz4[Social card] %s cannot be an SVG image, skipping...z1[Social card]: %s file doesn't exist, skipping...)
text_color
line_colorbackground_colorfontr   )hashlibsha1r"   encode	hexdigestr   replacemkdirexistsget__file__parentsuffixlowerLOGGERwarningogp_social_card_plt_objectsAttributeErrorcreate_social_card_objectsrender_social_card)r   r!   r   r   r#   r$   r%   r'   r(   r   hashpath_images_relativefilename_imagepath_images_absolute
path_image
kwargs_figcs_imagecs_image_miniimgimpathpass_through_configconfig	cs_configplt_objectss                           r   create_social_cardrX   <   s   * <	Z	+	-M0B0B	BJJLL   ikk"1"D   9::H	 1 1#s ; ;HHdHHHN  <<*>>d;;;%6J
  5#n44 02J !$$W---x 7"6llX5
7	 7"6llY6
7 &)),777} 
#'<<-#?
<   NN!$DD 	< 
 ' # #$$ 	 =  F**NNQSVWWW"JsO }} 	#NNNPSTTT"JsO S% + +%))&1119 	+!*Jv?5 ? ? ? 1>>:>>? % K '2C#  .00s   H H10H1pathr   siteurlrW   c                    |\  }}}}	}
|                     |           |                     |           |	                     |           |
                     |           |                    | d           ||||	|
fS )z?Render a social preview card with Matplotlib and write to disk.N)	facecolor)set_textsavefig)rY   r   r   r   rZ   rW   figtxt_site_titletxt_page_titletxt_descriptiontxt_urls              r   rI   rI      s     EPAC' J'''J'''[)))W KKK%%%HHr   #2f363d#585e63white#5A626Br2   Path | Noner3   page_title_colordescription_colorsite_title_colorsite_url_colorr6   r5   r7   c	                   |ut          t                    j        dz  }	t          j                            t          |	          d          }
t          j        j                            |	           |
j	        }d}d}t          j        ||z  |f          }|                    |           |                    d          }d	\  }}}}|                    ||||fd
          }d\  }}}}|                    ||||fd
          }|                    d          }d}t          j        d|i          5  d}|                    ||dddiddd|          }d}|                    ||dddddddd|          }t           |_        d}|                    ||ddd idd!d|          }t$          |_        d"}|                    ||d#dd$idd!d|%          }ddd           n# 1 swxY w Y   t'          |t                     r)t)          j        |          }|                    |           t'          | t                     rt)          j        |           }|j        dd&         \  } }!t1          | |!g          }"|                    d'|"g           |                    |"d'g           |"|!z
  d&z  }#|"| z
  d&z  }$|                    ||#|!|#z   | |$z   |$g(           |                    d'd'd)d*|+           |j        D ]}%|%                                 |||||fS ),z1Create the Matplotlib objects for the first time.Nz_static/Roboto-Flex.ttfzRoboto Flex)fnamenamegO[h?   )figsize)r   r      rr   )?rs   333333?rt   NE)anchor)g=
ףp=?皙?rw   rw   )gg{Gzg333333?rw   g?zfont.familygףp=
?zTest site titlesize   lefttopT)havawrapcgp=
ף?z%Test page title, a bit longer to demo.   kbold)rx   color
fontweightg?zNA longer description that we use to ,show off what the descriptions look like.   bottomgQ?ztesturl.org   )r|   r}   r   r      r   )extentrr      )lwr   )r   r@   rA   
matplotlibfont_manager	FontEntryr"   fontManageraddfontro   pltfigureset_facecoloradd_axes
rc_contexttextr   _get_wrap_line_widthr   
isinstancempimgimreadimshowshapemaxset_xlimset_ylimhlinesaxesset_axis_off)&r2   r3   ri   rj   rk   rl   r6   r5   r7   	path_fontroboto_fontratiomultipler_   axtextax_xax_yax_wax_h	axim_logo	axim_miniaxlineleft_marginsite_title_y_offsettxt_sitepage_title_y_offsettxt_pagedescription_y_offsetrb   url_y_axis_ofsetrc   rR   ywxwlongestxdiffydiffaxs&                                         r   rH   rH      s	    |NN),EE	 -77i..} 8 
 
 	+33I>>> EH
*eh.9
:
:
:C&''' \\,''F 4D$ddD$5dCCI 3D$ddD$5dCCI \\122F K	-	.	. @
 @
 #;;RL  	
 	
 #;;3#V<<  	
 	
 )C%  # ++ < RL & 
 
 0K,  ++RL  	
 	
o@
 @
 @
 @
 @
 @
 @
 @
 @
 @
 @
 @
 @
 @
 @
D *d## l:&& % Ml5!!2A2B r2h--Aw<(((GQ<((( 2"2"eR%ZeU%KLLL MM!Qb
M333 h  
(OW<<s   1BGG #G )r   r   )r   r    r!   r"   r   r"   r   r"   r#   r"   r$   r"   r%   r&   r'   r&   r(   r   r   r)   r   r   )rY   r   r   r"   r   r"   r   r"   rZ   r"   rW   r   r   r   )	NNrd   re   re   rd   rf   rg   N)r2   rh   r3   rh   ri   r"   rj   r"   rk   r"   rl   r"   r6   r"   r5   r"   r7   r)   r   r   ),__doc__
__future__r   r8   pathlibr   typingr   r   mplmatplotlib.font_managermatplotlib.imager2   r   r   r   sphinx.utilr   r   matplotlib.figurer	   matplotlib.textr
   sphinx.environmentr   tupler   __annotations__use	getLogger__name__rD   r@   rA   HEREMAX_CHAR_PAGE_TITLEMAX_CHAR_DESCRIPTIONDEFAULT_SOCIAL_CONFIGDEFAULT_KWARGS_FIGr   r   rX   rI   rH   r   r   r   <module>r      s.   < < < " " " " " "                                        $ $ $ $ $ $       B      (((((($$$$$$333333!&$dD"@AJAAAA 		8	$	$tH~~               !b1 b1 b1 b1 b1 b1JI I I I. "%&%##I= I= I= I= I= I= I=r   