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 Maik Schürer proveo GmbH <Ma...@proveo.de> on 2004/10/06 08:38:49 UTC

how to get parts of the 'style' attribute

Hi,
I'm new to batik and need to change parts of  a 'style' attribute in a given
SVG.
For example: read and change the  visibility of an element:
<rect id="bg" x="0" y="0" width="800" height="600"
style="visibility:hidden;fill:rgb(0,0,255)"/>
Is this possible with BATIK ?
Thanks
Maik


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


Re: how to get parts of the 'style' attribute

Posted by Maik Schuerer <Ma...@proveo.de>.
Many thanks Thomas,
now my symbol library is fully accessible (inklusive styles) and works fine.
Currently I not completely understand all steps of your code snippet, but I
will learn and read about it ;-)
Maik
----- Original Message ----- 
From: "Thomas DeWeese" <Th...@Kodak.com>
To: "Batik Users" <ba...@xml.apache.org>
Sent: Wednesday, October 06, 2004 2:25 PM
Subject: Re: how to get parts of the 'style' attribute


Hi Maik,

    You asked questions that I thought I had already answered.

Here is a small code snippet (mostly from batik.apps.slideshow.Main):

     UserAgent      userAgent;
     DocumentLoader loader;
     BridgeContext  ctx;
     GVTBuilder builder;

         userAgent = new UserAgentAdapter();
         loader    = new DocumentLoader(userAgent);
         ctx       = new BridgeContext(userAgent, loader);
ctx.setDynamicState(BridgeContext.DYNAMIC);
         builder   = new GVTBuilder();
         builder.build(ctx, svgDoc);

    The CSS and SVG DOM interfaces will now be live.  If you don't
want/need the SVG DOM you can use BridgeContext.STATIC and save
some memory and processing time.  In any 'real world' application
you will want to subclass UserAgentAdapter.




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


Re: how to get parts of the 'style' attribute

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Maik,

    You asked questions that I thought I had already answered.

Here is a small code snippet (mostly from batik.apps.slideshow.Main):

     UserAgent      userAgent;
     DocumentLoader loader;
     BridgeContext  ctx;
     GVTBuilder builder;

         userAgent = new UserAgentAdapter();
         loader    = new DocumentLoader(userAgent);
         ctx       = new BridgeContext(userAgent, loader);
	ctx.setDynamicState(BridgeContext.DYNAMIC);
         builder   = new GVTBuilder();
         builder.build(ctx, svgDoc);

    The CSS and SVG DOM interfaces will now be live.  If you don't
want/need the SVG DOM you can use BridgeContext.STATIC and save
some memory and processing time.  In any 'real world' application
you will want to subclass UserAgentAdapter.

Maik Schuerer wrote:
> Sorry, but I don't understand what you want me to say
> Maybe because english ís not my native language ..
> Maik
> ----- Original Message ----- 
> From: "Thomas DeWeese" <Th...@Kodak.com>
> To: "Batik Users" <ba...@xml.apache.org>
> Sent: Wednesday, October 06, 2004 1:42 PM
> Subject: Re: how to get parts of the 'style' attribute
> 
> 
> 
>>Hi Maik,
>>
>>Maik Schuerer wrote:
>>
>>>>   If you are going to display or transcode the file you probably want
>>>>to wait until after those components 'build' the GVT tree before you
>>>>do your work.
>>>
>>>Yes, I know and getting styles from a (first) SVG which is diplayed at a
>>>JSVGCanvas works fine and is controlled by the SVGDocumentLoaderListener
> 
> and
> 
>>>GVTTreeBuilderListener. But my (second) SVG document will never be
> 
> displayed
> 
>>>or manipulate, because it is my 'symbol library' and I want to read some
>>>elements with there styles from it. 'Normal' attributes I can read
>>>immediately after SVGDocumentFactory.createSVGDocument(svgURI) - but why
> 
> not
> 
>>>the styles ?
>>
>> >>    Because we are a toolkit, we don't automatically build
>> >>the CSS or SVG DOM information (there is additional information
>> >>that we want/need - like a UserAgent for errors/security handling).
>>
>>
>>>What can I do with my 'symbol library' to have access to styles
>>>too ? Should I use a second dummy JSVGCanvas to get it work or is there
> 
> a
> 
>>>other way ?
>>
>> >> If you are just manipulating the document before
>> >> writing it back out then you will have to 'bootstrap' the document
>> >> yourself.  Search this list for references to
>> >> GVTBuilder/BridgeContext.
>>
>>
>>
>>
>>>Thanks in advance
>>>Maik
>>>
>>>----- Original Message ----- 
>>>From: "Thomas DeWeese" <Th...@Kodak.com>
>>>To: "Batik Users" <ba...@xml.apache.org>
>>>Sent: Wednesday, October 06, 2004 12:12 PM
>>>Subject: Re: how to get parts of the 'style' attribute
>>>
>>>
>>>
>>>
>>>>Hi Maik,
>>>>
>>>>   Because we are a toolkit, we don't automatically build
>>>>the CSS or SVG DOM information (there is additional information
>>>>that we want/need - like a UserAgent for errors/security handling).
>>>>
>>>>   If you are going to display or transcode the file you probably want
>>>>to wait until after those components 'build' the GVT tree before you
>>>>do your work.  If you are just manipulating the document before
>>>>writing it back out then you will have to 'bootstrap' the document
>>>>yourself.  Search this list for references to
>>>>GVTBuilder/BridgeContext.
>>>>
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
>>>For additional commands, e-mail: batik-users-help@xml.apache.org
>>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
>>For additional commands, e-mail: batik-users-help@xml.apache.org
>>
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 



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


