Ejemplo n.º 1
0
    def build_svg_line(self, line_fragment, fill):
        _lines = render_text.Render.split_text_to_lines(
            line_fragment, self.act_line_width)
        _line, _w, _h = _lines[0]

        if self.svg_text is None:
            self.svg_text = Text(text="")

        if len(_lines) == 1 and self.act_line_width < self.max_line_width:
            self.svg_text.add(TSpan(text=_line, fill=fill))
            self.act_line_width += _w
            self.width_max = max(self.act_line_width, self.width_max)

        elif len(_lines) == 1 and self.act_line_width >= self.max_line_width:
            self.svg_text.add(TSpan(text=_line, fill=fill))
            self.svg_text["x"] = 0
            self.svg_text["y"] = self.height
            self.svg.add(self.svg_text)
            self.height += _h
            self.act_line_width = 0
            self.svg_text = None

        elif len(_lines) > 1:

            for _line, _w, _h in _lines:

                if self.svg_text is None:
                    self.svg_text = Text(text="")

                if _line == "%NewLine%":
                    self.svg_text["x"] = 0
                    self.svg_text["y"] = self.height
                    self.svg.add(self.svg_text)
                    self.height += _h
                    self.act_line_width = 0
                    self.svg_text = None

                elif self.act_line_width < self.max_line_width:
                    self.svg_text.add(TSpan(text=_line, fill=fill))
                    self.act_line_width += _w
                    self.width_max = max(self.act_line_width, self.width_max)

                else:

                    self.svg_text["x"] = 0
                    self.svg_text["y"] = self.height
                    self.svg.add(self.svg_text)
                    self.height += _h
                    self.act_line_width = _w
                    self.width_max = max(self.act_line_width, self.width_max)
                    self.svg_text = None
Ejemplo n.º 2
0
 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>'
     )
Ejemplo n.º 3
0
 def test_subelement(self):
     txt = TSpan('testtext')
     txt.add(TSpan('subtext1'))
     txt.add(TSpan('subtext2'))
     self.assertEqual(
         txt.tostring(),
         '<tspan>testtext<tspan>subtext1</tspan><tspan>subtext2</tspan></tspan>'
     )
Ejemplo n.º 4
0
    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')
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
 def test_non_us_ascii_chars(self):
     txt = TSpan('öäü')
     self.assertEqual(txt.tostring(), to_unicode('<tspan>öäü</tspan>'))
Ejemplo n.º 7
0
 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>')
Ejemplo n.º 8
0
 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>')
Ejemplo n.º 9
0
 def test_insert(self):
     txt = TSpan('testtext', insert=(1, 1))
     self.assertEqual(txt.tostring(), '<tspan x="1" y="1">testtext</tspan>')
Ejemplo n.º 10
0
 def test_constructor(self):
     txt = TSpan('testtext')
     self.assertEqual(txt.tostring(), '<tspan>testtext</tspan>')
Ejemplo n.º 11
0
 def test_non_us_ascii_chars(self):
     txt = TSpan('öäü')
     self.assertEqual(txt.tostring(), to_unicode('<tspan>öäü</tspan>'))
Ejemplo n.º 12
0
 def test_subelement_tspan(self):
     txt = TSpan('text')
     txt.add(TSpan('subtext'))
     self.assertEqual(txt.tostring(), '<tspan>text<tspan>subtext</tspan></tspan>')
Ejemplo n.º 13
0
 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>')
Ejemplo n.º 14
0
 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>')
Ejemplo n.º 15
0
 def test_insert(self):
     txt = TSpan('testtext', insert=(1,1))
     self.assertEqual(txt.tostring(), '<tspan x="1" y="1">testtext</tspan>')
Ejemplo n.º 16
0
 def test_constructor(self):
     txt = TSpan('testtext')
     self.assertEqual(txt.tostring(), '<tspan>testtext</tspan>')