
^Q\r                @   s  d  d l  Z  d  d l Z e  j j e j j e   d  d l m Z d  d l	 m
 Z
 m Z d  d l m Z d  d l m Z d  d l m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m  Z  m! Z! m" Z" m# Z# m$ Z$ Gd d   d  Z% Gd	 d
   d
  Z& i d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d  6d! d" 6d# d$ 6d% d& 6Z' Gd' d(   d( e j(  Z) Gd) d*   d* e)  Z* d S)+    N)handler)escape	quoteattr)Node)load)ANIMNSCHARTNSCONFIGNSDCNSDR3DNSDRAWNSFONSFORMNSMATHNSMETANSNUMBERNSOFFICENSPRESENTATIONNSSCRIPTNSSMILNSSTYLENSSVGNSTABLENSTEXTNSXLINKNSc               @   s   e  Z d  Z d Z d d   Z d d   Z d d   Z d d	   Z d
 d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d  S)!
StyleToCSSz The purpose of the StyleToCSS class is to contain the rules to convert
        ODF styles to CSS2. Since it needs the generic fonts, it would probably
        make sense to also contain the Styles in a dict as well..
    c             C   so  i  |  _  i  |  _ i% |  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d	 f 6|  j t d
 f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j t d f 6|  j	 t
 d f 6|  j t d f 6|  j t d  f 6|  j t d! f 6|  j t d" f 6|  j t d# f 6|  j t d$ f 6|  j t d% f 6|  _ d  S)&Nzfill-image-namezbackground-colorZborderzborder-bottomzborder-leftzborder-rightz
border-topZcolorzfont-familyz	font-sizez
font-stylezfont-variantzfont-weightzline-heightmarginzmargin-bottomzmargin-leftzmargin-rightz
margin-topz
min-heightpaddingzpadding-bottomzpadding-leftzpadding-rightzpadding-topz
page-widthzpage-heightz
text-alignztext-indentzborder-modelzcolumn-widthz	font-namezhorizontal-posztext-positionztext-line-through-styleztext-underline-stylewidth)fontdict
fillimagesc_drawfillimager   c_for   c_page_widthc_page_heightc_text_alignc_border_modelr   c_widthr   c_fnc_hpc_text_positionc_text_line_through_stylec_text_underline_styleruleconversions)self r/   B/var/www/dbchiro/venv/lib/python3.4/site-packages/odf/odf2xhtml.py__init__?   sP    		zStyleToCSS.__init__c             C   s   d } | d k r d } ni | d k r0 d } nT | d k rE d } n? | d k rZ d } n* | d k ro d } n | d	 k r d } n  | | f |  j  | <d
 S)a   It is possible that the HTML browser doesn't know how to
            show a particular font. Fortunately ODF provides generic fallbacks.
            Unfortunately they are not the same as CSS2.
            CSS2: serif, sans-serif, cursive, fantasy, monospace
            ODF: roman, swiss, modern, decorative, script, system
            This method put the font and fallback into a dictionary
        z
sans-serifZromanserifZswissZmodernZ	monospaceZ
decorativescriptsystemN)r   )r.   namefamilygenerichtmlgenericr/   r/   r0   	save_fonto   s     	 	 	 	 	 	zStyleToCSS.save_fontc             C   s   d |  j  | | d <d S)z Fill a figure with an image. Since CSS doesn't let you resize images
            this should really be implemented as an absolutely position <img>
            with a width and a height
        z	url('%s')zbackground-imageN)r    )r.   rulesetsdictrulevalr/   r/   r0   r!      s    zStyleToCSS.c_drawfillimagec             C   s   | d } | | | <d S)z XSL formatting attributes    Nr/   )r.   r:   r;   r<   r=   selectorr/   r/   r0   r"      s    
zStyleToCSS.c_foc             C   s'   | d k r d | d <n
 d | d <d S)z Convert to CSS2 border model Z
collapsingZcollapsezborder-collapseZseparateNr/   )r.   r:   r;   r<   r=   r/   r/   r0   r&      s    zStyleToCSS.c_border_modelc             C   s   | | d <d S)z Set width of box r   Nr/   )r.   r:   r;   r<   r=   r/   r/   r0   r'      s    zStyleToCSS.c_widthc             C   s8   | d k r d } n  | d k r* d } n  | | d <d S)z Text align startleftendrightz
text-alignNr/   )r.   r:   r;   r<   Zalignr/   r/   r0   r%      s
     	 	zStyleToCSS.c_text_alignc             C   sp   | j  t d f  } | d k	 r7 |  j | | |  n  |  j j  | | d f  \ } } d | | f | d <d S)z Generate the CSS font family
            A generic font can be found in two ways. In a <style:font-face>
            element or as a font-family-generic attribute in text-properties.
        zfont-family-genericNr2   z%s, %szfont-family)getr   r9   r   )r.   r:   r;   r<   Z	fontstyler7   r6   r8   r/   r/   r0   r(      s
    !zStyleToCSS.c_fnc             C   s   | j  d  } t |  d k rB | d d k rB | d | d <n  | d d k r_ d | d	 <n+ | d d
 k r| d | d	 <n | d | d	 <d S)a   Text position. This is used e.g. to make superscript and subscript
            This attribute can have one or two values.

            The first value must be present and specifies the vertical
            text position as a percentage that relates to the current font
            height or it takes one of the values sub or super. Negative
            percentages or the sub value place the text below the
            baseline. Positive percentages or the super value place
            the text above the baseline. If sub or super is specified,
            the application can choose an appropriate text position.

            The second value is optional and specifies the font height
            as a percentage that relates to the current font-height. If
            this value is not specified, an appropriate font height is
            used. Although this value may change the font height that
            is displayed, it never changes the current font height that
            is used for additional calculations.
            r   z0%r>   z	font-sizesuperz33%zvertical-alignsubz-33%N)splitlen)r.   r:   r;   r<   tpZtextposr/   r/   r0   r*      s    "zStyleToCSS.c_text_positionc             C   sl  | j  t d f d  } | d k r; d | d <d | d <n  | d k r | d k r` d | d <qh| d k r d | d <d | d <d | d <qhd | d <d | d <n | d k r| d k r d	 | d <qh| d k r d | d <d | d <d | d	 <qhd | d <d | d <n[ | d k rh| d k r2d	 | d <qhd | d <t d f | k rh| t d f | d	 <qhn  d  S)NwrapparallelcenterZautozmargin-leftzmargin-rightrC   outsiderA   dynamicfloatzrun-throughZabsoluteposition0topZ0cminside	from-leftfrom-insiderelativex)rightrO   )leftrM   rP   )r[   rU   )rZ   rM   rP   )rV   rW   )rZ   rM   )rD   r   r   )r.   r:   r;   r<   ZhposrL   r/   r/   r0   r)      s8    







