Gitweb links:

...log 
http://git.netsurf-browser.org/libcss.git/shortlog/21a344cfb578bc53ef41b2d2459f3f8892aec30b
...commit 
http://git.netsurf-browser.org/libcss.git/commit/21a344cfb578bc53ef41b2d2459f3f8892aec30b
...tree 
http://git.netsurf-browser.org/libcss.git/tree/21a344cfb578bc53ef41b2d2459f3f8892aec30b

The branch, lcneves/units has been updated
       via  21a344cfb578bc53ef41b2d2459f3f8892aec30b (commit)
      from  10f5daa91de724edafd79094100787ad3a73a7c4 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commitdiff 
http://git.netsurf-browser.org/libcss.git/commit/?id=21a344cfb578bc53ef41b2d2459f3f8892aec30b
commit 21a344cfb578bc53ef41b2d2459f3f8892aec30b
Author: Lucas Neves <[email protected]>
Commit: Lucas Neves <[email protected]>

    WIP: Select: Autogen for selection properties.

diff --git a/src/select/__pycache__/select_config.cpython-36.pyc 
b/src/select/__pycache__/select_config.cpython-36.pyc
new file mode 100644
index 0000000..52b37eb
Binary files /dev/null and 
b/src/select/__pycache__/select_config.cpython-36.pyc differ
diff --git a/src/select/assets.py b/src/select/assets.py
new file mode 100644
index 0000000..8151182
--- /dev/null
+++ b/src/select/assets.py
@@ -0,0 +1,61 @@
+# This file is part of LibCSS.
+# Licensed under the MIT License,
+# http://www.opensource.org/licenses/mit-license.php
+# Copyright 2017 Lucas Neves <[email protected]>
+
+assets = {}
+
+assets['computed_h'] = {}
+assets['computed_h']['header'] = '''\
+/*
+ * This file is part of LibCSS
+ * Licensed under the MIT License,
+ *                http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2017 The NetSurf Project
+ */
+
+#ifndef css_select_computed_h_
+#define css_select_computed_h_
+
+#include <libcss/computed.h>
+#include <libcss/hint.h>
+
+'''
+assets['computed_h']['footer'] = '''\
+/**
+ * Take a new reference to a computed style
+ *
+ * \param style  The style to take a new reference to.
+ * \return The new computed style reference
+ */
+static inline css_computed_style * css__computed_style_ref(
+               css_computed_style *style)
+{
+       if (style == NULL)
+               return NULL;
+
+       if (style->i.uncommon != NULL) {
+               style->i.uncommon->count++;
+       }
+
+       style->count++;
+       return style;
+}
+
+css_error css__computed_style_create(css_computed_style **result);
+
+css_error css__computed_style_initialise(css_computed_style *style,
+               struct css_select_handler *handler, void *pw);
+
+
+css_error css__computed_uncommon_destroy(css_computed_uncommon *uncommon);
+
+css_error css__compute_absolute_values(const css_computed_style *parent,
+               css_computed_style *style,
+               css_error (*compute_font_size)(void *pw,
+                       const css_hint *parent, css_hint *size),
+               void *pw);
+
+#endif
+'''
+
diff --git a/src/select/computed_properties.py 
b/src/select/computed_properties.py
deleted file mode 100644
index 3f87bed..0000000
--- a/src/select/computed_properties.py
+++ /dev/null
@@ -1,197 +0,0 @@
-# This file is part of LibCSS.
-# Licensed under the MIT License,
-# http://www.opensource.org/licenses/mit-license.php
-# Copyright 2017 Lucas Neves <[email protected]>
-
-def get_tuple(from_var):
-    if type(from_var) is tuple:
-        return from_var
-    elif type(from_var) is str:
-        return (from_var,)
-    else:
-        return ()
-
-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, #  `None` means sizeof(ptr)
-        'default': default,
-        'bits': None if bits_name is None else {
-            'name': bits_name,
-            'type': bits_type,
-            'size': bits_size,
-            'default': bits_default
-        }
-    }
-
-# Configuration of types
-type_config = {
-    ('length', 'css_fixed', 4, 0, 'unit', 'css_unit', 5, 'CSS_UNIT_PX'),
-    ('integer', 'int32_t', 4, 0),
-    ('fixed', 'css_fixed', 4, 0),
-    ('color', 'css_color', 4, 0),
-    ('string', 'lwc_string*'),
-    ('string_arr', 'lwc_string**'),
-    ('counter', 'css_computed_counter*'),
-    ('content_item', 'css_computed_content_item*')
-}
-
-types = [ make_type(*x) for x in type_config ]
-
-def make_property(name, opcode_size, values = None,
-                  defaults = None, comments = None):
-    'Returns a CSS property.'
-    default_tuple = get_tuple(defaults)
-    value_tuple = get_tuple(values)
-
-    return {
-        'name': name,
-        'size': opcode_size,
-        'values': [ types[x] for x in value_tuple ] or None,
-        'defaults': default_tuple or None, # May be `None` only for main group
-        'comments': comments
-    }
-
-# Configuration of properties
-style_config = {
-    # Style group, only opcode
-    ('align_content', 3),
-    ('align_items', 3),
-    ('align_self', 3),
-    ('background_attachment', 2),
-    ('background_repeat', 3),
-    ('border_collapse', 2),
-    ('border_top_style', 4),
-    ('border_right_style', 4),
-    ('border_bottom_style', 4),
-    ('border_left_style', 4),
-    ('box_sizing', 2),
-    ('caption_side', 2),
-    ('clear', 3),
-    ('direction', 2),
-    ('display', 5),
-    ('empty_cells', 2),
-    ('flex_direction', 3),
-    ('flex_wrap', 2),
-    ('float', 2),
-    ('font_style', 2),
-    ('font_variant', 2),
-    ('font_weight', 4),
-    ('justify_content', 3),
-    ('list_style_position', 2),
-    ('list_style_type', 4),
-    ('overflow', 3),
-    ('outline_style', 4),
-    ('position', 3),
-    ('table_layout', 2),
-    ('text_align', 4),
-    ('text_decoration', 5),
-    ('text_transform', 3),
-    ('unicode_bidi', 2),
-    ('visibility', 2),
-    ('white_space', 3),
-    # Style group, with additional value
-    ('background_color', 2, 'color'),
-    ('background_image', 1, 'string'),
-    ('background_position', 1, ('length', 'length')),
-    ('border_top_color', 2, 'color'),
-    ('border_right_color', 2, 'color'),
-    ('border_bottom_color', 2, 'color'),
-    ('border_left_color', 2, 'color'),
-    ('border_top_width', 3, 'length'),
-    ('border_right_width', 3, 'length'),
-    ('border_bottom_width', 3, 'length'),
-    ('border_left_width', 3, 'length'),
-    ('top', 2, 'length'),
-    ('right', 2, 'length'),
-    ('bottom', 2, 'length'),
-    ('left', 2, 'length'),
-    ('color', 1, 'color'),
-    ('flex_basis', 2, 'length'),
-    ('flex_grow', 1, 'fixed'),
-    ('flex_shrink', 1, 'fixed'),
-    ('font_size', 4, 'length'),
-    ('height', 2, 'length'),
-    ('line_height', 2, 'length'),
-    ('list_style_image', 1, 'string'),
-    ('margin_top', 2, 'length'),
-    ('margin_right', 2, 'length'),
-    ('margin_bottom', 2, 'length'),
-    ('margin_left', 2, 'length'),
-    ('max_height', 2, 'length'),
-    ('max_width', 2, 'length'),
-    ('min_height', 2, 'length'),
-    ('min_width', 2, 'length'),
-    ('order', 1, 'integer'),
-    ('padding_top', 1, 'length'),
-    ('padding_right', 1, 'length'),
-    ('padding_left', 1, 'length'),
-    ('padding_bottom', 1, 'length'),
-    ('text_indent', 1, 'length'),
-    ('vertical_align', 4, 'length'),
-    ('width', 2, 'length'),
-    ('z_index', 2, 'integer'),
-    # Style group, arrays
-    ('font_family', 3, 'string_arr', None,
-        'Encode font family as an array of string objects, terminated with a'
-        '\n' 'blank entry.'),
-    ('quotes', 1, 'string_arr', None,
-        'Encode quotes as an array of string objects, terminated with a '
-        '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))
-}
-
-uncommon_config = {
-    # Uncommon group
-    ('border_spacing', 1, ('length', 'length'),
-        ('CSS_BORDER_SPACING_SET', 0, 'CSS_UNIT_PX', 0, 'CSS_UNIT_PX')),
-    ('break_after', 4, None, 'CSS_BREAK_AFTER_AUTO'),
-    ('break_before', 4, None, 'CSS_BREAK_BEFORE_AUTO'),
-    ('break_inside', 4, None, 'CSS_BREAK_INSIDE_AUTO'),
-    ('clip', 6, ('length, length, length, length'), ('get', 'set')),
-    ('column_count', 2, 'integer', 'CSS_COLUMN_COUNT_AUTO'),
-    ('column_fill', 2, None, 'CSS_COLUMN_FILL_BALANCE'),
-    ('column_gap', 2, 'length', 'CSS_COLUMN_GAP_NORMAL'),
-    ('column_rule_color', 2, 'color', ('CSS_COLUMN_RULE_CURRENT_COLOR', 0)),
-    ('column_rule_style', 4, None, 'CSS_COLUMN_RULE_STYLE_NONE'),
-    ('column_rule_width', 3, 'length', 'CSS_COLUMN_RULE_WIDTH_MEDIUM'),
-    ('column_span', 2, None, 'CSS_COLUMN_SPAN_NONE'),
-    ('column_width', 2, 'length', 'CSS_COLUMN_WIDTH_AUTO'),
-    ('letter_spacing', 2, 'length', 'CSS_LETTER_SPACING_NORMAL'),
-    ('outline_color', 2, 'color', 'CSS_OUTLINE_COLOR_INVERT'),
-    ('outline_width', 3, 'length', 'CSS_OUTLINE_WIDTH_MEDIUM'),
-    ('word_spacing', 2, 'length', 'CSS_WORD_SPACING_NORMAL'),
-    # Uncommon group, arrays
-    ('counter_increment', 1, 'counter', 'CSS_COUNTER_INCREMENT_NONE',
-        'Encode counter_increment as an array of name, value pairs,\n'
-        'terminated with a blank entry.'),
-    ('counter_reset', 1, 'counter', 'CSS_COUNTER_RESET_NONE',
-        'Encode counter_reset as an array of name, value pairs,\n'
-        'terminated with a blank entry.'),
-    ('cursor', 5, 'string_arr', 'CSS_CURSOR_AUTO',
-        'Encode cursor uri(s) as an array of string objects, terminated\n'
-        'with a blank entry'),
-    ('content', 2, 'content_item', 'CSS_CONTENT_NORMAL',
-        'Encode content as an array of content items, terminated with '
-        'a blank entry.')
-}
-
-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 ]
-
-properties = {
-    groups: [ uncommon, page, style ],
-    default_group: style
-}
diff --git a/src/select/overrides.py b/src/select/overrides.py
index 930bd4a..3834c3f 100644
--- a/src/select/overrides.py
+++ b/src/select/overrides.py
@@ -5,7 +5,7 @@
 
 clip = {}
 clip['get'] = '''\
-static inline uint32_t get_clip(
+static inline uint8_t get_clip(
                const css_computed_style *style,
                css_computed_clip_rect *rect)
 {
@@ -86,3 +86,27 @@ static inline css_error set_clip(
        return CSS_OK;
 }
 '''
