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 Lukasz Matuszczak <l....@atrem.pl> on 2005/06/28 15:16:40 UTC

convert CSS class to style attribute

I would like to convert all CSS "class" attributes of svg document tags to 
"style" attributes, for example:
Input:
<?xml version="1.0" encoding="ISO-8859-2"?>
<svg   width="200" viewBox="0 0 200 400" 
height="400"xmlns="http://www.w3.org/2000/svg">
   <defs>
  <style type="text/css">
   <![CDATA[
    .str2 {stroke:#4C4C4C;stroke-width:25}
    .str1 {stroke:#FF00FF;stroke-width:7;stroke-dasharray:13 7}
    .fil1 {fill:#0000FF}
    .fil2 {fill:#00FF00}
   ]]>
  </style>
 </defs>
 <g class="fil1 str1">
    <rect x="50" y="50" width="100" height="75" class="fil2"/>
    <rect x="50" y="150" width="100" height="75"/>
    <rect x="50" y="250" width="100" height="75" class="fil2 str2"/>
 </g>
</svg>

Output:
<?xml version="1.0" encoding="ISO-8859-2"?>
<svg   width="200" viewBox="0 0 200 400" height="400" 
xmlns="http://www.w3.org/2000/svg">
 <g style="fill:#0000FF; stroke:#FF00FF;stroke-width:7;stroke-dasharray:13 7">
    <rect x="50" y="50" width="100" height="75" style="fill:#00FF00"/>
    <rect x="50" y="150" width="100" height="75"/>
    <rect x="50" y="250" width="100" height="75" 
style="fill:#00FF00;stroke:#4C4C4C;stroke-width:25"/>
 </g>
</svg>

I've thought about using Batik CSS and SVG specific DOM interfaces, but I am not 
sure if there are suitable methods for my problem.

I tried:
String styleCSS = 
((CSSStylableElement)node).getComputedStyleMap(null).toString(CSSUtilities.getCSSEngine((Element)node));
but it gives me a lot of inherited and default CSS settings for the node. For 
example for the second rect from the document above I get:
clip-path: none; color-rendering: auto; display: inline; fill: rgb(0, 255, 0); 
fill-opacity: 1; filter: none; mask: none;
opacity: 1; pointer-events: visiblepainted; shape-rendering: auto; stroke: 
rgb(255, 0, 255); stroke-dasharray: 
org.apache.batik.css.engine.value.ComputedValue@766ec3; stroke-dashoffset: 0; 
stroke-linecap: butt;
stroke-linejoin: miter; stroke-miterlimit: 4; stroke-opacity: 1; stroke-width: 
7; visibility: visible;

Thanks in advance for help,

Regards,
Lukasz Matuszczak 



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


Re: convert CSS class to style attribute

Posted by Thomas DeWeese <Th...@Kodak.com>.
Lukasz Matuszczak wrote:
> I would like to convert all CSS "class" attributes of svg document tags 
> to "style" attributes, for example:

    This is a little complex.  I'm not an expert in the CSS DOM so
it might be possible to get this information from here (however
I can't see how).  However if you are willing to dig into the
Batik implementation a little you can get that information with:

StyleMap sm = CSSEngine.getCascadedStyleMap(CSSStylableElement elt,
                               String pseudo)
short origin = sm.getOrigin(int propIdx);
if (origin == StyleMap.USER_ORIGIN) {
    // This value came from a stylesheet.
}

    You can get the CSSEngine from the BridgeContext.
    The CSSEngine can map between property Indexes and
property names (some methods of interest,
getNumberOfProperties(),
getPropertyName(int idx)).


> Input:
> <?xml version="1.0" encoding="ISO-8859-2"?>
> <svg   width="200" viewBox="0 0 200 400" 
> height="400"xmlns="http://www.w3.org/2000/svg">
>   <defs>
>  <style type="text/css">
>   <![CDATA[
>    .str2 {stroke:#4C4C4C;stroke-width:25}
>    .str1 {stroke:#FF00FF;stroke-width:7;stroke-dasharray:13 7}
>    .fil1 {fill:#0000FF}
>    .fil2 {fill:#00FF00}
>   ]]>
>  </style>
> </defs>
> <g class="fil1 str1">
>    <rect x="50" y="50" width="100" height="75" class="fil2"/>
>    <rect x="50" y="150" width="100" height="75"/>
>    <rect x="50" y="250" width="100" height="75" class="fil2 str2"/>
> </g>
> </svg>
> 
> Output:
> <?xml version="1.0" encoding="ISO-8859-2"?>
> <svg   width="200" viewBox="0 0 200 400" height="400" 
> xmlns="http://www.w3.org/2000/svg">
> <g style="fill:#0000FF; 
> stroke:#FF00FF;stroke-width:7;stroke-dasharray:13 7">
>    <rect x="50" y="50" width="100" height="75" style="fill:#00FF00"/>
>    <rect x="50" y="150" width="100" height="75"/>
>    <rect x="50" y="250" width="100" height="75" 
> style="fill:#00FF00;stroke:#4C4C4C;stroke-width:25"/>
> </g>
> </svg>
> 
> I've thought about using Batik CSS and SVG specific DOM interfaces, but 
> I am not sure if there are suitable methods for my problem.
> 
> I tried:
> String styleCSS = 
> ((CSSStylableElement)node).getComputedStyleMap(null).toString(CSSUtilities.getCSSEngine((Element)node)); 
> 
> but it gives me a lot of inherited and default CSS settings for the 
> node. For example for the second rect from the document above I get:
> clip-path: none; color-rendering: auto; display: inline; fill: rgb(0, 
> 255, 0); fill-opacity: 1; filter: none; mask: none;
> opacity: 1; pointer-events: visiblepainted; shape-rendering: auto; 
> stroke: rgb(255, 0, 255); stroke-dasharray: 
> org.apache.batik.css.engine.value.ComputedValue@766ec3; 
> stroke-dashoffset: 0; stroke-linecap: butt;
> stroke-linejoin: miter; stroke-miterlimit: 4; stroke-opacity: 1; 
> stroke-width: 7; visibility: visible;
> 
> Thanks in advance for help,
> 
> Regards,
> Lukasz Matuszczak
> 
> 
> ---------------------------------------------------------------------
> 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: convert CSS class to style attribute

Posted by Tonny Kohar <to...@kiyut.com>.
Hi,

For CSS class and Style Attributes, I do not know.

But for Presentation Attribute you can check using "attr.getSpecified()"
whether it is a default value or not.

Regards
Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com

On Tue, 2005-06-28 at 15:16 +0200, Lukasz Matuszczak wrote:
> I would like to convert all CSS "class" attributes of svg document tags to 
> "style" attributes, for example:
> Input:
> <?xml version="1.0" encoding="ISO-8859-2"?>
> <svg   width="200" viewBox="0 0 200 400" 
> height="400"xmlns="http://www.w3.org/2000/svg">
>    <defs>
>   <style type="text/css">
>    <![CDATA[
>     .str2 {stroke:#4C4C4C;stroke-width:25}
>     .str1 {stroke:#FF00FF;stroke-width:7;stroke-dasharray:13 7}
>     .fil1 {fill:#0000FF}
>     .fil2 {fill:#00FF00}
>    ]]>
>   </style>
>  </defs>
>  <g class="fil1 str1">
>     <rect x="50" y="50" width="100" height="75" class="fil2"/>
>     <rect x="50" y="150" width="100" height="75"/>
>     <rect x="50" y="250" width="100" height="75" class="fil2 str2"/>
>  </g>
> </svg>
> 
> Output:
> <?xml version="1.0" encoding="ISO-8859-2"?>
> <svg   width="200" viewBox="0 0 200 400" height="400" 
> xmlns="http://www.w3.org/2000/svg">
>  <g style="fill:#0000FF; stroke:#FF00FF;stroke-width:7;stroke-dasharray:13 7">
>     <rect x="50" y="50" width="100" height="75" style="fill:#00FF00"/>
>     <rect x="50" y="150" width="100" height="75"/>
>     <rect x="50" y="250" width="100" height="75" 
> style="fill:#00FF00;stroke:#4C4C4C;stroke-width:25"/>
>  </g>
> </svg>
> 
> I've thought about using Batik CSS and SVG specific DOM interfaces, but I am not 
> sure if there are suitable methods for my problem.
> 
> I tried:
> String styleCSS = 
> ((CSSStylableElement)node).getComputedStyleMap(null).toString(CSSUtilities.getCSSEngine((Element)node));
> but it gives me a lot of inherited and default CSS settings for the node. For 
> example for the second rect from the document above I get:
> clip-path: none; color-rendering: auto; display: inline; fill: rgb(0, 255, 0); 
> fill-opacity: 1; filter: none; mask: none;
> opacity: 1; pointer-events: visiblepainted; shape-rendering: auto; stroke: 
> rgb(255, 0, 255); stroke-dasharray: 
> org.apache.batik.css.engine.value.ComputedValue@766ec3; stroke-dashoffset: 0; 
> stroke-linecap: butt;
> stroke-linejoin: miter; stroke-miterlimit: 4; stroke-opacity: 1; stroke-width: 
> 7; visibility: visible;
> 
> Thanks in advance for help,
> 
> Regards,
> Lukasz Matuszczak 
> 
> 
> 
> ---------------------------------------------------------------------
> 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