Skip to main content

PdfRenderer

Struct PdfRenderer 

Source
pub struct PdfRenderer { /* private fields */ }
Expand description

Renders into a PDF document exactly like matplotlib’s RendererPdf and PdfFile. Coordinates are points with the origin at the bottom left of the current page.

Implementations§

Source§

impl PdfRenderer

Source

pub fn reserve_object(&mut self) -> u32

Reserves an object number (reserveObject).

Source

pub fn record_xref(&mut self, id: u32)

Records that object id starts at the current end of the file (recordXref), for objects the program writes itself with write.

Source

pub fn write_object( &mut self, id: u32, contents: &Obj, ) -> Result<(), VectorError>

Writes object id with contents (writeObject).

§Errors

When contents holds a non-finite number.

Source

pub fn write(&mut self, data: &[u8])

Appends data to the open stream, or to the file when none is open (write).

Source

pub fn output_objects(&mut self, objects: &[Obj]) -> Result<(), VectorError>

Writes objects as one line of the open stream or of the file (output).

§Errors

When an object holds a non-finite number.

Source

pub fn open_stream(&self) -> Option<u32>

The object of the open stream, if any (currentstream): the content stream of the page being drawn, or a stream begun with begin_stream.

Source

pub fn begin_stream( &mut self, id: u32, length: Option<u32>, extra: Vec<(String, Obj)>, png: Option<Obj>, ) -> Result<(), VectorError>

Opens the stream object id whose length goes to object length (inline for None), with the extra entries in its dictionary and, for data PNG-predicted already, the decode parameters png (beginStream).

§Errors

When a stream is open already.

Source

pub fn end_stream(&mut self) -> Result<(), VectorError>

Closes the open stream, compressed at pdf.compression, if any (endStream); the content stream of a page after restoring the graphics state its drawing saved.

§Errors

When its dictionary holds a non-finite number.

Source

pub fn output_stream( &mut self, id: u32, data: &[u8], extra: Vec<(String, Obj)>, ) -> Result<(), VectorError>

Writes the stream object id holding data (outputStream).

§Errors

When a stream is open already, or extra holds a non-finite number.

Source

pub fn write_stream( &mut self, id: u32, extra: Vec<(String, Obj)>, png: Option<Obj>, data: Vec<u8>, ) -> Result<(), VectorError>

Writes the stream object id holding data whole, with the extra entries and, for data PNG-predicted already, the decode parameters png, whether or not a stream is open: matplotlib’s Stream of an inline length keeps its data until it ends, then writes itself to the end of the file.

§Errors

When extra holds a non-finite number.

Source

pub fn object_count(&self) -> usize

How many objects the file numbers so far, the zero object included (the length of matplotlib’s xrefTable).

Source

pub fn alpha_state(&mut self, alphas: (f64, f64)) -> String

The name of the graphics state setting the stroke and fill alpha alphas (alphaState), made on first use.

Source

pub fn new_alpha_state(&mut self, alphas: (f64, f64)) -> String

A new graphics state setting the alphas alphas, though another may set the same: alphaState for a value the program has not given before (matplotlib keys its states by the program’s values, which may be of other types but of equal numbers).

Source

pub fn hatch_pattern( &mut self, edge: Option<Rgba>, face: Option<Rgba>, pattern: &str, linewidth: f64, ) -> String

The name of the tiling pattern drawing pattern (matplotlib’s hatch string) in edge, over face, with lines linewidth wide (hatchPattern), made on first use.

Source

pub fn new_hatch_pattern( &mut self, edge: Option<Rgba>, face: Option<Rgba>, pattern: &str, linewidth: f64, ) -> String

A new tiling pattern, though another may draw the same: hatchPattern for a style the program has not given before (see new_alpha_state).

Source

pub fn hatch_patterns(&self) -> Vec<(PdfHatch, String)>

The hatch patterns made so far with their names, in order.

Source

pub fn add_gouraud_triangles( &mut self, points: Vec<[Point; 3]>, colors: ShadingColors, ) -> (String, u32)

The name and object of a new shading of the triangles points (display coordinates) in the vertex colours colors (addGouraudTriangles).

Source

pub fn image_object(&mut self, image: &RgbaImage) -> String

The name of a new image XObject showing image (imageObject).

Source

pub fn marker_object( &mut self, path: &Path, transform: Affine2D, paint: MarkerPaint, ) -> String

The name of a new form XObject drawing the marker path under transform as paint says (markerObject).

Source

pub fn path_collection_object( &mut self, path: &Path, transform: Affine2D, paint: TemplatePaint, ) -> String

The name of a new form XObject drawing path of a collection under transform as paint says (pathCollectionObject).

Source

