Class MetapostTemplate

java.lang.Object
atessera.templ.MetapostTemplate

public final class MetapostTemplate extends Object
Velocity template for generating MetaPost figure source.

This class populates the metapost.vm template with the figure drawing commands, producing a compilable MetaPost source file. The resulting source can be compiled with Metapost.

Typical usage:


 MetapostTemplate t = new MetapostTemplate(factory);
 t.setText(metapostCommands);
 List<String> mpSource = t.renderToStringList();
 
See Also:
  • Constructor Details

    • MetapostTemplate

      public MetapostTemplate(EngineFactory engineFactory)
      Constructs a new MetaPost template.
      Parameters:
      engineFactory - the factory for obtaining a Velocity engine; must not be null
      Throws:
      org.apache.velocity.exception.ResourceNotFoundException - if metapost.vm cannot be loaded
  • Method Details

    • setText

      public MetapostTemplate setText(List<String> text)
      Sets the MetaPost drawing commands.
      Parameters:
      text - the MetaPost source lines; may be null or empty
      Returns:
      this template (for fluent chaining)
    • render

      public void render(Writer wr)
      Merges the context into the template and writes the result to the given writer.
      Parameters:
      wr - the writer to receive the rendered output; must not be null
    • renderToStringList

      public List<String> renderToStringList()
      Renders the template and returns the result split into lines.
      Returns:
      the rendered output as a list of lines (trailing empty lines are preserved)