zStyleToCSS.c_hpc             C   s   | | d <d S)zt Set width of box
            HTML doesn't really have a page-width. It is always 100% of the browser width
        r   Nr/   )r.   r:   r;   r<   r=   r/   r/   r0   r#      s    zStyleToCSS.c_page_widthc             C   s#   | r | d k r d | d <n  d S)z| Set underline decoration
            HTML doesn't really have a page-width. It is always 100% of the browser width
        noneZ	underlineztext-decorationNr/   )r.   r:   r;   r<   r=   r/   r/   r0   r,      s    z!StyleToCSS.c_text_underline_stylec             C   s#   | r | d k r d | d <n  d S)z| Set underline decoration
            HTML doesn't really have a page-width. It is always 100% of the browser width
        r\   zline-throughztext-decorationNr/   )r.   r:   r;   r<   r=   r/   r/   r0   r+      s    z$StyleToCSS.c_text_line_through_stylec             C   s   | | d <d S)z Set height of box heightNr/   )r.   r:   r;   r<   r=   r/   r/   r0   r$     s    zStyleToCSS.c_page_heightc                s'  i  } g  } xx | j    D]j \ } } | d d k rI | | | d <q n    j j | d  } | r | j | | | | | g  q q WxK t   f d d   |  D]. } | \ } } } } } | | | | |  q WxK t   f d d   |  D]. } | \ } } } } } | | | | |  q W| S)zj Rule is a tuple of (namespace, name). If the namespace is '' then
            it is already CSS2
        r    r>   Nc                s   |  d   j  k S)Nr   )r)   )rY   )r.   r/   r0   <lambda>  s    z+StyleToCSS.convert_styles.<locals>.<lambda>c                s   |  d   j  k S)Nr   )r)   )rY   )r.   r/   r0   r_     s    )itemsr-   rD   appendfilter)r.   r:   r;   Z
proceduresr<   r=   methodpr/   )r.   r0   convert_styles  s     #""zStyleToCSS.convert_stylesN)__name__
__module____qualname____doc__r1   r9   r!   r"   r&   r'   r%   r(   r*   r)   r#   r,   r+   r$   re   r/   r/   r/   r0   r   9   s    0*r   c               @   sX   e  Z d  Z d d   Z d d   Z d d   Z d d   Z d	 d
   Z d d   Z d S)TagStackc             C   s   g  |  _  d  S)N)stack)r.   r/   r/   r0   r1   #  s    zTagStack.__init__c             C   s   |  j  j | | f  d  S)N)rk   ra   )r.   tagattrsr/   r/   r0   push&  s    zTagStack.pushc             C   s   |  j  j   } | S)N)rk   pop)r.   itemr/   r/   r0   ro   )  s    zTagStack.popc             C   s   |  j  d } | d S)Nr>   )rk   )r.   rp   r/   r/   r0   stackparent-  s    zTagStack.stackparentc             C   s2   x+ |  j  D]  \ } } | | k r
 | | Sq
 Wd S)z% Find a tag with the given attribute N)rk   )r.   attrrl   rm   r/   r/   r0   	rfindattr1  s    zTagStack.rfindattrc             C   s=   d } x0 |  j  D]% \ } } | | k r | d } q q W| S)Nr   r>   )rk   )r.   rl   cZttagZtattrsr/   r/   r0   
count_tags7  s
     zTagStack.count_tagsN)	rf   rg   rh   r1   rn   ro   rr   rt   rv   r/   r/   r/   r0   rj   "  s   rj   Zemz
