Package atessera.comp
Class Metapost
java.lang.Object
atessera.comp.Metapost
Facade for compiling MetaPost figures to cropped PDF.
This class encapsulates a three-step MetaPost pipeline:
mpost— compiles the MetaPost source (main.mp) into a PostScript figure (figure.mps). The environment variableTEX=latexis set so that MetaPost uses LaTeX for typesetting labels.mptopdf— convertsfigure.mpstofigure-mps.pdf.pdfcrop— crops the PDF to its bounding box, producingfigure-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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancompile()Runs the MetaPost-to-PDF pipeline.getLog()Returns the contents ofmain.logafter a failed compilation.byte[]Returns the compiled cropped PDF figure.Returns the raw stderr captured from each command in the pipeline.Returns the raw stdout captured from each command in the pipeline.Returns the stack trace if an internal exception occurred during compilation.
-
Constructor Details
-
Metapost
Constructs a newMetapostcompilation facade.- Parameters:
compiler- the underlyingCompilerto use; must not benullsource- the MetaPost source as a list of lines; must not benull
-
-
Method Details
-
compile
public boolean compile()Runs the MetaPost-to-PDF pipeline.- Returns:
trueif all steps completed successfully and the cropped PDF was produced;falseotherwise- 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
nullif compilation has not been run or was unsuccessful
-
getLog
Returns the contents ofmain.logafter a failed compilation.- Returns:
- the log file as a list of lines, or
nullif the log was not captured
-
getRawOutput
Returns the raw stdout captured from each command in the pipeline.- Returns:
- an unmodifiable view of the captured stdout, or
nullbefore compilation
-
getRawErrorOutput
Returns the raw stderr captured from each command in the pipeline.- Returns:
- an unmodifiable view of the captured stderr, or
nullbefore compilation
-
getStackTrace
Returns the stack trace if an internal exception occurred during compilation.- Returns:
- the stack trace as a string, or
nullif no exception was thrown
-