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
impl PdfRenderer
Sourcepub fn reserve_object(&mut self) -> u32
pub fn reserve_object(&mut self) -> u32
Reserves an object number (reserveObject).
Sourcepub fn record_xref(&mut self, id: u32)
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.
Sourcepub fn write_object(
&mut self,
id: u32,
contents: &Obj,
) -> Result<(), VectorError>
pub fn write_object( &mut self, id: u32, contents: &Obj, ) -> Result<(), VectorError>
Sourcepub fn write(&mut self, data: &[u8])
pub fn write(&mut self, data: &[u8])
Appends data to the open stream, or to the file when none is open
(write).
Sourcepub fn output_objects(&mut self, objects: &[Obj]) -> Result<(), VectorError>
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.
Sourcepub fn open_stream(&self) -> Option<u32>
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.
Sourcepub fn begin_stream(
&mut self,
id: u32,
length: Option<u32>,
extra: Vec<(String, Obj)>,
png: Option<Obj>,
) -> Result<(), VectorError>
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.
Sourcepub fn end_stream(&mut self) -> Result<(), VectorError>
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.
Sourcepub fn output_stream(
&mut self,
id: u32,
data: &[u8],
extra: Vec<(String, Obj)>,
) -> Result<(), VectorError>
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.
Sourcepub fn write_stream(
&mut self,
id: u32,
extra: Vec<(String, Obj)>,
png: Option<Obj>,
data: Vec<u8>,
) -> Result<(), VectorError>
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.
Sourcepub fn object_count(&self) -> usize
pub fn object_count(&self) -> usize
How many objects the file numbers so far, the zero object included
(the length of matplotlib’s xrefTable).
Sourcepub fn alpha_state(&mut self, alphas: (f64, f64)) -> String
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.
Sourcepub fn new_alpha_state(&mut self, alphas: (f64, f64)) -> String
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).
Sourcepub fn hatch_pattern(
&mut self,
edge: Option<Rgba>,
face: Option<Rgba>,
pattern: &str,
linewidth: f64,
) -> String
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.
Sourcepub fn new_hatch_pattern(
&mut self,
edge: Option<Rgba>,
face: Option<Rgba>,
pattern: &str,
linewidth: f64,
) -> String
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).
Sourcepub fn hatch_patterns(&self) -> Vec<(PdfHatch, String)>
pub fn hatch_patterns(&self) -> Vec<(PdfHatch, String)>
The hatch patterns made so far with their names, in order.
Sourcepub fn add_gouraud_triangles(
&mut self,
points: Vec<[Point; 3]>,
colors: ShadingColors,
) -> (String, u32)
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).
Sourcepub fn image_object(&mut self, image: &RgbaImage) -> String
pub fn image_object(&mut self, image: &RgbaImage) -> String
The name of a new image XObject showing image (imageObject).
Sourcepub fn marker_object(
&mut self,
path: &Path,
transform: Affine2D,
paint: MarkerPaint,
) -> String
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).
Sourcepub fn path_collection_object(
&mut self,
path: &Path,
transform: Affine2D,
paint: TemplatePaint,
) -> String
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).
Sourcepub fn write_ext_gstates(&mut self) -> Result<(), VectorError>
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.
Sourcepub fn write_hatches(&mut self) -> Result<(), VectorError>
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.
Sourcepub fn write_gouraud_triangles(&mut self) -> Result<(), VectorError>
pub fn write_gouraud_triangles(&mut self) -> Result<(), VectorError>
Writes the shadings and their dictionary
(writeGouraudTriangles).
§Errors
When a vertex is not finite.
Sourcepub fn write_images(&mut self) -> Result<(), VectorError>
pub fn write_images(&mut self) -> Result<(), VectorError>
Sourcepub fn write_markers(&mut self) -> Result<(), VectorError>
pub fn write_markers(&mut self) -> Result<(), VectorError>
Sourcepub fn write_path_collection_templates(&mut self) -> Result<(), VectorError>
pub fn write_path_collection_templates(&mut self) -> Result<(), VectorError>
Writes the path-collection templates
(writePathCollectionTemplates).
§Errors
When a path is not finite.
Sourcepub fn font_name(
&mut self,
path: &FsPath,
index: u32,
subset: usize,
) -> Result<String, VectorError>
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.
Sourcepub fn core_font_name(&mut self, file: &str) -> Result<String, VectorError>
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.
Sourcepub fn reserve_font_name(&mut self) -> String
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.
Sourcepub fn font_names(&self) -> Vec<(PdfFont, String)>
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.
Sourcepub fn dvi_font_name(
&mut self,
font: Arc<DviFont>,
files: &'static TexFiles,
) -> String
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.
Sourcepub fn dvi_font_used(&self, name: &str) -> bool
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.
Sourcepub fn write_fonts(&mut self) -> Result<(), VectorError>
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.
Sourcepub fn tracks_font(
&self,
path: &FsPath,
index: u32,
) -> Result<bool, VectorError>
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.
Sourcepub fn embed_ttf(
&mut self,
path: &FsPath,
index: u32,
subset_index: usize,
charmap: Vec<(u32, GlyphId)>,
) -> Result<u32, VectorError>
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.
Sourcepub fn create_type1_descriptor(
&mut self,
font: &Type1Font,
) -> Result<u32, VectorError>
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.
Sourcepub fn write_info_dict(&mut self) -> Result<u32, VectorError>
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.
Sourcepub fn unwritten_object(&self) -> Option<usize>
pub fn unwritten_object(&self) -> Option<usize>
The first object reserved but not written yet, if any (the one
write_xref would fail on).
Sourcepub fn write_xref(&mut self) -> Result<(), VectorError>
pub fn write_xref(&mut self) -> Result<(), VectorError>
Writes the cross-reference table (writeXref).
§Errors
When an object was reserved but never written.
Sourcepub fn write_trailer(&mut self) -> Result<(), VectorError>
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.
Sourcepub fn finalize(&mut self) -> Result<(), VectorError>
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.
Sourcepub fn write_deferred(&mut self) -> Result<(), VectorError>
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§impl PdfRenderer
impl PdfRenderer
Sourcepub fn new(
width: f64,
height: f64,
image_dpi: f64,
options: PdfOptions,
) -> Result<Self, VectorError>
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.
Sourcepub fn document(options: PdfOptions) -> Result<Self, VectorError>
pub fn document(options: PdfOptions) -> Result<Self, VectorError>
Sourcepub fn new_page(
&mut self,
width: f64,
height: f64,
image_dpi: f64,
) -> Result<(), VectorError>
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.
Sourcepub fn new_page_spanning(
&mut self,
width: f64,
height: f64,
image_dpi: f64,
media_box: Obj,
) -> Result<(), VectorError>
pub fn new_page_spanning( &mut self, width: f64, height: f64, image_dpi: f64, media_box: Obj, ) -> Result<(), VectorError>
Sourcepub fn attach_note(&mut self, text: &str, rect: [f64; 4])
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).
Sourcepub fn attach_note_objects(&mut self, contents: Obj, rect: Obj)
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.
Sourcepub fn page_count(&self) -> usize
pub fn page_count(&self) -> usize
How many pages the document has.
Sourcepub fn image_names(&self) -> Vec<String>
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).
Sourcepub fn metadata_mut(&mut self) -> &mut Metadata
pub fn metadata_mut(&mut self) -> &mut Metadata
The document information written when the document is finished
(matplotlib’s PdfPages.infodict).
Sourcepub fn afm_directory(&self) -> Option<AfmDirectory>
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).
Sourcepub fn finish(self) -> Result<Vec<u8>, VectorError>
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.
Sourcepub fn restore_gc(&mut self) -> Result<(), VectorError>
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.
Sourcepub fn check_gc(&mut self, gc: &GraphicsContext, fill: Option<Rgba>)
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
impl Debug for PdfRenderer
Source§impl Renderer for PdfRenderer
impl Renderer for PdfRenderer
Source§fn points_to_pixels(&self, points: f64) -> f64
fn points_to_pixels(&self, points: f64) -> f64
Lengths are points already.
Source§fn open_part_group(&mut self, _name: &str, _gid: Option<&str>)
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)
fn canvas_size(&self) -> (f64, f64)
Source§fn draw_path(
&mut self,
gc: &GraphicsContext,
path: &Path,
transform: &Affine2D,
fill: Option<Rgba>,
)
fn draw_path( &mut self, gc: &GraphicsContext, path: &Path, transform: &Affine2D, fill: Option<Rgba>, )
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>,
)
fn draw_markers( &mut self, gc: &GraphicsContext, marker: &Path, marker_transform: &Affine2D, path: &Path, transform: &Affine2D, fill: Option<Rgba>, )
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<'_>,
)
fn draw_path_collection( &mut self, gc: &GraphicsContext, collection: &PathCollection<'_>, )
Source§fn draw_gouraud_triangles(
&mut self,
gc: &GraphicsContext,
triangles: &[[Point; 3]],
colors: &[[Rgba; 3]],
transform: &Affine2D,
)
fn draw_gouraud_triangles( &mut self, gc: &GraphicsContext, triangles: &[[Point; 3]], colors: &[[Rgba; 3]], transform: &Affine2D, )
transform maps the vertices to display space.Source§fn draw_image(
&mut self,
gc: &GraphicsContext,
origin: Point,
image: &RgbaImage,
transform: Option<&Affine2D>,
)
fn draw_image( &mut self, gc: &GraphicsContext, origin: Point, image: &RgbaImage, transform: Option<&Affine2D>, )
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,
)
fn draw_text( &mut self, gc: &GraphicsContext, run: &TextRun, origin: Point, angle: f64, )
origin, rotated by angle degrees counter-clockwise about it. Read moreSource§fn draw_tex(
&mut self,
gc: &GraphicsContext,
_run: &TextRun,
tex: &TexText,
origin: Point,
angle: f64,
) -> Result<(), TexError>
fn draw_tex( &mut self, gc: &GraphicsContext, _run: &TextRun, tex: &TexText, origin: Point, angle: f64, ) -> Result<(), TexError>
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 moreSource§fn open_group(&mut self, _name: &str, _gid: Option<&str>)
fn open_group(&mut self, _name: &str, _gid: Option<&str>)
Source§fn close_group(&mut self, _name: &str)
fn close_group(&mut self, _name: &str)
Source§fn close_part_group(&mut self, _name: &str)
fn close_part_group(&mut self, _name: &str)
Source§fn option_image_nocomposite(&self) -> bool
fn option_image_nocomposite(&self) -> bool
true, images are drawn one by one instead of being
composited into a single image first.Source§fn option_scale_image(&self) -> bool
fn option_scale_image(&self) -> bool
true, draw_image accepts arbitrary
affine transforms (vector backends); otherwise images arrive
pre-resampled at display resolution.Source§fn image_magnification(&self) -> f64
fn image_magnification(&self) -> f64
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<'_>)
fn draw_quad_mesh(&mut self, gc: &GraphicsContext, mesh: &QuadMesh<'_>)
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
fn draw_text_lines( &mut self, _gc: &GraphicsContext, _text: &TextLines<'_>, ) -> bool
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
fn takes_texts_whole(&self) -> bool
draw_text_lines), which those drawing
texts ask before they describe one.Source§fn rounds_glyph_positions(&self) -> bool
fn rounds_glyph_positions(&self) -> bool
round(0x40 * x)), which refuses a position that is
not finite. Renderers drawing glyphs as paths don’t.Source§fn start_rasterizing(&mut self)
fn start_rasterizing(&mut self)
stop_rasterizing (matplotlib’s
start_rasterizing); only vector output distinguishes the modes.Source§fn stop_rasterizing(&mut self)
fn stop_rasterizing(&mut self)
start_rasterizing in the output as an
image and resumes drawing directly.Source§fn raster_dpi(&self) -> Option<f64>
fn raster_dpi(&self) -> Option<f64>
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)
fn start_filter(&mut self)
stop_filter (matplotlib’s start_filter).
Only raster canvases filter; other backends draw as usual.Source§fn stop_filter(&mut self, _filter: &FilterFn<'_>)
fn stop_filter(&mut self, _filter: &FilterFn<'_>)
start_filter,
cropped to its visible pixels, to filter and draws the image it
returns in its place (matplotlib’s stop_filter).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.