Difference between revisions of "CSS Support"

From Inkscape Wiki
Jump to navigation Jump to search
(* Draw attention to "Duplicating libcroco code" on inkscape-devel)
(No difference)

Revision as of 00:38, 8 March 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.
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.
Message posted to inkscape-devel of subject "Duplicating libcroco code in Inkscape tree" seeking concensus on how much of libcroco to put in inkscape source tree; once this has been decided, Peter will modify his local sources accordingly and then check in the current state of most or all files (so long as this doesn't break anything). So reply to that message if you're keen to have the current work checked in as soon as possible.
  • Parse <style> element content, gathering all rules (across possibly many <style> elements) into a single stylesheet.
Progress so far: have a skeletal implementation of sp-style-elem.{cpp,h} that doesn't actually parse the CSS. (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.
  • Modify style.cpp to query the stylesheet. (Done but not checked in.)

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.)