From 23aa9cd7d8154c822335531f0619acce43f544b8 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Tue, 2 Dec 2008 13:57:35 +0000 Subject: Something approximating clip svn path=/trunk/libcss/; revision=5870 --- docs/Bytecode | 31 ++++++++----- src/bytecode/opcodes.h | 8 +++- src/parse/properties.c | 113 +++++++++++++++++++++++++++++++++++++++++++++--- src/parse/propstrings.h | 3 +- 4 files changed, 138 insertions(+), 17 deletions(-) diff --git a/docs/Bytecode b/docs/Bytecode index 552fc30..37a1a27 100644 --- a/docs/Bytecode +++ b/docs/Bytecode @@ -7,7 +7,7 @@ Format [] is 32 bits wide: - bits 18-13: value + bits 18-31: value bits 10-17 : flags bits 0-9 : opcode @@ -78,14 +78,6 @@ CSS colours are stored as one 32bit value: bits 8-15 : Blue component bits 0-7 : Alpha component -CSS shapes are stored as one 32bit value followed by n CSS dimensions: - - bits 1-31: MBZ - bit 0 : clear => rect, 4 dimensions follow - set => reserved for future expansion - - TODO: how to handle "auto"? - Shorthand properties -------------------- @@ -289,11 +281,30 @@ Opcodes bits 8-13: MBZ bits 0-7: bit 7 set => shape follows - bits 0-6: MBZ + bits 0-2: 000 => rect, + bit 3 => top auto + bit 4 => right auto + bit 5 => bottom auto + bit 6 => left auto + other => rffe. + bits 3-6: MBZ. + bit 7 clear => keywords: bits 0-6: 0000000 => auto, other => rffe. + If the value is rect(top, right, bottom, left), then bits 3-6 encode + which of , , , is set to auto. The + subsequent parameter list is then 4 - entries long. + Each entry is a dimension. Entries are always ordered top, right, + bottom, left. + + For example, + clip: rect(10px, auto, auto, 10px) + would produce the following bytecode: + + <02c0000e> <0000000a> <00000000> <0000000a> <00000000> + 0f - color (14bits) : bits 8-13: MBZ diff --git a/src/bytecode/opcodes.h b/src/bytecode/opcodes.h index 9565225..330489e 100644 --- a/src/bytecode/opcodes.h +++ b/src/bytecode/opcodes.h @@ -122,7 +122,13 @@ enum op_clear { }; enum op_clip { - CLIP_SHAPE = 0x0080, + CLIP_SHAPE_RECT = 0x0080, + + CLIP_RECT_TOP_AUTO = 0x0008, + CLIP_RECT_RIGHT_AUTO = 0x0010, + CLIP_RECT_BOTTOM_AUTO = 0x0020, + CLIP_RECT_LEFT_AUTO = 0x0040, + CLIP_AUTO = 0x0000, }; diff --git a/src/parse/properties.c b/src/parse/properties.c index b531f90..9f6e69a 100644 --- a/src/parse/properties.c +++ b/src/parse/properties.c @@ -1319,11 +1319,114 @@ css_error parse_clip(css_language *c, const parserutils_vector *vector, int *ctx, css_style **result) { - /** \todo clip */ - UNUSED(c); - UNUSED(vector); - UNUSED(ctx); - UNUSED(result); + css_error error; + const css_token *token; + uint8_t flags = 0; + uint16_t value = 0; + uint32_t opv; + int num_lengths = 0; + fixed length[4] = { 0 }; + uint32_t unit[4] = { 0 }; + uint32_t required_size; + + /* FUNCTION(rect) [ [ IDENT(auto) | length ] CHAR(,)? ]{3} + * [ IDENT(auto) | length ] CHAR{)} | + * IDENT(auto, inherit) */ + token = parserutils_vector_iterate(vector, ctx); + if (token == NULL) + return CSS_INVALID; + + if (token->type == CSS_TOKEN_IDENT && + token->ilower == c->strings[INHERIT]) { + flags = FLAG_INHERIT; + } else if (token->type == CSS_TOKEN_IDENT && + token->ilower == c->strings[AUTO]) { + value = CLIP_AUTO; + } else if (token->type == CSS_TOKEN_FUNCTION && + token->ilower == c->strings[RECT]) { + value = CLIP_SHAPE_RECT; + + consumeWhitespace(vector, ctx); + + for (int i = 0; i < 4; i++) { + token = parserutils_vector_peek(vector, *ctx); + if (token == NULL) + return CSS_INVALID; + + if (token->type == CSS_TOKEN_IDENT) { + /* Slightly magical way of generating the auto + * values. These are bits 3-6 of the value. */ + if (token->ilower == c->strings[AUTO]) + value |= (i+1) << 3; + else + return CSS_INVALID; + } else { + error = parse_unit_specifier(c, vector, ctx, + &length[i], &unit[i]); + if (error != CSS_OK) + return error; + + if (unit[i] & UNIT_ANGLE || + unit[i] & UNIT_TIME || + unit[i] & UNIT_FREQ || + unit[i] & UNIT_PCT) + return CSS_INVALID; + + num_lengths++; + } + + consumeWhitespace(vector, ctx); + + /* Consume optional comma after first 3 parameters */ + if (i < 3) { + token = parserutils_vector_peek(vector, *ctx); + if (token == NULL) + return CSS_INVALID; + + if (tokenIsChar(token, ',')) + parserutils_vector_iterate(vector, ctx); + } + } + + consumeWhitespace(vector, ctx); + + /* Finally, consume closing parenthesis */ + token = parserutils_vector_iterate(vector, ctx); + if (token == NULL || tokenIsChar(token, ')') == false) + return CSS_INVALID; + } else { + return CSS_INVALID; + } + + error = parse_important(c, vector, ctx, &flags); + if (error != CSS_OK) + return error; + + opv = buildOPV(OP_CLIP, flags, value); + + required_size = sizeof(opv); + if ((flags & FLAG_INHERIT) == false && value == CLIP_SHAPE_RECT) { + required_size += + num_lengths * (sizeof(length[0]) + sizeof(unit[0])); + } + + /* Allocate result */ + error = css_stylesheet_style_create(c->sheet, required_size, result); + if (error != CSS_OK) + return error; + + /* Copy the bytecode to it */ + memcpy((*result)->bytecode, &opv, sizeof(opv)); + if ((flags & FLAG_INHERIT) == false && value == CLIP_SHAPE_RECT) { + uint8_t *ptr = ((uint8_t *) (*result)->bytecode) + sizeof(opv); + + for (int i = 0; i < num_lengths; i++) { + memcpy(ptr, &length[i], sizeof(length[i])); + ptr += sizeof(length[i]); + memcpy(ptr, &unit[i], sizeof(unit[i])); + ptr += sizeof(unit[i]); + } + } return CSS_OK; } diff --git a/src/parse/propstrings.h b/src/parse/propstrings.h index 460c426..2942578 100644 --- a/src/parse/propstrings.h +++ b/src/parse/propstrings.h @@ -63,7 +63,7 @@ enum { UPPERCASE, LOWERCASE, EMBED, BIDI_OVERRIDE, BASELINE, SUB, SUPER, TEXT_TOP, MIDDLE, TEXT_BOTTOM, SILENT, X_SOFT, SOFT, LOUD, X_LOUD, PRE, NOWRAP, PRE_WRAP, PRE_LINE, LEFTWARDS, RIGHTWARDS, LEFT_SIDE, - FAR_LEFT, FAR_RIGHT, RIGHT_SIDE, BEHIND, + FAR_LEFT, FAR_RIGHT, RIGHT_SIDE, BEHIND, RECT, LAST_KNOWN }; @@ -312,6 +312,7 @@ static struct { { "far-right", SLEN("far-right") }, { "right-side", SLEN("right-side") }, { "behind", SLEN("behind") }, + { "rect", SLEN("rect") }, }; #endif -- cgit v1.2.3