From 59caf847183261bf31ac75e5e1ab7d819480ffee Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Wed, 1 Apr 2009 17:35:29 +0000 Subject: Support named colours. Fix malformed declaration test data -- everything up to and including the next semicolon is dropped on the floor. svn path=/trunk/libcss/; revision=7020 --- src/parse/properties.c | 183 +++++++++++++++++++++++++++++++++++++++++++++-- src/parse/propstrings.h | 184 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 360 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/parse/properties.c b/src/parse/properties.c index c40b223..d08d23a 100644 --- a/src/parse/properties.c +++ b/src/parse/properties.c @@ -5,8 +5,8 @@ * Copyright 2008 John-Mark Bell */ -#ifndef css_parse_css21props_c_ -#define css_parse_css21props_c_ +#ifndef css_parse_properties_c_ +#define css_parse_properties_c_ #include "bytecode/bytecode.h" #include "bytecode/opcodes.h" @@ -315,6 +315,8 @@ static inline css_error parse_important(css_language *c, static inline css_error parse_colour_specifier(css_language *c, const parserutils_vector *vector, int *ctx, uint32_t *result); +static css_error parse_named_colour(css_language *c, lwc_string *data, + uint32_t *result); static inline css_error parse_hash_colour(lwc_string *data, uint32_t *result); static inline css_error parse_unit_specifier(css_language *c, const parserutils_vector *vector, int *ctx, @@ -6631,14 +6633,14 @@ css_error parse_colour_specifier(css_language *c, } if (token->type == CSS_TOKEN_IDENT) { - /** \todo Parse colour names */ - - if (c->sheet->quirks_allowed) { + error = parse_named_colour(c, token->idata, result); + if (error != CSS_OK && c->sheet->quirks_allowed) { error = parse_hash_colour(token->idata, result); if (error == CSS_OK) c->sheet->quirks_used = true; - return error; } + + return error; } else if (token->type == CSS_TOKEN_HASH) { return parse_hash_colour(token->idata, result); } else if (c->sheet->quirks_allowed && @@ -6722,6 +6724,175 @@ css_error parse_colour_specifier(css_language *c, return CSS_OK; } +css_error parse_named_colour(css_language *c, lwc_string *data, + uint32_t *result) +{ + static const uint32_t colourmap[LAST_COLOUR + 1 - FIRST_COLOUR] = { + 0xf0f8ff00, /* ALICEBLUE */ + 0xfaebd700, /* ANTIQUEWHITE */ + 0x00ffff00, /* AQUA */ + 0x7fffd400, /* AQUAMARINE */ + 0xf0ffff00, /* AZURE */ + 0xf5f5dc00, /* BEIGE */ + 0xffe4c400, /* BISQUE */ + 0x00000000, /* BLACK */ + 0xffebcd00, /* BLANCHEDALMOND */ + 0x0000ff00, /* BLUE */ + 0x8a2be200, /* BLUEVIOLET */ + 0xa52a2a00, /* BROWN */ + 0xdeb88700, /* BURLYWOOD */ + 0x5f9ea000, /* CADETBLUE */ + 0x7fff0000, /* CHARTREUSE */ + 0xd2691e00, /* CHOCOLATE */ + 0xff7f5000, /* CORAL */ + 0x6495ed00, /* CORNFLOWERBLUE */ + 0xfff8dc00, /* CORNSILK */ + 0xdc143c00, /* CRIMSON */ + 0x00ffff00, /* CYAN */ + 0x00008b00, /* DARKBLUE */ + 0x008b8b00, /* DARKCYAN */ + 0xb8860b00, /* DARKGOLDENROD */ + 0xa9a9a900, /* DARKGRAY */ + 0x00640000, /* DARKGREEN */ + 0xa9a9a900, /* DARKGREY */ + 0xbdb76b00, /* DARKKHAKI */ + 0x8b008b00, /* DARKMAGENTA */ + 0x556b2f00, /* DARKOLIVEGREEN */ + 0xff8c0000, /* DARKORANGE */ + 0x9932cc00, /* DARKORCHID */ + 0x8b000000, /* DARKRED */ + 0xe9967a00, /* DARKSALMON */ + 0x8fbc8f00, /* DARKSEAGREEN */ + 0x483d8b00, /* DARKSLATEBLUE */ + 0x2f4f4f00, /* DARKSLATEGRAY */ + 0x2f4f4f00, /* DARKSLATEGREY */ + 0x00ced100, /* DARKTURQUOISE */ + 0x9400d300, /* DARKVIOLET */ + 0xff149300, /* DEEPPINK */ + 0x00bfff00, /* DEEPSKYBLUE */ + 0x69696900, /* DIMGRAY */ + 0x69696900, /* DIMGREY */ + 0x1e90ff00, /* DODGERBLUE */ + 0xd1927500, /* FELDSPAR */ + 0xb2222200, /* FIREBRICK */ + 0xfffaf000, /* FLORALWHITE */ + 0x228b2200, /* FORESTGREEN */ + 0xff00ff00, /* FUCHSIA */ + 0xdcdcdc00, /* GAINSBORO */ + 0xf8f8ff00, /* GHOSTWHITE */ + 0xffd70000, /* GOLD */ + 0xdaa52000, /* GOLDENROD */ + 0x80808000, /* GRAY */ + 0x00800000, /* GREEN */ + 0xadff2f00, /* GREENYELLOW */ + 0x80808000, /* GREY */ + 0xf0fff000, /* HONEYDEW */ + 0xff69b400, /* HOTPINK */ + 0xcd5c5c00, /* INDIANRED */ + 0x4b008200, /* INDIGO */ + 0xfffff000, /* IVORY */ + 0xf0e68c00, /* KHAKI */ + 0xe6e6fa00, /* LAVENDER */ + 0xfff0f500, /* LAVENDERBLUSH */ + 0x7cfc0000, /* LAWNGREEN */ + 0xfffacd00, /* LEMONCHIFFON */ + 0xadd8e600, /* LIGHTBLUE */ + 0xf0808000, /* LIGHTCORAL */ + 0xe0ffff00, /* LIGHTCYAN */ + 0xfafad200, /* LIGHTGOLDENRODYELLOW */ + 0xd3d3d300, /* LIGHTGRAY */ + 0x90ee9000, /* LIGHTGREEN */ + 0xd3d3d300, /* LIGHTGREY */ + 0xffb6c100, /* LIGHTPINK */ + 0xffa07a00, /* LIGHTSALMON */ + 0x20b2aa00, /* LIGHTSEAGREEN */ + 0x87cefa00, /* LIGHTSKYBLUE */ + 0x8470ff00, /* LIGHTSLATEBLUE */ + 0x77889900, /* LIGHTSLATEGRAY */ + 0x77889900, /* LIGHTSLATEGREY */ + 0xb0c4de00, /* LIGHTSTEELBLUE */ + 0xffffe000, /* LIGHTYELLOW */ + 0x00ff0000, /* LIME */ + 0x32cd3200, /* LIMEGREEN */ + 0xfaf0e600, /* LINEN */ + 0xff00ff00, /* MAGENTA */ + 0x80000000, /* MAROON */ + 0x66cdaa00, /* MEDIUMAQUAMARINE */ + 0x0000cd00, /* MEDIUMBLUE */ + 0xba55d300, /* MEDIUMORCHID */ + 0x9370db00, /* MEDIUMPURPLE */ + 0x3cb37100, /* MEDIUMSEAGREEN */ + 0x7b68ee00, /* MEDIUMSLATEBLUE */ + 0x00fa9a00, /* MEDIUMSPRINGGREEN */ + 0x48d1cc00, /* MEDIUMTURQUOISE */ + 0xc7158500, /* MEDIUMVIOLETRED */ + 0x19197000, /* MIDNIGHTBLUE */ + 0xf5fffa00, /* MINTCREAM */ + 0xffe4e100, /* MISTYROSE */ + 0xffe4b500, /* MOCCASIN */ + 0xffdead00, /* NAVAJOWHITE */ + 0x00008000, /* NAVY */ + 0xfdf5e600, /* OLDLACE */ + 0x80800000, /* OLIVE */ + 0x6b8e2300, /* OLIVEDRAB */ + 0xffa50000, /* ORANGE */ + 0xff450000, /* ORANGERED */ + 0xda70d600, /* ORCHID */ + 0xeee8aa00, /* PALEGOLDENROD */ + 0x98fb9800, /* PALEGREEN */ + 0xafeeee00, /* PALETURQUOISE */ + 0xdb709300, /* PALEVIOLETRED */ + 0xffefd500, /* PAPAYAWHIP */ + 0xffdab900, /* PEACHPUFF */ + 0xcd853f00, /* PERU */ + 0xffc0cb00, /* PINK */ + 0xdda0dd00, /* PLUM */ + 0xb0e0e600, /* POWDERBLUE */ + 0x80008000, /* PURPLE */ + 0xff000000, /* RED */ + 0xbc8f8f00, /* ROSYBROWN */ + 0x4169e100, /* ROYALBLUE */ + 0x8b451300, /* SADDLEBROWN */ + 0xfa807200, /* SALMON */ + 0xf4a46000, /* SANDYBROWN */ + 0x2e8b5700, /* SEAGREEN */ + 0xfff5ee00, /* SEASHELL */ + 0xa0522d00, /* SIENNA */ + 0xc0c0c000, /* SILVER */ + 0x87ceeb00, /* SKYBLUE */ + 0x6a5acd00, /* SLATEBLUE */ + 0x70809000, /* SLATEGRAY */ + 0x70809000, /* SLATEGREY */ + 0xfffafa00, /* SNOW */ + 0x00ff7f00, /* SPRINGGREEN */ + 0x4682b400, /* STEELBLUE */ + 0xd2b48c00, /* TAN */ + 0x00808000, /* TEAL */ + 0xd8bfd800, /* THISTLE */ + 0xff634700, /* TOMATO */ + 0x40e0d000, /* TURQUOISE */ + 0xee82ee00, /* VIOLET */ + 0xd0209000, /* VIOLETRED */ + 0xf5deb300, /* WHEAT */ + 0xffffff00, /* WHITE */ + 0xf5f5f500, /* WHITESMOKE */ + 0xffff0000, /* YELLOW */ + 0x9acd3200 /* YELLOWGREEN */ + }; + int i; + + for (i = FIRST_COLOUR; i <= LAST_COLOUR; i++) { + if (data == c->strings[i]) + break; + } + if (i == LAST_COLOUR + 1) + return CSS_INVALID; + + *result = colourmap[i - FIRST_COLOUR]; + + return CSS_OK; +} + css_error parse_hash_colour(lwc_string *data, uint32_t *result) { uint8_t r = 0, g = 0, b = 0; diff --git a/src/parse/propstrings.h b/src/parse/propstrings.h index 10c394a..884fe75 100644 --- a/src/parse/propstrings.h +++ b/src/parse/propstrings.h @@ -82,6 +82,37 @@ enum { FANTASY, MONOSPACE, MALE, FEMALE, CHILD, MIX, UNDERLINE, OVERLINE, LINE_THROUGH, BLINK, RGB, + /* Named colours */ + FIRST_COLOUR, + + ALICEBLUE = FIRST_COLOUR, ANTIQUEWHITE, AQUA, AQUAMARINE, AZURE, + BEIGE, BISQUE, BLACK, BLANCHEDALMOND, BLUE, BLUEVIOLET, BROWN, + BURLYWOOD, CADETBLUE, CHARTREUSE, CHOCOLATE, CORAL, CORNFLOWERBLUE, + CORNSILK, CRIMSON, CYAN, DARKBLUE, DARKCYAN, DARKGOLDENROD, DARKGRAY, + DARKGREEN, DARKGREY, DARKKHAKI, DARKMAGENTA, DARKOLIVEGREEN, DARKORANGE, + DARKORCHID, DARKRED, DARKSALMON, DARKSEAGREEN, DARKSLATEBLUE, + DARKSLATEGRAY, DARKSLATEGREY, DARKTURQUOISE, DARKVIOLET, DEEPPINK, + DEEPSKYBLUE, DIMGRAY, DIMGREY, DODGERBLUE, FELDSPAR, FIREBRICK, + FLORALWHITE, FORESTGREEN, FUCHSIA, GAINSBORO, GHOSTWHITE, GOLD, + GOLDENROD, GRAY, GREEN, GREENYELLOW, GREY, HONEYDEW, HOTPINK, + INDIANRED, INDIGO, IVORY, KHAKI, LAVENDER, LAVENDERBLUSH, LAWNGREEN, + LEMONCHIFFON, LIGHTBLUE, LIGHTCORAL, LIGHTCYAN, LIGHTGOLDENRODYELLOW, + LIGHTGRAY, LIGHTGREEN, LIGHTGREY, LIGHTPINK, LIGHTSALMON, LIGHTSEAGREEN, + LIGHTSKYBLUE, LIGHTSLATEBLUE, LIGHTSLATEGRAY, LIGHTSLATEGREY, + LIGHTSTEELBLUE, LIGHTYELLOW, LIME, LIMEGREEN, LINEN, MAGENTA, MAROON, + MEDIUMAQUAMARINE, MEDIUMBLUE, MEDIUMORCHID, MEDIUMPURPLE, + MEDIUMSEAGREEN, MEDIUMSLATEBLUE, MEDIUMSPRINGGREEN, MEDIUMTURQUOISE, + MEDIUMVIOLETRED, MIDNIGHTBLUE, MINTCREAM, MISTYROSE, MOCCASIN, + NAVAJOWHITE, NAVY, OLDLACE, OLIVE, OLIVEDRAB, ORANGE, ORANGERED, + ORCHID, PALEGOLDENROD, PALEGREEN, PALETURQUOISE, PALEVIOLETRED, + PAPAYAWHIP, PEACHPUFF, PERU, PINK, PLUM, POWDERBLUE, PURPLE, RED, + ROSYBROWN, ROYALBLUE, SADDLEBROWN, SALMON, SANDYBROWN, SEAGREEN, + SEASHELL, SIENNA, SILVER, SKYBLUE, SLATEBLUE, SLATEGRAY, SLATEGREY, + SNOW, SPRINGGREEN, STEELBLUE, TAN, TEAL, THISTLE, TOMATO, TURQUOISE, + VIOLET, VIOLETRED, WHEAT, WHITE, WHITESMOKE, YELLOW, YELLOWGREEN, + + LAST_COLOUR = YELLOWGREEN, + LAST_KNOWN }; @@ -394,7 +425,158 @@ static struct { { "overline", SLEN("overline") }, { "line-through", SLEN("line-through") }, { "blink", SLEN("blink") }, - { "rgb", SLEN("rgb") } + { "rgb", SLEN("rgb") }, + + { "aliceblue", SLEN("aliceblue") }, + { "antiquewhite", SLEN("antiquewhite") }, + { "aqua", SLEN("aqua") }, + { "aquamarine", SLEN("aquamarine") }, + { "azure", SLEN("azure") }, + { "beige", SLEN("beige") }, + { "bisque", SLEN("bisque") }, + { "black", SLEN("black") }, + { "blanchedalmond", SLEN("blanchedalmond") }, + { "blue", SLEN("blue") }, + { "blueviolet", SLEN("blueviolet") }, + { "brown", SLEN("brown") }, + { "burlywood", SLEN("burlywood") }, + { "cadetblue", SLEN("cadetblue") }, + { "chartreuse", SLEN("chartreuse") }, + { "chocolate", SLEN("chocolate") }, + { "coral", SLEN("coral") }, + { "cornflowerblue", SLEN("cornflowerblue") }, + { "cornsilk", SLEN("cornsilk") }, + { "crimson", SLEN("crimson") }, + { "cyan", SLEN("cyan") }, + { "darkblue", SLEN("darkblue") }, + { "darkcyan", SLEN("darkcyan") }, + { "darkgoldenrod", SLEN("darkgoldenrod") }, + { "darkgray", SLEN("darkgray") }, + { "darkgreen", SLEN("darkgreen") }, + { "darkgrey", SLEN("darkgrey") }, + { "darkkhaki", SLEN("darkkhaki") }, + { "darkmagenta", SLEN("darkmagenta") }, + { "darkolivegreen", SLEN("darkolivegreen") }, + { "darkorange", SLEN("darkorange") }, + { "darkorchid", SLEN("darkorchid") }, + { "darkred", SLEN("darkred") }, + { "darksalmon", SLEN("darksalmon") }, + { "darkseagreen", SLEN("darkseagreen") }, + { "darkslateblue", SLEN("darkslateblue") }, + { "darkslategray", SLEN("darkslategray") }, + { "darkslategrey", SLEN("darkslategrey") }, + { "darkturquoise", SLEN("darkturquoise") }, + { "darkviolet", SLEN("darkviolet") }, + { "deeppink", SLEN("deeppink") }, + { "deepskyblue", SLEN("deepskyblue") }, + { "dimgray", SLEN("dimgray") }, + { "dimgrey", SLEN("dimgrey") }, + { "dodgerblue", SLEN("dodgerblue") }, + { "feldspar", SLEN("feldspar") }, + { "firebrick", SLEN("firebrick") }, + { "floralwhite", SLEN("floralwhite") }, + { "forestgreen", SLEN("forestgreen") }, + { "fuchsia", SLEN("fuchsia") }, + { "gainsboro", SLEN("gainsboro") }, + { "ghostwhite", SLEN("ghostwhite") }, + { "gold", SLEN("gold") }, + { "goldenrod", SLEN("goldenrod") }, + { "gray", SLEN("gray") }, + { "green", SLEN("green") }, + { "greenyellow", SLEN("greenyellow") }, + { "grey", SLEN("grey") }, + { "honeydew", SLEN("honeydew") }, + { "hotpink", SLEN("hotpink") }, + { "indianred", SLEN("indianred") }, + { "indigo", SLEN("indigo") }, + { "ivory", SLEN("ivory") }, + { "khaki", SLEN("khaki") }, + { "lavender", SLEN("lavender") }, + { "lavenderblush", SLEN("lavenderblush") }, + { "lawngreen", SLEN("lawngreen") }, + { "lemonchiffon", SLEN("lemonchiffon") }, + { "lightblue", SLEN("lightblue") }, + { "lightcoral", SLEN("lightcoral") }, + { "lightcyan", SLEN("lightcyan") }, + { "lightgoldenrodyellow", SLEN("lightgoldenrodyellow") }, + { "lightgray", SLEN("lightgray") }, + { "lightgreen", SLEN("lightgreen") }, + { "lightgrey", SLEN("lightgrey") }, + { "lightpink", SLEN("lightpink") }, + { "lightsalmon", SLEN("lightsalmon") }, + { "lightseagreen", SLEN("lightseagreen") }, + { "lightskyblue", SLEN("lightskyblue") }, + { "lightslateblue", SLEN("lightslateblue") }, + { "lightslategray", SLEN("lightslategray") }, + { "lightslategrey", SLEN("lightslategrey") }, + { "lightsteelblue", SLEN("lightsteelblue") }, + { "lightyellow", SLEN("lightyellow") }, + { "lime", SLEN("lime") }, + { "limegreen", SLEN("limegreen") }, + { "linen", SLEN("linen") }, + { "magenta", SLEN("magenta") }, + { "maroon", SLEN("maroon") }, + { "mediumaquamarine", SLEN("mediumaquamarine") }, + { "mediumblue", SLEN("mediumblue") }, + { "mediumorchid", SLEN("mediumorchid") }, + { "mediumpurple", SLEN("mediumpurple") }, + { "mediumseagreen", SLEN("mediumseagreen") }, + { "mediumslateblue", SLEN("mediumslateblue") }, + { "mediumspringgreen", SLEN("mediumspringgreen") }, + { "mediumturquoise", SLEN("mediumturquoise") }, + { "mediumvioletred", SLEN("mediumvioletred") }, + { "midnightblue", SLEN("midnightblue") }, + { "mintcream", SLEN("mintcream") }, + { "mistyrose", SLEN("mistyrose") }, + { "moccasin", SLEN("moccasin") }, + { "navajowhite", SLEN("navajowhite") }, + { "navy", SLEN("navy") }, + { "oldlace", SLEN("oldlace") }, + { "olive", SLEN("olive") }, + { "olivedrab", SLEN("olivedrab") }, + { "orange", SLEN("orange") }, + { "orangered", SLEN("orangered") }, + { "orchid", SLEN("orchid") }, + { "palegoldenrod", SLEN("palegoldenrod") }, + { "palegreen", SLEN("palegreen") }, + { "paleturquoise", SLEN("paleturquoise") }, + { "palevioletred", SLEN("palevioletred") }, + { "papayawhip", SLEN("papayawhip") }, + { "peachpuff", SLEN("peachpuff") }, + { "peru", SLEN("peru") }, + { "pink", SLEN("pink") }, + { "plum", SLEN("plum") }, + { "powderblue", SLEN("powderblue") }, + { "purple", SLEN("purple") }, + { "red", SLEN("red") }, + { "rosybrown", SLEN("rosybrown") }, + { "royalblue", SLEN("royalblue") }, + { "saddlebrown", SLEN("saddlebrown") }, + { "salmon", SLEN("salmon") }, + { "sandybrown", SLEN("sandybrown") }, + { "seagreen", SLEN("seagreen") }, + { "seashell", SLEN("seashell") }, + { "sienna", SLEN("sienna") }, + { "silver", SLEN("silver") }, + { "skyblue", SLEN("skyblue") }, + { "slateblue", SLEN("slateblue") }, + { "slategray", SLEN("slategray") }, + { "slategrey", SLEN("slategrey") }, + { "snow", SLEN("snow") }, + { "springgreen", SLEN("springgreen") }, + { "steelblue", SLEN("steelblue") }, + { "tan", SLEN("tan") }, + { "teal", SLEN("teal") }, + { "thistle", SLEN("thistle") }, + { "tomato", SLEN("tomato") }, + { "turquoise", SLEN("turquoise") }, + { "violet", SLEN("violet") }, + { "violetred", SLEN("violetred") }, + { "wheat", SLEN("wheat") }, + { "white", SLEN("white") }, + { "whitesmoke", SLEN("whitesmoke") }, + { "yellow", SLEN("yellow") }, + { "yellowgreen", SLEN("yellowgreen") } }; #endif -- cgit v1.2.3