U
    a+dV                     @   s:   d Z ddlmZ ddlmZ ddlmZmZ dddZdS )z
This module contains different functions to make end and opening
credits, even though it is difficult to fill everyone needs in this
matter.
    )CompositeVideoClip)resize)	ImageClipTextClip   whiteblack   Impact-Normal<   c	              	      sb  g }	d}
t | }|D ]}|dr(qq|dr^tt|dd D ]}|	ddg qHq|dr|	|dd	 d
g d}
q|
r|	d
|g d}
q|	d|g qW 5 Q R X dd t|	 D \}} fdd|df|dffD \}}t|||j	| dfg|j	|j	 | |j
fd	d}t||d}t|d}t|jddd}||S )a{  

    Parameters
    -----------
    
    creditfile
      A text file whose content must be as follows: ::
        
        # This is a comment
        # The next line says : leave 4 blank lines
        .blank 4
        
        ..Executive Story Editor
        MARCEL DURAND
        
        ..Associate Producers
        MARTIN MARCEL
        DIDIER MARTIN
        
        ..Music Supervisor
        JEAN DIDIER
    
    width
      Total width of the credits text in pixels
      
    gap
      Horizontal gap in pixels between the jobs and the names
    
    color
      Color of the text. See ``TextClip.list('color')``
      for a list of acceptable names.

    font
      Name of the font to use. See ``TextClip.list('font')`` for
      the list of fonts you can use on your computer.

    fontsize
      Size of font to use

    stroke_color
      Color of the stroke (=contour line) of the text. If ``None``,
      there will be no stroke.

    stroke_width
      Width of the stroke, in pixels. Can be a float, like 1.5.
    
        
    Returns
    ---------
    
    image
      An ImageClip instance that looks like this and can be scrolled
      to make some credits:

          Executive Story Editor    MARCEL DURAND
             Associate Producers    MARTIN MARCEL
                                    DIDIER MARTIN
                Music Supervisor    JEAN DIDIER
              
    T)
#z.blank    r   z..r	   N Fc                 s   s   | ]}d  |V  qdS )r   N)join).0l r   ?/tmp/pip-unpacked-wheel-0yp4gafk/moviepy/video/tools/credits.py	<genexpr>a   s     zcredits1.<locals>.<genexpr>c                    s&   g | ]\}}t | |d qS ))colorstroke_colorstroke_widthfontfontsizeZalign)r   )r   txtalr   r   r   r   r   r   r   
<listcomp>d   s     zcredits1.<locals>.<listcomp>ZEastZWestr   )sizeZbg_color)width)Zismask)open
startswithrangeintsplitappendzipr   Zset_positionwhr   r   Z	get_framemaskZset_mask)Z
creditfiler!   Zstretchr   r   r   r   r   ZgapZtextsZonelinefr   ileftrightccZscaledZimclipZamaskr   r   r   credits1   s8    @




r1   N)r   r   r   r	   r
   r   r   )	__doc__Z,moviepy.video.compositing.CompositeVideoClipr   Zmoviepy.video.fx.resizer   Zmoviepy.video.VideoClipr   r   r1   r   r   r   r   <module>   s           