Esempio n. 1
0
 /**
  * Processes MathML data.
  *
  * @param element MathML data element
  * @param block parent block
  * @throws DocumentException if some error occurs
  */
 private void processMath(Element element, Block<Atom> block) throws DocumentException {
   try {
     element.setAttribute("xmlns:m", URI_M);
     element.setAttribute("xmlns:w", URI_W);
     ByteArrayOutputStream omml = new ByteArrayOutputStream();
     DomUtil.save(element, omml);
     Source xsl = new StreamSource(getClass().getResourceAsStream(XSL_OMML2MML));
     Source xml = new StreamSource(new ByteArrayInputStream(omml.toByteArray()));
     DOMResult mml = new DOMResult();
     XslUtil.transform(xml, xsl, mml);
     LayoutContextImpl context =
         new LayoutContextImpl(LayoutContextImpl.getDefaultLayoutContext());
     Float fontSize = (Float) context.getParameter(Parameter.MATHSIZE);
     final float factor = 1.5F;
     context.setParameter(Parameter.MATHSIZE, factor * fontSize);
     context.setParameter(Parameter.MFRAC_KEEP_SCRIPTLEVEL, Boolean.FALSE);
     ByteArrayOutputStream out = new ByteArrayOutputStream();
     ConverterRegistry.getInstance()
         .getConverter("image/png")
         .convert(mml.getNode(), context, out);
     Image image = new Image();
     mathImageIndex++;
     final String imageName = "mml-" + mathImageIndex + ".png";
     image.setUrl(imageName);
     image.setAlt(imageName);
     image.setData(out.toByteArray());
     block.add(image);
   } catch (XmlException e) {
     throw new DocumentException(e);
   } catch (IOException e) {
     throw new DocumentException(e);
   }
 }
Esempio n. 2
0
 /**
  * Provides root node of given data stream.
  *
  * @param zip ZIP input stream
  * @return root node
  * @throws DocumentException if some error occurs
  */
 private Node getContext(ZipInputStream zip) throws DocumentException {
   try {
     return DomUtil.open(getInputStream(zip));
   } catch (XmlException e) {
     throw new DocumentException(e);
   }
 }