0
|
1 |
"
|
4
|
2 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
24
|
3 |
All Rights Reserved
|
0
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
View subclass:#Ruler
|
24
|
14 |
instanceVariableNames:'fgColor metric paperWidth paperHeight'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Interactors'
|
0
|
18 |
!
|
|
19 |
|
|
20 |
Ruler comment:'
|
4
|
21 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
24
|
22 |
All Rights Reserved
|
0
|
23 |
|
|
24 |
a Ruler for page layout.
|
|
25 |
|
24
|
26 |
$Header: /cvs/stx/stx/libwidg2/Ruler.st,v 1.7 1994-10-10 03:13:35 claus Exp $
|
0
|
27 |
|
|
28 |
written oct 91 by claus
|
|
29 |
'!
|
|
30 |
|
|
31 |
!Ruler methodsFor:'accessing'!
|
|
32 |
|
|
33 |
metric:aSymbol
|
24
|
34 |
"set the metric. The argument may be either #inch or #mm"
|
|
35 |
|
|
36 |
aSymbol ~~ metric ifTrue:[
|
|
37 |
metric := aSymbol.
|
|
38 |
shown ifTrue:[
|
|
39 |
self redraw
|
|
40 |
]
|
|
41 |
]
|
|
42 |
!
|
|
43 |
|
|
44 |
paperWidthInch:inches
|
|
45 |
"set the width of the document"
|
0
|
46 |
|
24
|
47 |
paperWidth := inches.
|
0
|
48 |
shown ifTrue:[
|
24
|
49 |
self redraw
|
|
50 |
]
|
|
51 |
!
|
|
52 |
|
|
53 |
paperWidthMM:millis
|
|
54 |
"set the width of the document"
|
|
55 |
|
|
56 |
paperWidth := self millimeterToInch:millis.
|
|
57 |
shown ifTrue:[
|
|
58 |
self redraw
|
0
|
59 |
]
|
|
60 |
! !
|
|
61 |
|
|
62 |
!Ruler methodsFor:'redrawing'!
|
|
63 |
|
|
64 |
redraw
|
|
65 |
"redraw scale"
|
|
66 |
|
|
67 |
|x pixelPerMM pixelPerInch mod pos shortLen veryShortLen longLen charY
|
6
|
68 |
top paperWidthMM paperWidthPixel xOrigin labelRight marg|
|
0
|
69 |
|
24
|
70 |
shown ifFalse:[^ self].
|
|
71 |
|
|
72 |
"/ self fill:viewBackground.
|
|
73 |
self clear.
|
0
|
74 |
|
6
|
75 |
xOrigin := viewOrigin x.
|
|
76 |
|
0
|
77 |
paperWidthPixel := (self inchToPixel:paperWidth) rounded.
|
6
|
78 |
(xOrigin + width > paperWidthPixel) ifTrue:[
|
24
|
79 |
self paint:(Color darkGrey).
|
|
80 |
self fillRectangleX:paperWidthPixel - xOrigin y:0
|
|
81 |
width:(width - (paperWidthPixel - xOrigin)) height:height.
|
|
82 |
self paint:fgColor.
|
|
83 |
self displayLineFromX:paperWidthPixel - xOrigin y:0
|
|
84 |
toX:paperWidthPixel - xOrigin y:height
|
0
|
85 |
].
|
|
86 |
|
|
87 |
self paint:fgColor.
|
|
88 |
|
|
89 |
top := height - font height - font ascent.
|
|
90 |
longLen := font height.
|
|
91 |
shortLen := longLen // 2.
|
|
92 |
charY := top + (font ascent) + shortLen.
|
|
93 |
mod := 1.
|
6
|
94 |
marg := 3. "character shift"
|
0
|
95 |
|
|
96 |
(metric == #mm) ifTrue:[
|
24
|
97 |
"centimeter - long blibs every centimeter; short ones every half"
|
0
|
98 |
|
24
|
99 |
paperWidthMM := self inchToMillimeter:paperWidth.
|
|
100 |
pixelPerMM := self millimeterToPixel:1.
|
|
101 |
pos := 5.
|
|
102 |
labelRight := marg + (font widthOf:'cm').
|
6
|
103 |
|
24
|
104 |
x := (pixelPerMM * pos - xOrigin) rounded.
|
|
105 |
[(x < width) and:[pos <= paperWidthMM]] whileTrue:[
|
|
106 |
(mod == 1) ifTrue:[
|
|
107 |
self displayLineFromX:x y:top
|
|
108 |
toX:x y:(top + shortLen)
|
|
109 |
] ifFalse:[
|
|
110 |
x < labelRight ifFalse:[
|
|
111 |
self displayLineFromX:x y:top
|
|
112 |
toX:x y:(top + longLen).
|
|
113 |
self displayString:(pos // 10) printString
|
|
114 |
x:(x + marg)
|
|
115 |
y:charY
|
|
116 |
]
|
|
117 |
].
|
|
118 |
mod := (mod + 1) \\ 2.
|
|
119 |
pos := pos + 5.
|
|
120 |
x := (pixelPerMM * pos - xOrigin) rounded
|
|
121 |
].
|
|
122 |
self displayString:'cm ' x:marg y:charY.
|
0
|
123 |
].
|
|
124 |
(metric == #inch) ifTrue:[
|
24
|
125 |
"inches - long blibs every inch; short ones every half; very
|
|
126 |
short ones every quarter"
|
0
|
127 |
|
24
|
128 |
pixelPerInch := self inchToPixel:1.
|
|
129 |
pos := 0.25.
|
|
130 |
labelRight := marg + (font widthOf:'inch').
|
6
|
131 |
|
24
|
132 |
x := (pixelPerInch * pos - xOrigin) rounded.
|
|
133 |
veryShortLen := longLen // 4.
|
|
134 |
[(x < width) and:[pos <= paperWidth]] whileTrue:[
|
|
135 |
(mod == 0) ifTrue:[
|
|
136 |
x < labelRight ifFalse:[
|
|
137 |
self displayLineFromX:x y:top
|
|
138 |
toX:x y:(top + longLen).
|
|
139 |
self displayString:pos asInteger printString
|
|
140 |
x:(x + marg)
|
|
141 |
y:charY
|
|
142 |
]
|
|
143 |
] ifFalse:[
|
|
144 |
(mod == 2) ifTrue:[
|
|
145 |
self displayLineFromX:x y:top
|
|
146 |
toX:x y:(top + shortLen)
|
|
147 |
] ifFalse:[
|
|
148 |
self displayLineFromX:x y:top
|
|
149 |
toX:x y:(top + veryShortLen)
|
|
150 |
]
|
|
151 |
].
|
|
152 |
mod := (mod + 1) \\ 4.
|
|
153 |
pos := pos + 0.25.
|
|
154 |
x := (pixelPerInch * pos - xOrigin) rounded
|
|
155 |
].
|
|
156 |
self displayString:'inch ' x:marg y:charY.
|
0
|
157 |
].
|
|
158 |
self redrawEdges
|
7
|
159 |
|
0
|
160 |
! !
|
|
161 |
|
|
162 |
!Ruler methodsFor:'initialization'!
|
|
163 |
|
|
164 |
initialize
|
|
165 |
super initialize.
|
|
166 |
|
|
167 |
fgColor := Black.
|
|
168 |
self height:(font height + font descent + font descent).
|
|
169 |
(Language == #english) ifTrue:[
|
24
|
170 |
metric := #inch
|
0
|
171 |
] ifFalse:[
|
24
|
172 |
metric := #mm
|
0
|
173 |
].
|
|
174 |
paperWidth := 8.5.
|
24
|
175 |
paperHeight := 11.
|
0
|
176 |
|
24
|
177 |
"
|
|
178 |
take a smaller font
|
|
179 |
"
|
|
180 |
font := (Font family:(font family)
|
|
181 |
face:(font face)
|
|
182 |
style:(font style)
|
|
183 |
size:8) on:device.
|
|
184 |
|
|
185 |
"
|
|
186 |
Ruler new open
|
|
187 |
"
|
|
188 |
!
|
|
189 |
|
|
190 |
reinitialize
|
|
191 |
super reinitialize.
|
|
192 |
font := font on:device.
|
0
|
193 |
! !
|
|
194 |
|
|
195 |
!Ruler methodsFor:'metric conversions'!
|
|
196 |
|
|
197 |
inchToMillimeter:inches
|
|
198 |
"convert inches to mm"
|
|
199 |
|
|
200 |
^ inches * 25.4
|
|
201 |
!
|
|
202 |
|
|
203 |
inchToPixel:inches
|
|
204 |
"convert inches to screen pixels"
|
|
205 |
|
|
206 |
^ inches * self horizontalPixelPerInch
|
|
207 |
!
|
|
208 |
|
|
209 |
inchToTwip:inches
|
|
210 |
"convert inches to twips"
|
|
211 |
|
|
212 |
^ inches * 1440
|
|
213 |
|
|
214 |
!
|
|
215 |
|
|
216 |
millimeterToPixel:mm
|
|
217 |
"convert mms to screen pixels"
|
|
218 |
|
|
219 |
^ mm * self horizontalPixelPerMillimeter
|
|
220 |
|
|
221 |
!
|
|
222 |
|
|
223 |
millimeterToInch:mm
|
|
224 |
"convert mm to inches"
|
|
225 |
|
|
226 |
^ mm / 25.4
|
|
227 |
!
|
|
228 |
|
|
229 |
pointToTwip:points
|
|
230 |
"convert points to twips"
|
|
231 |
|
|
232 |
^ points * 20
|
|
233 |
!
|
|
234 |
|
|
235 |
twipToInch:twips
|
|
236 |
"convert twips to inches"
|
|
237 |
|
|
238 |
^ twips / 1440.0
|
|
239 |
!
|
|
240 |
|
|
241 |
pixelToInch:pixels
|
|
242 |
"convert pixels to inches"
|
|
243 |
|
|
244 |
^ pixels / self horizontalPixelPerInch
|
|
245 |
!
|
|
246 |
|
|
247 |
twipToPixel:twips
|
|
248 |
"convert twips to screen pixels"
|
|
249 |
|
|
250 |
^ (twips / 1440.0) * self horizontalPixelPerInch
|
|
251 |
|
|
252 |
!
|
|
253 |
|
|
254 |
twipToPoint:twips
|
|
255 |
"convert twips to points"
|
|
256 |
|
|
257 |
^ twips / 20.0
|
|
258 |
! !
|