[squeak-dev] The Trunk: Graphics-nice.170.mcz

commits at source.squeak.org commits at source.squeak.org
Wed Dec 29 15:05:38 UTC 2010


Nicolas Cellier uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-nice.170.mcz

==================== Summary ====================

Name: Graphics-nice.170
Author: nice
Time: 29 December 2010, 4:04:55.524 pm
UUID: 872a3907-7951-40b8-991b-0b15318c5c32
Ancestors: Graphics-mtf.169

Add a few spaces in order to avoid Transcript warnings about @- ambiguity when recompiling.

Remove unused charIndex instance variable from StrikeFont.

=============== Diff against Graphics-mtf.169 ===============

Item was changed:
  ----- Method: Form>>findShapeAroundSeedBlock: (in category 'filling') -----
  findShapeAroundSeedBlock: seedBlock
  	"Build a shape that is black in any region marked by seedBlock. 
  	SeedBlock will be supplied a form, in which to blacken various
  	pixels as 'seeds'.  Then the seeds are smeared until 
  	there is no change in the smear when it fills the region, ie,
  	when smearing hits a black border and thus goes no further."
  	| smearForm previousSmear all count smearPort |
  	self depth > 1 ifTrue: [self halt]. "Only meaningful for B/W forms."
  	all := self boundingBox.
  	smearForm := Form extent: self extent.
  	smearPort := BitBlt current toForm: smearForm.
  	seedBlock value: smearForm.		"Blacken seeds to be smeared"
+ 	smearPort copyForm: self to: 0 @ 0 rule: Form erase.  "Clear any in black"
- 	smearPort copyForm: self to: 0 at 0 rule: Form erase.  "Clear any in black"
  	previousSmear := smearForm deepCopy.
  	count := 1.
  	[count = 10 and:   "check for no change every 10 smears"
  		[count := 1.
+ 		previousSmear copy: all from: 0 @ 0 in: smearForm rule: Form reverse.
- 		previousSmear copy: all from: 0 at 0 in: smearForm rule: Form reverse.
  		previousSmear isAllWhite]]
  		whileFalse: 
+ 			[smearPort copyForm: smearForm to: 1 @ 0 rule: Form under.
+ 			smearPort copyForm: smearForm to: -1 @ 0 rule: Form under.
- 			[smearPort copyForm: smearForm to: 1 at 0 rule: Form under.
- 			smearPort copyForm: smearForm to: -1 at 0 rule: Form under.
  			"After horiz smear, trim around the region border"
+ 			smearPort copyForm: self to: 0 @ 0 rule: Form erase.
+ 			smearPort copyForm: smearForm to: 0 @ 1 rule: Form under.
+ 			smearPort copyForm: smearForm to: 0 @ -1 rule: Form under.
- 			smearPort copyForm: self to: 0 at 0 rule: Form erase.
- 			smearPort copyForm: smearForm to: 0 at 1 rule: Form under.
- 			smearPort copyForm: smearForm to: 0 at -1 rule: Form under.
  			"After vert smear, trim around the region border"
+ 			smearPort copyForm: self to: 0 @ 0 rule: Form erase.
+ 			count := count + 1.
- 			smearPort copyForm: self to: 0 at 0 rule: Form erase.
- 			count := count+1.
  			count = 9 ifTrue: "Save penultimate smear for comparison"
+ 				[previousSmear copy: all from: 0 @ 0 in: smearForm rule: Form over]].
- 				[previousSmear copy: all from: 0 at 0 in: smearForm rule: Form over]].
  	"Now paint the filled region in me with aHalftone"
  	^ smearForm!

