Package atessera.comp

Class Metapost

java.lang.Object
atessera.comp.Metapost

public final class Metapost extends Object
Facade for compiling MetaPost figures to cropped PDF.

This class encapsulates a three-step MetaPost pipeline:

  1. mpost — compiles the MetaPost source (main.mp) into a PostScript figure (figure.mps). The environment variable TEX=latex is set so that MetaPost uses LaTeX for typesetting labels.
  2. mptopdf — converts figure.mps to figure-mps.pdf.
  3. pdfcrop — crops the PDF to its bounding box, producing figure-mps-crop.pdf.

After a successful compilation the cropped PDF is available via getOutput(). On failure the contents of main.log are available via getLog().

See Also:
  • Constructor Details

    • Metapost

      public Metapost(Compiler compiler, List<String> source)
      Constructs a new Metapost compilation facade.
      Parameters:
      compiler - the underlying Compiler to use; must not be null
      source - the MetaPost source as a list of lines; must not be null
  • Method Details

    • compile

      public boolean compile()
      Runs the MetaPost-to-PDF pipeline.
      Returns:
      true if all steps completed successfully and the cropped PDF was produced; false otherwise
      Throws:
      IllegalStateException - if the compiler result is inconsistent (e.g. zero exit code but no PDF, or non-zero exit code but no log file)
    • getOutput

      public byte[] getOutput()
      Returns the compiled cropped PDF figure.
      Returns:
      the PDF as a byte array, or null if compilation has not been run or was unsuccessful
    • getLog

      public List<String> getLog()
      Returns the contents of main.log after a failed compilation.
      Returns:
      the log file as a list of lines, or null if the log was not captured
    • getRawOutput

      public List<List<String>> getRawOutput()
      Returns the raw stdout captured from each command in the pipeline.
      Returns:
      an unmodifiable view of the captured stdout, or null before compilation
    • getRawErrorOutput

      public List<List<String>> getRawErrorOutput()
      Returns the raw stderr captured from each command in the pipeline.
      Returns:
      an unmodifiable view of the captured stderr, or null before compilation
    • getStackTrace

      public String getStackTrace()
      Returns the stack trace if an internal exception occurred during compilation.
      Returns:
      the stack trace as a string, or null if no exception was thrown