xmlgraphics-fop-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthias Reischenbacher <matthias8...@gmx.at>
Subject Re: Dynamically insert SVG graphics in the XML passed to FOP
Date Thu, 22 Jun 2017 10:48:25 GMT
Hi,

you should try to write out the SVG Elements with the following method
(instead of using a string):

handler.startElement(String namespaceURI, String localName,
                        String qName, Attributes atts)

handler.endElement(String namespaceURI, String localName,
                        String qName)

e.g.

handler.startElement("http://www.w3.org/2000/svg", "svg", "svg:svg", atts)

handler.startElement("http://www.w3.org/2000/svg", "svg", "svg:g", atts)

handler.endElement("http://www.w3.org/2000/svg", "svg", "svg:svg")

handler.endElement("http://www.w3.org/2000/svg", "svg", "svg:g")

etc.

Best regards,
Matthias

On 21.06.2017 13:53, Pierre Caron wrote:
> Hello,
>
> I have a rather trivial problem that I haven't found a solution yet.
>
> I want to insert dynamically generated SVG code Inside the XML data
> which is supplied to FOP.
>
> To make things simpler, suppose you start from the ExampleObj2PDF
> found in FOP Embedding page
> (https://xmlgraphics.apache.org/fop/2.2/embedding.html#ExampleObj2PDF)
> and that you add a method in the ProjectTeam entity that generates a
> SVG String :
>
>
> public String getDynamicSVG()  {
>      return " <svg:svg width=\"20\" height=\"20\">\n" + ... +
> "</svg:svg>";
> }
>
> (http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop/examples/embedding/java/embedding/model/ProjectTeam.java?view=markup)
>
>
> And that this method would be called by the following line inside
> ProjectTeamXMLReader class
>
> handler.element("SVGdynamique",projectMember.getDynamicSVG());
> (http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop/examples/embedding/java/embedding/model/ProjectTeamXMLReader.java?view=markup)
>
> The question is : how to prevent the SVG tags from being escaped into
> &lt; and &gt;?  Below is the XML code I'm getting :
>
> ...
> <svgDynamique> &lt;svg:svg width="20" height="20"&gt;
>   &lt;svg:g style="fill:red; stroke:#000000"&gt;
>      &lt;svg:rect x="0" y="0" width="15" height="15"/&gt;
>      &lt;svg:rect x="5" y="5" width="15" height="15"/&gt;
>   &lt;/svg:g&gt;
> &lt;/svg:svg&gt;</svgDynamique>
> ...
>
> In the final step, the SVG string would be merged by the
> projectteam2fo.xsl like this :
>
>                 <fo:block space-before.optimum="15pt">
> <fo:instream-foreign-object>
>                         <svg xmlns="http://www.w3.org/2000/svg"
> width="20" height="20">
>                             <xsl:copy-of select="svgDynamique" />
>                         </svg>
>                     </fo:instream-foreign-object>]
>                 </fo:block>
>
> Is there a way to prevent the escaping?
>
> Note that the SVG tags get escaped during the XML processing by SAX
> not during the insertion into the xsl file.
>
> Any help would be greatly appreciated!
>
> Pierre Caron
>


Mime
View raw message