rst2odt and large table/images

POIRET via Docutils-users <[email protected]> Wed, 24 Apr 2019 16:24:23 +0200
Newsgroups gmane.text.docutils.user
Message-ID <[email protected]>
Hello, 

I'm still trying to produce automatically odt documents from
rst file. I have currently two problems, when using docutils0.14 /
rst2odt tool. 

With large table and images, those objects exceed table
boundaries, and so the produced document can't be used as is. 

I'm
sharing below my wonderings/changes to fix that. Any comment are
welcome. 

Regards, 

-- 

Gilles Poiret 

TABLE: 

          analysis:
in the visit_table function, the lines "style:width" are commented. 

  
      workaround Uncomment them solve my issue, even if using the
self.get_page_width() to compute the value should be better..I guess you
have chosen to comment them. Could you explain why please? 

         
drawback : the small tables become bigger, but at least the document is
consistent. 

IMAGE: 

analysis & workaround : nothing seems planed to
avoid this behavior. I added the following in the
get_image_scaled_width_height function. Not perfect, especially if the
image is not put at the beginning of a line, but it's better than the
current situation, at least for me. 

-- at the beginning of the
function 

       line_width = self.get_page_width() # GP - the call of
this code can be removed below, in the "if width_unit == '%' test" 

--
at the end of the function 

        width *= scale
        height *=
scale

        if width > line_width:      # GP - resize the image to
fit the page size if bigger
            ratio_vs_pagesize = line_width /
width
            width = line_width
            height *=
ratio_vs_pagesize

        width = '%.2fcm' % width
        height =
'%.2fcm' % height
        return width, height 

Environment : Debian 10
"testing" / package python3-docutils 0.14+dfsg-4