Re: Translate characters/string size to data/normal coordinates? [message #40253] |
Sun, 01 August 2004 17:41 |
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  |
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  |
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/
|
|
|