Difference between revisions of "CSS Support"

From Inkscape Wiki
Jump to navigation Jump to search
(* first text)
 
(* More detail on progress)
Line 1: Line 1:
=== Hack: Convert to style-less SVG ===
=== 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 (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 <tt>&lt;style&gt;</tt> elements and fetching external stylesheets, and to change the outputted namespace from css: to 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 <tt>&lt;style&gt;</tt> elements and fetching external stylesheets, and to change the outputted namespace from css: to svg:.


Ideally change <tt>add_single_property</tt> to ignore properties other than SVG ones.  I.e. add an array of names of SVG properties, and check whether <tt>name</tt> 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).
Ideally change <tt>add_single_property</tt> to ignore properties other than SVG ones.  I.e. add an array of names of SVG properties, and check whether <tt>name</tt> 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).
Line 6: Line 6:
=== libcroco ===
=== libcroco ===


Peter Moulder is looking at using libcroco from Inkscape.  He expects to need help ensuring that updates happen properly (e.g. refreshing the picture when the stylesheet is edited from the XML editor).
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 <tt>SPRepr</tt> 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 <tt>&lt;style&gt;</tt> element content, gathering all rules (across possibly many <tt>&lt;style&gt;</tt> 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 <tt>&lt;style&gt;</tt> elements change (or are deleted or created etc.).
 
* Similarly, ensure that the picture is refreshed when the stylesheet is changed.
 
* Create a user agent style sheet as required by http://www.w3.org/TR/SVG11/styling.html#UAStyleSheet
 
* 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.)

Revision as of 02:07, 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.
  • 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.)