S-EmphasisZcitez
S-CitationZstrongzS-Strong_20_Emphasisvarz
S-VariableZdfnzS-Definitionttz
S-TeletypeZh1zP-Heading_20_1Zh2zP-Heading_20_2Zh3zP-Heading_20_3Zh4zP-Heading_20_4Zh5zP-Heading_20_5Zh6zP-Heading_20_6addresszP-AddresseeprezP-Preformatted_20_Textc               @   s<  e  Z d  Z d Z d d d d  Z d d   Z d d	   Z d
 d d  Z d d   Z d d   Z	 d d   Z
 d d   Z i  d d d  Z d d d  Z i  d d  Z d d   Z d d   Z d d    Z d! d"   Z d# d$   Z d% d&   Z d' d(   Z d) d*   Z d+ d,   Z d- d.   Z d/ d0   Z d1 d2   Z d3 d4   Z d5 d6   Z d7 d8   Z d9 d:   Z d; d<   Z d= d>   Z  d? d@   Z! dA dB   Z" dC dD   Z# dE dF   Z$ dG dH   Z% dI dJ   Z& dK dL   Z' dM dN   Z( dO dP   Z) dQ dR   Z* dS dT   Z+ dU dV   Z, dW dX   Z- dY Z. dZ d[   Z/ d\ d]   Z0 d^ d_   Z1 d` da   Z2 db dc   Z3 dd de   Z4 df dg   Z5 dh di   Z6 dj dk   Z7 dl dm   Z8 dn do   Z9 dp dq   Z: dr ds   Z; dt du   Z< i
 dv dv 6dw dx 6dy dy 6dz d{ 6d| d} 6d~ d~ 6d d 6d d 6d d 6d d 6Z= d d   Z> d d   Z? d d   Z@ d d   ZA d d   ZB d d   ZC d d   ZD d d   ZE d d   ZF d d   ZG d d   ZH d d   ZI d d   ZJ i
 d d 6d dx 6d dy 6d d{ 6d d} 6d d~ 6d d 6d d 6d d 6d d 6ZK d d   ZL d d   ZM d d   ZN d d   ZO d d   ZP d d   ZQ d d   ZR d d   ZS d d   ZT d d   ZU d d   ZV d d   ZW d d   ZX d d   ZY d d   ZZ d d   Z[ d d   Z\ d d   Z] d d   Z^ d d   Z_ d d   Z` d d   Za d d   Zb d d   Zc d d   Zd d d   Ze d d   Zf d d   Zg d d   Zh d d   Zi d d   Zj d d   Zk d d   Zl d d   Zm d d   Zn d d   Zo d d   Zp d d   Zq d d   Zr d d   Zs d d   Zt d d   Zu d d   Zv dd  Zw dd  Zx dd  Zy d dd Zz d
 S(	  	ODF2XHTMLz4 The ODF2XHTML parses an ODF file and produces XHTMLTFc             C   s  | |  _  iW |  j |  j f t d f 6|  j |  j f t d f 6|  j |  j f t d f 6|  j |  j f t d f 6|  j |  j f t d f 6|  j |  j f t	 d f 6|  j
 |  j f t	 d f 6|  j d  f t	 d f 6|  j d  f t	 d	 f 6|  j d  f t	 d
 f 6|  j d  f t	 d f 6|  j d  f t	 d f 6|  j |  j f t	 d f 6|  j |  j f t	 d f 6|  j |  j f t d f 6|  j |  j f t d f 6|  j |  j f t d f 6|  j |  j f t d f 6|  j d  f t d f 6|  j d  f t d f 6|  j d  f t d f 6|  j d  f t d f 6|  j d  f t d f 6|  j d  f t d f 6|  j d  f t d f 6|  j |  j f t d f 6|  j |  j f t d f 6|  j d  f t d f 6|  j d  f t d f 6|  j d  f t d f 6|  j |  j f t d f 6|  j |  j  f t d  f 6|  j! d  f t d! f 6|  j" |  j# f t d" f 6|  j d  f t d# f 6|  j d  f t d$ f 6|  j d  f t$ d% f 6|  j d  f t% d& f 6|  j& |  j' f t% d' f 6|  j( d  f t% d( f 6|  j) d  f t% d) f 6|  j( d  f t% d* f 6|  j d  f t% d+ f 6|  j* d  f t% d, f 6|  j( d  f t% d- f 6|  j+ |  j, f t% d. f 6|  j( d  f t% d/ f 6|  j- |  j. f t% d0 f 6|  j( d  f t% d1 f 6|  j( d  f t% d2 f 6|  j( d  f t% d3 f 6|  j( d  f t% d4 f 6|  j d  f t/ d5 f 6|  j d  f t0 d6 f 6|  j1 |  j2 f t0 d7 f 6|  j3 d  f t0 d8 f 6|  j4 |  j5 f t0 d9 f 6|  j6 |  j7 f t0 d: f 6|  j8 |  j9 f t: d; f 6|  j; |  j< f t: d< f 6|  j d  f t: d= f 6|  j; |  j< f t: d> f 6|  j= d  f t: d? f 6|  j= d  f t: d@ f 6|  j> |  j9 f t: dA f 6|  j> d  f t: dB f 6|  j? |  j@ f t: dC f 6|  j; |  j< f t: dD f 6|  jA d  f t: dE f 6|  j d  f t: dF f 6|  jB |  jC f t: dG f 6|  jD |  jE f t: dH f 6|  jF |  jG f t: dI f 6|  jH |  jI f t: dJ f 6dX t: dK f 6|  jJ d  f t: dL f 6|  jK |  jL f t: dM f 6d  |  jM f t: dN f 6|  j d  f t: dO f 6|  j; |  j< f t: dP f 6|  jN |  jO f t: dQ f 6|  jP d  f t: dR f 6|  jQ |  jR f t: dS f 6|  jS d  f t: dT f 6|  j; |  j< f t: dU f 6|  j; |  j< f t: dV f 6|  j; |  j< f t: dW f 6|  _T | r|  jU   n  |  jV   d  S)YNtitlelanguagecreatordescriptiondatezcustom-shapeframeimagez
fill-imagez	layer-setobjectz
object-olepageztext-boxzcreation-date	generatorzinitial-creatorkeywordzboolean-stylezcurrency-stylez
date-styleznumber-stylez
text-styleZ
annotationzautomatic-stylesdocumentzdocument-contentformszmaster-stylesmetapresentationspreadsheetstylestextscriptsZsettingsnoteszdefault-page-layoutzdefault-stylezdrawing-page-propertiesz	font-facezgraphic-propertieszhandout-masterzmaster-pagezpage-layout-propertieszpage-layoutzparagraph-propertiesstyleztable-cell-propertiesztable-column-propertiesztable-propertiesztext-propertiesdesczcovered-table-cellz
table-cellztable-columnz	table-rowtableazalphabetical-index-sourcezbibliography-configurationzbibliography-sourceZbookmarkzbookmark-startzbookmark-refzbookmark-ref-starthzillustration-index-sourcez
line-breakzlinenumbering-configurationlistz	list-itemzlist-level-style-bulletzlist-level-style-numberz
list-stylenotez	note-bodyznote-citationznotes-configurationzobject-index-sourcerd   sspantabztable-index-sourceztable-of-content-sourcezuser-index-source)NN)Wgenerate_csss_processcont
e_dc_titler
   e_dc_contentlanguagee_dc_creatore_dc_metatags_custom_shapee_custom_shaper   s_draw_framee_draw_frames_draw_images_draw_fill_images_ignorexmls_draw_objects_draw_object_oles_draw_pagee_draw_pages_draw_textboxe_draw_textboxr   r   r   s_office_automatic_styless_office_document_contente_office_document_contents_office_master_styless_ignoreconts_office_presentatione_office_presentations_office_spreadsheete_office_spreadsheets_office_styless_office_texte_office_textr   r   s_style_default_stylee_style_default_styles_style_handle_propertiess_style_font_faces_style_master_pages_style_page_layoute_style_page_layouts_style_stylee_style_styler   r   s_table_table_celle_table_table_cells_table_table_columns_table_table_rowe_table_table_rows_table_tablee_table_tables_text_ae_text_ar   s_text_x_sourcee_text_x_sources_text_bookmarks_text_bookmark_refs_text_he_text_hs_text_line_breaks_text_liste_text_lists_text_list_iteme_text_list_items_text_list_level_style_bullete_text_list_level_style_bullets_text_list_level_style_numbere_text_list_level_style_numbers_text_notes_text_note_bodye_text_note_bodye_text_note_citations_text_pe_text_ps_text_ss_text_spane_text_span
s_text_tabelementsset_embedable_resetobject)r.   r   	embedabler/   r/   r0   r1   \  s    	zODF2XHTML.__init__c             C   s   d |  _  d S)z% Tell the parser to not generate CSS FN)r   )r.   r/   r/   r0   	set_plain  s    zODF2XHTML.set_plainc             C   sP   d |  j  t d f <d |  j  t d f <d |  j  t d f <d	 |  j  t d f <d S)
z? Tells the converter to only output the parts inside the <body>Nr   r   r   zdocument-content)NN)NN)NN)NN)r   r   )r.   r/   r/   r0   r     s    zODF2XHTML.set_embedableNc             C   sM   d |  _  | |  _ | r5 |  j j d | | f  n |  j j d |  d S)zm Add a link to an external style file.
            Also turns of the embedding of styles in the HTML
        Fz><link rel="stylesheet" type="text/css" href="%s" media="%s"/>
z3<link rel="stylesheet" type="text/css" href="%s"/>
N)use_internal_cssstylefilenamemetatagsra   )r.   r   Zmediar/   r/   r0   add_style_file  s
    		zODF2XHTML.add_style_filec             C   s   i  |  _  d |  _ d |  _ d  S)Nr   r^   )notedictcurrentnotenotebody)r.   r/   r/   r0   _resetfootnotes  s    		zODF2XHTML._resetfootnotesc             C   s   g  |  _  |  j |  _ d |  _ d |  _ d |  _ d |  _ g  |  _ t   |  _	 g  |  _
 g  |  _ d |  _ d |  _ i  |  _ d d d d d d d d d d d g |  _ d |  _ t   |  _ i  |  _ g  |  _ i  |  _ d  |  _ |  j   g  |  _ d  S)Nr^   Tr   )lines_wlines_wfuncxmlfiler|   r}   r~   datarj   tagstack	htmlstackpstackprocesselemprocesscont	listtypesheadinglevelsr   r   csanchors
stylestack	styledictcurrentstyler   r   )r.   r/   r/   r0   r     s,    											*					
zODF2XHTML._resetobjectc             C   s    | d k r |  j  |  n  d  S)Nr^   )r   )r.   r   r/   r/   r0   writeout  s    zODF2XHTML.writeoutc             C   s8   d j  |  j  } | d k r4 |  j t |   n  d  S)Nr^   )joinr   r  r   )r.   dr/   r/   r0   	writedata  s    zODF2XHTML.writedatac             C   s   |  j  j | | | f  g  } x7 | j   D]) \ } } | j d | t |  f  q, Wt |  d k r |  j d |  n  |  j d | d j |  f  | d k r |  j d  n  d S)	z Create an open HTML tag z%s=%sr   z<%s>z<%s %s>rE   T
N)r   ra   r`   r   rJ   r  r  )r.   rl   rm   blockr   keyr=   r/   r/   r0   opentag  s    ! zODF2XHTML.opentagc             C   s>   |  j  j   |  j d |  | d k r: |  j d  n  d S)z Close an open HTML tag z</%s>Tr  N)r   ro   r  )r.   rl   r  r/   r/   r0   closetag  s    zODF2XHTML.closetagc             C   sd   g  } x7 | j    D]) \ } } | j d | t |  f  q W|  j d | d j |  f  d  S)Nz%s=%sz	<%s %s/>
rE   )r`   ra   r   r  r  )r.   rl   rm   r   r  r=   r/   r/   r0   emptytag  s    !zODF2XHTML.emptytagc             C   s)   |  j  r% |  j r% |  j j |  n  d  S)N)r   r   r   ra   )r.   r   r/   r/   r0   
characters$  s    zODF2XHTML.charactersc             C   s   |  j  j |  j |  j f  |  j rm |  j j | d  d } | rZ |  j | | |  qm |  j | |  n  |  j j	 | |  d  S)Nr   )NN)
r   ra   r   r   r   rD   handle_starttagunknown_starttagr   rn   )r.   rl   qnamerm   rc   r/   r/   r0   startElementNS(  s    	zODF2XHTML.startElementNSc             C   s   |  j  j   \ } } |  j rf |  j j | d  d } | rS |  j | | |  qf |  j | |  n  |  j j   \ |  _ |  _ d  S)Nr>   )NN)	r   ro   r   r   rD   handle_endtagunknown_endtagr   r   )r.   rl   r  Zstagrm   rc   r/   r/   r0   endElementNS2  s    	zODF2XHTML.endElementNSc             C   s   | | |  d  S)Nr/   )r.   rl   rc   rm   r/   r/   r0   r  =  s    zODF2XHTML.handle_starttagc             C   s   | | |  d  S)Nr/   )r.   rl   rm   rc   r/   r/   r0   r  @  s    zODF2XHTML.handle_endtagc             C   s   d  S)Nr/   )r.   rl   rm   r/   r/   r0   r  C  s    zODF2XHTML.unknown_starttagc             C   s   d  S)Nr/   )r.   rl   rm   r/   r/   r0   r  F  s    zODF2XHTML.unknown_endtagc             C   s   d |  _  d S)zh Ignore this xml element and all children of it
            It will automatically stop ignoring
        FN)r   )r.   rl   rm   r/   r/   r0   r   I  s    zODF2XHTML.s_ignorexmlc             C   s   d |  _  d S)z  Stop processing the text nodes FN)r   )r.   rl   rm   r/   r/   r0   r   O  s    zODF2XHTML.s_ignorecontc             C   s   d |  _  d S)z! Start processing the text nodes TN)r   )r.   rl   rm   r/   r/   r0   r   S  s    zODF2XHTML.s_processcontc             C   s.   | j  t d f d  } | j d d  } | S)z) Generate a class name from a style name z
style-namer^   ._)rD   r   replace)r.   rm   ru   r/   r/   r0   	classnameW  s    zODF2XHTML.classnamec             C   s@   | |  j  k r0 d t |  j   d |  j  | <n  |  j  j |  S)z+ Create a unique anchor id for a href name z
anchor%03dr>   )r   rJ   rD   )r.   r5   r/   r/   r0   
get_anchor]  s    !zODF2XHTML.get_anchorc             C   s   g  |  _  d  S)N)r   )r.   r/   r/   r0   	purgedataf  s    zODF2XHTML.purgedatac             C   s"   d j  |  j  |  _ g  |  _ d S)zD Get the title from the meta data and create a HTML <title>
        r^   N)r  r   r|   )r.   rl   rm   r/   r/   r0   r   n  s    zODF2XHTML.e_dc_titlec             C   s=   |  j  j d | d t d j |  j   f  g  |  _ d S)z: Any other meta data is added as a <meta> element
        z<meta name="%s" content=%s/>
r>   r^   N)r   ra   r   r  r   )r.   rl   rm   r/   r/   r0   r   u  s    0zODF2XHTML.e_dc_metatagc             C   s?   d j  |  j  |  _ |  j j d t |  j   g  |  _ d S)zD Set the content language. Identifies the targeted audience
        r^   z3<meta http-equiv="content-language" content="%s"/>
N)r  r   r}   r   ra   r   )r.   rl   rm   r/   r/   r0   r   {  s    zODF2XHTML.e_dc_contentlanguagec             C   s?   d j  |  j  |  _ |  j j d t |  j   g  |  _ d S)zC Set the content creator. Identifies the targeted audience
        r^   z*<meta http-equiv="creator" content="%s"/>
N)r  r   r~   r   ra   r   )r.   rl   rm   r/   r/   r0   r     s    zODF2XHTML.e_dc_creatorc             C   s  | j  t d f d  } d } d | j  t d f d  } | d k re d | j  t d f d  } n  | j d d	  } | d
 k r d } n6 | d k r d } n! | d k r d } d } n d } t d f | k r | d | t d f d } n  t d f | k r$| d | t d f d } n  t d f | k rU| d | t d f d } n  t d f | k r| d | t d f d } n  |  j r|  j | i | d 6| d 6 n |  j |  d S)zQ A <draw:custom-shape> is made into a <div> in HTML which is then styled
        zanchor-typenotfounddivzG-z
style-namer^   zPR-r  r  	paragraphzposition:absolute;charzas-charzposition: absolute;r   zwidth:;r]   zheight:rY   zleft:yztop:classr   N)rD   r   r   r   r  r   r   r	  )r.   rl   rm   anchor_typehtmltagr5   r   r/   r/   r0   r     s2    				!zODF2XHTML.s_custom_shapec             C   s   |  j  d  d S)z End the <draw:frame>
        r  N)r
  )r.   rl   rm   r/   r/   r0   r     s    zODF2XHTML.e_custom_shapec             C   s  | j  t d f d  } d } d | j  t d f d  } | d k re d | j  t d f d  } n  | j d d	  } | d
 k r d } n6 | d k r d } n! | d k r d } d } n d } t d f | k r | d | t d f d } n  t d f | k r$| d | t d f d } n  t d f | k rU| d | t d f d } n  t d f | k r| d | t d f d } n  |  j r|  j | i | d 6| d 6 n |  j |  d S)zJ A <draw:frame> is made into a <div> in HTML which is then styled
        zanchor-typer  r  zG-z
style-namer^   zPR-r  r  r  zposition:relative;r  zas-charzposition:absolute;r   zwidth:r  r]   zheight:rY   zleft:r  ztop:r   r   N)rD   r   r   r   r  r   r   r	  )r.   rl   rm   r!  r"  r5   r   r/   r/   r0   r     s2    				!zODF2XHTML.s_draw_framec             C   s   |  j  d  d S)z End the <draw:frame>
        r  N)r
  )r.   rl   rm   r/   r/   r0   r     s    zODF2XHTML.e_draw_framec             C   sK   | j  t d f d  } | t d f } |  j |  } | |  j j | <d  S)Nr5   NoNamehref)rD   r   r   rewritelinkr   r    )r.   rl   rm   r5   imghrefr/   r/   r0   r     s    zODF2XHTML.s_draw_fill_imagec             C   s   | S)zh Intended to be overloaded if you don't store your pictures
            in a Pictures subfolder
        r/   )r.   r&  r/   r/   r0   r%    s    zODF2XHTML.rewritelinkc             C   s   |  j  j   } | j t d f  } | t d f } |  j |  } i d d 6| d 6} |  j r| | d k r| d | d <q| n  |  j d	 |  d
 S)z2 A <draw:image> becomes an <img/> element
        zanchor-typer$  r^   altsrcr  zdisplay: block;r   ZimgN)r   rr   rD   r   r   r%  r   r  )r.   rl   rm   parentr!  r&  	htmlattrsr/   r/   r0   r     s    	zODF2XHTML.s_draw_imagec             C   sM   | t  d f } x6 |  j j D]( } | j | k r |  j | j  q q Wd S)z` A <draw:object> is embedded object in the document (e.g. spreadsheet in presentation).
        r$  N)r   r   ZchildobjectsZfolder	_walknodetopnode)r.   rl   rm   Zobjhrefru   r/   r/   r0   r     s    
