I created a simple proof of concept – and it worked!
from svg.path import parse_path #pip3 install svg.path
from svg.path.path import Line
from xml.dom import minidom
from bokeh.models import ColumnDataSource, Plot
from bokeh.models.glyphs import Bezier
from bokeh.io import show
import pandas as pd
# read the SVG file
doc = minidom.parse('./Apple_logo_black.svg')
path_strings = [path.getAttribute('d') for path
in doc.getElementsByTagName('path')]
doc.unlink()
#parse path and load into ColumnDataSource
l=[]
path=parse_path(path_strings[0])#example is only of len == 1
for p in path:
try: #y coords need to be negative for some reason
x0 = p.start.real
y0 = -1 * p.start.imag
x1 = p.end.real
y1 = -1 * p.end.imag
cx0 = p.control1.real
cy0 = -1 * p.control1.imag
cx1 = p.control2.real
cy1 = -1 * p.control2.imag
l.append((x0,y0,x1,y1,cx0,cy0,cx1,cy1))
except AttributeError: #this excepts the "move to" object
pass
l=pd.DataFrame(l,columns=["x0","y0","x1","y1","cx0","cy0","cx1","cy1"])
l=ColumnDataSource(l)
#plot
plot = Plot(
title=None, plot_width=400, plot_height=400,
min_border=0, toolbar_location=None)
glyph = Bezier(x0="x0", y0="y0", x1="x1", y1="y1", cx0="cx0", cy0="cy0", cx1="cx1", cy1="cy1", line_color="#000000", line_width=2)
plot.add_glyph(l,glyph)
show(plot)
file: File:Apple logo black.svg - Wikimedia Commons
Im not certain why they y coords need to be flipped, but this is certainly a promising start. I’ll open a GitHub issue for filled beziers (or bezier patches?), though Im not certain how much I’ll be able to contribute as I am a mid-level python programmer.