From bc9c80c2dbf21d805f5372aea3df14d310a1512c Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Tue, 10 Sep 2013 17:44:53 +0100 Subject: Add support for parsing the writing-mode property. Thanks to Caitlin Potter. --- src/bytecode/opcodes.h | 6 ++++ src/parse/properties/properties.gen | 1 + src/parse/properties/properties.h | 3 ++ src/parse/propstrings.c | 4 +++ src/parse/propstrings.h | 5 +-- src/select/computed.h | 2 +- src/select/dispatch.c | 5 +++ src/select/properties/Makefile | 1 + src/select/properties/writing_mode.c | 70 ++++++++++++++++++++++++++++++++++++ src/select/propget.h | 19 ++++++++++ src/select/propset.h | 24 ++++++++++++- 11 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 src/select/properties/writing_mode.c (limited to 'src') diff --git a/src/bytecode/opcodes.h b/src/bytecode/opcodes.h index a0d38d4..544687a 100644 --- a/src/bytecode/opcodes.h +++ b/src/bytecode/opcodes.h @@ -718,6 +718,12 @@ enum op_word_spacing { WORD_SPACING_NORMAL = 0x0000 }; +enum op_writing_mode { + WRITING_MODE_HORIZONTAL_TB = 0x0000, + WRITING_MODE_VERTICAL_RL = 0x0001, + WRITING_MODE_VERTICAL_LR = 0x0002 +}; + enum op_z_index { Z_INDEX_SET = 0x0080, diff --git a/src/parse/properties/properties.gen b/src/parse/properties/properties.gen index 5a4ebe0..80f1a30 100644 --- a/src/parse/properties/properties.gen +++ b/src/parse/properties/properties.gen @@ -212,3 +212,4 @@ column_span:CSS_PROP_COLUMN_SPAN IDENT:( INHERIT: NONE:0,COLUMN_SPAN_NONE ALL:0, column_width:CSS_PROP_COLUMN_WIDTH IDENT:( INHERIT: AUTO:0,COLUMN_WIDTH_AUTO IDENT:) LENGTH_UNIT:( UNIT_PX:COLUMN_WIDTH_SET DISALLOW:unit&UNIT_ANGLE||unit&UNIT_TIME||unit&UNIT_FREQ||unit&UNIT_PCT LENGTH_UNIT:) +writing_mode:CSS_PROP_WRITING_MODE IDENT:( INHERIT: HORIZONTAL_TB:0,WRITING_MODE_HORIZONTAL_TB VERTICAL_RL:0,WRITING_MODE_VERTICAL_RL VERTICAL_LR:0,WRITING_MODE_VERTICAL_LR IDENT:) diff --git a/src/parse/properties/properties.h b/src/parse/properties/properties.h index 7280d93..7c4d8a1 100644 --- a/src/parse/properties/properties.h +++ b/src/parse/properties/properties.h @@ -406,6 +406,9 @@ css_error css__parse_width(css_language *c, css_error css__parse_word_spacing(css_language *c, const parserutils_vector *vector, int *ctx, css_style *result); +css_error css__parse_writing_mode(css_language *c, + const parserutils_vector *vector, int *ctx, + css_style *result); css_error css__parse_z_index(css_language *c, const parserutils_vector *vector, int *ctx, css_style *result); diff --git a/src/parse/propstrings.c b/src/parse/propstrings.c index 35466eb..913241c 100644 --- a/src/parse/propstrings.c +++ b/src/parse/propstrings.c @@ -210,6 +210,7 @@ const stringmap_entry stringmap[LAST_KNOWN] = { { "widows", SLEN("widows") }, { "width", SLEN("width") }, { "word-spacing", SLEN("word-spacing") }, + { "writing-mode", SLEN("writing-mode") }, { "z-index", SLEN("z-index") }, { "inherit", SLEN("inherit") }, @@ -406,6 +407,9 @@ const stringmap_entry stringmap[LAST_KNOWN] = { { "avoid-page", SLEN("avoid_page") }, { "avoid-column", SLEN("avoid-column") }, { "balance", SLEN("balance") }, + { "horizontal-tb", SLEN("horizontal-tb") }, + { "vertical-rl", SLEN("vertical-rl") }, + { "vertical-lr", SLEN("vertical-lr") }, { "aliceblue", SLEN("aliceblue") }, { "antiquewhite", SLEN("antiquewhite") }, diff --git a/src/parse/propstrings.h b/src/parse/propstrings.h index 2ed0743..72a60ae 100644 --- a/src/parse/propstrings.h +++ b/src/parse/propstrings.h @@ -64,7 +64,8 @@ enum { SPEAK_HEADER, SPEAK_NUMERAL, SPEAK_PUNCTUATION, SPEAK, SPEECH_RATE, STRESS, TABLE_LAYOUT, TEXT_ALIGN, TEXT_DECORATION, TEXT_INDENT, TEXT_TRANSFORM, TOP, UNICODE_BIDI, VERTICAL_ALIGN, VISIBILITY, - VOICE_FAMILY, VOLUME, WHITE_SPACE, WIDOWS, WIDTH, WORD_SPACING, Z_INDEX, + VOICE_FAMILY, VOLUME, WHITE_SPACE, WIDOWS, WIDTH, WORD_SPACING, + WRITING_MODE, Z_INDEX, LAST_PROP = Z_INDEX, @@ -96,7 +97,7 @@ enum { LINE_THROUGH, BLINK, RGB, RGBA, HSL, HSLA, LIBCSS_LEFT, LIBCSS_CENTER, LIBCSS_RIGHT, CURRENTCOLOR, ODD, EVEN, SRC, LOCAL, INITIAL, FORMAT, WOFF, TRUETYPE, OPENTYPE, EMBEDDED_OPENTYPE, SVG, COLUMN, - AVOID_PAGE, AVOID_COLUMN, BALANCE, + AVOID_PAGE, AVOID_COLUMN, BALANCE, HORIZONTAL_TB, VERTICAL_RL, VERTICAL_LR, /* Named colours */ FIRST_COLOUR, diff --git a/src/select/computed.h b/src/select/computed.h index f891047..8be3873 100644 --- a/src/select/computed.h +++ b/src/select/computed.h @@ -59,7 +59,7 @@ typedef struct css_computed_uncommon { * 2 ooooooob outline-width | border-spacing * 3 bbbbbbbb border-spacing * 4 wwwwwwir word-spacing | counter-increment | counter-reset - * 5 uuuuu... cursor | + * 5 uuuuumm. cursor | writing-mode | * 6 cccccccc clip * 7 cccccccc clip * 8 ccccccoo clip | content diff --git a/src/select/dispatch.c b/src/select/dispatch.c index 85c1289..03d5c63 100644 --- a/src/select/dispatch.c +++ b/src/select/dispatch.c @@ -572,5 +572,10 @@ struct prop_table prop_dispatch[CSS_N_PROPERTIES] = { PROPERTY_FUNCS(column_width), 0, GROUP_NORMAL + }, + { + PROPERTY_FUNCS(writing_mode), + 0, + GROUP_UNCOMMON } }; diff --git a/src/select/properties/Makefile b/src/select/properties/Makefile index a557846..eacc240 100644 --- a/src/select/properties/Makefile +++ b/src/select/properties/Makefile @@ -110,6 +110,7 @@ white_space.c \ width.c \ windows.c \ word_spacing.c \ +writing_mode.c \ z_index.c include $(NSBUILD)/Makefile.subdir diff --git a/src/select/properties/writing_mode.c b/src/select/properties/writing_mode.c new file mode 100644 index 0000000..3ec1352 --- /dev/null +++ b/src/select/properties/writing_mode.c @@ -0,0 +1,70 @@ +/* + * This file is part of LibCSS + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2009 John-Mark Bell + */ + +#include "bytecode/bytecode.h" +#include "bytecode/opcodes.h" +#include "select/propset.h" +#include "select/propget.h" +#include "utils/utils.h" + +#include "select/properties/properties.h" +#include "select/properties/helpers.h" + +css_error css__cascade_writing_mode(uint32_t opv, css_style *style, + css_select_state *state) +{ + bool inherit = isInherit(opv); + uint16_t writing_mode = CSS_WRITING_MODE_INHERIT; + UNUSED(style); + + if (inherit == false) { + switch (getValue(opv)) { + case WRITING_MODE_HORIZONTAL_TB: + writing_mode = CSS_WRITING_MODE_HORIZONTAL_TB; + break; + case WRITING_MODE_VERTICAL_RL: + writing_mode = CSS_WRITING_MODE_VERTICAL_RL; + break; + case WRITING_MODE_VERTICAL_LR: + writing_mode = CSS_WRITING_MODE_VERTICAL_LR; + break; + } + } + + if (css__outranks_existing(getOpcode(opv), isImportant(opv), state, + inherit)) { + return set_writing_mode(state->computed, writing_mode); + } + + return CSS_OK; +} + +css_error css__set_writing_mode_from_hint(const css_hint *hint, + css_computed_style *style) +{ + return set_writing_mode(style, hint->status); +} + +css_error css__initial_writing_mode(css_select_state *state) +{ + return set_writing_mode(state->computed, + CSS_WRITING_MODE_HORIZONTAL_TB); +} + +css_error css__compose_writing_mode(const css_computed_style *parent, + const css_computed_style *child, + css_computed_style *result) +{ + uint8_t writing_mode = get_writing_mode(child); + + if (writing_mode == CSS_WRITING_MODE_INHERIT) { + writing_mode = get_writing_mode(parent); + } + + return set_writing_mode(result, writing_mode); +} + diff --git a/src/select/propget.h b/src/select/propget.h index 41f6315..16b8fc2 100644 --- a/src/select/propget.h +++ b/src/select/propget.h @@ -174,6 +174,25 @@ static inline uint8_t get_word_spacing( #undef WORD_SPACING_SHIFT #undef WORD_SPACING_INDEX +#define WRITING_MODE_INDEX 4 +#define WRITING_MODE_MASK 0x6 +#define WRITING_MODE_SHIFT 1 +static inline uint8_t get_writing_mode( + const css_computed_style *style) +{ + if (style->uncommon != NULL) { + uint8_t bits = style->uncommon->bits[WRITING_MODE_INDEX]; + bits &= WRITING_MODE_MASK; + bits >>= WRITING_MODE_SHIFT; + return bits; + } + + return CSS_WRITING_MODE_HORIZONTAL_TB; +} +#undef WRITING_MODE_INDEX +#undef WRITING_MODE_MASK +#undef WRITING_MODE_SHIFT + #define COUNTER_INCREMENT_INDEX 3 #define COUNTER_INCREMENT_SHIFT 1 #define COUNTER_INCREMENT_MASK 0x2 diff --git a/src/select/propset.h b/src/select/propset.h index 2b705ae..29e8ae5 100644 --- a/src/select/propset.h +++ b/src/select/propset.h @@ -22,7 +22,7 @@ static const css_computed_uncommon default_uncommon = { 0, (CSS_WORD_SPACING_INHERIT << 2) | (CSS_COUNTER_INCREMENT_NONE << 1) | CSS_COUNTER_RESET_NONE, - (CSS_CURSOR_INHERIT << 3) | 0, + (CSS_CURSOR_INHERIT << 3) | (CSS_WRITING_MODE_INHERIT << 1) | 0, 0, 0, (CSS_CLIP_AUTO << 2) | CSS_CONTENT_NORMAL @@ -214,6 +214,28 @@ static inline css_error set_word_spacing( #undef WORD_SPACING_SHIFT #undef WORD_SPACING_INDEX +#define WRITING_MODE_INDEX 4 +#define WRITING_MODE_SHIFT 1 +#define WRITING_MODE_MASK 0x6 +static inline css_error set_writing_mode( + css_computed_style *style, uint8_t type) +{ + uint8_t *bits; + + ENSURE_UNCOMMON; + + bits = &style->uncommon->bits[WRITING_MODE_INDEX]; + + /* 2bits: type */ + *bits = (*bits & ~WRITING_MODE_MASK) | + ((type & 0x3) << WRITING_MODE_SHIFT); + + return CSS_OK; +} +#undef WRITING_MODE_MASK +#undef WRITING_MODE_SHIFT +#undef WRITING_MODE_INDEX + #define COUNTER_INCREMENT_INDEX 3 #define COUNTER_INCREMENT_SHIFT 1 #define COUNTER_INCREMENT_MASK 0x2 -- cgit v1.2.3