zODF2XHTML.s_draw_objectc             C   sc   | t  d f } | r_ | j   d k r_ i d d 6d d 6} |  j d |  |  j d |  n  d S)	zU A <draw:object-ole> is embedded OLE object in the document (e.g. MS Graph).
        zclass-idz$00020803-0000-0000-c000-000000000046Zobject_ole_graphr5   z	ole-graphr   r   N)r   lowerr	  r
  )r.   rl   rm   Zclass_idZtagattrsr/   r/   r0   r     s
    zODF2XHTML.s_draw_object_olec             C   s   | j  t d f d  } | j  t d f d  } | j d d  } | j  t d f d  } | j d d  } |  j r |  j d i d	 | | f d
 6 n |  j d  |  j d  |  j t |   |  j d  d S)z A <draw:page> is a slide in a presentation. We use a <fieldset> element in HTML.
            Therefore if you convert a ODP file, you get a series of <fieldset>s.
            Override this for your own purpose.
        r5   r#  z
style-namer^   r  r  zmaster-page-namefieldsetzDP-%s MP-%sr   ZlegendN)rD   r   r  r   r	  r  r   r
  )r.   rl   rm   r5   Z	stylenameZ
masterpager/   r/   r0   r     s    	$zODF2XHTML.s_draw_pagec             C   s   |  j  d  d  S)Nr.  )r
  )r.   rl   rm   r/   r/   r0   r     s    zODF2XHTML.e_draw_pagec             C   sH   d } t  d f | k r7 | d | t  d f d } n  |  j d  d  S)Nr^   z
