STR_SIZE
The purpose of this function is to return the proper character size to make a specified string a specifed width in a window. The width is specified in normalized coordinates. The function is extremely useful for sizing strings and labels in resizeable graphics windows.
FANNING SOFTWARE CONSULTING David Fanning, Ph.D. 1645 Sheely Drive Fort Collins, CO 80526 USA Phone: 970-221-0438 E-mail: david@idlcoyote.com Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Graphics Programs, Widgets.
thisCharSize = STR_SIZE(thisSting, targetWidth)
thisString: This is the string that you want to make a specifed target size or width.
targetWidth: This is the target width of the string in normalized coordinates in the current graphics window. The character size of the string (returned as thisCharSize) will be calculated to get the string width as close as possible to the target width. The default is 0.25.
INITSIZE: This is the initial size of the string. Default is 1.0. STEP: This is the amount the string size will change in each step of the interative process of calculating the string size. The default value is 0.05. XPOS: X position of the output test string. This can be used on the Postscript device, where no pixmap windows are available and where therefore the test strings would appear on the printable area. Default is 0.5 on most devices. If !D.NAME is PS, the default is 2.0 to draw the test string out of the drawable window area. YPOS: Y position of the output test string. This can be used on the Postscript device, where no pixmap windows are available and where therefore the test strings would appear on the printable area. Default is 0.5 on most devices. If !D.NAME is PS, the default is 2.0 to draw the test string out of the drawable window area.
thisCharSize: This is the size the specified string should be set to if you want to produce output of the specified target width. The value is in standard character size units where 1.0 is the standard character size.
To make the string "Happy Holidays" take up 30% of the width of the current graphics window, type this: XYOUTS, 0.5, 0.5, ALIGN=0.5, "Happy Holidays", $ CHARSIZE=STR_SIZE("Happy Holidays", 0.3)
Written by: David Fanning, 17 DEC 96. Added a scaling factor to take into account the aspect ratio of the window in determing the character size. 28 Oct 97. DWF Added check to be sure hardware fonts are not selected. 29 April 2000. DWF. Added a pixmap to get proper scaling in skinny windows. 16 May 2000. DWF. Forgot I can't do pixmaps in all devices. :-( Fixed. 7 Aug 2000. DWF. Added support of PostScript at behest of Benjamin Hornberger. 11 November 2004. DWF. Cleaned up the code a bit. 28 Feb 2011. DWF. Fixed non-square window algorithm to reflect my original intentions. 10 June 2011.