Text

class visigoth.common.text.Text(text_or_list='', max_width=None, font_height=24, text_attributes={}, url=None, line_spacing=None)

Create a text string

Arguments:

Keyword Arguments:
 
  • text_or_list (str) – str or list of Span or str
  • max_width (int) – maximum width for text, wrap to multiple lines
  • font_height (int) – font size in pixels
  • text_attributes (dict) – a dict containing SVG name/value attributes
  • url (str) – url to link to from the text
  • line_spacing (int) – spacing between line in pixels

Example

(Link to open example in new tab):

Source Code (Link to Github):

# -*- coding: utf-8 -*-

from visigoth import Diagram
from visigoth.common import Text, Span
from visigoth.containers import Box

d = Diagram(fill="white",title="visigoth Text example",description="some description")
d.setFontEmbedding(True)

d.add(Box(Text("Some Small Text",font_height=10)))
d.add(Box(Text("Link to repo",url="https://github.com/visigoths/visigoth")))
d.add(Box(Text("Some Fancy Text",font_height=32,text_attributes={"stroke":"darkblue", "fill":"red"})))
d.add(Box(Text("Some Big Text",font_height=48)))
d.add(Box(Text("Different",text_attributes={"font-family":"Raleway"})))
d.add(Box(Text(
    [Span("Text can be combined with"),
     Span(" a url",url="https://github.com/visigoths/visigoth"),
     Span(" different styles",text_attributes={"font-style":"normal"}),
     Span(" different fonts", text_attributes={"font-family":"Roboto"}),
     Span(" different sizes ",font_height=32),
     Span(" and different colours!", text_attributes={"stroke":"red"})],max_width=400,font_height=24)))

html = d.draw(format="html")

f = open("example.html", "w")
f.write(html)
f.close()