min-heightzmin-height:r  r  )r   r	  )r.   rl   rm   r   r/   r/   r0   r     s    zODF2XHTML.s_draw_textboxc             C   s   |  j  d  d S)z! End the <draw:text-box>
        r  N)r
  )r.   rl   rm   r/   r/   r0   r      s    zODF2XHTML.e_draw_textboxc             C   s   |  j    |  j rj |  j rj |  j d i d d 6d  |  j d  |  j   |  j d  |  j d  n  |  j   |  j d  |  j d d	 d d  S)
Nr   ztext/csstypeTz/*<![CDATA[*/
z/*]]>*/
headbodyr  )r  r   r   r	  r  generate_stylesheetr
  r  )r.   rl   rm   r/   r/   r0   	html_body%  s    


zODF2XHTML.html_bodyz
img { width: 100%; height: 100%; }
* { padding: 0; margin: 0;  background-color:white; }
body { margin: 0 1em; }
ol, ul { padding-left: 2em; }
c             C   s  x|  j  D]} |  j j |  } d | k r | d |  j k r |  j | d j   } | d =x$ | j   D] \ } } | | | <ql W| } n  xn d | k r | d |  j k r |  j | d j   } | d =x$ | j   D] \ } } | | | <q W| } q W| |  j | <q
 W|  j |  j  x |  j  D]| } |  j j |  } |  j j |  } |  j d |  x1 | j   D]# \ } } |  j d | | f  qsW|  j d  q+Wd  S)Nz__style-familyz__parent-style-namez%s {
z		%s: %s;
z}
)	r   r   rD   copyr`   r  default_stylesr   re   )r.   r5   r   Zfamilystyler   r=   ZparentstyleZcss2r/   r/   r0   r2  8  s.    	"
zODF2XHTML.generate_stylesheetc             C   s   |  j  d k r d  S|  j r9 |  j d i d d 6d  n |  j d  xd t d |  j  d  D]L } |  j | } |  j d i d | d	 6 |  j | d
  |  j d  q] W|  j d  d  S)Nr   olzborder-top: 1px solid blackr   Tr>   lizfootnote-%didr1  )r   r   r	  ranger   r  r
  )r.   r  r   r/   r/   r0   generate_footnotesT  s    	zODF2XHTML.generate_footnotesc             C   s(   |  j  d k r d |  _ n	 d |  _ d  S)Nz
styles.xmlAr^   )r   
autoprefix)r.   rl   rm   r/   r/   r0   r   f  s    z#ODF2XHTML.s_office_automatic_stylesc             C   s   |  j  d  |  j  d  |  j d i d d 6d  |  j d d d |  j d	 i d
 d 6d d 6 x |  j D] } |  j  |  qo W|  j  d t |  j   d S)z" First tag in the content.xml filez2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" z0"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
htmlzhttp://www.w3.org/1999/xhtmlZxmlnsTr0  r  r   zContent-Typez
http-equivztext/html;charset=UTF-8contentz<title>%s</title>
N)r  r	  r  r   r   r|   )r.   rl   rm   Zmetaliner/   r/   r0   r   l  s    z#ODF2XHTML.s_office_document_contentc             C   s   |  j  d  d S)z
 Last tag r=  N)r
  )r.   rl   rm   r/   r/   r0   r   w  s    z#ODF2XHTML.e_office_document_contentc             C   s   d S)rE   Nr/   )r.   rl   rm   r/   r/   r0   r   {  s    z ODF2XHTML.s_office_master_stylesc             C   sH   i d t  d f 6|  j d <i d t  d f 6|  j d <|  j | |  d S)z For some odd reason, OpenOffice Impress doesn't define a default-style
            for the 'paragraph'. We therefore force a standard when we see
            it is a presentation
        Z24ptz	font-sizerd   r   N)r   r   r3  )r.   rl   rm   r/   r/   r0   r   ~  s    zODF2XHTML.s_office_presentationc             C   s   |  j    |  j d  d  S)Nr1  )r:  r
  )r.   rl   rm   r/   r/   r0   r     s    
zODF2XHTML.e_office_presentationc             C   s   |  j  | |  d  S)N)r3  )r.   rl   rm   r/   r/   r0   r     s    zODF2XHTML.s_office_spreadsheetc             C   s   |  j    |  j d  d  S)Nr1  )r:  r
  )r.   rl   rm   r/   r/   r0   r     s    
zODF2XHTML.e_office_spreadsheetc             C   s   d |  _  d  S)Nr^   )r<  )r.   rl   rm   r/   r/   r0   r     s    zODF2XHTML.s_office_stylesc             C   s.   i d t  d f 6|  j d <|  j | |  d S)z OpenDocument text rM   rL   r   N)r   r   r3  )r.   rl   rm   r/   r/   r0   r     s    zODF2XHTML.s_office_textc             C   s   |  j    |  j d  d  S)Nr1  )r:  r
  )r.   rl   rm   r/   r/   r0   r     s    
zODF2XHTML.e_office_textc             C   s5   x. | j    D]  \ } } | |  j |  j | <q Wd S)zY Copy all attributes to a struct.
            We will later convert them to CSS2
        N)r`   r   r  )r.   rl   rm   r  rs   r/   r/   r0   r     s    z#ODF2XHTML.s_style_handle_propertiesr   rd   r  r   r   r   r  sectionr   tdz
table-cellcolztable-columntrz	table-rowZgraphicc             C   sB   | t  d f } |  j j | d  } | |  _ i  |  j |  j <d S)z8 A default style is like a style on an HTML tag
        r6   unknownN)r   	familymaprD   r  r   )r.   rl   rm   r6   
htmlfamilyr/   r/   r0   r     s    	zODF2XHTML.s_style_default_stylec             C   s   d  |  _  d  S)N)r  )r.   rl   rm   r/   r/   r0   r     s    zODF2XHTML.e_style_default_stylec             C   sR   | t  d f } | t d f } | j t  d f d  } |  j j | | |  d S)aI   It is possible that the HTML browser doesn't know how to
            show a particular font. Luckily ODF provides generic fallbacks
            Unfortunately they are not the same as CSS2.
            CSS2: serif, sans-serif, cursive, fantasy, monospace
            ODF: roman, swiss, modern, decorative, script, system
        r5   zfont-familyzfont-family-genericr^   N)r   r   rD   r   r9   )r.   rl   rm   r5   r6   r7   r/   r/   r0   r     s    zODF2XHTML.s_style_font_facec             C   s%   |  j  d i d d 6 |  j   d  S)Nr  Zfooterr8  )r	  r  )r.   rl   rm   r/   r/   r0   s_style_footer  s    zODF2XHTML.s_style_footerc             C   s%   |  j    |  j d  |  j   d  S)Nr  )r  r
  r  )r.   rl   rm   r/   r/   r0   e_style_footer  s    
