I wanted to add some new length units to LibCSS, such as rem, vw, vh and
others. The problem is that the css_unit value, which is stored in the
style bits array, would need to gain a bit to accomodate the new values.
Since many properties have length units, this change would require
rewriting the files select/computed.h, propget.h and propset.h, because
they need to be kept in sync.

My solution, in the git branch lcneves/select-autogen
<http://source.netsurf-browser.org/libcss.git/log/?h=lcneves/select-autogen>,
is a Python script that autogenerates most of computed.h, propget.h and
propset.h based on a simple configuration of properties and values. The
bits array for each property group is automatically created by a "best fit"
heuristics, which has produced optimal results for our data in all of my
tests -- not guaranteed, though, since the bin packing problem is np-hard!
This way, all three files are kept in sync.

Adding or modifying a property or value is just a matter of editing one
line in the file select-config.py. If the property needs special functions
in propget.h or propset.h, these can be provided in the file overrides.py
(note that the index in the bits array and the bitwise mask and shift will
still be autogenerated). Additional header and footer text for the
autogenerated files goes in assets.py.

In the future, the script can be easily extended to autogenerate the files
in select/properties/. Also, the script treats the groups "style" and
"page" as special, but not "uncommon", so that adding more groups like
"uncommon" can be done entirely in the config file -- but this would
require autogenerating parts of computed.c and arena.c as well, to ensure
that these groups are properly created and destroyed.

So, to sum it up: the branch libcss/lcneves/select-autogen features a
generator script for a big chunk of the selection engine. Plus, 13 new
length units.


Best,
Lucas

Reply via email to