1 | ;+ |
---|
2 | ; NAME: |
---|
3 | ; PS_START/PS_END |
---|
4 | ; |
---|
5 | ; PURPOSE: |
---|
6 | ; |
---|
7 | ; The purpose of PS_START and PS_END is to make it easy to set-up |
---|
8 | ; for and close a PostScript file. The programs work in close conjunction |
---|
9 | ; with PSCONFIG, another program from the Coyote Library. |
---|
10 | ; |
---|
11 | ; If ImageMagick (http://www.imagemagick.org/script/index.php) is installed |
---|
12 | ; on your computer, you can easily convert PostScript output to JPEG, PNG, and TIFF |
---|
13 | ; image output. (See the keywords to PS_END.) |
---|
14 | ; |
---|
15 | ; AUTHOR: |
---|
16 | ; |
---|
17 | ; FANNING SOFTWARE CONSULTING |
---|
18 | ; David Fanning, Ph.D. |
---|
19 | ; 1645 Sheely Drive |
---|
20 | ; Fort Collins, CO 80526 USA |
---|
21 | ; Phone: 970-221-0438 |
---|
22 | ; E-mail: davidf@dfanning.com |
---|
23 | ; Coyote's Guide to IDL Programming: http://www.dfanning.com/ |
---|
24 | ; |
---|
25 | ; CATEGORY: |
---|
26 | ; |
---|
27 | ; Graphics, File Output, PostScript |
---|
28 | ; |
---|
29 | ; CALLING SEQUENCE: |
---|
30 | ; |
---|
31 | ; PS_START |
---|
32 | ; Various graphics commands here... |
---|
33 | ; PS_END |
---|
34 | ; |
---|
35 | ; KEYWORD PARAMETERS FOR PS_START: |
---|
36 | ; |
---|
37 | ; GUI: The default behavior is to use PSCONFIG to configure the |
---|
38 | ; PostScript device silently. If you wish to allow the user |
---|
39 | ; to interatively configure the PostScript device, set this |
---|
40 | ; keyword. |
---|
41 | ; |
---|
42 | ; SCALE_FACTOR: Set this to the PostScript scale factor. By default: 1. |
---|
43 | ; |
---|
44 | ; Any keyword supported by PSCONFIG can be used to configure the PostScript device. |
---|
45 | ; Common keywords would include FILENAME, XSIZE, YSIZE, XOFFSET, YOFFSET, etc. See |
---|
46 | ; the PSCONFIG documentation for details. |
---|
47 | ; |
---|
48 | ; KEYWORD PARAMETERS FOR PS_END: |
---|
49 | ; |
---|
50 | ; All keywords for PS_END require that ImageMagick is installed on your computer |
---|
51 | ; and is configured correctly. Image conversion is done by spawning a "convert" |
---|
52 | ; command to ImageMagick. |
---|
53 | ; |
---|
54 | ; JPEG: Set this keyword to convert the PostScript output file to a JPEG image. |
---|
55 | ; PNG: Set this keyword to convert the PostScript output file to a PNG image. |
---|
56 | ; TIFF: Set this keyword to convert the PostScript output file to a TIFF image. |
---|
57 | ; |
---|
58 | ; COMMON BLOCKS: |
---|
59 | ; |
---|
60 | ; _$FSC_PS_START_ Contains the PS_STRUCT structure for communication between |
---|
61 | ; PS_START and PS_END. |
---|
62 | ; |
---|
63 | ; SIDE EFFECTS: |
---|
64 | ; |
---|
65 | ; When PS_START is called, the current graphics device is set to "PS" (the PostScript |
---|
66 | ; device). When PS_END is called the current graphics device is returned to the device |
---|
67 | ; in effect when PS_START was called. |
---|
68 | ; |
---|
69 | ; RESTRICTIONS: |
---|
70 | ; |
---|
71 | ; Requires numerous programs from the Coyote Library. To convert PostScript files |
---|
72 | ; to PNG, JPEG, and TIFF files requires ImageMagick be installed on your |
---|
73 | ; computer and configured correctly. You can download Coyote Library programs here: |
---|
74 | ; |
---|
75 | ; http://www.dfanning.com/programs/coyoteprograms.zip |
---|
76 | ; |
---|
77 | ; ImageMagick can be found here: |
---|
78 | ; |
---|
79 | ; http://www.imagemagick.org/script/index.php |
---|
80 | ; |
---|
81 | ; EXAMPLE: |
---|
82 | ; |
---|
83 | ; To create a line plot in a PostScript file named lineplot.ps and |
---|
84 | ; also create a PNG file named lineplot.png for display in a browser, |
---|
85 | ; type these commands. |
---|
86 | ; |
---|
87 | ; PS_Start, FILENAME='lineplot.ps' |
---|
88 | ; Plot, Findgen(11), COLOR=FSC_Color('navy'), /NODATA, XTITLE='Time', YTITLE='Signal' |
---|
89 | ; OPlot, Findgen(11), COLOR=FSC_Color('indian red') |
---|
90 | ; OPlot, Findgen(11), COLOR=FSC_Color('olive'), PSYM=2 |
---|
91 | ; PS_End, /PNG |
---|
92 | ; |
---|
93 | ; NOTES: |
---|
94 | ; |
---|
95 | ; You can easily configure any modifications you like for your PostScript output |
---|
96 | ; by setting fields in the plot and axis system variables (!P, !X, !Y, and !Z). |
---|
97 | ; The modifications currently made by default in this program are these: |
---|
98 | ; |
---|
99 | ; !P.Charsize = 1.5 |
---|
100 | ; !P.Thick = 2 |
---|
101 | ; !X.Thick = 2 |
---|
102 | ; !Y.Thick = 2 |
---|
103 | ; !Z.Thick = 2 |
---|
104 | ; !P.Symsize = 1.25 |
---|
105 | ; !P.Font = 1 |
---|
106 | ; |
---|
107 | ; MODIFICATION HISTORY: |
---|
108 | ; |
---|
109 | ; Written by: David W. Fanning, 20 May 2008. |
---|
110 | ;- |
---|
111 | ; |
---|
112 | ;########################################################################### |
---|
113 | ; |
---|
114 | ; LICENSE |
---|
115 | ; |
---|
116 | ; This software is OSI Certified Open Source Software. |
---|
117 | ; OSI Certified is a certification mark of the Open Source Initiative. |
---|
118 | ; |
---|
119 | ; Copyright 2008 Fanning Software Consulting. |
---|
120 | ; |
---|
121 | ; This software is provided "as-is", without any express or |
---|
122 | ; implied warranty. In no event will the authors be held liable |
---|
123 | ; for any damages arising from the use of this software. |
---|
124 | ; |
---|
125 | ; Permission is granted to anyone to use this software for any |
---|
126 | ; purpose, including commercial applications, and to alter it and |
---|
127 | ; redistribute it freely, subject to the following restrictions: |
---|
128 | ; |
---|
129 | ; 1. The origin of this software must not be misrepresented; you must |
---|
130 | ; not claim you wrote the original software. If you use this software |
---|
131 | ; in a product, an acknowledgment in the product documentation |
---|
132 | ; would be appreciated, but is not required. |
---|
133 | ; |
---|
134 | ; 2. Altered source versions must be plainly marked as such, and must |
---|
135 | ; not be misrepresented as being the original software. |
---|
136 | ; |
---|
137 | ; 3. This notice may not be removed or altered from any source distribution. |
---|
138 | ; |
---|
139 | ; For more information on Open Source Software, visit the Open Source |
---|
140 | ; web site: http://www.opensource.org. |
---|
141 | ; |
---|
142 | ;########################################################################### |
---|
143 | PRO FSC_PS_SETUP__DEFINE |
---|
144 | |
---|
145 | struct = { FSC_PS_SETUP, $ |
---|
146 | currentDevice: "", $ |
---|
147 | setup: 0, $ |
---|
148 | convert: "", $ |
---|
149 | filename: "", $ |
---|
150 | p: !P, $ |
---|
151 | x: !X, $ |
---|
152 | y: !Y, $ |
---|
153 | z: !Z $ |
---|
154 | } |
---|
155 | |
---|
156 | END ;--------------------------------------------------------------- |
---|
157 | |
---|
158 | |
---|
159 | |
---|
160 | PRO PS_END, JPEG=jpeg, PNG=png, TIFF=tiff |
---|
161 | |
---|
162 | COMMON _$FSC_PS_START_, ps_struct |
---|
163 | |
---|
164 | ON_ERROR, 2 ; Return to caller. |
---|
165 | |
---|
166 | ; Close the PostScript file, if this is PostScript device. |
---|
167 | IF !D.Name EQ 'PS' THEN Device, /CLOSE_FILE |
---|
168 | |
---|
169 | ; Need to convert with ImageMagick? |
---|
170 | IF Keyword_Set(png) THEN ps_struct.convert = 'PNG' |
---|
171 | IF Keyword_Set(jpeg) THEN ps_struct.convert = 'JPEG' |
---|
172 | IF Keyword_Set(tiff) THEN ps_struct.convert = 'TIFF' |
---|
173 | IF ps_struct.convert NE "" THEN BEGIN |
---|
174 | |
---|
175 | basename = FSC_Base_Filename(ps_struct.filename, DIRECTORY=theDir, EXTENSION=theExtension) |
---|
176 | CASE 1 OF |
---|
177 | ps_struct.convert EQ 'PNG': outfilename = Filepath(ROOT_DIR=theDir, basename + '.png') |
---|
178 | ps_struct.convert EQ 'JPEG': outfilename = Filepath(ROOT_DIR=theDir, basename + '.jpg') |
---|
179 | ps_struct.convert EQ 'TIFF': outfilename = Filepath(ROOT_DIR=theDir, basename + '.tif') |
---|
180 | ENDCASE |
---|
181 | IF N_Elements(outfilename) NE "" THEN BEGIN |
---|
182 | ;;; resize fait baisser la taille, density bcp moins |
---|
183 | ; cmd = 'convert +antialias -density 300 ' + ps_struct.filename + ' -resize 25% ' + outfilename |
---|
184 | ; cmd = 'convert -density 600 ' + ps_struct.filename + ' -resize 12% ' + outfilename |
---|
185 | cmd = 'ps2epsi '+ps_struct.filename+' 2> /dev/null ; gs -sDEVICE=png16m -dTextAlphaBits=4 -sOutputFile='+outfilename+' -dNOPAUSE -dBATCH -dEPSCrop -r500x500 '+basename+'.epsi > /dev/null 2> /dev/null' |
---|
186 | SPAWN, cmd |
---|
187 | ENDIF |
---|
188 | |
---|
189 | ENDIF |
---|
190 | |
---|
191 | ; Clean up. |
---|
192 | Set_Plot, ps_struct.currentDevice |
---|
193 | !P = ps_struct.p |
---|
194 | !X = ps_struct.x |
---|
195 | !Y = ps_struct.y |
---|
196 | !Z = ps_struct.z |
---|
197 | ps_struct.setup = 0 |
---|
198 | ps_struct.currentDevice = "" |
---|
199 | ps_struct.filename = "" |
---|
200 | ps_struct.convert = "" |
---|
201 | |
---|
202 | END ;--------------------------------------------------------------- |
---|
203 | |
---|
204 | |
---|
205 | |
---|
206 | PRO PS_START, SCALE_FACTOR=scale_factor, GUI=gui, _EXTRA=extra |
---|
207 | |
---|
208 | COMMON _$FSC_PS_START_, ps_struct |
---|
209 | |
---|
210 | ; Define the PS structure. |
---|
211 | IF N_Elements(ps_struct) EQ 0 THEN ps_struct = {FSC_PS_SETUP} |
---|
212 | |
---|
213 | ; If the setup flag is on, then we have to close the previous |
---|
214 | ; start command before we can continue. |
---|
215 | IF ps_struct.setup EQ 1 THEN PS_END |
---|
216 | |
---|
217 | ; Save current setup information in the PS_STRUCT structure. |
---|
218 | ps_struct.setup = 1 |
---|
219 | ps_struct.currentDevice = !D.Name |
---|
220 | ps_struct.p = !P |
---|
221 | ps_struct.x = !X |
---|
222 | ps_struct.y = !Y |
---|
223 | ps_struct.z = !Z |
---|
224 | |
---|
225 | ; Change any parameters you feel like changing. |
---|
226 | ;;;;;;; AYMERIC |
---|
227 | ; !P.Charsize = 1.75 |
---|
228 | ; !P.Thick = 2 |
---|
229 | ; !X.Thick = 2 |
---|
230 | ; !Y.Thick = 2 |
---|
231 | !Z.Thick = 2 |
---|
232 | !P.Symsize = 1.25 |
---|
233 | !P.Font = 1 |
---|
234 | |
---|
235 | ;;;;;;; AYMERIC |
---|
236 | !P.Charsize = 1.2 |
---|
237 | !p.charthick = 2.0 |
---|
238 | !p.thick = 2.0 |
---|
239 | !x.thick = 2.0 |
---|
240 | !y.thick = 2.0 |
---|
241 | |
---|
242 | |
---|
243 | Device, Set_Font='Helvetica', /TT_FONT |
---|
244 | |
---|
245 | ; Configure the PostScript Device |
---|
246 | cancelled = 0 |
---|
247 | sizes = PSWindow(_Extra=extra) |
---|
248 | keywords = PSConfig(_Extra=extra, INCHES=sizes.inches, XSIZE=sizes.xsize, YSIZE=sizes.ysize, $ |
---|
249 | XOFFSET=sizes.xoffset, YOFFSET=sizes.yoffset, Cancel=cancelled, NOGUI=(1-Keyword_Set(gui))) |
---|
250 | IF cancelled THEN BEGIN |
---|
251 | PS_END |
---|
252 | RETURN |
---|
253 | ENDIF |
---|
254 | Set_Plot, 'PS' |
---|
255 | Device, _EXTRA=keywords |
---|
256 | |
---|
257 | ; What about scale factor? |
---|
258 | IF N_Elements(scale_factor) NE 0 THEN $ |
---|
259 | DEVICE, SCALE_FACTOR=scale_factor ELSE $ |
---|
260 | DEVICE, SCALE_FACTOR=1 |
---|
261 | |
---|
262 | ; Store filename. |
---|
263 | ps_struct.filename = keywords.filename |
---|
264 | |
---|
265 | END |
---|