zODF2XHTML.e_style_footerc             C   s0   d |  _  |  j j |  j   i  |  j |  j  <d  S)Nz@print #footer)r  r   ra   r   )r.   rl   rm   r/   r/   r0   s_style_footer_style  s    	zODF2XHTML.s_style_footer_stylec             C   s%   |  j  d i d d 6 |  j   d  S)Nr  headerr8  )r	  r  )r.   rl   rm   r/   r/   r0   s_style_header  s    zODF2XHTML.s_style_headerc             C   s%   |  j    |  j d  |  j   d  S)Nr  )r  r
  r  )r.   rl   rm   r/   r/   r0   e_style_header  s    
zODF2XHTML.e_style_headerc             C   s0   d |  _  |  j j |  j   i  |  j |  j  <d  S)Nz@print #header)r  r   ra   r   )r.   rl   rm   r/   r/   r0   s_style_header_style  s    	zODF2XHTML.s_style_header_stylec             C   s0   d |  _  |  j j |  j   i  |  j |  j  <d S)zC Collect the formatting for the default page layout style.
        z@pageN)r  r   ra   r   )r.   rl   rm   r/   r/   r0   s_style_default_page_layout  s    	z%ODF2XHTML.s_style_default_page_layoutc             C   sV   | t  d f } | j d d  } d | |  _ |  j j |  j  i  |  j |  j <d S)z Collect the formatting for the page layout style.
            This won't work in CSS 2.1, as page identifiers are not allowed.
            It is legal in CSS3, but the rest of the application doesn't specify when to use what page layout
        r5   r  r  z.PL-N)r   r  r  r   ra   r   )r.   rl   rm   r5   r/   r/   r0   r     s
    zODF2XHTML.s_style_page_layoutc             C   s   d |  _  d S)z End this style
        N)r  )r.   rl   rm   r/   r/   r0   r     s    zODF2XHTML.e_style_page_layoutc             C   s   | t  d f } | j d d  } d | |  _ |  j j |  j  i d d 6|  j |  j <| j t  d f d	  } | r d
 | } | |  j k r |  j | } xE | j   D]  \ } } | |  j |  j | <q Wq | |  j |  j d <n  |  j | |  d	 S)z; Collect the formatting for the page layout style.
        r5   r  r  z.MP-rX   r^   rR   zpage-layout-nameNz.PL-z__parent-style-name)r^   zposition)	r   r  r  r   ra   r   rD   r`   r   )r.   rl   rm   r5   Z
pagelayoutr   r   r=   r/   r/   r0   r     s    
zODF2XHTML.s_style_master_pageZDPzdrawing-pagePZPRSDTZTDZTCZTRGc             C   s  | t  d f } | j d d  } | t  d f } |  j j | d  } |  j j | d  } d |  j | | f } | j t  d f  } t j | d |  |  _ |  j j	 |  j  |  j |  j
 k r i  |  j
 |  j <n  | |  j
 |  j d	 <| rd
 | | f } t j | d |  } | |  j
 k rh|  j
 | } xE | j   D]  \ }	 }
 |
 |  j
 |  j |	 <qAWq| |  j
 |  j d <n  d S)au   Collect the formatting for the style.
            Styles have scope. The same name can be used for both paragraph and
            character styles Since CSS has no scope we use a prefix. (Not elegant)
            In ODF a style can have a parent, these parents can be chained.
            We may not have encountered the parent yet, but if we have, we resolve it.
        r5   r  r  r6   rC  Xz%s%s-%szparent-style-namez__style-familyz%s-%sz__parent-style-nameN)r   r  rD  rD   _familyshortr<  special_stylesr  r   ra   r   r`   )r.   rl   rm   r5   r6   rE  Zsfamilyr)  r   r   r=   r/   r/   r0   r     s(    zODF2XHTML.s_style_stylec             C   s   d |  _  d S)z End this style
        N)r  )r.   rl   rm   r/   r/   r0   r   1  s    zODF2XHTML.e_style_stylec             C   sr   | j  t d f d  } | rW |  j rW | j d d  } |  j d i d | d 6 n |  j d  |  j   d S)z Start a table
        z
style-nameNr  r  r   zT-%sr   )rD   r   r   r  r	  r  )r.   rl   rm   ru   r/   r/   r0   r   6  s    zODF2XHTML.s_table_tablec             C   s%   |  j    |  j d  |  j   d S)z End a table
        r   N)r  r
  r  )r.   rl   rm   r/   r/   r0   r   A  s    
zODF2XHTML.e_table_tablec             C   s   i  } | j  t d f  } | r. | | d <n  | j  t d f  } | rV | | d <n  | j  t d f  } | r d | j d d  | d	 <n  |  j d
 |  |  j   d S)z Start a table cell znumber-rows-spannedrowspanznumber-columns-spannedcolspanz
style-namezTD-%sr  r  r   r@  N)rD   r   r  r	  r  )r.   rl   rm   r*  rV  rW  ru   r/   r/   r0   r   H  s    zODF2XHTML.s_table_table_cellc             C   s%   |  j    |  j d  |  j   d S)z End a table cell r@  N)r  r
  r  )r.   rl   rm   r/   r/   r0   r   Z  s    