Item was changed:
  ----- Method: Form>>pageImage:at:corner: (in category 'transitions') -----
  pageImage: otherImage at: topLeft corner: corner
  	"Produce a page-turning illusion that gradually reveals otherImage
  	located at topLeft in this form.  Corner specifies which corner, as
  		1=topLeft, 2=topRight, 3=bottomRight, 4=bottomLeft."
  	| bb maskForm resultForm delta maskLoc maskRect stepSize cornerSel smallRect |
  	stepSize := 10.
  	bb := otherImage boundingBox.
  	resultForm := self copy: (topLeft extent: bb extent).
  	maskForm := Form extent: ((otherImage width min: otherImage height) + stepSize) asPoint.
  
  	"maskLoc := starting loc rel to topLeft"
  	otherImage width > otherImage height
  		ifTrue: ["wide image; motion is horizontal."
  				(corner between: 2 and: 3) not ifTrue:
  					["motion is to the right"
+ 					delta := 1 @ 0.
- 					delta := 1 at 0.
  					maskLoc := bb topLeft - (corner = 1
+ 						ifTrue: [maskForm width @ 0]
+ 						ifFalse: [maskForm width @ stepSize])]
- 						ifTrue: [maskForm width at 0]
- 						ifFalse: [maskForm width at stepSize])]
  					ifFalse:
  					["motion is to the left"
+ 					delta := -1 @ 0.
- 					delta := -1 at 0.
  					maskLoc := bb topRight - (corner = 2
+ 						ifTrue: [0 @ 0]
+ 						ifFalse: [0 @ stepSize])]]
- 						ifTrue: [0 at 0]
- 						ifFalse: [0 at stepSize])]]
  		ifFalse: ["tall image; motion is vertical."
  				corner <= 2 ifTrue:
  					["motion is downward"
+ 					delta := 0 @ 1.
- 					delta := 0 at 1.
  					maskLoc := bb topLeft - (corner = 1
+ 						ifTrue: [0 @ maskForm height]
+ 						ifFalse: [stepSize @ maskForm height])]
- 						ifTrue: [0 at maskForm height]
- 						ifFalse: [stepSize at maskForm height])]
  					ifFalse:
  					["motion is upward"
+ 					delta := 0 @ -1.
- 					delta := 0 at -1.
  					maskLoc := bb bottomLeft - (corner = 3
+ 						ifTrue: [stepSize @ 0]
+ 						ifFalse: [0 @ 0])]].
- 						ifTrue: [stepSize at 0]
- 						ifFalse: [0 at 0])]].
  
  	"Build a solid triangle in the mask form"
  	(Pen newOnForm: maskForm) in: [:p |
  		corner even  "Draw 45-degree line"
+ 			ifTrue: [p place: 0 @ 0; turn: 135; go: maskForm width * 3 // 2]
+ 			ifFalse: [p place: 0 @ (maskForm height - 1); turn: 45; go: maskForm width * 3 // 2]].
- 			ifTrue: [p place: 0 at 0; turn: 135; go: maskForm width*3//2]
- 			ifFalse: [p place: 0@(maskForm height-1); turn: 45; go: maskForm width*3//2]].
  	maskForm smear: delta negated distance: maskForm width.
  	"Copy the mask to full resolution for speed.  Make it be the reversed
  	so that it can be used for ORing in the page-corner color"
  	maskForm := (Form extent: maskForm extent depth: otherImage depth)
+ 		copyBits: maskForm boundingBox from: maskForm at: 0 @ 0
- 		copyBits: maskForm boundingBox from: maskForm at: 0 at 0
  		colorMap: (Bitmap with: 16rFFFFFFFF with: 0).
  
  	"Now move the triangle maskForm across the resultForm selecting the
  	triangular part of otherImage to display, and across the resultForm,
  	selecting the part of the original image to erase."
  	cornerSel := #(topLeft topRight bottomRight bottomLeft) at: corner.
+ 	1 to: (otherImage width + otherImage height // stepSize) + 1 do:
- 	1 to: (otherImage width + otherImage height // stepSize)+1 do:
  		[:i |		"Determine the affected square"
  		maskRect := (maskLoc extent: maskForm extent) intersect: bb.
+ 		((maskLoc x * delta x) + (maskLoc y * delta y)) < 0 ifTrue:
+ 			[smallRect := 0 @ 0 extent: (maskRect width min: maskRect height) asPoint.
- 		((maskLoc x*delta x) + (maskLoc y*delta y)) < 0 ifTrue:
- 			[smallRect := 0 at 0 extent: (maskRect width min: maskRect height) asPoint.
  			maskRect := smallRect align: (smallRect perform: cornerSel)
  								with: (maskRect perform: cornerSel)].
  
  		"AND otherForm with triangle mask, and OR into result"
+ 		resultForm copyBits: bb from: otherImage at: 0 @ 0
- 		resultForm copyBits: bb from: otherImage at: 0 at 0
  				clippingBox: maskRect rule: Form over fillColor: nil.
  		resultForm copyBits: maskForm boundingBox from: maskForm at: maskLoc
  				clippingBox: maskRect rule: Form erase fillColor: nil.
  		resultForm copyBits: maskForm boundingBox from: maskForm at: maskLoc
  				clippingBox: maskRect rule: Form under fillColor: Color lightBrown.
  
  		"Now update Display in a single BLT."
  		self copyBits: maskRect from: resultForm at: topLeft + maskRect topLeft
  				clippingBox: self boundingBox rule: Form over fillColor: nil.
  		Display forceDisplayUpdate.
+ 		maskLoc := maskLoc + (delta * stepSize)]
- 		maskLoc := maskLoc + (delta*stepSize)]
  "
  1 to: 4 do: [:corner | Display pageImage:
  				(Form fromDisplay: (10 at 10 extent: 200 at 300)) reverse
  			at: 10 at 10 corner: corner]
  "
  !

Item was changed:
  ----- Method: Point>>eightNeighbors (in category 'point functions') -----
  eightNeighbors
+ 	^ (Array with: self + (1 @ 0)
+ 		with: self + (1 @ 1)
+ 		with: self + (0 @ 1)
+ 		with: self + (-1 @ 1)) ,
+ 	(Array with: self + (-1 @ 0)
+ 		with: self + (-1 @ -1)
+ 		with: self + (0 @ -1)
+ 		with: self + (1 @ -1))
- 	^ (Array with: self + (1 at 0)
- 		with: self + (1 at 1)
- 		with: self + (0 at 1)
- 		with: self + (-1 at 1)) ,
- 	(Array with: self + (-1 at 0)
- 		with: self + (-1 at -1)
- 		with: self + (0 at -1)
- 		with: self + (1 at -1))
  !

Item was changed:
  ----- Method: Point>>fourNeighbors (in category 'point functions') -----
  fourNeighbors
+ 	^ Array with: self + (1 @ 0)
+ 		with: self + (0 @ 1)
+ 		with: self + (-1 @ 0)
+ 		with: self + (0 @ -1)
- 	^ Array with: self + (1 at 0)
- 		with: self + (0 at 1)
- 		with: self + (-1 at 0)
- 		with: self + (0 at -1)
  !

Item was changed:
  AbstractFont subclass: #StrikeFont
+ 	instanceVariableNames: 'characterToGlyphMap xTable glyphs name type minAscii maxAscii maxWidth strikeLength ascent descent xOffset raster subscript superscript emphasis derivativeFonts pointSize fallbackFont'
- 	instanceVariableNames: 'characterToGlyphMap xTable glyphs name type minAscii maxAscii maxWidth strikeLength ascent descent xOffset raster subscript superscript emphasis derivativeFonts pointSize fallbackFont charIndex'
  	classVariableNames: 'DefaultStringScanner'
  	poolDictionaries: 'TextConstants'
  	category: 'Graphics-Fonts'!
  
  !StrikeFont commentStamp: '<historical>' prior: 0!
  I represent a compact encoding of a set of Forms corresponding to characters in the ASCII character set. All the forms are placed side by side in a large form whose height is the font height, and whose width is the sum of all the character widths. The xTable variable gives the left-x coordinates of the subforms corresponding to the glyphs. Characters are mapped to glyphs by using the characterToGyphMap.
  
  Subclasses can have non-trivial mapping rules as well as different representations for glyphs sizes (e.g., not using an xTable). If so, these classes should return nil when queried for xTable and/or the characterToGlyphMap. This will cause the CharacterScanner primitive to fail and query the font for the width of a character (so that a more programatical approach can be implemented).
  
  For display, fonts need to implement two messages:
  	#installOn: aDisplayContext foregroundColor: foregroundColor backgroundColor: backgroundColor
  This method installs the receiver (a font) on the given DisplayContext (which may be an instance of BitBlt or Canvas (or any of it's subclasses). The font should take the appropriate action to initialize the display context so that further display operations can be optimized.
  	#displayString: aString on: aDisplayContext from: startIndex to: stopIndex at: aPoint kern: kernDelta
  This method is called for each subsequent run of characters in aString which is to be displayed with the (previously installed) settings.
  !

Item was changed:
  ----- Method: StrikeFont>>displayMultiString:on:from:to:at:kern:baselineY: (in category 'displaying') -----
  displayMultiString: aString on: aBitBlt from: startIndex to: stopIndex at: aPoint kern: kernDelta baselineY: baselineY
  
  	| leftX rightX glyphInfo char destY form gfont destX destPt |
  	destX := aPoint x.
- 	charIndex := startIndex.
  	glyphInfo := Array new: 5.
  	startIndex to: stopIndex do:[:charIndex|
  		char := aString at: charIndex.
  		(self hasGlyphOf: char) ifTrue: [
  			self glyphInfoOf: char into: glyphInfo.
  			form := glyphInfo at: 1.
  			leftX := glyphInfo at: 2.
  			rightX := glyphInfo at: 3.
  			destY := glyphInfo at: 4.
  			gfont := glyphInfo at: 5.
  			(gfont == aBitBlt lastFont) ifFalse: [gfont installOn: aBitBlt].
  			destY := baselineY - destY. 
  			aBitBlt displayGlyph: form at: destX @ destY left: leftX right: rightX font: self.
  			destX := destX + (rightX - leftX + kernDelta).
  		] ifFalse:[
  			destPt := self fallbackFont displayString: aString on: aBitBlt from: charIndex to: charIndex at: destX @ aPoint y kern: kernDelta from: self baselineY: baselineY.
  			destPt x = destX ifTrue:[
  				"In some situations BitBlt doesn't return the advance width from the primitive.
  				Work around the situation"
  				destX := destX + (self widthOfString: aString from: charIndex to: charIndex) + kernDelta.
  			] ifFalse:[destX := destPt x].
  		].
  	].
  	^destX @ aPoint y
  !




More information about the Squeak-dev mailing list