U
    ª6#^ ã                   @   s  d dl Z d dlZe j e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$ G dd„ dƒZ%G d	d
„ d
ƒZ&dddddddddddddddœZ'G dd„ dej(ƒZ)G d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              J   C   sˆ  i | _ i | _tdf| jtdf| jtdf| jtdf| jtdf| jtdf| jtdf| jtdf| jtd	f| jtd
f| jtdf| jtdf| jtdf| jtdf| jtdf| jtdf| jtdf| jtdf| jtdf| jtdf| jtdf| jtdf| jtdf| jtdf| jtdf| jtdf| jtdf| jtdf| jtdf| jt	df| j
tdf| jtd f| jtd!f| jtd"f| jtd#f| jtd$f| jtd%f| ji%| _d S )&Nzfill-image-namezbackground-colorZborderzborder-bottomzborder-leftzborder-rightz
border-topZcolorúfont-familyú	font-sizez
font-stylezfont-variantzfont-weightzline-heightÚmarginzmargin-bottomúmargin-leftúmargin-rightz
margin-topú
min-heightÚpaddingzpadding-bottomzpadding-leftzpadding-rightzpadding-topz
page-widthzpage-heightú
text-alignztext-indentzborder-modelzcolumn-widthz	font-namezhorizontal-posztext-positionztext-line-through-styleztext-underline-styleÚwidth)ÚfontdictÚ
fillimagesr   Úc_drawfillimager   Úc_foÚc_page_widthÚc_page_heightÚc_text_alignr   Úc_border_modelr   Úc_widthÚc_fnÚc_hpÚc_text_positionÚc_text_line_through_styleÚc_text_underline_styleÚruleconversions©Úself© r6   úM/var/www/html/UseVoiceDocker/env/lib/python3.8/site-packages/odf/odf2xhtml.pyÚ__init__?   sš                                         ÛzStyleToCSS.__init__c                 C   sh   d}|dkrd}nD|dkr d}n6|dkr.d}n(|dkr<d}n|dkrJd}n|d	krVd}||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%   )r5   ÚnameÚfamilyÚgenericÚhtmlgenericr6   r6   r7   Ú	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&   ©r5   ÚrulesetÚsdictÚruleÚvalr6   r6   r7   r'   €   s    zStyleToCSS.c_drawfillimagec                 C   s   |d }|||< dS )z XSL formatting attributes é   Nr6   )r5   rB   rC   rD   rE   Úselectorr6   r6   r7   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separateNr6   rA   r6   r6   r7   r,   Œ   s    
zStyleToCSS.c_border_modelc                 C   s   ||d< dS )z Set width of box r$   Nr6   rA   r6   r6   r7   r-   “   s    zStyleToCSS.c_widthc                 C   s$   |dkrd}|dkrd}||d< dS )z Text align ÚstartÚleftÚendÚrightr#   Nr6   )r5   rB   rC   rD   Zalignr6   r6   r7   r+   —   s
      zStyleToCSS.c_text_alignc                 C   sN   |  tdf¡}|dk	r$|  |||¡ | 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.
        úfont-family-genericNr9   z%s, %sr   )Úgetr   r@   r%   )r5   rB   rC   rD   Z	fontstyler>   r=   r?   r6   r6   r7   r.      s
    zStyleToCSS.c_fnc                 C   sj   |  d¡}t|ƒdkr.|d dkr.|d |d< |d dkrDd|d	< n"|d d
krZd|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%rF   r   Úsuperz33%zvertical-alignÚsubz-33%N)ÚsplitÚlen)r5   rB   rC   rD   ÚtpZtextposr6   r6   r7   r0   ¨   s    


zStyleToCSS.c_text_positionc                 C   s
  |  tdfd¡}|dkr(d|d< d|d< |dkrv|dkrBd	|d
< n2|dkrdd|d< d|d< d|d	< nd|d< d|d< n|dkrÄ|dkrd|d
< n2|dkr²d|d< d|d< d|d< nd|d< d|d< nB|dkr|dkràd|d
< n&d|d< tdf|kr|tdf |d< d S )NÚwrapÚparallelÚcenterÚautor   r    )rK   Zoutside)rI   rV   ÚdynamicrK   Úfloatzrun-throughZabsoluteÚpositionÚ0ÚtopZ0cm)rI   Zinside)rK   rV   rY   rI   )z	from-leftzfrom-inside)rK   rV   ÚrelativeÚx)rM   r   r   )r5   rB   rC   rD   ZhposrU   r6   r6   r7   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$   Nr6   rA   r6   r6   r7   r)   ð   s    zStyleToCSS.c_page_widthc                 C   s   |r|dkrd|d< dS )ú| Set underline decoration
            HTML doesn't really have a page-width. It is always 100% of the browser width
        ÚnoneZ	underlineútext-decorationNr6   rA   r6   r6   r7   r2   ö   s    z!StyleToCSS.c_text_underline_stylec                 C   s   |r|dkrd|d< dS )r`   ra   zline-throughrb   Nr6   rA   r6   r6   r7   r1   ý   s    z$StyleToCSS.c_text_line_through_stylec                 C   s   ||d< dS )z Set height of box ÚheightNr6   rA   r6   r6   r7   r*     s    zStyleToCSS.c_page_heightc                    sÆ   i }g }|  ¡ D ]H\}}|d dkr2|||d < qˆ j |d¡}|r| |||||g¡ qt‡ fdd„|ƒD ] }|\}}}}}|||||ƒ qlt‡ fdd„|ƒD ] }|\}}}}}|||||ƒ q |S )zj Rule is a tuple of (namespace, name). If the namespace is '' then
            it is already CSS2
        r   Ú rF   Nc                    s   | d ˆ j kS ©Nr   ©r/   ©r_   r4   r6   r7   Ú<lambda>  ó    z+StyleToCSS.convert_styles.<locals>.<lambda>c                    s   | d ˆ j kS re   rf   rg   r4   r6   r7   rh     ri   )Úitemsr3   rM   ÚappendÚfilter)r5   rB   rC   Z
proceduresrD   rE   ÚmethodÚpr6   r4   r7   Úconvert_styles  s     zStyleToCSS.convert_stylesN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r8   r@   r'   r(   r,   r-   r+   r.   r0   r/   r)   r2   r1   r*   ro   r6   r6   r6   r7   r   9   s    0*r   c                   @   s<   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©Ústackr4   r6   r6   r7   r8   #  s    zTagStack.__init__c                 C   s   | j  ||f¡ d S ru   )rw   rk   ©r5   ÚtagÚattrsr6   r6   r7   Úpush&  s    zTagStack.pushc                 C   s   | j  ¡ }|S ru   )rw   Úpop©r5   Úitemr6   r6   r7   r|   )  s    
zTagStack.popc                 C   s   | j d }|d S )NéÿÿÿÿrF   rv   r}   r6   r6   r7   Ústackparent-  s    
zTagStack.stackparentc                 C   s(   | j D ]\}}||kr||   S qdS )z% Find a tag with the given attribute Nrv   )r5   Úattrry   rz   r6   r6   r7   Ú	rfindattr1  s    zTagStack.rfindattrc                 C   s(   d}| j D ]\}}||kr
|d }q
|S )Nr   rF   rv   )r5   ry   ÚcZttagZtattrsr6   r6   r7   Ú
count_tags7  s
     
zTagStack.count_tagsN)	rp   rq   rr   r8   r{   r|   r€   r‚   r„   r6   r6   r6   r7   rt   "  s   rt   ZemZciteZstrongÚvarZdfnÚttZh1Zh2Zh3Zh4Zh5Zh6ÚaddressÚpre)z
S-Emphasisz
S-CitationzS-Strong_20_Emphasisz
S-VariablezS-Definitionz
S-TeletypezP-Heading_20_1zP-Heading_20_2zP-Heading_20_3zP-Heading_20_4zP-Heading_20_5zP-Heading_20_6zP-AddresseezP-Preformatted_20_Textc                   @   s
  e Zd ZdZ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fdd„Zddd„Zi f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d1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;d<„ Zd=d>„ Z d?d@„ Z!dAdB„ Z"dCdD„ Z#dEdF„ Z$dGdH„ Z%dIdJ„ Z&dKdL„ Z'dMdN„ Z(dOdP„ Z)dQdR„ Z*dSdT„ Z+dUdV„ Z,dWdX„ Z-dYZ.dZd[„ Z/d\d]„ Z0d^d_„ Z1d`da„ Z2dbdc„ Z3ddde„ Z4dfdg„ Z5dhdi„ Z6djdk„ Z7dldm„ Z8dndo„ Z9dpdq„ Z:drds„ Z;dtdu„ Z<dvdwdxdydzd{d|d}d~dd€œ
Z=dd‚„ Z>dƒd„„ Z?d…d†„ Z@d‡dˆ„ ZAd‰dŠ„ ZBd‹dŒ„ ZCddŽ„ ZDdd„ ZEd‘d’„ ZFd“d”„ ZGd•d–„ ZHd—d˜„ ZId™dš„ ZJd›dœddždŸd d¡d¢d£d¤d¥œ
ZKd¦d§„ ZLd¨d©„ ZMdªd«„ ZNd¬d­„ ZOd®d¯„ ZPd°d±„ ZQd²d³„ ZRd´dµ„ ZSd¶d·„ ZTd¸d¹„ ZUdºd»„ ZVd¼d½„ ZWd¾d¿„ ZXdÀdÁ„ ZYdÂdÃ„ ZZdÄdÅ„ Z[dÆdÇ„ Z\dÈdÉ„ Z]dÊdË„ Z^dÌdÍ„ Z_dÎdÏ„ Z`dÐdÑ„ ZadÒdÓ„ ZbdÔdÕ„ ZcdÖd×„ ZddØdÙ„ ZedÚdÛ„ ZfdÜdÝ„ ZgdÞdß„ Zhdàdá„ Zidâdã„ Zjdädå„ Zkdædç„ Zldèdé„ Zmdêdë„ Zndìdí„ Zodîdï„ Zpdðdñ„ Zqdòdó„ Zrdôdõ„ Zsdöd÷„ Ztdødù„ Zudúdû„ Zvdüdý„ Zwdþdÿ„ Zxd d„ Zyddd„Zzd
S (  Ú	ODF2XHTMLú4 The ODF2XHTML parses an ODF file and produces XHTMLTFc              ¯   C   s4  || _ tdf| j| jftdf| j| jftdf| j| jftdf| j| jftdf| j| jftdf| j| j	ftdf| j
| jftdf| jd ftd	f| jd ftd
f| jd ftdf| jd ftdf| jd ftdf| j| jftdf| j| jftdf| j| jftdf| j| jftdf| j| jftdf| j| jftdf| jd ftdf| jd ftdf| jd ftdf| jd ftdf| jd ftdf| jd ftdf| jd ftdf| j| jftdf| j| jftdf| jd ftdf| jd ftdf| jd ftdf| j| jftd f| j| j ftd!f| j!d ftd"f| j"| j#ftd#f| jd ftd$f| jd ft$d%f| jd ft%d&f| jd ft%d'f| j&| j'ft%d(f| j(d ft%d)f| j)d ft%d*f| j(d ft%d+f| jd ft%d,f| j*d ft%d-f| j(d ft%d.f| j+| j,ft%d/f| j(d ft%d0f| j-| j.ft%d1f| j(d ft%d2f| j(d ft%d3f| j(d ft%d4f| j(d ft/d5f| jd ft0d6f| jd ft0d7f| j1| j2ft0d8f| j3d ft0d9f| j4| j5ft0d:f| j6| j7ft8d;f| j9| j:ft8d<f| j;| j<ft8d=f| jd ft8d>f| j;| j<ft8d?f| j=d ft8d@f| j=d ft8dAf| j>| j:ft8dBf| j>d ft8dCf| j?| j@ft8dDf| j;| j<ft8dEf| jAd ft8dFf| jd ft8dGf| jB| jCft8dHf| jD| jEft8dIf| jF| jGft8dJf| jH| jIft8dKfdLt8dMf| jJd ft8dNf| jK| jLft8dOfd | jMft8dPf| jd ft8dQf| j;| j<ft8dRf| jN| jOft8dSf| jPd ft8dTf| jQ| jRft8dUf| jSd ft8dVf| j;| j<ft8dWf| j;| j<ft8dXf| j;| j<fiW| _T|r(|  U¡  |  V¡  d S )YNÚtitleÚlanguageÚcreatorÚdescriptionÚdatezcustom-shapeÚframeÚimageú
fill-imageú	layer-setÚobjectú
object-oleÚpageútext-boxzcreation-dateÚ	generatorzinitial-creatorÚkeywordúboolean-styleúcurrency-styleú
date-styleúnumber-styleú
text-styleÚ
annotationzautomatic-stylesÚdocumentú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Údescúcovered-table-cellú
table-cellútable-columnú	table-rowÚtableÚaúalphabetical-index-sourceúbibliography-configurationúbibliography-sourceZbookmarkzbookmark-startzbookmark-refzbookmark-ref-startÚhúillustration-index-sourceú
line-breakúlinenumbering-configurationÚlistú	list-itemúlist-level-style-bulletúlist-level-style-numberú
list-style©NNÚnoteú	note-bodyúnote-citationúnotes-configurationúobject-index-sourcern   ÚsÚspanÚtabútable-index-sourceútable-of-content-sourceúuser-index-source)WÚgenerate_cssr
   Ús_processcontÚ
e_dc_titleÚe_dc_contentlanguageÚe_dc_creatorÚe_dc_metatagr   Ús_custom_shapeÚe_custom_shapeÚ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_tabler   Ús_text_aÚe_text_aÚ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)r5   rÊ   Ú	embedabler6   r6   r7   r8   \  sf    
 
 
 
 
 
 
      
 
 
 
 
 
        
 
    
 
  
     
       
  
       
  
 
 
 
  
   
  
 
   
 
 
 
   
   
 
  
  
 
 
¢`zODF2XHTML.__init__c                 C   s
   d| _ dS )z% Tell the parser to not generate CSS FN)rÊ   r4   r6   r6   r7   Ú	set_plainÃ  s    zODF2XHTML.set_plainc                 C   s<   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>r¾   r§   r¥   r¤   r¡   N)r  r   r4   r6   r6   r7   r  Ç  s    zODF2XHTML.set_embedableNc                 C   s:   d| _ || _|r&| j d||f ¡ n| 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Úmetatagsrk   )r5   r  Zmediar6   r6   r7   Úadd_style_fileÏ  s
    zODF2XHTML.add_style_filec                 C   s   i | _ d| _d| _d S )Nr   rd   )ÚnotedictÚcurrentnoteÚnotebodyr4   r6   r6   r7   Ú_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 | _|  ¡  g | _d S )Nrd   Tr   )ÚlinesÚ_wlinesÚ_wfuncÚxmlfiler‹   rŒ   r   Údatart   ÚtagstackÚ	htmlstackÚpstackÚprocesselemÚprocesscontÚ	listtypesÚheadinglevelsr  r   ÚcsÚanchorsÚ
