Get text outline
Hi again,
In order to follow some style guide, I would like to draw text tags with rounded rectangles. The Tag command seems to support only rectangular boxes. So I worked with DrawText and really felt delighted about the drawing toolbox. I followed the idea to write text with DrawText, read back the outline with DrawAction extractOutline and then draw a rounded rectangle around it. Nevertheless I did not succeed in reading back any text outline.
DrawAction extractOutline works nicely on geometrical objects like DrawRect, but it seems to totally ignore DrawText commands. And it also seems to ignore DrawLine commands.
Here is one example
variable dy = -40
SetDrawEnv push
SetDrawEnv gstart, gname=this
SetDrawEnv xcoord=bottom, ycoord=left
SetDrawEnv origin = MyXWave[5], MyYWave[5]
SetDrawEnv xcoord=abs,ycoord=abs
SetDrawEnv arrow=2,arrowlen=15,arrowsharp=0
SetDrawEnv linefgc=(65535,0,0)
SetDrawEnv linethick=2
SetDrawEnv save
DrawLine 0, 0, dx, dy
SetDrawEnv origin = dx, dy
SetDrawEnv save
DrawText 0, 0, "This\ris a\rtest"
SetDrawEnv gstop
DrawAction getgroup=this, extractOutline
SetDrawEnv pop
It yields empty W_PolyX and W_PolyY waves.
Is there any other way?
Best regards,
Joerg.
You could draw the text as an annotation (eg. TextBox) and then use the AnnotationInfo function to get the RECT of the annotation for drawing a rounded rectangle. You might want to set a window hook on the graph to update the outline rectangle automatically whenever the graph is modified (so that if the annotation is modified you can redraw the rect properly). Your hook will get called many times when the annotation hasn't actually changed, but that shouldn't be a problem since drawing the outline should be very fast.
December 8, 2018 at 08:46 am - Permalink
Hi,
that was a good hint. Well, TextBox does not seem to be the right choice. because I did not found a possibility to place a TextBox to specific coordinates. The good news is, that AnnotationInfo also works on a Tag. And Tag can easily be placed.
Problem solved.
Thanks and best regards,
Joerg.
December 9, 2018 at 10:14 pm - Permalink