Exemplo n.º 1
0
 public void processImage(String fileName) throws IOException {
   if (fileName.startsWith("/")) {
     throw new IllegalArgumentException();
   }
   final SourceStringReader sourceStringReader = new SourceStringReader(incoming.get(fileName));
   final ByteArrayOutputStream baos = new ByteArrayOutputStream();
   final FileFormat format = FileFormat.PNG;
   final DiagramDescription desc =
       sourceStringReader.generateDiagramDescription(baos, new FileFormatOption(format));
   final String pngFileName = format.changeName(fileName, 0);
   final String errorFileName = pngFileName.substring(0, pngFileName.length() - 4) + ".err";
   synchronized (this) {
     outgoing.remove(pngFileName);
     outgoing.remove(errorFileName);
     if (desc != null && desc.getDescription() != null) {
       outgoing.put(pngFileName, baos.toByteArray());
       if (desc.getDescription().startsWith("(Error)")) {
         final ByteArrayOutputStream errBaos = new ByteArrayOutputStream();
         sourceStringReader.generateImage(errBaos, new FileFormatOption(FileFormat.ATXT));
         errBaos.close();
         outgoing.put(errorFileName, errBaos.toByteArray());
       }
     }
   }
 }
Exemplo n.º 2
0
 private UGraphic2 createUGraphic(
     FileFormatOption fileFormatOption,
     final Dimension2D dim,
     Animation affineTransforms,
     double dx,
     double dy) {
   final FileFormat fileFormat = fileFormatOption.getFileFormat();
   switch (fileFormat) {
     case PNG:
       return createUGraphicPNG(
           colorMapper, dpiFactor, dim, mybackcolor, affineTransforms, dx, dy);
     case SVG:
       return createUGraphicSVG(
           colorMapper, dpiFactor, dim, mybackcolor, fileFormatOption.getSvgLinkTarget());
     case EPS:
       return new UGraphicEps(colorMapper, EpsStrategy.getDefault2());
     case EPS_TEXT:
       return new UGraphicEps(colorMapper, EpsStrategy.WITH_MACRO_AND_TEXT);
     case HTML5:
       return new UGraphicHtml5(colorMapper);
     case VDX:
       return new UGraphicVdx(colorMapper);
     case LATEX:
       return new UGraphicTikz(colorMapper);
     default:
       throw new UnsupportedOperationException(fileFormat.toString());
   }
 }