stylestackÚ	styledictÚcurrentstyler   r  r4   r6   r6   r7   r  à  s,    zODF2XHTML._resetobjectc                 C   s   |dkr|   |¡ d S ©Nrd   )r#  ©r5   rÄ   r6   r6   r7   Úwriteoutþ  s    zODF2XHTML.writeoutc                 C   s&   d  | j¡}|dkr"|  t|ƒ¡ d S r2  )Újoinr%  r4  r   )r5   Údr6   r6   r7   Ú	writedata  s    zODF2XHTML.writedatac                 C   sˆ   | j  |||f¡ g }| ¡ D ]\}}| d|t|ƒf ¡ qt|ƒdkrZ|  d| ¡ n|  d|d |¡f ¡ |dkr„|  d¡ dS )	z Create an open HTML tag ú%s=%sr   z<%s>z<%s %s>rN   TÚ
N)r'  rk   rj   r   rS   r4  r5  )r5   ry   rz   Úblockr±   ÚkeyrE   r6   r6   r7   Úopentag  s    zODF2XHTML.opentagc                 C   s.   | j  ¡  |  d| ¡ |dkr*|  d¡ dS )z Close an open HTML tag z</%s>Tr9  N)r'  r|   r4  )r5   ry   r:  r6   r6   r7   Úclosetag  s    
zODF2XHTML.closetagc                 C   sH   g }|  ¡ D ]\}}| d|t|ƒf ¡ q|  d|d |¡f ¡ d S )Nr8  z	<%s %s/>
rN   )rj   rk   r   r4  r5  )r5   ry   rz   r±   r;  rE   r6   r6   r7   Úemptytag  s    zODF2XHTML.emptytagc                 C   s   | j r| jr| j |¡ d S ru   )r)  r*  r%  rk   )r5   r%  r6   r6   r7   Ú
characters$  s    zODF2XHTML.charactersc                 C   s^   | j  | j| jf¡ | jrL| j |d¡d }|r@|  |||¡ n|  ||¡ | j 	||¡ d S )Nr¾   r   )
r(  rk   r)  r*  r  rM   Úhandle_starttagÚunknown_starttagr&  r{   )r5   ry   Úqnamerz   rm   r6   r6   r7   ÚstartElementNS(  s    zODF2XHTML.startElementNSc                 C   s\   | j  ¡ \}}| jrF| j |d¡d }|r:|  |||¡ n|  ||¡ | j ¡ \| _| _d S )Nr¾   rF   )	r&  r|   r)  r  rM   Úhandle_endtagÚunknown_endtagr(  r*  )r5   ry   rB  Zstagrz   rm   r6   r6   r7   ÚendElementNS2  s    zODF2XHTML.endElementNSc                 C   s   |||ƒ d S ru   r6   )r5   ry   rm   rz   r6   r6   r7   r@  =  s    zODF2XHTML.handle_starttagc                 C   s   |||ƒ d S ru   r6   )r5   ry   rz   rm   r6   r6   r7   rD  @  s    zODF2XHTML.handle_endtagc                 C   s   d S ru   r6   rx   r6   r6   r7   rA  C  s    zODF2XHTML.unknown_starttagc                 C   s   d S ru   r6   rx   r6   r6   r7   rE  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)  rx   r6   r6   r7   rÖ   I  s    zODF2XHTML.s_ignorexmlc                 C   s
   d| _ dS )z  Stop processing the text nodes FN©r*  rx   r6   r6   r7   rá   O  s    zODF2XHTML.s_ignorecontc                 C   s
   d| _ dS )z! Start processing the text nodes TNrG  rx   r6   r6   r7   rË   S  s    zODF2XHTML.s_processcontc                 C   s    |  tdfd¡}| dd¡}|S )z) Generate a class name from a style name ú
style-namerd   Ú.Ú_)rM   r   Úreplace)r5   rz   rƒ   r6   r6   r7   Ú	classnameW  s    zODF2XHTML.classnamec                 C   s.   || j kr"dt| j ƒd  | j |< | j  |¡S )z+ Create a unique anchor id for a href name z
anchor%03drF   )r.  rS   rM   )r5   r<   r6   r6   r7   Ú
get_anchor]  s    
zODF2XHTML.get_anchorc                 C   s
   g | _ d S ru   )r%  r4   r6   r6   r7   Ú	purgedataf  s    zODF2XHTML.purgedatac                 C   s   d  | j¡| _g | _dS )zD Get the title from the meta data and create a HTML <title>
        rd   N)r5  r%  r‹   rx   r6   r6   r7   rÌ   n  s    zODF2XHTML.e_dc_titlec                 C   s.   | j  d|d td | j¡ƒf ¡ g | _dS )z: Any other meta data is added as a <meta> element
        z<meta name="%s" content=%s/>
