[Pkg] The Trunk: Graphics-pre.367.mcz

commits at source.squeak.org commits at source.squeak.org
Fri Jan 20 16:48:04 UTC 2017


Patrick Rein uploaded a new version of Graphics to project The Trunk:
http://source.squeak.org/trunk/Graphics-pre.367.mcz

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

Name: Graphics-pre.367
Author: pre
Time: 20 January 2017, 5:44:33.081379 pm
UUID: 6258ced8-1a7f-5344-914d-5a641a0734cf
Ancestors: Graphics-bp.366

Implements HTML colors with 8 characters denoting RGBa colors. Small refactoring of fromString: method.

=============== Diff against Graphics-bp.366 ===============

Item was added:
+ ----- Method: Color class>>fromHTMLString: (in category 'other') -----
+ fromHTMLString: aColorHex
+ 	"Do not call this method directly, call Color>>#fromString: instead as it is more generic"
+ 
+ 	| green red blue resultColor |
+ 	red := (Integer readFrom: (aColorHex first: 2) base: 16).
+ 	green := (Integer readFrom: (aColorHex copyFrom: 3 to: 4) base: 16).
+ 	blue := (Integer readFrom: (aColorHex copyFrom: 5 to: 6) base: 16).
+ 	resultColor := self r: red g: green b: blue range: 255.
+ 	^ (aColorHex size = 8) 
+ 		ifTrue: [resultColor alpha: ((Integer readFrom: (aColorHex last: 2) base: 16) / 255)]
+ 		ifFalse: [resultColor]!

Item was added:
+ ----- Method: Color class>>fromRGBString: (in category 'other') -----
+ fromRGBString: rgb
+ 	"Do not call this method directly, call Color>>#fromString: instead as it is more generic"
+ 	
+ 	| green red blue |
+ 	red := (Integer readFrom:(rgb at: 1)) min: 255 max: 0.
+ 	green := (Integer readFrom:(rgb at: 2)) min: 255 max: 0.
+ 	blue := (Integer readFrom:(rgb at: 3)) min: 255 max: 0.
+ 	^self r: red g: green b: blue range: 255!

Item was changed:
  ----- Method: Color class>>fromString: (in category 'instance creation') -----
  fromString: aString
  	"for HTML color spec: #FFCCAA or white/black/red/other name, or an r,g,b triplet string"
  	"Color fromString: '#FFCCAA'.
  	 Color fromString: 'white'.
  	 Color fromString: 'orange'
  	 Color fromString: '126,42,33' "
  	
  	| aColorHex rgb|
  	aString isEmptyOrNil ifTrue: [ ^self white ].
  	aString first = $#
  		ifTrue: [ aColorHex := aString allButFirst ]
  		ifFalse: [ aColorHex := aString ].
+ 	
  	"is the string a 6 digit hex number?"
+ 	((aColorHex size = 6 or: [aColorHex size = 8]) and: [ 
- 	(aColorHex size = 6 and: [ 
  		aColorHex allSatisfy: [ :each | '0123456789ABCDEFabcdef' includes: each ] ])
+ 			ifTrue: [^ self fromHTMLString: aColorHex ].
+ 	
- 			ifTrue: [
- 				| green red blue |
- 				red := (Integer readFrom: (aColorHex first: 2) base: 16).
- 				green := (Integer readFrom: (aColorHex copyFrom: 3 to: 4) base: 16).
- 				blue := (Integer readFrom: (aColorHex last: 2) base: 16).
- 				^self r: red g: green b: blue range: 255].	
  	"is the string in the form a,b,c ?"
  	rgb := aColorHex findTokens: $, .
+ 	rgb size = 3 ifTrue: [^ self fromRGBString: rgb].
+ 	
- 	rgb size = 3 ifTrue: [
- 				| green red blue |
- 				red := (Integer readFrom:(rgb at: 1)) min: 255 max: 0.
- 				green := (Integer readFrom:(rgb at: 2)) min: 255 max: 0.
- 				blue := (Integer readFrom:(rgb at: 3)) min: 255 max: 0.
- 				^self r: red g: green b: blue range: 255].
  	"try to match aColorHex with known named colors, case insensitive"
  	^self perform: (ColorNames detect: [:colorSymbol | aColorHex sameAs: colorSymbol] ifNone: [ #white ])!

Item was added:
+ ----- Method: TranslucentColor>>asHTMLColor (in category 'conversions') -----
+ asHTMLColor
+ 
+ 	^ super asHTMLColor 
+ 		, (Character digitValue: ((alpha bitShift: -4) bitAnd: 15))
+ 		, (Character digitValue: (alpha bitAnd: 15))!



More information about the Packages mailing list