pub struct PdfGraphics { /* private fields */ }Expand description
PDF graphics context for drawing operations
Implementations§
Source§impl PdfGraphics
impl PdfGraphics
Sourcepub fn set_stroke_color(&mut self, color: Color) -> Result<()>
pub fn set_stroke_color(&mut self, color: Color) -> Result<()>
Set stroke color (for lines and borders)
Sourcepub fn set_fill_color(&mut self, color: Color) -> Result<()>
pub fn set_fill_color(&mut self, color: Color) -> Result<()>
Set fill color (for rectangles)
Sourcepub fn set_opacity(&mut self, gs_name: &str) -> Result<()>
pub fn set_opacity(&mut self, gs_name: &str) -> Result<()>
Set fill opacity (for fill operations)
Sets the alpha value for fill operations using the /ca operator in the graphics state dictionary. This requires ExtGState support.
§Arguments
opacity- Opacity value from 0.0 (transparent) to 1.0 (opaque)gs_name- Name of the graphics state resource (e.g., “gs1”)
§PDF Reference
See PDF specification section 8.4 for graphics state parameters.
Sourcepub fn set_stroke_opacity(&mut self, gs_name: &str) -> Result<()>
pub fn set_stroke_opacity(&mut self, gs_name: &str) -> Result<()>
Set stroke opacity (for stroke operations)
Sets the alpha value for stroke operations using the /CA operator in the graphics state dictionary. This requires ExtGState support.
§Arguments
gs_name- Name of the graphics state resource (e.g., “gs1”)
§PDF Reference
See PDF specification section 8.4 for graphics state parameters.
Sourcepub fn set_line_width(&mut self, width: Length) -> Result<()>
pub fn set_line_width(&mut self, width: Length) -> Result<()>
Set line width
Sourcepub fn set_dash_pattern(&mut self, dash_array: &[f64], phase: f64) -> Result<()>
pub fn set_dash_pattern(&mut self, dash_array: &[f64], phase: f64) -> Result<()>
Set dash pattern for line drawing
§Arguments
dash_array- Array of on/off lengths (e.g., &[3.0, 2.0] for dashed)phase- Offset into the dash pattern (usually 0)
§Examples
- Solid:
set_dash_pattern(&[], 0)or[]0 d - Dashed:
set_dash_pattern(&[6.0, 3.0], 0)or[6 3] 0 d - Dotted:
set_dash_pattern(&[1.0, 2.0], 0)or[1 2] 0 d
Sourcepub fn draw_rectangle(
&mut self,
x: Length,
y: Length,
width: Length,
height: Length,
) -> Result<()>
pub fn draw_rectangle( &mut self, x: Length, y: Length, width: Length, height: Length, ) -> Result<()>
Draw a rectangle (stroke only)
Sourcepub fn fill_rectangle(
&mut self,
x: Length,
y: Length,
width: Length,
height: Length,
) -> Result<()>
pub fn fill_rectangle( &mut self, x: Length, y: Length, width: Length, height: Length, ) -> Result<()>
Fill a rectangle
Sourcepub fn fill_rectangle_with_radius(
&mut self,
x: Length,
y: Length,
width: Length,
height: Length,
border_radius: Option<[Length; 4]>,
) -> Result<()>
pub fn fill_rectangle_with_radius( &mut self, x: Length, y: Length, width: Length, height: Length, border_radius: Option<[Length; 4]>, ) -> Result<()>
Fill a rectangle with optional rounded corners
Sourcepub fn draw_rounded_rectangle(
&mut self,
x: Length,
y: Length,
width: Length,
height: Length,
radii: [Length; 4],
fill: bool,
) -> Result<()>
pub fn draw_rounded_rectangle( &mut self, x: Length, y: Length, width: Length, height: Length, radii: [Length; 4], fill: bool, ) -> Result<()>
Draw a rounded rectangle with independent corner radii
Uses Bezier curves to approximate circular arcs for rounded corners. The magic number 0.552284749831 is used to approximate a circle with cubic Bezier curves. This is derived from 4*(sqrt(2)-1)/3, which minimizes the error between the arc and the curve.
§Arguments
x, y- Bottom-left corner of the rectanglewidth, height- Dimensions of the rectangleradii- Corner radii [top-left, top-right, bottom-right, bottom-left]fill- If true, fill the rectangle; if false, stroke it
Sourcepub fn draw_line(
&mut self,
x1: Length,
y1: Length,
x2: Length,
y2: Length,
) -> Result<()>
pub fn draw_line( &mut self, x1: Length, y1: Length, x2: Length, y2: Length, ) -> Result<()>
Draw a line
Sourcepub fn draw_borders(
&mut self,
x: Length,
y: Length,
width: Length,
height: Length,
border_widths: [Length; 4],
border_colors: [Color; 4],
border_styles: [BorderStyle; 4],
) -> Result<()>
pub fn draw_borders( &mut self, x: Length, y: Length, width: Length, height: Length, border_widths: [Length; 4], border_colors: [Color; 4], border_styles: [BorderStyle; 4], ) -> Result<()>
Draw borders (all four sides)
Sourcepub fn draw_borders_with_radius(
&mut self,
x: Length,
y: Length,
width: Length,
height: Length,
border_widths: [Length; 4],
border_colors: [Color; 4],
border_styles: [BorderStyle; 4],
border_radius: Option<[Length; 4]>,
) -> Result<()>
pub fn draw_borders_with_radius( &mut self, x: Length, y: Length, width: Length, height: Length, border_widths: [Length; 4], border_colors: [Color; 4], border_styles: [BorderStyle; 4], border_radius: Option<[Length; 4]>, ) -> Result<()>
Draw borders with optional rounded corners
Sourcepub fn save_state(&mut self) -> Result<()>
pub fn save_state(&mut self) -> Result<()>
Save graphics state
Sourcepub fn restore_state(&mut self) -> Result<()>
pub fn restore_state(&mut self) -> Result<()>
Restore graphics state
Sourcepub fn save_clip_state(
&mut self,
x: Length,
y: Length,
width: Length,
height: Length,
) -> Result<()>
pub fn save_clip_state( &mut self, x: Length, y: Length, width: Length, height: Length, ) -> Result<()>
Save graphics state and set clipping path
This method saves the current graphics state and establishes a rectangular clipping path. Content drawn after this call will be clipped to the specified rectangle until restore_clip_state() is called.
PDF operators used:
- q: Save graphics state
- re: Rectangle path
- W: Set clipping path (intersect with current path)
- n: End path without stroking or filling
§Arguments
x, y- Bottom-left corner of clipping rectangle (PDF coordinates)width, height- Dimensions of clipping rectangle
§PDF Reference
See PDF specification section 8.5 for clipping path details.
Sourcepub fn restore_clip_state(&mut self) -> Result<()>
pub fn restore_clip_state(&mut self) -> Result<()>
Restore graphics state after clipping
This restores the graphics state that was saved by save_clip_state(), removing the clipping path.
PDF operator used:
- Q: Restore graphics state
Sourcepub fn fill_gradient(
&mut self,
x: Length,
y: Length,
width: Length,
height: Length,
gradient_index: usize,
) -> Result<()>
pub fn fill_gradient( &mut self, x: Length, y: Length, width: Length, height: Length, gradient_index: usize, ) -> Result<()>
Fill a rectangle with a gradient
Uses PDF shading pattern to fill the specified rectangle with a gradient.
§Arguments
x, y- Bottom-left corner of the rectanglewidth, height- Dimensions of the rectanglegradient_index- Index of the gradient shading resource (Sh0, Sh1, etc.)
§PDF Reference
See PDF specification section 8.7 for shading patterns. Uses the /sh operator to paint with shading pattern.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PdfGraphics
impl RefUnwindSafe for PdfGraphics
impl Send for PdfGraphics
impl Sync for PdfGraphics
impl Unpin for PdfGraphics
impl UnsafeUnpin for PdfGraphics
impl UnwindSafe for PdfGraphics
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().