Re: how to get parts of the 'style' attribute

Posted by Maik Schuerer <Ma...@proveo.de>.
Sorry, but I don't understand what you want me to say
Maybe because english ís not my native language ..
Maik
----- Original Message ----- 
From: "Thomas DeWeese" <Th...@Kodak.com>
To: "Batik Users" <ba...@xml.apache.org>
Sent: Wednesday, October 06, 2004 1:42 PM
Subject: Re: how to get parts of the 'style' attribute


> Hi Maik,
>
> Maik Schuerer wrote:
> >>    If you are going to display or transcode the file you probably want
> >>to wait until after those components 'build' the GVT tree before you
> >>do your work.
> >
> > Yes, I know and getting styles from a (first) SVG which is diplayed at a
> > JSVGCanvas works fine and is controlled by the SVGDocumentLoaderListener
and
> > GVTTreeBuilderListener. But my (second) SVG document will never be
displayed
> > or manipulate, because it is my 'symbol library' and I want to read some
> > elements with there styles from it. 'Normal' attributes I can read
> > immediately after SVGDocumentFactory.createSVGDocument(svgURI) - but why
not
> > the styles ?
>
>  >>    Because we are a toolkit, we don't automatically build
>  >>the CSS or SVG DOM information (there is additional information
>  >>that we want/need - like a UserAgent for errors/security handling).
>
> > What can I do with my 'symbol library' to have access to styles
> > too ? Should I use a second dummy JSVGCanvas to get it work or is there
a
> > other way ?
>
>  >> If you are just manipulating the document before
>  >> writing it back out then you will have to 'bootstrap' the document
>  >> yourself.  Search this list for references to
>  >> GVTBuilder/BridgeContext.
>
>
>
> > Thanks in advance
> > Maik
> >
> > ----- Original Message ----- 
> > From: "Thomas DeWeese" <Th...@Kodak.com>
> > To: "Batik Users" <ba...@xml.apache.org>
> > Sent: Wednesday, October 06, 2004 12:12 PM
> > Subject: Re: how to get parts of the 'style' attribute
> >
> >
> >
> >>Hi Maik,
> >>
> >>    Because we are a toolkit, we don't automatically build
> >>the CSS or SVG DOM information (there is additional information
> >>that we want/need - like a UserAgent for errors/security handling).
> >>
> >>    If you are going to display or transcode the file you probably want
> >>to wait until after those components 'build' the GVT tree before you
> >>do your work.  If you are just manipulating the document before
> >>writing it back out then you will have to 'bootstrap' the document
> >>yourself.  Search this list for references to
> >>GVTBuilder/BridgeContext.
> >>
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> > For additional commands, e-mail: batik-users-help@xml.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
>
>


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


Re: how to get parts of the 'style' attribute

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Maik,

Maik Schuerer wrote:
>>    If you are going to display or transcode the file you probably want
>>to wait until after those components 'build' the GVT tree before you
>>do your work.
> 
> Yes, I know and getting styles from a (first) SVG which is diplayed at a
> JSVGCanvas works fine and is controlled by the SVGDocumentLoaderListener and
> GVTTreeBuilderListener. But my (second) SVG document will never be displayed
> or manipulate, because it is my 'symbol library' and I want to read some
> elements with there styles from it. 'Normal' attributes I can read
> immediately after SVGDocumentFactory.createSVGDocument(svgURI) - but why not
> the styles ? 

 >>    Because we are a toolkit, we don't automatically build
 >>the CSS or SVG DOM information (there is additional information
 >>that we want/need - like a UserAgent for errors/security handling).

