mirror of
https://github.com/typst/typst
synced 2025-06-08 13:16:24 +08:00
More improvements to conic gradients
This commit is contained in:
parent
9ae7a1520b
commit
e532d9c870
@ -307,6 +307,20 @@ impl Transform {
|
|||||||
Self { sx, sy, ..Self::identity() }
|
Self { sx, sy, ..Self::identity() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A scale transform at a specific position.
|
||||||
|
pub fn scale_at(sx: Ratio, sy: Ratio, px: Abs, py: Abs) -> Self {
|
||||||
|
Self::translate(px, py)
|
||||||
|
.pre_concat(Self::scale(sx, sy))
|
||||||
|
.pre_concat(Self::translate(-px, -py))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A rotate transform at a specific position.
|
||||||
|
pub fn rotate_at(angle: Angle, px: Abs, py: Abs) -> Self {
|
||||||
|
Self::translate(px, py)
|
||||||
|
.pre_concat(Self::rotate(angle))
|
||||||
|
.pre_concat(Self::translate(-px, -py))
|
||||||
|
}
|
||||||
|
|
||||||
/// A rotate transform.
|
/// A rotate transform.
|
||||||
pub fn rotate(angle: Angle) -> Self {
|
pub fn rotate(angle: Angle) -> Self {
|
||||||
let cos = Ratio::new(angle.cos());
|
let cos = Ratio::new(angle.cos());
|
||||||
|
@ -211,15 +211,11 @@ fn convert_gradient(
|
|||||||
|
|
||||||
let pdf_gradient = PdfGradient {
|
let pdf_gradient = PdfGradient {
|
||||||
aspect_ratio: size.aspect_ratio(),
|
aspect_ratio: size.aspect_ratio(),
|
||||||
transform,
|
transform: Transform::identity(),
|
||||||
gradient: gradient.clone(),
|
gradient: gradient.clone(),
|
||||||
angle: Gradient::correct_aspect_ratio(rotation, size.aspect_ratio()),
|
angle: Gradient::correct_aspect_ratio(rotation, size.aspect_ratio()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let actual_transform = transforms.transform.invert().unwrap().pre_concat(transform)
|
|
||||||
.pre_concat(Transform::scale(-Ratio::one(), Ratio::one()))
|
|
||||||
.pre_concat(Transform::rotate(-pdf_gradient.angle));
|
|
||||||
|
|
||||||
match &gradient {
|
match &gradient {
|
||||||
Gradient::Linear(_) => {
|
Gradient::Linear(_) => {
|
||||||
(krilla::color::rgb::Color::black().into(), 255)
|
(krilla::color::rgb::Color::black().into(), 255)
|
||||||
@ -229,7 +225,11 @@ fn convert_gradient(
|
|||||||
}
|
}
|
||||||
Gradient::Conic(conic) => {
|
Gradient::Conic(conic) => {
|
||||||
// Correct the gradient's angle
|
// Correct the gradient's angle
|
||||||
let angle = Gradient::correct_aspect_ratio(conic.angle, pdf_gradient.aspect_ratio);
|
let cx = size.x.to_f32() * conic.center.x.get() as f32;
|
||||||
|
let cy = size.y.to_f32() * conic.center.y.get() as f32;
|
||||||
|
let actual_transform = transforms.transform.invert().unwrap().pre_concat(transform)
|
||||||
|
.pre_concat(Transform::scale_at(-Ratio::one(), Ratio::one(), Abs::pt(cx as f64), Abs::pt(cy as f64)))
|
||||||
|
.pre_concat(Transform::rotate_at(-pdf_gradient.angle, Abs::pt(cx as f64), Abs::pt(cy as f64)));
|
||||||
let mut stops: Vec<krilla::paint::Stop<krilla::color::rgb::Color>> = vec![];
|
let mut stops: Vec<krilla::paint::Stop<krilla::color::rgb::Color>> = vec![];
|
||||||
|
|
||||||
let mut add_single = |color: &Color, offset: Ratio| {
|
let mut add_single = |color: &Color, offset: Ratio| {
|
||||||
@ -296,8 +296,8 @@ fn convert_gradient(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let sweep = krilla::paint::SweepGradient {
|
let sweep = krilla::paint::SweepGradient {
|
||||||
cx: size.x.to_f32() * conic.center.x.get() as f32,
|
cx,
|
||||||
cy: size.y.to_f32() * conic.center.y.get() as f32,
|
cy,
|
||||||
start_angle: 0.0,
|
start_angle: 0.0,
|
||||||
end_angle: 360.0,
|
end_angle: 360.0,
|
||||||
transform: actual_transform.as_krilla(),
|
transform: actual_transform.as_krilla(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user