JDK-8293776 : Adds CSS 4 and 8 digits hex coded Color #13
Labels
Author
Contributed a patch to fix this issue
Enhancement
New feature or request
Fixed
Fixed issue.
Reporter
Reported this Issue to Java Bug DataBase
WIP
Work In Progress
The purpose of this issue is to add CSS 4 and 8 digits hex coded Color in CSS.java.
This is referenced in Java Bug Database as
This is tracked in JBS as
Related Pull Request
<rgb()>
and<rgba()>
function behavioursAdds the 4 and 8 digits color hex notations to CSS.java, as described in :
CSS Color Module Level 4
W3C Candidate Recommendation Snapshot, 5 July 2022
4.1 The
<Color>
syntax6.2 The RGB Hexadecimal Notations:
#RRGGBB
Status
This Enhancement Request is not yet accepted so it's internaly referenced in Java Bug Database as JI-9073933.This extends the previous closed JDK-4895924 issue see table below.
The present CSS implementation accepts 3 digits or 6 digits hex coded Color as following :
#rgb
must be interpreted as#rrggbb
opaque Color.#f0a
is interpreted as#ff00aa
opaque Color (Correct).#f00a
is interpreted as#00f00a
opaque Color (Wrong).I request to reach CSS Color Level 4 recommendation which accepts 3, 4, 6 and 8 digits.
#rgb
must be interpreted as#rrggbb
opaque Color.#rgba
must be interpreted as#rrggbbaa
Color with an aa Alpha value.#rrggbb
must be interpreted as#rrggbb
opaque Color.#rrggbbaa
must be interpreted as#rrggbbaa
Color with an aa Alpha value.#f00a
will be interpreted as#ff0000aa
.Impacts of these modifications.
CSS.java
hexToColor
methodrgb
method will be treated in another PR.rgba
is a legacy format, it would be better to not mention it in documentation even if CSS.java takes it in charge. In fact rgb could be reached troughrgba
.jdk/src/java.desktop/share/classes/javax/swing/text/html/CSS.java
Lines 1387 to 1388 in 7d7f49f
Integer.rotateRight(int i, int distance)
method +Color(int rgba, boolean hasalpha)
constructor.Test will determine which is the best. Conclusion, none gain in time, only
jdk/src/java.desktop/share/classes/javax/swing/text/html/CSS.java
Lines 1354 to 1411 in 5067200
Details :
()
multiple white-space (according to Java) occurences are replaced by only one space character.rgb
orrgba
and(
are removed.Implementation examples
First proposition
jdk/src/java.desktop/share/classes/javax/swing/text/html/CSS.java
Lines 1354 to 1412 in 7d7f49f
Notes :
jdk/src/java.desktop/share/classes/javax/swing/text/html/CSS.java
Line 1389 in 7d7f49f
chartAt
replacesubstring
methods.<
rather than==
. In fact, try to mix his proposition in my test flow.Optimized version using
Map
: Main-line discussions lead to this new approach.String
+formatted
+%n$s
usage.String
+formatted
+%s
usage.String
+format
with a string concatenation.charAt
out of bounds possible ! Not when using integrated parsing.Notes :
Notes :
Notes :
* 16
by<< 4
.Notes :
long
byint
.+
by|
.Notes :
Notes :
Long
operations are not atomic. Then retry to use string. First times, performances seemed no good, test again !Notes :
This method is too strict ! Test with "#1fe56980 ", "#1fe56980 ". Made changes to be able to parse this kind of string.Unnecessary, all leading and trailing spaces have been removed during the parsing process.Should I declareidseq
asfinal
for the same reasonsa
,b
,c
were declaredfinal
in the previous version.The code to test the present implementation.
Implementation evaluations : according the number of tests to reach a case
Test results :
Regression test
jdk/test/jdk/javax/swing/text/html/CSS/Hex3468DigitsColor.java
Lines 36 to 92 in 24040cf
About performances
%s
%n$s
""+r+...
CSS Level 4 details
#[2 digits Red][2 digits Green][2 digits Blue][2 digits Alpha]
. With digit 0 ... f.3 digits #[R][G][B]
........ represents#[RR][GG][BB]FF
#[R][G][B][A]
..... represents#[RR][GG][BB][AA]
#[RR][GG][BB]
..... represents#[RR][GG][BB]FF
#[RR][GG][BB][AA]
. represents#[RR][GG][BB][AA]
Becareful ! In java.awt.Color hex
#[2 digits Alpha][2 digits Red][2 digits Green][2 digits Blue]
Since this method is defined in CSS.java, it must only take in charge CSS Level 4 color format.
As explained in the code, the current OpenJDK implementation follows CSS1 Recommandation
#[R][G][B]
represents#[RR][GG][BB]FF
#[R][G][B]
represents#[RR][GG][BB]FF
JDK-4895924 : Strings in format #rgb not handled by Color.decode() (affects CSS / Swing)
JDK-4895924 : Strings in format #rgb not handled by Color.decode() (affects CSS / Swing)
The text was updated successfully, but these errors were encountered: