Content

Struct Content 

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

A builder for a content stream.

Implementations§

Source§

impl Content

Core methods.

Source

pub fn new() -> Self

Create a new content stream with the default buffer capacity (currently 1 KB).

Source

pub fn with_capacity(capacity: usize) -> Self

Create a new content stream with the specified initial buffer capacity.

Source

pub fn op<'a>(&'a mut self, operator: &'a str) -> Operation<'a>

Start writing an arbitrary operation.

Source

pub fn finish(self) -> Buf

Return the buffer of the content stream.

The buffer is essentially a thin wrapper around two objects:

  • A Limits object, which can optionally be used to keep track of data such as the largest used integer or the longest string used in the content streams, which is useful information for some export modes.
  • The actual underlying data of the content stream, which can be written to a chunk (and optionally apply a filter before doing so).
Source§

impl Content

General graphics state.

Source

pub fn set_line_width(&mut self, width: f32) -> &mut Self

w: Set the stroke line width.

Panics if width is negative.

Source

pub fn set_line_cap(&mut self, cap: LineCapStyle) -> &mut Self

J: Set the line cap style.

Source

pub fn set_line_join(&mut self, join: LineJoinStyle) -> &mut Self

j: Set the line join style.

Source

pub fn set_miter_limit(&mut self, limit: f32) -> &mut Self

M: Set the miter limit.

Source

pub fn set_dash_pattern( &mut self, array: impl IntoIterator<Item = f32>, phase: f32, ) -> &mut Self

d: Set the line dash pattern.

Source

pub fn set_rendering_intent(&mut self, intent: RenderingIntent) -> &mut Self

ri: Set the color rendering intent to the parameter. PDF 1.1+.

Source

pub fn set_flatness(&mut self, tolerance: i32) -> &mut Self

i: Set the flatness tolerance in device pixels.

Panics if tolerance is negative or larger than 100.

Source

pub fn set_parameters(&mut self, dict: Name<'_>) -> &mut Self

gs: Set the parameters from an ExtGState dictionary. PDF 1.2+.

Source§

impl Content

Special graphics state.

Source

pub fn save_state(&mut self) -> &mut Self

q: Save the graphics state on the stack.

Source

pub fn restore_state(&mut self) -> &mut Self

Q: Restore the graphics state from the stack.

Source

pub fn state_nesting_depth(&self) -> usize

The current q nesting depth.

Source

pub fn transform(&mut self, matrix: [f32; 6]) -> &mut Self

cm: Pre-concatenate the matrix with the current transformation matrix.

Source§

impl Content

Path construction.

Source

pub fn move_to(&mut self, x: f32, y: f32) -> &mut Self

m: Begin a new subpath at (x, y).

Source

pub fn line_to(&mut self, x: f32, y: f32) -> &mut Self

l: Append a straight line to (x, y).

Source

pub fn cubic_to( &mut self, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, ) -> &mut Self

c: Append a cubic Bézier segment to (x3, y3) with (x1, y1), (x2, y2) as control points.

Source

pub fn cubic_to_initial( &mut self, x2: f32, y2: f32, x3: f32, y3: f32, ) -> &mut Self

v: Append a cubic Bézier segment to (x3, y3) with (x2, y2) as control point.

Source

pub fn cubic_to_final( &mut self, x1: f32, y1: f32, x3: f32, y3: f32, ) -> &mut Self

y: Append a cubic Bézier segment to (x3, y3) with (x1, y1) as control point.

Source

pub fn close_path(&mut self) -> &mut Self

h: Close the current subpath with a straight line.

Source

pub fn rect(&mut self, x: f32, y: f32, width: f32, height: f32) -> &mut Self

re: Append a rectangle to the current path.

Source§

impl Content

Path painting.

Source

pub fn stroke(&mut self) -> &mut Self

S: Stroke the current path.

Source

pub fn close_and_stroke(&mut self) -> &mut Self

s: Close the current path and then stroke it.

Source

pub fn fill_nonzero(&mut self) -> &mut Self

f: Fill the current path using the nonzero winding number rule.

Source

pub fn fill_even_odd(&mut self) -> &mut Self

f*: Fill the current path using the even-odd rule.

Source

pub fn fill_nonzero_and_stroke(&mut self) -> &mut Self

B: Fill the current path using the nonzero winding number rule and then stroke it.

Source

pub fn fill_even_odd_and_stroke(&mut self) -> &mut Self

B*: Fill the current path using the even-odd rule and then stroke it.

Source

pub fn close_fill_nonzero_and_stroke(&mut self) -> &mut Self

b: Close the current path, fill it using the nonzero winding number rule and then stroke it.

Source

pub fn close_fill_even_odd_and_stroke(&mut self) -> &mut Self

b*: Close the current path, fill it using the even-odd rule and then stroke it.

Source

pub fn end_path(&mut self) -> &mut Self

n: End the current path without filling or stroking it.

This is primarily used for clipping paths.

Source§

impl Content

Clipping paths.

Source

pub fn clip_nonzero(&mut self) -> &mut Self

W: Intersect the current clipping path with the current path using the nonzero winding number rule.

Source

pub fn clip_even_odd(&mut self) -> &mut Self

W*: Intersect the current clipping path with the current path using the even-odd rule.

Source§

impl Content

Text objects.

Source

pub fn begin_text(&mut self) -> &mut Self

BT: Begin a text object.

Source

pub fn end_text(&mut self) -> &mut Self

ET: End a text object.

Source§

impl Content

Text state.

Source

pub fn set_char_spacing(&mut self, spacing: f32) -> &mut Self

Tc: Set the character spacing.

Source

pub fn set_word_spacing(&mut self, spacing: f32) -> &mut Self

Tw: Set the word spacing.

Source

pub fn set_horizontal_scaling(&mut self, scaling: f32) -> &mut Self

Tz: Set the horizontal scaling.

Source

pub fn set_leading(&mut self, leading: f32) -> &mut Self

TL: Set the leading.

Source

pub fn set_font(&mut self, font: Name<'_>, size: f32) -> &mut Self

Tf: Set font and font size.

Source

pub fn set_text_rendering_mode(&mut self, mode: TextRenderingMode) -> &mut Self

Tr: Set the text rendering mode.

Source

pub fn set_rise(&mut self, rise: f32) -> &mut Self

Ts: Set the rise.

Source§

impl Content

Text positioning.

Source

pub fn next_line(&mut self, x: f32, y: f32) -> &mut Self

Td: Move to the start of the next line.

Source

pub fn next_line_and_set_leading(&mut self, x: f32, y: f32) -> &mut Self

TD: Move to the start of the next line and set the text state’s leading parameter to -y.

Source

pub fn set_text_matrix(&mut self, matrix: [f32; 6]) -> &mut Self

Tm: Set the text matrix.

Source

pub fn next_line_using_leading(&mut self) -> &mut Self

T*: Move to the start of the next line, determining the vertical offset through the text state’s leading parameter.

Source§

impl Content

Text showing.

Source

pub fn show(&mut self, text: Str<'_>) -> &mut Self

Tj: Show text.

The encoding of the text depends on the font.

Source

pub fn next_line_show(&mut self, text: Str<'_>) -> &mut Self

': Move to the next line and show text.

Source

pub fn next_line_show_and_set_word_and_char_spacing( &mut self, word_spacing: f32, char_spacing: f32, text: Str<'_>, ) -> &mut Self

": Move to the next line, show text and set the text state’s word and character spacing.

Source

pub fn show_positioned(&mut self) -> ShowPositioned<'_>

TJ: Start showing text with individual glyph positioning.

Source§

impl Content

Type 3 fonts.

These operators are only allowed in Type 3 CharProcs.

Source

pub fn start_color_glyph(&mut self, wx: f32) -> &mut Self

d0: Starts a Type 3 glyph that contains color information.

  • wx defines the glyph’s width
  • wy is set to 0.0 automatically
Source

pub fn start_shape_glyph( &mut self, wx: f32, ll_x: f32, ll_y: f32, ur_x: f32, ur_y: f32, ) -> &mut Self

d1: Starts a Type 3 glyph that contains only shape information.

  • wx defines the glyph’s width
  • wy is set to 0.0 automatically
  • ll_x and ll_y define the lower-left corner of the glyph bounding box
  • ur_x and ur_y define the upper-right corner of the glyph bounding box
Source§

impl Content

Color.

Source

pub fn set_stroke_color_space<'a>( &mut self, space: impl Into<ColorSpaceOperand<'a>>, ) -> &mut Self

CS: Set the stroke color space to the parameter. PDF 1.1+.

The parameter must be the name of a parameter-less color space or of a color space dictionary within the current resource dictionary.

Source

pub fn set_fill_color_space<'a>( &mut self, space: impl Into<ColorSpaceOperand<'a>>, ) -> &mut Self

cs: Set the fill color space to the parameter. PDF 1.1+.

The parameter must be the name of a parameter-less color space or of a color space dictionary within the current resource dictionary.

Source

pub fn set_stroke_color( &mut self, color: impl IntoIterator<Item = f32>, ) -> &mut Self

SCN: Set the stroke color to the parameter within the current color space. PDF 1.2+.

Source

pub fn set_stroke_pattern( &mut self, tint: impl IntoIterator<Item = f32>, name: Name<'_>, ) -> &mut Self

SCN: Set the stroke pattern. PDF 1.2+.

The name parameter is the name of a pattern. If this is an uncolored pattern, a tint color in the current Pattern base color space must be given, otherwise, the color iterator shall remain empty.

Source

pub fn set_fill_color( &mut self, color: impl IntoIterator<Item = f32>, ) -> &mut Self

scn: Set the fill color to the parameter within the current color space. PDF 1.2+.

Source

pub fn set_fill_pattern( &mut self, tint: impl IntoIterator<Item = f32>, name: Name<'_>, ) -> &mut Self

scn: Set the fill pattern. PDF 1.2+.

The name parameter is the name of a pattern. If this is an uncolored pattern, a tint color in the current Pattern base color space must be given, otherwise, the color iterator shall remain empty.

Source

pub fn set_stroke_gray(&mut self, gray: f32) -> &mut Self

G: Set the stroke color to the parameter and the color space to DeviceGray.

Source

pub fn set_fill_gray(&mut self, gray: f32) -> &mut Self

g: Set the fill color to the parameter and the color space to DeviceGray.

Source

pub fn set_stroke_rgb(&mut self, r: f32, g: f32, b: f32) -> &mut Self

RG: Set the stroke color to the parameter and the color space to DeviceRGB.

Source

pub fn set_fill_rgb(&mut self, r: f32, g: f32, b: f32) -> &mut Self

rg: Set the fill color to the parameter and the color space to DeviceRGB.

Source

pub fn set_stroke_cmyk(&mut self, c: f32, m: f32, y: f32, k: f32) -> &mut Self

K: Set the stroke color to the parameter and the color space to DeviceCMYK.

Source

pub fn set_fill_cmyk(&mut self, c: f32, m: f32, y: f32, k: f32) -> &mut Self

k: Set the fill color to the parameter and the color space to DeviceCMYK.

Source§

impl Content

Shading patterns.

Source

pub fn shading(&mut self, shading: Name<'_>) -> &mut Self

sh: Fill the whole drawing area with the specified shading.

Source§

impl Content

XObjects.

Source

pub fn x_object(&mut self, name: Name<'_>) -> &mut Self

Do: Write an external object.

Source§

impl Content

Marked Content.

Source

pub fn marked_content_point(&mut self, tag: Name<'_>) -> &mut Self

MP: Write a marked-content point. PDF 1.2+.

Source

pub fn marked_content_point_with_properties( &mut self, tag: Name<'_>, ) -> MarkContent<'_>

DP: Start writing a marked-content point operation. PDF 1.2+.

Source

pub fn begin_marked_content(&mut self, tag: Name<'_>) -> &mut Self

BMC: Begin a marked-content sequence. PDF 1.2+.

Source

pub fn begin_marked_content_with_properties( &mut self, tag: Name<'_>, ) -> MarkContent<'_>

BDC: Start writing a “begin marked content” operation. PDF 1.2+.

Source

pub fn end_marked_content(&mut self) -> &mut Self

EMC: End a marked-content sequence. PDF 1.2+.

Source§

impl Content

Compatibility.

Source

pub fn begin_compat(&mut self) -> &mut Self

BX: Begin a compatibility section.

Source

pub fn end_compat(&mut self) -> &mut Self

EX: End a compatibility section.

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> Finish for T

Source§

fn finish(self)

Does nothing but move self, equivalent to drop.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.