... a number is either an integer, or zero or more decimal digits followed by a dot (.) followed by one or more decimal digits; optionally, it can be concluded by the letter “e” or “E” followed by an integer indicating the base-ten exponent in scientific notation. ...
Status
This Enhancement Request is not yet accepted so it's internaly referenced in Java Bug Database as JI-9073933.
Basic test
In jshell type :
import java.awt.Color;
import javax.swing.text.html.StyleSheet;
StyleSheet styleSheet = new StyleSheet();
First test :
Expected result, a value not an Exception.
styleSheet.stringToColor("rgba(12 23 17 50%)").getAlpha();
| Exception java.lang.IllegalArgumentException: Color parameter outside of expected range: Alpha
| at Color.testColorValueRange (Color.java:312)
| at Color.<init> (Color.java:397)
| at Color.<init> (Color.java:492)
| at CSS.parseRGBA (CSS.java:1475)
| at CSS.stringToColor (CSS.java:1404)
| at StyleSheet.stringToColor (StyleSheet.java:1029)
| at (#21:1)
Second test :
Expected result, 240.
styleSheet.stringToColor("rgb(12 23 17 / 0.94)").getAlpha();
color ==> 255
Leading and trailing white-spaces (according to Java) in the argument string were removed.
Inside () multiple white-space (according to Java) occurences are replaced by only one space character.
white-spaces (according to Java) between rgb or rgba and ( are removed.
If / is not present, <rgb> functions need 3 values. Not verified.
Else functions need 4 values. Not verified.
To avoid later incompatibilies, other cases should return null.
A value can be percent or number. But the range is not the same according the component.
r, g, b numbers in range 0 to 255 or percents in range 0% to 100%.
a number in range 0 to 1 or percent in range 0% to 100%.
none keyword not scaned.
The format of number used as value is not defined in the specification. Then implementations should use the previous implementation format.
Add number e-notation support (see above).
Consequences
<rgba> accepts most of these functionalities excepted % for alpha value. According comments above, implementation doesn't respect the alpha range and treates this component like r, g, b. It's a bug.
<rgb> doesn't accept alpha value. It's an enhancement.
none keyword not supported. It's an enhancement.
number used as value is Javafloat $s \times m \times 2^{e-150}$.
The purpose of this issue is to align the
<rgb()>
and<rgba()>
function behaviours in CSS.java.This is referenced in Java Bug Database as
<rgb()>
and<rgba()>
function behavioursThis is tracked in JBS as
<rgb()>
and<rgba()>
function behavioursRelated Pull Request
<rgb()>
and<rgba()>
function behavioursAligns the
<rgb()>
and<rgba()>
function behaviours in CSS.java, as described in : CSS Color Module Level 4 W3C Candidate Recommendation Snapshot, 5 July 2022 4.1 The<Color>
syntax 6.1. The RGB functions: rgb() and rgba()<number>
typeStatus
This Enhancement Request is not yet accepted so it's internaly referenced in Java Bug Database as JI-9073933.Basic test
jshell
type :Details :
()
multiple white-space (according to Java) occurences are replaced by only one space character.rgb
orrgba
and(
are removed./
is not present,<rgb>
functions need 3 values. Not verified.none
keyword not scaned.number
used as value is not defined in the specification. Then implementations should use the previous implementation format.Consequences
<rgba>
accepts most of these functionalities excepted % for alpha value. According comments above, implementation doesn't respect the alpha range and treates this component like r, g, b. It's a bug.<rgb>
doesn't accept alpha value. It's an enhancement.none
keyword not supported. It's an enhancement.number
used as value isJava
float
$s \times m \times 2^{e-150}$.s
is sign, 1 bitm
is magnitude 23 bitse
is exponent 8 bitsSyntax
rgb()
rgb( [<percentage> \| none]{3} [ / [<alpha-value> \| none] ]? )
rgb( [<number> \| none]{3} [ / [<alpha-value> \| none] ]? )
rgb( <percentage>#{3} , <alpha-value>? )
rgb( <number>#{3} , <alpha-value>? )
number:= [+\|-]? [0...9]* [[. [0...9]*]]? [[e\|E]! [0...9]*]?
Some tests
rgb(12 24 200)
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
rgb(-1 24 200%)
java.awt.Color[r=0,g=24,b=255] + a=255
rgba(0 24 255 1.0)
rgb(300 24 28)
java.awt.Color[r=255,g=24,b=28] + a=255
rgba(255 24 28 1.0)
rgb(12 24 200 / 82%)
java.awt.Color[r=12,g=24,b=200] + a=209
rgba(12 24 200 0.82)
rgb(12 24 200 / 0.82)
java.awt.Color[r=12,g=24,b=200] + a=209
rgba(12 24 200 0.82)
rgb(12 24 200 / -210)
java.awt.Color[r=12,g=24,b=200] + a=0
rgba(12 24 200 0.0)
rgb(12, 24, 200)
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
rgb(12, 24, 200, 210)
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
rgb(12, 24, 200 , 210)
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
rgb(12 , 24 , 200 , 210)
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
rgb( 12 , 24 , 200 , 210 )
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
rgb(12 ,24, 200 ,210)
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
rgb(12,24,200,210)
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
rgb(15% 60% 49%)
java.awt.Color[r=38,g=153,b=125] + a=255
rgba(38 153 125 1.0)
rgb(15% 60% 49% / 82%)
java.awt.Color[r=38,g=153,b=125] + a=209
rgba(38 153 125 0.82)
rgb(15%, 60%, 49% / 82%)
java.awt.Color[r=38,g=153,b=125] + a=209
rgba(38 153 125 0.82)
rgb(0.14 60% 52.3 / 0.98)
java.awt.Color[r=0,g=153,b=52] + a=250
rgba(0 153 52 0.98)
rgb(none none none)
java.awt.Color[r=0,g=0,b=0] + a=255
rgba(0 0 0 1.0)
rgb(none none none / none)
java.awt.Color[r=0,g=0,b=0] + a=0
rgba(0 0 0 0.0)
rgb(none none none / none)
java.awt.Color[r=0,g=0,b=0] + a=0
rgba(0 0 0 0.0)
rgb(none none 30)
java.awt.Color[r=0,g=0,b=30] + a=255
rgba(0 0 30 1.0)
rgb(none 20 none)
java.awt.Color[r=0,g=20,b=0] + a=255
rgba(0 20 0 1.0)
rgb(10 none none)
java.awt.Color[r=10,g=0,b=0] + a=255
rgba(10 0 0 1.0)
rgb(none none none)
java.awt.Color[r=0,g=0,b=0] + a=255
rgba(0 0 0 1.0)
rgb(10 50 13% / 50%)
java.awt.Color[r=10,g=50,b=33] + a=128
rgba(10 50 33 0.5)
rgb(10 50 13% // 50%)
java.awt.Color[r=0,g=0,b=0] + a=255
rgba(0 0 0 1.0)
rgb(10 50,, 13% // 50%)
java.awt.Color[r=0,g=0,b=0] + a=255
rgba(0 0 0 1.0)
rgb(10 50 ,, 13% // 50%)
java.awt.Color[r=0,g=0,b=0] + a=255
rgba(0 0 0 1.0)
rgb(1.2e1 0.24e2 2e2)
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
rgb(1200e-2 2400e-2 200000e-3)
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
rgb(12 24 200)
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
rgb(12 24 200%)
java.awt.Color[r=12,g=24,b=255] + a=255
rgba(12 24 255 1.0)
rgb(-1 24 200%)
java.awt.Color[r=0,g=24,b=255] + a=255
rgba(0 24 255 1.0)
rgb(300 24 28)
java.awt.Color[r=255,g=24,b=28] + a=255
rgba(255 24 28 1.0)
rgb(12 24 200 / 82%)
java.awt.Color[r=12,g=24,b=200] + a=209
rgba(12 24 200 0.82)
rgb(12 24 200 / 0.82)
java.awt.Color[r=12,g=24,b=200] + a=209
rgba(12 24 200 0.82)
rgb(12 24 200 / -210)
java.awt.Color[r=12,g=24,b=200] + a=0
rgba(12 24 200 0.0)
rgb(12, 24, 200)
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
rgb(12, 24, 200, 210)
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
rgb(12, 24, 200 , 210)
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
rgb(12 , 24 , 200 , 210)
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
rgb( 12 , 24 , 200 , 210 )
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
rgb(12 ,24, 200 ,210)
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
rgb(12,24,200,210)
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
rgb(15% 60% 49%)
java.awt.Color[r=38,g=153,b=125] + a=255
rgba(38 153 125 1.0)
rgb(15% 60% 49% / 82%)
java.awt.Color[r=38,g=153,b=125] + a=209
rgba(38 153 125 0.82)
rgb(15%, 60%, 49% / 82%)
java.awt.Color[r=38,g=153,b=125] + a=209
rgba(38 153 125 0.82)
rgb(0.14 60% 52.3 / 0.98)
java.awt.Color[r=0,g=153,b=52] + a=250
rgba(0 153 52 0.98)
rgb(none none none)
java.awt.Color[r=0,g=0,b=0] + a=255
rgba(0 0 0 1.0)
rgb(none none none / none)
java.awt.Color[r=0,g=0,b=0] + a=0
rgba(0 0 0 0.0)
rgb(none none none/none)
java.awt.Color[r=0,g=0,b=0] + a=0
rgba(0 0 0 0.0)
rgb(none none 30)
java.awt.Color[r=0,g=0,b=30] + a=255
rgba(0 0 30 1.0)
rgb(none 20 none)
java.awt.Color[r=0,g=20,b=0] + a=255
rgba(0 20 0 1.0)
rgb(10 none none)
java.awt.Color[r=10,g=0,b=0] + a=255
rgba(10 0 0 1.0)
rgb(none none none)
java.awt.Color[r=0,g=0,b=0] + a=255
rgba(0 0 0 1.0)
rgb(10 50 13% / 50%)
java.awt.Color[r=10,g=50,b=33] + a=128
rgba(10 50 33 0.5)
rgb(10 50 13% // 50%)
java.awt.Color[r=0,g=0,b=0] + a=255
rgba(0 0 0 1.0)
rgb(10 50,, 13% // 50%)
java.awt.Color[r=0,g=0,b=0] + a=255
rgba(0 0 0 1.0)
rgb(10 50 ,, 13% // 50%)
java.awt.Color[r=0,g=0,b=0] + a=255
rgba(0 0 0 1.0)
rgb(1.2e1 0.24e2 2e2)
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
rgb(1200e-2 2400e-2 200000e-3)
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
rgb(120560.64646464632469823160676064670646798706406464098706464097970906464067e-4 2400e-2 200000e-3)
java.awt.Color[r=12,g=24,b=200] + a=255
rgba(12 24 200 1.0)
About performances
<rgb>
alpha support<rgb>
none
support<rgb>
base-ten floating-point notation support:heavy_check_mark: