Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/pdf-canvas/src/canvas_graphics_state_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ impl<B: CanvasBackend> GraphicsStateOps for PdfCanvas<'_, B> {
.map(|resources| resources.get())
.transpose()?,
None,
None,
)?;

let transform = self.current_state()?.transform;
Expand Down
22 changes: 20 additions & 2 deletions crates/pdf-canvas/src/pdf_canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ impl<'a, B: CanvasBackend> PdfCanvas<'a, B> {
/// - `bbox`: The content-space bounding box that sizes the recording surface.
/// - `resources`: Optional resource dictionary for resolving fonts, patterns, etc.
/// - `filter`: Optional filter function to skip certain operations.
/// - `cell_color`: Optional initial fill and stroke color, used by uncolored tiling
/// patterns whose cell is painted in the color selected with the pattern.
///
/// # Errors
///
Expand All @@ -193,14 +195,20 @@ impl<'a, B: CanvasBackend> PdfCanvas<'a, B> {
bbox: &Rect,
resources: Option<Arc<Resources>>,
filter: Option<&mut (dyn FnMut(&PdfOperatorVariant) -> bool + '_)>,
cell_color: Option<Color>,
) -> Result<RecordingCanvas, PdfCanvasError> {
let mut recording_canvas = RecordingCanvas::new(bbox.width(), bbox.height());
let canvas_stack = vec![CanvasState {
let mut initial_state = CanvasState {
transform: Transform::identity(),
pattern_parent_transform: Transform::identity(),
text_state: TextState::default(),
..Default::default()
}];
};
if let Some(color) = cell_color {
initial_state.paint.set_fill_color(color);
initial_state.paint.set_stroke_color(color);
}
let canvas_stack = vec![initial_state];

let mut other = PdfCanvas::<RecordingCanvas> {
current_path: None,
Expand Down Expand Up @@ -403,13 +411,23 @@ impl<'a, B: CanvasBackend> PdfCanvas<'a, B> {
PaintType::Uncolored => Some(&mut uncolored_filter),
};

// The cell of an uncolored pattern is painted in the color selected
// together with the pattern.
let paint = &self.current_state()?.paint;
let cell_color = match paint_type {
PaintType::Colored => None,
PaintType::Uncolored if for_stroke => Some(paint.stroke_color),
PaintType::Uncolored => Some(paint.fill_color),
};

// Render the tiling content into a temporary canvas.
let recording_canvas = self.record_content_stream(
content_stream,
None,
&bbox,
Some(resources.get()?),
filter,
cell_color,
)?;

let step = [*x_step, *y_step];
Expand Down
Loading