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 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Translate characters/string size to data/normal coordinates? [message #40253] Sun, 01 August 2004 17:41
andrew.cool is currently offline  andrew.cool
Messages: 47
Registered: July 2003
Member
ellips@yahoo.com (J.K.) wrote in message news:<90c173a.0407290707.65405a8@posting.google.com>...
> 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?
>
> Thanks,
> John K.

Hi John,

Try using a negative value with the CHARSIZE keyword, which will

1. Not write anyhting to the screen, and

2. Return in the Width keyword the width of the string in
normalised coordinates.

e.g. :-

string = 'This is a normal string'
XYOUTS, x, y, string, WIDTH=thisWidth, CHARSIZE=-1

Of course, Charsize = -2 gives you a string twice as wide.

See http://www.dfanning.com/tips/stringsize.html for more info.


Cheers,

Andrew Cool
DSTO, Adelaide, South Australia
Re: Translate characters/string size to data/normal coordinates? [message #40255 is a reply to message #40253] Sun, 01 August 2004 09:33 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
J.K. wrote:
> 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?
>
> Thanks,
> John K.


You could use the widths keyword of xyouts. First write the word outside
of the plot.

You could also have a look in our xyouts_box routine
http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_source/idl _html/dbase/xyouts_box_dbase.pro.html

This routine did already the job you described.


tek_color
PLOT, findgen(10)
x=RANDOMU(1, 1000)*10 & y=randomu(2, 1000)*10
OPLOT, x,y, psym=1
OPLOT, findgen(10)-0.5 & oplot, findgen(10)-0.6
xyouts_box, 1, 1, 'test 11', /DATA $
, textcolor=2, boxcolor= 3 $
, charsize=3



Please have a look for further routines into

http://www.fz-juelich.de/icg/icg-i/idl_icglib/idl_lib_intro. html



cheers

Reimar
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/
  Switch to threaded view of this topic Create a new topic Submit Reply
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: Wed Oct 08 14:53:46 PDT 2025

Total time taken to generate the page: 0.00597 seconds