Skip to content

Commit

Permalink
Merge pull request sass#515 from benesch/filter-effects-functions
Browse files Browse the repository at this point in the history
support colliding CSS filter effects functions
  • Loading branch information
HamptonMakes committed Oct 8, 2014
2 parents 859d11d + 46769e9 commit 0aa1495
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 34 deletions.
14 changes: 7 additions & 7 deletions color_names.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ namespace Sass {
"darkblue",
"darkcyan",
"darkgoldenrod",
"darkgray",
"darkgrey",
"darkgray",
"darkgreen",
"darkkhaki",
"darkmagenta",
Expand All @@ -40,14 +40,14 @@ namespace Sass {
"darksalmon",
"darkseagreen",
"darkslateblue",
"darkslategray",
"darkslategrey",
"darkslategray",
"darkturquoise",
"darkviolet",
"deeppink",
"deepskyblue",
"dimgray",
"dimgrey",
"dimgray",
"dodgerblue",
"firebrick",
"floralwhite",
Expand All @@ -57,8 +57,8 @@ namespace Sass {
"ghostwhite",
"gold",
"goldenrod",
"gray",
"grey",
"gray",
"green",
"greenyellow",
"honeydew",
Expand All @@ -75,15 +75,15 @@ namespace Sass {
"lightcoral",
"lightcyan",
"lightgoldenrodyellow",
"lightgray",
"lightgrey",
"lightgray",
"lightgreen",
"lightpink",
"lightsalmon",
"lightseagreen",
"lightskyblue",
"lightslategray",
"lightslategrey",
"lightslategray",
"lightsteelblue",
"lightyellow",
"lime",
Expand Down Expand Up @@ -135,8 +135,8 @@ namespace Sass {
"silver",
"skyblue",
"slateblue",
"slategray",
"slategrey",
"slategray",
"snow",
"springgreen",
"steelblue",
Expand Down
59 changes: 38 additions & 21 deletions functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,18 @@ namespace Sass {
position);
}

Signature saturate_sig = "saturate($color, $amount)";
Signature saturate_sig = "saturate($color, $amount: false)";
BUILT_IN(saturate)
{
// CSS3 filter function overload: pass literal through directly
Number* amount = dynamic_cast<Number*>(env["$amount"]);
if (!amount) {
To_String to_string(&ctx);
return new (ctx.mem) String_Constant(path, position, "saturate(" + env["$color"]->perform(&to_string) + ")");
}

ARGR("$amount", Number, 0, 100);
Color* rgb_color = ARG("$color", Color);
Number* amount = ARGR("$amount", Number, 0, 100);
HSL hsl_color = rgb_to_hsl(rgb_color->r(),
rgb_color->g(),
rgb_color->b());
Expand Down Expand Up @@ -409,6 +416,13 @@ namespace Sass {
Signature grayscale_sig = "grayscale($color)";
BUILT_IN(grayscale)
{
// CSS3 filter function overload: pass literal through directly
Number* amount = dynamic_cast<Number*>(env["$color"]);
if (amount) {
To_String to_string(&ctx);
return new (ctx.mem) String_Constant(path, position, "grayscale(" + amount->perform(&to_string) + ")");
}

Color* rgb_color = ARG("$color", Color);
HSL hsl_color = rgb_to_hsl(rgb_color->r(),
rgb_color->g(),
Expand Down Expand Up @@ -438,26 +452,23 @@ namespace Sass {
position);
}

Signature invert_sig = "invert($value)";
Signature invert_sig = "invert($color)";
BUILT_IN(invert)
{
Expression* v = ARG("$value", Expression);
if (v->concrete_type() == Expression::NUMBER) {
To_String to_string;
String_Constant* str = new String_Constant(path,
position,
v->perform(&to_string));
return new (ctx.mem) String_Constant(path, position, "invert(" + str->value() + ")");
}
else {
Color* rgb_color = static_cast<Color*>(v);
return new (ctx.mem) Color(path,
position,
255 - rgb_color->r(),
255 - rgb_color->g(),
255 - rgb_color->b(),
rgb_color->a());
// CSS3 filter function overload: pass literal through directly
Number* amount = dynamic_cast<Number*>(env["$color"]);
if (amount) {
To_String to_string(&ctx);
return new (ctx.mem) String_Constant(path, position, "invert(" + amount->perform(&to_string) + ")");
}

Color* rgb_color = ARG("$color", Color);
return new (ctx.mem) Color(path,
position,
255 - rgb_color->r(),
255 - rgb_color->g(),
255 - rgb_color->b(),
rgb_color->a());
}

////////////////////
Expand All @@ -471,9 +482,15 @@ namespace Sass {
if (ie_kwd) {
return new (ctx.mem) String_Constant(path, position, "alpha(" + ie_kwd->value() + ")");
}
else {
return new (ctx.mem) Number(path, position, ARG("$color", Color)->a());

// CSS3 filter function overload: pass literal through directly
Number* amount = dynamic_cast<Number*>(env["$color"]);
if (amount) {
To_String to_string(&ctx);
return new (ctx.mem) String_Constant(path, position, "opacity(" + amount->perform(&to_string) + ")");
}

return new (ctx.mem) Number(path, position, ARG("$color", Color)->a());
}

Signature opacify_sig = "opacify($color, $amount)";
Expand Down
12 changes: 6 additions & 6 deletions inspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,9 @@ namespace Sass {
void Inspect::operator()(Color* c)
{
stringstream ss;
double r = cap_channel<0xff>(c->r());
double g = cap_channel<0xff>(c->g());
double b = cap_channel<0xff>(c->b());
double r = round(cap_channel<0xff>(c->r()));
double g = round(cap_channel<0xff>(c->g()));
double b = round(cap_channel<0xff>(c->b()));
double a = cap_channel<1> (c->a());

// if (a >= 1 && ctx.colors_to_names.count(numval)) {
Expand All @@ -360,9 +360,9 @@ namespace Sass {
else {
// otherwise output the hex triplet
ss << '#' << setw(2) << setfill('0');
ss << hex << setw(2) << static_cast<unsigned long>(floor(r+0.5));
ss << hex << setw(2) << static_cast<unsigned long>(floor(g+0.5));
ss << hex << setw(2) << static_cast<unsigned long>(floor(b+0.5));
ss << hex << setw(2) << static_cast<unsigned long>(r);
ss << hex << setw(2) << static_cast<unsigned long>(g);
ss << hex << setw(2) << static_cast<unsigned long>(b);
}
}
else {
Expand Down

0 comments on commit 0aa1495

Please sign in to comment.