Commit e4af18b0 by Aaron Leung

Giving all colors an alpha channel by default. Will simplify the internals.

parent dd03cb8a
...@@ -127,7 +127,7 @@ namespace Sass { ...@@ -127,7 +127,7 @@ namespace Sass {
} break; } break;
case Node::textual_hex: { case Node::textual_hex: {
Node triple(Node::numeric_color, expr.line_number, 3); Node triple(Node::numeric_color, expr.line_number, 4);
Token hext(Token::make(expr.content.token.begin+1, expr.content.token.end)); Token hext(Token::make(expr.content.token.begin+1, expr.content.token.end));
if (hext.length() == 6) { if (hext.length() == 6) {
for (int i = 0; i < 6; i += 2) { for (int i = 0; i < 6; i += 2) {
...@@ -139,7 +139,8 @@ namespace Sass { ...@@ -139,7 +139,8 @@ namespace Sass {
triple << Node(expr.line_number, static_cast<double>(std::strtol(string(2, hext.begin[i]).c_str(), NULL, 16))); triple << Node(expr.line_number, static_cast<double>(std::strtol(string(2, hext.begin[i]).c_str(), NULL, 16)));
} }
} }
return triple; triple << Node(expr.line_number, 1.0);
return triple;
} break; } break;
case Node::variable: { case Node::variable: {
...@@ -194,11 +195,12 @@ namespace Sass { ...@@ -194,11 +195,12 @@ namespace Sass {
// TO DO: find a way to merge the following two clauses // TO DO: find a way to merge the following two clauses
else if (lhs.type == Node::number && rhs.type == Node::numeric_color) { else if (lhs.type == Node::number && rhs.type == Node::numeric_color) {
if (op != Node::sub && op != Node::div) { if (op != Node::sub && op != Node::div) {
double h1 = operate(op, lhs.content.numeric_value, rhs[0].content.numeric_value); // TO DO: check that alphas match
double h2 = operate(op, lhs.content.numeric_value, rhs[1].content.numeric_value); double r = operate(op, lhs.content.numeric_value, rhs[0].content.numeric_value);
double h3 = operate(op, lhs.content.numeric_value, rhs[2].content.numeric_value); double g = operate(op, lhs.content.numeric_value, rhs[1].content.numeric_value);
double b = operate(op, lhs.content.numeric_value, rhs[2].content.numeric_value);
acc.content.children->pop_back(); acc.content.children->pop_back();
acc << Node(acc.line_number, h1, h2, h3); acc << Node(acc.line_number, r, g, b);
} }
// trying to handle weird edge cases ... not sure if it's worth it // trying to handle weird edge cases ... not sure if it's worth it
else if (op == Node::div) { else if (op == Node::div) {
...@@ -214,18 +216,18 @@ namespace Sass { ...@@ -214,18 +216,18 @@ namespace Sass {
} }
} }
else if (lhs.type == Node::numeric_color && rhs.type == Node::number) { else if (lhs.type == Node::numeric_color && rhs.type == Node::number) {
double h1 = operate(op, lhs[0].content.numeric_value, rhs.content.numeric_value); double r = operate(op, lhs[0].content.numeric_value, rhs.content.numeric_value);
double h2 = operate(op, lhs[1].content.numeric_value, rhs.content.numeric_value); double g = operate(op, lhs[1].content.numeric_value, rhs.content.numeric_value);
double h3 = operate(op, lhs[2].content.numeric_value, rhs.content.numeric_value); double b = operate(op, lhs[2].content.numeric_value, rhs.content.numeric_value);
acc.content.children->pop_back(); acc.content.children->pop_back();
acc << Node(acc.line_number, h1, h2, h3); acc << Node(acc.line_number, r, g, b);
} }
else if (lhs.type == Node::numeric_color && rhs.type == Node::numeric_color) { else if (lhs.type == Node::numeric_color && rhs.type == Node::numeric_color) {
double h1 = operate(op, lhs[0].content.numeric_value, rhs[0].content.numeric_value); double r = operate(op, lhs[0].content.numeric_value, rhs[0].content.numeric_value);
double h2 = operate(op, lhs[1].content.numeric_value, rhs[1].content.numeric_value); double g = operate(op, lhs[1].content.numeric_value, rhs[1].content.numeric_value);
double h3 = operate(op, lhs[2].content.numeric_value, rhs[2].content.numeric_value); double b = operate(op, lhs[2].content.numeric_value, rhs[2].content.numeric_value);
acc.content.children->pop_back(); acc.content.children->pop_back();
acc << Node(acc.line_number, h1, h2, h3); acc << Node(acc.line_number, r, g, b);
} }
else { else {
// TO DO: disallow division and multiplication on lists // TO DO: disallow division and multiplication on lists
......
...@@ -158,7 +158,7 @@ namespace Sass { ...@@ -158,7 +158,7 @@ namespace Sass {
} break; } break;
case numeric_color: { case numeric_color: {
if (size() == 3 || (size() == 4 && at(3).content.numeric_value >= 0xff)) { if (at(3).content.numeric_value >= 1.0) {
double a = at(0).content.numeric_value; double a = at(0).content.numeric_value;
double b = at(1).content.numeric_value; double b = at(1).content.numeric_value;
double c = at(2).content.numeric_value; double c = at(2).content.numeric_value;
......
...@@ -182,16 +182,17 @@ namespace Sass { ...@@ -182,16 +182,17 @@ namespace Sass {
content.dimension.unit = tok.begin; content.dimension.unit = tok.begin;
} }
Node(unsigned int ln, double r, double g, double b) // colors Node(unsigned int ln, double r, double g, double b, double a = 1.0) // colors
{ {
clear(); clear();
type = numeric_color; type = numeric_color;
line_number = ln; line_number = ln;
content.children = new vector<Node>; content.children = new vector<Node>;
content.children->reserve(3); content.children->reserve(4);
content.children->push_back(Node(ln, r)); content.children->push_back(Node(ln, r));
content.children->push_back(Node(ln, g)); content.children->push_back(Node(ln, g));
content.children->push_back(Node(ln, b)); content.children->push_back(Node(ln, b));
content.children->push_back(Node(ln, a));
has_children = true; has_children = true;
++allocations; ++allocations;
} }
......
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