J.K. writes:
> Is there any way to know the position of characters written to a
> device with xyouts? I'd like to do an xyouts but clear anything
> drawn underneath the text first with a polyfill.
>
> I can do it by trial and error but I could generalize it if I could
> translate characters to width and height in data or normal coordinates.
> I suppose this would change with !p.charsize/charsize/font selection.
>
> Any ideas?
This tickled some ideas I've had lately about writing an
annotation object. (Although I despair of ever having decent
fonts to work with in direct graphics.) Here is a quick and
dirty test program I built in a few minutes this morning.
It at least gives me some hope. :-)
Cheers,
David
;*********************************************************** ***
PRO TestWidth
Window, XSize=400, YSize=400
!P.Charsize = 1.0
xyouts, 0.5, 0.5, alignment=0.5, 'This is a text string', /normal,
width=w & print, w
skosh = 4.0/!D.Y_Size * !P.Charsize
x1 = 0.5 - w/2
x2 = 0.5 + w/2
y1 = 0.5 - skosh
y2 = 0.5 + (!P.Charsize * !D.Y_CH_SIZE / !D.Y_Size)
plots, [x1, x1, x2, x2, x1], [y1, y2, y2, y1, y1], /Normal
!P.Charsize = 2.0
xyouts, 0.5, 0.25, alignment=0.5, 'This is a text string', /normal,
width=w & print, w
skosh = 4.0/!D.Y_Size * !P.Charsize
x1 = 0.5 - w/2
x2 = 0.5 + w/2
y1 = 0.25 - skosh
y2 = 0.25 + (!P.Charsize * !D.Y_CH_SIZE / !D.Y_Size)
plots, [x1, x1, x2, x2, x1], [y1, y2, y2, y1, y1], /Normal
!P.Charsize = 3.0
xyouts, 0.5, 0.75, alignment=0.5, 'This is a text string', /normal,
width=w & print, w
skosh = 4.0/!D.Y_Size * !P.Charsize
x1 = 0.5 - w/2
x2 = 0.5 + w/2
y1 = 0.75 - skosh
y2 = 0.75 + (!P.Charsize * !D.Y_CH_SIZE / !D.Y_Size)
plots, [x1, x1, x2, x2, x1], [y1, y2, y2, y1, y1], /Normal
END
;*********************************************************** ***
That hardcoded "4" in the skosh variable should probably be
something like this: Round(!D.Y_CH_SIZE * 0.4). It's purpose
is to account for descenders.
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|