XftFontDescription.st
branchdelegated_gc_jv
changeset 6527 2e58bb576883
parent 6526 7b413d1887b6
child 6529 701cc8c05f3a
--- a/XftFontDescription.st	Mon Jun 16 10:44:24 2014 +0100
+++ b/XftFontDescription.st	Thu Jun 19 10:26:33 2014 +0100
@@ -76,8 +76,7 @@
 
 # define __HANDLE_VAL(type, externalAddress) \
 	((type)__externalAddressVal(externalAddress))
-
-# define __HANDLE_NEW(ptr, __cls)                \
+#define __HANDLE_NEW(ptr, __cls)                \
 	({                                      \
 	    OBJ handle;                         \
 	    handle = __MKEXTERNALADDRESS(ptr);  \
@@ -421,7 +420,7 @@
 !XftFontDescription methodsFor:'accessing'!
 
 encoding
-    ^ encoding ? 'iso10646-1'
+    ^ encoding ? #'iso10646-1'
 !
 
 face
@@ -534,31 +533,29 @@
 displayString:aString from:index1 to:index2Arg x:xArg y:yArg in:aGC opaque:opaque
     "display a partial string at some position in aGC."
 
-    |index2 bytesPerCharacter transformation clipR clipX clipY clipW clipH fg fgR fgG fgB fgA fgPixel bg bgR bgG bgB bgA bgPixel drawX drawY displayId screen drawableId error  stringLen|
+    |index2 bytesPerCharacter transformation clipR clipX clipY clipW clipH fg fgR fgG fgB fgA fgPixel
+     bg bgR bgG bgB bgA bgPixel drawX drawY displayId screen drawableId error stringLen|
 
     "limit the string len, otherwise bad output is generated"
-    stringLen := index2Arg - index1 + 1.
-    stringLen > 8000 ifTrue:[
-        index2 := index1 + 8000 - 1.
+    stringLen := index2Arg - index1.
+    stringLen > 4000 ifTrue:[
+        index2 := index1 + 4000.
     ]  ifFalse:[
-        stringLen <= 0 ifTrue:[^ self].
         index2 := index2Arg.
     ].
     bytesPerCharacter := aString bitsPerCharacter // 8.
-    transformation := aGC transformation.
 
-    clipR := aGC clippingBoundsOrNil.
+    clipR := aGC deviceClippingBoundsOrNil.
     clipR notNil ifTrue:[
         clipX := clipR left.
         clipY := clipR top.
         clipW := clipR width.
         clipH := clipR height.
-"/        transformation notNil ifTrue:[
-"/            clipX := (transformation applyToX:clipX) ceiling.
-"/            clipY := (transformation applyToY:clipY) ceiling.
-"/        ].
+clipW > 32767 ifTrue:['clipW > 32767 ' errorPrintCR. clipW errorPrintCR. self halt. clipW := 32767].
+(clipX > 16384 or:[clipX < -16384]) ifTrue:['clipX < 16384 ' errorPrintCR. clipX errorPrintCR.].
     ].
 
+    transformation := aGC transformation.
     transformation isNil ifTrue:[
         drawX := xArg.
         drawY := yArg.
@@ -569,15 +566,14 @@
 
     fg  :=  aGC paint.
     fgPixel := fg colorId.
-    "/ fgPixel notNil ifTrue:[
-        fgR := fg scaledRed.
+    fgA := fg scaledAlpha.
+    fgR := fg scaledRed.
+    fgR notNil ifTrue:[
         fgG := fg scaledGreen.
         fgB := fg scaledBlue.
-        fgA := (fg alpha * 65535) rounded.
-    "/].
-    fgR isNil ifTrue:[
+    ] ifFalse:[
         "/ when drawing into a pixmap...
-        fg colorId == 0 ifTrue:[
+        fgPixel == 0 ifTrue:[
             fgR := fgG := fgB := 0.
         ] ifFalse:[
             fgR := fgG := fgB := 16rFFFF.
@@ -587,15 +583,14 @@
     opaque ifTrue:[
         bg  := aGC backgroundPaint.
         bgPixel := bg colorId.
-        "/bgPixel notNil ifTrue:[
-            bgR := bg scaledRed.
+        bgA := bg scaledAlpha.
+        bgR := bg scaledRed.
+        bgR notNil ifTrue:[
             bgG := bg scaledGreen.
             bgB := bg scaledBlue.
-            bgA := (bg alpha * 65535) rounded.
-        "/].
-        bgR isNil ifTrue:[
+        ] ifFalse:[
             "/ when drawing into a pixmap...
-            bg colorId == 0 ifTrue:[
+            bgPixel == 0 ifTrue:[
                 bgR := bgG := bgB := 0.
             ] ifFalse:[
                 bgR := bgG := bgB := 16rFFFF.
@@ -678,6 +673,7 @@
             XftTextExtents32( DISPLAY( displayId ), XFT_FONT( __INST( fontId ) ), (FcChar32*)string, len, &extents);
             break;
         }
+if (extents.width < 0) printf("width: %d  < 0\n", extents.width);
         XftDrawRect( XFT_DRAW ( __INST( sharedDrawId ) ), &color, __intVal(drawX) - extents.x, __intVal(drawY) - XFT_FONT( __INST( fontId ) )->ascent, extents.width, XFT_FONT(__INST (fontId ) )->height);
     }
     if (fgPixel != nil) {
@@ -715,8 +711,8 @@
         RETURN ( self );
         break;
     }
+#endif
     err:;
-#endif
 %}.
     self primitiveFailed: error.
 
@@ -762,94 +758,94 @@
     (device == aGraphicsDevice) ifTrue:[^ self].
 
     (aGraphicsDevice isNil and:[device notNil]) ifTrue:[
-        ^ self
+	^ self
     ].
 
     (closestFont notNil and:[closestFont graphicsDevice == aGraphicsDevice]) ifTrue:[
-        ^ closestFont onDevice: aGraphicsDevice.
+	^ closestFont onDevice: aGraphicsDevice.
     ].
 
     RecentlyUsedFonts isNil ifTrue:[
-        RecentlyUsedFonts := OrderedCollection new:10.
+	RecentlyUsedFonts := OrderedCollection new:10.
     ].
 
     RecentlyUsedFonts keysAndValuesDo:[:index :aFont |
-        ((aFont class == self class) and:[(self sameDeviceFontAs:aFont) and:[aFont getFontId notNil]]) ifTrue:[
-            "/ Transcript showCR:'hit'.
-            RecentlyUsedFonts removeIndex:index.
-            RecentlyUsedFonts addFirst:aFont.
-            ^ aFont
-        ]
+	((aFont class == self class) and:[self sameDeviceFontAs:aFont]) ifTrue:[
+	    "/ Transcript showCR:'hit'.
+	    RecentlyUsedFonts removeIndex:index.
+	    RecentlyUsedFonts addFirst:aFont.
+	    ^ aFont
+	]
     ].
 
     RecentlyUsedFonts size > 20 ifTrue:[
-        RecentlyUsedFonts removeLast.
+	RecentlyUsedFonts removeLast.
     ].
 
     aGraphicsDevice deviceFonts do:[:aFont |
-        ((aFont class == self class) and:[self sameDeviceFontAs:aFont]) ifTrue:[
-            RecentlyUsedFonts addFirst:aFont.
-            ^ aFont
-        ].
+	((aFont class == self class) and:[self sameDeviceFontAs:aFont]) ifTrue:[
+	    RecentlyUsedFonts addFirst:aFont.
+	    ^ aFont
+	].
     ].
 
     [
-        myPatternId := self xftPatternCreate.
-        self xftPatternAdd: myPatternId attribute: FC_FAMILY  value: family.
-        pixelSize notNil ifTrue:[
-            self xftPatternAdd: myPatternId attribute: FC_PIXEL_SIZE value: pixelSize.
-        ] ifFalse:[
-            self xftPatternAdd: myPatternId attribute: FC_SIZE value: size.
-        ].
-        self xftPatternAdd: myPatternId attribute: FC_WEIGHT value: (StXFace2FCWeightMap at: (face ? 'regular')).
-        self xftPatternAdd: myPatternId attribute: FC_SLANT value: (StXStyle2FCSlantMap at: (style ? 'roman') ifAbsent:[StXStyle2FCSlantMap at: (style ? 'roman') asLowercase]).
+	myPatternId := self xftPatternCreate.
+	self xftPatternAdd: myPatternId attribute: FC_FAMILY  value: family.
+	pixelSize notNil ifTrue:[
+	    self xftPatternAdd: myPatternId attribute: FC_PIXEL_SIZE value: pixelSize.
+	] ifFalse:[
+	    self xftPatternAdd: myPatternId attribute: FC_SIZE value: size.
+	].
+	self xftPatternAdd: myPatternId attribute: FC_WEIGHT value: (StXFace2FCWeightMap at: (face ? 'regular')).
+	self xftPatternAdd: myPatternId attribute: FC_SLANT value: (StXStyle2FCSlantMap at: (style ? 'roman') ifAbsent:[StXStyle2FCSlantMap at: (style ? 'roman') asLowercase]).
 
-        newFontId := self xftFontOpenPattern: aGraphicsDevice displayId pattern: myPatternId.
-        newFontId notNil ifTrue:[
-            "/ Good, this font exists!!
-            fontId := newFontId.
-            device := aGraphicsDevice.
-            aGraphicsDevice registerFont:self.
-            RecentlyUsedFonts addFirst:self.
-            ^ self.
-        ] ifFalse:[
-            closestPatternId1 := self xftFontMatch: aGraphicsDevice displayId screen: aGraphicsDevice screen pattern: myPatternId.
-            closestPatternId1 isNil ifTrue:[
-                self error: 'No font matches'.
-            ].
-            "
-            self xftPatternGet: closestPatternId attribute: 'family' index: 0.
-            self xftPatternGet: closestPatternId attribute: 'size' index: 0.
-            "
-            closestPatternId2 := self xftPatternDuplicate: closestPatternId1.
-            newFontId := self xftFontOpenPattern: aGraphicsDevice displayId pattern: closestPatternId1.
-            "/ !!!!!!!! closestPatternId is no longer valid !!!!!!!!
-            closestPatternId1 :=  nil.
-            newFontId isNil ifTrue:[
-                self error: 'Pattern matched, but font could not be opened (should not happen)'.
-            ].
+	newFontId := self xftFontOpenPattern: aGraphicsDevice displayId pattern: myPatternId.
+	newFontId notNil ifTrue:[
+	    "/ Good, this font exists!!
+	    fontId := newFontId.
+	    device := aGraphicsDevice.
+	    aGraphicsDevice registerFont:self.
+	    RecentlyUsedFonts addFirst:self.
+	    ^ self.
+	] ifFalse:[
+	    closestPatternId1 := self xftFontMatch: aGraphicsDevice displayId screen: aGraphicsDevice screen pattern: myPatternId.
+	    closestPatternId1 isNil ifTrue:[
+		self error: 'No font matches'.
+	    ].
+	    "
+	    self xftPatternGet: closestPatternId attribute: 'family' index: 0.
+	    self xftPatternGet: closestPatternId attribute: 'size' index: 0.
+	    "
+	    closestPatternId2 := self xftPatternDuplicate: closestPatternId1.
+	    newFontId := self xftFontOpenPattern: aGraphicsDevice displayId pattern: closestPatternId1.
+	    "/ !!!!!!!! closestPatternId is no longer valid !!!!!!!!
+	    closestPatternId1 :=  nil.
+	    newFontId isNil ifTrue:[
+		self error: 'Pattern matched, but font could not be opened (should not happen)'.
+	    ].
 
-            "/ Search for existing registered font. Note, that XftFont instances
-            "/ are shared (and refcounted) so newFontId = aFont getFontId is enough
-            "/ to check whether some other font instance represents the same font...
-            aGraphicsDevice deviceFonts do:[:aFont |
-                ((self class == aFont class) and:[newFontId = aFont getFontId]) ifTrue:[
-                    closestFont := aFont.
-                    ^ closestFont
-                ].
-            ].
+	    "/ Search for existing registered font. Note, that XftFont instances
+	    "/ are shared (and refcounted) so newFontId = aFont getFontId is enough
+	    "/ to check whether some other font instance represents the same font...
+	    aGraphicsDevice deviceFonts do:[:aFont |
+		((self class == aFont class) and:[newFontId = aFont getFontId]) ifTrue:[
+		    closestFont := aFont.
+		    ^ closestFont
+		].
+	    ].
 
-            closestFont := self shallowCopy
-                                setDevice: aGraphicsDevice patternId: closestPatternId2 fontId: newFontId;
-                                yourself.
-            aGraphicsDevice registerFont: closestFont.
-            RecentlyUsedFonts addFirst:closestFont.
-            ^ closestFont
-        ].
+	    closestFont := self shallowCopy
+				setDevice: aGraphicsDevice patternId: closestPatternId2 fontId: newFontId;
+				yourself.
+	    aGraphicsDevice registerFont: closestFont.
+	    RecentlyUsedFonts addFirst:closestFont.
+	    ^ closestFont
+	].
     ] ensure:[
-        myPatternId notNil ifTrue:[self xftPatternDestroy: myPatternId].
-        closestPatternId1 notNil ifTrue:[self xftPatternDestroy: closestPatternId1].
-        closestPatternId2 notNil ifTrue:[self xftPatternDestroy: closestPatternId2].
+	myPatternId notNil ifTrue:[self xftPatternDestroy: myPatternId].
+	closestPatternId1 notNil ifTrue:[self xftPatternDestroy: closestPatternId1].
+	closestPatternId2 notNil ifTrue:[self xftPatternDestroy: closestPatternId2].
     ].
 
     "
@@ -877,16 +873,17 @@
     device := deviceArg.
     fontId := fontIdArg.
     patternIdArg notNil ifTrue:[
-	family  := self xftPatternGet: patternIdArg attribute: FC_FAMILY index: 0.
-	size    := self xftPatternGet: patternIdArg attribute: FC_SIZE index: 0.
-	face    := self xftPatternGet: patternIdArg attribute: FC_WEIGHT index: 0.
-	face    := StXFace2FCWeightMap keyAtValue: face.
-	style   := self xftPatternGet: patternIdArg attribute: FC_SLANT index: 0.
-	style   := StXStyle2FCSlantMap keyAtValue: style.
+        family  := self xftPatternGet: patternIdArg attribute: FC_FAMILY index: 0.
+        size    := self xftPatternGet: patternIdArg attribute: FC_SIZE index: 0.
+        face    := self xftPatternGet: patternIdArg attribute: FC_WEIGHT index: 0.
+        face    := StXFace2FCWeightMap keyAtValue: face.
+        style   := self xftPatternGet: patternIdArg attribute: FC_SLANT index: 0.
+        style   := StXStyle2FCSlantMap keyAtValue: style.
 
-	name:= self xftPatternGet: patternIdArg attribute: 'fullname' index: 0.
+        name:= self xftPatternGet: patternIdArg attribute: 'fullname' index: 0.
 
-	encoding:= self xftPatternGet: patternIdArg attribute: 'encoding' index: 0.
+        encoding:= self xftPatternGet: patternIdArg attribute: 'encoding' index: 0.
+        encoding notNil ifTrue:[encoding := encoding asSymbol].
     ].
 
     "Created: / 21-12-2013 / 00:46:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -1665,10 +1662,26 @@
 widthOf:aString from:start to:stop
     "return the width of a sub string"
 
-    | extents |
+    |extents maxWidthOfSingleGlyph|
 
     (stop < start) ifTrue:[^ 0].
-    extents := self xftTextExtents: device displayId font: fontId string: aString from: start to: stop.
+    maxWidthOfSingleGlyph := self maxWidth.
+    "xOff from XFTTextExtents is a signed short.
+     Work arond for long strings"
+    (stop - start + 1) * maxWidthOfSingleGlyph > 32767 ifTrue:[
+        |total chunkSize|
+
+        chunkSize := (32767 // maxWidthOfSingleGlyph) - 1.
+        total := 0.
+        start to:stop by:chunkSize do:[:eachChunkStart|
+            extents := self xftTextExtents:device displayId font:fontId string:aString 
+                            from:eachChunkStart to:((eachChunkStart+chunkSize-1) min:stop).
+            "/ extents --> #(width height x y xOff yOff)
+            total := total + extents fifth.
+        ].
+        ^ total.
+    ].    
+    extents := self xftTextExtents: device displayId font:fontId string:aString from:start to:stop.
     "/ extents --> #(width height x y xOff yOff)
     ^ extents fifth.
 
@@ -2035,11 +2048,11 @@
 !XftFontDescription class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.56 2014-06-06 09:05:55 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.51.2.1 2014-05-08 08:27:51 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.56 2014-06-06 09:05:55 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/XftFontDescription.st,v 1.51.2.1 2014-05-08 08:27:51 stefan Exp $'
 ! !