pub fn write_ext_gstates(&mut self) -> Result<(), VectorError>

Writes the dictionary of the graphics states (writeExtGSTates) and the transparency groups of the soft masks.

§Errors

When an alpha is not finite.

Source

pub fn write_hatches(&mut self) -> Result<(), VectorError>

Writes the tiling patterns and their dictionary (writeHatches).

§Errors

When a hatch colour or width is not finite.

Source

pub fn write_gouraud_triangles(&mut self) -> Result<(), VectorError>

Writes the shadings and their dictionary (writeGouraudTriangles).

§Errors

When a vertex is not finite.

Source

pub fn write_images(&mut self) -> Result<(), VectorError>

Writes the image XObjects (writeImages).

§Errors

When an image cannot be encoded.

Source

pub fn write_markers(&mut self) -> Result<(), VectorError>

Writes the marker forms (writeMarkers).

§Errors

When a marker is not finite.

Source

pub fn write_path_collection_templates(&mut self) -> Result<(), VectorError>

Writes the path-collection templates (writePathCollectionTemplates).

§Errors

When a path is not finite.

Source

pub fn font_name( &mut self, path: &FsPath, index: u32, subset: usize, ) -> Result<String, VectorError>

The name of subset subset of face index of the TrueType file path (fontName), assigned on first use.

§Errors

When the file cannot be read or has no face index.

Source

pub fn core_font_name(&mut self, file: &str) -> Result<String, VectorError>

The name of the PDF core font whose metrics file is file (fontName under pdf.use14corefonts), assigned on first use.

§Errors

When file is not the metrics of a core font.

Source

pub fn reserve_font_name(&mut self) -> String

A name for a font the program names that pltrs cannot embed (a file it cannot read, a subset that is no count): matplotlib’s fontName names any file, failing only when it writes the fonts. The name takes its place among the others and is written as no font.

Source

pub fn font_names(&self) -> Vec<(PdfFont, String)>

The fonts named so far with their names, in first-use order (matplotlib’s fontNames), but those of reserve_font_name.

Source

