source: trunk/SRC/ToBeReviewed/POSTSCRIPT/calibre.pro @ 222

Last change on this file since 222 was 222, checked in by smasson, 17 years ago

small improvement

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.6 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; @file_comments
6; From a rapport of aspect and values (in line of character) of different margins,
7; it calculate POSFENETRE and POSBAR which serve to place the drawing and the color
8; bar thanks to !p.position on a leaf or a screen output whose the window has the same
9; proportion.
10;
11; @categories
12; Graphics
13;
14;
15; @param RAPPORTYX {in}{required}
16; Scale rapport between the length of the y axis and the x one. For example,
17; for an xy map: RAPPORTYX=(lat2-lat1)/(lon2-lon1)
18;
19; @param MARGE {in}{required}{type=vector}
20; Vector made of 4 elements containing the size of the left, right, up and
21; bottom margin having to surround the graph. All is measured in lines of characters.
22;
23; @param MARGEBAR {in}{required}{type=vector}
24; Vector made of 4 elements containing the size of the left, right and bottom
25; margin and -BEWARE- the last element is this time the position of the right up
26; corner, having to surround the color bar. All is measured in lines of characters.
27;
28; @param SMALLDRAW {in}{required}{type=vector}
29; 2 possibilities:
30;    It is vector made of 4 elements giving (in portrait or landscape) the position
31; of the frame in which the drawing must go in. This position is given by coordinates
32; of the 2 corners of the frame: in the left bottom and the right up. It is always
33; (for a postscript or a screen output) express in cm, the origin being the
34; left bottom corner.
35;    It is a vector made of 3 elements giving the number of column to be done in the
36; drawing, the number of line and the number of the case the number have to occupy
37; (see matlab). For example, to do 6 drawing in 3 columns and 2 lines and occupy
38; the 4th case, small=[2,3,4]
39;
40; @keyword REMPLI
41; Force the drawing to occupy the biggest possible place defined by
42; SMALLDRAW without respect the rapport y on x.
43;
44; @keyword YXASPECT
45; Force the rapport y on x to take the value RAPPORTYX*YXASPECT.
46; This keyword can be used in 2 cases:
47;   1) YXASPECT=1 : force RAPPORTYX to be respected otherwise, Calibre take the
48;   initiative to change it a little in the case of the aspect rapport of SMALL
49;   is too different of the one of SMALLDRAW.
50;   2) YXASPECT=n : multiply by n the aspect rapport given by default.
51;   For example in plt, RAPPORTYX is calculated to the reference be orthonormal,
52;   to have a reference where the y axis is 2 time bigger than the x one, YXASPECT=2.
53;       
54; @keyword PORTRAIT       
55; Force the page or the window to be in standing position.
56;
57; @keyword LANDSCAPE       
58; Force the page or the window on the screen to be in lengthened position.
59;
60; @keyword _EXTRA
61; Used to pass your keywords
62;
63; @param POSFENETRE {type=vector}
64; It is a vector made of 4 elements containing the position of the frame
65; containing captions + the graph in normalized coordinates.
66; Comment: to position the drawing, we have to do !p.position=POSFENETRE
67; after the call of calibre.
68;
69; @param POSBAR {type=vector}
70; See POSFENTRE but for the color bar. Same comment to position the color bar, !p.position=POSBAR
71;
72; @uses
73; common.pro
74;
75; @history
76; Sebastien Masson (smasson\@lodyc.jussieu.fr)
77;                       11/12/98
78;
79; @version
80; $Id$
81;-
82;------------------------------------------------------------
83;------------------------------------------------------------
84;------------------------------------------------------------
85pro calibre, rapportyx, marge, margebar, smalldraw, posfenetre, posbar $
86             , REMPLI = rempli, YXASPECT = yxaspect, PORTRAIT = portrait $
87             , LANDSCAPE = lanscape, _extra = ex
88;---------------------------------------------------------
89;
90  compile_opt idl2, strictarrsubs
91;
92@cm_4ps
93  IF NOT keyword_set(key_forgetold) THEN BEGIN
94@updatenew
95@updatekwd
96  ENDIF
97;---------------------------------------------------------
98;------------------------------------------------------------
99   tempsun = systime(1)         ; For key_performance
100;
101;-------------------------------------------------------------
102   if keyword_set(portrait) then key_portrait=1
103   if keyword_set(landscape) then key_portrait=0
104   if keyword_set(yxaspect) then begin
105      rapportyx=rapportyx*yxaspect
106      test2=0
107   endif else begin
108      yxaspect=1.
109      test2=1
110    ENDELSE
111;
112    mipgsz = min(page_size, max = mapgsz)
113;------------------------------------------------------------
114; choice of Landscape or Portrait
115;------------------------------------------------------------
116   if n_elements(key_portrait) eq 0  then begin
117      if rapportyx ge 1 then key_portrait=1
118      if rapportyx lt 1 then key_portrait=0
119   endif
120;-------------------------------------------------------------
121; If smalldraw is count like in matlab
122;-------------------------------------------------------------
123   if n_elements(smalldraw) EQ 3  then BEGIN
124     IF smalldraw[2] LT 1 OR smalldraw[2] GT smalldraw[0]*smalldraw[1] THEN BEGIN
125       dummy = report('wrong definition of the small keyword, we stop')
126       stop
127     ENDIF
128      if n_elements(page_margins) EQ 0 then page_margins = [1, 1, 1, 1]
129      smalldraw = long(smalldraw)
130      nbrecol = smalldraw[0]
131      nbrelig = smalldraw[1]
132      numero = smalldraw[2]-1
133      numlig = numero/nbrecol
134      numcol = numero-numlig*nbrecol
135      bas = mipgsz*key_portrait+mapgsz*(1-key_portrait)
136      cote = mapgsz*key_portrait+mipgsz*(1-key_portrait)
137      poscol = page_margins[0]+findgen(nbrecol+1)*(1.*(bas-(page_margins[0]+page_margins[1]))/nbrecol)
138      poslig = cote-page_margins[3]-findgen(nbrelig+1)*(1.*(cote-(page_margins[2]+page_margins[3]))/nbrelig)
139      smalldraw = [poscol[numcol], poslig[numlig+1], poscol[numcol+1], poslig[numlig]]
140   endif
141;------------------------------------------------------------
142; determination of the size of characters (!p.charsize)
143;------------------------------------------------------------
144   nombre_de_mots_ds_titre = 60.
145   !p.charsize=1.*(smalldraw[2]-smalldraw[0])*!d.x_px_cm / $
146    (nombre_de_mots_ds_titre* !d.y_ch_size)
147   if !p.charsize gt 1 then !p.charsize=1
148;------------------------------------------------------------
149; transfert of margin in cm
150;------------------------------------------------------------
151   cm=1.*!d.x_px_cm
152   marge=1.* marge * !d.y_ch_size * !p.charsize / cm
153   margebar=1.* margebar * !d.y_ch_size * !p.charsize / cm
154;------------------------------------------------------------
155; definition of the part of the leaf where we draw
156;------------------------------------------------------------
157   if key_portrait eq 0 then begin
158      big=smalldraw[2]-smalldraw[0]
159      small=smalldraw[3]-smalldraw[1]
160   endif else begin
161      small=smalldraw[2]-smalldraw[0]
162      big=smalldraw[3]-smalldraw[1]
163   endelse
164   if key_portrait eq 0 then $
165    rapportmax=1.*(small-marge[3]-marge[1])/(big-marge[2]-marge[0]) $
166   else rapportmax=1.*(small-marge[2]-marge[0])/(big-marge[3]-marge[1])
167;------------------------------------------------------------
168; If YXASPECT is not specified, we modify the value of RAPPORTYX
169; to it match better with the leaf's proportions.
170;------------------------------------------------------------
171   if rapportyx le rapportmax then begin
172      if test2 then begin
173         rap=1.*rapportmax/rapportyx
174         if rap ge 5. and rap lt 6. then rapportyx=rapportyx*1.5
175         if rap ge 6. and rap lt 7. then rapportyx=rapportyx*2.
176         if rap ge 7. and rap lt 8. then rapportyx=rapportyx*2.5
177         if rap ge 8. then rapportyx=rapportyx*3.
178      endif
179   endif else begin
180      if test2 then begin
181         rap=1.*rapportmax/rapportyx
182         if rap lt 1./5. and rap ge 1./6. then rapportyx=rapportyx/1.5
183         if rap lt 1./6. and rap ge 1./7. then rapportyx=rapportyx/2.
184         if rap lt 1./7. and rap ge 1./8. then rapportyx=rapportyx/2.5
185         if rap lt 1./8. then rapportyx=rapportyx*3.
186      endif
187   endelse
188;------------------------------------------------------------
189; in the case where we do a Landscape:
190;------------------------------------------------------------
191   if key_portrait eq 0 then begin       
192      if keyword_set(rempli) then begin
193         xs=big
194         ys=small
195      endif else begin
196         if rapportyx le rapportmax then begin
197            xs=big
198            ys=1.*(big-marge[0]-marge[1])*rapportyx+marge[2]+marge[3]
199            if ys gt small then begin
200               xs=1.*(small-marge[2]-marge[3])/rapportyx+marge[0]+marge[1]
201               ys=small
202            endif
203         endif else begin
204            xs=1.*(small-marge[2]-marge[3])/rapportyx+marge[0]+marge[1]
205            ys=small
206            if xs gt big then begin
207               xs=big
208               ys=1.*(big-marge[0]-marge[1])*rapportyx+marge[2]+marge[3]
209            endif
210         endelse
211      endelse
212      xoff=1.*(small-ys)/2.+smalldraw[1]
213      yoff=1.*(big-xs)/2.+xs+mapgsz-smalldraw[2]
214      a=1.*(mapgsz-yoff)/mapgsz
215      b=1.*xoff/mipgsz
216      c=a+1.*xs/mapgsz
217      d=b+1.*ys/mipgsz
218   endif $
219;------------------------------------------------------------
220; In the case where we do a portrait:
221;------------------------------------------------------------
222   else begin       
223      if keyword_set(rempli) then begin
224         xs=small
225         ys=big
226      endif else begin
227         if rapportyx le rapportmax then begin
228            xs=small
229            ys=1.*(small-marge[0]-marge[1])*rapportyx+marge[2]+marge[3]
230            if ys gt big then begin
231               xs=1.*(big-marge[2]-marge[3])/rapportyx+marge[0]+marge[1]
232               ys=big
233            endif
234         endif else begin
235            xs=1.*(big-marge[2]-marge[3])/rapportyx+marge[0]+marge[1]
236            ys=big
237            if xs gt small then begin
238               xs=small
239               ys=1.*(small-marge[0]-marge[1])*rapportyx+marge[2]+marge[3]
240            endif
241         endelse
242      endelse
243      xoff=1.*(small-xs)/2.+smalldraw[0]
244      yoff=1.*(big-ys)/2.+smalldraw[1]
245      a=1.*xoff/mipgsz
246      b=1.*yoff/mapgsz
247      c=a+1.*xs/mipgsz
248      d=b+1.*ys/mapgsz
249      xset = xoff
250      yset = yoff
251   endelse
252;------------------------------------------------------------
253   bas=mapgsz*(1-key_portrait)+mipgsz*key_portrait
254   cote=mipgsz*(1-key_portrait)+mapgsz*key_portrait
255   posfenetre=[a,b,c,d]+[ marge[0]/bas, marge[2]/cote $
256                          ,-marge[1]/bas,-marge[3]/cote ]
257   posbar=[a,b,c,d]+[ margebar[0]/bas, margebar[2]/cote $
258                      ,-margebar[1]/bas,(-ys+margebar[3])/cote ]
259;------------------------------------------------------------
260   if keyword_set(key_performance) THEN print, 'temps calibre', systime(1)-tempsun
261
262  IF NOT keyword_set(key_forgetold) THEN BEGIN
263   @updateold
264  ENDIF
265 
266   return
267end
Note: See TracBrowser for help on using the repository browser.