svg.text
result = svg.text(x, y, text, [font_size=16], [font_family="sans-serif"], [fill="#000000"], [stroke="none"], [stroke_width=1], [opacity=1])
Input: x, y, text, font_size, font_family, fill, stroke, stroke_width, opacity · Output: result
What it is
A text run anchored at (x, y) — which in SVG is the *baseline start*, not the top-left corner. font_size must be more than 0. The content is XML-escaped on write, so & and < in a label are safe.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = svg.text(x, y, text, [font_size=16], [font_family="sans-serif"], [fill="#000000"], [stroke="none"], [stroke_width=1], [opacity=1]) | x —A text run anchored at (x, y) — which in SVG is the *baseline start*, not the top-left corner.y —A text run anchored at (x, y) — which in SVG is the *baseline start*, not the top-left corner.text —A text run anchored at (x, y) — which in SVG is the *baseline start*, not the top-left corner.font_size optional (default 16)font_size must be more than 0.font_family Record, optional (default "sans-serif")Returns a Record with fields kind, x, y, text, font_size, font_family and the four styling fields.fill optional (default "#000000")not documented yetstroke optional (default "none")not documented yetstroke_width optional (default 1)not documented yetopacity optional (default 1)not documented yet | result Record | Returns a Record with fields kind, x, y, text, font_size, font_family and the four styling fields. Added in v0.3.0. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
import svg
shapes = [
svg.rect(10, 10, 100, 50, fill = "#e74c3c"),
svg.circle(200, 60, 40, fill = "#3498db", stroke = "#000000", stroke_width = 2),
svg.line(0, 0, 300, 120, stroke = "#333333", stroke_width = 1.5),
svg.path("M 10 100 L 60 40 L 110 100 Z", stroke = "#2ecc71", stroke_width = 2),
svg.text(20, 150, "R&D output", font_size = 16, fill = "#111111")]
save_svg("drawing.svg", shapes, width = 320, height = 180)
doc = load_svg("drawing.svg")
print(doc.width) # 320
print(len(doc.shapes)) # 5
print(doc.shapes[1].kind) # circle
print(doc.shapes[1].r) # 40
output
320 5 circle 40
from images