Struct pdf_writer::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) -> Vec<u8>

Return the raw constructed byte stream.

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 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>,

§

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>,

§

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.