I am trying to implement the suggestion Thomas made in the previous note but was hoping for some guidance...

I have simple SVG file that places text that flows outside the bounds of a circle ...
<svg width="350" height="300">
<!-- Circle -->
  <circle id="circle" cx="120" cy="120" r="100" fill="darkred" stroke="black" stroke-width="3" />
  <!-- This text is too wide. -->
  <text id="lines" x="120" y="60" fill="white" font-family="Verdana" text-anchor="middle">
    <tspan font-size="28">Line 1</tspan>
    <tspan font-size="12">Line 2</tspan>
    <tspan font-size="12">Line 3</tspan>
  </text>
</svg> 

I have then written some code modeled on the slideshow app that attempts to read this file, render it and then determine if the text is outside the circle as Thomas suggested...
It seems to work to the extent that I have a non-null bounding box size for the text.
However I am stuck at the point where I'm trying to figure out how to derive the shape node  (batik.gvt.GraphicsNode.getOutline()) of the circle. Any suggestions on where to look next would be greatly appreciated as would be any comments on what I've done so far. Thanks in advance...Kevin

    public static void traverseSVG( String fileSpec ) {
        try {
            java.io.File file = new java.io.File( fileSpec );
            org.apache.batik.util.XMLResourceDescriptor.setXMLParserClassName("org.apache.crimson.parser.XMLReaderImpl");
            System.out.println("Reading: " + file );
            org.apache.batik.bridge.UserAgentAdapter userAgent = new org.apache.batik.bridge.UserAgentAdapter();
            org.apache.batik.bridge.DocumentLoader loader = new org.apache.batik.bridge.DocumentLoader(userAgent);
            org.w3c.dom.Document svgDoc = loader.loadDocument(file.toURL().toString());
            System.out.println( "Building...");   
            org.apache.batik.bridge.BridgeContext ctx  = new org.apache.batik.bridge.BridgeContext(userAgent, loader);
            ctx.setDynamicState(BridgeContext.DYNAMIC);
   
            System.out.println( "  ...context...");
            org.apache.batik.bridge.GVTBuilder builder = new org.apache.batik.bridge.GVTBuilder();
            System.out.println( "  ...builder...");   
            org.apache.batik.gvt.GraphicsNode gvt = builder.build(ctx, svgDoc);
            System.out.println( "  ...graphics node...");
            System.out.print("Rendering...");
            System.out.println( "  ...build static renderer...");
            StaticRenderer renderer = new StaticRenderer();
            System.out.println( "  ...set tree...");
            renderer.setTree(gvt);
            System.out.println( "  ...render image...");
            BufferedImage image = renderer.getOffScreen();
            System.out.println("...Ok");
           
            SVGDocument svg = (SVGDocument) svgDoc;
            System.out.println( svg );           
            Element lines = svg.getElementById("lines");
            SVGTextElement textElement = (SVGTextElement) lines;
            System.out.println( lines );
            SVGRect bbox = textElement.getBBox();
            //I've got a non-null bounding box here so I'm hoping I'm ok...
            System.out.println( bbox +" height="+ bbox.getHeight() + " width="+bbox.getWidth() );
           
            Element circle = svg.getElementById("circle");
            System.out.println( circle );
            //I am trying to figure out how to get the shape node representing the circle so I can apply
            //Thomas's suggestion...
                                   
            System.out.println( "Completed successfully...");
        } catch( Throwable t ) {
            System.out.println( "Throwable:"+t);
        }
       
    }


-------- Original Message --------
Subject: Re: Detecting Text Overflow in irregular shapes
Date: Mon, 17 Nov 2003 18:26:19 -0500
From: Thomas DeWeese <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]
Organization: Eastman Kodak Company
To: [EMAIL PROTECTED]
References: <[EMAIL PROTECTED]>


Hi Kevin,

    Well Batik will not 'do this for you' however Java2D with Batik
will do this fairly easily.  In particular using Batik you can get
the BBox of the text (org.w3.dom.svg.SVGText.getBBox()) and you can get the
'outline' of a shape node (batik.gvt.GraphicsNode.getOutline()).
The using the Java2D Area class (java.awt.geom.Area) you can
call 'contains(x, y, w, h)' which will return true if the
specified rectangle lies completely within the Area.


Kevin Maione wrote:

> I am considering using Batik / SVG to build a web application that 
> merges text and images and displays the results as a JPEG. The 
> application allows the users to specify font info including point size. 
> One of the requirements is to give an error message if content goes 
> outside the boundaries of a specified background area. Can this be done 
> using Batik? For example, let us say I have a circle background and 
> allow the users to enter multiple lines of text oriented towards the 
> middle of the circle. At some point one or more of the lines could get 
> long enough to extend past the boundary of the circle. Although I 
> suspect I could use some clipping to cut this off I need a way to know 
> that the clipping occurred? If the background was rectangular I  could 
> take the text and calculate the width / height and figure it out myself. 
> But in the case of a non-rectangular background I'm hoping Batik can 
> help.





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Reply via email to