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

Screenshot (Link to open SVG for interactive features):

../_images/example13.png

Source Code (Link to Github):


import os
import sys
import argparse

from visigoth import Diagram

from visigoth.common.text import Text, Span
from visigoth.containers.box import Box

if __name__ == "__main__":

    parser = argparse.ArgumentParser()
    parser.add_argument("--outpath", help="path for output SVG", default="example.svg")
    args = parser.parse_args()

    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("Difffferent",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)))

    svg = d.draw()

    f = open(args.outpath, "wb")
    f.write(svg)
    f.close()