[prev in list] [next in list] [prev in thread] [next in thread] 

List:       batik-users
Subject:    Re: keeping DOM and Graphics in sync
From:       DeWeese Thomas <thomas.deweese () gmail ! com>
Date:       2012-10-23 23:42:44
Message-ID: BF6C4B2C-653F-44FD-BD1D-1D108E79933C () gmail ! com
[Download RAW message or body]

Hi Ruben,
   Sorry w/o knowing what SvgUtil.setSvgAttribute does it's hard to know for sure but the
raw 'setAttributeNS' version looks good to me so if the SvgUtil version was different that may be it.

   Thomas

On Oct 18, 2012, at 6:57 AM, rm <ruben.malchow@googlemail.com> wrote:

> 
> 
> ***cough*** it seems to work now … if somebody knows why? this is the same code after fiddling with it:
> 
> something about attribute namespaces?
> 
> 
> 			DOMImplementation domImpl = new SVGDOMImplementation();
> 			SVGDocument svg = (SVGDocument) domImpl.createDocument(
> 					SvgNamespaceContext.SVG_NS_URI,
> 					SvgNamespaceContext.SVG_NS_PREFIX, null);
> 
> 			SVGGraphics2D graphics = new SVGGraphics2D(svg);
> 			UserAgent userAgent = new UserAgentAdapter();
> 			DocumentLoader loader = new DocumentLoader(userAgent);
> 			BridgeContext ctx = new BridgeContext(userAgent, loader);
> 			ctx.setDynamicState(BridgeContext.DYNAMIC);
> 			GVTBuilder builder = new GVTBuilder();
> 			GraphicsNode rootGN = builder.build(ctx, svg);
> 
> 			// create a G node
> 			Element g = svg.createElementNS(SvgNamespaceContext.SVG_NS_URI,SVG12Constants.SVG_G_TAG);
> 			g.setAttributeNS(null,"id", "test-g");
> 			svg.getDocumentElement().appendChild(g);
> 			
> 			Element n = svg.createElementNS(SvgNamespaceContext.SVG_NS_URI,SVG12Constants.SVG_RECT_TAG);
> 			n.setAttributeNS(null,"id", "test-rect");
> 			n.setAttributeNS(null,"x", "5");
> 			n.setAttributeNS(null,"y", "15");
> 			n.setAttributeNS(null,"width", "300");
> 			n.setAttributeNS(null,"height", "150");
> 			n.setAttributeNS(null,"fill", "orange");
> 			n.setAttributeNS(null,"transform", "rotate(10,4,2)");
> 			g.appendChild(n);
> 
> 			System.err.println(" ========> g "+((SVGLocatable)g).getBBox().getWidth());
> 			System.err.println(" ========> g "+((SVGLocatable)g).getBBox().getHeight());
> 			System.err.println(" ========> r "+((SVGLocatable)n).getBBox().getWidth());
> 			System.err.println(" ========> r "+((SVGLocatable)n).getBBox().getHeight());
> 
> 			System.err.println();
> 			XmlUtil.transform(svg, System.err);
> 			System.err.println();
> 			
> 			ByteArrayOutputStream baos = new ByteArrayOutputStream();
> 			XmlUtil.transform(ctx.getDocument(), baos);
> 			
> 			dByte = baos.toByteArray();
> 			
> 			
> 			System.err.flush(); 


[Attachment #3 (unknown)]

<html><head><meta http-equiv="Content-Type" content="text/html \
charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: \
space; -webkit-line-break: after-white-space; ">Hi Ruben,<div>&nbsp; &nbsp;Sorry w/o \
knowing what SvgUtil.setSvgAttribute does it's hard to know for sure but \
the</div><div>raw 'setAttributeNS' version looks good to me so if the SvgUtil version \
was different that may be it.</div><div><br></div><div>&nbsp; \
&nbsp;Thomas</div><div><br><div><div>On Oct 18, 2012, at 6:57 AM, rm &lt;<a \
href="mailto:ruben.malchow@googlemail.com">ruben.malchow@googlemail.com</a>&gt; \
wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div \
style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: \
after-white-space; "><div><br></div><div><br></div>***cough*** it seems to work now … \
if somebody knows why? this is the same code after fiddling with \
it:<div><br></div><div>something about attribute \
namespaces?<br><div><br></div><div><br></div><div style="margin-top: 0px; \
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal \
11px/normal Monaco; "><span class="Apple-tab-span" \
style="white-space:pre">			</span>DOMImplementation domImpl = <span style="color: \
#951865">new</span> SVGDOMImplementation();</div><div style="margin-top: 0px; \
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal \
11px/normal Monaco; "><span class="Apple-tab-span" \
style="white-space:pre">			</span>SVGDocument svg = (SVGDocument) \
domImpl.createDocument(</div><div style="margin-top: 0px; margin-right: 0px; \
margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; \
"><span class="Apple-tab-span" \
style="white-space:pre">					</span>SvgNamespaceContext.<span style="color: \
#341ec4">SVG_NS_URI</span>,</div><div style="margin-top: 0px; margin-right: 0px; \
margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; \
"><span class="Apple-tab-span" \
style="white-space:pre">					</span>SvgNamespaceContext.<span style="color: \
#341ec4">SVG_NS_PREFIX</span>, <span style="color: #951865">null</span>);</div><div \
style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \
font: normal normal normal 11px/normal Monaco; min-height: 15px; "><br></div><div \
style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \
font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" \
style="white-space:pre">			</span>SVGGraphics2D <span style="text-decoration: \
underline">graphics</span> = <span style="color: #951865">new</span> \
SVGGraphics2D(svg);</div><div style="margin-top: 0px; margin-right: 0px; \
margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; \
"><span class="Apple-tab-span" style="white-space:pre">			</span>UserAgent userAgent \
= <span style="color: #951865">new</span> UserAgentAdapter();</div><div \
style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \
font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" \
style="white-space:pre">			</span>DocumentLoader loader = <span style="color: \
#951865">new</span> DocumentLoader(userAgent);</div><div style="margin-top: 0px; \
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal \
11px/normal Monaco; "><span class="Apple-tab-span" \
style="white-space:pre">			</span>BridgeContext ctx = <span style="color: \
#951865">new</span> BridgeContext(userAgent, loader);</div><div style="margin-top: \
0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal \
normal 11px/normal Monaco; "><span class="Apple-tab-span" \
style="white-space:pre">			</span>ctx.setDynamicState(BridgeContext.<span \
style="color: #341ec4">DYNAMIC</span>);</div><div style="margin-top: 0px; \
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal \
11px/normal Monaco; "><span class="Apple-tab-span" \
style="white-space:pre">			</span>GVTBuilder builder = <span style="color: \
#951865">new</span> GVTBuilder();</div><div style="margin-top: 0px; margin-right: \
0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal \
Monaco; "><span class="Apple-tab-span" style="white-space:pre">			</span>GraphicsNode \
<span style="text-decoration: underline">rootGN</span> = builder.build(ctx, \
svg);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; \
margin-left: 0px; font: normal normal normal 11px/normal Monaco; min-height: 15px; \
"><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; \
margin-left: 0px; font: normal normal normal 11px/normal Monaco; color: rgb(72, 143, \
115); "><span style=""><span class="Apple-tab-span" \
style="white-space:pre">			</span></span>// create a G node</div><div \
style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \
font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" \
style="white-space:pre">			</span>Element g = \
svg.createElementNS(SvgNamespaceContext.<span style="color: \
#341ec4">SVG_NS_URI</span>,SVG12Constants.<span style="color: \
#341ec4">SVG_G_TAG</span>);</div><div style="margin-top: 0px; margin-right: 0px; \
margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; \
"><span class="Apple-tab-span" \
style="white-space:pre">			</span>g.setAttributeNS(<span style="color: \
#951865">null</span>,<span style="color: #5626f8">"id"</span>, <span style="color: \
#5626f8">"test-g"</span>);</div><div style="margin-top: 0px; margin-right: 0px; \
margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; \
"><span class="Apple-tab-span" \
style="white-space:pre">			</span>svg.getDocumentElement().appendChild(g);</div><div \
style="margin: 0px; font-style: normal; font-variant: normal; font-weight: normal; \
font-size: 11px; line-height: normal; font-family: Monaco; min-height: 15px; "><span \
class="Apple-tab-span" style="white-space:pre">			</span><br \
class="webkit-block-placeholder"></div><div style="margin-top: 0px; margin-right: \
0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal \
Monaco; "><span class="Apple-tab-span" style="white-space:pre">			</span>Element n = \
svg.createElementNS(SvgNamespaceContext.<span style="color: \
#341ec4">SVG_NS_URI</span>,SVG12Constants.<span style="color: \
#341ec4">SVG_RECT_TAG</span>);</div><div style="margin-top: 0px; margin-right: 0px; \
margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; \
"><span class="Apple-tab-span" \
style="white-space:pre">			</span>n.setAttributeNS(<span style="color: \
#951865">null</span>,<span style="color: #5626f8">"id"</span>, <span style="color: \
#5626f8">"test-rect"</span>);</div><div style="margin-top: 0px; margin-right: 0px; \
margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; \
"><span class="Apple-tab-span" \
style="white-space:pre">			</span>n.setAttributeNS(<span style="color: \
#951865">null</span>,<span style="color: #5626f8">"x"</span>, <span style="color: \
#5626f8">"5"</span>);</div><div style="margin-top: 0px; margin-right: 0px; \
margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; \
"><span class="Apple-tab-span" \
style="white-space:pre">			</span>n.setAttributeNS(<span style="color: \
#951865">null</span>,<span style="color: #5626f8">"y"</span>, <span style="color: \
#5626f8">"15"</span>);</div><div style="margin-top: 0px; margin-right: 0px; \
margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; \
"><span class="Apple-tab-span" \
style="white-space:pre">			</span>n.setAttributeNS(<span style="color: \
#951865">null</span>,<span style="color: #5626f8">"width"</span>, <span style="color: \
#5626f8">"300"</span>);</div><div style="margin-top: 0px; margin-right: 0px; \
margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; \
"><span class="Apple-tab-span" \
style="white-space:pre">			</span>n.setAttributeNS(<span style="color: \
#951865">null</span>,<span style="color: #5626f8">"height"</span>, <span \
style="color: #5626f8">"150"</span>);</div><div style="margin-top: 0px; margin-right: \
0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal \
Monaco; "><span class="Apple-tab-span" \
style="white-space:pre">			</span>n.setAttributeNS(<span style="color: \
#951865">null</span>,<span style="color: #5626f8">"fill"</span>, <span style="color: \
#5626f8">"orange"</span>);</div><div style="margin-top: 0px; margin-right: 0px; \
margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; \
color: rgb(86, 38, 248); "><span style=""><span class="Apple-tab-span" \
style="white-space:pre">			</span>n.setAttributeNS(</span><span style="color: \
#951865">null</span><span style="">,</span>"transform"<span style="">, \
</span>"rotate(10,4,2)"<span style="">);</span></div><div style="margin-top: 0px; \
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal \
11px/normal Monaco; "><span class="Apple-tab-span" \
style="white-space:pre">			</span>g.appendChild(n);</div><div style="margin-top: 0px; \
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal \
11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; \
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal \
11px/normal Monaco; "><span class="Apple-tab-span" \
style="white-space:pre">			</span>System.<span style="color: \
#341ec4">err</span>.println(<span style="color: #5626f8">" ========&gt; g \
"</span>+((SVGLocatable)g).getBBox().getWidth());</div><div style="margin-top: 0px; \
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal \
11px/normal Monaco; "><span class="Apple-tab-span" \
style="white-space:pre">			</span>System.<span style="color: \
#341ec4">err</span>.println(<span style="color: #5626f8">" ========&gt; g \
"</span>+((SVGLocatable)g).getBBox().getHeight());</div><div style="margin-top: 0px; \
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal \
11px/normal Monaco; "><span class="Apple-tab-span" \
style="white-space:pre">			</span>System.<span style="color: \
#341ec4">err</span>.println(<span style="color: #5626f8">" ========&gt; r \
"</span>+((SVGLocatable)n).getBBox().getWidth());</div><div style="margin-top: 0px; \
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal \
11px/normal Monaco; "><span class="Apple-tab-span" \
style="white-space:pre">			</span>System.<span style="color: \
#341ec4">err</span>.println(<span style="color: #5626f8">" ========&gt; r \
"</span>+((SVGLocatable)n).getBBox().getHeight());</div><div style="margin-top: 0px; \
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal \
11px/normal Monaco; min-height: 15px; "><br></div><div style="margin-top: 0px; \
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal \
11px/normal Monaco; "><span class="Apple-tab-span" \
style="white-space:pre">			</span>System.<span style="color: \
#341ec4">err</span>.println();</div><div style="margin-top: 0px; margin-right: 0px; \
margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; \
"><span class="Apple-tab-span" \
style="white-space:pre">			</span>XmlUtil.transform(svg, System.<span style="color: \
#341ec4">err</span>);</div><div style="margin-top: 0px; margin-right: 0px; \
margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; \
"><span class="Apple-tab-span" style="white-space:pre">			</span>System.<span \
style="color: #341ec4">err</span>.println();</div><div style="margin: 0px; \
font-style: normal; font-variant: normal; font-weight: normal; font-size: 11px; \
line-height: normal; font-family: Monaco; min-height: 15px; "><span \
class="Apple-tab-span" style="white-space:pre">			</span><br \
class="webkit-block-placeholder"></div><div style="margin-top: 0px; margin-right: \
0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal \
Monaco; "><span class="Apple-tab-span" \
style="white-space:pre">			</span>ByteArrayOutputStream baos = <span style="color: \
#951865">new</span> ByteArrayOutputStream();</div><div style="margin-top: 0px; \
margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal \
11px/normal Monaco; "><span class="Apple-tab-span" \
style="white-space:pre">			</span>XmlUtil.transform(ctx.getDocument(), \
baos);</div><div style="margin: 0px; font-style: normal; font-variant: normal; \
font-weight: normal; font-size: 11px; line-height: normal; font-family: Monaco; \
min-height: 15px; "><span class="Apple-tab-span" \
style="white-space:pre">			</span><br class="webkit-block-placeholder"></div><div \
style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; \
font: normal normal normal 11px/normal Monaco; "><span class="Apple-tab-span" \
style="white-space:pre">			</span>dByte = baos.toByteArray();</div><div \
style="margin: 0px; font-style: normal; font-variant: normal; font-weight: normal; \
font-size: 11px; line-height: normal; font-family: Monaco; min-height: 15px; "><span \
class="Apple-tab-span" style="white-space:pre">			</span><br \
class="webkit-block-placeholder"></div><div style="margin: 0px; font-style: normal; \
font-variant: normal; font-weight: normal; font-size: 11px; line-height: normal; \
font-family: Monaco; min-height: 15px; "><span class="Apple-tab-span" \
style="white-space:pre">			</span><br \
class="webkit-block-placeholder"></div><div><span class="Apple-style-span" \
style="font-family: Monaco; font-size: 11px; "><span class="Apple-tab-span" \
style="white-space:pre">			</span></span><span class="Apple-style-span" \
style="font-family: Monaco; font-size: 11px; ">System.</span><span \
class="Apple-style-span" style="font-family: Monaco; font-size: 11px; "><span \
style="color: #341ec4">err</span></span><span class="Apple-style-span" \
style="font-family: Monaco; font-size: 11px; \
">.flush();</span>&nbsp;</div></div></div></blockquote></div><br></div></body></html>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic