#TUNING by cg
authorClaus Gittinger <cg@exept.de>
Fri, 01 Mar 2019 22:02:36 +0100
changeset 6554 f65b459a7d91
parent 6553 1b15add12d92
child 6555 3af24552a8e0
#TUNING by cg class: ListView comment/format in: #xOfCol:inVisibleLine: changed: #colOfX:inVisibleLine:
ListView.st
--- a/ListView.st	Fri Mar 01 16:15:10 2019 +0100
+++ b/ListView.st	Fri Mar 01 22:02:36 2019 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 1989 by Claus Gittinger
 	      All Rights Reserved
@@ -2752,11 +2754,11 @@
 colOfX:x inVisibleLine:visLineNr
     "given a visible lineNr and x-coordinate, return colNr"
 
-    |lineString linePixelWidth xRel runCol posLeft posRight done
-     hasEmphasis oPosRight oPosLeft|
-
-    xRel := x - textStartLeft + viewOrigin x.
-    (xRel <= 0) ifTrue:[^ 1].
+    |lineString linePixelWidth xAbs runCol posLeft posRight done
+     hasEmphasis oPosRight oPosLeft font|
+
+    xAbs := x - textStartLeft + viewOrigin x.
+    (xAbs <= 0) ifTrue:[^ 1].
 
     lineString := self visibleAt:visLineNr.
 
@@ -2765,9 +2767,11 @@
     "
     (fontIsFixedWidth
     and:[lineString isNil or:[lineString hasChangeOfEmphasis not]]) ifTrue:[
-        ^ (xRel // fontWidth) + 1
+        ^ (xAbs // fontWidth) + 1
     ].
 
+    font := gc font.
+    
     "
      for variable fonts, more work is required ...
     "
@@ -2777,13 +2781,13 @@
             linePixelWidth := lineString widthOn:self
         ] ifFalse:[
             lineString := lineString string.
-            linePixelWidth := gc font widthOf:lineString.
+            linePixelWidth := font widthOf:lineString.
         ]
     ] ifFalse:[
         linePixelWidth := 0
     ].
 
-    (linePixelWidth <= xRel) ifTrue:[
+    (linePixelWidth <= xAbs) ifTrue:[
         fontWidth == 0 ifTrue:[
             "
              although this 'cannot happen',
@@ -2791,7 +2795,7 @@
             "
             ^ lineString size
         ].
-        ^ lineString size + ((xRel - linePixelWidth) // fontWidth) + 1
+        ^ lineString size + ((xAbs - linePixelWidth) // fontWidth) + 1
     ].
 
     "/ cannot simply count individual characters,
@@ -2799,7 +2803,7 @@
     "/ use a binary search, initialized with some guess.
 
     "/ a guess: take some 'average' character's width and compute an initial guess
-    runCol := x // (gc font widthOf:'e').
+    runCol := x // (font widthOf:'e').
     runCol := runCol min:lineString size.
 
 "/    runCol := lineString size // 2.
@@ -2809,37 +2813,37 @@
         posLeft := (lineString copyFrom:1 to:(runCol - 1)) widthOn:self.
         posRight := (lineString copyFrom:1 to:runCol) widthOn:self.
     ] ifFalse:[
-        posLeft := gc font widthOf:lineString from:1 to:(runCol - 1).
-        posRight := gc font widthOf:lineString from:1 to:runCol.
+        posLeft := font widthOf:lineString from:1 to:(runCol - 1).
+        posRight := font widthOf:lineString from:1 to:runCol.
     ].
 
-    done := (posLeft <= xRel) and:[posRight > xRel].
+    done := (posLeft <= xAbs) and:[posRight > xAbs].
 
     [done] whileFalse:[
         oPosRight := posRight.
         oPosLeft := posLeft.
 
-        (posRight <= xRel) ifTrue:[
+        (posRight <= xAbs) ifTrue:[
             runCol := runCol + 1.
             posLeft := posRight.
             hasEmphasis ifTrue:[
                 posRight := (lineString copyFrom:1 to:runCol) widthOn:self.
             ] ifFalse:[
-                posRight := gc font widthOf:lineString from:1 to:runCol
+                posRight := font widthOf:lineString from:1 to:runCol
             ]
         ] ifFalse:[
-            (posLeft > xRel) ifTrue:[
+            (posLeft > xAbs) ifTrue:[
                 runCol := runCol - 1.
                 (runCol == 0) ifTrue:[^ 0].
                 posRight := posLeft.
                 hasEmphasis ifTrue:[
                     posLeft := (lineString copyFrom:1 to:(runCol - 1)) widthOn:self.
                 ] ifFalse:[
-                    posLeft := gc font widthOf:lineString from:1 to:(runCol - 1)
+                    posLeft := font widthOf:lineString from:1 to:(runCol - 1)
                 ]
             ]
         ].
-        done := (posLeft <= xRel) and:[posRight > xRel].
+        done := (posLeft <= xAbs) and:[posRight > xAbs].
 "234567890123456789012345678901234567890"
         ((oPosRight == posRight) and:[oPosLeft == posLeft]) ifTrue:[
             "/ paranoia: just in case there are unprintable characters
@@ -2855,6 +2859,7 @@
 
     "Modified: / 25-04-2011 / 11:26:58 / cg"
     "Modified: / 02-05-2011 / 14:08:54 / sr"
+    "Modified: / 01-03-2019 / 22:01:30 / Claus Gittinger"
 !
 
 computeNumberOfLinesShown
@@ -3439,39 +3444,39 @@
     |line lineSize tcol lText|
 
     col == 1 ifTrue:[
-	lText := 0
+        lText := 0
     ] ifFalse:[
-	tcol := col - 1.
-
-	line := self visibleAt:visLineNr.
-	(fontIsFixedWidth
-	and:[line isNil or:[line isSingleByteString]])
-	ifTrue:[
-	    lText := (tcol * fontWidth)
-	] ifFalse:[
-	    line notNil ifTrue:[
-		lineSize := line string size
-	    ] ifFalse:[
-		lineSize := 0
-	    ].
-	    (lineSize == 0) ifTrue:[
-		lText := (tcol * fontWidth)
-	    ] ifFalse:[
-		(lineSize < col) ifTrue:[
-		    lText := (line widthOn:self) + (fontWidth * (tcol - lineSize))
-		] ifFalse:[
-		    (line isSingleByteString) ifTrue:[
-			lText := (gc font widthOf:line from:1 to:tcol)
-		    ] ifFalse:[
-			lText := line widthFrom:1 to:tcol on:self.
-		    ]
-		]
-	    ]
-	]
+        tcol := col - 1.
+
+        line := self visibleAt:visLineNr.
+        (fontIsFixedWidth and:[line isNil or:[line isSingleByteString]])
+        ifTrue:[
+            lText := (tcol * fontWidth)
+        ] ifFalse:[
+            line notNil ifTrue:[
+                lineSize := line string size
+            ] ifFalse:[
+                lineSize := 0
+            ].
+            (lineSize == 0) ifTrue:[
+                lText := (tcol * fontWidth)
+            ] ifFalse:[
+                (lineSize < col) ifTrue:[
+                    lText := (line widthOn:self) + (fontWidth * (tcol - lineSize))
+                ] ifFalse:[
+                    (line isSingleByteString) ifTrue:[
+                        lText := (gc font widthOf:line from:1 to:tcol)
+                    ] ifFalse:[
+                        lText := line widthFrom:1 to:tcol on:self.
+                    ]
+                ]
+            ]
+        ]
     ].
     ^ lText + textStartLeft
 
-    "Modified: / 3.9.1998 / 21:56:33 / cg"
+    "Modified: / 03-09-1998 / 21:56:33 / cg"
+    "Modified (format): / 01-03-2019 / 21:50:17 / Claus Gittinger"
 !
 
 yOfLine:lineNr