The graphic for the updated
http://code.xwiki.org/xwiki/bin/view/Modules/RenderingModule suggests that
PDF is one of the outputs of the rendering module, although the document
itself says "XWiki Syntax 2.0 (xwiki/2.0), XHTML (xhtml/1.0), Plain Text
(plain/1.0)".
Can the new rendering module be used to render a PNG, SVG, GIF, JPG, or
Flash, instead of the above? Actually, I guess the best way to phrase this,
is there a way to get the rendering module "out of the way" and allow a
simple document containing a setContentType() declaration appropriate for
the given image at the beginning, followed by a single call to the macro,
which would output "binary data". Of course, "plain text" could be
used,
ultimately, for outputting PNG and xhtml/1.0 for SVG...
Lets say I do some Query against all wiki documents, and instead of
rendering the query "textually" I want to render it as a graphics
image. Given it's capabilities, this might best be achievable with a groovy
script. So assume a groovy script which creates, "in memory" a SVG, GIF,
PNG, or JPG of the aforementioned query, via Java library calls, glued
together with groovy. Lets say I used this example, which outputs SVG:
http://www.jroller.com/aalmiray/entry/graphicsbuilder_update_on_svgrenderer how
could the SVG get rendered from the groovy script and output directly to the
document, rather than being written as an attachment to be included in the
document as in is this hypothetical example:
1. def go = {
2. antialias true
3. rect( x: 50, y: 50, w: 100, h: 100, f: 'red', bc: 'darkRed' )
4. rect( x: 10, y: 10, w: 100, h: 100, f: 'blue', bc: 'navy' )
5. circle( cx: 150, cy: 150, r: 40, f: 'orange', bc: 'darkOrange' )
6. star( cx: 100, cy: 100, or: 50, ir: 20, f: 'green', bc:
'darkGreen'
)
7. }
1. def sr = new SVGRenderer()
2. def stream new MemoryStream() /* MemoryStream() is my handwaving for
some package that lets you simulate file IO without writing to disk */
3. sr.renderToFile( stream, 200, 200, go )
4. def targetDoc = xwiki.getDocument("Groovy.GroovyTest4")
5. targetDoc.addAttachment("PNGGraphicsAttachment", stream.getBytes());
6. targetDoc.save()
One of the reasons one might want to use a "document" to render an image is
that if the computation to render took some time, the rest of the
surrounding text would appear in the browser first, rather than holding up
the whole render. I imagine the current behavior, if, hypothetically, the
chart macro took a long time to render a huge dataset, or a TeX equation
took long to render into HTML, one could achieve a performance improvement
by having the equivalent rendered separately into the browser as an image.
The text surrounding any long-running macros wouldn't need to be "held up"
until the macro rendered. Streaming images, or even flash, could be used to
handle asynchronous updates to this "active document/image."
As corollary, wouldn't it be useful to have an additional parameter on macro
creation which would allow macros to run as their own document/thread, and
automatically insert an iframe for the "subdocument" if the output is
HTML/rendered-wikitext, and an image if the output is GIF/JPG/PNG ?
Niels
http://nielsmayer.com
PS: are there any "snippet" or coding examples of outputting "computed
images" from Xwiki via groovy?