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 "Frizzell, Michael A" <mi...@eds.com> on 2002/08/15 16:07:54 UTC

Filter Problem with Java

Hello,

This problem occurs only when I try and use a "filter:url(#Filter_Name)"
inside the style tag of a given item. Whenever I run the file with that
filter info in the style tag it returns a "java.lang.NullPointerException". 

Successful fixes:
- Print out the dom that I'm creating to a file, use a rasterizer to import
the xml and create the jpg.

My filter code looks as such:

public void addFilter() {
	Element newDefs = doc.createElement("defs");
	newDefs.setAttributeNS(null, "id", "filterdefs");
	root.appendChild(newDefs);

	Element cmatrix = doc.createElement("feColorMatrix");
		cmatrix.setAttributeNS(null, "type", "matrix");
		cmatrix.setAttributeNS(null, "values", "0 0 0 0 0 0 0 0 .9 0
0 0 0 .9 0 0 0 0 1 0");

	Element merge = doc.createElement("feMerge");
	Element merge1 = doc.createElement("feMergeNode");
	merge1.setAttributeNS(null, "in", "coloredBlur");
   	Element merge2 = doc.createElement("feMergeNode");
   	merge2.setAttributeNS(null, "in", "SourceGraphic");
   	merge.appendChild(merge1);
  	merge.appendChild(merge2);


	Element gblur = doc.createElement("feGaussianBlur");
  	gblur.setAttributeNS(null, "stdDeviation", "5");
   	gblur.setAttributeNS(null, "result", "coloredBlur");

	Element MyFilter = doc.createElement("filter");
	MyFilter.setAttributeNS(null, "id", "glow");
	MyFilter.appendChild(cmatrix);
	MyFilter.appendChild(gblur);
	MyFilter.appendChild(merge);

	newDefs.appendChild(MyFilter);
}

The part where I use the filter:

Element path = doc.createElementNS(svgNS,"path");

path.setAttributeNS(null,"d", "M10 191 C16.6819 172.06 26.7093 40.9726 37 34
C72.0466 10.2538 49.9817 151 108 151 C147.528 151 176.714 90 225 90 L260 90
C272.484 90 292.389 88.4206 303 96 C319.88 108.057 326.492 168.377 352 162
C378.063 155.484 377.921 118.263 397 103 C435.649 72.0804 496.52 167.533 510
195");

path.setAttributeNS(null,"style","filter:url(#glow);fill:none;stroke-width:5
;opacity:1;fill-opacity:1;stroke-opacity:1;stroke:rgb(255,255,0)");
root.appendChild(path);

I'm thinking that it has everything to do with Namespace. That somehow when
I create the dom dynamically the namespacing is getting messed up and the
filter:url(#glow) can't find the filter id correctly, but when I open import
the outputted xml through the rasterizer, it does the namespacing correctly.
Any aid in how I might resolve this would be greatly appreciated. Thanks....

	Mike

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


Filter Problem with Java

Posted by Thomas E Deweese <th...@kodak.com>.
>>>>> "FMA" == Frizzell, Michael A <mi...@eds.com> writes:

FMA> This problem occurs only when I try and use a
FMA> "filter:url(#Filter_Name)" inside the style tag of a given
FMA> item. Whenever I run the file with that filter info in the style
FMA> tag it returns a "java.lang.NullPointerException".

FMA> Successful fixes: 

FMA> - Print out the dom that I'm creating to a file, use a rasterizer
FMA> to import the xml and create the jpg.

FMA> My filter code looks as such:

FMA> public void addFilter() { 

FMA> Element newDefs = doc.createElement("defs");

     I think you want 'doc.createElementNS(svg_ns, "defs");'
Likewise for all your other elements.  The DOM is not quite as
user friendly as the raw XML.


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