Skip to content

Commit 98a7403

Browse files
committed
add support for 4 and 8 digit colors. #61
1 parent 8ffb04c commit 98a7403

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

src/com/inet/lib/less/ValueExpression.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,21 @@ private void eval( CssFormatter formatter ) {
214214
}
215215
unit = "";
216216
long rgb;
217+
long alpha = ALPHA_1;
217218
if( str.startsWith( "#" ) ) {
218219
str = str.substring( 1 );
219220
switch( str.length() ) {
221+
case 4:
222+
{
223+
char ch = str.charAt( 3 );
224+
int digit = Character.digit( ch, 16 );
225+
if( digit < 0 ) {
226+
type = STRING;
227+
return;
228+
}
229+
alpha = digit * 0x1111 << 48;
230+
}
231+
//$FALL-THROUGH$
220232
case 3:
221233
rgb = 0;
222234
for( int i = 0; i < 3; i++ ) {
@@ -231,6 +243,24 @@ private void eval( CssFormatter formatter ) {
231243
rgb *= 0x100;
232244
}
233245
break;
246+
case 8:
247+
{
248+
char ch = str.charAt( 6 );
249+
int digit = Character.digit( ch, 16 );
250+
if( digit < 0 ) {
251+
type = STRING;
252+
return;
253+
}
254+
rgb = digit * 16;
255+
ch = str.charAt( 7 );
256+
digit = Character.digit( ch, 16 );
257+
if( digit < 0 ) {
258+
type = STRING;
259+
return;
260+
}
261+
alpha = (rgb + digit) * 0x101 << 48;
262+
}
263+
//$FALL-THROUGH$
234264
case 6:
235265
rgb = 0;
236266
for( int i = 0; i < 6; i++ ) {
@@ -298,7 +328,7 @@ private void eval( CssFormatter formatter ) {
298328
}
299329
}
300330
}
301-
value = Double.longBitsToDouble( ALPHA_1 | rgb );
331+
value = Double.longBitsToDouble( alpha | rgb );
302332
type = COLOR;
303333
} catch( NumberFormatException e ) {
304334
type = STRING;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
colors {
2+
a: #000A;
3+
b: #001122AA;
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
colors {
2+
a: #000A;
3+
b: #001122AA;
4+
}

0 commit comments

Comments
 (0)