List Info

Thread: Stroke property for feFlood filter




Stroke property for feFlood filter
user name
2006-04-24 06:15:33
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-unsubscribexmlgraphics.apache.org
For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org

Stroke property for feFlood filter
user name
2006-04-24 06:52:14
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 <cammcc.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-unsubscribexmlgraphics.apache.org
> For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org
>
>

------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-users-unsubscribexmlgraphics.apache.org
For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org

Stroke property for feFlood filter
user name
2006-04-24 07:09:21
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-unsubscribexmlgraphics.apache.org
For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org

Stroke property for feFlood filter
user name
2006-04-24 07:21:06
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 <cammcc.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-unsubscribexmlgraphics.apache.org
> For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org
>
>

------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-users-unsubscribexmlgraphics.apache.org
For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org

Stroke property for feFlood filter
user name
2006-04-24 08:09:42
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-unsubscribexmlgraphics.apache.org
For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org

Stroke property for feFlood filter
user name
2006-04-24 15:30:40
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
"
	xmlnslink=
"http://www.w3.org/1999/x
link"
    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-unsubscribexmlgraphics.apache.org
> For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org
>
>

------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-users-unsubscribexmlgraphics.apache.org
For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org

Stroke property for feFlood filter
user name
2006-04-25 01:29:23
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-unsubscribexmlgraphics.apache.org
For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org

Stroke property for feFlood filter
user name
2006-04-25 09:51:41
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-unsubscribexmlgraphics.apache.org
> > For additional commands, e-mail: 
batik-users-helpxmlgraphics.apache.org
> >
> >
> 
>
------------------------------------------------------------
---------
> To unsubscribe, e-mail: batik-users-unsubscribexmlgraphics.apache.org
> For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org
> 


------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-users-unsubscribexmlgraphics.apache.org
For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org

[1-8]

about | contact  Other archives ( Real Estate discussion Medical topics )