DeviceGraphicsContext.st
branchjv
changeset 7071 4939fcb844d6
parent 7033 91e900cc092a
parent 7066 ac2d03dac697
child 7149 eb604cc734e9
--- a/DeviceGraphicsContext.st	Thu Oct 29 06:54:23 2015 +0000
+++ b/DeviceGraphicsContext.st	Mon Nov 16 13:35:11 2015 +0000
@@ -1,5 +1,3 @@
-"{ Encoding: utf8 }"
-
 "
  COPYRIGHT (c) 1992 by Claus Gittinger
 	      All Rights Reserved
@@ -177,17 +175,17 @@
     parents := Array with:anId address.
 
     [
-	newChildren := Set new.
-	Lobby unregisterAllForWhichHandle:[:handle |
-	    |parentId|
-
-	    (handle notNil
-		and:[handle device == aDevice
-		and:[(parentId := handle parentId) notNil
-		and:[parents includes:parentId]]]
-	    ) ifTrue:[newChildren add:handle id. true] ifFalse:[false]
-	].
-	parents := newChildren.
+        newChildren := Set new.
+        Lobby unregisterAllForWhichHandle:[:handle |
+            |parentId|
+
+            (handle notNil
+                and:[handle device == aDevice
+                and:[(parentId := handle parentId) notNil
+                and:[parents includes:parentId]]]
+            ) ifTrue:[newChildren add:handle id. true] ifFalse:[false]
+        ].
+        parents := newChildren.
     ] doWhile:[parents notEmpty].
 !
 
@@ -562,11 +560,39 @@
 !
 
 deviceClippingRectangle
-    <resource: #obsolete>
-    "get the clipping rectangle for drawing (in device coordinates);
-     a nil clipping rectangle means: no clipping (i.e. whole view is drawable - incl. margins)"
-
-    ^ clipRect
+    "answer the clipping rectangle for drawing in device coordinates, or nil."
+
+    |x y w h transformedRectangle|
+
+    (clipRect isNil or:[transformation isNil]) ifTrue:[
+        ^ clipRect.
+    ].
+
+    transformedRectangle := transformation transformRectangle:clipRect.
+
+    x := transformedRectangle left.
+    y := transformedRectangle top.
+    w := transformedRectangle width + 1.
+    h := transformedRectangle height + 1.
+
+    (x class == SmallInteger) ifFalse:[
+        w := w + (x - x truncated).
+        x := x truncated
+    ].
+    (y class == SmallInteger) ifFalse:[
+        h := h + (y - y truncated).
+        y := y truncated
+    ].
+    (w class == SmallInteger) ifFalse:[
+        w := w ceiling.
+    ].
+    (h class == SmallInteger) ifFalse:[
+        h := h ceiling.
+    ].
+    w := w max:0.
+    h := h max:0.
+
+    ^ Rectangle left:x top:y width:w height:h
 !
 
 deviceClippingRectangle:aRectangleOrNil
@@ -1686,13 +1712,13 @@
      Assuming that device can only draw in device colors, we have to handle
      the case where paint and/or bgPaint are dithered colors or images."
 
-    (aString isString not or:[aString isText]) ifTrue:[
-	"
-	 hook for non-strings (i.e. attributed text)
-	 that 'thing' should know how to display itself ...
-	"
-	aString displayOpaqueOn:self x:x y:y.
-	^ self
+    aString isPlainString ifFalse:[
+        "
+         hook for non-strings (i.e. attributed text)
+         that 'thing' should know how to display itself ...
+        "
+        aString displayOpaqueOn:self x:x y:y.
+        ^ self
     ].
 
     self displayOpaqueString:aString from:1 to:(aString size) x:x y:y
@@ -2969,7 +2995,7 @@
     "Modified: 22.4.1997 / 21:44:10 / cg"
 !
 
-displayDeviceOpaqueString:aStringArg from:index1 to:index2 in:font x:x y:y
+displayDeviceOpaqueString:aString from:index1 to:index2 in:font x:x y:y
     "draw a substring at the coordinate x/y - draw foreground pixels in
      paint-color and background pixels in bgPaint-color.
      Assuming that device can only draw in device colors, we have to handle
@@ -2977,7 +3003,7 @@
      No translation or scaling is done."
 
     |easy w h savedPaint fgId bgId allColor allBits noColor
-     id bgForm fgForm tmpForm maskForm dx dy pX pY fontUsed aString
+     id bgForm fgForm tmpForm maskForm dx dy pX pY fontUsed s
      deviceDepth fontsEncoding ascent|
 
     "
@@ -2985,34 +3011,22 @@
      this is a non-opaque draw
     "
     bgPaint isNil ifTrue:[
-        self displayDeviceString:aStringArg from:index1 to:index2 x:x y:y.
+        self displayDeviceString:aString from:index1 to:index2 x:x y:y.
         ^ self
     ].
 
-    (aStringArg isString not or:[aStringArg isText]) ifTrue:[
+    aString isPlainString ifFalse:[
         "
          hook for non-strings (i.e. attributed text)
          that 'thing' should know how to display itself ...
         "
-        aStringArg displayOpaqueOn:self x:x y:y from:index1 to:index2.
+        aString displayOpaqueOn:self x:x y:y from:index1 to:index2.
         ^ self
     ].
 
     pX := x rounded.
     pY := y rounded.
 
-    aString := aStringArg.
-    fontsEncoding := font encoding.
-    (characterEncoding ~~ fontsEncoding) ifTrue:[
-        [
-            aString := CharacterEncoder encodeString:aString from:characterEncoding into:fontsEncoding.
-        ] on:CharacterEncoderError do:[:ex|
-            "substitute a default value for codes that cannot be represented
-             in the new character set"
-            ex proceedWith:ex defaultValue.
-        ].
-    ].
-
     font isAlienFont ifTrue:[
         "
          hook for alien fonts
@@ -3026,7 +3040,20 @@
         self initGC
     ].
 
+
+    s := aString.
     fontUsed := font onDevice:device.
+    fontsEncoding := fontUsed encoding.
+    (characterEncoding ~~ fontsEncoding) ifTrue:[
+        [
+            s := CharacterEncoder encodeString:s from:characterEncoding into:fontsEncoding.
+        ] on:CharacterEncoderError do:[:ex|
+            "substitute a default value for codes that cannot be represented
+             in the new character set"
+            ex proceedWith:ex defaultValue.
+        ].
+    ].
+
     id := fontUsed fontId.
     id isNil ifTrue:[
         "this should not happen, since #onDevice tries replacement fonts"
@@ -3064,11 +3091,11 @@
         device setForeground:fgId background:bgId in:gcId.
         foreground := paint.
         background := bgPaint.
-        device displayOpaqueString:aString from:index1 to:index2 x:pX y:pY in:drawableId with:gcId.
+        device displayOpaqueString:s from:index1 to:index2 x:pX y:pY in:drawableId with:gcId.
         ^ self
     ].
 
-    w := fontUsed widthOf:aString from:index1 to:index2.
+    w := fontUsed widthOf:s from:index1 to:index2.
     h := fontUsed height.
     ascent := fontUsed ascent.
 
@@ -3084,7 +3111,7 @@
         "
          then draw using fgPaint (which is a real color)
         "
-        device displayString:aString from:index1 to:index2 x:pX y:pY in:drawableId with:gcId.
+        device displayString:s from:index1 to:index2 x:pX y:pY in:drawableId with:gcId.
         ^ self
     ].
 
@@ -3161,7 +3188,7 @@
             ].
         ].
 
-        device displayString:aString from:index1 to:index2 x:pX y:pY in:drawableId with:gcId.
+        device displayString:s from:index1 to:index2 x:pX y:pY in:drawableId with:gcId.
         ^ self.
     ].
 
@@ -3202,14 +3229,14 @@
     bgForm font:fontUsed.
     bgForm paint:noColor on:allColor.
     bgForm function:#and.
-    bgForm displayString:aString from:index1 to:index2 x:0 y:ascent.
+    bgForm displayString:s from:index1 to:index2 x:0 y:ascent.
 
     "
      stamp-out foreground
     "
     maskForm font:fontUsed.
     maskForm paint:allColor on:noColor.
-    maskForm displayOpaqueString:aString from:index1 to:index2 x:0 y:ascent.
+    maskForm displayOpaqueString:s from:index1 to:index2 x:0 y:ascent.
 
     fgForm function:#and.
     fgForm copyFrom:maskForm x:0 y:0 toX:0 y:0 width:w height:h.
@@ -3275,32 +3302,42 @@
     self displayDeviceOpaqueString:aString from:1 to:(aString size) in:font x:x y:y
 !
 
-displayDeviceString:aStringArg from:index1 to:index2 in:font x:x y:y
+displayDeviceString:aString from:index1 to:index2 in:font x:x y:y
     "draw a substring at the coordinate x/y -
      draw foreground-pixels only (in current paint-color), leaving background as-is.
      No translation or scaling is done"
 
-    |id pX pY fontUsed aString fontsEncoding|
+    |id pX pY fontUsed s fontsEncoding|
 
     "
      hook for non-strings (i.e. attributed text)
     "
-    (aStringArg isString not or:[aStringArg isText]) ifTrue:[
-        ^ aStringArg displayOn:self x:x y:y from:index1 to:index2
+    aString isPlainString ifFalse:[
+        ^ aString displayOn:self x:x y:y from:index1 to:index2
     ].
 
     pX := x rounded.
     pY := y rounded.
 
+    font isAlienFont ifTrue:[
+        "
+         hook for alien fonts
+         that 'font' should know how to display the string ...
+        "
+        font displayOpaqueString:aString from:index1 to:index2 x:pX y:pY in:self.
+        ^ self
+    ].
+
     gcId isNil ifTrue:[
         self initGC
     ].
 
-    aString := aStringArg.
-    fontsEncoding := font encoding.
+    s := aString.
+    fontUsed := font onDevice:device.
+    fontsEncoding := fontUsed encoding.
     (characterEncoding ~~ fontsEncoding) ifTrue:[
         [
-            aString := CharacterEncoder encodeString:aString from:characterEncoding into:fontsEncoding.
+            s := CharacterEncoder encodeString:s from:characterEncoding into:fontsEncoding.
         ] on:CharacterEncoderError do:[:ex|
             "substitute a default value for codes that cannot be represented
              in the new character set"
@@ -3308,16 +3345,6 @@
         ].
     ].
 
-    font isAlienFont ifTrue:[
-        "
-         hook for alien fonts
-         that 'font' should know how to display the string ...
-        "
-        font displayString:aString from:index1 to:index2 x:pX y:pY in:self.
-        ^ self
-    ].
-
-    fontUsed := font onDevice:device.
     id := fontUsed fontId.
     id isNil ifTrue:[
         "this should not happen, since #onDevice tries replacement fonts"
@@ -3328,7 +3355,7 @@
             device setFont:id in:gcId.
             deviceFont := fontUsed
         ].
-        device displayString:aString from:index1 to:index2 x:pX y:pY in:drawableId with:gcId
+        device displayString:s from:index1 to:index2 x:pX y:pY in:drawableId with:gcId
     ]
 
     "Modified: 1.7.1997 / 17:08:48 / cg"
@@ -4276,4 +4303,5 @@
     ^ '$Header$'
 ! !
 
+
 DeviceGraphicsContext initialize!