You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Dylan Browne <db...@mango-solutions.com> on 2005/12/13 17:59:01 UTC

Using CSS in Batik

Hi,

 

Im trying to import a CSS file into Batik in order to remove hard-wired
styles from my code. I checked out the Javadocs which helped slightly but
haven't managed to get anything working. Ive Googled and searched the
archives, and can not find any examples or sample code.

 

If anyone has a code snippet that shows how to import the CSS file, and
reference a style class within it I'd be very grateful

 

Thanks in advance, cheers,

Dylan 


RE: Using CSS in Batik

Posted by Dylan Browne <db...@mango-solutions.com>.
Thanks for that Thomas.

For anyone having a similar problem, this solution works!

Thanks again,
Dylan.


-----Original Message-----
From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com] 
Sent: 14 December 2005 11:06
To: batik-users@xmlgraphics.apache.org
Subject: RE: Using CSS in Batik

Hi Dylan,

"Dylan Browne" <db...@mango-solutions.com> wrote on 12/14/2005 02:09:28 
AM:

> Sorry, I wasn't specific enough in my question. I am familiar with using 
CSS
> in SVG, but I have recently begun using the Apache Batik SVG java 
libraries,
> using the SVG DOM, to create SVG dynamically from java.
> 
> Currently I am using code like this to style my Elements:
> 
> text.setAttributeNS(null, "style",
> "fill:green;font-family:sans-serif;font-size:18pt;text-anchor:middle");
> 
> And what I would like to be able to do instead is import my stylesheet 
into
> the SVG DOC that I generate through Java.

   Just create an 'xml-stylesheet' processing instruction and insert it
before the root element in your dynamic document:

        ProcessingInstruction pi = doc.createProcessingInstruction
        ("xml-stylesheet", "type=\"text/css\" href=\"foo.css\"");
        doc.insertBefore(pi, doc.getRootElement()); 

> I can see there is a style sheet class, but no examples on how to use 
it.
> That's really what I was after.

   I don't think there is a standard way to construct a stylesheet
'in memory' and attach it to a document.  To be honest I'm not an
expert in the CSS DOM.  If you wanted to hack against Batik internals
you might be able to pull it off but it would be fairly ugly.  The
main 'CSS' class in Batik is org.apache.batik.css.engine.CSSEngine
but it seems to always get it's list of StyleSheets from the document.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: Using CSS in Batik

Posted by th...@kodak.com.
Hi Dylan,

"Dylan Browne" <db...@mango-solutions.com> wrote on 12/14/2005 02:09:28 
AM:

> Sorry, I wasn't specific enough in my question. I am familiar with using 
CSS
> in SVG, but I have recently begun using the Apache Batik SVG java 
libraries,
> using the SVG DOM, to create SVG dynamically from java.
> 
> Currently I am using code like this to style my Elements:
> 
> text.setAttributeNS(null, "style",
> "fill:green;font-family:sans-serif;font-size:18pt;text-anchor:middle");
> 
> And what I would like to be able to do instead is import my stylesheet 
into
> the SVG DOC that I generate through Java.

   Just create an 'xml-stylesheet' processing instruction and insert it
before the root element in your dynamic document:

        ProcessingInstruction pi = doc.createProcessingInstruction
        ("xml-stylesheet", "type=\"text/css\" href=\"foo.css\"");
        doc.insertBefore(pi, doc.getRootElement()); 

> I can see there is a style sheet class, but no examples on how to use 
it.
> That's really what I was after.

   I don't think there is a standard way to construct a stylesheet
'in memory' and attach it to a document.  To be honest I'm not an
expert in the CSS DOM.  If you wanted to hack against Batik internals
you might be able to pull it off but it would be fairly ugly.  The
main 'CSS' class in Batik is org.apache.batik.css.engine.CSSEngine
but it seems to always get it's list of StyleSheets from the document.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


RE: Using CSS in Batik

Posted by Dylan Browne <db...@mango-solutions.com>.
Hi, thanks for the reply. 

Sorry, I wasn't specific enough in my question. I am familiar with using CSS
in SVG, but I have recently begun using the Apache Batik SVG java libraries,
using the SVG DOM, to create SVG dynamically from java.

Currently I am using code like this to style my Elements:

text.setAttributeNS(null, "style",
"fill:green;font-family:sans-serif;font-size:18pt;text-anchor:middle");

And what I would like to be able to do instead is import my stylesheet into
the SVG DOC that I generate through Java.

I can see there is a style sheet class, but no examples on how to use it.
That's really what I was after.

Any further advice very gratefully received.

Thanks in advance again,
Dylan

-----Original Message-----
From: thomas.deweese@kodak.com [mailto:thomas.deweese@kodak.com] 
Sent: 14 December 2005 01:23
To: batik-users@xmlgraphics.apache.org
Subject: Re: Using CSS in Batik

Hi Dylan,

"Dylan Browne" <db...@mango-solutions.com> wrote on 12/13/2005 11:59:01 
AM:

> Im trying to import a CSS file into Batik in order to remove hard-wired 
styles
> from my code. I checked out the Javadocs which helped slightly but 
haven't 
> managed to get anything working. Ive Googled and searched the archives, 
and 
> can not find any examples or sample code.

   You might try looking at the SVG specification.  You use the
'style' element to reference CSS style sheets.  You might also take
a look at samples/tests/spec/styling in general and 
'alternateStylesheet.svg' in particular.

> If anyone has a code snippet that shows how to import the CSS file, and 
> reference a style class within it I'd be very grateful

   You don't reference a style class with in the selector selects
elements from your document that they apply to based on the selector
associated with the style.



---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Using CSS in Batik

Posted by th...@kodak.com.
Hi Dylan,

"Dylan Browne" <db...@mango-solutions.com> wrote on 12/13/2005 11:59:01 
AM:

> Im trying to import a CSS file into Batik in order to remove hard-wired 
styles
> from my code. I checked out the Javadocs which helped slightly but 
haven’t 
> managed to get anything working. Ive Googled and searched the archives, 
and 
> can not find any examples or sample code.

   You might try looking at the SVG specification.  You use the
'style' element to reference CSS style sheets.  You might also take
a look at samples/tests/spec/styling in general and 
'alternateStylesheet.svg' in particular.

> If anyone has a code snippet that shows how to import the CSS file, and 
> reference a style class within it I’d be very grateful

   You don't reference a style class with in the selector selects
elements from your document that they apply to based on the selector
associated with the style.