> What can I do with my 'symbol library' to have access to styles
> too ? Should I use a second dummy JSVGCanvas to get it work or is there a
> other way ?

 >> If you are just manipulating the document before
 >> writing it back out then you will have to 'bootstrap' the document
 >> yourself.  Search this list for references to
 >> GVTBuilder/BridgeContext.



> Thanks in advance
> Maik
> 
> ----- Original Message ----- 
> From: "Thomas DeWeese" <Th...@Kodak.com>
> To: "Batik Users" <ba...@xml.apache.org>
> Sent: Wednesday, October 06, 2004 12:12 PM
> Subject: Re: how to get parts of the 'style' attribute
> 
> 
> 
>>Hi Maik,
>>
>>    Because we are a toolkit, we don't automatically build
>>the CSS or SVG DOM information (there is additional information
>>that we want/need - like a UserAgent for errors/security handling).
>>
>>    If you are going to display or transcode the file you probably want
>>to wait until after those components 'build' the GVT tree before you
>>do your work.  If you are just manipulating the document before
>>writing it back out then you will have to 'bootstrap' the document
>>yourself.  Search this list for references to
>>GVTBuilder/BridgeContext.
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 


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


Re: how to get parts of the 'style' attribute

Posted by Maik Schuerer <Ma...@proveo.de>.
>     If you are going to display or transcode the file you probably want
> to wait until after those components 'build' the GVT tree before you
> do your work.
Yes, I know and getting styles from a (first) SVG which is diplayed at a
JSVGCanvas works fine and is controlled by the SVGDocumentLoaderListener and
GVTTreeBuilderListener. But my (second) SVG document will never be displayed
or manipulate, because it is my 'symbol library' and I want to read some
elements with there styles from it. 'Normal' attributes I can read
immediately after SVGDocumentFactory.createSVGDocument(svgURI) - but why not
the styles ? What can I do with my 'symbol library' to have access to styles
too ? Should I use a second dummy JSVGCanvas to get it work or is there a
other way ?
Thanks in advance
Maik

----- Original Message ----- 
From: "Thomas DeWeese" <Th...@Kodak.com>
To: "Batik Users" <ba...@xml.apache.org>
Sent: Wednesday, October 06, 2004 12:12 PM
Subject: Re: how to get parts of the 'style' attribute


> Hi Maik,
>
>     Because we are a toolkit, we don't automatically build
> the CSS or SVG DOM information (there is additional information
> that we want/need - like a UserAgent for errors/security handling).
>
>     If you are going to display or transcode the file you probably want
> to wait until after those components 'build' the GVT tree before you
> do your work.  If you are just manipulating the document before
> writing it back out then you will have to 'bootstrap' the document
> yourself.  Search this list for references to
> GVTBuilder/BridgeContext.
>


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


Re: how to get parts of the 'style' attribute

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Maik,

    Because we are a toolkit, we don't automatically build
the CSS or SVG DOM information (there is additional information
that we want/need - like a UserAgent for errors/security handling).

    If you are going to display or transcode the file you probably want
to wait until after those components 'build' the GVT tree before you
do your work.  If you are just manipulating the document before
writing it back out then you will have to 'bootstrap' the document
yourself.  Search this list for references to
GVTBuilder/BridgeContext.

Maik Schuerer wrote:

> ok, I try to cast my element to SVGStylable, but getStyle throws a
> NullPointerException:
> 
> but I checked: s (SVGStylabl) itself is not null ! (it is a
> SVGOMRectElement):
> 
>   SVGStylable s = (SVGStylable)myElement;
>   CSSStyleDeclaration sd = s.getStyle();
> 
> java.lang.NullPointerException
>  at
> org.apache.batik.dom.svg.SVGStylableElement$StyleDeclaration.<init>(Unknown
> Source)
>  at org.apache.batik.dom.svg.SVGStylableElement.getStyle(Unknown Source)
> 
> any idea ? is it the wrong way to get SVGStylable ?
> Maik
> 
> ----- Original Message ----- 
> From: "Cameron McCormack" <ca...@aka.mcc.id.au>
> To: "Batik Users" <ba...@xml.apache.org>
> Sent: Wednesday, October 06, 2004 8:59 AM
> Subject: Re: how to get parts of the 'style' attribute
> 
> 
> 
>>Maik Schrer  proveo GmbH:
>>
>>>Thanks Cameron for fast reply
>>>but what is the type (class) of 'bgRect' with a method 'getStyle' in
> 
> your
> 
>>>example and how to get it?
>>
>>It is org.w3c.dom.svg.SVGStylable:
>>
>>  http://www.w3.org/TR/SVG11/types.html#InterfaceSVGStylable
>>
>>Cameron
>>
>>-- 
>>Cameron McCormack
>>|  Web: http://mcc.id.au/
>>|  ICQ: 26955922
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
>>For additional commands, e-mail: batik-users-help@xml.apache.org
>>
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 


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


