SVG profile for cssutils

15 views
Skip to first unread message

Jason R. Coombs

unread,
Aug 31, 2009, 10:22:10 PM8/31/09
to cssutils
Yesterday, my interest was renewed in svg.charts, and I finally
released v 2.0.

I noticed, though, that there were copious warnings still regarding
many of the CSS tags used in the examples.

I noticed there was still no SVG profile in cssutils, so I started
adding one.

I began by adding the profile properties required to get the
svg.charts tests to run without warnings or errors.

You can find the code at https://py-svg.svn.sourceforge.net/svnroot/py-svg/trunk/svg/charts/css.py.
As you can see, it's currently very minimal, but even with just those
few properties, I was able to eliminate all of the warnings in the
tests _and_ discovered two syntax errors!

I have one question: Is the approach I took, injecting the profile
into cssutils.profile, a reasonable and desirable approach, or would
you have done it differently?

But I just wanted to share this minimal success story. Next, I want
to find someone who's interested in implementing the full SVG
properties spec, either in svg.charts or cssutils. Do you have a
preference where it's contributed?

I'm even willing to pay someone to complete an implementation of the
spec. Any suggestions on a good site for hiring that kind of labor?

Regards,
Jason

see

unread,
Sep 1, 2009, 3:31:33 PM9/1/09
to cssutils
hi Jason,
very nice!

> I have one question: Is the approach I took, injecting the profile
> into cssutils.profile, a reasonable and desirable approach, or would
> you have done it differently?

yes, exactly as I imagined it may be done. (BTW, any suggestions if
this way is easy enough.)

Some notes to your code:

You can get rid of the line

macros = cssutils.profile._MACROS.copy()

as cssutils uses these macros for any added profiles anyway (macros
given during registration have priority and may overwrite the cssutils
basic macros just like you did manually and actually they are used
twice now ;). So you should be fine in just defining:

macros = {
'paint': 'none|currentColor|{color}',
# spec actually says length, but our length macro requires units, so
use positivenum
'dasharray': '{positivenum}(\s*,\s*{positivenum})*',
}

Another thing: cssutils.profiles._MACROS defines a "length" macro,
maybe you want to use that?.
Also {color} does not yet define all SVG colors (these seem quite a
list last time I checked). You might want to defined your own colors
macro.


> But I just wanted to share this minimal success story. Next, I want
> to find someone who's interested in implementing the full SVG
> properties spec, either in svg.charts or cssutils. Do you have a
> preference where it's contributed?

Hm, not really. having the profile in cssutils would certainly be
nice. Just do what you think is best, I certainly would be willing to
add a complete (but also the minimal SVG profile) into a cssutils
release (and the SVN of course).


> I'm even willing to pay someone to complete an implementation of the
> spec. Any suggestions on a good site for hiring that kind of labor?

Sorry, not right away. Maybe someone will read your post?

Anyway, thanks a lot and let me know how this works out,
Christof

Jason R. Coombs

unread,
Sep 2, 2009, 9:16:44 AM9/2/09
to cssutils
Thanks for the suggestions.

I've decided to try getafreelancer.com to complete the rest of the
implementation. See
https://www.getafreelancer.com/projects/Python-CSS/Implement-SVG-CSS-profile
-Python.html.

Comments below.

> -----Original Message-----
> From: cssu...@googlegroups.com [mailto:cssu...@googlegroups.com] On
> Behalf Of see
>
> yes, exactly as I imagined it may be done. (BTW, any suggestions if
> this way is easy enough.)