zODF2XHTML.e_table_table_cellc             C   s   | j  t d f d  } t | j  t d f d   } i  } | r_ d | j d d  | d <n  x$ t |  D] } |  j d	 |  ql W|  j   d S)
z Start a table column z
style-nameNznumber-columns-repeatedr>   zTC-%sr  r  r   rA  )rD   r   intr  r9  r  r  )r.   rl   rm   ru   Zrepeatedr*  rY   r/   r/   r0   r   `  s    zODF2XHTML.s_table_table_columnc             C   s_   | j  t d f d  } i  } | rA d | j d d  | d <n  |  j d |  |  j   d S)z Start a table row z
style-nameNzTR-%sr  r  r   rB  )rD   r   r  r	  r  )r.   rl   rm   ru   r*  r/   r/   r0   r   k  s    zODF2XHTML.s_table_table_rowc             C   s%   |  j    |  j d  |  j   d S)z End a table row rB  N)r  r
  r  )r.   rl   rm   r/   r/   r0   r   u  s    
zODF2XHTML.e_table_table_rowc             C   s|   |  j    | t d f j d  d } | d d k rW d |  j | d d   } n  |  j d i | d 6 |  j   d S)z Anchors start r$  |r   #r>   Nr   )r  r   rI   r  r	  r  )r.   rl   rm   r$  r/   r/   r0   r   {  s    
 zODF2XHTML.s_text_ac             C   s(   |  j    |  j d d  |  j   d S)z% End an anchor or bookmark reference r   FN)r  r
  r  )r.   rl   rm   r/   r/   r0   r     s    
zODF2XHTML.e_text_ac             C   s^   | t  d f } |  j |  } |  j   |  j d i | d 6 |  j d d  |  j   d S)z Bookmark definition r5   r   r8  FN)r   r  r  r	  r
  r  )r.   rl   rm   r5   html_idr/   r/   r0   r     s    
zODF2XHTML.s_text_bookmarkc             C   sR   | t  d f } d |  j |  } |  j   |  j d i | d 6 |  j   d S)z Bookmark reference zref-namerZ  r   r$  N)r   r  r  r	  r  )r.   rl   rm   r5   r[  r/   r/   r0   r     s
    
zODF2XHTML.s_text_bookmark_refc             C   s   t  | t d f  } | d k r+ d } n  | d k  r@ d } n  |  j | d |  j | <|  j |  } x( t | d d  D] } d |  j | <q{ Wt j d |  } | s |  j r |  j d |  n |  j d | i d | d	 6 |  j	   d
 S)z Headings start zoutline-level   r>   
   r   zP-zh%szP-%sr   N)
rX  r   r   r  r9  rU  rD   r   r	  r  )r.   rl   rm   levelr5   rY   specialr/   r/   r0   r     s     	 	zODF2XHTML.s_text_hc             C   s  |  j    t | t d f  } | d k r5 d } n  | d k  rJ d } n  |  j d | d  } d j t t |   } d j |  j  } |  j d k r | |  _ n  |  j	 d | | f  } |  j
 d i | d 6 |  j d d	  |  j d
 |  |  j   d S)z Headings end
            Side-effect: If there is no title in the metadata, then it is taken
            from the first heading of any level.
        zoutline-levelr\  r>   r  r^   z%s.%sr   r8  Fzh%sN)r  rX  r   r   r  mapstrr   r|   r  r	  r
  r  )r.   rl   rm   r^  Zlevoutlineheadinganchorr/   r/   r0   r     s     
 	 	 zODF2XHTML.e_text_hc             C   s%   |  j    |  j d  |  j   d S)z Force a line break (<br/>) brN)r  r  r  )r.   rl   rm   r/   r/   r0   r     s    
zODF2XHTML.s_text_line_breakc             C   s   | j  t d f  } |  j j |  d } | rF | j d d  } n |  j j t d f  } d | | f } |  j r |  j d |  j j  | d  i | d 6 n  |  j d |  j j  | d   |  j	   d	 S)
z Start a list (<ul> or <ol>)
            To know which level we're at, we have to count the number
            of <text:list> elements on the tagstack.
        z
style-namer>   r  r  z%s_%dz%sulr   N)
rD   r   r   rv   r  rt   r   r	  r   r  )r.   rl   rm   r5   r^  
list_classr/   r/   r0   r     s    	- zODF2XHTML.s_text_listc             C   s   |  j    | j t d f  } |  j j |  d } | rP | j d d  } n |  j j t d f  } d | | f } |  j |  j j | d   |  j	   d S)z End a list z
style-namer>   r  r  z%s_%drf  N)
r  rD   r   r   rv   r  rt   r
  r   r  )r.   rl   rm   r5   r^  rg  r/   r/   r0   r     s    
zODF2XHTML.e_text_listc             C   s   |  j  d  |  j   d S)z Start list item r7  N)r	  r  )r.   rl   rm   r/   r/   r0   r     s    zODF2XHTML.s_text_list_itemc             C   s%   |  j    |  j d  |  j   d S)z End list item r7  N)r  r
  r  )r.   rl   rm   r/   r/   r0   r     s    
zODF2XHTML.e_text_list_itemc             C   s   |  j  j t d f  } | t d f } |  j |  _ d | | f } d |  j | <d | j d d  | f |  _ |  j j	 |  j  i  |  j
 |  j <t |  } d | d } | |  j
 |  j d <d S)z CSS doesn't have the ability to set the glyph
            to a particular character, so we just go through
            the available glyphs
        r5   r^  z%s_%srf  z.%s_%sr  r  squaredisccircle   r^   list-style-typeN)rh  ri  rj  )r^   rl  )r   rt   r   r   r  	prevstyler   r  r   ra   r   rX  )r.   rl   rm   r5   r^  rg  listtyper/   r/   r0   r     s    z(ODF2XHTML.s_text_list_level_style_bulletc             C   s   |  j  |  _ |  `  d  S)N)rm  r  )r.   rl   rm   r/   r/   r0   r     s    z(ODF2XHTML.e_text_list_level_style_bulletc             C   s3  |  j  j   t d f } | t d f } | j t d f d  } d | | f } |  j |  _ d | j d d  | f |  _ d |  j | <|  j	 j
 |  j  i  |  j |  j <| d k r d	 } nZ | d
 k r d } nE | d k r d } n0 | d k r d } n | d k rd } n d	 } | |  j |  j d <d  S)Nr5   r^  1z%s_%sz.%s_%sr  r  r6  ZdecimalIzupper-romanizlower-romanr;  zupper-alphar   zlower-alphar^   list-style-type)r^   rr  )r   rr   r   r   rD   r  rm  r  r   r   ra   r   )r.   rl   rm   r5   r^  Z
num_formatrg  rn  r/   r/   r0   r   
  s*     	 	 	 	 	z(ODF2XHTML.s_text_list_level_style_numberc             C   s   |  j  |  _ |  `  d  S)N)rm  r  )r.   rl   rm   r/   r/   r0   r     s    z(ODF2XHTML.e_text_list_level_style_numberc             C   sA   |  j    |  j   |  j d |  _ i  |  j |  j <g  |  _ d  S)Nr>   )r  r  r   r   r   )r.   rl   rm   r/   r/   r0   r      s
    

zODF2XHTML.s_text_notec             C   s   d  S)Nr/   )r.   rl   rm   r/   r/   r0   e_text_note'  s    zODF2XHTML.e_text_notec             C   s#   | d k r |  j  j |  n  d  S)Nr^   )r   ra   )r.   r   r/   r/   r0   collectnote*  s    zODF2XHTML.collectnotec             C   s   |  j  |  _ |  j |  _  d  S)N)r   	_orgwfuncrt  )r.   rl   rm   r/   r/   r0   r   .  s    zODF2XHTML.s_text_note_bodyc             C   s?   |  j  |  _ d j |  j  |  j |  j d <d |  _ |  `  d  S)Nr^   r1  )ru  r   r  r   r   r   )r.   rl   rm   r/   r/   r0   r   2  s     	zODF2XHTML.e_text_note_bodyc             C   s   d j  |  j  } | |  j |  j d <|  j d i d |  j d 6 |  j d  t j d d k rw |  j |  j  n |  j t |  j   |  j	 d  |  j	 d  d  S)	Nr^   Zcitationr   z#footnote-%sr$  supr   rk  )
r  r   r   r   r	  sysversion_infor  unicoder
  )r.   rl   rm   markr/   r/   r0   r   8  s    zODF2XHTML.e_text_note_citationc             C   s   i  } d } | j  t d f d  } | r | j d d  } t j  d |  } | d k r d } |  j r~ d | | d <q~ q n  |  j | |  |  j   d S)	z Paragraph
        rd   z
style-nameNr  r  zP-zP-%sr   )rD   r   r  rU  r   r	  r  )r.   rl   rm   r*  
specialtagru   r/   r/   r0   r   G  s    	zODF2XHTML.s_text_pc             C   s   d } | j  t d f d  } | ra | j d d  } t j  d |  } | d k ra d } qa n  |  j   |  j |  |  j   d S)z End Paragraph
        rd   z
style-nameNr  r  zP-)rD   r   r  rU  r  r
  r  )r.   rl   rm   r{  ru   r/   r/   r0   r   W  s    
zODF2XHTML.e_text_pc             C   sF   | j  t d f d  } x' t t |   D] } |  j d  q+ Wd S)z Generate a number of spaces. ODF has an element; HTML uses &nbsp;
            We use &#160; so we can send the output through an XML parser if we desire to
        ru   ro  z&#160;N)rD   r   r9  rX  r  )r.   rl   rm   ru   rY   r/   r/   r0   r   e  s    zODF2XHTML.s_text_sc             C   s   |  j    | j t d f d  } i  } | r| | j d d  } t j d |  } | d k r| |  j r| d | | d <q| n  |  j d |  |  j   d S)	z The <text:span> element matches the <span> element in HTML. It is
            typically used to properties of the text.
        z