Re: how to get parts of the 'style' attribute

Posted by Maik Schuerer <Ma...@proveo.de>.
ok, I try to cast my element to SVGStylable, but getStyle throws a
NullPointerException:

but I checked: s (SVGStylabl) itself is not null ! (it is a
SVGOMRectElement):

  SVGStylable s = (SVGStylable)myElement;
  CSSStyleDeclaration sd = s.getStyle();

java.lang.NullPointerException
 at
org.apache.batik.dom.svg.SVGStylableElement$StyleDeclaration.<init>(Unknown
Source)
 at org.apache.batik.dom.svg.SVGStylableElement.getStyle(Unknown Source)

any idea ? is it the wrong way to get SVGStylable ?
Maik

----- Original Message ----- 
From: "Cameron McCormack" <ca...@aka.mcc.id.au>
To: "Batik Users" <ba...@xml.apache.org>
Sent: Wednesday, October 06, 2004 8:59 AM
Subject: Re: how to get parts of the 'style' attribute


> Maik Schrer  proveo GmbH:
> > Thanks Cameron for fast reply
> > but what is the type (class) of 'bgRect' with a method 'getStyle' in
your
> > example and how to get it?
>
> It is org.w3c.dom.svg.SVGStylable:
>
>   http://www.w3.org/TR/SVG11/types.html#InterfaceSVGStylable
>
> Cameron
>
> -- 
> Cameron McCormack
> |  Web: http://mcc.id.au/
> |  ICQ: 26955922
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
>
>


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


Re: how to get parts of the 'style' attribute

Posted by Cameron McCormack <ca...@aka.mcc.id.au>.
Maik Schrer  proveo GmbH:
> Thanks Cameron for fast reply
> but what is the type (class) of 'bgRect' with a method 'getStyle' in your
> example and how to get it?

It is org.w3c.dom.svg.SVGStylable:

  http://www.w3.org/TR/SVG11/types.html#InterfaceSVGStylable

Cameron

-- 
Cameron McCormack
|  Web: http://mcc.id.au/
|  ICQ: 26955922

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


Re: how to get parts of the 'style' attribute

Posted by Maik Schürer proveo GmbH <Ma...@proveo.de>.
Thanks Cameron for fast reply
but what is the type (class) of 'bgRect' with a method 'getStyle' in your
example and how to get it?
Maik
----- Original Message ----- 
From: "Cameron McCormack" <ca...@aka.mcc.id.au>
To: <ba...@xml.apache.org>
Sent: Wednesday, October 06, 2004 8:45 AM
Subject: Re: how to get parts of the 'style' attribute


> Hi Maik.
>
> Maik Schrer  proveo GmbH:
> > I'm new to batik and need to change parts of  a 'style' attribute in a
given
> > SVG.
> > For example: read and change the  visibility of an element:
> > <rect id="bg" x="0" y="0" width="800" height="600"
> > style="visibility:hidden;fill:rgb(0,0,255)"/>
> > Is this possible with BATIK ?
>
> Certainly.  In script you can use the style property of the element to
> get a CSSStyleDeclaration object that corresponds to the style
> attribute.
>
>   var currentVisibility = bgRect.style.getProperty("visibility").cssText;
>   bgRect.style.setProperty("visibility", "visible");
>
> Similarly from Java:
>
>   String currentVisibility =
>   bgRect.getStyle().getProperty("visibility)".getCssText();
>   bgRect.getStyle().setProperty("visibility", "visible");
>
> Cameron
>
> -- 
> Cameron McCormack
> |  Web: http://mcc.id.au/
> |  ICQ: 26955922
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
>
>


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


Re: how to get parts of the 'style' attribute

Posted by Cameron McCormack <ca...@aka.mcc.id.au>.
Hi Maik.

Maik Schrer  proveo GmbH:
> I'm new to batik and need to change parts of  a 'style' attribute in a given
> SVG.
> For example: read and change the  visibility of an element:
> <rect id="bg" x="0" y="0" width="800" height="600"
> style="visibility:hidden;fill:rgb(0,0,255)"/>
> Is this possible with BATIK ?

Certainly.  In script you can use the style property of the element to
get a CSSStyleDeclaration object that corresponds to the style
attribute.

  var currentVisibility = bgRect.style.getProperty("visibility").cssText;
  bgRect.style.setProperty("visibility", "visible");

Similarly from Java:

  String currentVisibility =
  	bgRect.getStyle().getProperty("visibility)".getCssText();
  bgRect.getStyle().setProperty("visibility", "visible");

Cameron

-- 
Cameron McCormack
|  Web: http://mcc.id.au/
|  ICQ: 26955922

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