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);
}
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;
}
Aggregations