def test_subelement_tspan(self): txt = TextPath('#test', 'text') txt.add(TSpan('subtext')) self.assertEqual( txt.tostring(), '<textPath xlink:href="#test">text<tspan>subtext</tspan></textPath>' )
def test_text_decoration(self): with self.assertRaises(TypeError): TSpan('text', text_decoration='xxx') self.assertTrue(TSpan('text', text_decoration='none')) self.assertTrue(TSpan('text', text_decoration='inherit')) self.assertTrue(TSpan('text', text_decoration='underline')) self.assertTrue(TSpan('text', text_decoration='overline')) self.assertTrue(TSpan('text', text_decoration='line-through')) self.assertTrue(TSpan('text', text_decoration='blink')) # multiple decoration are allowed self.assertTrue( TSpan('text', text_decoration='underline blink overline')) with self.assertRaises( TypeError): # can not mix none with decoration styles TSpan('text', text_decoration='none underline') with self.assertRaises( TypeError): # can not mix inherit with decoration styles TSpan('text', text_decoration='inherit underline')
def add_text_box(self, dx_nodes): ''' Simple text box with fixed width. :param dx_nodes: XTypes.DiffxElement ''' _text = self.get_element_text(dx_nodes.node) _lines = self._lines_callback(_text) _y = copy.deepcopy(self.pos_y) _svg = SVG(insert=(self.pos_x, self.pos_y)) _t = Text('', insert=(0, 0), font_size=self.font_size, font_family=self.font_family) _h = 0 _w = 0 for _line, _width, _height in _lines: _h = _h + float(_height) _w = max(_w, float(_width)) _text = TSpan(_line, fill="black", insert=(0, _h)) _t.add(_text) self.pos_y = self.pos_y + _h self.pos_y_max = max(self.pos_y_max, self.pos_y) self.pos_x_max = max(self.pos_x_max, _w + self.pos_x) _svg['height'] = _h _svg['width'] = _w _svg.viewbox(0, 0, _w, _h) _svg.add(_t) return _svg
def test_non_us_ascii_chars(self): txt = TSpan('öäü') self.assertEqual(txt.tostring(), to_unicode('<tspan>öäü</tspan>'))
def test_subelement_tspan(self): txt = TSpan('text') txt.add(TSpan('subtext')) self.assertEqual(txt.tostring(), '<tspan>text<tspan>subtext</tspan></tspan>')
def test_rotate_values(self): txt = TSpan('text', rotate=[1, 2, 3, 4]) self.assertEqual(txt.tostring(), '<tspan rotate="1 2 3 4">text</tspan>')
def test_dy_values(self): txt = TSpan('text', dy=[1, 2, 3, 4]) self.assertEqual(txt.tostring(), '<tspan dy="1 2 3 4">text</tspan>')
def test_insert(self): txt = TSpan('testtext', insert=(1, 1)) self.assertEqual(txt.tostring(), '<tspan x="1" y="1">testtext</tspan>')
def test_constructor(self): txt = TSpan('testtext') self.assertEqual(txt.tostring(), '<tspan>testtext</tspan>')