ó
0Ó›Yc           @   s™   d  d l  m Z d d l m Z m Z d „  Z d „  Z d „  Z d e f d „  ƒ  YZ d	 „  Z	 d
 „  Z
 d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   i   (   t
   BiffRecordiÿÿÿÿ(   t   packt   unpackc         C   s   |  j  | ƒ S(   N(   t	   col_width(   t   sheett   col(    (    s*   lib/python2.7/site-packages/xlwt/Bitmap.pyt	   _size_col   s    c         C   s   |  j  | ƒ S(   N(   t
   row_height(   R   t   row(    (    s*   lib/python2.7/site-packages/xlwt/Bitmap.pyt	   _size_row   s    c         C   s  x6 | t  |  | ƒ k r8 | t  |  | ƒ 8} | d 7} q Wx6 | t |  | ƒ k rq | t |  | ƒ 8} | d 7} q< W| } | } | | d } | | d } x6 | t  |  | ƒ k rÒ | t  |  | ƒ 8} | d 7} q Wx6 | t |  | ƒ k r| t |  | ƒ 8} | d 7} qÖ Wt  |  | ƒ d k s`t  |  | ƒ d k s`t |  | ƒ d k s`t |  | ƒ d k rdd St t | ƒ t  |  | ƒ d ƒ } t t | ƒ t |  | ƒ d ƒ } t t | ƒ t  |  | ƒ d ƒ }	 t t | ƒ t |  | ƒ d ƒ }
 | | | | | |	 | |
 f S(   sú  Calculate the vertices that define the position of the image as required by
    the OBJ record.

             +------------+------------+
             |     A      |      B     |
       +-----+------------+------------+
       |     |(x1,y1)     |            |
       |  1  |(A1)._______|______      |
       |     |    |              |     |
       |     |    |              |     |
       +-----+----|    BITMAP    |-----+
       |     |    |              |     |
       |  2  |    |______________.     |
       |     |            |        (B2)|
       |     |            |     (x2,y2)|
       +---- +------------+------------+

    Example of a bitmap that covers some of the area from cell A1 to cell B2.

    Based on the width and height of the bitmap we need to calculate 8 vars:
        col_start, row_start, col_end, row_end, x1, y1, x2, y2.
    The width and height of the cells are also variable and have to be taken into
    account.
    The values of col_start and row_start are passed in from the calling
    function. The values of col_end and row_end are calculated by subtracting
    the width and height of the bitmap from the width and height of the
    underlying cells.
    The vertices are expressed as a percentage of the underlying cell width as
    follows (rhs values are in pixels):

           x1 = X / W *1024
           y1 = Y / H *256
           x2 = (X-1) / W *1024
           y2 = (Y-1) / H *256

           Where:  X is distance from the left side of the underlying cell
                   Y is distance from the top of the underlying cell
                   W is the width of the cell
                   H is the height of the cell

    Note: the SDK incorrectly states that the height should be expressed as a
    percentage of 1024.

    col_start  - Col containing upper left corner of object
    row_start  - Row containing top left corner of object
    x1  - Distance to left side of object
    y1  - Distance to top of object
    width  - Width of image frame
    height  - Height of image frame

    i   i    Ni   i   (   R   R	   t   intt   float(   R   t	   row_startt	   col_startt   x1t   y1t   widtht   heightt   row_endt   col_endt   x2t   y2(    (    s*   lib/python2.7/site-packages/xlwt/Bitmap.pyt   _position_image   s0    5**####t   ObjBmpRecordc           B   s   e  Z d  Z d „  Z RS(   i]   c	   3      C   sM  | j  | }	 | j | }
 t | | | | | |	 |
 ƒ } | \ } } } } } } } } d } d } d } d } | } | } | } | } | } | } | } | } d }  d }! d }" d }# d }$ d }% d }& d }' d }( d }) d }* d }+ d }, d }- d }. d }/ d }0 d }1 t d | ƒ }2 |2 t d | ƒ 7}2 |2 t d | ƒ 7}2 |2 t d | ƒ 7}2 |2 t d | ƒ 7}2 |2 t d | ƒ 7}2 |2 t d | ƒ 7}2 |2 t d | ƒ 7}2 |2 t d | ƒ 7}2 |2 t d | ƒ 7}2 |2 t d | ƒ 7}2 |2 t d | ƒ 7}2 |2 t d |  ƒ 7}2 |2 t d |! ƒ 7}2 |2 t d |" ƒ 7}2 |2 t d	 |# ƒ 7}2 |2 t d	 |$ ƒ 7}2 |2 t d	 |% ƒ 7}2 |2 t d	 |& ƒ 7}2 |2 t d	 |' ƒ 7}2 |2 t d	 |( ƒ 7}2 |2 t d	 |) ƒ 7}2 |2 t d	 |* ƒ 7}2 |2 t d |+ ƒ 7}2 |2 t d |, ƒ 7}2 |2 t d |- ƒ 7}2 |2 t d |. ƒ 7}2 |2 t d |/ ƒ 7}2 |2 t d |0 ƒ 7}2 |2 t d |1 ƒ 7}2 |2 |  _ d  S(
   Ni   i   i  i    i	   iÿ   s   <Ls   <Hs   <B(   R   R   R   R   t	   _rec_data(3   t   selfR   R   R   t   im_data_bmpt   xt   yt   scale_xt   scale_yR   R   t   coordinatesR   R   R   R   R   R   R   R   t   cObjt   OTt   idt   grbitt   colLt   dxLt   rwTt   dyTt   colRt   dxRt   rwBt   dyBt   cbMacrot	   Reserved1t	   Reserved2t   icvBackt   icvForet   flst   fAutot   icvt   lnst   lnwt   fAutoBt   frst   cft	   Reserved3t
   cbPictFmlat	   Reserved4t   grbit2t	   Reserved5t   data(    (    s*   lib/python2.7/site-packages/xlwt/Bitmap.pyt   __init__n   s‚    (   t   __name__t
   __module__t   _REC_IDR?   (    (    (    s*   lib/python2.7/site-packages/xlwt/Bitmap.pyR   k   s   c         C   s.   t  |  d ƒ  } | j ƒ  } Wd QXt | ƒ S(   s±   Convert a 24 bit bitmap into the modified internal format used by Windows.
    This is described in BITMAPCOREHEADER and BITMAPCOREINFO structures in the
    MSDN library.

    t   rbN(   t   opent   readt   _process_bitmap_data(   t   bitmapt   fhR>   (    (    s*   lib/python2.7/site-packages/xlwt/Bitmap.pyt   _process_bitmap¼   s    c         C   s¶  t  |  ƒ d k r! t d ƒ ‚ n  |  d  d k r@ t d ƒ ‚ n  |  d }  t d |  d  ƒ d } | d 8} | d	 7} |  d }  |  d	 }  t d
 |  d  ƒ \ } } |  d }  | d k rÇ t d ƒ ‚ n  | d k râ t d ƒ ‚ n  t d |  d  ƒ \ } } |  d }  | d k r t d ƒ ‚ n  | d k r;t d ƒ ‚ n  t d |  d  ƒ d } |  d }  | d k rwt d ƒ ‚ n  |  d }  t d d	 | | d d ƒ } | |  }  | | | |  f S(   Ni6   s#   bitmap doesn't contain enough data.i   t   BMs4   bitmap doesn't appear to to be a valid bitmap image.s   <Li   i    i   s   <LLi   iÿÿ  s-   bitmap: largest image width supported is 65k.s.   bitmap: largest image height supported is 65k.s   <HHi   s'   bitmap isn't a 24bit true color bitmap.i   s/   bitmap: only 1 plane supported in bitmap image.s2   bitmap: compression not supported in bitmap image.i   s   <LHHHH(   t   lent	   ExceptionR   R   (   R>   t   sizeR   R   t   planest   bitcountt   compressiont   header(    (    s*   lib/python2.7/site-packages/xlwt/Bitmap.pyRF   È   s<    









t   ImRawDataBmpRecordc           B   s    e  Z d  Z d „  Z d „  Z RS(   i   c         C   s?   t  j |  ƒ t | ƒ \ |  _ |  _ |  _ } |  j | ƒ d S(   s¡   Insert a 24bit bitmap image in a worksheet. The main record required is
        IMDATA but it must be proceeded by a OBJ record to define its position.

        N(   R    R?   RF   R   R   RM   t   _write_imdata(   R   R>   (    (    s*   lib/python2.7/site-packages/xlwt/Bitmap.pyR?   ø   s    !c         C   s5   d } d } |  j  } t d | | | ƒ | |  _ d  S(   Ni	   i   s   <HHL(   RM   R   R   (   R   R>   R8   t   envt   lcb(    (    s*   lib/python2.7/site-packages/xlwt/Bitmap.pyRS     s    	(   R@   RA   RB   R?   RS   (    (    (    s*   lib/python2.7/site-packages/xlwt/Bitmap.pyRR   õ   s   	
t   ImDataBmpRecordc           B   s   e  Z d  „  Z RS(   c         C   s?   t  j |  ƒ t | ƒ \ |  _ |  _ |  _ } |  j | ƒ d S(   s¡   Insert a 24bit bitmap image in a worksheet. The main record required is
        IMDATA but it must be proceeded by a OBJ record to define its position.

        N(   R    R?   RI   R   R   RM   RS   (   R   t   filenameR>   (    (    s*   lib/python2.7/site-packages/xlwt/Bitmap.pyR?   
  s    !(   R@   RA   R?   (    (    (    s*   lib/python2.7/site-packages/xlwt/Bitmap.pyRV   	  s   N(   t   BIFFRecordsR    t   structR   R   R   R	   R   R   RI   RF   RR   RV   (    (    (    s*   lib/python2.7/site-packages/xlwt/Bitmap.pyt   <module>   s   			XQ		-