New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: add support for ID and Class attributes to BezierPath #356
Comments
This is indeed very handy... but Im not sure about the syntax: the init of a bezierPath would be heavily populated with svg specific arguments. I would prefer a solution where additional data is provided in size(800, 800)
B1 = BezierPath()
B1.rect(100, 100, 400, 400)
fill(0, 0, 1)
drawPath(B1)
B2 = BezierPath()
B2.oval(300, 300, 400, 400)
fill(1, 0, 0)
stroke(0, 1, 0)
strokeWidth(20)
drawPath(B2)
saveImage('output.svg',
svgIDMap={
B1: "square",
B2: "circle"},
svgClassMap={
B1:["shape"],
B2:["foo", "shape"]}
) as such other objects like, FormattedString could also get an svg |
I don't think it's all bad to add things to the BezierPath object, but maybe indeed not in the constructor. How about separate methods or attributes? b = BezierPath()
b.cssClass = "shape"
b.cssID = "circle" (Could also work for FormattedString, in fact, neither BezierPath nor FormattedString need to be changed for this, only the SVG writer.) |
custom attributes are fine, they are harder to document
|
@justvanrossum I like the cleaner syntax, thanks. wouldn’t it make more sense to prefix with b = BezierPath()
b.svgID = "circle"
b.svgClass = "shape foo"
b.svgCursor = "move" # sneaked another one here ;) (here’s a list of all SVG path attributes) hyperlinks would be really useful too (thinking about the FontParts map, for example). a link is not an attribute of <a xlink:href="https://drawbot.com/">
<path id='square' class='shape' d="M100,100 l400,0 l0,400 l-400,0 Z M100,100" fill="rgb(0,0,255)" transform="matrix(1,0,0,-1,0,800)"/>
</a> edit: possible syntax for links: B.svgLink = 'http://www.drawbot.com/'
# + a better syntax for PDF links?
B1.pdfLinkDestination = 'example'
B2.pdfLink = 'example' |
Yes, you're right. |
I know properties can have docs but if we only change the svgContext those properties does not exists... |
pdf links are already supported in with
|
If we only change svgContext then there is no documentation for those attrs. If we want documentation of those attrs, we need to add them as properties. What is the problem? |
I dont like to add context specific attributes in main classes this could work in the svgContext.py from drawBot.context.baseContext import BezierPath
def _get_svgID(self):
return getattr(self, "_svgID", None)
def _set_svgID(self, value):
self._svgID = value
BezierPath.svgID = property(_get_svgID, _set_svgID, doc="svg ID") wonder if this ends up in the docs and so can every context add his own attributes for specific objects |
This still adds the property to BezierPath globally. I don't see a big problem with having a few context-specific attributes on main objects. However, an alternative could be: from svgObjects import BezierPath, FormattedString
b = BezierPath()
b.svgClass = "sadsadsa" |
Im just afraid if lots of those properties are added, it becomes un manageable. While hosting those properties in a context (even if they are added to the main objects) its feels like only the svgContext (in this case) is responsible for those properties. see the PR #357 |
weekend idea: the original proposal (“add support for ID and Class”) could be generalized into “add support for SVG path attributes”. it could be implemented as a single function which takes the attribute name and the value: B = BezierPath()
B.svgAttribute("class", "foo bar)
B.svgAttribute("id", "square")
B.svgAttribute("cursor", "move") seems more elegant and more flexible (?) |
Or path = BezierPath()
path.svgAttributes = dict(foo="bar") |
Smells like overgeneralization to me. |
ID and class are the ones I need at the moment, I’m fine if only those are added. (I have little experience with SVGs though, and the list of supported attributes is very extensive. they must be useful to someone :) cursor can be added by the ‘behavior layer’ (JS), see this example. thanks! looking forward to put it to good use |
Sure, but DrawBot cannot be the ultimate SVG generator: there are way more things that SVG can do that DB can't (and shouldn't). For DB, SVG is simply one of the output formats. If we can add something to make SVG a lot more useful in some contexts (such as class and id attrs) then by all means, let's do that, but let's also keep in mind that writing SVG is not DB's core business :) |
added #357 |
DrawBot can generate SVGs; SVGs can be embedded in HTML and styled with CSS just like the rest of the page.
SVG objects need an ID or class so that CSS can refer to them. in the example below,
id
andclass
attributes were added manually after the SVG was generated.Proposal
add support for setting an ID and/or class when the
BezierPath
is created:thanks!
The text was updated successfully, but these errors were encountered: