can I separate SVG rendering stroke width from shape size? (line fonts for plotting)

Hi,

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.

PShape h;

void setup() {
  size(640, 360);
  h = loadShape("h.svg");
  h.disableStyle();
  noFill();
  strokeWeight(0.02);
  noLoop();
} 

void draw(){
  background(255);
  shape(h, 110, 90, 100, 100); 
  shape(h, 280, 90,400,400);    
}

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.

Well then I suggest you could parse the svg as text strings and grab your line points coordinates and draw them “manually” with bezier()

roger that I’ll have a go

1 Like

Can you share h.svg?

My first guess (untested) based on what you are describing is something like this:

void shapeStroke(PShape s, float x, float y, float w, float h, float basewidth, float baseweight){
  strokeWeight(baseweight * w/basewidth);
  shape(s, x, y, w, h);
}

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…?