rF   rd   N)r  rk   r   r5  r%  rx   r6   r6   r7   rÏ   u  s    $zODF2XHTML.e_dc_metatagc                 C   s.   d  | j¡| _| j dt| jƒ ¡ g | _dS )zD Set the content language. Identifies the targeted audience
        rd   z3<meta http-equiv="content-language" content="%s"/>
N)r5  r%  rŒ   r  rk   r   rx   r6   r6   r7   rÍ   {  s    zODF2XHTML.e_dc_contentlanguagec                 C   s.   d  | j¡| _| j dt| jƒ ¡ g | _dS )zC Set the content creator. Identifies the targeted audience
        rd   z*<meta http-equiv="creator" content="%s"/>
N)r5  r%  r   r  rk   r   rx   r6   r6   r7   rÎ   ‚  s    zODF2XHTML.e_dc_creatorc                 C   s>  |  tdfd¡}d}d|  tdfd¡ }|dkrDd|  tdfd¡ }| dd	¡}|d
kr^d}n$|dkrld}n|dkr~d}d}nd}tdf|kr¦|d |tdf  d }tdf|krÊ|d |tdf  d }tdf|krî|d |tdf  d }tdf|kr|d |tdf  d }| jr0|  |||dœ¡ n
|  |¡ dS )zQ A <draw:custom-shape> is made into a <div> in HTML which is then styled
        úanchor-typeÚnotfoundÚdivúG-rH  rd   úPR-rI  rJ  Ú	paragraphúposition:absolute;Úcharúas-charzposition: absolute;r$   úwidth:ú;rc   úheight:r_   úleft:Úyútop:©Úclassrª   N©rM   r   r   r   rK  r   rÊ   r<  ©r5   ry   rz   Úanchor_typeZhtmltagr<   rª   r6   r6   r7   rÐ   ‰  s2    zODF2XHTML.s_custom_shapec                 C   s   |   d¡ dS ©z End the <draw:frame>
        rQ  N©r=  rx   r6   r6   r7   rÑ   ¨  s    zODF2XHTML.e_custom_shapec                 C   s>  |  tdfd¡}d}d|  tdfd¡ }|dkrDd|  tdfd¡ }| dd	¡}|d
kr^d}n$|dkrld}n|dkr~d}d}nd}tdf|kr¦|d |tdf  d }tdf|krÊ|d |tdf  d }tdf|krî|d |tdf  d }tdf|kr|d |tdf  d }| jr0|  |||dœ¡ n
|  |¡ dS )zJ A <draw:frame> is made into a <div> in HTML which is then styled
        rO  rP  rQ  rR  rH  rd   rS  rI  rJ  rT  zposition:relative;rV  rW  rU  r$   rX  rY  rc   rZ  r_   r[  r\  r]  r^  Nr`  ra  r6   r6   r7   rÒ   ­  s2    zODF2XHTML.s_draw_framec                 C   s   |   d¡ dS rc  rd  rx   r6   r6   r7   rÓ   Ì  s    zODF2XHTML.e_draw_framec                 C   s6   |  tdfd¡}|tdf }|  |¡}|| jj|< d S )Nr<   ÚNoNameÚhref)rM   r   r   Úrewritelinkr-  r&   )r5   ry   rz   r<   Úimghrefr6   r6   r7   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
        r6   )r5   rh  r6   r6   r7   rg  ×  s    zODF2XHTML.rewritelinkc                 C   s^   | j  ¡ }| tdf¡}|tdf }|  |¡}d|dœ}| jrN|dkrNd|d< |  d|¡ d	S )
z2 A <draw:image> becomes an <img/> element
        rO  rf  rd   )ÚaltÚsrcrV  zdisplay: block;rª   ZimgN)r&  r€   rM   r   r   rg  rÊ   r>  )r5   ry   rz   Úparentrb  rh  Ú	htmlattrsr6   r6   r7   rÔ   Ý  s    


zODF2XHTML.s_draw_imagec                 C   s4   |t df }| jjD ]}|j|kr|  |j¡ qdS )z` A <draw:object> is embedded object in the document (e.g. spreadsheet in presentation).
        rf  N)r   r    ZchildobjectsZfolderÚ	_walknodeÚtopnode)r5   ry   rz   Zobjhrefrƒ   r6   r6   r7   r×   ê  s    

zODF2XHTML.s_draw_objectc                 C   sB   |t df }|r>| ¡ dkr>dddœ}|  d|¡ |  d|¡ 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_graphz	ole-graph)r<   r_  r±   N)r   Úlowerr<  r=  )r5   ry   rz   Zclass_idZtagattrsr6   r6   r7   rØ   û  s
    
zODF2XHTML.s_draw_object_olec                 C   s˜   |  tdfd¡}|  tdfd¡}| dd¡}|  tdfd¡}| dd¡}| jrh|  dd	d
||f i¡ n
|  d¡ |  d¡ |  t|ƒ¡ |  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.
        r<   re  rH  rd   rI  rJ  zmaster-page-nameÚfieldsetr_  zDP-%s MP-%sZlegendN)rM   r   rK  rÊ   r<  r4  r   r=  )r5   ry   rz   r<   Z	stylenameZ
masterpager6   r6   r7   rÙ     s    

zODF2XHTML.s_draw_pagec                 C   s   |   d¡ d S )Nrp  rd  rx   r6   r6   r7   rÚ     s    zODF2XHTML.e_draw_pagec                 C   s6   d}t df|kr(|d |t df  d }|  d¡ d S )Nrd   r!   zmin-height:rY  rQ  )r   r<  )r5   ry   rz   rª   r6   r6   r7   rÛ     s    zODF2XHTML.s_draw_textboxc                 C   s   |   d¡ dS )z! End the <draw:text-box>
        rQ  Nrd  rx   r6   r6   r7   rÜ      s    zODF2XHTML.e_draw_textboxc                 C   sp   |   ¡  | jrL| jrL|  dddid¡ |  d¡ |  ¡  |  d¡ |  d¡ |  ¡  |  d¡ | jddd	 d S )
