diff options
author | Lucas Neves <lcneves@gmail.com> | 2017-10-27 19:41:11 +0000 |
---|---|---|
committer | Lucas Neves <lcneves@gmail.com> | 2017-10-27 19:41:11 +0000 |
commit | 10f5daa91de724edafd79094100787ad3a73a7c4 (patch) | |
tree | 96b3bd89c9caa1fef33cc7f2a954b64cbe1780e0 | |
parent | 577f2f370a636953cc57485cf5cc3e3887c691c9 (diff) | |
download | libcss-10f5daa91de724edafd79094100787ad3a73a7c4.tar.gz |
Add override getter and setter functions for the clip property.
-rw-r--r-- | src/select/computed_properties.py | 140 | ||||
-rw-r--r-- | src/select/overrides.py | 88 |
2 files changed, 106 insertions, 122 deletions
diff --git a/src/select/computed_properties.py b/src/select/computed_properties.py index a9fc0e7..3f87bed 100644 --- a/src/select/computed_properties.py +++ b/src/select/computed_properties.py @@ -11,13 +11,13 @@ def get_tuple(from_var): else: return () -def make_type(name, css_type, size = 0, default = 'NULL', +def make_type(name, css_type, size = None, default = 'NULL', bits_name = None, bits_type = None, bits_size = None, bits_default = 0): return { 'name': name, 'type': css_type, - 'size': size, + 'size': size, # `None` means sizeof(ptr) 'default': default, 'bits': None if bits_name is None else { 'name': bits_name, @@ -51,12 +51,12 @@ def make_property(name, opcode_size, values = None, 'name': name, 'size': opcode_size, 'values': [ types[x] for x in value_tuple ] or None, - 'defaults': default_tuple or None, + 'defaults': default_tuple or None, # May be `None` only for main group 'comments': comments } # Configuration of properties -prop_config = { +style_config = { # Style group, only opcode ('align_content', 3), ('align_items', 3), @@ -140,13 +140,19 @@ prop_config = { '\n' 'blank entry.'), ('quotes', 1, 'string_arr', None, 'Encode quotes as an array of string objects, terminated with a ' - 'blank entry.'), + 'blank entry.') +} + +page_config = { # Page group ('page_break_after', 3, None, 'CSS_PAGE_BREAK_AFTER_AUTO'), ('page_break_before', 3, None, 'CSS_PAGE_BREAK_BEFORE_AUTO'), ('page_break_inside', 2, None, 'CSS_PAGE_BREAK_INSIDE_AUTO'), ('widows', 1, 'integer', ('CSS_WIDOWS_SET', 2)), - ('orphans', 1, 'integer', ('CSS_ORPHANS_SET', 2)), + ('orphans', 1, 'integer', ('CSS_ORPHANS_SET', 2)) +} + +uncommon_config = { # Uncommon group ('border_spacing', 1, ('length', 'length'), ('CSS_BORDER_SPACING_SET', 0, 'CSS_UNIT_PX', 0, 'CSS_UNIT_PX')), @@ -181,121 +187,11 @@ prop_config = { 'a blank entry.') } -properties = [ make_property(*x) for x in prop_config ] +uncommon = [ make_property(*x) for x in uncommon_config ] +page = [ make_property(*x) for x in page_config ] +style = [ make_property(*x) for x in style_config ] -uncommon_config = { - 'border_spacing', - 'break_before', - 'break_after', - 'break_inside', - 'clip', - 'column_count', - 'column_fill', - 'column_gap', - 'column_rule_color', - 'column_rule_style', - 'column_rule_width', - 'content', - 'counter_increment', - 'counter_reset', - 'cursor', - 'letter_spacing', - 'outline_color', - 'outline_width', - 'word_spacing' +properties = { + groups: [ uncommon, page, style ], + default_group: style } - -page_config = { - 'page_break_after', - 'page_break_before', - 'page_break_inside', - 'orphans', - 'windows' -} - -style_config = { - 'align_content', - 'align_items', - 'align_self', - 'background_attachment', - 'background_repeat', - 'background_color', - 'background_image', - 'background_position', - 'border_collapse', - 'border_top_style', - 'border_right_style', - 'border_bottom_style', - 'border_left_style', - 'border_top_color', - 'border_right_color', - 'border_bottom_color', - 'border_left_color', - 'border_top_width', - 'border_right_width', - 'border_bottom_width', - 'border_left_width', - 'top', - 'right', - 'bottom', - 'left', - 'box_sizing', - 'caption_side', - 'clear', - 'color', - 'direction', - 'display', - 'empty_cells', - 'flex_basis', - 'flex_direction', - 'flex_grow', - 'flex_shrink', - 'flex_wrap', - 'float', - 'font_family', - 'font_size', - 'font_style', - 'font_variant', - 'font_weight', - 'height', - 'justify_content', - 'line_height', - 'list_style_image', - 'list_style_position', - 'list_style_type', - 'margin_top', - 'margin_right', - 'margin_bottom', - 'margin_left', - 'max_height', - 'max_width', - 'min_height', - 'min_width', - 'order', - 'outline_style', - 'overflow', - 'padding_top', - 'padding_right', - 'padding_bottom', - 'padding_left', - 'position', - 'quotes', - 'table_layout', - 'text_align', - 'text_decoration', - 'text_indent', - 'text_transform', - 'unicode_bidi', - 'vertical_align', - 'visibility', - 'white_space', - 'width', - 'z_index' -} - -uncommon = [ x for x in properties if x['name'] in uncommon_config ] -page = [ x for x in properties if x['name'] in page_config ] -style = [ x for x in properties if x['name'] in style_config ] - -groups = [ uncommon, page, style ] - diff --git a/src/select/overrides.py b/src/select/overrides.py new file mode 100644 index 0000000..930bd4a --- /dev/null +++ b/src/select/overrides.py @@ -0,0 +1,88 @@ +# This file is part of LibCSS. +# Licensed under the MIT License, +# http://www.opensource.org/licenses/mit-license.php +# Copyright 2017 Lucas Neves <lcneves@gmail.com> + +clip = {} +clip['get'] = '''\ +static inline uint32_t get_clip( + const css_computed_style *style, + css_computed_clip_rect *rect) +{ + if (style->i.uncommon != NULL) { + uint32_t bits = style->i.uncommon->i.bits[CLIP_INDEX]; + bits &= CLIP_MASK; + bits >>= CLIP_SHIFT; + + /* + 26bits: tt tttr rrrr bbbb blll llTR BLyy: + units: top | right | bottom | left + opcodes: top | right | bottom | left | type + */ + + if ((bits & 0x3) == CSS_CLIP_RECT) { + rect->left_auto = (bits & 0x4); + rect->bottom_auto = (bits & 0x8); + rect->right_auto = (bits & 0x10); + rect->top_auto = (bits & 0x20); + + rect->top = style->i.uncommon->i.clip_a; + rect->tunit = bits & 0x3e00000; + + rect->right = style->i.uncommon->i.clip_b; + rect->runit = bits & 0x1f0000; + + rect->bottom = style->i.uncommon->i.clip_c; + rect->bunit = bits & 0xf800; + + rect->left = style->i.uncommon->i.clip_d; + rect->lunit = bits & 0x7c0; + } + + return (bits & 0x3); + } + + /* Initial value */ + return CSS_CLIP_AUTO; +} +''' +clip['set'] = '''\ +static inline css_error set_clip( + css_computed_style *style, uint8_t type, + css_computed_clip_rect *rect) +{ + uint32_t *bits; + + ENSURE_UNCOMMON; + + bits = &style->i.uncommon->i.bits[CLIP_INDEX]; + + /* + 26bits: tt tttr rrrr bbbb blll llTR BLyy: + units: top | right | bottom | left + opcodes: top | right | bottom | left | type + */ + *bits = (*bits & ~CLIP_MASK) | + ((type & 0x3) << CLIP_SHIFT); + + if (type == CSS_CLIP_RECT) { + *bits |= (((rect->top_auto ? 0x20 : 0) | + (rect->right_auto ? 0x10 : 0) | + (rect->bottom_auto ? 0x8 : 0) | + (rect->left_auto ? 0x4 : 0)) << CLIP_SHIFT); + + *bits |= (((rect->tunit << 5) | rect->runit) + << (CLIP_SHIFT + 16)); + + *bits |= (((rect->bunit << 5) | rect->lunit) + << (CLIP_SHIFT + 6)); + + style->i.uncommon->i.clip_a = rect->top; + style->i.uncommon->i.clip_b = rect->right; + style->i.uncommon->i.clip_c = rect->bottom; + style->i.uncommon->i.clip_d = rect->left; + } + + return CSS_OK; +} +''' |