Color Class has a bug
Frank Shearar
frank.shearar at angband.za.org
Thu Nov 9 11:12:12 UTC 2006
"Peter Osburg" <peter.osburg at gmail.com> wrote:
> hello there,
>
> i don't know it the problem is still known but the following i figured
> yesterday:
>
> when using the class method
> Color>>fromString: 'yellow'
>
> or also
> Color>>fromString: 'orange'
>
>
> you will always get the hex-value of black. so i figured the following
> mistake
I'm running Squeak3.8-6665 (admittedly that's quite old, but anyhow). I ran
in a Workspace
Color fromString: '#orange' which returned a "Color orange", and
Color fromString: 'orange' which returned a "Color orange".
In short, I can't duplicate your problem (on my system).
> aString first = $#
> > ifTrue: [aColorHex := aString copyFrom: 2 to: aString size]
> > ifFalse: [aColorHex := aString].
> > [aColorHex size = 6
> > ifTrue:
> > [aColorHex := aColorHex asUppercase.
> > red := ('16r', (aColorHex copyFrom: 1 to: 2)) asNumber/255.
> > green := ('16r', (aColorHex copyFrom: 3 to: 4))
asNumber/255.
> > blue := ('16r', (aColorHex copyFrom: 5 to: 6)) asNumber/255.
> > ^ self r: red g: green b: blue]]
>
>
> u see: aColorHex will be aString when there is no '#' within the string.
but
> when the string has just the size of 6 (like it is given with 'yellow' or
> 'orange' then the statement will also be true. in fact of that you get a
> wrong hex for the right color :)
This is only part of the version of fromString in my image. The bit
immediately after the above snippet says
ifError: [:err :rcvr | "not a hex color triplet" ].
If you debug "Color fromString: 'orange'" you'll see the debugger will trace
into this (empty) block. Since 'orange' isn't a hex colour triple, nothing's
returned, and we continue execution:
"try to match aColorHex with known named colors"
aColorHex _ aColorHex asLowercase.
^self perform: (ColorNames detect: [:i | i asString asLowercase =
aColorHex]
ifNone: [#white])
Since 'orange' is an element in ColorNames, the "self perform" bit will
execute "Color orange", returning the colour you desired.
Does this help?
frank
More information about the Squeak-dev
mailing list
|