pub struct PSTool { /* private fields */ }Expand description
The PSTool structure records a series of PostScript events – drawing of
lines, boxes, circles, color changes, text, and so on. A bounding box of the
events is computed when the generate function is called, with the events being
output to the specified file as raw PostScript commands.
By default, line widths are 1 point. A scale factor can be set (with each
event scaled by that amount when it is added).
Implementations§
Source§impl PSTool
impl PSTool
Sourcepub fn add_box(&mut self, llx: f32, lly: f32, urx: f32, ury: f32)
pub fn add_box(&mut self, llx: f32, lly: f32, urx: f32, ury: f32)
Add an axis-aligned box to the generated output. The box will use the current fill status, and selected color.
Sourcepub fn add_line(&mut self, llx: f32, lly: f32, urx: f32, ury: f32)
pub fn add_line(&mut self, llx: f32, lly: f32, urx: f32, ury: f32)
Add a line between the indicated coordinates, using the current selected color.
Sourcepub fn add_circle(&mut self, x: f32, y: f32, radius: f32)
pub fn add_circle(&mut self, x: f32, y: f32, radius: f32)
Add a circle at the indicated coordinates and radius, using the current fill status and color.
Sourcepub fn add_curve(
&mut self,
x1: f32,
y1: f32,
x2: f32,
y2: f32,
x3: f32,
y3: f32,
)
pub fn add_curve( &mut self, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, )
Add a curve, using a start, mid, and end point. PostScript supports Bezier curves; a curve can be helpful in showing a connection where co-linear connections might often overlap.
Sourcepub fn add_postscript(&mut self, t: String)
pub fn add_postscript(&mut self, t: String)
Adds raw PostScript commands to the instruction stream. Can be used to get full access to PostScript functionality (gsave/grestore, translation, scaling, and so on). Note that the bounding box of the output will not correctly track the graphic elements introduced with raw PostScript.
Sourcepub fn add_text(&mut self, x: f32, y: f32, t: String)
pub fn add_text(&mut self, x: f32, y: f32, t: String)
Adds text onto the display at the specified coordintes. The currently selected color, font, and font size will be utilized. Note that currently the String is not character-escaped; close parentheses may not render correctly (or cause invalid PostScript generation).
Sourcepub fn add_text_rotated(&mut self, x: f32, y: f32, angle: f32, t: String)
pub fn add_text_rotated(&mut self, x: f32, y: f32, angle: f32, t: String)
Adds text onto the display at the specified coordintes. The currently selected color, font, and font size will be utilized. Note that currently the String is not character-escaped; close parentheses may not render correctly (or cause invalid PostScript generation).
Sourcepub fn set_text_ln(&mut self, x: f32, y: f32)
pub fn set_text_ln(&mut self, x: f32, y: f32)
Sets the location for text lines (and auto-increments the line position with each add_text_nl call).
Sourcepub fn add_text_ln(&mut self, t: String)
pub fn add_text_ln(&mut self, t: String)
Adds a string at the current text line location, then increments to the next position
Sourcepub fn add_comment(&mut self, t: String)
pub fn add_comment(&mut self, t: String)
Adds commented text to the PostScript output; while this will not cause visual changes to the generated PostScript, it can be helpful for annotating a PostScript file with information such as configuration parameters or command line arguments for a software tool. The comment will be embedded in the PostScript file in sequence with other events – if there’s something specific being drawn, it may be helpful to have the comment adjacent to the PostScript commands in the output file. PSTool also supports notes, which are added to the start of the output file.
Sourcepub fn add_note(&mut self, s: String)
pub fn add_note(&mut self, s: String)
Adds a note to the PostScript output – in contast to the comment, a note is placed at the start of an output PostScript file.
Sourcepub fn chart(
&mut self,
data: Vec<f32>,
min: f32,
max: f32,
llx: f32,
lly: f32,
urx: f32,
ury: f32,
)
pub fn chart( &mut self, data: Vec<f32>, min: f32, max: f32, llx: f32, lly: f32, urx: f32, ury: f32, )
Generates a very simple two-dimensional chart, using floating point numbers from the data vector. The size of the chart is specified by the bounding coordinates. The data in the input vector is scaled so that the range of values fills the vertical span of the chart. The chart is written with the currently specified color. If the input max and min are equal, the range is determined by the data. Otherwise, the supplied max and min will be used (with these limits clamping the data).
Sourcepub fn set_color(&mut self, r: f32, g: f32, b: f32, a: f32)
pub fn set_color(&mut self, r: f32, g: f32, b: f32, a: f32)
Sets the color for object rendering, using Red/Green/Blue hues, where each of these values is in the range of 0.0-1.0. The library currently also supports n alpha color channel, which is not supported by PostScript. Future versions of this library may add support for PNG file generation (where alpha would be relevant).
Sourcepub fn set_fill(&mut self, state: bool)
pub fn set_fill(&mut self, state: bool)
Sets the state of rectangle and circle filling; true causes a filled object, false only draws the outline.
Sourcepub fn set_border(&mut self, border: f32)
pub fn set_border(&mut self, border: f32)
The generated PostScript has a bounding box (determined by the coordinates of boxes and lines). When converting to PDF, the resulting file wraps the bounding box tightly. To add additional space around a figure, a border can be added (effectively expanding the size of the bounding box used in PDF generation).
Sourcepub fn set_bounds(&mut self, llx: f32, lly: f32, urx: f32, ury: f32)
pub fn set_bounds(&mut self, llx: f32, lly: f32, urx: f32, ury: f32)
The bounds for a figure can be set explicitly – the fixed bounding box can be used to trim a figure to only an area of interest.
Sourcepub fn set_scale(&mut self, scale: f32)
pub fn set_scale(&mut self, scale: f32)
Lines generated are one point wide by default; the scale of all graphic elements can be adjusted if needed, so that the line widths appear reasonable. Set the scale prior to adding elements; the scaling factor is applied to coordinates as these elements are added.
Sourcepub fn set_font(&mut self, scale: f32, font: String)
pub fn set_font(&mut self, scale: f32, font: String)
The font size and scale can be set; the scale of a font is normally given in points. The supported fonts may depend on a PostScript engine, but Times-Roman, Helvetica, and Courier are generally available.
Sourcepub fn bbox(&self) -> (f32, f32, f32, f32)
pub fn bbox(&self) -> (f32, f32, f32, f32)
Returns the bounding box of elements that have been added. The bounding box does not track text entries – only lines, and boxes.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the event vector – the number of objects that have been added. If no events have been added to a PSTool, PostScript output will not be generated.
Sourcepub fn generate(&self, filepath: String) -> Result<usize>
pub fn generate(&self, filepath: String) -> Result<usize>
Generates simple PostScript to express the objects that have been added. The filepath should be the name of a file to store the PostScript in. If this string is zero length, output will be sent to standard out.
Sourcepub fn parse(&mut self, filename: String) -> Result<usize>
pub fn parse(&mut self, filename: String) -> Result<usize>
Simple text file commands can be parsed, and converted into PostScript. There should be one command per line. Blank lines, and lines starting with a hash mark are ignored. I need to figure out the proper Rust way to read from either a file or standard input.