小编Pet*_*ano的帖子

Python Svgwrite和字体样式/大小

我正在尝试将SVG文件连接到Web scraper.

如何使用svgwrite更改字体和文本大小?我知道我必须定义一个CSS样式,并以某种方式将其连接到文本对象.但是这是怎么做的?

这是我到目前为止的代码

import svgwrite

svg_document = svgwrite.Drawing(filename = "test-svgwrite3.svg",
                            size = ("1200px", "800px"))
#This is the line I'm stuck at
#svg_document.add(svg_document.style('style="font-family: Arial; font-size  : 34;'))

svg_document.add(svg_document.rect(insert = (900, 800),
                                   size = ("200px", "100px"),
                                   stroke_width = "1",
                                   stroke = "black",
                                   fill = "rgb(255,255,0)"))

svg_document.add(svg_document.text("Reported Crimes in Sweden",
                                   insert = (410, 50),
                                   fill = "rgb(255,255,0)",

                                  #This is the connection to the first line that I'm stuck at
                                  #style = 'style="font-family: Arial; font-size  : 104;'))

print(svg_document.tostring())

svg_document.save()
Run Code Online (Sandbox Code Playgroud)

css python svg svgwrite

5
推荐指数
2
解决办法
6798
查看次数

标签 统计

css ×1

python ×1

svg ×1

svgwrite ×1