1 | ;+ |
---|
2 | ; NAME: |
---|
3 | ; PSWINDOW |
---|
4 | ; |
---|
5 | ; PURPOSE: |
---|
6 | ; |
---|
7 | ; This function is used to calculate the size of a PostScript |
---|
8 | ; window that has the same aspect ratio (ratio of height to |
---|
9 | ; width) as the current display graphics window. It creates |
---|
10 | ; the largest possible PostScript output window with the |
---|
11 | ; desired aspect ratio. This assures that graphics output |
---|
12 | ; looks similar, if not identical, to PostScript output. |
---|
13 | ; |
---|
14 | ; AUTHOR: |
---|
15 | ; |
---|
16 | ; FANNING SOFTWARE CONSULTING |
---|
17 | ; David Fanning, Ph.D. |
---|
18 | ; 1645 Sheely Drive |
---|
19 | ; Fort Collins, CO 80526 USA |
---|
20 | ; Phone: 970-221-0438 |
---|
21 | ; E-mail: davidf@dfanning.com |
---|
22 | ; Coyote's Guide to IDL Programming: http://www.dfanning.com/ |
---|
23 | ; |
---|
24 | ; CATEGORY: |
---|
25 | ; |
---|
26 | ; Graphics. |
---|
27 | ; |
---|
28 | ; CALLING SEQUENCE: |
---|
29 | ; |
---|
30 | ; pageInfo = PSWINDOW() |
---|
31 | ; |
---|
32 | ; INPUTS: |
---|
33 | ; |
---|
34 | ; None. |
---|
35 | ; |
---|
36 | ; KEYWORD PARAMETERS: |
---|
37 | ; |
---|
38 | ; CM: Normally the structure value that is returned from this |
---|
39 | ; function reports its values in inches. Setting this keyword |
---|
40 | ; causes the return values to be in units of centimeters. |
---|
41 | ; |
---|
42 | ; FUDGE: A quick way to set symetrical XFUDGE and YFUDGE factors. |
---|
43 | ; If this keyword is set to a value, XFUDGE and YFUDGE keywords are |
---|
44 | ; set to the same value. |
---|
45 | ; |
---|
46 | ; LANDSCAPE: Normally this function assumes a PostScript window |
---|
47 | ; in Portrait mode. Setting this keyword assumes you want |
---|
48 | ; the graphic in Landscape mode. |
---|
49 | ; |
---|
50 | ; MARGIN: The margin around the edges of the plot. The value must be |
---|
51 | ; a floating point value between 0.0 and 0.5. It is expressed in |
---|
52 | ; normalized coordinate units. The default margin is 0.05. |
---|
53 | ; |
---|
54 | ; PAGESIZE: Set this keyword to a string indicating the type |
---|
55 | ; of PostScript page size you want. Current values are "LETTER", |
---|
56 | ; "LEGAL", and "A4". Default is "LETTER". |
---|
57 | ; |
---|
58 | ; PRINTER: Set this keyword if the output will be used to |
---|
59 | ; configure the PRINTER device, rather than the PS device. |
---|
60 | ; (In the PRINTER device, offsets are always calculated from |
---|
61 | ; the lower-left corner of the page and do not rotate in |
---|
62 | ; Landscape mode, as they do with the PS device.) Note that |
---|
63 | ; the PRINTER device is only able to accept these keywords |
---|
64 | ; in IDL 5.1 and higher. |
---|
65 | ; |
---|
66 | ; XFUDGE: Printers calculate the offset point from the printable |
---|
67 | ; edge of the paper (sometimes), rather from the corner of the paper. |
---|
68 | ; For example, on my Lexmark printer, both X and Y offsets are |
---|
69 | ; calculated from a point 0.25 inches in from the edge. This keyword |
---|
70 | ; allows you to set a "fudge" factor that will be subtracted from |
---|
71 | ; the XOFFSET that is returned to the user. This allows you to create |
---|
72 | ; output that is centered on the page. The fudge factor should be in |
---|
73 | ; the same units as the returned size and offset values. |
---|
74 | ; |
---|
75 | ; YFUDGE: Printers calculate the offset point from the printable |
---|
76 | ; edge of the paper (sometimes), rather from the corner of the paper. |
---|
77 | ; For example, on my Lexmark printer, both X and Y offsets are |
---|
78 | ; calculated from a point 0.25 inches in from the edge. This keyword |
---|
79 | ; allows you to set a "fudge" factor that will be subtracted from |
---|
80 | ; the YOFFSET that is returned to the user. This allows you to create |
---|
81 | ; output that is centered on the page. The fudge factor should be in |
---|
82 | ; the same units as the returned size and offset values. |
---|
83 | ; |
---|
84 | ; OUTPUTS: |
---|
85 | ; |
---|
86 | ; pageInfo: The output value is a named structure defined like |
---|
87 | ; this: |
---|
88 | ; |
---|
89 | ; pageInfo = {PSWINDOW_STRUCT, XSIZE:0.0, YSIZE:0.0, $ |
---|
90 | ; XOFSET:0.0, YOFFSET:0.0, INCHES:0, PORTRAIT:0, LANDSCAPE:0} |
---|
91 | ; |
---|
92 | ; The units of the four size fields are inches unless the CM |
---|
93 | ; keyword is set. |
---|
94 | ; |
---|
95 | ; The output can be used to immediately configure the PostScript |
---|
96 | ; or Printer device, like this: |
---|
97 | ; |
---|
98 | ; Set_Plot, 'PS' ; or 'PRINTER' |
---|
99 | ; Device, _Extra=pageInfo |
---|
100 | ; |
---|
101 | ; RESTRICTIONS: |
---|
102 | ; |
---|
103 | ; The aspect ratio of the current graphics window is calculated |
---|
104 | ; like this: |
---|
105 | ; |
---|
106 | ; aspectRatio = FLOAT(!D.Y_VSIZE) / !D.X_VSIZE |
---|
107 | ; |
---|
108 | ; EXAMPLE: |
---|
109 | ; |
---|
110 | ; To create a PostScript output window with the same aspect |
---|
111 | ; ratio as the curently active display window, type: |
---|
112 | ; |
---|
113 | ; pageInfo = PSWINDOW() |
---|
114 | ; SET_PLOT, 'PS' |
---|
115 | ; DEVICE, _Extra=pageInfo |
---|
116 | ; |
---|
117 | ; To configure the PRINTER device: |
---|
118 | ; |
---|
119 | ; pageInfo = PSWINDOW(/Printer, Fudge=0.25) |
---|
120 | ; SET_PLOT, 'PRINTER' |
---|
121 | ; DEVICE, _Extra=pageInfo |
---|
122 | ; |
---|
123 | ; MODIFICATION HISTORY: |
---|
124 | ; |
---|
125 | ; Written by: David W. Fanning, November 1996. |
---|
126 | ; Fixed a bug in which the YOFFSET was calculated incorrectly |
---|
127 | ; in Landscape mode. 12 Feb 97. |
---|
128 | ; Took out a line of code that wasn't being used. 14 Mar 97. |
---|
129 | ; Added correct units keyword to return structure. 29 JUN 98. DWF |
---|
130 | ; Fixed a bug in how landscape offsets were calculated. 19 JUL 99. DWF. |
---|
131 | ; Fixed a bug in the way margins were used to conform to my |
---|
132 | ; original conception of the program. 19 JUL 99. DWF. |
---|
133 | ; Added Landscape and Portrait fields to the return structure. 19 JUL 99. DWF. |
---|
134 | ; Added PageSize keyword, changed MARGIN keyword, and completely |
---|
135 | ; rewrote most of the intenal code. 9 FEB 2000. DWF. |
---|
136 | ; Fixed a bug in how I calculated the aspect ratio. 1 MAR 2000. DWF. |
---|
137 | ; Added PRINTER keyword to return proper offset values for the |
---|
138 | ; PRINTER device, where the offset location is not rotated. 1 MAR 2000. DWF. |
---|
139 | ; Added PRINTER fudge factors to take into account that printer offsets are |
---|
140 | ; calculated from the printable area of the paper, rather than the corner |
---|
141 | ; of the paper. 8 AUG 2000. DWF. |
---|
142 | ; Changed the default margin to 0.05 from 0.15. 29 Nov 2004, DWF. |
---|
143 | ;- |
---|
144 | ; |
---|
145 | ;########################################################################### |
---|
146 | ; |
---|
147 | ; LICENSE |
---|
148 | ; |
---|
149 | ; This software is OSI Certified Open Source Software. |
---|
150 | ; OSI Certified is a certification mark of the Open Source Initiative. |
---|
151 | ; |
---|
152 | ; Copyright © 2000-2004 Fanning Software Consulting |
---|
153 | ; |
---|
154 | ; This software is provided "as-is", without any express or |
---|
155 | ; implied warranty. In no event will the authors be held liable |
---|
156 | ; for any damages arising from the use of this software. |
---|
157 | ; |
---|
158 | ; Permission is granted to anyone to use this software for any |
---|
159 | ; purpose, including commercial applications, and to alter it and |
---|
160 | ; redistribute it freely, subject to the following restrictions: |
---|
161 | ; |
---|
162 | ; 1. The origin of this software must not be misrepresented; you must |
---|
163 | ; not claim you wrote the original software. If you use this software |
---|
164 | ; in a product, an acknowledgment in the product documentation |
---|
165 | ; would be appreciated, but is not required. |
---|
166 | ; |
---|
167 | ; 2. Altered source versions must be plainly marked as such, and must |
---|
168 | ; not be misrepresented as being the original software. |
---|
169 | ; |
---|
170 | ; 3. This notice may not be removed or altered from any source distribution. |
---|
171 | ; |
---|
172 | ; For more information on Open Source Software, visit the Open Source |
---|
173 | ; web site: http://www.opensource.org. |
---|
174 | ; |
---|
175 | ;########################################################################### |
---|
176 | |
---|
177 | |
---|
178 | |
---|
179 | FUNCTION PSWINDOW_ASPECT, aspectRatio, MARGIN=margin, WindowAspect=wAspectRatio |
---|
180 | |
---|
181 | ON_ERROR, 1 |
---|
182 | |
---|
183 | ; Check for aspect ratio parameter and possibilities. |
---|
184 | |
---|
185 | IF N_PARAMS() EQ 0 THEN aspectRatio = 1.0 |
---|
186 | |
---|
187 | IF aspectRatio EQ 0 THEN BEGIN |
---|
188 | MESSAGE, 'Aspect Ratio of 0. Changing to 1...', /Informational |
---|
189 | aspectRatio = 1.0 |
---|
190 | ENDIF |
---|
191 | |
---|
192 | s = SIZE(aspectRatio) |
---|
193 | IF s(s(0)+1) NE 4 THEN $ |
---|
194 | MESSAGE, 'Aspect Ratio is not a FLOAT. Take care...', /Informational |
---|
195 | |
---|
196 | ; Check for margins. |
---|
197 | |
---|
198 | IF N_ELEMENTS(margin) EQ 0 THEN margin = 0.15 |
---|
199 | |
---|
200 | ; Error checking. |
---|
201 | |
---|
202 | IF margin LT 0 OR margin GE 0.5 THEN $ |
---|
203 | MESSAGE, 'The MARGIN keyword value must be between 0.0 and 0.5.' |
---|
204 | |
---|
205 | ; Calculate the aspect ratio of the current window. |
---|
206 | |
---|
207 | IF N_Elements(wAspectRatio) EQ 0 THEN wAspectRatio = FLOAT(!D.Y_VSIZE) / !D.X_VSIZE |
---|
208 | |
---|
209 | ; Calculate normalized positions in window. |
---|
210 | |
---|
211 | IF (aspectRatio LE wAspectRatio) THEN BEGIN |
---|
212 | xstart = margin |
---|
213 | ystart = 0.5 - (0.5 - margin) * (aspectRatio / wAspectRatio) |
---|
214 | xend = 1.0 - margin |
---|
215 | yend = 0.5 + (0.5 - margin) * (aspectRatio / wAspectRatio) |
---|
216 | ENDIF ELSE BEGIN |
---|
217 | xstart = 0.5 - (0.5 - margin) * (wAspectRatio / aspectRatio) |
---|
218 | ystart = margin |
---|
219 | xend = 0.5 + (0.5 - margin) * (wAspectRatio / aspectRatio) |
---|
220 | yend = 1.0 - margin |
---|
221 | ENDELSE |
---|
222 | |
---|
223 | position = [xstart, ystart, xend, yend] |
---|
224 | |
---|
225 | RETURN, position |
---|
226 | END ; ---------------------------------------------------------------------------------- |
---|
227 | |
---|
228 | |
---|
229 | |
---|
230 | FUNCTION PSWINDOW, LANDSCAPE=landscape, CM=cm, MARGIN=margin, $ |
---|
231 | PageSize=pagesize, Printer=printer, Fudge=fudge, XFudge=xfudge, YFudge=yfudge |
---|
232 | |
---|
233 | ; Set up default values. |
---|
234 | |
---|
235 | landscape = Keyword_Set(landscape) |
---|
236 | cm = Keyword_Set(cm) |
---|
237 | printer = Keyword_Set(printer) |
---|
238 | inches = 1 |
---|
239 | |
---|
240 | ; Set up printer fudge factors, if necessary. |
---|
241 | |
---|
242 | IF N_Elements(fudge) NE 0 THEN BEGIN |
---|
243 | xfudge = fudge |
---|
244 | yfudge = fudge |
---|
245 | ENDIF |
---|
246 | IF N_Elements(xfudge) EQ 0 THEN xfudge = 0.0 |
---|
247 | IF N_Elements(yfudge) EQ 0 THEN yfudge = 0.0 |
---|
248 | |
---|
249 | ; Get the page size. |
---|
250 | |
---|
251 | IF N_Elements(pagesize) EQ 0 THEN pagesize = 'LETTER' $ |
---|
252 | ELSE pagesize = StrUpCase(pagesize) |
---|
253 | CASE pagesize OF |
---|
254 | 'LETTER': BEGIN |
---|
255 | shortside = 8.5 |
---|
256 | longside = 11.0 |
---|
257 | ENDCASE |
---|
258 | 'LEGAL': BEGIN |
---|
259 | shortside = 8.5 |
---|
260 | longside = 14.0 |
---|
261 | ENDCASE |
---|
262 | 'A4': BEGIN |
---|
263 | shortside = 8.27 |
---|
264 | longside = 11.7 |
---|
265 | ENDCASE |
---|
266 | ELSE: BEGIN |
---|
267 | Message, 'Unknown page size. Using LETTER...', /Informational |
---|
268 | shortside = 8.5 |
---|
269 | longside = 11.0 |
---|
270 | ENDCASE |
---|
271 | ENDCASE |
---|
272 | |
---|
273 | ; Need measurements in centimeters? |
---|
274 | |
---|
275 | IF KEYWORD_SET(cm) THEN BEGIN |
---|
276 | shortside = shortside * 2.54 |
---|
277 | longside = longside * 2.54 |
---|
278 | inches = 0 |
---|
279 | ENDIF |
---|
280 | |
---|
281 | ; Determine the margin of the window on the page. |
---|
282 | |
---|
283 | IF N_ELEMENTS(margin) EQ 0 THEN margin=0.05 |
---|
284 | |
---|
285 | ; Get the aspect ratio of the current display window. Aspect ratio |
---|
286 | ; is ratio of xsize/ysize. |
---|
287 | |
---|
288 | aspectRatio = FLOAT(!D.Y_VSIZE) / !D.X_VSIZE |
---|
289 | |
---|
290 | ; Get the aspect ratio of the page. |
---|
291 | |
---|
292 | IF Keyword_Set(landscape) THEN pAspectRatio = shortside / longside $ |
---|
293 | ELSE pAspectRatio = longside / shortside |
---|
294 | |
---|
295 | ; Get the position on the page for this window. |
---|
296 | |
---|
297 | pos = PSWindow_Aspect(aspectRatio, Margin=margin, WindowAspect=pAspectRatio) |
---|
298 | |
---|
299 | ; Convert normalized position coordinates to size units. |
---|
300 | |
---|
301 | IF KEYWORD_SET(landscape) THEN BEGIN |
---|
302 | IF printer THEN BEGIN |
---|
303 | xsize = (pos[2] - pos[0]) * longside |
---|
304 | ysize = (pos[3] - pos[1]) * shortside |
---|
305 | yoffset = pos[1] * shortside - yfudge |
---|
306 | xoffset = pos[0] * longside - xfudge |
---|
307 | landscape = 1 |
---|
308 | portrait = 0 |
---|
309 | ENDIF ELSE BEGIN |
---|
310 | xsize = (pos[2] - pos[0]) * longside |
---|
311 | ysize = (pos[3] - pos[1]) * shortside |
---|
312 | xoffset = pos[1] * shortside |
---|
313 | yoffset = longside - (pos[0] * longside) |
---|
314 | landscape = 1 |
---|
315 | portrait = 0 |
---|
316 | ENDELSE |
---|
317 | ENDIF ELSE BEGIN |
---|
318 | xsize = (pos[2] - pos[0]) * shortside |
---|
319 | ysize = (pos[3] - pos[1]) * longside |
---|
320 | IF printer THEN BEGIN |
---|
321 | xoffset = pos[0] * shortside - xfudge |
---|
322 | yoffset = pos[1] * longside - yfudge |
---|
323 | ENDIF ELSE BEGIN |
---|
324 | xoffset = pos[0] * shortside |
---|
325 | yoffset = pos[1] * longside |
---|
326 | ENDELSE |
---|
327 | landscape = 0 |
---|
328 | portrait = 1 |
---|
329 | ENDELSE |
---|
330 | |
---|
331 | ; Return the proper DEVICE data structure. |
---|
332 | |
---|
333 | RETURN, {PSWINDOW_STRUCT, XSIZE:xsize, YSIZE:ysize, $ |
---|
334 | XOFFSET:xoffset, YOFFSET:yoffset, INCHES:inches, $ |
---|
335 | PORTRAIT:portrait, LANDSCAPE:landscape} |
---|
336 | |
---|
337 | END |
---|