PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
Merge PR #3246: Shading patterns use the stroke or fill alpha current at paint time (#3176)
aiongg61cbaf3e23dc
diff --cc vendor/hayro-interpret/src/pattern.rsindex 1b3e046c4,054a88e0d..04750f376--- a/vendor/hayro-interpret/src/pattern.rs+++ b/vendor/hayro-interpret/src/pattern.rs@@@ -46,8 -43,6 +46,7 @@@ impl<'a> Pattern<'a>Object::Dict(dict) => Some(Self::Shading(ShadingPattern::new(&dict,&ctx.interpreter_cache.object_cache,- ctx.get().graphics_state.non_stroke_alpha,+ defaults,)?)),Object::Stream(stream) => Some(Self::Tiling(Box::new(TilingPattern::new(stream, ctx, resources,@@@ -67,20 -62,14 +66,28 @@@}}+ /// PdfCraft patch (46): the pattern without the fill or stroke opacity it captured when it was+ /// set (`scn`). A stencil mask's transparency group applies the opacity in force when the mask+ /// is drawn, so a pattern paint carrying it too drew the mask at the opacity squared (#2975).+ pub(crate) fn without_opacity(mut self) -> Self {+ match &mut self {+ Self::Shading(p) => p.opacity = 1.0,+ Self::Tiling(p) => {+ p.non_stroking_paint = p.non_stroking_paint.clone().opaque();+ p.stroke_paint = p.stroke_paint.clone().opaque();+ }+ }+ self+ }++ /// PdfCraft patch: set the alpha of the graphics state in effect when the pattern is painted. The `gs` operator+ /// can come after `scn`/`SCN`, so the alpha must not be captured when the pattern is selected.+ pub(crate) fn set_alpha(&mut self, alpha: f32) {+ if let Self::Shading(p) = self {+ p.opacity = alpha;+ }+ }+pub(crate) fn set_transfer_function(&mut self, tf: ActiveTransferFunction) {if let Self::Shading(p) = self {p.transfer_function = Some(tf);@@@ -111,12 -100,7 +118,11 @@@ pub struct ShadingPattern}impl ShadingPattern {- pub(crate) fn new(dict: &Dict<'_>, cache: &Cache) -> Option<Self> {+ pub(crate) fn new(+ dict: &Dict<'_>,+ cache: &Cache,- opacity: f32,+ defaults: &DefaultColorSpaces<'_, '_>,+ ) -> Option<Self> {let shading = dict.get::<Object<'_>>(SHADING).and_then(|o| {let (dict, stream) = dict_or_stream(&o)?;