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 Phil Wright <ph...@gmail.com> on 2006/11/22 19:38:11 UTC

flowText elements not visible when loaded

I can add flowText elements to my displayed document and they show up as
desired.  If I then output the document and then load it into my app or
Squiggle the flowText elements aren't visible.

Here is a complete output file:
===========================================================
<svg contentScriptType="text/ecmascript" width="500"
     xmlns:xlink="http://www.w3.org/1999/xlink" zoomAndPan="magnify"
     contentStyleType="text/css" height="600"
     preserveAspectRatio="xMidYMid meet" xmlns="http://www.w3.org/2000/svg"
     version="1.2">
    <g style="overflow:hidden" id="content">
        <defs>
            <pattern x="0" y="0" width="100%"
                     xmlns:xlink="http://www.w3.org/1999/xlink"
                     patternUnits="userSpaceOnUse" xlink:type="simple"
                     xlink:actuate="onLoad" height=".25in" id="hstripes"
                     preserveAspectRatio="xMidYMid meet" xlink:show="other">
                <rect fill="black" width="100%" fill-opacity=".2"
height="2"/>
            </pattern>
            <pattern x="0" y="0" width=".25in"
                     xmlns:xlink="http://www.w3.org/1999/xlink"
                     patternUnits="userSpaceOnUse" xlink:type="simple"
                     xlink:actuate="onLoad" height="100%" id="vstripes"
                     preserveAspectRatio="xMidYMid meet" xlink:show="other">
                <rect fill="black" width="2" fill-opacity=".2"
height="100%"/>
            </pattern>
        </defs>
        <rect fill="url(#hstripes)" width="100%" height="100%" id="hstripes"
              visibility="visible"/>
        <rect fill="url(#vstripes)" width="100%" height="100%" id="vstripes"
              visibility="hidden"/>
        <g id="blocks">
            <flowText font-size="16pt" font-family="Dialog"
xml:space="preserve"
                      font-style="normal" id="txtblock0"
font-weight="normal">
                <flowRegion>
                    <rect width="210" x="75" height="141"
y="75"/></flowRegion>
                <flowDiv>
                    <flowPara>Some text</flowPara></flowDiv></flowText>
        </g>
    </g>
</svg>
===========================================================

I'm loading it with this code:

                String parser, uri;
                SAXSVGDocumentFactory factory;
                File f = fc.getSelectedFile();
                 try {
                        svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC
);
                        parser = XMLResourceDescriptor.getXMLParserClassName
();
                        factory = new SAXSVGDocumentFactory(parser);
                        svgCanvas.setURI(f.toURL().toString());
                        uri = svgCanvas.getURI();
                        document = factory.createSVGDocument(uri);
                        svgCanvas.setDocument(document);
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }

It is probably my lack of understanding of namespaces but what am I doing
wrong?

Thanks,

       Phil

-- 
Visit http://www.darkisle.com for photos of castles, cairns and other
historic sites in the British Isles.

Re: flowText elements not visible when loaded

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

"Phil Wright" <ph...@gmail.com> wrote on 11/26/2006 08:23:13 PM:

> As I have changed from using flowText to using flowRoot, should I use 
the 
> Batik extension namespace with them or leave everything in the SVG 
namespace? 

   The flowRoot stuff is in the SVG namespace for now.  It should probably
move since it is no longer part of the SVG spec.


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


Re: flowText elements not visible when loaded

Posted by Phil Wright <ph...@gmail.com>.
Hi Thomas,

On 11/26/06, thomas.deweese@kodak.com <th...@kodak.com> wrote:

>     Typically the namespace is given with a prefix like: "xlink:href".
> In this case href attribute in the xlink namespace, where the xlink prefix
> to namespace mapping is defined (usually on the root svg element) with:
>         xmlns:xlink="http://www.w3.org/1999/xlink"
>
>     Since the flow root elements have to be in the Batik extension
> namespace
> you need to do something like:
>
>         // This establishes the mapping between the prefix 'batikExt' and
>         // the Batik extension namespace.
>     document.getRootElement().setAttributeNS(
> "http://www.w3.org/2000/xmlns/",
>                                              "xmlns:batikExt",
> "http://xml.apache.org/batik/ext");
>
>         // Create elements in the batik extension namespace
>         Element flow =
> document.createElementNS("http://xml.apache.org/batik/ext",
> "batikExt:flowText");


