Christoph Thiede uploaded a new version of Graphics to project The Trunk: http://source.squeak.org/trunk/Graphics-ct.541.mcz
==================== Summary ====================
Name: Graphics-ct.541 Author: ct Time: 1 June 2023, 9:07:27.980127 pm UUID: ee2eb548-c686-9a4f-b85c-3dd027cf9d8f Ancestors: Graphics-nice.540
Merges Color-fromString-css-function-1.cs: Adds support for basic CSS color functions to Color fromString:. This may be especially helpful for parsing HTML. While there are other color functions in CSS such as hsv(), lch(), oklab(), et al. for color models that we don't support, and CSS colors may be complex expressions, simple rgb() and argb() expressions are especially common.
Revision: Moved private constructors into private category. Fixed plenk.
=============== Diff against Graphics-nice.540 ===============
Item was changed: + ----- Method: Color class>>fromHTMLString: (in category 'instance creation - private') ----- - ----- 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>>fromRGBAString: (in category 'instance creation - private') ----- + fromRGBAString: rgba + "Do not call this method directly, call Color>>#fromString: instead as it is more generic" + + | alpha | + alpha := (Float readFrom: (rgba at: 4)) min: 1 max: 0. + ^ (self fromRGBString: rgba) + alpha: alpha!
Item was changed: + ----- Method: Color class>>fromRGBString: (in category 'instance creation - private') ----- - ----- 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 allSatisfy: [ :each | '0123456789ABCDEFabcdef' includes: each ] ]) ifTrue: [^ self fromHTMLString: aColorHex ]. + "is the string a CSS function?" + aString last = $) ifTrue: [ + "While there are other color functions in CSS such as hsv(), lch(), oklab(), et al. for color models that we don't support, and CSS colors may be complex expressions, simple rgb() and argb() expressions are especially common." + (aString beginsWith: 'rgb(') ifTrue: [ + rgb := ((aString allButLast allButFirst: 4) findTokens: $,) collect: #withBlanksTrimmed. + ^ self fromRGBString: rgb]. + (aString beginsWith: 'rgba(') ifTrue: [ + | rgba | + rgba := ((aString allButLast allButFirst: 5) findTokens: $,) collect: #withBlanksTrimmed. + ^ self fromRGBAString: rgba]. + self flag: #forLater. "support hsl and hsla" + ^ self white]. + "is the string in the form a,b,c ?" rgb := aColorHex findTokens: $, . rgb size = 3 ifTrue: [^ self fromRGBString: rgb]. "try to match aColorHex with known named colors, case insensitive" ^self perform: (ColorNames detect: [:colorSymbol | aColorHex sameAs: colorSymbol] ifNone: [ #white ])!
Item was changed: + ----- Method: Color class>>shutDown (in category 'class initialization') ----- - ----- Method: Color class>>shutDown (in category 'other') ----- shutDown "Color shutDown"
ColorChart := nil. "Palette of colors for the user to pick from" CachedColormaps := nil. "Maps to translate between color depths" MaskingMap := nil. "Maps all colors except transparent to black for creating a mask" !
packages@lists.squeakfoundation.org