Search in sources :

Example 6 with ImageData

use of org.xwiki.formula.ImageData in project xwiki-platform by xwiki.

the class SnuggleTexFormulaRenderer method renderImage.

@Override
protected ImageData renderImage(String formula, boolean inline, FormulaRenderer.FontSize size, FormulaRenderer.Type type) throws IllegalArgumentException, IOException {
    SnuggleSession session = this.engine.createSession();
    SnuggleInput input = new SnuggleInput(wrapFormula(formula, inline));
    session.parseInput(input);
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    CustomMathMLImageSavingCallback callback = new CustomMathMLImageSavingCallback(output, size.getSize());
    WebPageOutputOptions options = JEuclidUtilities.createWebPageOptions(false, callback);
    session.writeWebPage(options, new NullOutputStream());
    return new ImageData(output.toByteArray(), type);
}
Also used : SnuggleInput(uk.ac.ed.ph.snuggletex.SnuggleInput) ImageData(org.xwiki.formula.ImageData) SnuggleSession(uk.ac.ed.ph.snuggletex.SnuggleSession) WebPageOutputOptions(uk.ac.ed.ph.snuggletex.WebPageOutputOptions) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) NullOutputStream(org.apache.commons.io.output.NullOutputStream)

Example 7 with ImageData

use of org.xwiki.formula.ImageData in project xwiki-platform by xwiki.

the class PDFURIResolver method resolve.

@Override
public Source resolve(String href, String base) throws TransformerException {
    if (this.attachmentMap != null) {
        // implemented for TemporaryResource...
        if (href.contains(TEX_ACTION)) {
            // Note: See the comments in FormulaMacro to understand why we do a replace...
            AttachmentReference reference = this.attachmentMap.get(href.replace(TEX_ACTION, "/download/"));
            if (reference != null) {
                // Get the generated image's input stream
                ImageStorage storage = Utils.getComponent(ImageStorage.class);
                ImageData image = storage.get(reference.getName());
                return new StreamSource(new ByteArrayInputStream(image.getData()));
            }
        }
        // TODO: end HACK
        AttachmentReference reference = this.attachmentMap.get(href);
        if (reference != null) {
            try {
                XWikiDocument xdoc = this.context.getWiki().getDocument(reference.extractReference(EntityType.DOCUMENT), this.context);
                // TODO: handle revisions
                XWikiAttachment attachment = xdoc.getAttachment(reference.extractReference(EntityType.ATTACHMENT).getName());
                return new StreamSource(attachment.getContentInputStream(this.context));
            } catch (Exception e) {
                throw new TransformerException(String.format("Failed to resolve export URI [%s]", href), e);
            }
        }
    }
    // Defaults to the default URI Resolver in FO
    return null;
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ImageStorage(org.xwiki.formula.ImageStorage) ByteArrayInputStream(java.io.ByteArrayInputStream) ImageData(org.xwiki.formula.ImageData) StreamSource(javax.xml.transform.stream.StreamSource) XWikiAttachment(com.xpn.xwiki.doc.XWikiAttachment) TransformerException(javax.xml.transform.TransformerException) TransformerException(javax.xml.transform.TransformerException)

Aggregations

ImageData (org.xwiki.formula.ImageData)7 IOException (java.io.IOException)4 ImageStorage (org.xwiki.formula.ImageStorage)3 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 GetMethod (org.apache.commons.httpclient.methods.GetMethod)2 AttachmentReference (org.xwiki.model.reference.AttachmentReference)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 Map (java.util.Map)1 TransformerException (javax.xml.transform.TransformerException)1 StreamSource (javax.xml.transform.stream.StreamSource)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 NullOutputStream (org.apache.commons.io.output.NullOutputStream)1 Resource (org.apache.xmlgraphics.io.Resource)1 SnuggleInput (uk.ac.ed.ph.snuggletex.SnuggleInput)1 SnuggleSession (uk.ac.ed.ph.snuggletex.SnuggleSession)1 WebPageOutputOptions (uk.ac.ed.ph.snuggletex.WebPageOutputOptions)1