Difference between revisions of "CSS Support"
PeterMoulder (talk | contribs) m (* typographical) |
PeterMoulder (talk | contribs) m (* more info on user agent style sheet) |
||
Line 21: | Line 21: | ||
* Similarly, ensure that the picture is refreshed when the stylesheet is changed. | * Similarly, ensure that the picture is refreshed when the stylesheet is changed. | ||
* | * Convert the simple user agent style sheet given at http://www.w3.org/TR/SVG11/styling.html#UAStyleSheet to libcroco structures (perhaps by passing strings to libcroco parsing functions) and store in <tt>desktop->style_cascade</tt>. | ||
* Modify style.cpp to query the stylesheet. (Done but not checked in.) | * Modify style.cpp to query the stylesheet. (Done but not checked in.) |
Revision as of 02:27, 17 January 2005
Hack: Convert to style-less SVG
A short-term solution (hack) for style support would be an input filter that converts stylesheet-using documents to non-stylesheet-using documents. cssanno.c (http://lists.w3.org/Archives/Public/www-archive/2004Jun/att-0001/cssanno.c or see google) does most of the work for this (for a generic XML document); the remainder of the work is to feed it a stylesheet by parsing the SVG document looking for <style> elements and fetching external stylesheets, and to change the outputted namespace from css: to svg:.
Ideally change add_single_property to ignore properties other than SVG ones. I.e. add an array of names of SVG properties, and check whether name is in this list. A linear search should be fine, I'd guess, and it's not too difficult to change it to a hash table or use a pre-coded binary search routine (whether glib or STL).
libcroco
Peter Moulder is looking at using libcroco from Inkscape.
There are a number of aspects of the work, some of which Peter will need help with:
- Modify libcroco selection stuff (cr-sel-eng.c) to allow us to use SPRepr rather than maintaining a libxml copy of the entire tree.
- Partly done (not checked in). The implementation is to provide a generic interface to nodes in a struct of function pointers (with names influenced by DOM).
- If we wish to, we could keep a copy of this modified cr-sel-eng.c in Inkscape, so that we can use current libcroco.
- Parse <style> element content, gathering all rules (across possibly many <style> elements) into a single stylesheet.
- Progress so far: have an initial implementation of sp-style-elem.{cpp,h}. (Not checked in.)
- Ensure that this single stylesheet is updated whenever any of the <style> elements change (or are deleted or created etc.).
- Similarly, ensure that the picture is refreshed when the stylesheet is changed.
- Convert the simple user agent style sheet given at http://www.w3.org/TR/SVG11/styling.html#UAStyleSheet to libcroco structures (perhaps by passing strings to libcroco parsing functions) and store in desktop->style_cascade.
- Modify style.cpp to query the stylesheet. (Done but not checked in.)
- There may be some work needed for "shorthand properties", e.g. `marker' is shorthand for modifying marker-start, marker-mid and marker-end properties (http://www.w3.org/TR/SVG11/painting.html#MarkerProperty). A non-SVG CSS example is `margin'.
Why can't we use the existing libxml interface to cr-sel-eng.c ?
Some CSS selectors (http://www.w3.org/TR/REC-CSS2/selector.html) can express "is preceded by X" or "is a descendent of X" (where X can itself be similarly constrained recursively), so we'd pretty much need to maintain the entire document in libxml form if we want to use libcroco for CSS selectors.
Suppose we want to find the style of node N. We pass libcroco a stylesheet and ask it what rules apply to N. If the stylesheet says "nodes that are preceded by a node that is preceded by a node that's a descendent of (... etc. ...) have red stroking" then libcroco needs to be able to navigate through the tree. So we can't pass libcroco just a libxml version of node N, we need to fill in its parent and sibling links, providing a libxml node for a significant proportion of all nodes in the tree. (Short of using hardware watchpoints to check access to the sibling/parent links and supply them lazily.)