comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Translate characters/string size to data/normal coordinates?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Translate characters/string size to data/normal coordinates? [message #40279 is a reply to message #40255] Thu, 29 July 2004 09:01 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
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/
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Object Graphics: Combine 2d with 3d
Next Topic: Re: Combobox / Droplist index problem

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 15:14:15 PDT 2025

Total time taken to generate the page: 1.83930 seconds