3 ms·
Ooh, ooh, how about text is kind of a nightmare? I ginned up some pretty inelegant stuff to rotate text 90 degrees[0] because I got tired of trying to figure o
by mauvehaus 2y ago
Ooh, ooh, how about text is kind of a nightmare?
I ginned up some pretty inelegant stuff to rotate text 90 degrees[0] because I got tired of trying to figure out if there was a sane, blessed approach that I could generate with whatever Python library I was using.
Ditto right justifying text. I just ended up fudging it [1]. Like, this is a pretty basic functionality if you're mixing text into your graphics. And I'm pretty willing to go down a rabbit hole if I can find one. I realize that doing this requires knowing the size of the text as rendered or doing something funny like rendering LtR text RtL reversed (which wouldn't work for centered?), but this is something that seems reasonable to expect a straightforward solution to.
[0] https://github.com/longwalkwoodworking/cutlist/blob/a7c96028b0faebbae98bb1dd3bab9b3c025eb741/cutlist.py#L199 https://github.com/longwalkwoodworking/cutlist/blob/a7c96028...
[1] https://github.com/longwalkwoodworking/cutlist/blob/a7c96028b0faebbae98bb1dd3bab9b3c025eb741/cutlist.py#L129 https://github.com/longwalkwoodworking/cutlist/blob/a7c96028...
- skgough 2y agoUsually when I have to use text in SVG I give up and use HTML in a <foreignObject> [1] tag. The article mentions that SVG is in an awkward halfway point between being useful for humans or a compile target for vector graphics. Text is where this becomes really obvious. Trying to generate SVG with <text> elements in it that end up where you want them is hopeless, especially if you don't know what font the text will be rendered in. I prefer specifying the x,y, width,height of a box that HTML goes into in a <foreignObject> tag and letting the browser reflow the text as necessary within that space. But that's still often not perfect, and I have run into browser incompatibilities when doing any more than basic CSS rules on the HTML inside. [1] https://developer.mozilla.org/en-US/docs/Web/SVG/Element/foreignObject https://developer.mozilla.org/en-US/docs/Web/SVG/Element/for...
- Tao3300 2y agoI wanted to programmatically generate chord diagrams for ukulele in SVG. My solution was to make an SVG file in Inkscape that had everything in it that could possibly be in the diagram, and then marked it up for use with a template library. Not very elegant, but it saved me time to work on the thing I actually wanted to work on. Not sure if this sort of approach would be applicable for your cut lists.