Nrª   Útypeztext/cssTz/*<![CDATA[*/
z/*]]>*/
ÚheadÚbody©r:  )r7  rÊ   r  r<  r4  Úgenerate_stylesheetr=  rN  rx   r6   r6   r7   Ú	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.  | j D ]´}| j |¡}d|krb|d | jkrb| j|d   ¡ }|d= | ¡ D ]\}}|||< qL|}d|kr°|d | jkr°| j|d   ¡ }|d= | ¡ D ]\}}|||< q˜|}qb|| j|< q|  | j¡ | j D ]Z}| j |¡}| j |¡}|  d| ¡ | ¡ D ]\}}|  d||f ¡ q |  d¡ qÎd S )Nú__style-familyú__parent-style-namez%s {
z		%s: %s;
z}
)	r/  r0  rM   Úcopyrj   r4  Údefault_stylesr-  ro   )r5   r<   r¦   Zfamilystylerª   rE   ZparentstyleZcss2r6   r6   r7   ru  8  s.    



zODF2XHTML.generate_stylesheetc                 C   sŒ   | j dkrd S | jr(|  dddid¡ n
|  d¡ td| j d ƒD ]:}| j| }|  ddd	| i¡ |  |d
 ¡ |  d¡ qB|  d¡ d S )Nr   Úolrª   zborder-top: 1px solid blackTrF   ÚliÚidzfootnote-%drs  )r  rÊ   r<  Úranger  r4  r=  )r5   r;  r¿   r6   r6   r7   Úgenerate_footnotesT  s    


zODF2XHTML.generate_footnotesc                 C   s   | j dkrd| _nd| _d S )Nz
styles.xmlÚArd   )r$  Ú
autoprefixrx   r6   r6   r7   rÝ   f  s    
z#ODF2XHTML.s_office_automatic_stylesc                 C   st   |   d¡ |   d¡ |  dddid¡ | jddd |  d	d
ddœ¡ | jD ]}|   |¡ qL|   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xmlnszhttp://www.w3.org/1999/xhtmlTrr  rt  r£   zContent-Typeztext/html;charset=UTF-8)z
http-equivÚcontentz<title>%s</title>
N)r4  r<  r>  r  r   r‹   )r5   ry   rz   Zmetaliner6   r6   r7   rÞ   l  s    


z#ODF2XHTML.s_office_document_contentc                 C   s   |   d¡ dS )z
 Last tag r‚  Nrd  rx   r6   r6   r7   rß   w  s    z#ODF2XHTML.e_office_document_contentc                 C   s   dS )rN   Nr6   rx   r6   r6   r7   rà   {  s    z ODF2XHTML.s_office_master_stylesc                 C   s4   t dfdi| jd< t dfdi| jd< |  ||¡ 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
        r   Z24ptrn   r¤   N)r   r0  rv  rx   r6   r6   r7   râ   ~  s    zODF2XHTML.s_office_presentationc                 C   s   |   ¡  |  d¡ d S ©Nrs  ©r  r=  rx   r6   r6   r7   rã   ‡  s    zODF2XHTML.e_office_presentationc                 C   s   |   ||¡ d S ru   )rv  rx   r6   r6   r7   rä   ‹  s    zODF2XHTML.s_office_spreadsheetc                 C   s   |   ¡  |  d¡ d S r„  r…  rx   r6   r6   r7   rå   Ž  s    zODF2XHTML.e_office_spreadsheetc                 C   s
   d| _ d S r2  )r  rx   r6   r6   r7   ræ   ’  s    zODF2XHTML.s_office_stylesc                 C   s"   t dfdi| jd< |  ||¡ dS )z OpenDocument text rU   rV   r   N)r   r0  rv  rx   r6   r6   r7   rç   •  s    zODF2XHTML.s_office_textc                 C   s   |   ¡  |  d¡ d S r„  r…  rx   r6   r6   r7   rè   š  s    zODF2XHTML.e_office_textc                 C   s&   |  ¡ D ]\}}|| j| j |< qdS )zY Copy all attributes to a struct.
            We will later convert them to CSS2
        N)rj   r0  r1  )r5   ry   rz   r;  r   r6   r6   r7   rë   ž  s    z#ODF2XHTML.s_style_handle_propertiesr   rn   r¤   rÅ   rQ  r°   ÚtdÚcolÚtrÚgraphic)
r   rT  r¤   r§   Úsectionr°   r­   r®   r¯   r‰  c                 C   s0   |t df }| j |d¡}|| _i | j| j< dS )z8 A default style is like a style on an HTML tag
        r=   ÚunknownN)r   Ú	familymaprM   r1  r0  )r5   ry   rz   r=   Ú
htmlfamilyr6   r6   r7   ré   «  s    zODF2XHTML.s_style_default_stylec                 C   s
   d | _ d S ru   ©r1  rx   r6   r6   r7   rê   ´  s    zODF2XHTML.e_style_default_stylec                 C   s<   |t df }|tdf }| t dfd¡}| 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
        r<   r   rL   rd   N)r   r   rM   r-  r@   )r5   ry   rz   r<   r=   r>   r6   r6   r7   rì   ·  s    zODF2XHTML.s_style_font_facec                 C   s   |   dddi¡ |  ¡  d S )NrQ  r}  Zfooter©r<  rN  rx   r6   r6   r7   Ús_style_footerÃ  s    zODF2XHTML.s_style_footerc                 C   s   |   ¡  |  d¡ |  ¡  d S ©NrQ  ©r7  r=  rN  rx   r6   r6   r7   Úe_style_footerÇ  s    
zODF2XHTML.e_style_footerc                 C   s$   d| _ | j | j ¡ i | j| j < d S )Nz@print #footer©r1  r/  rk   r0  rx   r6   r6   r7   Ús_style_footer_styleÌ  s    zODF2XHTML.s_style_footer_stylec                 C   s   |   dddi¡ |  ¡  d S )NrQ  r}  Úheaderr  rx   r6   r6   r7   Ús_style_headerÑ  s    zODF2XHTML.s_style_headerc                 C   s   |   ¡  |  d¡ |  ¡  d S r‘  r’  rx   r6   r6   r7   Úe_style_headerÕ  s    
zODF2XHTML.e_style_headerc                 C   s$   d| _ | j | j ¡ i | j| j < d S )Nz@print #headerr”  rx   r6   r6   r7   Ús_style_header_styleÚ  s    zODF2XHTML.s_style_header_stylec                 C   s$   d| _ | j | j ¡ i | j| j < dS )zC Collect the formatting for the default page layout style.
        z@pageNr”  rx   r6   r6   r7   Ús_style_default_page_layoutß  s    z%ODF2XHTML.s_style_default_page_layoutc                 C   s@   |t df }| dd¡}d| | _| 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
        r<   rI  rJ  ú.PL-N)r   rK  r1  r/  rk   r0  )r5   ry   rz   r<   r6   r6   r7   rî   æ  s
    
zODF2XHTML.s_style_page_layoutc                 C   s
   d| _ dS ©z End this style
        NrŽ  rx   r6   r6   r7   rï   ñ  s    zODF2XHTML.e_style_page_layoutc                 C   s´   |t df }| dd¡}d| | _| j | j¡ ddi| j| j< | t dfd¡}|r¤d	| }|| jkr”| j| }| ¡ D ]\}}|| j| j |< qxn|| j| j d
< |  ||¡ dS )z; Collect the formatting for the page layout style.
        r<   rI  rJ  z.MP-)rd   r[   r^   zpage-layout-nameNr›  rx  )	r   rK  r1  r/  rk   r0  rM   rj   rÖ   )r5   ry   rz   r<   Z
pagelayoutr¦   rª   rE   r6   r6   r7   rí   ö  s    


zODF2XHTML.s_style_master_pageZDPÚPZPRÚSÚDÚTZTDZTCZTRÚG)
zdrawing-pagerT  r¤   r§   rŠ  r°   r­   r®   r¯   r‰  c                 C   s  |t df }| dd¡}|t df }| j |d¡}| j |d¡}d| j||f }| t df¡}t |d| ¡| _| j 	| j¡ | j| j
kr–i | j
| j< || j
| j d	< |rd
||f }t |d| ¡}|| j
kr| j
| }| ¡ D ]\}	}
|
| j
| j |	< qæn|| j
| j d< 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.
        r<   rI  rJ  r=   r‹  ÚXz%s%s-%szparent-style-namerw  z%s-%srx  N)r   rK  rŒ  rM   Ú_familyshortr  Úspecial_stylesr1  r/  rk   r0  rj   )r5   ry   rz   r<   r=   r  Zsfamilyrk  r¦   rª   rE   r6   r6   r7   rð     s(    
zODF2XHTML.s_style_stylec                 C   s
   d| _ dS rœ  rŽ  rx   r6   r6   r7   rñ   1  s    zODF2XHTML.e_style_stylec                 C   sR   |  tdfd¡}|r<| jr<| dd¡}|  ddd| i¡ n
|  d¡ |  ¡  dS )z Start a table
        rH  NrI  rJ  r°   r_  zT-%s)rM   r   rÊ   rK  r<  rN  )r5   ry   rz   rƒ   r6   r6   r7   r÷   6  s    

zODF2XHTML.s_table_tablec                 C   s   |   ¡  |  d¡ |  ¡  dS )z End a table
        r°   Nr’  rx   r6   r6   r7   rø   A  s    
