tests/test_platypus_paragraphs.py
changeset 4389 61a7f0840d00
parent 4387 c9accf85d669
child 4396 7a77896c72f0
equal deleted inserted replaced
4388:9f93d62b9f6e 4389:61a7f0840d00
   118         sty.fontName = 'Courier'
   118         sty.fontName = 'Courier'
   119         sty.alignment = TA_LEFT
   119         sty.alignment = TA_LEFT
   120         sty.wordWrap = 'CJK'
   120         sty.wordWrap = 'CJK'
   121         p0=Paragraph('ABCDEFGHIJKL]N',sty)
   121         p0=Paragraph('ABCDEFGHIJKL]N',sty)
   122         p1=Paragraph('AB<font color="red">C</font>DEFGHIJKL]N',sty)
   122         p1=Paragraph('AB<font color="red">C</font>DEFGHIJKL]N',sty)
   123         canv = Canvas('test_platypus_paragraph_cjk3.pdf')
   123         canv = Canvas(outputfile('test_platypus_paragraph_cjk3.pdf'))
   124         ix = len(canv._code)
   124         ix = len(canv._code)
   125         aW = pdfmetrics.stringWidth('ABCD','Courier',15)
   125         aW = pdfmetrics.stringWidth('ABCD','Courier',15)
   126         w,h=p0.wrap(aW,1000000)
   126         w,h=p0.wrap(aW,1000000)
   127         y = canv._pagesize[1]-72-h
   127         y = canv._pagesize[1]-72-h
   128         p0.drawOn(canv,72,y)
   128         p0.drawOn(canv,72,y)
   197 it's actually easy to do using platypus.We can do greek letters <greek>mDngG</greek>. This should be a
   197 it's actually easy to do using platypus.We can do greek letters <greek>mDngG</greek>. This should be a
   198 u with a dieresis on top &lt;unichar code=0xfc/&gt;="<unichar code="0xfc"/>" and this &amp;#xfc;="&#xfc;" and this \\xc3\\xbc="\xc3\xbc". On the other hand this
   198 u with a dieresis on top &lt;unichar code=0xfc/&gt;="<unichar code="0xfc"/>" and this &amp;#xfc;="&#xfc;" and this \\xc3\\xbc="\xc3\xbc". On the other hand this
   199 should be a pound sign &amp;pound;="&pound;" and this an alpha &amp;alpha;="&alpha;". You can have links in the page <link href="http://www.reportlab.com" color="blue">ReportLab</link> &amp; <a href="http://www.reportlab.org" color="green">ReportLab.org</a>.
   199 should be a pound sign &amp;pound;="&pound;" and this an alpha &amp;alpha;="&alpha;". You can have links in the page <link href="http://www.reportlab.com" color="blue">ReportLab</link> &amp; <a href="http://www.reportlab.org" color="green">ReportLab.org</a>.
   200 Use scheme "pdf:" to indicate an external PDF link, "http:", "https:" to indicate an external link eg something to open in
   200 Use scheme "pdf:" to indicate an external PDF link, "http:", "https:" to indicate an external link eg something to open in
   201 your browser. If an internal link begins with something that looks like a scheme, precede with "document:". Empty hrefs should be allowed ie <a href="">&lt;a href=""&gt;test&lt;/a&gt;</a> should be allowed.
   201 your browser. If an internal link begins with something that looks like a scheme, precede with "document:". Empty hrefs should be allowed ie <a href="">&lt;a href=""&gt;test&lt;/a&gt;</a> should be allowed.
   202 <u>This text should be underlined.</u>
   202 <u>This text should be underlined.</u><br/>
   203 <strike>This text should have a strike through it.</strike>
   203 <strike>This text should have a strike through it.</strike><br/>
   204 <span backcolor="yellow"><strike>This text should have a strike through it and be highlighted.</strike></span>
   204 <span backcolor="yellow"><strike>This text should have a strike through it and be highlighted.</strike></span><br/>
   205 <span backcolor="yellow"><strike><u>This text should have a strike through it and be highlighted and underlined.</u></strike></span>
   205 <span backcolor="yellow"><strike><u>This text should have a strike through it and be highlighted and underlined.</u></strike></span><br/>
   206 This should be a mailto link <a href="mailto:reportlab-users@lists2.reportlab.com"><font color="blue">reportlab-users at lists2.reportlab.com</font></a>.
   206 This should be a mailto link <a href="mailto:reportlab-users@lists2.reportlab.com"><font color="blue">reportlab-users at lists2.reportlab.com</font></a>.<br/>
   207 This should be an underlined mailto link <a href="mailto:reportlab-users@lists2.reportlab.com"><font color="blue">reportlab-users at lists2.reportlab.com</font></a>.
   207 This should be an underlined mailto link <a underline="1" href="mailto:reportlab-users@lists2.reportlab.com"><font color="blue">reportlab-users at lists2.reportlab.com</font></a>.<br/>
   208 This should be a highlighted mailto link <span backcolor="yellow"><a href="mailto:reportlab-users@lists2.reportlab.com"><font color="blue">reportlab-users at lists2.reportlab.com</font></a></span>.
   208 This should be a highlighted mailto link <span backcolor="yellow"><a href="mailto:reportlab-users@lists2.reportlab.com"><font color="blue">reportlab-users at lists2.reportlab.com</font></a></span>.<br/>
   209 This should be a highlighted &amp; undelined mailto link <span backcolor="yellow"><a href="mailto:reportlab-users@lists2.reportlab.com"><u><font color="blue">reportlab-users at lists2.reportlab.com</font></u></a></span>.
   209 This should be a highlighted &amp; underlined mailto link <span backcolor="yellow"><a underline="1" ucolor="red" uwidth="0.01*F" href="mailto:reportlab-users@lists2.reportlab.com"><font color="blue">reportlab-users at lists2.reportlab.com</font></a></span>.<br/>
       
   210 <u offset="-.125*F">Underlined <font size="-1">Underlined</font></u><br/>
       
   211 This is A<sup><u>underlined</u></sup> as is A<u><sup>this</sup></u>
       
   212 <u color="red">This is A<sup><u>underlined</u></sup> as is A<u><sup>this</sup></u></u>
   210 '''
   213 '''
   211         from reportlab.platypus.flowables import ImageAndFlowables, Image
   214         from reportlab.platypus.flowables import ImageAndFlowables, Image
   212         from reportlab.lib.testutils import testsFolder
   215         from reportlab.lib.testutils import testsFolder
   213         gif = os.path.join(testsFolder,'pythonpowered.gif')
   216         gif = os.path.join(testsFolder,'pythonpowered.gif')
   214         heading = Paragraph('This is a heading',h3)
   217         heading = Paragraph('This is a heading',h3)
   457                             autoLeading,
   460                             autoLeading,
   458                             (s==normal_indent_lv_2 and '<seq id="document" inc="no"/>.<seq id="document_lv_2"/>' or ''),
   461                             (s==normal_indent_lv_2 and '<seq id="document" inc="no"/>.<seq id="document_lv_2"/>' or ''),
   459                             t,' '.join((n+1)*['A']),t,text0,t,' '.join((n+1)*['A']),t,text1),
   462                             t,' '.join((n+1)*['A']),t,text0,t,' '.join((n+1)*['A']),t,text1),
   460                             style=s))
   463                             style=s))
   461         a(Paragraph("The jump at the beginning should come here &lt;a name=\"theEnd\"/&gt;<a name=\"theEnd\"/>!",style=normal))
   464         a(Paragraph("The jump at the beginning should come here &lt;a name=\"theEnd\"/&gt;<a name=\"theEnd\"/>!",style=normal))
       
   465         a(Paragraph('Underlining <span fontSize="11"><u color="red">A<u color="green">B</u><u color="blue">C</u>D<sup><strike width="0.5" color="magenta">2</strike><sup><u color="darkgreen" width="0.2">3</u></sup></sup></u></span>',normal))
       
   466         a(Paragraph('<para autoLeading="max" spaceAfter="10">this is in 12 <font size=30>this is in 30</font> <u offset="-0.5" width="0.5" color="red"><u offset="-1.5" width="0.5" color="blue">and</u></u> <link underline="1" ucolor="blue" href="http://google.com/">the link box<sup><a color="red" ucolor="green" underline="1" href="https://www.reportlab.com">2</a></sup> is right (twice).</link></para>''',normal))
       
   467         a(Paragraph('<para autoLeading="max" spaceAfter="10">this is in 12 <font size=30>this is in 30</font> and <link underline="1" ucolor="blue" href="http://google.com/">the link box is right.</link></para>''',normal))
       
   468         a(Paragraph('Underlining <u><span color="red">underlined in red? <span color="blue"><u>or blue</u></span> or red again?</span></u>',normal))
       
   469         a(Paragraph('Link <a href="#theEnd" color="blue">jump</a> to end.<br/>Underlined link <a href="#theEnd" underline="1" ucolor="red" color="blue">jump</a> to end!',style=normal))
       
   470         a(Paragraph('<para autoleading=""><u>A</u>. Furthermore, a subset of <font size="14">English sentences</font> interesting on quite\nindependent grounds is not quite equivalent to a stipulation to place\nthe constructions into these various categories. <u>A</u>. We will bring evidence in favor of\nThe following thesis: most of the methodological work in modern\nlinguistics can be defined in such a way as to impose problems of\nphonemic and morphological analysis.</para>',normal))
       
   471         a(Paragraph('<para autoleading=""><u>A</u>. Furthermore, a subset of <font size="14">English sentences</font> interesting on quite<br/><u>A</u>.</para>',normal))
       
   472         a(Paragraph(u"<para>This is a <sup rise=5><span color='red'>sup</span></sup>rise=5.</para>",normal))
       
   473         a(Paragraph('<span fontSize="11"><u color="green"><strike color="blue">AAAAAA</strike></u></span>',normal))
       
   474         a(Paragraph("Underlining &amp; width proportional to first use font size ('f' suffix) <u offset='-0.125*f' width='0.05*f'>underlined <span size=14>underlined</span></u>!",style=normal))
       
   475         a(Paragraph("Underlining &amp; width proportional to first use font size ('F' suffix) <u offset='-0.125*F' width='0.05*F'>underlined <span size=14>underlined</span></u>!",style=normal))
       
   476         a(Paragraph('''<para spaceBefore="10">This is underlined &lt;sup&gt;: a<sup><u><span color="red">sup</span></u></sup></para>''',style=normal))
       
   477         a(Paragraph('''<para spaceBefore="10">This is <u>underlined</u></para>''',style=normal))
       
   478         a(Paragraph('''<para spaceBefore="10">This is <u kind="double">underlined double</u></para>''',style=normal))
       
   479         a(Paragraph('''<para spaceBefore="10">This is <strike>striken</strike></para>''',style=normal))
       
   480         a(Paragraph('''<para spaceBefore="10">This is <strike><u>both</u></strike></para>''',style=normal))
       
   481         a(Paragraph('''<para spaceBefore="10">This is <u width="0.5" offset="-1" kind="double">underlined kind="double"</u></para>''',style=normal))
       
   482         a(Paragraph('''<para spaceBefore="10">This is <u width="0.25" offset="-1" kind="double">double underlined with thinner lines</u></para>''',style=normal))
       
   483         a(Paragraph('''<para spaceBefore="10">This is <u width="0.5" offset="-0.5" color="red">underlined in red</u></para>''',style=normal))
       
   484         a(Paragraph('''<para spaceBefore="10">This is <strike width="0.5" color="red">overstruck in red</strike></para>''',style=normal))
       
   485         a(Paragraph('''<para spaceBefore="10">This is <strike width="0.5" color="red" kind="double">doubly overstruck in red</strike></para>''',style=normal))
       
   486         a(Paragraph('''<para spaceBefore="10">This is <strike width="0.5" offset="0.125*F" color="red" kind="triple" gap="0.5">triply overstruck in red</strike></para>''',style=normal))
       
   487         a(Paragraph('''<para autoLeading="max" spaceAfter="10" spaceBefore="30">this is in 12 <font size="30">this is in 30</font> <u offset="-0.5" width="0.5" color="red"><u offset="-1.5" width="0.5" color="blue">and</u></u> <link underline="1" ucolor="blue" href="http://google.com/">the link box<sup><a color="red" ucolor="green" underline="1" href="https://www.reportlab.com">2</a></sup> is right (twice).</link></para>''',style=normal))
       
   488         a(Paragraph("",style=normal))
   462         doc = MyDocTemplate(outputfile('test_platypus_paragraphs_ul.pdf'))
   489         doc = MyDocTemplate(outputfile('test_platypus_paragraphs_ul.pdf'))
   463         doc.build(story)
   490         doc.build(story)
   464 
   491 
   465 class AutoLeadingTestCase(unittest.TestCase):
   492 class AutoLeadingTestCase(unittest.TestCase):
   466     "Test underlining and overstriking of paragraphs."
   493     "Test underlining and overstriking of paragraphs."