--- a/Ruler.st Thu Nov 17 15:42:58 1994 +0100
+++ b/Ruler.st Mon Nov 21 17:49:32 1994 +0100
@@ -23,7 +23,7 @@
a Ruler for page layout.
-$Header: /cvs/stx/stx/libwidg2/Ruler.st,v 1.8 1994-11-17 14:42:26 claus Exp $
+$Header: /cvs/stx/stx/libwidg2/Ruler.st,v 1.9 1994-11-21 16:49:32 claus Exp $
written oct 91 by claus
'!
@@ -73,19 +73,26 @@
viewOrigin:origin
super setViewOrigin:origin.
self redraw
+!
+
+widthOfContents
+ ^ (device horizontalPixelPerInch * paperWidth) rounded
+!
+
+heightOfContents
+ ^ (device verticalPixelPerInch * paperHeight) rounded
! !
!Ruler methodsFor:'redrawing'!
redraw
- "redraw scale"
+ "redraw the scale"
|x pixelPerMM pixelPerInch mod pos shortLen veryShortLen longLen charY
top paperWidthMM paperWidthPixel xOrigin labelRight stringRight marg|
shown ifFalse:[^ self].
-"/ self fill:viewBackground.
self clear.
xOrigin := self viewOrigin x.
@@ -116,31 +123,27 @@
paperWidthMM := self inchToMillimeter:paperWidth.
pixelPerMM := (self millimeterToPixel:1) * scale.
pos := 5.
- labelRight := stringRight := marg + (font widthOf:'cm').
+ labelRight := stringRight := marg + (font widthOf:'cm') + 3.
x := (pixelPerMM * pos - xOrigin) rounded.
[(x < width) and:[pos <= paperWidthMM]] whileTrue:[
|l|
- (mod == 1) ifTrue:[
- self displayLineFromX:x y:top
- toX:x y:(top + shortLen)
- ] ifFalse:[
- x < stringRight ifTrue:[
- l := shortLen
- ] ifFalse:[
+ l := shortLen.
+ (mod ~~ 1) ifTrue:[
+ x < stringRight ifFalse:[
l := longLen
].
- self displayLineFromX:x y:top
- toX:x y:(top + l).
+ ].
+ self displayLineFromX:x y:top
+ toX:x y:(top + l).
- x < stringRight ifFalse:[
- self displayString:(pos // 10) printString
- x:(x + marg)
- y:charY.
- stringRight := x + marg
- + (font widthOf:(pos // 10) printString)
- ]
+ ((x < stringRight) or:[mod == 1]) ifFalse:[
+ self displayString:(pos // 10) printString
+ x:(x + marg)
+ y:charY.
+ stringRight := x + marg
+ + (font widthOf:(pos // 10) printString)
].
mod := (mod + 1) \\ 2.
pos := pos + 5.
@@ -154,28 +157,31 @@
pixelPerInch := (self inchToPixel:1) * scale.
pos := 0.25.
- labelRight := marg + (font widthOf:'inch').
+ labelRight := marg + (font widthOf:'inch') + 3.
x := (pixelPerInch * pos - xOrigin) rounded.
veryShortLen := longLen // 4.
[(x < width) and:[pos <= paperWidth]] whileTrue:[
+ |l|
+
+ l := shortLen.
(mod == 0) ifTrue:[
x < labelRight ifFalse:[
- self displayLineFromX:x y:top
- toX:x y:(top + longLen).
- self displayString:pos asInteger printString
- x:(x + marg)
- y:charY
+ l := longLen
]
] ifFalse:[
- (mod == 2) ifTrue:[
- self displayLineFromX:x y:top
- toX:x y:(top + shortLen)
- ] ifFalse:[
- self displayLineFromX:x y:top
- toX:x y:(top + veryShortLen)
+ (mod == 2) ifFalse:[
+ l := veryShortLen
]
].
+ self displayLineFromX:x y:top
+ toX:x y:(top + l).
+
+ (mod == 0 and:[x >= labelRight]) ifTrue:[
+ self displayString:pos asInteger printString
+ x:(x + marg)
+ y:charY
+ ].
mod := (mod + 1) \\ 4.
pos := pos + 0.25.
x := (pixelPerInch * pos - xOrigin) rounded
@@ -193,7 +199,7 @@
fgColor := Black.
bitGravity := #NorthWest.
- self height:(font height + font descent + font descent).
+ self height:(font height + (2 * font descent)).
(Language == #english) ifTrue:[
metric := #inch
] ifFalse:[