It would have been nice to have a How-To (and maybe there is one, but I
didn't see it in my natural course). It could be as simple as a couple of
comments at the heading of profile.py that describes what needs to be done
to add an additional profile. Of course, this use-case is probably so rare
that a how-to is probably unneeded.

One thing I did encounter since my initial implementation. It appears that
macro names must not have underscores. Is that correct? When I created
unit_identifier macro in my code, it didn't seem to match properly. Renamed
it to unitidentifier and it worked fine.

I also noticed that in profiles.py, it appears positivenum allows for
negative floating-point numbers. Is that a mistake?

'positivenum': r'\d+|[-]?\d*\.\d+',

> macros = {
> 'paint': 'none|currentColor|{color}',
> # spec actually says length, but our length macro requires units,
> so
> use positivenum
> 'dasharray': '{positivenum}(\s*,\s*{positivenum})*',
> }
>
> Another thing: cssutils.profiles._MACROS defines a "length" macro,
> maybe you want to use that?.

The _MACROS['length'] requires the unitidentifiers, so I needed to override
it in the SVG macros. (see the updated source for details). It could be
that the CSS2 MACRO should be updated as well.

> Also {color} does not yet define all SVG colors (these seem quite a
> list last time I checked). You might want to defined your own colors
> macro.

Thanks for pointing that out; I hope the freelancer is able to implement all
of these.

see

unread,
Sep 3, 2009, 3:25:46 PM9/3/09
to cssutils
> I've decided to try getafreelancer.com to complete the rest of the
> implementation.  Seehttps://www.getafreelancer.com/projects/Python-CSS/Implement-SVG-CSS-...
> -Python.html.

good luck!

> It would have been nice to have a How-To (and maybe there is one, but I
> didn't see it in my natural course).  It could be as simple as a couple of
> comments at the heading of profile.py that describes what needs to be done
> to add an additional profile.  Of course, this use-case is probably so rare
> that a how-to is probably unneeded.

the only stuff available are the docs which you probably checked
anyway: http://cssutils.googlecode.com/svn/trunk/docs/html/docs/profiles.html

It is simple enough (I hope :) so for most purposes it should be
sufficient?


> One thing I did encounter since my initial implementation.  It appears that
> macro names must not have underscores.  Is that correct?  When I created
> unit_identifier macro in my code, it didn't seem to match properly. Renamed
> it to unitidentifier and it worked fine.

All macro names are expanded with a simple substitution mechanism
which only uses a-zA-Z0-9 and "-" so you cannot use underscores, yes.
A mixture of - and _ is quite ugly anyway and I actually prefer - for
any identifiers (like used in CSS or XSLT). Probably a matter of taste
really :)


> I also noticed that in profiles.py, it appears positivenum allows for
> negative floating-point numbers.  Is that a mistake?
>
>         'positivenum': r'\d+|[-]?\d*\.\d+',

uh, yes, mistake, thanks!


> >   macros = {
> >    'paint': 'none|currentColor|{color}',
> >    # spec actually says length, but our length macro requires units,
> > so
> > use positivenum
> >    'dasharray': '{positivenum}(\s*,\s*{positivenum})*',
> >    }
>
> > Another thing: cssutils.profiles._MACROS defines a "length" macro,
> > maybe you want to use that?.
>
> The _MACROS['length'] requires the unitidentifiers, so I needed to override
> it in the SVG macros. (see the updated source for details).  It could be
> that the CSS2 MACRO should be updated as well.

lenghts in CSS (AFAIK) require a unit except if they are "0".
Different for your needs?


> > Also {color} does not yet define all SVG colors (these seem quite a
> > list last time I checked). You might want to defined your own colors
> > macro.
>
> Thanks for pointing that out; I hope the freelancer is able to implement all
> of these.

;)

Jason R. Coombs

unread,
Sep 3, 2009, 3:39:34 PM9/3/09
to cssutils
On Thursday, 03 September, 2009 15:26 see wrote:
> the only stuff available are the docs which you probably checked
> anyway:
> http://cssutils.googlecode.com/svn/trunk/docs/html/docs/profiles.html
>
> It is simple enough (I hope :) so for most purposes it should be
> sufficient?

I hadn't checked the docs; I read the code instead. Reading the docs would
have been a good idea :)

> lenghts in CSS (AFAIK) require a unit except if they are "0".
> Different for your needs?

Yes. For some reason, the SVG spec defines length as having an optional
unit for any number, and this is strictly necessary too, for relative
lengths, such as the dashed line.

Reply all
Reply to author
Forward
0 new messages