def write_presentation_plugin(frame, indoc, outdoc, encoding): plugin = frame.get_element('draw:plugin') src = plugin.get_attribute('xlink:href') if not isabs(src): f = open(make_image_path(outdoc, src), 'wb') f.write(indoc.get_part(src)) f.close() width, height = frame.get_size() width = Unit(width).convert('px') height = Unit(height).convert('px') text = plugin.get_text_content() # XXX get_svg_title? mimetype = plugin.get_attribute('draw:mime-type') outdoc.write( '''<div class="plugin"> <object data="%(src)s" type="%(mimetype)s" width="%(width)s" height="%(height)s"> <param name="src" value="%(src)s"/> <param name="autoplay" value="false"/> <param name="autoStart" value="0"/> %(text)s </object> </div>\n''' % { 'src': src, 'mimetype': mimetype, 'width': width, 'height': height, 'text': text })
def cmp_frames(a, b): # XXX obsolete if "get_position" returns Unit ax, ay = a.get_position() ax = Unit(ax) ay = Unit(ay) bx, by = b.get_position() bx = Unit(bx) by = Unit(by) # Top-bottom then left-right return cmp((ay, ax), (by, bx))
def write_presentation_table(frame, outdoc, encoding): width, height = frame.get_size() width = Unit(width).convert('px') height = Unit(height).convert('px') outdoc.write('<table width="%(width)s" height="%(height)s">') table = frame.get_table() for y, row in table.get_rows(): outdoc.write(' <tr>') for x, cell in row.get_cells(): text = get_string(cell.get_text_content(), encoding) outdoc.write(' <td>%s</td>\n' % text) outdoc.write(' </tr>\n') outdoc.write('</table>\n')
def test_encode(self): value = '1.847mm' unit = Unit(value) self.assertEqual(str(unit), value)
def test_convert(self): unit = Unit('10cm') self.assertEqual(unit.convert('px'), Unit('283px'))
def test_int(self): unit = Unit(1) self.assertEqual(unit.value, Decimal('1')) self.assertEqual(unit.unit, 'cm')
def test_float(self): unit = Unit(3.14) self.assertEqual(unit.value, Decimal('3.14')) self.assertEqual(unit.unit, 'cm')
def test_str(self): unit = Unit('1.847mm') self.assertEqual(unit.value, Decimal('1.847')) self.assertEqual(unit.unit, 'mm')
def test_ge(self): unit1 = Unit('2.54cm') unit2 = Unit('2.54cm') self.assertTrue(unit1 >= unit2)
def test_ngt(self): unit1 = Unit('2.54cm') unit2 = Unit('2.53cm') self.assertFalse(unit1 < unit2)
def test_gt(self): unit1 = Unit('2.54cm') unit2 = Unit('2.53cm') self.assertTrue(unit1 > unit2)