Commit 82811e91 by Aaron Leung

Correctly printing out colors with an alpha channel.

parent 6538833f
...@@ -158,35 +158,46 @@ namespace Sass { ...@@ -158,35 +158,46 @@ namespace Sass {
} break; } break;
case numeric_color: { case numeric_color: {
double a = at(0).content.numeric_value; if (size() == 3 || (size() == 4 && at(3).content.numeric_value >= 0xff)) {
double b = at(1).content.numeric_value; double a = at(0).content.numeric_value;
double c = at(2).content.numeric_value; double b = at(1).content.numeric_value;
if (a >= 0xff && b >= 0xff && c >= 0xff) double c = at(2).content.numeric_value;
{ return "white"; } if (a >= 0xff && b >= 0xff && c >= 0xff)
else if (a >= 0xff && b >= 0xff && c == 0) { return "white"; }
{ return "yellow"; } else if (a >= 0xff && b >= 0xff && c == 0)
else if (a == 0 && b >= 0xff && c >= 0xff) { return "yellow"; }
{ return "aqua"; } else if (a == 0 && b >= 0xff && c >= 0xff)
else if (a >= 0xff && b == 0 && c >= 0xff) { return "aqua"; }
{ return "fuchsia"; } else if (a >= 0xff && b == 0 && c >= 0xff)
else if (a >= 0xff && b == 0 && c == 0) { return "fuchsia"; }
{ return "red"; } else if (a >= 0xff && b == 0 && c == 0)
else if (a == 0 && b >= 0xff && c == 0) { return "red"; }
{ return "lime"; } else if (a == 0 && b >= 0xff && c == 0)
else if (a == 0 && b == 0 && c >= 0xff) { return "lime"; }
{ return "blue"; } else if (a == 0 && b == 0 && c >= 0xff)
else if (a <= 0 && b <= 0 && c <= 0) { return "blue"; }
{ return "black"; } else if (a <= 0 && b <= 0 && c <= 0)
else { return "black"; }
{ else
{
stringstream ss;
ss << '#' << std::setw(2) << std::setfill('0') << std::hex;
for (int i = 0; i < 3; ++i) {
double x = at(i).content.numeric_value;
if (x > 0xff) x = 0xff;
else if (x < 0) x = 0;
ss << std::hex << std::setw(2) << static_cast<unsigned long>(x);
}
return ss.str();
}
}
else {
stringstream ss; stringstream ss;
ss << '#' << std::setw(2) << std::setfill('0') << std::hex; ss << "rgba(" << at(0).content.numeric_value;
for (int i = 0; i < 3; ++i) { for (int i = 1; i < 4; ++i) {
double x = at(i).content.numeric_value; ss << ", " << at(i).content.numeric_value;
if (x > 0xff) x = 0xff;
else if (x < 0) x = 0;
ss << std::hex << std::setw(2) << static_cast<unsigned long>(x);
} }
ss << ')';
return ss.str(); return ss.str();
} }
} break; } break;
......
div {
color: rgb(255, $blue: 0, $green: 255);
background: rgb(123, 45, 6);
flah: rgba(0, 0, 0, 1) + #111;
grah: rgba(#fff, .5);
blah: rgba(1,2,3,.6);
}
div {
color: yellow;
background: #7b2d06;
flah: #111111;
grah: rgba(255, 255, 255, 0.5);
blah: rgba(1, 2, 3, 0.6); }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment