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 Selva <se...@yahoo.co.in> on 2006/04/23 09:24:58 UTC

Stroke property for feFlood filter

Hi All,

I am using feFlood for text background. But my text background should 
have "stroke" property. So that text background will be covered by border. Can 
anyone please give me the way to set "stroke" property for feFlood text 
background?

Thanks,
Selva




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


Re: Stroke property for feFlood filter

Posted by Selva <se...@yahoo.co.in>.
Hi Cameron,

Thank you very much Cameron.

Thanks,
Selva
 


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


Re: Stroke property for feFlood filter

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

Selva:
> After added the 'text' in the root only, you can able to get SVGRect. But is 
> it possible to get SVGRect/width before adding it to Root?

No it's not, since it needs to know the context (inherited CSS
properties, etc.) to compute the bounding box.

-- 
 Cameron McCormack			ICQ: 26955922
 cam (at) mcc.id.au			MSN: cam (at) mcc.id.au
 http://mcc.id.au/			JBR: heycam (at) jabber.org

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


Re: Stroke property for feFlood filter

Posted by Selva <se...@yahoo.co.in>.
Hi Cameron,

> Yes.
> 
>   Element text = doc.createElementNS(svgNS, "text");
>   Text value = doc.createTextNode("100.100.10.10");
>   text.appendChild(value);
>   text.setAttributeNS(null, "text-decoration", "none");
>   text.setAttributeNS(null, "x", "150");
>   text.setAttributeNS(null, "y", "150");
>   text.setAttributeNS(null, "font-family", "Arial");
>   text.setAttributeNS(null, "font-size", "12");
>   rootElement.appendChild(text);
>   var bbox = text.getBBox();

After added the 'text' in the root only, you can able to get SVGRect. But is 
it possible to get SVGRect/width before adding it to Root?

Thanks,
Selva




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


Re: Stroke property for feFlood filter

Posted by Cameron McCormack <ca...@mcc.id.au>.
Selva:
> getBBox and getComputedTextLength is returning the required values 
> after 'Text' Element has added in RootElement. But is it possible to create 
> the rectangle while creating the 'Text' Element?

Yes.

  Element text = doc.createElementNS(svgNS, "text");
  Text value = doc.createTextNode("100.100.10.10");
  text.appendChild(value);
  text.setAttributeNS(null, "text-decoration", "none");
  text.setAttributeNS(null, "x", "150");
  text.setAttributeNS(null, "y", "150");
  text.setAttributeNS(null, "font-family", "Arial");
  text.setAttributeNS(null, "font-size", "12");
  rootElement.appendChild(text);
  var bbox = text.getBBox();
  Element rect = doc.createElementNS(svgNS, "rect");
  rect.setAttributeNS(null, "x", bbox.x);
  rect.setAttributeNS(null, "y", bbox.y);
  rect.setAttributeNS(null, "width", bbox.width);
  rect.setAttributeNS(null, "height", bbox.height);
  rect.setAttributeNS(null, "fill", "yellow");
  rootElement.insertBefore(rect, text);

-- 
 Cameron McCormack			ICQ: 26955922
 cam (at) mcc.id.au			MSN: cam (at) mcc.id.au
 http://mcc.id.au/			JBR: heycam (at) jabber.org

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


Re: Stroke property for feFlood filter

Posted by Selva <se...@yahoo.co.in>.
Hi Cameron,

> Sure, you can just use a 'rect' to draw the background and then display
> the text atop.  If you need to make sure that the rect covers exactly
> the area of the text, you can use some script:
> 
>   <svg xmlns="http://www.w3.org/2000/svg"
>        version="1.1" font-size="24" width="400" height="400">
>     <rect id="theTextBackground" fill="yellow" width="0" height="0"/>
>     <text id="theText" x="100" y="100">This is some text.</text>
>     <script>
>       var r = document.getElementById("theTextBackground");
>       var t = document.getElementById("theText");
>       var bbox = t.getBBox();
>       r.setAttributeNS(null, "x", bbox.x);
>       r.setAttributeNS(null, "y", bbox.y);
>       r.setAttributeNS(null, "width", bbox.width);
>       r.setAttributeNS(null, "height", bbox.height);
>     </script>
>   </svg>


getBBox and getComputedTextLength is returning the required values 
after 'Text' Element has added in RootElement. But is it possible to create 
the rectangle while creating the 'Text' Element?

Element text = doc.createElementNS(svgNS, "text");
Text value = doc.createTextNode("100.100.10.10");
text.appendChild(value);
text.setAttributeNS(null, "text-decoration", "none");
text.setAttributeNS(null, "x", "150");
text.setAttributeNS(null, "y", "150");
text.setAttributeNS(null, "font-family", "Arial");
text.setAttributeNS(null, "font-size", "12");
text.setAttributeNS(null, "width", "???") //i need to set width here.

Thanks,
Selva




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


Re: Stroke property for feFlood filter

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

Roger Critchlow:
> The problem is, I think, that the <defs> document tree never gets
> rendered directly, it gets cloned into a "hidden" document fragment
> under the <use> which gets rendered at the location specified in the
> <use>.  So none of the rendering information is available, unless you
> want to hunt down the "hidden" fragment.

That is indeed the reason there is no rendering information available
about those elements.

-- 
 Cameron McCormack			ICQ: 26955922
 cam (at) mcc.id.au			MSN: cam (at) mcc.id.au
 http://mcc.id.au/			JBR: heycam (at) jabber.org

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


Re: Stroke property for feFlood filter

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

    Just to add a little more to this so people understand why this is. It 
is
important to remember that when you use 'use' CSS inherits through the
use, so a slight modification to your example:

<defs>
   <g id="pd1">
        <text id="pt1">Regime</text>
   </g>
</defs>

<use id="pu1" xlink:href="#pd1" x="250" y="250" font-size="24"/>
<use id="pu2" xlink:href="#pd1" x="250" y="300" font-size="12"/>

   The text will be 24 user units high in the first use and
it will be 12 user units high in the second tree.  Without
knowing the text in it's actual rendering context it would
be impossible to provide an accurate bounding box...

> The problem is, I think, that the <defs> document tree never gets
> rendered directly, it gets cloned into a "hidden" document fragment
> under the <use> which gets rendered at the location specified in the
> <use>.  So none of the rendering information is available, unless you
> want to hunt down the "hidden" fragment.
> 
> -- rec --
> 
> 
> > Hmm, yes, if it's set to dynamic then the bounding box should be
> > available.  The text element is in the document and is displayed, yes?
> > Can you post a slightly larger example?
> >
> > --
> >  Cameron McCormack                      ICQ: 26955922
> >  cam (at) mcc.id.au                     MSN: cam (at) mcc.id.au
> >  http://mcc.id.au/                      JBR: heycam (at) jabber.org
> >
> > ---------------------------------------------------------------------
> > 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
> 


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


Re: Stroke property for feFlood filter

Posted by Roger Critchlow <re...@elf.org>.
Okay, I've pared the document down to this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
	xmlns="http://www.w3.org/2000/svg"
	xmlns:xlink="http://www.w3.org/1999/xlink"
    width="1024" height="1024"
	viewBox="0 0 500 500">
	<defs>
		<g id="pd1">
	    	<rect id="pr1" x="-25" y="-25" width="50" height="50" rx="10"
			fill="blue" stroke="grey" />
	     	<text id="pt1">Regime</text>
		</g>
	</defs>
	<use id="pu1" xlink:href="#pd1" x="250" y="250" />
</svg>

The setup is:

        svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
        svgCanvas.setEnableRotateInteractor(false);

After document load I call:

    /*
     * Resize a rectangle element under a text.
     */
    protected void resizeElements(String when) {
    	SVGRectElement rect = (SVGRectElement)getElementById("pr1");
    	SVGTextElement text = (SVGTextElement)getElementById("pt1");
    	SVGUseElement use = (SVGUseElement)getElementById("pu1");
    	if (rect != null && text != null && use != null) {
    		SVGRect box = text.getBBox();
    		if (box == null) System.out.println(when+": text bbox is null");
    		box = rect.getBBox();
    		if (box == null) System.out.println(when+": rect bbox is null");
    		box = use.getBBox();
    		if (box == null) System.out.println(when+": use bbox is null");
    	}
    }

And it prints:

documentLoadingCompleted: text bbox is null
documentLoadingCompleted: rect bbox is null
documentLoadingCompleted: use bbox is null

Called again later, it prints:

gvtRenderingCompleted: text bbox is null
gvtRenderingCompleted: rect bbox is null

Which answers the question of when any BBox becomes valid.

The problem is, I think, that the <defs> document tree never gets
rendered directly, it gets cloned into a "hidden" document fragment
under the <use> which gets rendered at the location specified in the
<use>.  So none of the rendering information is available, unless you
want to hunt down the "hidden" fragment.

-- rec --


