partial fix for angleDrawing of non-strings (with labelAndIcons)
authorClaus Gittinger <cg@exept.de>
Thu, 29 Jan 1998 13:23:56 +0100
changeset 2032 cc11a2c3918d
parent 2031 d369d38213cf
child 2033 dad8f0ee02f4
partial fix for angleDrawing of non-strings (with labelAndIcons)
GC.st
GraphicsContext.st
--- a/GC.st	Thu Jan 29 13:12:42 1998 +0100
+++ b/GC.st	Thu Jan 29 13:23:56 1998 +0100
@@ -1557,114 +1557,144 @@
      Drawing is done by first drawing the string into a temporary bitmap, 
      which is rotated and finally drawn as usual.
      NOTICE: due to the rotation of the temporary bitmap, this is a slow
-	     operation - not to be used with cillions of strings ..."
+             operation - not to be used with cillions of strings ...
+     CAVEAT: if the string is not a real string (i.e. a LabelAndIcon),
+             this can (currently) only be done opaque"
 
     |angle tempForm tempImage w h asc desc a xN yN p r nBL nTL nB a1 a2
      dX dY sin cos m|
 
     angle := drawAngle.
     angle >= 360 ifTrue:[
-	angle := angle - (((angle // 360)) * 360)
+        angle := angle - (((angle // 360)) * 360)
     ] ifFalse:[
-	angle < 0 ifTrue:[
-	    angle := angle - (((angle // 360)) * 360).
-	    angle := angle + 360
-	].
+        angle < 0 ifTrue:[
+            angle := angle - (((angle // 360)) * 360).
+            angle := angle + 360
+        ].
     ].
 
     angle = 0 ifTrue:[
-	opaque ifTrue:[
-	    ^ self displayOpaqueString:aString x:x y:y
-	].
-	^ self displayString:aString x:x y:y
+        opaque ifTrue:[
+            ^ self displayOpaqueString:aString x:x y:y
+        ].
+        ^ self displayString:aString x:x y:y
     ].
 
-    w := font widthOf:aString.
-    h := font height.
-    asc := font ascent.
-    desc := h - asc.
+    aString isString ifTrue:[
+        "/ a real string;
+        "/ do it in a monochrome form (for speed)
+
+        w := font widthOf:aString.
+        h := font height.
+        asc := font ascent.
+        desc := h - asc.
 
-    tempForm := Form 
-		width:w 
-		height:h
-		on:device.
+        tempForm := Form 
+                    width:w 
+                    height:h
+                    on:device.
+
+        tempForm clear.
+        tempForm font:font.
+        tempForm displayString:aString x:0 y:asc.
 
-    tempForm clear.
-    tempForm font:font.
-    tempForm displayString:aString x:0 y:asc.
+        tempImage := (Depth1Image fromForm:tempForm) rotated:angle.
+    ] ifFalse:[
+        "/ something wierd (labelAndIcon ..)
+        "/ do it in a deep form.
+        "/ CAVEAT: this can only be done opaque ...
+
+        w := aString widthOn:self.
+        h := aString heightOn:self.
+        asc := font ascent.
+        desc := h - asc.
 
-    tempImage := (Depth1Image fromForm:tempForm) rotated:angle.
+        tempForm := Form 
+                    width:w 
+                    height:h
+                    depth:(device depth)
+                    on:device.
 
+        tempForm paint:bgPaint.
+        tempForm fillRectangleX:0 y:0 width:w height:h.
+        tempForm paint:paint on:bgPaint.
+        tempForm font:font.
+        aString displayOn:tempForm x:0 y:asc opaque:true.
+        tempImage := ((Image implementorForDepth:(device depth)) fromForm:tempForm) rotated:angle.
+    ].
     opaque ifTrue:[
-	m := ImageMask width:w height:h.
-	m bits:(ByteArray new:(h * m bytesPerRow) withAll:16rFF).
-	m := m rotated:angle
+        m := ImageMask width:w height:h.
+        m bits:(ByteArray new:(h * m bytesPerRow) withAll:16rFF).
+        m := m rotated:angle
     ].
 
+    "/ compute final position of rotated form
     "/ adjust position for baseline.
 
     angle = 90 ifTrue:[
-	xN := x - desc. 
-	yN := y.
+        xN := x - desc. 
+        yN := y.
     ] ifFalse:[
-	angle = 180 ifTrue:[
-	    xN := x - w.
-	    yN := y - desc "+ h - asc".
-	] ifFalse:[
-	    angle = 270 ifTrue:[
-		xN := x - asc.
-		yN := y - w.
-	    ] ifFalse:[
-		"/ sigh: since the new image has different dimensions,
-		"/ the computation is somewhat more difficult here.
-		"/ remember: the image has been rotated around its center,
-		"/ then shifted towards the top-left origin.
+        angle = 180 ifTrue:[
+            xN := x - w.
+            yN := y - desc "+ h - asc".
+        ] ifFalse:[
+            angle = 270 ifTrue:[
+                xN := x - asc.
+                yN := y - w.
+            ] ifFalse:[
+                "/ sigh: since the new image has different dimensions,
+                "/ the computation is somewhat more difficult here.
+                "/ remember: the image has been rotated around its center,
+                "/ then shifted towards the top-left origin.
 
-		p := (w@h) / 2.
-		r := p r.
-		a := p angle.
-		sin := angle degreesToRadians sin.
-		cos := angle degreesToRadians cos.
+                p := (w@h) / 2.
+                r := p r.
+                a := p angle.
+                sin := angle degreesToRadians sin.
+                cos := angle degreesToRadians cos.
 
-		angle < 90 ifTrue:[
-		    dX := desc * sin.
-		    dY := asc * cos.
-		    xN := x - dX.
-		    yN := y - dY
-		] ifFalse:[
-		    angle < 180 ifTrue:[
-			dX := asc * sin.
-			dY := desc * cos.
-			xN := x + dX - (tempImage width).
-			yN := y + dY.
-		    ] ifFalse:[
-			angle < 270 ifTrue:[
-			    dX := desc * sin.
-			    dY := asc * cos.
-			    xN := x - dX - (tempImage width).
-			    yN := y - dY - (tempImage height)
-			] ifFalse:[
-			    dX := asc * sin.
-			    dY := desc * cos.
-			    xN := x + dX.
-			    yN := y + dY - (tempImage height).
-			]
-		    ]
-		].
+                angle < 90 ifTrue:[
+                    dX := desc * sin.
+                    dY := asc * cos.
+                    xN := x - dX.
+                    yN := y - dY
+                ] ifFalse:[
+                    angle < 180 ifTrue:[
+                        dX := asc * sin.
+                        dY := desc * cos.
+                        xN := x + dX - (tempImage width).
+                        yN := y + dY.
+                    ] ifFalse:[
+                        angle < 270 ifTrue:[
+                            dX := desc * sin.
+                            dY := asc * cos.
+                            xN := x - dX - (tempImage width).
+                            yN := y - dY - (tempImage height)
+                        ] ifFalse:[
+                            dX := asc * sin.
+                            dY := desc * cos.
+                            xN := x + dX.
+                            yN := y + dY - (tempImage height).
+                        ]
+                    ]
+                ].
 
-		tempImage mask:nil.
-	    ]
-	].
+                tempImage mask:nil.
+            ]
+        ].
     ].
+
     opaque ifTrue:[
-	p := paint.
-	self paint:bgPaint.
-	self displayForm:m x:xN y:yN.
-	self paint:p.
+        p := paint.
+        self paint:bgPaint.
+        self displayForm:m x:xN y:yN.
+        self paint:p.
     ].
     self displayForm:tempImage x:xN y:yN.
 
-    "Modified: 24.4.1997 / 12:48:42 / cg"
+    "Modified: / 29.1.1998 / 13:23:23 / cg"
 !
 
 fillArcX:x y:y w:w h:h from:startAngle angle:angle
@@ -1975,6 +2005,6 @@
 !GraphicsContext class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Attic/GC.st,v 1.64 1998-01-29 12:11:55 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Attic/GC.st,v 1.65 1998-01-29 12:23:56 cg Exp $'
 ! !
 GraphicsContext initialize!
--- a/GraphicsContext.st	Thu Jan 29 13:12:42 1998 +0100
+++ b/GraphicsContext.st	Thu Jan 29 13:23:56 1998 +0100
@@ -1557,114 +1557,144 @@
      Drawing is done by first drawing the string into a temporary bitmap, 
      which is rotated and finally drawn as usual.
      NOTICE: due to the rotation of the temporary bitmap, this is a slow
-	     operation - not to be used with cillions of strings ..."
+             operation - not to be used with cillions of strings ...
+     CAVEAT: if the string is not a real string (i.e. a LabelAndIcon),
+             this can (currently) only be done opaque"
 
     |angle tempForm tempImage w h asc desc a xN yN p r nBL nTL nB a1 a2
      dX dY sin cos m|
 
     angle := drawAngle.
     angle >= 360 ifTrue:[
-	angle := angle - (((angle // 360)) * 360)
+        angle := angle - (((angle // 360)) * 360)
     ] ifFalse:[
-	angle < 0 ifTrue:[
-	    angle := angle - (((angle // 360)) * 360).
-	    angle := angle + 360
-	].
+        angle < 0 ifTrue:[
+            angle := angle - (((angle // 360)) * 360).
+            angle := angle + 360
+        ].
     ].
 
     angle = 0 ifTrue:[
-	opaque ifTrue:[
-	    ^ self displayOpaqueString:aString x:x y:y
-	].
-	^ self displayString:aString x:x y:y
+        opaque ifTrue:[
+            ^ self displayOpaqueString:aString x:x y:y
+        ].
+        ^ self displayString:aString x:x y:y
     ].
 
-    w := font widthOf:aString.
-    h := font height.
-    asc := font ascent.
-    desc := h - asc.
+    aString isString ifTrue:[
+        "/ a real string;
+        "/ do it in a monochrome form (for speed)
+
+        w := font widthOf:aString.
+        h := font height.
+        asc := font ascent.
+        desc := h - asc.
 
-    tempForm := Form 
-		width:w 
-		height:h
-		on:device.
+        tempForm := Form 
+                    width:w 
+                    height:h
+                    on:device.
+
+        tempForm clear.
+        tempForm font:font.
+        tempForm displayString:aString x:0 y:asc.
 
-    tempForm clear.
-    tempForm font:font.
-    tempForm displayString:aString x:0 y:asc.
+        tempImage := (Depth1Image fromForm:tempForm) rotated:angle.
+    ] ifFalse:[
+        "/ something wierd (labelAndIcon ..)
+        "/ do it in a deep form.
+        "/ CAVEAT: this can only be done opaque ...
+
+        w := aString widthOn:self.
+        h := aString heightOn:self.
+        asc := font ascent.
+        desc := h - asc.
 
-    tempImage := (Depth1Image fromForm:tempForm) rotated:angle.
+        tempForm := Form 
+                    width:w 
+                    height:h
+                    depth:(device depth)
+                    on:device.
 
+        tempForm paint:bgPaint.
+        tempForm fillRectangleX:0 y:0 width:w height:h.
+        tempForm paint:paint on:bgPaint.
+        tempForm font:font.
+        aString displayOn:tempForm x:0 y:asc opaque:true.
+        tempImage := ((Image implementorForDepth:(device depth)) fromForm:tempForm) rotated:angle.
+    ].
     opaque ifTrue:[
-	m := ImageMask width:w height:h.
-	m bits:(ByteArray new:(h * m bytesPerRow) withAll:16rFF).
-	m := m rotated:angle
+        m := ImageMask width:w height:h.
+        m bits:(ByteArray new:(h * m bytesPerRow) withAll:16rFF).
+        m := m rotated:angle
     ].
 
+    "/ compute final position of rotated form
     "/ adjust position for baseline.
 
     angle = 90 ifTrue:[
-	xN := x - desc. 
-	yN := y.
+        xN := x - desc. 
+        yN := y.
     ] ifFalse:[
-	angle = 180 ifTrue:[
-	    xN := x - w.
-	    yN := y - desc "+ h - asc".
-	] ifFalse:[
-	    angle = 270 ifTrue:[
-		xN := x - asc.
-		yN := y - w.
-	    ] ifFalse:[
-		"/ sigh: since the new image has different dimensions,
-		"/ the computation is somewhat more difficult here.
-		"/ remember: the image has been rotated around its center,
-		"/ then shifted towards the top-left origin.
+        angle = 180 ifTrue:[
+            xN := x - w.
+            yN := y - desc "+ h - asc".
+        ] ifFalse:[
+            angle = 270 ifTrue:[
+                xN := x - asc.
+                yN := y - w.
+            ] ifFalse:[
+                "/ sigh: since the new image has different dimensions,
+                "/ the computation is somewhat more difficult here.
+                "/ remember: the image has been rotated around its center,
+                "/ then shifted towards the top-left origin.
 
-		p := (w@h) / 2.
-		r := p r.
-		a := p angle.
-		sin := angle degreesToRadians sin.
-		cos := angle degreesToRadians cos.
+                p := (w@h) / 2.
+                r := p r.
+                a := p angle.
+                sin := angle degreesToRadians sin.
+                cos := angle degreesToRadians cos.
 
-		angle < 90 ifTrue:[
-		    dX := desc * sin.
-		    dY := asc * cos.
-		    xN := x - dX.
-		    yN := y - dY
-		] ifFalse:[
-		    angle < 180 ifTrue:[
-			dX := asc * sin.
-			dY := desc * cos.
-			xN := x + dX - (tempImage width).
-			yN := y + dY.
-		    ] ifFalse:[
-			angle < 270 ifTrue:[
-			    dX := desc * sin.
-			    dY := asc * cos.
-			    xN := x - dX - (tempImage width).
-			    yN := y - dY - (tempImage height)
-			] ifFalse:[
-			    dX := asc * sin.
-			    dY := desc * cos.
-			    xN := x + dX.
-			    yN := y + dY - (tempImage height).
-			]
-		    ]
-		].
+                angle < 90 ifTrue:[
+                    dX := desc * sin.
+                    dY := asc * cos.
+                    xN := x - dX.
+                    yN := y - dY
+                ] ifFalse:[
+                    angle < 180 ifTrue:[
+                        dX := asc * sin.
+                        dY := desc * cos.
+                        xN := x + dX - (tempImage width).
+                        yN := y + dY.
+                    ] ifFalse:[
+                        angle < 270 ifTrue:[
+                            dX := desc * sin.
+                            dY := asc * cos.
+                            xN := x - dX - (tempImage width).
+                            yN := y - dY - (tempImage height)
+                        ] ifFalse:[
+                            dX := asc * sin.
+                            dY := desc * cos.
+                            xN := x + dX.
+                            yN := y + dY - (tempImage height).
+                        ]
+                    ]
+                ].
 
-		tempImage mask:nil.
-	    ]
-	].
+                tempImage mask:nil.
+            ]
+        ].
     ].
+
     opaque ifTrue:[
-	p := paint.
-	self paint:bgPaint.
-	self displayForm:m x:xN y:yN.
-	self paint:p.
+        p := paint.
+        self paint:bgPaint.
+        self displayForm:m x:xN y:yN.
+        self paint:p.
     ].
     self displayForm:tempImage x:xN y:yN.
 
-    "Modified: 24.4.1997 / 12:48:42 / cg"
+    "Modified: / 29.1.1998 / 13:23:23 / cg"
 !
 
 fillArcX:x y:y w:w h:h from:startAngle angle:angle
@@ -1975,6 +2005,6 @@
 !GraphicsContext class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/GraphicsContext.st,v 1.64 1998-01-29 12:11:55 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/GraphicsContext.st,v 1.65 1998-01-29 12:23:56 cg Exp $'
 ! !
 GraphicsContext initialize!