pub fn dvi_font_name( &mut self, font: Arc<DviFont>, files: &'static TexFiles, ) -> String

The name of the TeX font font (F-<texname>, dviFontName), whose files files finds, registered to be embedded with the glyphs drawn in it.

Source

pub fn dvi_font_used(&self, name: &str) -> bool

Whether glyphs of the TeX font registered under name (dvi_font_name) were drawn in the document, which writeFonts needs to embed it.

Source

pub fn write_fonts(&mut self) -> Result<(), VectorError>

Writes the font dictionaries of every font named and their resource dictionary (writeFonts).

§Errors

When a font cannot be read or embedded.

Source

pub fn tracks_font( &self, path: &FsPath, index: u32, ) -> Result<bool, VectorError>

Whether glyphs of face index of the font file path were drawn in the document (matplotlib’s character tracker holds the font, which writeFonts and embedTTF read).

§Errors

When the file cannot be read or has no face index.

Source

pub fn embed_ttf( &mut self, path: &FsPath, index: u32, subset_index: usize, charmap: Vec<(u32, GlyphId)>, ) -> Result<u32, VectorError>

Embeds the glyphs charmap (character codes and the glyphs they show) of face index of the TrueType file path as subset subset_index, in the format of pdf.fonttype (embedTTF); returns the font dictionary.

§Errors

When charmap is empty or the font cannot be read.

Source

pub fn create_type1_descriptor( &mut self, font: &Type1Font, ) -> Result<u32, VectorError>

Writes the font descriptor and the program of the Type 1 font font (createType1Descriptor); returns the descriptor.

§Errors

When a number of the font is not finite.

Source

pub fn write_info_dict(&mut self) -> Result<u32, VectorError>

Writes the document information dictionary (writeInfoDict); returns its object.

§Errors

Never in practice: the information is text and dates.

Source

pub fn unwritten_object(&self) -> Option<usize>

The first object reserved but not written yet, if any (the one write_xref would fail on).

Source

pub fn write_xref(&mut self) -> Result<(), VectorError>

Writes the cross-reference table (writeXref).

§Errors

When an object was reserved but never written.

Source

pub fn write_trailer(&mut self) -> Result<(), VectorError>

Writes the trailer (writeTrailer), after the document information if it was not written yet.

§Errors

As write_info_dict.

Source

pub fn finalize(&mut self) -> Result<(), VectorError>

Closes the page and writes the deferred objects and the end of the file (finalize): what write_deferred writes, then the cross-reference table and the trailer.

§Errors

As write_deferred and write_xref.

Source

pub fn write_deferred(&mut self) -> Result<(), VectorError>

Closes the page and writes the deferred objects, all finalize writes before the cross-reference table: annotations, fonts, graphics states, hatches, shadings, XObjects, the page tree and the document information.

§Errors

When a font, image or number met while drawing could not be written.

Source

pub fn close(self) -> Result<Vec<u8>, VectorError>

The file written so far, after closing the open stream (matplotlib’s close).

§Errors

The first problem met while drawing (a font, image or number that could not be written), or one of closing the stream.

Source§

impl PdfRenderer

Source

pub fn new( width: f64, height: f64, image_dpi: f64, options: PdfOptions, ) -> Result<Self, VectorError>

A document with one page of width × height inches whose images are rasterized at image_dpi (matplotlib’s PdfFile plus newPage).

§Errors

When the page size or resolution is not positive and finite.

Source

pub fn document(options: PdfOptions) -> Result<Self, VectorError>

A document without pages yet (matplotlib’s PdfFile); drawing needs a page started with new_page.

§Errors

Never in practice: the document’s first objects are always writable.

Source

pub fn new_page( &mut self, width: f64, height: f64, image_dpi: f64, ) -> Result<(), VectorError>

Ends the current page, if any, and starts a page of width × height inches whose images are rasterized at image_dpi, drawn with a fresh graphics state (matplotlib’s newPage and a new RendererPdf). Notes attached since the last page go on it. Any finite size makes a page, as matplotlib’s newPage writes the media box it is given (an empty one for a size of zero).

§Errors

When the resolution is not positive and finite, the size is not finite, or the previous page could not be written.

Source

pub fn new_page_spanning( &mut self, width: f64, height: f64, image_dpi: f64, media_box: Obj, ) -> Result<(), VectorError>

new_page for a page whose media box is written as media_box: whatever matplotlib’s newPage writes for the size it is given ([0, 0, 72 * width, 72 * height] in Python’s arithmetic), the page drawn as width × height inches.

§Errors

As new_page, and when media_box holds a non-finite number.

Source

pub fn attach_note(&mut self, text: &str, rect: [f64; 4])

Attaches a text note shown at rect ([x0, y0, x1, y1] in points) to the next page started (matplotlib’s newTextnote).

Source

pub fn attach_note_objects(&mut self, contents: Obj, rect: Obj)

attach_note of a note whose text and rectangle are written as contents and rect: whatever matplotlib’s newTextnote is given, kept as it is until the annotations are written.

Source

pub fn page_count(&self) -> usize

How many pages the document has.

Source

pub fn image_names(&self) -> Vec<String>

The names of the images the document holds so far (I1, I2, …), one per image XObject written (matplotlib’s PdfFile._images).

Source

pub fn metadata_mut(&mut self) -> &mut Metadata

The document information written when the document is finished (matplotlib’s PdfPages.infodict).

Source

pub fn afm_directory(&self) -> Option<AfmDirectory>

The AFM fonts the document draws text that is not mathtext in, if any (see PdfOptions::afm_directory).

Source

pub fn finish(self) -> Result<Vec<u8>, VectorError>

Closes the page and writes the annotations, fonts, resources, the page tree, the document information and the cross-reference table (matplotlib’s finalize and close).

§Errors

When a font, image or number met while drawing could not be written.

Source

pub fn restore_gc(&mut self) -> Result<(), VectorError>

Restores every graphics state the page saved (matplotlib’s RendererPdf.finalize).

§Errors

When the content stream cannot be written.

Source

pub fn check_gc(&mut self, gc: &GraphicsContext, fill: Option<Rgba>)

Writes what changes the graphics state of the page into the one gc and the fill fill need, the state kept by the document (matplotlib’s RendererPdf.check_gc).

Trait Implementations§

Source§

impl Debug for PdfRenderer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Renderer for PdfRenderer

Source§

fn dpi(&self) -> f64

The image resolution, as matplotlib’s MixedModeRenderer.dpi.

Source§

fn points_to_pixels(&self, points: f64) -> f64

Lengths are points already.

Source§

fn open_part_group(&mut self, _name: &str, _gid: Option<&str>)

The parts of an artist draw in its generation.

Source§

fn canvas_size(&self) -> (f64, f64)

Canvas width and height in pixels.
Source§

fn draw_path( &mut self, gc: &GraphicsContext, path: &Path, transform: &Affine2D, fill: Option<Rgba>, )

Strokes path with gc and fills it with fill, if given.
Source§

fn draw_markers( &mut self, gc: &GraphicsContext, marker: &Path, marker_transform: &Affine2D, path: &Path, transform: &Affine2D, fill: Option<Rgba>, )

Draws marker (in marker coordinates, mapped by marker_transform to pixel offsets) at every vertex of path transformed by transform.
Source§

fn draw_path_collection( &mut self, gc: &GraphicsContext, collection: &PathCollection<'_>, )

Draws many paths with per-item properties (scatter, patches, meshes).
Source§

fn draw_gouraud_triangles( &mut self, gc: &GraphicsContext, triangles: &[[Point; 3]], colors: &[[Rgba; 3]], transform: &Affine2D, )

Draws triangles whose vertex colours are interpolated linearly (Gouraud shading); transform maps the vertices to display space.
Source§

fn draw_image( &mut self, gc: &GraphicsContext, origin: Point, image: &RgbaImage, transform: Option<&Affine2D>, )

Draws an image with its bottom-left corner at origin (display coordinates). With transform, the image’s unit square is mapped through it instead (only used when option_scale_image is true).
Source§

fn draw_text( &mut self, gc: &GraphicsContext, run: &TextRun, origin: Point, angle: f64, )

Draws laid-out text with its origin (left end of the baseline) at origin, rotated by angle degrees counter-clockwise about it. Read more
Source§

fn draw_tex( &mut self, gc: &GraphicsContext, _run: &TextRun, tex: &TexText, origin: Point, angle: f64, ) -> Result<(), TexError>

Draws tex, a line of TeX text that is the source of run (TextSource::Tex), with its origin at origin, rotated by angle degrees counter-clockwise about it (matplotlib’s draw_tex). Read more
Source§

fn open_group(&mut self, _name: &str, _gid: Option<&str>)

Starts a named group of draw calls (vector backends emit a group).
Source§

fn close_group(&mut self, _name: &str)

Ends the most recently opened group.
Source§

fn close_part_group(&mut self, _name: &str)

Ends the most recently opened group of a part.
Source§

fn option_image_nocomposite(&self) -> bool

When true, images are drawn one by one instead of being composited into a single image first.
Source§

fn option_scale_image(&self) -> bool

When true, draw_image accepts arbitrary affine transforms (vector backends); otherwise images arrive pre-resampled at display resolution.
Source§

fn image_magnification(&self) -> f64

The factor by which images are magnified before being drawn (matplotlib’s get_image_magnification): vector backends rasterize images at their own resolution rather than at 72 dpi.
Source§

fn draw_quad_mesh(&mut self, gc: &GraphicsContext, mesh: &QuadMesh<'_>)

Draws a flat-shaded quad mesh (matplotlib’s draw_quad_mesh): by default as a path collection of its cells in matplotlib’s order (QuadMesh::cell_paths) with the line width of gc.
Source§

fn draw_text_lines( &mut self, _gc: &GraphicsContext, _text: &TextLines<'_>, ) -> bool

Draws text whole, as matplotlib’s Text.draw hands a renderer a text’s lines one by one, each with its string, font and artist (draw_text(gc, x, y, s, prop, angle, ismath, mtext)); whether the renderer drew it. The renderers of this crate don’t (they draw each line through draw_text or draw_tex), a renderer of the program’s does.
Source§

fn takes_texts_whole(&self) -> bool

Whether the renderer takes texts whole (draw_text_lines), which those drawing texts ask before they describe one.
Source§

fn rounds_glyph_positions(&self) -> bool

Whether the renderer rounds where it puts each glyph (and each line of TeX) to whole numbers as Python rounds them, as matplotlib’s Agg renderer does (round(0x40 * x)), which refuses a position that is not finite. Renderers drawing glyphs as paths don’t.
Source§

fn start_rasterizing(&mut self)

Sends the following drawing to a raster canvas until stop_rasterizing (matplotlib’s start_rasterizing); only vector output distinguishes the modes.
Source§

fn stop_rasterizing(&mut self)

Places what was drawn since start_rasterizing in the output as an image and resumes drawing directly.
Source§

fn raster_dpi(&self) -> Option<f64>

The resolution of the raster canvas drawing goes to while a vector renderer is rasterizing, None otherwise. Artists drawn meanwhile compute their geometry at it, in canvas pixels (matplotlib changes the figure’s dpi in start_rasterizing).
Source§

fn start_filter(&mut self)

Sends the following drawing to a fresh transparent canvas until stop_filter (matplotlib’s start_filter). Only raster canvases filter; other backends draw as usual.
Source§

fn stop_filter(&mut self, _filter: &FilterFn<'_>)

Hands what was drawn since start_filter, cropped to its visible pixels, to filter and draws the image it returns in its place (matplotlib’s stop_filter).
Source§

fn stop_shared_filter(&mut self, filter: &SharedFilter)

stop_filter with a filter the renderer may keep, as matplotlib hands renderers the artist’s filter itself: a renderer passing it on (to a program’s renderer, say) overrides this; the others filter as stop_filter does.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.