Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slightly clean up the final URL creation in canvas.toDataURL #21850

Merged
merged 7 commits into from Oct 3, 2018

Clean up ToAzurePattern for FillOrStrokeStyle

  • Loading branch information
nox committed Oct 2, 2018
commit 426067069c5dbd20340c41e78f3e78d955e59bc2
@@ -901,9 +901,9 @@ pub trait ToAzurePattern {

impl ToAzurePattern for FillOrStrokeStyle {
fn to_azure_pattern(&self, drawtarget: &DrawTarget) -> Option<Pattern> {
match *self {
Some(match *self {
FillOrStrokeStyle::Color(ref color) => {
Some(Pattern::Color(ColorPattern::new(color.to_azure_style())))
Pattern::Color(ColorPattern::new(color.to_azure_style()))
},
FillOrStrokeStyle::LinearGradient(ref linear_gradient_style) => {
let gradient_stops: Vec<GradientStop> = linear_gradient_style.stops.iter().map(|s| {
@@ -913,11 +913,12 @@ impl ToAzurePattern for FillOrStrokeStyle {
}
}).collect();

Some(Pattern::LinearGradient(LinearGradientPattern::new(
Pattern::LinearGradient(LinearGradientPattern::new(
&Point2D::new(linear_gradient_style.x0 as AzFloat, linear_gradient_style.y0 as AzFloat),
&Point2D::new(linear_gradient_style.x1 as AzFloat, linear_gradient_style.y1 as AzFloat),
drawtarget.create_gradient_stops(&gradient_stops, ExtendMode::Clamp),
&Transform2D::identity())))
&Transform2D::identity(),
))
},
FillOrStrokeStyle::RadialGradient(ref radial_gradient_style) => {
let gradient_stops: Vec<GradientStop> = radial_gradient_style.stops.iter().map(|s| {
@@ -927,27 +928,29 @@ impl ToAzurePattern for FillOrStrokeStyle {
}
}).collect();

Some(Pattern::RadialGradient(RadialGradientPattern::new(
Pattern::RadialGradient(RadialGradientPattern::new(
&Point2D::new(radial_gradient_style.x0 as AzFloat, radial_gradient_style.y0 as AzFloat),
&Point2D::new(radial_gradient_style.x1 as AzFloat, radial_gradient_style.y1 as AzFloat),
radial_gradient_style.r0 as AzFloat, radial_gradient_style.r1 as AzFloat,
drawtarget.create_gradient_stops(&gradient_stops, ExtendMode::Clamp),
&Transform2D::identity())))
&Transform2D::identity(),
))
},
FillOrStrokeStyle::Surface(ref surface_style) => {
drawtarget.create_source_surface_from_data(&surface_style.surface_data,
surface_style.surface_size,
surface_style.surface_size.width * 4,
SurfaceFormat::B8G8R8A8)
.map(|source_surface| {
Pattern::Surface(SurfacePattern::new(
source_surface.azure_source_surface,
surface_style.repeat_x,
surface_style.repeat_y,
&Transform2D::identity()))
})
let source_surface = drawtarget.create_source_surface_from_data(
&surface_style.surface_data,
surface_style.surface_size,
surface_style.surface_size.width * 4,
SurfaceFormat::B8G8R8A8,
)?;
Pattern::Surface(SurfacePattern::new(
source_surface.azure_source_surface,
surface_style.repeat_x,
surface_style.repeat_y,
&Transform2D::identity(),
))
}
}
})
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.