def add_line(self, instance_xtype): ''' Draw svg line representing DiffxElement. :param instance_xtype: XTypes.DiffxElement ''' _text = instance_xtype.name() _w, _h = render_text.Render.get_text_size(_text) _h += _h * 0.25 _svg = SVG(insert=(self.pos_x, self.pos_y), width=_w, height=_h) _text_svg = Text(_text) _text_svg['x'] = 0 _text_svg['y'] = _h - _h * 0.25 _text_svg['font-size'] = self.font_size _text_svg['font-family'] = self.font_family _text_svg['opacity'] = 1.0 _text_svg['fill'] = rgb(0, 0, 0) _rect_svg = Rect() _rect_svg['x'] = 0 _rect_svg['y'] = 0 _rect_svg['fill'] = instance_xtype.fill _rect_svg['opacity'] = instance_xtype.opacity _rect_svg['height'] = _h _rect_svg['width'] = _w _svg.add(_text_svg) _svg.add(_rect_svg) _svg.viewbox(0, 0, _w, _h) self.pos_y = self.pos_y + _h self.pos_x_max = max(self.pos_x_max, _w + self.pos_x) self.pos_y_max = max(self.pos_y_max, self.pos_y) return _svg
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