zODF2XHTML.e_table_tablec                 C   sv   i }|  tdf¡}|r||d< |  tdf¡}|r8||d< |  tdf¡}|r^d| dd¡ |d	< |  d
|¡ |  ¡  dS )z Start a table cell znumber-rows-spannedÚrowspanznumber-columns-spannedÚcolspanrH  zTD-%srI  rJ  r_  r†  N©rM   r   rK  r<  rN  )r5   ry   rz   rl  r¥  r¦  rƒ   r6   r6   r7   rò   H  s    zODF2XHTML.s_table_table_cellc                 C   s   |   ¡  |  d¡ |  ¡  dS )z End a table cell r†  Nr’  rx   r6   r6   r7   ró   Z  s    
zODF2XHTML.e_table_table_cellc                 C   sf   |  tdfd¡}t|  tdfd¡ƒ}i }|r@d| dd¡ |d< t|ƒD ]}|  d	|¡ qH|  ¡  dS )
z Start a table column rH  Nznumber-columns-repeatedrF   zTC-%srI  rJ  r_  r‡  )rM   r   ÚintrK  r~  r>  rN  )r5   ry   rz   rƒ   Zrepeatedrl  r_   r6   r6   r7   rô   `  s    zODF2XHTML.s_table_table_columnc                 C   sD   |  tdfd¡}i }|r,d| dd¡ |d< |  d|¡ |  ¡  dS )z Start a table row rH  NzTR-%srI  rJ  r_  rˆ  r§  )r5   ry   rz   rƒ   rl  r6   r6   r7   rõ   k  s    zODF2XHTML.s_table_table_rowc                 C   s   |   ¡  |  d¡ |  ¡  dS )z End a table row rˆ  Nr’  rx   r6   r6   r7   rö   u  s    
zODF2XHTML.e_table_table_rowc                 C   s\   |   ¡  |tdf  d¡d }|d dkr@d|  |dd… ¡ }|  dd|i¡ |  ¡  dS )z Anchors start rf  ú|r   ú#rF   Nr±   )r7  r   rR   rM  r<  rN  )r5   ry   rz   rf  r6   r6   r7   rù   {  s    zODF2XHTML.s_text_ac                 C   s    |   ¡  |  dd¡ |  ¡  dS )z% End an anchor or bookmark reference r±   FNr’  rx   r6   r6   r7   rú   „  s    zODF2XHTML.e_text_ac                 C   sF   |t df }|  |¡}|  ¡  |  dd|i¡ |  dd¡ |  ¡  dS )z Bookmark definition r<   rÅ   r}  FN)r   rM  r7  r<  r=  rN  ©r5   ry   rz   r<   Zhtml_idr6   r6   r7   rý   Š  s    
zODF2XHTML.s_text_bookmarkc                 C   s>   |t df }d|  |¡ }|  ¡  |  dd|i¡ |  ¡  dS )z Bookmark reference zref-namerª  r±   rf  N)r   rM  r7  r<  rN  r«  r6   r6   r7   rþ   “  s
    zODF2XHTML.s_text_bookmark_refc                 C   s°   t |tdf ƒ}|dkrd}|dk r(d}| j| d | j|< |  |¡}t|d dƒD ]}d| j|< qTt d| ¡}|s|| jsŒ|  d| ¡ n|  d| dd	| i¡ |  	¡  d
S )z Headings start úoutline-levelé   rF   é
   r   úP-úh%sr_  úP-%sN)
r¨  r   r,  rL  r~  r¤  rM   rÊ   r<  rN  )r5   ry   rz   Úlevelr<   r_   Úspecialr6   r6   r7   rÿ   ›  s      

zODF2XHTML.s_text_hc                 C   s¶   |   ¡  t|tdf ƒ}|dkr$d}|dk r0d}| jd|d … }d tt|ƒ¡}d | j¡}| jdkrn|| _|  	d||f ¡}|  
dd|i¡ |  dd	¡ |  d
| ¡ |  ¡  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.
        r¬  r­  rF   rI  rd   z%s.%sr±   r}  Fr°  N)r7  r¨  r   r,  r5  ÚmapÚstrr%  r‹   rM  r<  r=  rN  )r5   ry   rz   r²  ZlevÚoutlineZheadingÚanchorr6   r6   r7   r   «  s       
 zODF2XHTML.e_text_hc                 C   s   |   ¡  |  d¡ |  ¡  dS )z Force a line break (<br/>) ÚbrN)r7  r>  rN  rx   r6   r6   r7   r  ¾  s    
zODF2XHTML.s_text_line_breakc                 C   s–   |  tdf¡}| j |¡d }|r0| dd¡}n| j tdf¡}d||f }| jrr|  d| j  |d¡ d|i¡ n|  d| j  |d¡ ¡ |  	¡  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.
        rH  rF   rI  rJ  ú%s_%dz%sÚulr_  N)
rM   r   r&  r„   rK  r‚   rÊ   r<  r+  rN  ©r5   ry   rz   r<   r²  Ú
list_classr6   r6   r7   r  Ä  s     zODF2XHTML.s_text_listc                 C   st   |   ¡  | tdf¡}| j |¡d }|r8| dd¡}n| j tdf¡}d||f }|  | j |d¡¡ |  	¡  dS )z End a list rH  rF   rI  rJ  r¹  rº  N)
r7  rM   r   r&  r„   rK  r‚   r=  r+  rN  r»  r6   r6   r7   r  Ù  s    zODF2XHTML.e_text_listc                 C   s   |   d¡ |  ¡  dS )z Start list item r|  Nr  rx   r6   r6   r7   r  é  s    
zODF2XHTML.s_text_list_itemc                 C   s   |   ¡  |  d¡ |  ¡  dS )z End list item r|  Nr’  rx   r6   r6   r7   r  î  s    
zODF2XHTML.e_text_list_itemc                 C   s’   | j  tdf¡}|tdf }| j| _d||f }d| j|< d| dd¡|f | _| 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
        r<   r²  ú%s_%srº  ú.%s_%srI  rJ  )ZsquareZdiscZcircleé   ©rd   zlist-style-typeN)r&  r‚   r   r   r1  Ú	prevstyler+  rK  r/  rk   r0  r¨  )r5   ry   rz   r<   r²  r¼  Úlisttyper6   r6   r7   r  ô  s    
z(ODF2XHTML.s_text_list_level_style_bulletc                 C   s   | j | _| ` d S ru   ©rÁ  r1  rx   r6   r6   r7   r    s    z(ODF2XHTML.e_text_list_level_style_bulletc                 C   sÚ   | j  ¡ tdf }|tdf }| tdfd¡}d||f }| j| _d| dd¡|f | _d| j|< | j	 
| j¡ i | j| j< |dkrŠd	}n<|d
kr˜d}n.|dkr¦d}n |dkr´d}n|dkrÂd}nd	}|| j| j d< d S )Nr<   r²  Ú1r½  r¾  rI  rJ  r{  ZdecimalÚIzupper-romanÚizlower-romanr€  zupper-alphar±   zlower-alpharÀ  )r&  r€   r   r   rM   r1  rÁ  rK  r+  r/  rk   r0  )r5   ry   rz   r<   r²  Z
num_formatr¼  rÂ  r6   r6   r7   r  
  s*    
     z(ODF2XHTML.s_text_list_level_style_numberc                 C   s   | j | _| ` d S ru   rÃ  rx   r6   r6   r7   r	    s    z(ODF2XHTML.e_text_list_level_style_numberc                 C   s2   |   ¡  |  ¡  | jd | _i | j| j< g | _d S )NrF   )r7  rN  r  r  r  rx   r6   r6   r7   r
     s
    zODF2XHTML.s_text_notec                 C   s   d S ru   r6   rx   r6   r6   r7   Úe_text_note'  s    zODF2XHTML.e_text_notec                 C   s   |dkr| j  |¡ d S r2  )r  rk   r3  r6   r6   r7   Úcollectnote*  s    zODF2XHTML.collectnotec                 C   s   | j | _| j| _ d S ru   )r#  Ú	_orgwfuncrÈ  rx   r6   r6   r7   r  .  s    zODF2XHTML.s_text_note_bodyc                 C   s.   | j | _d | j¡| j| j d< d| _| ` d S )Nrd   rs  )rÉ  r#  r5  r  r  r  rx   r6   r6   r7   r  2  s    zODF2XHTML.e_text_note_bodyc                 C   s€   d  | j¡}|| j| j d< |  ddd| j i¡ |  d¡ tjd dkrX|  | j¡ n|  t| jƒ¡ |  	d¡ |  	d¡ d S )	Nrd   Zcitationr±   rf  z#footnote-%sÚsupr   r¿  )
r5  r%  r  r  r<  ÚsysÚversion_infor4  Úunicoder=  )r5   ry   rz   Zmarkr6   r6   r7   r  8  s    

zODF2XHTML.e_text_note_citationc                 C   sl   i }d}|  tdfd¡}|rT| dd¡}t  d| ¡}|dkrTd}| jrTd| |d< |  ||¡ |  ¡  dS )	z Paragraph
        rn   rH  NrI  rJ  r¯  r±  r_  )rM   r   rK  r¤  rÊ   r<  rN  )r5   ry   rz   rl  Ú
specialtagrƒ   r6   r6   r7   r  G  s    zODF2XHTML.s_text_pc                 C   s\   d}|  tdfd¡}|r>| dd¡}t  d| ¡}|dkr>d}|  ¡  |  |¡ |  ¡  dS )z End Paragraph
        rn   rH  NrI  rJ  r¯  )rM   r   rK  r¤  r7  r=  rN  )r5   ry   rz   rÎ  rƒ   r6   r6   r7   r  W  s    