> Hmm, yes, if it's set to dynamic then the bounding box should be
> available.  The text element is in the document and is displayed, yes?
> Can you post a slightly larger example?
>
> --
>  Cameron McCormack                      ICQ: 26955922
>  cam (at) mcc.id.au                     MSN: cam (at) mcc.id.au
>  http://mcc.id.au/                      JBR: heycam (at) jabber.org
>
> ---------------------------------------------------------------------
> 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: Stroke property for feFlood filter

Posted by Cameron McCormack <ca...@mcc.id.au>.
Roger Critchlow:
> You mean something like this:
> 
> 		scrollPane = new JSVGScrollPane(new JSVGCanvas(null, true, false));
> 		svgCanvas = scrollPane.getCanvas();
> 		svgCanvas.setEnablePanInteractor(true);
> 		svgCanvas.setEnableResetTransformInteractor(true);
> 		svgCanvas.setEnableRotateInteractor(false);
> 		svgCanvas.setEnableZoomInteractor(true);
> 		svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
> 
> The loadSVGDocument() takes place well after all this, and getBBox()
> still returns null.

Hmm, yes, if it's set to dynamic then the bounding box should be
available.  The text element is in the document and is displayed, yes?
Can you post a slightly larger example?

-- 
 Cameron McCormack			ICQ: 26955922
 cam (at) mcc.id.au			MSN: cam (at) mcc.id.au
 http://mcc.id.au/			JBR: heycam (at) jabber.org

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


Re: Stroke property for feFlood filter

Posted by Roger Critchlow <re...@elf.org>.
Hi Cameron:

You mean something like this:

		scrollPane = new JSVGScrollPane(new JSVGCanvas(null, true, false));
		svgCanvas = scrollPane.getCanvas();
		svgCanvas.setEnablePanInteractor(true);
		svgCanvas.setEnableResetTransformInteractor(true);
		svgCanvas.setEnableRotateInteractor(false);
		svgCanvas.setEnableZoomInteractor(true);
		svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);

The loadSVGDocument() takes place well after all this, and getBBox()
still returns null.

Another idea?

-- rec --

On 4/24/06, Cameron McCormack <ca...@mcc.id.au> wrote:
> Hi Roger.
>
> Roger Critchlow:
> > That's just what I was trying to do in Java, but textNode.getBBox()
> > returns a null.
> >
> > I was trying it first from the documentLoadingCompleted() callback,
> > then I moved the computation to the gvtRenderingCompleted() callback,
> > but it still returns null.
> >
> > The textNode is a org.apache.batik.dom.svg.SVGOMTextElement, so it
> > should have a bounding box, right?
>
> Yes, if the document is "dynamic".  If there is no script in your
> document, you will have to call
>
>   myCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
>
> on your canvas component (assuming that's what you're using) before you
> load the document to ensure that dynamic features such as bounding box
> computations are able to be made.
>
> --
>  Cameron McCormack                      ICQ: 26955922
>  cam (at) mcc.id.au                     MSN: cam (at) mcc.id.au
>  http://mcc.id.au/                      JBR: heycam (at) jabber.org
>
> ---------------------------------------------------------------------
> 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: Stroke property for feFlood filter

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

Roger Critchlow:
> That's just what I was trying to do in Java, but textNode.getBBox()
> returns a null.
> 
> I was trying it first from the documentLoadingCompleted() callback,
> then I moved the computation to the gvtRenderingCompleted() callback,
> but it still returns null.
> 
> The textNode is a org.apache.batik.dom.svg.SVGOMTextElement, so it
> should have a bounding box, right?

Yes, if the document is "dynamic".  If there is no script in your
document, you will have to call

  myCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);

on your canvas component (assuming that's what you're using) before you
load the document to ensure that dynamic features such as bounding box
computations are able to be made.

-- 
 Cameron McCormack			ICQ: 26955922
 cam (at) mcc.id.au			MSN: cam (at) mcc.id.au
 http://mcc.id.au/			JBR: heycam (at) jabber.org

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


Re: Stroke property for feFlood filter

Posted by Roger Critchlow <re...@elf.org>.
Hmm,

That's just what I was trying to do in Java, but textNode.getBBox()
returns a null.

I was trying it first from the documentLoadingCompleted() callback,
then I moved the computation to the gvtRenderingCompleted() callback,
but it still returns null.

The textNode is a org.apache.batik.dom.svg.SVGOMTextElement, so it
should have a bounding box, right?

-- rec --

