In processing I make a two dimensional grid of petri dishes, and then center a name under each petridish. I get aligned text by using textAlign(CENTER, CENTER).

    beginRecord(SVG, svgs[2])
    textAlign(CENTER, CENTER)
    for col in range(COLS):
        for row in range(ROWS):
            print("col {0}  row {1}".format(col, row))
            pushMatrix() #store the default reference frame
            translate(CELL_WIDTH*col+0.5*CELL_WIDTH, CELL_HEIGHT*row+0.5*CELL_HEIGHT)

            for _ in range(int(random(20))):
                foo = Germ((0,0), PETRI_DIAMETER, debug=False)
            popMatrix() #lose this shifted reference frame

But I am going to print this out with my AxiDraw, so I want to use a Stroke Font, not an Outline Font. So I pull the svg into Inkscape and hersheyize the text.

The problem is, I lose the centering. The stroke font has different size/shape than the original outline font. The location of the text block seems to be specified in the SVG by the upper left XY origin. This doesn’t change when I change the font, but the physical width of the word changes, so it ends up losing its centering. Ideally, it would specify location of the text by the very middle of the text block, then it wold be centered regardless of the font. ( I was hoping that was what textAlign(CENTER, CENTER) would do, alas seems not.

It’s not like there is a bug anywhere, but I’d like to figure out how to get centered, stroke fonts on my processing output while avoiding fussy work inside Inkscape with Align and Distribute.


Take a look here:


1 Like