1 | ;+ |
---|
2 | ; ROUTINE: lenstr |
---|
3 | ; USEAGE: result=lenstr(str) |
---|
4 | ; |
---|
5 | ; input: |
---|
6 | ; str a single string or string array. |
---|
7 | ; |
---|
8 | ; output: |
---|
9 | ; result length of the string(s) in normalized units |
---|
10 | ; the number of elements of RESULT matches the number of |
---|
11 | ; elements of STRING. |
---|
12 | ; |
---|
13 | ; procedure: |
---|
14 | ; This function returns the physical length of the |
---|
15 | ; string on the output device, not the number of |
---|
16 | ; characters. This is done by first switching to 'X' |
---|
17 | ; and writing the string(s) with XYOUTS in graphics |
---|
18 | ; mode 5, which disables display to the screen but |
---|
19 | ; does not interfere with operation of XYOUTS. The |
---|
20 | ; WIDTH keyword parameter of XYOUTS is used to |
---|
21 | ; retrieve the physical length of the string(s). |
---|
22 | ; |
---|
23 | ; author: Paul Ricchiazzi 7apr93 |
---|
24 | ; Institute for Computational Earth System Science |
---|
25 | ; University of California, Santa Barbara |
---|
26 | ; |
---|
27 | ; @todo seb |
---|
28 | ; |
---|
29 | ;- |
---|
30 | ; |
---|
31 | FUNCTION lenstr, str |
---|
32 | ; |
---|
33 | compile_opt idl2, strictarrsubs |
---|
34 | ; |
---|
35 | dsave=!d.name |
---|
36 | |
---|
37 | thisOS = !VERSION.OS_FAMILY |
---|
38 | thisOS = STRMID(thisOS, 0, 3) |
---|
39 | thisOS = STRUPCASE(thisOS) |
---|
40 | CASE thisOS of |
---|
41 | 'MAC': SET_PLOT, thisOS |
---|
42 | 'WIN': SET_PLOT, thisOS |
---|
43 | ELSE: SET_PLOT, 'X' |
---|
44 | ENDCASE |
---|
45 | !p.BACKGROUND=(!d.n_colors-1) < 255 |
---|
46 | !p.color=0 |
---|
47 | if !d.n_colors gt 256 then !p.background='ffffff'x |
---|
48 | |
---|
49 | device,get_graphics=oldg,set_graphics=5 |
---|
50 | if keyword_set(charsize) eq 0 then charsize=1 |
---|
51 | nn=n_elements(str) |
---|
52 | |
---|
53 | case nn of |
---|
54 | |
---|
55 | 0:w=0 |
---|
56 | |
---|
57 | 1:xyouts,0,0,/device,str,width=w |
---|
58 | |
---|
59 | else:begin |
---|
60 | w=fltarr(nn) |
---|
61 | for i=0,nn-1 do begin |
---|
62 | xyouts,0,0,/device,str[i],width=ww |
---|
63 | w[i]=ww |
---|
64 | endfor |
---|
65 | end |
---|
66 | endcase |
---|
67 | |
---|
68 | fac1=float(!d.x_ch_size)/!d.x_vsize ; ratio of char width to device1 width |
---|
69 | |
---|
70 | device,set_graphics=oldg |
---|
71 | set_plot,dsave |
---|
72 | IF dsave EQ 'X' OR dsave EQ 'MAC' OR dsave EQ 'WIN' then BEGIN |
---|
73 | !p.BACKGROUND=(!d.n_colors-1) < 255 |
---|
74 | !p.color=0 |
---|
75 | if !d.n_colors gt 256 then !p.background='ffffff'x |
---|
76 | ENDIF |
---|
77 | |
---|
78 | fac2=float(!d.x_ch_size)/!d.x_vsize ; ratio of char width to device2 width |
---|
79 | |
---|
80 | return,w*fac2/fac1 ; string width adjusted for device width |
---|
81 | end |
---|
82 | |
---|