On 4/24/06, Cameron McCormack <ca...@mcc.id.au> wrote:
> Hi Selva.
>
> Selva:
> > My requirement is that my text label should have the background color covered
> > by rectangle. So i tried to use feFlood filter.
> >
> > Is there any other way to do this without feFlood filter?
>
> Sure, you can just use a 'rect' to draw the background and then display
> the text atop.  If you need to make sure that the rect covers exactly
> the area of the text, you can use some script:
>
>   <svg xmlns="http://www.w3.org/2000/svg"
>        version="1.1" font-size="24" width="400" height="400">
>     <rect id="theTextBackground" fill="yellow" width="0" height="0"/>
>     <text id="theText" x="100" y="100">This is some text.</text>
>     <script>
>       var r = document.getElementById("theTextBackground");
>       var t = document.getElementById("theText");
>       var bbox = t.getBBox();
>       r.setAttributeNS(null, "x", bbox.x);
>       r.setAttributeNS(null, "y", bbox.y);
>       r.setAttributeNS(null, "width", bbox.width);
>       r.setAttributeNS(null, "height", bbox.height);
>     </script>
>   </svg>
>
> --
>  Cameron McCormack                      ICQ: 26955922
>  cam (at) mcc.id.au                     MSN: cam (at) mcc.id.au
>  http://mcc.id.au/                      JBR: heycam (at) jabber.org
>
> ---------------------------------------------------------------------
> 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: Stroke property for feFlood filter

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

Selva:
> My requirement is that my text label should have the background color covered 
> by rectangle. So i tried to use feFlood filter. 
> 
> Is there any other way to do this without feFlood filter?

Sure, you can just use a 'rect' to draw the background and then display
the text atop.  If you need to make sure that the rect covers exactly
the area of the text, you can use some script:

  <svg xmlns="http://www.w3.org/2000/svg"
       version="1.1" font-size="24" width="400" height="400">
    <rect id="theTextBackground" fill="yellow" width="0" height="0"/>
    <text id="theText" x="100" y="100">This is some text.</text>
    <script>
      var r = document.getElementById("theTextBackground");
      var t = document.getElementById("theText");
      var bbox = t.getBBox();
      r.setAttributeNS(null, "x", bbox.x);
      r.setAttributeNS(null, "y", bbox.y);
      r.setAttributeNS(null, "width", bbox.width);
      r.setAttributeNS(null, "height", bbox.height);
    </script>
  </svg>

-- 
 Cameron McCormack			ICQ: 26955922
 cam (at) mcc.id.au			MSN: cam (at) mcc.id.au
 http://mcc.id.au/			JBR: heycam (at) jabber.org

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


Re: Stroke property for feFlood filter

Posted by Selva <se...@yahoo.co.in>.
Hi Thomas,

>    I think you need to describe what you are doing a bit better
> (sample of the filter and how you are using it on the text perhaps).

My requirement is that my text label should have the background color covered 
by rectangle. So i tried to use feFlood filter. 

Is there any other way to do this without feFlood filter?

Thanks,
Selva

 <thomas.deweese <at> kodak.com> writes:

> 
> Hi Selva,
> 
> news <news <at> sea.gmane.org> wrote on 04/23/2006 03:24:58 AM:
> 
> > I am using feFlood for text background.
> 
>    Why aren't you just using 'fill' on the text?  feFlood is perhaps
> one of the most expensive ways to get a solid color filled area...
> 
> > But my text background should have "stroke" property. So that text 
> > background will be covered by border. Can anyone please give me the 
> > way to set "stroke" property for feFlood text background?
> 
>    You can't set 'stroke' on feFlood since feFlood fills a rect with
> a solid color.  however if you use 'fill' to set the color of the
> text you can use 'stroke' to set the stroke color of the text...
> 
>    I think you need to describe what you are doing a bit better
> (sample of the filter and how you are using it on the text perhaps).
> 





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


Re: Stroke property for feFlood filter

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

news <ne...@sea.gmane.org> wrote on 04/23/2006 03:24:58 AM:

> I am using feFlood for text background.

   Why aren't you just using 'fill' on the text?  feFlood is perhaps
one of the most expensive ways to get a solid color filled area...

> But my text background should have "stroke" property. So that text 
> background will be covered by border. Can anyone please give me the 
> way to set "stroke" property for feFlood text background?

   You can't set 'stroke' on feFlood since feFlood fills a rect with
a solid color.  however if you use 'fill' to set the color of the
text you can use 'stroke' to set the stroke color of the text...

   I think you need to describe what you are doing a bit better
(sample of the filter and how you are using it on the text perhaps).



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