You can obtain the width of a string in the current font with stringwidth and although this actually pushes offset coordinates on the stack, the y-value always seems to be useless. Is there a way to determine the exact height of a string, that may or may not include descenders?
You can obtain the width of a string in the current font with stringwidth
Share
stringwidth, as it says, doesn’t return string’s height. (In all cases I looked at, the second integer on the stack after executingstringwidthwas0— for strings that run in horizontal direction.)stringwidthgives the relative coordinates of the currentpoint after executing a(string) show.The PLRM has this to say about
stringwidth:So what would work to take into account the string’s height? The magic words to read up about in PRLM are
charpathandpathbbox. Try this:It calculates the string’s (printed in red) height and uses that info to try and center a small filled circle (printed in black) into the center of its bounding box: