Closed andrewzwicky closed 1 year ago
Wow, that's a weird bug! It took a while to track down, but I believe I now know what's going on.
Inkscape extensions lack an elegant way to acquire the bounding box of a piece of text. The best approach I know is to spawn another copy of Inkscape with command-line options requesting the bounding box of a given object ID. However, in the case of freshly generated text, an ID has not yet been assigned so invalid values come back from Inkscape.
According to the documentation for get_id
, the function will
Get the id for the element, will set a new unique id if not set.
Hence, when you invoke text_obj._inkscape_obj.get_id()
, this has a side effect of assigning an ID to the text object, and that enables Inkscape to return a valid bounding box.
I'll modify Simple Inkscape Scripting always to invoke get_id
before launching Inkscape to query an object's bounding box. That should take just a moment…
Produces:
But if I add:
text_obj._inkscape_obj.get_id()
I get my intended result of:
I found this while doing print debugging. Printing somehow caused the output to change, which I tracked to the object id being evaluated, which lead me to this solution.