zODF2XHTML.e_text_pc                 C   s0   |  tdfd¡}tt|ƒƒD ]}|  d¡ qd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
        rƒ   rÄ  z&#160;N)rM   r   r~  r¨  r4  )r5   ry   rz   rƒ   r_   r6   r6   r7   r  e  s    zODF2XHTML.s_text_sc                 C   sl   |   ¡  | tdfd¡}i }|rT| dd¡}t d| ¡}|dkrT| jrTd| |d< |  d|¡ |  ¡  dS )	z The <text:span> element matches the <span> element in HTML. It is
            typically used to properties of the text.
        rH  NrI  rJ  zS-zS-%sr_  rÅ   )r7  rM   r   rK  r¤  rÊ   r<  rN  )r5   ry   rz   rƒ   rl  r³  r6   r6   r7   r  m  s    zODF2XHTML.s_text_spanc                 C   s    |   ¡  |  dd¡ |  ¡  dS )z End the <text:span> rÅ   FNr’  rx   r6   r6   r7   r  |  s    zODF2XHTML.e_text_spanc                 C   s   |   ¡  |  d¡ |  ¡  dS )z: Move to the next tabstop. We ignore this in HTML
        rN   N)r7  r4  rN  rx   r6   r6   r7   r  ‚  s    
zODF2XHTML.s_text_tabc                 C   s    |   ¡  |  ¡  |  ||¡ dS ©zB Various indexes and tables of contents. We ignore those.
        N)r7  rN  rÖ   rx   r6   r6   r7   rû   ‰  s    zODF2XHTML.s_text_x_sourcec                 C   s   |   ¡  |  ¡  dS rÏ  )r7  rN  rx   r6   r6   r7   rü     s    zODF2XHTML.e_text_x_sourcec                 C   sb   t |ƒt dƒks8dt|ƒks8dt|ƒks8dt|ƒks8t‚g | _| j| _t|ƒ| _|  | 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
        rd   ÚrbÚBufferedReaderÚBytesION)
rq  ÚreprÚAssertionErrorr!  r"  r#  r   r    rm  rn  )r5   Úodffiler6   r6   r7   r     s
    8
zODF2XHTML.loadc                 C   sŽ   |j tjkrF|  |j|j|j¡ |jD ]}|  |¡ q&|  	|j|j¡ |j tj
ks^|j tjkrŠtjd dkr||  t|ƒ¡ n|  t|ƒ¡ d S )Nr   r¿  )ZnodeTyper   ZELEMENT_NODErC  rB  ZtagNameZ
attributesZ
childNodesrm  rF  Z	TEXT_NODEZCDATA_SECTION_NODErË  rÌ  r?  rµ  rÍ  )r5   Únoderƒ   r6   r6   r7   rm  «  s    
zODF2XHTML._walknodec                 C   sb   t |ƒt dƒks8dt|ƒks8dt|ƒks8dt|ƒks8t‚|  |¡ |  ¡ }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
        rd   rÐ  rÑ  rÒ  )rq  rÓ  rÔ  r   Úxhtml)r5   rÕ  Úresultr6   r6   r7   Ú	odf2xhtml¸  s
    8
zODF2XHTML.odf2xhtmlc                 C   s   |dkr| j  |¡ d S r2  )r!  rk   r3  r6   r6   r7   r"  È  s     zODF2XHTML._wlinesc                 C   s   d  | j¡S )z Returns the xhtml
        rd   )r5  r!  r4   r6   r6   r7   r×  Ë  s    zODF2XHTML.xhtmlc                 C   s   |dkr| j  |¡ d S r2  )Ú	_csslinesrk   r3  r6   r6   r7   Ú	_writecssÐ  s     zODF2XHTML._writecssc                 C   s   d S ru   r6   r3  r6   r6   r7   Ú_writenothingÓ  s    zODF2XHTML._writenothingc                 C   s2   g | _ | j| _|  ¡  d | j ¡}| j| _| ` |S )z Returns the CSS content rd   )rÚ  rÛ  r#  ru  r5  r"  )r5   Úresr6   r6   r7   ÚcssÖ  s    zODF2XHTML.cssc                 C   sH   |dkrt j}n|r|d }t|dƒ}| |  ¡  dd¡¡ | ¡  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)rË  ÚstdoutÚfileÚwriter×  ÚencodeÚclose)r5   Z
outputfileZ	addsuffixZoutputfpr6   r6   r7   Úsaveà  s    
zODF2XHTML.save)TF)N)T)F){rp   rq   rr   rs   r8   r  r  r  r   r  r4  r7  r<  r=  r>  r?  rC  rF  r@  rD  rA  rE  rÖ   rá   rË   rL  rM  rN  rÌ   rÏ   rÍ   rÎ   rÐ   rÑ   rÒ   rÓ   rÕ   rg  rÔ   r×   rØ   rÙ   rÚ   rÛ   rÜ   rv  rz  ru  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  r  r  r  r  rû   rü   r   rm  rÙ  r"  r×  rÛ  rÜ  rÞ  rç  r6   r6   r6   r7   r‰   Y  s  g	
			    ý	    ý 
		
r‰   c                   @   s   e Zd ZdZddd„ZdS )ÚODF2XHTMLembeddedrŠ   TFc              b   C   sì  |   ¡  || _|| _tdf| j| jftdf| jd ftdf| jd ftdf| jd ftdf| j	| j
ftdf| jd ftdf| jd ftdf| j| jftd	f| jd ftd
f| jd ftdf| jd ftdf| jd ftdf| jd ftdf| jd ftdf| jd ftdf| jd ftdf| jd ftdf| jd ftdf| jd ftdf| j| jftdf| jd ftdf| j| jftdf| j| jftdf| j| jftdf| j| j ftdf| jd ftdf| j| j ftdf| j!| j"ftdf| j| j ftdf| j#d ftdf| jd ftd f| j$| j%ftd!f| j&| j'ftd"f| j(| j)ftd#f| j*| j+ftd$fd%td&f| j,d ftd'f| j-| j.ftd(fd | j/ftd)f| jd ftd*f| j| j ftd+f| j0| j1ftd,f| j2d ftd-f| j3| j4ftd.f| j5d ftd/f| j| j ftd0f| j| j ftd1f| j| j ftd2fd%i1| _6d S )3Nr   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Ã   rn   rÄ   rÅ   rÆ   rÇ   rÈ   rÉ   zpage-number)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  )r5   r!  rÊ   r  r6   r6   r7   r8   ò  sÌ     
    
   
            
  
 
 
 
  
 
 
   
 
 
 
   
   
 
  
  
 
 
 ©zODF2XHTMLembedded.__init__N)TF)rp   rq   rr   rs   r8   r6   r6   r6   r7   rè  ï  s   rè  )+rË  Úos.pathÚosÚpathrk   Ú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   rt   r¤  ZContentHandlerr‰   rè  r6   r6   r6   r7   Ú<module>   sF   X jï         