+
+line_height = {}
+line_height['get'] = '''\
+static inline uint8_t get_line_height(
+               const css_computed_style *style,
+               css_fixed *length, css_unit *unit)
+{
+       uint32_t bits = style->i.bits[LINE_HEIGHT_INDEX];
+       bits &= LINE_HEIGHT_MASK;
+       bits >>= LINE_HEIGHT_SHIFT;
+
+       /* 6bits: uuuutt : units | type */
+       if ((bits & 0x3) == CSS_LINE_HEIGHT_NUMBER ||
+                       (bits & 0x3) == CSS_LINE_HEIGHT_DIMENSION) {
+               *length = style->i.line_height;
+       }
+
+       if ((bits & 0x3) == CSS_LINE_HEIGHT_DIMENSION) {
+               *unit = bits >> 2;
+       }
+
+       return (bits & 0x3);
+}
+'''
diff --git a/src/select/select_config.py b/src/select/select_config.py
new file mode 100644
index 0000000..d5cd525
--- /dev/null
+++ b/src/select/select_config.py
@@ -0,0 +1,167 @@
+# This file is part of LibCSS.
+# Licensed under the MIT License,
+# http://www.opensource.org/licenses/mit-license.php
+# Copyright 2017 Lucas Neves <[email protected]>
+
+# Configuration of CSS values
+values = {
+    ('length', 'css_fixed', 4, 0, 'unit', 'css_unit', 5, 'CSS_UNIT_PX'),
+    ('integer', 'int32_t', 4, 0),
+    ('fixed', 'css_fixed', 4, 0),
+    ('color', 'css_color', 4, 0),
+    ('string', 'lwc_string*'),
+    ('string_arr', 'lwc_string**'),
+    ('counter', 'css_computed_counter*'),
+    ('content_item', 'css_computed_content_item*')
+}
+
+# Configuration of properties
+style = {
+    # Style group, only opcode
+    ('align_content', 3),
+    ('align_items', 3),
+    ('align_self', 3),
+    ('background_attachment', 2),
+    ('background_repeat', 3),
+    ('border_collapse', 2),
+    ('border_top_style', 4),
+    ('border_right_style', 4),
+    ('border_bottom_style', 4),
+    ('border_left_style', 4),
+    ('box_sizing', 2),
+    ('caption_side', 2),
+    ('clear', 3),
+    ('direction', 2),
+    ('display', 5),
+    ('empty_cells', 2),
+    ('flex_direction', 3),
+    ('flex_wrap', 2),
+    ('float', 2),
+    ('font_style', 2),
+    ('font_variant', 2),
+    ('font_weight', 4),
+    ('justify_content', 3),
+    ('list_style_position', 2),
+    ('list_style_type', 4),
+    ('overflow', 3),
+    ('outline_style', 4),
+    ('position', 3),
+    ('table_layout', 2),
+    ('text_align', 4),
+    ('text_decoration', 5),
+    ('text_transform', 3),
+    ('unicode_bidi', 2),
+    ('visibility', 2),
+    ('white_space', 3),
+    # Style group, with additional value
+    ('background_color', 2, 'color'),
+    ('background_image', 1, 'string'),
+    ('background_position', 1, ('length', 'length'),
+        'CSS_BACKGROUND_POSITION_SET'),
+    ('border_top_color', 2, 'color'),
+    ('border_right_color', 2, 'color'),
+    ('border_bottom_color', 2, 'color'),
+    ('border_left_color', 2, 'color'),
+    ('border_top_width', 3, 'length', 'CSS_BORDER_WIDTH_WIDTH'),
+    ('border_right_width', 3, 'length', 'CSS_BORDER_WIDTH_WIDTH'),
+    ('border_bottom_width', 3, 'length', 'CSS_BORDER_WIDTH_WIDTH'),
+    ('border_left_width', 3, 'length', 'CSS_BORDER_WIDTH_WIDTH'),
+    ('top', 2, 'length', 'CSS_TOP_SET'),
+    ('right', 2, 'length', 'CSS_RIGHT_SET'),
+    ('bottom', 2, 'length', 'CSS_BOTTOM_SET'),
+    ('left', 2, 'length', 'CSS_LEFT_SET'),
+    ('color', 1, 'color'),
+    ('flex_basis', 2, 'length', 'CSS_FLEX_BASIS_SET'),
+    ('flex_grow', 1, 'fixed', 'CSS_FLEX_GROW_SET'),
+    ('flex_shrink', 1, 'fixed', 'CSS_FLEX_SHRINK_SET'),
+    ('font_size', 4, 'length', 'CSS_FONT_SIZE_DIMENSION'),
+    ('height', 2, 'length', 'CSS_HEIGHT_SET'),
+    ('line_height', 2, 'length', None, None, None, ('get')),
+    ('list_style_image', 1, 'string'),
+    ('margin_top', 2, 'length', 'CSS_MARGIN_SET'),
+    ('margin_right', 2, 'length', 'CSS_MARGIN_SET'),
+    ('margin_bottom', 2, 'length', 'CSS_MARGIN_SET'),
+    ('margin_left', 2, 'length', 'CSS_MARGIN_SET'),
+    ('max_height', 2, 'length', 'CSS_MAX_HEIGHT_SET'),
+    ('max_width', 2, 'length', 'CSS_MAX_WIDTH_SET'),
+    ('min_height', 2, 'length', 'CSS_MIN_HEIGHT_SET'),
+    ('min_width', 2, 'length', 'CSS_MIN_WIDTH_SET'),
+    ('opacity', 1, 'fixed', 'CSS_OPACITY_SET'),
+    ('order', 1, 'integer', 'CSS_ORDER_SET'),
+    ('padding_top', 1, 'length', 'CSS_PADDING_SET'),
+    ('padding_right', 1, 'length', 'CSS_PADDING_SET'),
+    ('padding_left', 1, 'length', 'CSS_PADDING_SET'),
+    ('padding_bottom', 1, 'length', 'CSS_PADDING_SET'),
+    ('text_indent', 1, 'length', 'CSS_TEXT_INDENT_SET'),
+    ('vertical_align', 4, 'length', 'CSS_VERTICAL_ALIGN_SET'),
+    ('width', 2, 'length', 'CSS_WIDTH_SET'),
+    ('z_index', 2, 'integer'),
+    # Style group, arrays
+    ('font_family', 3, 'string_arr', None, None,
+        'Encode font family as an array of string objects, terminated with a'
+        '\n' 'blank entry.'),
+    ('quotes', 1, 'string_arr', None, None,
+        'Encode quotes as an array of string objects, terminated with a '
+        'blank entry.')
+}
+
+page = {
+    # Page group
+    ('page_break_after', 3, None, None, 'CSS_PAGE_BREAK_AFTER_AUTO'),
+    ('page_break_before', 3, None, None, 'CSS_PAGE_BREAK_BEFORE_AUTO'),
+    ('page_break_inside', 2, None, None, 'CSS_PAGE_BREAK_INSIDE_AUTO'),
+    ('widows', 1, 'integer', None, ('CSS_WIDOWS_SET', 2)),
+    ('orphans', 1, 'integer', None, ('CSS_ORPHANS_SET', 2))
+}
+
+uncommon = {
+    # Uncommon group
+    ('border_spacing', 1, ('length', 'length'), 'CSS_BORDER_SPACING_SET',
+        ('CSS_BORDER_SPACING_SET', 0, 'CSS_UNIT_PX', 0, 'CSS_UNIT_PX')),
+    ('break_after', 4, None, None, 'CSS_BREAK_AFTER_AUTO'),
+    ('break_before', 4, None, None, 'CSS_BREAK_BEFORE_AUTO'),
+    ('break_inside', 4, None, None, 'CSS_BREAK_INSIDE_AUTO'),
+    ('clip', 6, ('length, length, length, length'),
+        'CSS_CLIP_RECT', None, None, ('get', 'set')),
+    ('column_count', 2, 'integer', None, 'CSS_COLUMN_COUNT_AUTO'),
+    ('column_fill', 2, None, None, 'CSS_COLUMN_FILL_BALANCE'),
+    ('column_gap', 2, 'length',
+        'CSS_COLUMN_GAP_SET', 'CSS_COLUMN_GAP_NORMAL'),
+    ('column_rule_color', 2, 'color', None,
+        ('CSS_COLUMN_RULE_CURRENT_COLOR', 0)),
+    ('column_rule_style', 4, None, None, 'CSS_COLUMN_RULE_STYLE_NONE'),
+    ('column_rule_width', 3, 'length',
+        'CSS_COLUMN_RULE_WIDTH_WIDTH', 'CSS_COLUMN_RULE_WIDTH_MEDIUM'),
+    ('column_span', 2, None, None, 'CSS_COLUMN_SPAN_NONE'),
+    ('column_width', 2, 'length',
+        'CSS_COLUMN_WIDTH_SET', 'CSS_COLUMN_WIDTH_AUTO'),
+    ('letter_spacing', 2, 'length',
+        'CSS_LETTER_SPACING_SET', 'CSS_LETTER_SPACING_NORMAL'),
+    ('outline_color', 2, 'color',
+        'CSS_OUTLINE_COLOR_COLOR', 'CSS_OUTLINE_COLOR_INVERT'),
+    ('outline_width', 3, 'length',
+        'CSS_OUTLINE_WIDTH_WIDTH', 'CSS_OUTLINE_WIDTH_MEDIUM'),
+    ('word_spacing', 2, 'length',
+        'CSS_WORD_SPACING_SET', 'CSS_WORD_SPACING_NORMAL'),
+    # Uncommon group, arrays
+    ('counter_increment', 1, 'counter', None, 'CSS_COUNTER_INCREMENT_NONE',
+        'Encode counter_increment as an array of name, value pairs,\n'
+        'terminated with a blank entry.'),
+    ('counter_reset', 1, 'counter', None, 'CSS_COUNTER_RESET_NONE',
+        'Encode counter_reset as an array of name, value pairs,\n'
+        'terminated with a blank entry.'),
+    ('cursor', 5, 'string_arr', 'CSS_CURSOR_AUTO', None,
+        'Encode cursor uri(s) as an array of string objects, terminated\n'
+        'with a blank entry'),
+    ('content', 2, 'content_item', 'CSS_CONTENT_NORMAL', None,
+        'Encode content as an array of content items, terminated with '
+        'a blank entry.')
+}
+
+groups = {
+    'main': { 'name': 'style', 'props': style },
+    'others': [
+        { 'name': 'uncommon', 'props': uncommon },
+        { 'name': 'page', 'props': page }
+    ]
+}
diff --git a/src/select/select_generator.py b/src/select/select_generator.py
new file mode 100644
index 0000000..701d7d5
--- /dev/null
+++ b/src/select/select_generator.py
@@ -0,0 +1,123 @@
+# This file is part of LibCSS.
+# Licensed under the MIT License,
+# http://www.opensource.org/licenses/mit-license.php
+# Copyright 2017 Lucas Neves <[email protected]>
+
+from select_config import values, groups
+from assets import assets
+
+def get_tuple(from_var):
+    'Accepts tuples and strings, returns a tuple.'
+    if type(from_var) is tuple:
+        return from_var
+    elif type(from_var) is str:
+        return (from_var,)
+    else:
+        return ()
+
+class Bin:
+    def __init__(self, first_object):
+        self.contents = [ first_object ]
+
+    @property
+    def size(self):
+        return sum([ x['size'] for x in self.contents ])
+
+    def push(self, obj):
+        self.contents.append(obj)
+
+def make_bit_map(group):
+    '''Implements a `best fit first` heuristics for the bin packing of
+    property bits in the bits array'''
+
+    bin_size = 32
+    bit_map = []
+    group_props = sorted([ { 'name': p.name, 'size': p.bits_size }
+        for p in group['props'] ], key=(lambda x: x['size']), reverse=True)
+    for p in group_props:
+        for b in bit_map:
+            if b.size + p['size'] <= bin_size:
+                b.push(p)
+                break
+        else:
+            bit_map.append(Bin(p))
+        bit_map.sort(key=(lambda x: x.size), reverse=True)
+
+class FileText:
+    def __init__(self):
+        self._lines = []
+        self._comment = False
+        self._indent = 0
+
+    def indent(self, value, absolute=False):
+        if absolute:
+            self._indent = value
+        else:
+            self._indent += value
+
+    def comment(self):
+        self.append(' */' if self._comment else '/*')
+        self._comment = !self._comment
+
+    def append(self, text):
+        column_max = 80
+        multiline = False
+
+        while text:
+            line = '\t' * self._indent
+            if self._comment:
+                line += ' * '
+            prefix_size = (3 if self._comment else 0) + 8 * self._indent
+            line += text[:column_max - prefix_size]
+            self.lines.append(line)
+            text = text[column_max - prefix_size:]
+            if text and not self._comment and not multiline:
+                self._indent(2)
+                multiline = True
+
+        if multiline:
+            self._indent(-2)
+
+def make_computed_h(group, is_main=false):
+    pass
+
+class CSSValue:
+    'Values to be associated with properties.'
+    def __init__(self, name, css_type, size=None, default='NULL',
+                 bits_name=None, bits_type=None,
+                 bits_size=None, bits_default=0):
+        self.name = name
+        self.type = css_type
+        self.size = size #  `None` means sizeof(ptr)
+        self.default = default
+        self.bits = None if bits_size is None else {
+            'name': bits_name,
+            'type': bits_type,
+            'size': bits_size,
+            'default': bits_default
+        }
+
+class CSSProperty:
+    def __init__(self, name, type_size, values=None, condition=None,
+             defaults=None, comments=None, override=None):
+        self.name = name
+        self.type_size = type_size
+        self.values = [ v for v in self.__vals if v.name in get_tuple(values) ]
+        self.defaults = get_tuple(defaults)
+        self.condition = condition
+        self.override = get_tuple(override)
+        self.comments = comments
+
+    __vals = [ CSSValue(*x) for x in values ]
+
+    @property
+    def bits_size(self):
+        return self.type_size + sum([ v.bits['size'] for v in self.values
+            if v.bits is not None ])
+
+groups['main']['props'] = [ CSSProperty(*x) for x in groups['main']['props'] ]
+groups['main']['map'] = make_bit_map(groups['main'])
+for g in groups['others']:
+    g['props'] = [ CSSProperty(*x) for x in g['props'] ]
+    g['map'] = make_bit_map(g)
+


-----------------------------------------------------------------------

Summary of changes:
 .../__pycache__/select_config.cpython-36.pyc       |  Bin 0 -> 6502 bytes
 src/select/assets.py                               |   61 ++++++
 src/select/computed_properties.py                  |  197 --------------------
 src/select/overrides.py                            |   26 ++-
 src/select/select_config.py                        |  167 +++++++++++++++++
 src/select/select_generator.py                     |  123 ++++++++++++
 6 files changed, 376 insertions(+), 198 deletions(-)
 create mode 100644 src/select/__pycache__/select_config.cpython-36.pyc
 create mode 100644 src/select/assets.py
 delete mode 100644 src/select/computed_properties.py
 create mode 100644 src/select/select_config.py
 create mode 100644 src/select/select_generator.py

diff --git a/src/select/__pycache__/select_config.cpython-36.pyc 
b/src/select/__pycache__/select_config.cpython-36.pyc
new file mode 100644
index 0000000..52b37eb
Binary files /dev/null and 
b/src/select/__pycache__/select_config.cpython-36.pyc differ
diff --git a/src/select/assets.py b/src/select/assets.py
new file mode 100644
index 0000000..8151182
--- /dev/null
+++ b/src/select/assets.py
@@ -0,0 +1,61 @@
+# This file is part of LibCSS.
+# Licensed under the MIT License,
+# http://www.opensource.org/licenses/mit-license.php
+# Copyright 2017 Lucas Neves <[email protected]>
+
+assets = {}
+
+assets['computed_h'] = {}
+assets['computed_h']['header'] = '''\
+/*
+ * This file is part of LibCSS
+ * Licensed under the MIT License,
+ *                http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2017 The NetSurf Project
+ */
+
+#ifndef css_select_computed_h_
+#define css_select_computed_h_
+
+#include <libcss/computed.h>
+#include <libcss/hint.h>
+
+'''
+assets['computed_h']['footer'] = '''\
+/**
+ * Take a new reference to a computed style
+ *
+ * \param style  The style to take a new reference to.
+ * \return The new computed style reference
+ */
+static inline css_computed_style * css__computed_style_ref(
+               css_computed_style *style)
+{
+       if (style == NULL)
+               return NULL;
+
+       if (style->i.uncommon != NULL) {
+               style->i.uncommon->count++;
+       }
+
+       style->count++;
+       return style;
+}
+
+css_error css__computed_style_create(css_computed_style **result);
+
+css_error css__computed_style_initialise(css_computed_style *style,
+               struct css_select_handler *handler, void *pw);
+
+
+css_error css__computed_uncommon_destroy(css_computed_uncommon *uncommon);
+
+css_error css__compute_absolute_values(const css_computed_style *parent,
+               css_computed_style *style,
+               css_error (*compute_font_size)(void *pw,
+                       const css_hint *parent, css_hint *size),
+               void *pw);
+
+#endif
+'''
+
diff --git a/src/select/computed_properties.py 
b/src/select/computed_properties.py
deleted file mode 100644
index 3f87bed..0000000
--- a/src/select/computed_properties.py
+++ /dev/null
@@ -1,197 +0,0 @@
-# This file is part of LibCSS.
-# Licensed under the MIT License,
-# http://www.opensource.org/licenses/mit-license.php
-# Copyright 2017 Lucas Neves <[email protected]>
-
-def get_tuple(from_var):
-    if type(from_var) is tuple:
-        return from_var
-    elif type(from_var) is str:
-        return (from_var,)
-    else:
-        return ()
-
-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, #  `None` means sizeof(ptr)
-        'default': default,
-        'bits': None if bits_name is None else {
-            'name': bits_name,
-            'type': bits_type,
-            'size': bits_size,
-            'default': bits_default
-        }
-    }
-
-# Configuration of types
-type_config = {
-    ('length', 'css_fixed', 4, 0, 'unit', 'css_unit', 5, 'CSS_UNIT_PX'),
-    ('integer', 'int32_t', 4, 0),
-    ('fixed', 'css_fixed', 4, 0),
-    ('color', 'css_color', 4, 0),
-    ('string', 'lwc_string*'),
-    ('string_arr', 'lwc_string**'),
-    ('counter', 'css_computed_counter*'),
-    ('content_item', 'css_computed_content_item*')
-}
-
-types = [ make_type(*x) for x in type_config ]
-
-def make_property(name, opcode_size, values = None,
-                  defaults = None, comments = None):
-    'Returns a CSS property.'
-    default_tuple = get_tuple(defaults)
-    value_tuple = get_tuple(values)
-
-    return {
-        'name': name,
-        'size': opcode_size,
-        'values': [ types[x] for x in value_tuple ] or None,
-        'defaults': default_tuple or None, # May be `None` only for main group
-        'comments': comments
-    }
-
-# Configuration of properties
-style_config = {
-    # Style group, only opcode
-    ('align_content', 3),
-    ('align_items', 3),
-    ('align_self', 3),
-    ('background_attachment', 2),
-    ('background_repeat', 3),
-    ('border_collapse', 2),
-    ('border_top_style', 4),
-    ('border_right_style', 4),
-    ('border_bottom_style', 4),
-    ('border_left_style', 4),
-    ('box_sizing', 2),
-    ('caption_side', 2),
-    ('clear', 3),
-    ('direction', 2),
-    ('display', 5),
-    ('empty_cells', 2),
-    ('flex_direction', 3),
-    ('flex_wrap', 2),
-    ('float', 2),
-    ('font_style', 2),
-    ('font_variant', 2),
-    ('font_weight', 4),
-    ('justify_content', 3),
-    ('list_style_position', 2),
-    ('list_style_type', 4),
-    ('overflow', 3),
-    ('outline_style', 4),
-    ('position', 3),
-    ('table_layout', 2),
-    ('text_align', 4),
-    ('text_decoration', 5),
-    ('text_transform', 3),
-    ('unicode_bidi', 2),
-    ('visibility', 2),
-    ('white_space', 3),
-    # Style group, with additional value
-    ('background_color', 2, 'color'),
-    ('background_image', 1, 'string'),
-    ('background_position', 1, ('length', 'length')),
-    ('border_top_color', 2, 'color'),
-    ('border_right_color', 2, 'color'),
-    ('border_bottom_color', 2, 'color'),
-    ('border_left_color', 2, 'color'),
-    ('border_top_width', 3, 'length'),
-    ('border_right_width', 3, 'length'),
-    ('border_bottom_width', 3, 'length'),
-    ('border_left_width', 3, 'length'),
-    ('top', 2, 'length'),
-    ('right', 2, 'length'),
-    ('bottom', 2, 'length'),
-    ('left', 2, 'length'),
-    ('color', 1, 'color'),
-    ('flex_basis', 2, 'length'),
-    ('flex_grow', 1, 'fixed'),
-    ('flex_shrink', 1, 'fixed'),
-    ('font_size', 4, 'length'),
-    ('height', 2, 'length'),
-    ('line_height', 2, 'length'),
-    ('list_style_image', 1, 'string'),
-    ('margin_top', 2, 'length'),
-    ('margin_right', 2, 'length'),
-    ('margin_bottom', 2, 'length'),
-    ('margin_left', 2, 'length'),
-    ('max_height', 2, 'length'),
-    ('max_width', 2, 'length'),
-    ('min_height', 2, 'length'),
-    ('min_width', 2, 'length'),
-    ('order', 1, 'integer'),
-    ('padding_top', 1, 'length'),
-    ('padding_right', 1, 'length'),
-    ('padding_left', 1, 'length'),
-    ('padding_bottom', 1, 'length'),
-    ('text_indent', 1, 'length'),
-    ('vertical_align', 4, 'length'),
-    ('width', 2, 'length'),
-    ('z_index', 2, 'integer'),
-    # Style group, arrays
-    ('font_family', 3, 'string_arr', None,
-        'Encode font family as an array of string objects, terminated with a'
-        '\n' 'blank entry.'),
-    ('quotes', 1, 'string_arr', None,
-        'Encode quotes as an array of string objects, terminated with a '
-        '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))
-}
-
-uncommon_config = {
-    # Uncommon group
-    ('border_spacing', 1, ('length', 'length'),
-        ('CSS_BORDER_SPACING_SET', 0, 'CSS_UNIT_PX', 0, 'CSS_UNIT_PX')),
-    ('break_after', 4, None, 'CSS_BREAK_AFTER_AUTO'),
-    ('break_before', 4, None, 'CSS_BREAK_BEFORE_AUTO'),
-    ('break_inside', 4, None, 'CSS_BREAK_INSIDE_AUTO'),
-    ('clip', 6, ('length, length, length, length'), ('get', 'set')),
-    ('column_count', 2, 'integer', 'CSS_COLUMN_COUNT_AUTO'),
-    ('column_fill', 2, None, 'CSS_COLUMN_FILL_BALANCE'),
-    ('column_gap', 2, 'length', 'CSS_COLUMN_GAP_NORMAL'),
-    ('column_rule_color', 2, 'color', ('CSS_COLUMN_RULE_CURRENT_COLOR', 0)),
-    ('column_rule_style', 4, None, 'CSS_COLUMN_RULE_STYLE_NONE'),
-    ('column_rule_width', 3, 'length', 'CSS_COLUMN_RULE_WIDTH_MEDIUM'),
-    ('column_span', 2, None, 'CSS_COLUMN_SPAN_NONE'),
-    ('column_width', 2, 'length', 'CSS_COLUMN_WIDTH_AUTO'),
-    ('letter_spacing', 2, 'length', 'CSS_LETTER_SPACING_NORMAL'),
-    ('outline_color', 2, 'color', 'CSS_OUTLINE_COLOR_INVERT'),
-    ('outline_width', 3, 'length', 'CSS_OUTLINE_WIDTH_MEDIUM'),
-    ('word_spacing', 2, 'length', 'CSS_WORD_SPACING_NORMAL'),
-    # Uncommon group, arrays
-    ('counter_increment', 1, 'counter', 'CSS_COUNTER_INCREMENT_NONE',
-        'Encode counter_increment as an array of name, value pairs,\n'
-        'terminated with a blank entry.'),
-    ('counter_reset', 1, 'counter', 'CSS_COUNTER_RESET_NONE',
-        'Encode counter_reset as an array of name, value pairs,\n'
-        'terminated with a blank entry.'),
-    ('cursor', 5, 'string_arr', 'CSS_CURSOR_AUTO',
-        'Encode cursor uri(s) as an array of string objects, terminated\n'
-        'with a blank entry'),
-    ('content', 2, 'content_item', 'CSS_CONTENT_NORMAL',
-        'Encode content as an array of content items, terminated with '
-        'a blank entry.')
-}
-
-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 ]
-
-properties = {
-    groups: [ uncommon, page, style ],
-    default_group: style
-}
diff --git a/src/select/overrides.py b/src/select/overrides.py
index 930bd4a..3834c3f 100644
--- a/src/select/overrides.py
+++ b/src/select/overrides.py
@@ -5,7 +5,7 @@
 
 clip = {}
 clip['get'] = '''\
-static inline uint32_t get_clip(
+static inline uint8_t get_clip(
                const css_computed_style *style,
                css_computed_clip_rect *rect)
 {
@@ -86,3 +86,27 @@ static inline css_error set_clip(
        return CSS_OK;
 }
 '''
