pub struct FilterContext {
    stroke_paint: Rc<UserSpacePaintSource>,
    fill_paint: Rc<UserSpacePaintSource>,
    source_surface: SharedImageSurface,
    last_result: Option<FilterOutput>,
    previous_results: HashMap<CustomIdent, FilterOutput>,
    background_surface: OnceCell<Result<SharedImageSurface, FilterError>>,
    stroke_paint_surface: OnceCell<Result<SharedImageSurface, FilterError>>,
    fill_paint_surface: OnceCell<Result<SharedImageSurface, FilterError>>,
    primitive_units: CoordUnits,
    effects_region: Rect,
    _affine: Transform,
    paffine: Transform,
}
Expand description

The filter rendering context.

Fields§

§stroke_paint: Rc<UserSpacePaintSource>

Paint source for primitives which have an input value equal to StrokePaint.

§fill_paint: Rc<UserSpacePaintSource>

Paint source for primitives which have an input value equal to FillPaint.

§source_surface: SharedImageSurface

The source graphic surface.

§last_result: Option<FilterOutput>

Output of the last filter primitive.

§previous_results: HashMap<CustomIdent, FilterOutput>

Surfaces of the previous filter primitives by name.

§background_surface: OnceCell<Result<SharedImageSurface, FilterError>>

Input surface for primitives that require an input of BackgroundImage or BackgroundAlpha. Computed lazily.

§stroke_paint_surface: OnceCell<Result<SharedImageSurface, FilterError>>§fill_paint_surface: OnceCell<Result<SharedImageSurface, FilterError>>§primitive_units: CoordUnits

Primtive units

§effects_region: Rect

The filter effects region.

§_affine: Transform

The filter element affine matrix.

If filterUnits == userSpaceOnUse, equal to the drawing context matrix, so, for example, if the target node is in a group with transform="translate(30, 20)", this will be equal to a matrix that translates to 30, 20 (and does not scale). Note that the target node bounding box isn’t included in the computations in this case.

If filterUnits == objectBoundingBox, equal to the target node bounding box matrix multiplied by the drawing context matrix, so, for example, if the target node is in a group with transform="translate(30, 20)" and also has x="1", y="1", width="50", height="50", this will be equal to a matrix that translates to 31, 21 and scales to 50, 50.

This is to be used in conjunction with setting the viewbox size to account for the scaling. For filterUnits == userSpaceOnUse, the viewbox will have the actual resolution size, and for filterUnits == objectBoundingBox, the viewbox will have the size of 1, 1.

§paffine: Transform

The filter primitive affine matrix.

See the comments for _affine, they largely apply here.

Implementations§

source§

impl FilterContext

source

pub fn new( filter: &UserSpaceFilter, stroke_paint: Rc<UserSpacePaintSource>, fill_paint: Rc<UserSpacePaintSource>, source_surface: &SharedImageSurface, draw_transform: Transform, node_bbox: BoundingBox ) -> Result<Self, FilterError>

Creates a new FilterContext.

source

pub fn source_graphic(&self) -> &SharedImageSurface

Returns the surface corresponding to the source graphic.

source

fn background_image( &self, draw_ctx: &DrawingCtx ) -> Result<SharedImageSurface, FilterError>

Returns the surface corresponding to the background image snapshot.

source

fn stroke_paint_image( &self, acquired_nodes: &mut AcquiredNodes<'_>, draw_ctx: &mut DrawingCtx ) -> Result<SharedImageSurface, FilterError>

Returns a surface filled with the current stroke’s paint, for StrokePaint inputs in primitives.

Filter Effects 1: https://www.w3.org/TR/filter-effects/#attr-valuedef-in-strokepaint

source

fn fill_paint_image( &self, acquired_nodes: &mut AcquiredNodes<'_>, draw_ctx: &mut DrawingCtx ) -> Result<SharedImageSurface, FilterError>

Returns a surface filled with the current fill’s paint, for FillPaint inputs in primitives.

Filter Effects 1: https://www.w3.org/TR/filter-effects/#attr-valuedef-in-fillpaint

source

pub fn into_output(self) -> Result<SharedImageSurface, Error>

Converts this FilterContext into the surface corresponding to the output of the filter chain.

The returned surface is in the sRGB color space.

source

pub fn store_result(&mut self, result: FilterResult)

Stores a filter primitive result into the context.

source

pub fn paffine(&self) -> Transform

Returns the paffine matrix.

source

pub fn primitive_units(&self) -> CoordUnits

Returns the primitive units.

source

pub fn effects_region(&self) -> Rect

Returns the filter effects region.

source

fn get_unspecified_input(&self) -> FilterInput

Get a filter primitive’s default input as if its in=\"...\" were not specified.

Per https://drafts.fxtf.org/filter-effects/#element-attrdef-filter-primitive-in, “References to non-existent results will be treated as if no result was specified”. That is, fall back to the last result in the filter chain, or if this is the first in the chain, just use SourceGraphic.

source

fn get_input_raw( &self, acquired_nodes: &mut AcquiredNodes<'_>, draw_ctx: &mut DrawingCtx, in_: &Input ) -> Result<FilterInput, FilterError>

Retrieves the filter input surface according to the SVG rules.

source

pub fn get_input( &self, acquired_nodes: &mut AcquiredNodes<'_>, draw_ctx: &mut DrawingCtx, in_: &Input, color_interpolation_filters: ColorInterpolationFilters ) -> Result<FilterInput, FilterError>

Retrieves the filter input surface according to the SVG rules.

The surface will be converted to the color space specified by color_interpolation_filters.

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> 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.