style-nameNr  r  zS-zS-%sr   r   )r  rD   r   r  rU  r   r	  r  )r.   rl   rm   ru   r*  r_  r/   r/   r0   r   m  s    
zODF2XHTML.s_text_spanc             C   s(   |  j    |  j d d  |  j   d S)z End the <text:span> r   FN)r  r
  r  )r.   rl   rm   r/   r/   r0   r   |  s    
zODF2XHTML.e_text_spanc             C   s%   |  j    |  j d  |  j   d S)z: Move to the next tabstop. We ignore this in HTML
        rE   N)r  r  r  )r.   rl   rm   r/   r/   r0   r     s    
zODF2XHTML.s_text_tabc             C   s(   |  j    |  j   |  j | |  d S)zB Various indexes and tables of contents. We ignore those.
        N)r  r  r   )r.   rl   rm   r/   r/   r0   r     s    

zODF2XHTML.s_text_x_sourcec             C   s   |  j    |  j   d S)zB Various indexes and tables of contents. We ignore those.
        N)r  r  )r.   rl   rm   r/   r/   r0   r     s    
zODF2XHTML.e_text_x_sourcec             C   s   t  |  t  d  k sT d t |  k sT d t |  k sT d t |  k sT t  g  |  _ |  j |  _ t  |  t  d  k r t |  |  _ n	 | |  _ |  j |  j j	  d S)z
        Loads a document into the parser and parses it.
        The argument can either be a filename or a document in memory.
        @param odffile if the type is unicode string: name of a file; else
        it must be an open file type
        r^   rbBufferedReaderBytesION)
r/  reprAssertionErrorr   r   r   r   r   r+  r,  )r.   odffiler/   r/   r0   r     s    T		zODF2XHTML.loadc             C   s   | j  t j k rh |  j | j | j | j  x | j D] } |  j |  q8 W|  j	 | j | j  n  | j  t j
 k s | j  t j k r t j d d k r |  j t |   q |  j t |   n  d  S)Nr   rk  )ZnodeTyper   ZELEMENT_NODEr  r  ZtagNameZ
attributesZ
childNodesr+  r  Z	TEXT_NODEZCDATA_SECTION_NODErw  rx  r  ra  ry  )r.   noderu   r/   r/   r0   r+    s    $zODF2XHTML._walknodec             C   s   t  |  t  d  k sT d t |  k sT d t |  k sT d t |  k sT t  |  j |  |  j   } t  |  t  d  k s t  | S)z
        Load a file and return the XHTML
        @param odffile if the type is unicode string: name of a file; else
        it must be an open file type
        @return XHTML code as a a unicode string
        r^   r|  r}  r~  )r/  r  r  r   xhtml)r.   r  resultr/   r/   r0   	odf2xhtml  s
    TzODF2XHTML.odf2xhtmlc             C   s#   | d k r |  j  j |  n  d  S)Nr^   )r   ra   )r.   r   r/   r/   r0   r     s     zODF2XHTML._wlinesc             C   s   d j  |  j  S)z Returns the xhtml
        r^   )r  r   )r.   r/   r/   r0   r    s    zODF2XHTML.xhtmlc             C   s#   | d k r |  j  j |  n  d  S)Nr^   )	_csslinesra   )r.   r   r/   r/   r0   	_writecss  s     zODF2XHTML._writecssc             C   s   d  S)Nr/   )r.   r   r/   r/   r0   _writenothing  s    zODF2XHTML._writenothingc             C   sG   g  |  _  |  j |  _ |  j   d j |  j   } |  j |  _ |  `  | S)z Returns the CSS content r^   )r  r  r   r2  r  r   )r.   resr/   r/   r0   css  s    	
zODF2XHTML.cssc             C   sg   | d k r t  j } n" | r+ | d } n  t | d  } | j |  j   j d d   | j   d S)z Save the HTML under the filename.
            If the filename is '-' then save to stdout
            We have the last style filename in self.stylefilename
        -z.htmlwzus-asciixmlcharrefreplaceN)rw  stdoutfilewriter  encodeclose)r.   
outputfileZ	addsuffixZoutputfpr/   r/   r0   save  s    zODF2XHTML.save){rf   rg   rh   ri   r1   r   r   r   r   r   r  r  r	  r
  r  r  r  r  r  r  r  r  r   r   r   r  r  r  r   r   r   r   r   r   r   r   r   r%  r   r   r   r   r   r   r   r3  r5  r2  r:  r   r   r   r   r   r   r   r   r   r   r   r   rD  r   r   r   rF  rG  rH  rJ  rK  rL  rM  r   r   r   rT  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rs  rt  r   r   r   r   r   r   r   r   r   r   r   r   r+  r  r   r  r  r  r  r  r/   r/   r/   r0   r{   Y  s   g	
				 
		
r{   c               @   s(   e  Z d  Z d Z d d d d  Z d S)ODF2XHTMLembeddedz4 The ODF2XHTML parses an ODF file and produces XHTMLTFc             C   s  |  j    | |  _ | |  _ i1 |  j |  j f t d f 6|  j d  f t d f 6|  j d  f t d f 6|  j d  f t d f 6|  j	 |  j
 f t d f 6|  j d  f t d f 6|  j d  f t d f 6|  j |  j f t d f 6|  j d  f t d	 f 6|  j d  f t d
 f 6|  j d  f t d f 6|  j d  f t d f 6|  j d  f t d f 6|  j d  f t d f 6|  j d  f t d f 6|  j d  f t d f 6|  j d  f t d f 6|  j d  f t d f 6|  j d  f t d f 6|  j |  j f t d f 6|  j d  f t d f 6|  j |  j f t d f 6|  j |  j f t d f 6|  j |  j f t d f 6|  j |  j  f t d f 6|  j d  f t d f 6|  j |  j  f t d f 6|  j! |  j" f t d f 6|  j |  j  f t d f 6|  j# d  f t d f 6|  j d  f t d f 6|  j$ |  j% f t d  f 6|  j& |  j' f t d! f 6|  j( |  j) f t d" f 6|  j* |  j+ f t d# f 6d2 t d$ f 6|  j, d  f t d% f 6|  j- |  j. f t d& f 6d  |  j/ f t d' f 6|  j d  f t d( f 6|  j |  j  f t d) f 6|  j0 |  j1 f t d* f 6|  j2 d  f t d+ f 6|  j3 |  j4 f t d, f 6|  j5 d  f t d- f 6|  j |  j  f t d. f 6|  j |  j  f t d/ f 6|  j |  j  f t d0 f 6d3 t d1 f 6|  _6 d  S)4Nr   r   z
fill-imagez	layer-setr   r   z
object-oleztext-boxzboolean-stylezcurrency-stylez
date-styleznumber-stylez
text-styler   r   r   r   r   zcovered-table-cellz
table-cellztable-columnz	table-rowr   r   zalphabetical-index-sourcezbibliography-configurationzbibliography-sourcer   zillustration-index-sourcez
line-breakzlinenumbering-configurationr   z	list-itemzlist-level-style-bulletzlist-level-style-numberz
list-styler   z	note-bodyznote-citationznotes-configurationzobject-index-sourcerd   r   r   r   ztable-index-sourceztable-of-content-sourcezuser-index-sourcezpage-number)NN)NN)7r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r.   r   r   r   r/   r/   r0   r1     sj    
		zODF2XHTMLembedded.__init__N)rf   rg   rh   ri   r1   r/   r/   r/   r0   r    s   r  )+rw  os.pathospathra   dirname__file__Zxml.saxr   Zxml.sax.saxutilsr   r   Zxml.domr   Zopendocumentr   Zodf.namespacesr   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rj   rU  ZContentHandlerr{   r  r/   r/   r/   r0   <module>   s:   
    