+
+line_height = {}
+line_height['get'] = '''\
+static inline uint8_t get_line_height(
+               const css_computed_style *style,
+               css_fixed *length, css_unit *unit)
+{
+       uint32_t bits = style->i.bits[LINE_HEIGHT_INDEX];
+       bits &= LINE_HEIGHT_MASK;
+       bits >>= LINE_HEIGHT_SHIFT;
+
+       /* 6bits: uuuutt : units | type */
+       if ((bits & 0x3) == CSS_LINE_HEIGHT_NUMBER ||
+                       (bits & 0x3) == CSS_LINE_HEIGHT_DIMENSION) {
+               *length = style->i.line_height;
+       }
+
+       if ((bits & 0x3) == CSS_LINE_HEIGHT_DIMENSION) {
+               *unit = bits >> 2;
+       }
+
+       return (bits & 0x3);
+}
+'''
diff --git a/src/select/select_config.py b/src/select/select_config.py
new file mode 100644
index 0000000..d5cd525
--- /dev/null
+++ b/src/select/select_config.py
@@ -0,0 +1,167 @@
+# This file is part of LibCSS.
+# Licensed under the MIT License,
+# http://www.opensource.org/licenses/mit-license.php
+# Copyright 2017 Lucas Neves <[email protected]>
+
+# Configuration of CSS values
+values = {
+    ('length', 'css_fixed', 4, 0, 'unit', 'css_unit', 5, 'CSS_UNIT_PX'),
+    ('integer', 'int32_t', 4, 0),
+    ('fixed', 'css_fixed', 4, 0),
+    ('color', 'css_color', 4, 0),
+    ('string', 'lwc_string*'),
+    ('string_arr', 'lwc_string**'),
+    ('counter', 'css_computed_counter*'),
+    ('content_item', 'css_computed_content_item*')
+}
+
+# Configuration of properties
+style = {
+    # Style group, only opcode
+    ('align_content', 3),
+    ('align_items', 3),
+    ('align_self', 3),
+    ('background_attachment', 2),
+    ('background_repeat', 3),
+    ('border_collapse', 2),
+    ('border_top_style', 4),
+    ('border_right_style', 4),
+    ('border_bottom_style', 4),
+    ('border_left_style', 4),
+    ('box_sizing', 2),
+    ('caption_side', 2),
+    ('clear', 3),
+    ('direction', 2),
+    ('display', 5),
+    ('empty_cells', 2),
+    ('flex_direction', 3),
+    ('flex_wrap', 2),
+    ('float', 2),
+    ('font_style', 2),
+    ('font_variant', 2),
+    ('font_weight', 4),
+    ('justify_content', 3),
+    ('list_style_position', 2),
+    ('list_style_type', 4),
+    ('overflow', 3),
+    ('outline_style', 4),
+    ('position', 3),
+    ('table_layout', 2),
+    ('text_align', 4),
+    ('text_decoration', 5),
+    ('text_transform', 3),
+    ('unicode_bidi', 2),
+    ('visibility', 2),
+    ('white_space', 3),
+    # Style group, with additional value
+    ('background_color', 2, 'color'),
+    ('background_image', 1, 'string'),
+    ('background_position', 1, ('length', 'length'),
+        'CSS_BACKGROUND_POSITION_SET'),
+    ('border_top_color', 2, 'color'),
+    ('border_right_color', 2, 'color'),
+    ('border_bottom_color', 2, 'color'),
+    ('border_left_color', 2, 'color'),
+    ('border_top_width', 3, 'length', 'CSS_BORDER_WIDTH_WIDTH'),
+    ('border_right_width', 3, 'length', 'CSS_BORDER_WIDTH_WIDTH'),
+    ('border_bottom_width', 3, 'length', 'CSS_BORDER_WIDTH_WIDTH'),
+    ('border_left_width', 3, 'length', 'CSS_BORDER_WIDTH_WIDTH'),
+    ('top', 2, 'length', 'CSS_TOP_SET'),
+    ('right', 2, 'length', 'CSS_RIGHT_SET'),
+    ('bottom', 2, 'length', 'CSS_BOTTOM_SET'),
+    ('left', 2, 'length', 'CSS_LEFT_SET'),
+    ('color', 1, 'color'),
+    ('flex_basis', 2, 'length', 'CSS_FLEX_BASIS_SET'),
+    ('flex_grow', 1, 'fixed', 'CSS_FLEX_GROW_SET'),
+    ('flex_shrink', 1, 'fixed', 'CSS_FLEX_SHRINK_SET'),
+    ('font_size', 4, 'length', 'CSS_FONT_SIZE_DIMENSION'),
+    ('height', 2, 'length', 'CSS_HEIGHT_SET'),
+    ('line_height', 2, 'length', None, None, None, ('get')),
+    ('list_style_image', 1, 'string'),
+    ('margin_top', 2, 'length', 'CSS_MARGIN_SET'),
+    ('margin_right', 2, 'length', 'CSS_MARGIN_SET'),
+    ('margin_bottom', 2, 'length', 'CSS_MARGIN_SET'),
+    ('margin_left', 2, 'length', 'CSS_MARGIN_SET'),
+    ('max_height', 2, 'length', 'CSS_MAX_HEIGHT_SET'),
+    ('max_width', 2, 'length', 'CSS_MAX_WIDTH_SET'),
+    ('min_height', 2, 'length', 'CSS_MIN_HEIGHT_SET'),
+    ('min_width', 2, 'length', 'CSS_MIN_WIDTH_SET'),
+    ('opacity', 1, 'fixed', 'CSS_OPACITY_SET'),
+    ('order', 1, 'integer', 'CSS_ORDER_SET'),
+    ('padding_top', 1, 'length', 'CSS_PADDING_SET'),
+    ('padding_right', 1, 'length', 'CSS_PADDING_SET'),
+    ('padding_left', 1, 'length', 'CSS_PADDING_SET'),
+    ('padding_bottom', 1, 'length', 'CSS_PADDING_SET'),
+    ('text_indent', 1, 'length', 'CSS_TEXT_INDENT_SET'),
+    ('vertical_align', 4, 'length', 'CSS_VERTICAL_ALIGN_SET'),
+    ('width', 2, 'length', 'CSS_WIDTH_SET'),
+    ('z_index', 2, 'integer'),
+    # Style group, arrays
+    ('font_family', 3, 'string_arr', None, None,
+        'Encode font family as an array of string objects, terminated with a'
+        '\n' 'blank entry.'),
+    ('quotes', 1, 'string_arr', None, None,
+        'Encode quotes as an array of string objects, terminated with a '
+        'blank entry.')
+}
+
+page = {
+    # Page group
+    ('page_break_after', 3, None, None, 'CSS_PAGE_BREAK_AFTER_AUTO'),
+    ('page_break_before', 3, None, None, 'CSS_PAGE_BREAK_BEFORE_AUTO'),
+    ('page_break_inside', 2, None, None, 'CSS_PAGE_BREAK_INSIDE_AUTO'),
+    ('widows', 1, 'integer', None, ('CSS_WIDOWS_SET', 2)),
+    ('orphans', 1, 'integer', None, ('CSS_ORPHANS_SET', 2))
+}
+
+uncommon = {
+    # Uncommon group
+    ('border_spacing', 1, ('length', 'length'), 'CSS_BORDER_SPACING_SET',
+        ('CSS_BORDER_SPACING_SET', 0, 'CSS_UNIT_PX', 0, 'CSS_UNIT_PX')),
+    ('break_after', 4, None, None, 'CSS_BREAK_AFTER_AUTO'),
+    ('break_before', 4, None, None, 'CSS_BREAK_BEFORE_AUTO'),
+    ('break_inside', 4, None, None, 'CSS_BREAK_INSIDE_AUTO'),
+    ('clip', 6, ('length, length, length, length'),
+        'CSS_CLIP_RECT', None, None, ('get', 'set')),
+    ('column_count', 2, 'integer', None, 'CSS_COLUMN_COUNT_AUTO'),
+    ('column_fill', 2, None, None, 'CSS_COLUMN_FILL_BALANCE'),
+    ('column_gap', 2, 'length',
+        'CSS_COLUMN_GAP_SET', 'CSS_COLUMN_GAP_NORMAL'),
+    ('column_rule_color', 2, 'color', None,
+        ('CSS_COLUMN_RULE_CURRENT_COLOR', 0)),
+    ('column_rule_style', 4, None, None, 'CSS_COLUMN_RULE_STYLE_NONE'),
+    ('column_rule_width', 3, 'length',
+        'CSS_COLUMN_RULE_WIDTH_WIDTH', 'CSS_COLUMN_RULE_WIDTH_MEDIUM'),
+    ('column_span', 2, None, None, 'CSS_COLUMN_SPAN_NONE'),
+    ('column_width', 2, 'length',
+        'CSS_COLUMN_WIDTH_SET', 'CSS_COLUMN_WIDTH_AUTO'),
+    ('letter_spacing', 2, 'length',
+        'CSS_LETTER_SPACING_SET', 'CSS_LETTER_SPACING_NORMAL'),
+    ('outline_color', 2, 'color',
+        'CSS_OUTLINE_COLOR_COLOR', 'CSS_OUTLINE_COLOR_INVERT'),
+    ('outline_width', 3, 'length',
+        'CSS_OUTLINE_WIDTH_WIDTH', 'CSS_OUTLINE_WIDTH_MEDIUM'),
+    ('word_spacing', 2, 'length',
+        'CSS_WORD_SPACING_SET', 'CSS_WORD_SPACING_NORMAL'),
+    # Uncommon group, arrays
+    ('counter_increment', 1, 'counter', None, 'CSS_COUNTER_INCREMENT_NONE',
+        'Encode counter_increment as an array of name, value pairs,\n'
+        'terminated with a blank entry.'),
+    ('counter_reset', 1, 'counter', None, 'CSS_COUNTER_RESET_NONE',
+        'Encode counter_reset as an array of name, value pairs,\n'
+        'terminated with a blank entry.'),
+    ('cursor', 5, 'string_arr', 'CSS_CURSOR_AUTO', None,
+        'Encode cursor uri(s) as an array of string objects, terminated\n'
+        'with a blank entry'),
+    ('content', 2, 'content_item', 'CSS_CONTENT_NORMAL', None,
+        'Encode content as an array of content items, terminated with '
+        'a blank entry.')
+}
+
+groups = {
+    'main': { 'name': 'style', 'props': style },
+    'others': [
+        { 'name': 'uncommon', 'props': uncommon },
+        { 'name': 'page', 'props': page }
+    ]
+}
diff --git a/src/select/select_generator.py b/src/select/select_generator.py
new file mode 100644
index 0000000..701d7d5
--- /dev/null
+++ b/src/select/select_generator.py
@@ -0,0 +1,123 @@
+# This file is part of LibCSS.
+# Licensed under the MIT License,
+# http://www.opensource.org/licenses/mit-license.php
+# Copyright 2017 Lucas Neves <[email protected]>
+
+from select_config import values, groups
+from assets import assets
+
+def get_tuple(from_var):
+    'Accepts tuples and strings, returns a tuple.'
+    if type(from_var) is tuple:
+        return from_var
+    elif type(from_var) is str:
+        return (from_var,)
+    else:
+        return ()
+
+class Bin:
+    def __init__(self, first_object):
+        self.contents = [ first_object ]
+
+    @property
+    def size(self):
+        return sum([ x['size'] for x in self.contents ])
+
+    def push(self, obj):
+        self.contents.append(obj)
+
+def make_bit_map(group):
+    '''Implements a `best fit first` heuristics for the bin packing of
+    property bits in the bits array'''
+
+    bin_size = 32
+    bit_map = []
+    group_props = sorted([ { 'name': p.name, 'size': p.bits_size }
+        for p in group['props'] ], key=(lambda x: x['size']), reverse=True)
+    for p in group_props:
+        for b in bit_map:
+            if b.size + p['size'] <= bin_size:
+                b.push(p)
+                break
+        else:
+            bit_map.append(Bin(p))
+        bit_map.sort(key=(lambda x: x.size), reverse=True)
+
+class FileText:
+    def __init__(self):
+        self._lines = []
+        self._comment = False
+        self._indent = 0
+
+    def indent(self, value, absolute=False):
+        if absolute:
+            self._indent = value
+        else:
+            self._indent += value
+
+    def comment(self):
+        self.append(' */' if self._comment else '/*')
+        self._comment = !self._comment
+
+    def append(self, text):
+        column_max = 80
+        multiline = False
+
+        while text:
+            line = '\t' * self._indent
+            if self._comment:
+                line += ' * '
+            prefix_size = (3 if self._comment else 0) + 8 * self._indent
+            line += text[:column_max - prefix_size]
+            self.lines.append(line)
+            text = text[column_max - prefix_size:]
+            if text and not self._comment and not multiline:
+                self._indent(2)
+                multiline = True
+
+        if multiline:
+            self._indent(-2)
+
+def make_computed_h(group, is_main=false):
+    pass
+
+class CSSValue:
+    'Values to be associated with properties.'
+    def __init__(self, name, css_type, size=None, default='NULL',
+                 bits_name=None, bits_type=None,
+                 bits_size=None, bits_default=0):
+        self.name = name
+        self.type = css_type
+        self.size = size #  `None` means sizeof(ptr)
+        self.default = default
+        self.bits = None if bits_size is None else {
+            'name': bits_name,
+            'type': bits_type,
+            'size': bits_size,
+            'default': bits_default
+        }
+
+class CSSProperty:
+    def __init__(self, name, type_size, values=None, condition=None,
+             defaults=None, comments=None, override=None):
+        self.name = name
+        self.type_size = type_size
+        self.values = [ v for v in self.__vals if v.name in get_tuple(values) ]
+        self.defaults = get_tuple(defaults)
+        self.condition = condition
+        self.override = get_tuple(override)
+        self.comments = comments
+
+    __vals = [ CSSValue(*x) for x in values ]
+
+    @property
+    def bits_size(self):
+        return self.type_size + sum([ v.bits['size'] for v in self.values
+            if v.bits is not None ])
+
+groups['main']['props'] = [ CSSProperty(*x) for x in groups['main']['props'] ]
+groups['main']['map'] = make_bit_map(groups['main'])
+for g in groups['others']:
+    g['props'] = [ CSSProperty(*x) for x in g['props'] ]
+    g['map'] = make_bit_map(g)
+


-- 
Cascading Style Sheets library

_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org

Reply via email to