Rendering an SVG. Have disabled the SVG’s style. My problem is that even though I’m setting the stroke weight through processing, it still scales that stroke when I render the SVG at different sizes.
What I want is the shape its self to scale but the stroke to remain constant. This is ultimately going to be plotted with a real pen so I want to visualize that.
As an aside I’m planning to create an entire ‘line font’ as SVG’s and an accompanying processing lib for this purpose (plotting normal fonts sucks), which I’ll be happy to share if I can get it to work.
Hello,
I can but guess without seeing the svg, but if it was converted from a ttf it doesn’t matter what you do with strokeWidth because those glyphs are built assuming noStroke but fill()
Thanks for replying. It’s a single un-closed spline that I traced manually - that’s the whole point because when I plot this with a pen I don’t want it to outline the characters as it does with regular fonts.
So that you can call your shape with different dimensions and it will counterbalance the strokeWeight by the same ratio, given an assumed base size and base weight. The idea would be to scale the shape but keep line thicknesses the same.
…although I’m surprised at what you are describing. I wonder if you have a parent and child shape, so disableStyles isn’t actually doing anything…?
Hello!
Thanks for the reply, I didn’t notice it until now!
Your function worked, assuming you know the width of PShape s. Is there a way to calculate that?
I’ve attached the svg - I went in with a text editor and removed everything except the lines for the actual path but with the same result. Also attached the original for completeness.
If it contains a vertex list then you can iterate over all vertices and get minx, miny, maxx, maxy to form a bounding box – and maxx-minx is the width.
If those fields don’t have (useful) values and you can’t get the vertices, then you just need to specify it manually.
PShape is a really complex class, and svg is a complex spec that has multiple ways of specifying dimensions, viewports, and the coordinates of their contents – these don’t always map cleanly to the width/height that you may want, so it tends to depend a lot on your data.
That said, I’m not actually sure what the reliable way is of generating svg files that correctly populate PShape.width / .height – I’ve never tried. If you discover that you are able to do that reliably, could you post about it here?
Edit
For your h.svg, which is a simple svg, the PShape.width approach from the reference works fine:
// https://processing.org/reference/PShape_width.html
PShape s;
void setup() {
s = loadShape("h.svg");
println(s.width); // Prints "6.0", the width of the shape
println(s.height); // Prints "9.0", the width of the shape
}