Beispiel #1
0
 def test_split_when_it_cant(self):
     canvas = mock.Mock()
     canvas.stringWidth = lambda s, font, size: len(s) * 7
     chunk = mgp2pdf.TextChunk("this-is-a-very-long, unsplittable, word",
                               "Arial", 6, 0, mgp2pdf.parse_color("black"))
     bits = chunk.split(canvas, 1024, 768, 130)
     self.assertEqual(len(bits), 2)
     self.assertEqual(bits[0].text, "this-is-a-very-long,")
     self.assertEqual(bits[1].text, "unsplittable, word")
Beispiel #2
0
 def test_size_line_with_images_only(self, mock_ImageReader):
     mock_ImageReader().getSize.return_value = 100, 50
     line = mgp2pdf.Line()
     line.add(mgp2pdf.Image('cat.png'))
     line.add(mgp2pdf.TextChunk('', 'Helvetica', 10, 0,
                                mgp2pdf.parse_color('black')))
     canvas = mock.Mock()
     canvas.stringWidth = lambda s, font, size: len(s) * 7
     w, h = line.size(canvas, 1024, 768)
     # TBH I'm not 100% sure this is correct, but at some point I
     # thought so.  I ought to find which of the documents under
     # samples/ triggered this special case.
     self.assertEqual((w, h), (100, 51))