pub struct GraphicsContext { /* private fields */ }Implementations§
Source§impl GraphicsContext
impl GraphicsContext
pub fn new() -> Self
pub fn move_to(&mut self, x: f64, y: f64) -> &mut Self
pub fn line_to(&mut self, x: f64, y: f64) -> &mut Self
pub fn curve_to( &mut self, x1: f64, y1: f64, x2: f64, y2: f64, x3: f64, y3: f64, ) -> &mut Self
pub fn rect(&mut self, x: f64, y: f64, width: f64, height: f64) -> &mut Self
pub fn circle(&mut self, cx: f64, cy: f64, radius: f64) -> &mut Self
pub fn close_path(&mut self) -> &mut Self
pub fn stroke(&mut self) -> &mut Self
pub fn fill(&mut self) -> &mut Self
pub fn fill_stroke(&mut self) -> &mut Self
Sourcepub fn paint_shading(&mut self, name: impl Into<String>) -> &mut Self
pub fn paint_shading(&mut self, name: impl Into<String>) -> &mut Self
Paint a registered shading into the current clip region with the
sh operator (ISO 32000-1 §8.7.4.2, issue #297).
name must match a shading registered on the page via
[Page::add_shading]; the writer emits it under
/Resources/Shading/<name>. sh fills the current clip (the whole
page if unclipped), so callers typically wrap it in q … W n … Q
with a clip path to bound the gradient.
pub fn set_stroke_color(&mut self, color: Color) -> &mut Self
pub fn set_fill_color(&mut self, color: Color) -> &mut Self
Sourcepub fn set_fill_color_icc(
&mut self,
name: impl Into<String>,
components: Vec<f64>,
) -> &mut Self
pub fn set_fill_color_icc( &mut self, name: impl Into<String>, components: Vec<f64>, ) -> &mut Self
Set fill color using an ICC-based color space already registered on the
page under /Resources/ColorSpace/<name> (see crate::page::Page::add_color_space).
components are the raw color values for the profile’s channel count
(1=Gray, 3=RGB/Lab, 4=CMYK).
ICC profiles are named dynamically by IccProfileManager, so the
resource name is supplied by the caller rather than hardcoded.
components must be non-empty: an empty list would emit a bare sc
operator with no operands, invalid per ISO 32000-1 §8.6.8.
Sourcepub fn set_stroke_color_icc(
&mut self,
name: impl Into<String>,
components: Vec<f64>,
) -> &mut Self
pub fn set_stroke_color_icc( &mut self, name: impl Into<String>, components: Vec<f64>, ) -> &mut Self
Set stroke color using an ICC-based color space already registered on
the page under /Resources/ColorSpace/<name> (see
crate::page::Page::add_color_space). See Self::set_fill_color_icc.
components must be non-empty (see Self::set_fill_color_icc).
Sourcepub fn set_fill_color_calibrated_named(
&mut self,
name: impl Into<String>,
color: CalibratedColor,
) -> &mut Self
pub fn set_fill_color_calibrated_named( &mut self, name: impl Into<String>, color: CalibratedColor, ) -> &mut Self
Set fill color using a calibrated color space registered under a
caller-supplied resource name (/Resources/ColorSpace/<name>).
Unlike Self::set_fill_color_calibrated, which always references the
single default CalGray1/CalRGB1 slot, this accepts the name of any
registered calibrated space — removing the one-calibrated-space-per-page
limitation.
Sourcepub fn set_stroke_color_calibrated_named(
&mut self,
name: impl Into<String>,
color: CalibratedColor,
) -> &mut Self
pub fn set_stroke_color_calibrated_named( &mut self, name: impl Into<String>, color: CalibratedColor, ) -> &mut Self
Set stroke color using a calibrated color space registered under a
caller-supplied resource name. See Self::set_fill_color_calibrated_named.
Sourcepub fn set_fill_color_lab_named(
&mut self,
name: impl Into<String>,
color: LabColor,
) -> &mut Self
pub fn set_fill_color_lab_named( &mut self, name: impl Into<String>, color: LabColor, ) -> &mut Self
Set fill color using a Lab color space registered under a
caller-supplied resource name (/Resources/ColorSpace/<name>).
Companion to Self::set_fill_color_lab (which references the default
Lab1 slot); accepts any registered Lab space so multiple Lab spaces
can coexist on one page.
Sourcepub fn set_stroke_color_lab_named(
&mut self,
name: impl Into<String>,
color: LabColor,
) -> &mut Self
pub fn set_stroke_color_lab_named( &mut self, name: impl Into<String>, color: LabColor, ) -> &mut Self
Set stroke color using a Lab color space registered under a
caller-supplied resource name. See Self::set_fill_color_lab_named.
Sourcepub fn set_fill_color_calibrated(&mut self, color: CalibratedColor) -> &mut Self
pub fn set_fill_color_calibrated(&mut self, color: CalibratedColor) -> &mut Self
Set fill color using calibrated color space, referencing the default
CalGray1/CalRGB1 resource slot.
Delegates to Self::set_fill_color_calibrated_named with the default
name; behaviour is unchanged for existing callers.
Sourcepub fn set_stroke_color_calibrated(
&mut self,
color: CalibratedColor,
) -> &mut Self
pub fn set_stroke_color_calibrated( &mut self, color: CalibratedColor, ) -> &mut Self
Set stroke color using calibrated color space, referencing the default
CalGray1/CalRGB1 resource slot.
Delegates to Self::set_stroke_color_calibrated_named with the
default name; behaviour is unchanged for existing callers.
Sourcepub fn set_fill_color_lab(&mut self, color: LabColor) -> &mut Self
pub fn set_fill_color_lab(&mut self, color: LabColor) -> &mut Self
Set fill color using Lab color space, referencing the default Lab1
resource slot.
Delegates to Self::set_fill_color_lab_named with the default name;
behaviour is unchanged for existing callers.
Sourcepub fn set_stroke_color_lab(&mut self, color: LabColor) -> &mut Self
pub fn set_stroke_color_lab(&mut self, color: LabColor) -> &mut Self
Set stroke color using Lab color space, referencing the default Lab1
resource slot.
Delegates to Self::set_stroke_color_lab_named with the default name;
behaviour is unchanged for existing callers.
pub fn set_line_width(&mut self, width: f64) -> &mut Self
pub fn set_line_cap(&mut self, cap: LineCap) -> &mut Self
pub fn set_line_join(&mut self, join: LineJoin) -> &mut Self
Sourcepub fn set_opacity(&mut self, opacity: f64) -> &mut Self
pub fn set_opacity(&mut self, opacity: f64) -> &mut Self
Set the opacity for both fill and stroke operations (0.0 to 1.0)
Sourcepub fn set_fill_opacity(&mut self, opacity: f64) -> &mut Self
pub fn set_fill_opacity(&mut self, opacity: f64) -> &mut Self
Set the fill opacity (0.0 to 1.0)
Sourcepub fn set_stroke_opacity(&mut self, opacity: f64) -> &mut Self
pub fn set_stroke_opacity(&mut self, opacity: f64) -> &mut Self
Set the stroke opacity (0.0 to 1.0)
pub fn save_state(&mut self) -> &mut Self
pub fn restore_state(&mut self) -> &mut Self
Sourcepub fn begin_transparency_group(
&mut self,
group: TransparencyGroup,
) -> &mut Self
pub fn begin_transparency_group( &mut self, group: TransparencyGroup, ) -> &mut Self
Begin a transparency group ISO 32000-1:2008 Section 11.4
Sourcepub fn end_transparency_group(&mut self) -> &mut Self
pub fn end_transparency_group(&mut self) -> &mut Self
End a transparency group
Sourcepub fn in_transparency_group(&self) -> bool
pub fn in_transparency_group(&self) -> bool
Check if we’re currently inside a transparency group
Sourcepub fn current_transparency_group(&self) -> Option<&TransparencyGroup>
pub fn current_transparency_group(&self) -> Option<&TransparencyGroup>
Get the current transparency group (if any)
pub fn translate(&mut self, tx: f64, ty: f64) -> &mut Self
pub fn scale(&mut self, sx: f64, sy: f64) -> &mut Self
pub fn rotate(&mut self, angle: f64) -> &mut Self
pub fn transform( &mut self, a: f64, b: f64, c: f64, d: f64, e: f64, f: f64, ) -> &mut Self
pub fn rectangle( &mut self, x: f64, y: f64, width: f64, height: f64, ) -> &mut Self
pub fn draw_image( &mut self, image_name: impl Into<String>, x: f64, y: f64, width: f64, height: f64, ) -> &mut Self
Sourcepub fn draw_image_with_transparency(
&mut self,
image_name: impl Into<String>,
x: f64,
y: f64,
width: f64,
height: f64,
mask_name: Option<&str>,
) -> &mut Self
pub fn draw_image_with_transparency( &mut self, image_name: impl Into<String>, x: f64, y: f64, width: f64, height: f64, mask_name: Option<&str>, ) -> &mut Self
Draw an image with transparency support (soft mask) This method handles images with alpha channels or soft masks
Sourcepub fn uses_transparency(&self) -> bool
pub fn uses_transparency(&self) -> bool
Check if transparency is used (opacity != 1.0)
Sourcepub fn generate_graphics_state_dict(&self) -> Option<String>
pub fn generate_graphics_state_dict(&self) -> Option<String>
Generate the graphics state dictionary for transparency
Sourcepub fn fill_color(&self) -> Color
pub fn fill_color(&self) -> Color
Get the current fill color
Sourcepub fn stroke_color(&self) -> Color
pub fn stroke_color(&self) -> Color
Get the current stroke color
Sourcepub fn line_width(&self) -> f64
pub fn line_width(&self) -> f64
Get the current line width
Sourcepub fn fill_opacity(&self) -> f64
pub fn fill_opacity(&self) -> f64
Get the current fill opacity
Sourcepub fn stroke_opacity(&self) -> f64
pub fn stroke_opacity(&self) -> f64
Get the current stroke opacity
Sourcepub fn operations(&self) -> String
pub fn operations(&self) -> String
Get the operations as a serialised PDF content-stream String.
Pre-2.7.0 this returned &str. The IR migration replaced the
internal String buffer with a typed Vec<Op>, so the legacy
borrow is materialised on demand. Internal callers prefer
generate_operations() which returns the byte buffer directly.
Sourcepub fn get_operations(&self) -> String
pub fn get_operations(&self) -> String
Get the operations as a serialised content-stream String (alias
retained for legacy tests; mirrors operations()).
Sourcepub fn begin_text(&mut self) -> &mut Self
pub fn begin_text(&mut self) -> &mut Self
Begin a text object
Sourcepub fn set_text_position(&mut self, x: f64, y: f64) -> &mut Self
pub fn set_text_position(&mut self, x: f64, y: f64) -> &mut Self
Set text position
Sourcepub fn show_text(&mut self, text: &str) -> Result<&mut Self>
pub fn show_text(&mut self, text: &str) -> Result<&mut Self>
Show text
For custom (Type0/CID) fonts, text is encoded as Unicode code points (CIDs). BMP characters (U+0000..U+FFFF) are written as 4-hex-digit values. Supplementary plane characters (U+10000..U+10FFFF) use UTF-16BE surrogate pairs. For standard fonts, text is encoded as literal PDF strings.
Sourcepub fn set_word_spacing(&mut self, spacing: f64) -> &mut Self
pub fn set_word_spacing(&mut self, spacing: f64) -> &mut Self
Set word spacing for text justification
Sourcepub fn set_character_spacing(&mut self, spacing: f64) -> &mut Self
pub fn set_character_spacing(&mut self, spacing: f64) -> &mut Self
Set character spacing
Sourcepub fn show_justified_text(
&mut self,
text: &str,
target_width: f64,
) -> Result<&mut Self>
pub fn show_justified_text( &mut self, text: &str, target_width: f64, ) -> Result<&mut Self>
Show justified text with automatic word spacing calculation
Sourcepub fn render_table(&mut self, table: &Table) -> Result<()>
pub fn render_table(&mut self, table: &Table) -> Result<()>
Render a table
Sourcepub fn render_list(&mut self, list: &ListElement) -> Result<()>
pub fn render_list(&mut self, list: &ListElement) -> Result<()>
Render a list
Sourcepub fn render_column_layout(
&mut self,
layout: &ColumnLayout,
content: &ColumnContent,
x: f64,
y: f64,
height: f64,
) -> Result<()>
pub fn render_column_layout( &mut self, layout: &ColumnLayout, content: &ColumnContent, x: f64, y: f64, height: f64, ) -> Result<()>
Render column layout
Sourcepub fn set_line_dash_pattern(&mut self, pattern: LineDashPattern) -> &mut Self
pub fn set_line_dash_pattern(&mut self, pattern: LineDashPattern) -> &mut Self
Set line dash pattern
Sourcepub fn set_line_solid(&mut self) -> &mut Self
pub fn set_line_solid(&mut self) -> &mut Self
Set line dash pattern to solid (no dashes)
Sourcepub fn set_miter_limit(&mut self, limit: f64) -> &mut Self
pub fn set_miter_limit(&mut self, limit: f64) -> &mut Self
Set miter limit
Sourcepub fn set_rendering_intent(&mut self, intent: RenderingIntent) -> &mut Self
pub fn set_rendering_intent(&mut self, intent: RenderingIntent) -> &mut Self
Set rendering intent
Sourcepub fn set_flatness(&mut self, flatness: f64) -> &mut Self
pub fn set_flatness(&mut self, flatness: f64) -> &mut Self
Set flatness tolerance
Sourcepub fn apply_extgstate(&mut self, state: ExtGState) -> Result<&mut Self>
pub fn apply_extgstate(&mut self, state: ExtGState) -> Result<&mut Self>
Apply an ExtGState dictionary immediately
Sourcepub fn with_extgstate<F>(&mut self, builder: F) -> Result<&mut Self>
pub fn with_extgstate<F>(&mut self, builder: F) -> Result<&mut Self>
Create and apply a custom ExtGState
Sourcepub fn set_blend_mode(&mut self, mode: BlendMode) -> Result<&mut Self>
pub fn set_blend_mode(&mut self, mode: BlendMode) -> Result<&mut Self>
Set blend mode for transparency
Sourcepub fn set_alpha(&mut self, alpha: f64) -> Result<&mut Self>
pub fn set_alpha(&mut self, alpha: f64) -> Result<&mut Self>
Set alpha for both stroke and fill operations
Sourcepub fn set_alpha_stroke(&mut self, alpha: f64) -> Result<&mut Self>
pub fn set_alpha_stroke(&mut self, alpha: f64) -> Result<&mut Self>
Set alpha for stroke operations only
Sourcepub fn set_alpha_fill(&mut self, alpha: f64) -> Result<&mut Self>
pub fn set_alpha_fill(&mut self, alpha: f64) -> Result<&mut Self>
Set alpha for fill operations only
Sourcepub fn set_overprint_stroke(&mut self, overprint: bool) -> Result<&mut Self>
pub fn set_overprint_stroke(&mut self, overprint: bool) -> Result<&mut Self>
Set overprint for stroke operations
Sourcepub fn set_overprint_fill(&mut self, overprint: bool) -> Result<&mut Self>
pub fn set_overprint_fill(&mut self, overprint: bool) -> Result<&mut Self>
Set overprint for fill operations
Sourcepub fn set_stroke_adjustment(&mut self, adjustment: bool) -> Result<&mut Self>
pub fn set_stroke_adjustment(&mut self, adjustment: bool) -> Result<&mut Self>
Set stroke adjustment
Sourcepub fn set_smoothness(&mut self, smoothness: f64) -> Result<&mut Self>
pub fn set_smoothness(&mut self, smoothness: f64) -> Result<&mut Self>
Set smoothness tolerance
Sourcepub fn line_dash_pattern(&self) -> Option<&LineDashPattern>
pub fn line_dash_pattern(&self) -> Option<&LineDashPattern>
Get current line dash pattern
Sourcepub fn miter_limit(&self) -> f64
pub fn miter_limit(&self) -> f64
Get current miter limit
Sourcepub fn rendering_intent(&self) -> RenderingIntent
pub fn rendering_intent(&self) -> RenderingIntent
Get current rendering intent
Sourcepub fn smoothness(&self) -> f64
pub fn smoothness(&self) -> f64
Get current smoothness tolerance
Sourcepub fn extgstate_manager(&self) -> &ExtGStateManager
pub fn extgstate_manager(&self) -> &ExtGStateManager
Get the ExtGState manager (for advanced usage)
Sourcepub fn extgstate_manager_mut(&mut self) -> &mut ExtGStateManager
pub fn extgstate_manager_mut(&mut self) -> &mut ExtGStateManager
Get mutable ExtGState manager (for advanced usage)
Sourcepub fn generate_extgstate_resources(&self) -> Result<String>
pub fn generate_extgstate_resources(&self) -> Result<String>
Generate ExtGState resource dictionary for PDF
Sourcepub fn has_extgstates(&self) -> bool
pub fn has_extgstates(&self) -> bool
Check if any extended graphics states are defined
Sourcepub fn add_command(&mut self, command: &str)
pub fn add_command(&mut self, command: &str)
Add a command to the operations.
Untyped escape hatch — bytes are emitted verbatim with a trailing
newline. Used by callers that need to inject operators not yet
modelled as Op variants. New code should prefer the typed
methods on GraphicsContext.
Sourcepub fn clip(&mut self) -> &mut Self
pub fn clip(&mut self) -> &mut Self
Create clipping path from current path using non-zero winding rule
Sourcepub fn end_path(&mut self) -> &mut Self
pub fn end_path(&mut self) -> &mut Self
End the current path without filling or stroking (n).
Required to terminate a clipping path: the canonical sequence is
<path> W n (ISO 32000-1 §8.5.4). Use after clip
before painting a shading into the clipped region.
Sourcepub fn clip_even_odd(&mut self) -> &mut Self
pub fn clip_even_odd(&mut self) -> &mut Self
Create clipping path from current path using even-odd rule
Sourcepub fn clip_stroke(&mut self) -> &mut Self
pub fn clip_stroke(&mut self) -> &mut Self
Create clipping path and stroke it
Sourcepub fn set_clipping_path(&mut self, path: ClippingPath) -> Result<&mut Self>
pub fn set_clipping_path(&mut self, path: ClippingPath) -> Result<&mut Self>
Set a custom clipping path
Sourcepub fn clear_clipping(&mut self) -> &mut Self
pub fn clear_clipping(&mut self) -> &mut Self
Clear the current clipping path
Sourcepub fn clip_rect(
&mut self,
x: f64,
y: f64,
width: f64,
height: f64,
) -> Result<&mut Self>
pub fn clip_rect( &mut self, x: f64, y: f64, width: f64, height: f64, ) -> Result<&mut Self>
Create a rectangular clipping region
Sourcepub fn clip_circle(
&mut self,
cx: f64,
cy: f64,
radius: f64,
) -> Result<&mut Self>
pub fn clip_circle( &mut self, cx: f64, cy: f64, radius: f64, ) -> Result<&mut Self>
Create a circular clipping region
Sourcepub fn clip_ellipse(
&mut self,
cx: f64,
cy: f64,
rx: f64,
ry: f64,
) -> Result<&mut Self>
pub fn clip_ellipse( &mut self, cx: f64, cy: f64, rx: f64, ry: f64, ) -> Result<&mut Self>
Create an elliptical clipping region
Sourcepub fn has_clipping(&self) -> bool
pub fn has_clipping(&self) -> bool
Check if a clipping path is active
Sourcepub fn clipping_path(&self) -> Option<&ClippingPath>
pub fn clipping_path(&self) -> Option<&ClippingPath>
Get the current clipping path
Sourcepub fn set_font_manager(&mut self, font_manager: Arc<FontManager>) -> &mut Self
pub fn set_font_manager(&mut self, font_manager: Arc<FontManager>) -> &mut Self
Set the font manager for custom fonts
Sourcepub fn set_custom_font(&mut self, font_name: &str, size: f64) -> &mut Self
pub fn set_custom_font(&mut self, font_name: &str, size: f64) -> &mut Self
Set the current font to a custom font
Sourcepub fn set_glyph_mapping(&mut self, mapping: HashMap<u32, u16>) -> &mut Self
pub fn set_glyph_mapping(&mut self, mapping: HashMap<u32, u16>) -> &mut Self
Set the glyph mapping for Unicode fonts (Unicode -> GlyphID)
Sourcepub fn draw_text(&mut self, text: &str, x: f64, y: f64) -> Result<&mut Self>
pub fn draw_text(&mut self, text: &str, x: f64, y: f64) -> Result<&mut Self>
Draw text at the specified position with automatic encoding detection
Sourcepub fn draw_text_hex(&mut self, text: &str, x: f64, y: f64) -> Result<&mut Self>
👎Deprecated: Use draw_text() which automatically detects encoding
pub fn draw_text_hex(&mut self, text: &str, x: f64, y: f64) -> Result<&mut Self>
Use draw_text() which automatically detects encoding
Legacy: Draw text with hex encoding (kept for compatibility)
Trait Implementations§
Source§impl Clone for GraphicsContext
impl Clone for GraphicsContext
Source§fn clone(&self) -> GraphicsContext
fn clone(&self) -> GraphicsContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more