Ahh.  That makes sense now that I've seen it.

As I have changed from using flowText to using flowRoot, should I use the
Batik extension namespace with them or leave everything in the SVG
namespace?

Thanks,

      Phil


-- 
Visit http://www.darkisle.com for photos of castles, cairns and other
historic sites in the British Isles.

Re: flowText elements not visible when loaded

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

> On 11/26/06, thomas.deweese@kodak.com <thomas.deweese@kodak.com > wrote:
> Hi Phil,
> 
> "Phil Wright" < phergus@gmail.com> wrote on 11/22/2006 01:38:11 PM:
> 
> > I can add flowText elements to my displayed document and they show up 
as
> 
> > desired.  If I then output the document and then load it into my app 
or 
> > Squiggle the flowText elements aren't visible.
> 
>    It looks like you aren't providing xml prefixes or changing
> the default namespace for the flowText elements.  The DOM lets
> you provide the namespace explicitly but unless you associate 
> a namespace prefix and use it, that namespace association may
> be lost when you serialize the document.

"Phil Wright" <ph...@gmail.com> wrote on 11/26/2006 07:02:03 PM:

> I've changed to using flowRoot elements but chances are that I am still 
doing 
> it all wrong. 
> 
> I was under the impression that when I did something like:
> 
>         froot = 
document.createElementNS("http://xml.apache.org/batik/ext", 
> "flowText"); 
> 
> That providing that namespace parameter did everything that was needed. 
I 
> don't see any prefixes anywhere so I'm guessing I was still missing a 
step 
> somewhere in the creation of the root document element(s).

    Typically the namespace is given with a prefix like: "xlink:href".
In this case href attribute in the xlink namespace, where the xlink prefix
to namespace mapping is defined (usually on the root svg element) with:
        xmlns:xlink="http://www.w3.org/1999/xlink"

    Since the flow root elements have to be in the Batik extension 
namespace
you need to do something like:

        // This establishes the mapping between the prefix 'batikExt' and 
        // the Batik extension namespace.
    document.getRootElement().setAttributeNS(
"http://www.w3.org/2000/xmlns/", 
                                             "xmlns:batikExt",
 "http://xml.apache.org/batik/ext");

        // Create elements in the batik extension namespace
        Element flow = 
document.createElementNS("http://xml.apache.org/batik/ext",
 "batikExt:flowText");


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


Re: flowText elements not visible when loaded

Posted by Phil Wright <ph...@gmail.com>.
Hi Thomas,

On 11/26/06, thomas.deweese@kodak.com <th...@kodak.com> wrote:
>
> Hi Phil,
>
> "Phil Wright" <ph...@gmail.com> wrote on 11/22/2006 01:38:11 PM:
>
> > I can add flowText elements to my displayed document and they show up as
>
> > desired.  If I then output the document and then load it into my app or
> > Squiggle the flowText elements aren't visible.
>
>    It looks like you aren't providing xml prefixes or changing
> the default namespace for the flowText elements.  The DOM lets
> you provide the namespace explicitly but unless you associate
> a namespace prefix and use it, that namespace association may
> be lost when you serialize the document.


I've changed to using flowRoot elements but chances are that I am still
doing it all wrong.

I was under the impression that when I did something like:

        froot = document.createElementNS("http://xml.apache.org/batik/ext",
"flowText");

That providing that namespace parameter did everything that was needed.  I
don't see any prefixes anywhere so I'm guessing I was still missing a step
somewhere in the creation of the root document element(s).

        private static final String svgNS =
SVG12DOMImplementation.SVG_NAMESPACE_URI;
        private static DOMImplementation impl = null;

        impl = SVG12DOMImplementation.getDOMImplementation();

        SVGDocument document = (SVGDocument)impl.createDocument(svgNS,
"svg", null);
        Element root = document.getDocumentElement();
        root.setAttributeNS(null, "version", "1.2");

Is all of that right?

Thanks again,

     Phil



-- 
Visit http://www.darkisle.com for photos of castles, cairns and other
historic sites in the British Isles.

Re: flowText elements not visible when loaded

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

"Phil Wright" <ph...@gmail.com> wrote on 11/22/2006 01:38:11 PM:

> I can add flowText elements to my displayed document and they show up as 

> desired.  If I then output the document and then load it into my app or 
> Squiggle the flowText elements aren't visible.

   It looks like you aren't providing xml prefixes or changing
the default namespace for the flowText elements.  The DOM lets
you provide the namespace explicitly but unless you associate
a namespace prefix and use it, that namespace association may
be lost when you serialize the document.

> Here is a complete output file: 
> ===========================================================
> <svg contentScriptType="text/ecmascript" width="500"
>      xmlns:xlink="http://www.w3.org/1999/xlink " zoomAndPan="magnify"
>      contentStyleType="text/css" height="600"
>      preserveAspectRatio="xMidYMid meet" 
xmlns="http://www.w3.org/2000/svg "
>      version="1.2">
>     <g style="overflow:hidden" id="content">
>         <defs>
>             <pattern x="0" y="0" width="100%" 
>                      xmlns:xlink="http://www.w3.org/1999/xlink"
>                      patternUnits="userSpaceOnUse" xlink:type="simple"
>                      xlink:actuate="onLoad" height=".25in" id="hstripes" 

>                      preserveAspectRatio="xMidYMid meet" 
xlink:show="other">
>                 <rect fill="black" width="100%" fill-opacity=".2" 
height="2"/> 
>             </pattern>
>             <pattern x="0" y="0" width=".25in"
>                      xmlns:xlink="http://www.w3.org/1999/xlink "
>                      patternUnits="userSpaceOnUse" xlink:type="simple"
>                      xlink:actuate="onLoad" height="100%" id="vstripes"
>                      preserveAspectRatio="xMidYMid meet" 
xlink:show="other"> 
>                 <rect fill="black" width="2" fill-opacity=".2" 
height="100%"/>
>             </pattern>
>         </defs>
>         <rect fill="url(#hstripes)" width="100%" height="100%" 
id="hstripes" 
>               visibility="visible"/>
>         <rect fill="url(#vstripes)" width="100%" height="100%" 
id="vstripes"
>               visibility="hidden"/> 
>         <g id="blocks">
>             <flowText font-size="16pt" font-family="Dialog" 
xml:space="preserve"
>                       font-style="normal" id="txtblock0" 
font-weight="normal"> 
>                 <flowRegion>
>                     <rect width="210" x="75" height="141" 
y="75"/></flowRegion>
>                 <flowDiv>
>                     <flowPara>Some text</flowPara></flowDiv></flowText> 
>         </g>
>     </g>
> </svg>
> ===========================================================
> 
> I'm loading it with this code:
> 
>                 String parser, uri;
>                 SAXSVGDocumentFactory factory;
>                 File f = fc.getSelectedFile();
>                  try {
> svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
>                         parser = 
XMLResourceDescriptor.getXMLParserClassName();
>                         factory = new SAXSVGDocumentFactory(parser);
>                         svgCanvas.setURI(f.toURL().toString());
>                         uri = svgCanvas.getURI();
>                         document = factory.createSVGDocument(uri);
>                         svgCanvas.setDocument(document); 
>                     } catch (IOException ex) {
>                         ex.printStackTrace();
>                     }
> 
> It is probably my lack of understanding of namespaces but what am I 
doing wrong?
> 
> Thanks, 
> 
>        Phil
> 
> -- 
> Visit http://www.darkisle.com for photos of castles, cairns and other 
historic
> sites in the British Isles. 

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