pub struct DrawTarget<Backing = Vec<u32>> { /* private fields */ }
Expand description
The main type used for drawing
Implementations§
Source§impl DrawTarget
impl DrawTarget
Sourcepub fn new(width: i32, height: i32) -> DrawTarget
pub fn new(width: i32, height: i32) -> DrawTarget
Examples found in repository?
3fn main() {
4 let mut dt = DrawTarget::new(400, 400);
5
6 let mut pb = PathBuilder::new();
7 pb.move_to(200., 200.);
8 pb.line_to(300., 300.);
9 pb.line_to(200., 300.);
10
11 let path = pb.finish();
12 dt.stroke(
13 &path,
14 &Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
15 &StrokeStyle {
16 width: 100000., // <--
17 ..StrokeStyle::default()
18 },
19 &DrawOptions::new(),
20 );
21
22 dt.write_png("out.png").unwrap();
23}
More examples
4fn main() {
5 let mut dt = DrawTarget::new(400, 400);
6
7 let mut pb = PathBuilder::new();
8 pb.arc(0., 0., 20., 0., std::f32::consts::PI);
9
10 let path = pb.finish();
11 dt.set_transform(&Transform::translation(50., 50.));
12 dt.stroke(
13 &path,
14 &Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
15 &StrokeStyle {
16 width: 40., // <--
17 ..StrokeStyle::default()
18 },
19 &DrawOptions::new(),
20 );
21
22 dt.write_png("out.png").unwrap();
23}
1fn main() {
2 use raqote::*;
3
4let mut dt = DrawTarget::new(400, 400);
5
6let mut pb = PathBuilder::new();
7pb.rect(0., 0., 400., 400.);
8let path = pb.finish();
9
10let gradient = Source::new_sweep_gradient(
11 Gradient {
12 stops: vec![
13 GradientStop {
14 position: 0.,
15 color: Color::new(0xff, 0, 0, 0),
16 },
17 GradientStop {
18 position: 0.5,
19 color: Color::new(0xff, 0xff, 0xff, 0x0),
20 },
21 GradientStop {
22 position: 1.,
23 color: Color::new(0xff, 0, 0, 0x0),
24 },
25 ],
26 },
27 Point::new(150., 200.),
28 45.,
29 180.+45.,
30 Spread::Repeat,
31);
32dt.fill(&path, &gradient, &DrawOptions::new());
33
34
35
36dt.write_png("example.png");
37}
10fn main() {
11 let mut dt = DrawTarget::new(200, 200);
12
13 let gradient = Source::new_linear_gradient(
14 Gradient {
15 stops: vec![
16 GradientStop {
17 position: 0.0,
18 color: Color::new(0xff, 0xff, 0xff, 0xff),
19 },
20 GradientStop {
21 position: 0.9999,
22 color: Color::new(0xff, 0x0, 0x0, 0x0),
23 },
24 GradientStop {
25 position: 1.0,
26 color: Color::new(0xff, 0x0, 0x0, 0x0),
27 },
28 ],
29 },
30 Point::new(40., 0.),
31 Point::new(100., 0.),
32 Spread::Pad,
33 );
34
35 let mut pb = PathBuilder::new();
36 pb.rect(0., 0., 80., 80.);
37 let path = pb.finish();
38 dt.fill(&path, &gradient, &DrawOptions::default());
39
40 dt.write_png("out.png").unwrap();
41}
6fn main() {
7 let mut dt = DrawTarget::new(300, 100);
8 dt.clear(SolidSource::from_unpremultiplied_argb(
9 0xff, 0xcf, 0xcf, 0xcf,
10 ));
11
12 let font = SystemSource::new()
13 .select_best_match(
14 &[FamilyName::Title("Roboto".into())],
15 &Properties::new().weight(Weight::MEDIUM),
16 )
17 .unwrap()
18 .load()
19 .unwrap();
20 println!("{:?}", font);
21
22 //dt.set_transform(&Transform::create_translation(50.0, 0.0));
23 dt.set_transform(&Transform::rotation(euclid::Angle::degrees(15.0)));
24 let font = font_kit::loader::Loader::from_file(&mut std::fs::File::open("res/Box3.ttf").unwrap(), 0).unwrap();
25 dt.draw_text(
26 &font,
27 30.,
28 "3",
29 Point::new(0., 30.),
30 &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
31 &DrawOptions::new(),
32 );
33 dt.fill_rect(0., 35., 40., 5., &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
34 &DrawOptions::new() );
35
36 dt.write_png("out.png").unwrap();
37}
11fn main() {
12 let mut dt = DrawTarget::new(400, 400);
13
14 let mut pb = PathBuilder::new();
15 pb.move_to(340., 190.);
16 pb.arc(160., 190., 180., 0., 2. * 3.14159);
17 pb.close();
18 let path = pb.finish();
19 dt.push_clip(&path);
20
21 let mut pb = PathBuilder::new();
22 pb.move_to(0., 0.);
23 pb.line_to(200., 0.);
24 pb.line_to(200., 300.);
25 pb.line_to(0., 300.);
26 pb.close();
27 let path = pb.finish();
28 dt.fill(
29 &path,
30 &Source::Solid(SolidSource {
31 r: 0x80,
32 g: 0x80,
33 b: 0,
34 a: 0x80,
35 }),
36 &DrawOptions::new(),
37 );
38
39 let mut pb = PathBuilder::new();
40 pb.move_to(50., 50.);
41 pb.line_to(100., 70.);
42 pb.line_to(110., 150.);
43 pb.line_to(40., 180.);
44 pb.close();
45
46 /*
47 dt.move_to(100., 10.);
48 dt.quad_to(150., 40., 200., 10.);
49 dt.quad_to(120., 100., 80., 200.);
50 dt.quad_to(150., 180., 200., 200.);
51 dt.close();
52 */
53
54 pb.move_to(100., 10.);
55 pb.cubic_to(150., 40., 175., 0., 200., 10.);
56 pb.quad_to(120., 100., 80., 200.);
57 pb.quad_to(150., 180., 200., 200.);
58 pb.close();
59
60 let path = pb.finish();
61
62 let decoder = png::Decoder::new(File::open("photo.png").unwrap());
63 let mut reader = decoder.read_info().unwrap();
64 let mut buf = vec![0; reader.output_buffer_size()];
65 let info = reader.next_frame(&mut buf).unwrap();
66
67 println!("{:?}", info.color_type);
68
69 let mut image: Vec<u32> = Vec::new();
70 for i in buf.chunks(3) {
71 image.push(0xff << 24 | ((i[0] as u32) << 16) | ((i[1] as u32) << 8) | (i[2] as u32))
72 }
73 let _bitmap = Image {
74 width: info.width as i32,
75 height: info.height as i32,
76 data: &image[..],
77 };
78
79 //dt.fill(Source::Solid(SolidSource{r: 0xff, g: 0xff, b: 0, a: 0xff}));
80 //dt.fill(Source::Bitmap(bitmap, Transform::create_scale(2., 2.)));
81
82 let gradient = Source::RadialGradient(
83 Gradient {
84 stops: vec![
85 GradientStop {
86 position: 0.2,
87 color: Color::new(0xff, 0x00, 0xff, 0x00),
88 },
89 GradientStop {
90 position: 0.8,
91 color: Color::new(0xff, 0xff, 0xff, 0xff),
92 },
93 GradientStop {
94 position: 1.,
95 color: Color::new(0xff, 0xff, 0x00, 0xff),
96 },
97 ],
98 },
99 Spread::Pad,
100 Transform::translation(-150., -150.),
101 );
102 dt.fill(&path, &gradient, &DrawOptions::new());
103
104 let mut pb = PathBuilder::new();
105 pb.move_to(200., 200.);
106 pb.line_to(300., 300.);
107 pb.line_to(200., 300.);
108
109 let path = pb.finish();
110 dt.stroke(
111 &path,
112 &gradient,
113 &StrokeStyle {
114 cap: LineCap::Butt,
115 join: LineJoin::Bevel,
116 width: 10.,
117 miter_limit: 2.,
118 dash_array: vec![10., 5.],
119 dash_offset: 3.,
120 },
121 &DrawOptions::new(),
122 );
123
124 let font = SystemSource::new()
125 .select_best_match(&[FamilyName::SansSerif], &Properties::new())
126 .unwrap()
127 .load()
128 .unwrap();
129
130 dt.draw_text(
131 &font,
132 24.,
133 "Hello",
134 Point::new(0., 100.),
135 &Source::Solid(SolidSource {
136 r: 0,
137 g: 0,
138 b: 0xff,
139 a: 0xff,
140 }),
141 &DrawOptions::new(),
142 );
143
144 dt.write_png("out.png").unwrap();
145}
Source§impl<Backing: AsRef<[u32]> + AsMut<[u32]>> DrawTarget<Backing>
impl<Backing: AsRef<[u32]> + AsMut<[u32]>> DrawTarget<Backing>
Sourcepub fn from_backing(width: i32, height: i32, buf: Backing) -> Self
pub fn from_backing(width: i32, height: i32, buf: Backing) -> Self
Use an existing backing storage for the bitmap
The backing store must be the correct size (width*height elements).
pub fn width(&self) -> i32
pub fn height(&self) -> i32
Sourcepub fn set_transform(&mut self, transform: &Transform)
pub fn set_transform(&mut self, transform: &Transform)
sets a transform that will be applied to all drawing operations
Examples found in repository?
4fn main() {
5 let mut dt = DrawTarget::new(400, 400);
6
7 let mut pb = PathBuilder::new();
8 pb.arc(0., 0., 20., 0., std::f32::consts::PI);
9
10 let path = pb.finish();
11 dt.set_transform(&Transform::translation(50., 50.));
12 dt.stroke(
13 &path,
14 &Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
15 &StrokeStyle {
16 width: 40., // <--
17 ..StrokeStyle::default()
18 },
19 &DrawOptions::new(),
20 );
21
22 dt.write_png("out.png").unwrap();
23}
More examples
6fn main() {
7 let mut dt = DrawTarget::new(300, 100);
8 dt.clear(SolidSource::from_unpremultiplied_argb(
9 0xff, 0xcf, 0xcf, 0xcf,
10 ));
11
12 let font = SystemSource::new()
13 .select_best_match(
14 &[FamilyName::Title("Roboto".into())],
15 &Properties::new().weight(Weight::MEDIUM),
16 )
17 .unwrap()
18 .load()
19 .unwrap();
20 println!("{:?}", font);
21
22 //dt.set_transform(&Transform::create_translation(50.0, 0.0));
23 dt.set_transform(&Transform::rotation(euclid::Angle::degrees(15.0)));
24 let font = font_kit::loader::Loader::from_file(&mut std::fs::File::open("res/Box3.ttf").unwrap(), 0).unwrap();
25 dt.draw_text(
26 &font,
27 30.,
28 "3",
29 Point::new(0., 30.),
30 &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
31 &DrawOptions::new(),
32 );
33 dt.fill_rect(0., 35., 40., 5., &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
34 &DrawOptions::new() );
35
36 dt.write_png("out.png").unwrap();
37}
Sourcepub fn get_transform(&self) -> &Transform
pub fn get_transform(&self) -> &Transform
gets the current transform
pub fn push_clip_rect(&mut self, rect: IntRect)
pub fn pop_clip(&mut self)
Sourcepub fn push_clip(&mut self, path: &Path)
pub fn push_clip(&mut self, path: &Path)
Examples found in repository?
11fn main() {
12 let mut dt = DrawTarget::new(400, 400);
13
14 let mut pb = PathBuilder::new();
15 pb.move_to(340., 190.);
16 pb.arc(160., 190., 180., 0., 2. * 3.14159);
17 pb.close();
18 let path = pb.finish();
19 dt.push_clip(&path);
20
21 let mut pb = PathBuilder::new();
22 pb.move_to(0., 0.);
23 pb.line_to(200., 0.);
24 pb.line_to(200., 300.);
25 pb.line_to(0., 300.);
26 pb.close();
27 let path = pb.finish();
28 dt.fill(
29 &path,
30 &Source::Solid(SolidSource {
31 r: 0x80,
32 g: 0x80,
33 b: 0,
34 a: 0x80,
35 }),
36 &DrawOptions::new(),
37 );
38
39 let mut pb = PathBuilder::new();
40 pb.move_to(50., 50.);
41 pb.line_to(100., 70.);
42 pb.line_to(110., 150.);
43 pb.line_to(40., 180.);
44 pb.close();
45
46 /*
47 dt.move_to(100., 10.);
48 dt.quad_to(150., 40., 200., 10.);
49 dt.quad_to(120., 100., 80., 200.);
50 dt.quad_to(150., 180., 200., 200.);
51 dt.close();
52 */
53
54 pb.move_to(100., 10.);
55 pb.cubic_to(150., 40., 175., 0., 200., 10.);
56 pb.quad_to(120., 100., 80., 200.);
57 pb.quad_to(150., 180., 200., 200.);
58 pb.close();
59
60 let path = pb.finish();
61
62 let decoder = png::Decoder::new(File::open("photo.png").unwrap());
63 let mut reader = decoder.read_info().unwrap();
64 let mut buf = vec![0; reader.output_buffer_size()];
65 let info = reader.next_frame(&mut buf).unwrap();
66
67 println!("{:?}", info.color_type);
68
69 let mut image: Vec<u32> = Vec::new();
70 for i in buf.chunks(3) {
71 image.push(0xff << 24 | ((i[0] as u32) << 16) | ((i[1] as u32) << 8) | (i[2] as u32))
72 }
73 let _bitmap = Image {
74 width: info.width as i32,
75 height: info.height as i32,
76 data: &image[..],
77 };
78
79 //dt.fill(Source::Solid(SolidSource{r: 0xff, g: 0xff, b: 0, a: 0xff}));
80 //dt.fill(Source::Bitmap(bitmap, Transform::create_scale(2., 2.)));
81
82 let gradient = Source::RadialGradient(
83 Gradient {
84 stops: vec![
85 GradientStop {
86 position: 0.2,
87 color: Color::new(0xff, 0x00, 0xff, 0x00),
88 },
89 GradientStop {
90 position: 0.8,
91 color: Color::new(0xff, 0xff, 0xff, 0xff),
92 },
93 GradientStop {
94 position: 1.,
95 color: Color::new(0xff, 0xff, 0x00, 0xff),
96 },
97 ],
98 },
99 Spread::Pad,
100 Transform::translation(-150., -150.),
101 );
102 dt.fill(&path, &gradient, &DrawOptions::new());
103
104 let mut pb = PathBuilder::new();
105 pb.move_to(200., 200.);
106 pb.line_to(300., 300.);
107 pb.line_to(200., 300.);
108
109 let path = pb.finish();
110 dt.stroke(
111 &path,
112 &gradient,
113 &StrokeStyle {
114 cap: LineCap::Butt,
115 join: LineJoin::Bevel,
116 width: 10.,
117 miter_limit: 2.,
118 dash_array: vec![10., 5.],
119 dash_offset: 3.,
120 },
121 &DrawOptions::new(),
122 );
123
124 let font = SystemSource::new()
125 .select_best_match(&[FamilyName::SansSerif], &Properties::new())
126 .unwrap()
127 .load()
128 .unwrap();
129
130 dt.draw_text(
131 &font,
132 24.,
133 "Hello",
134 Point::new(0., 100.),
135 &Source::Solid(SolidSource {
136 r: 0,
137 g: 0,
138 b: 0xff,
139 a: 0xff,
140 }),
141 &DrawOptions::new(),
142 );
143
144 dt.write_png("out.png").unwrap();
145}
Sourcepub fn push_layer(&mut self, opacity: f32)
pub fn push_layer(&mut self, opacity: f32)
Pushes a new layer as the drawing target. This is used for implementing group opacity effects.
Sourcepub fn push_layer_with_blend(&mut self, opacity: f32, blend: BlendMode)
pub fn push_layer_with_blend(&mut self, opacity: f32, blend: BlendMode)
Pushes a new layer as the drawing target. This is used for implementing group opacity or blend effects.
Sourcepub fn pop_layer(&mut self)
pub fn pop_layer(&mut self)
Draws the most recently pushed layer to the drawing target with the pushed opacity applied.
Sourcepub fn draw_image_with_size_at(
&mut self,
width: f32,
height: f32,
x: f32,
y: f32,
image: &Image<'_>,
options: &DrawOptions,
)
pub fn draw_image_with_size_at( &mut self, width: f32, height: f32, x: f32, y: f32, image: &Image<'_>, options: &DrawOptions, )
Draws an image at (x, y) with the size (width, height). This will rescale the image to the destination size.
Sourcepub fn draw_image_at(
&mut self,
x: f32,
y: f32,
image: &Image<'_>,
options: &DrawOptions,
)
pub fn draw_image_at( &mut self, x: f32, y: f32, image: &Image<'_>, options: &DrawOptions, )
Draws an image at x, y
Sourcepub fn mask(&mut self, src: &Source<'_>, x: i32, y: i32, mask: &Mask)
pub fn mask(&mut self, src: &Source<'_>, x: i32, y: i32, mask: &Mask)
Draws src
through an untransformed mask
positioned at x
, y
in device space
Sourcepub fn stroke(
&mut self,
path: &Path,
src: &Source<'_>,
style: &StrokeStyle,
options: &DrawOptions,
)
pub fn stroke( &mut self, path: &Path, src: &Source<'_>, style: &StrokeStyle, options: &DrawOptions, )
Strokes path
with style
and fills the result with src
Examples found in repository?
3fn main() {
4 let mut dt = DrawTarget::new(400, 400);
5
6 let mut pb = PathBuilder::new();
7 pb.move_to(200., 200.);
8 pb.line_to(300., 300.);
9 pb.line_to(200., 300.);
10
11 let path = pb.finish();
12 dt.stroke(
13 &path,
14 &Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
15 &StrokeStyle {
16 width: 100000., // <--
17 ..StrokeStyle::default()
18 },
19 &DrawOptions::new(),
20 );
21
22 dt.write_png("out.png").unwrap();
23}
More examples
4fn main() {
5 let mut dt = DrawTarget::new(400, 400);
6
7 let mut pb = PathBuilder::new();
8 pb.arc(0., 0., 20., 0., std::f32::consts::PI);
9
10 let path = pb.finish();
11 dt.set_transform(&Transform::translation(50., 50.));
12 dt.stroke(
13 &path,
14 &Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
15 &StrokeStyle {
16 width: 40., // <--
17 ..StrokeStyle::default()
18 },
19 &DrawOptions::new(),
20 );
21
22 dt.write_png("out.png").unwrap();
23}
11fn main() {
12 let mut dt = DrawTarget::new(400, 400);
13
14 let mut pb = PathBuilder::new();
15 pb.move_to(340., 190.);
16 pb.arc(160., 190., 180., 0., 2. * 3.14159);
17 pb.close();
18 let path = pb.finish();
19 dt.push_clip(&path);
20
21 let mut pb = PathBuilder::new();
22 pb.move_to(0., 0.);
23 pb.line_to(200., 0.);
24 pb.line_to(200., 300.);
25 pb.line_to(0., 300.);
26 pb.close();
27 let path = pb.finish();
28 dt.fill(
29 &path,
30 &Source::Solid(SolidSource {
31 r: 0x80,
32 g: 0x80,
33 b: 0,
34 a: 0x80,
35 }),
36 &DrawOptions::new(),
37 );
38
39 let mut pb = PathBuilder::new();
40 pb.move_to(50., 50.);
41 pb.line_to(100., 70.);
42 pb.line_to(110., 150.);
43 pb.line_to(40., 180.);
44 pb.close();
45
46 /*
47 dt.move_to(100., 10.);
48 dt.quad_to(150., 40., 200., 10.);
49 dt.quad_to(120., 100., 80., 200.);
50 dt.quad_to(150., 180., 200., 200.);
51 dt.close();
52 */
53
54 pb.move_to(100., 10.);
55 pb.cubic_to(150., 40., 175., 0., 200., 10.);
56 pb.quad_to(120., 100., 80., 200.);
57 pb.quad_to(150., 180., 200., 200.);
58 pb.close();
59
60 let path = pb.finish();
61
62 let decoder = png::Decoder::new(File::open("photo.png").unwrap());
63 let mut reader = decoder.read_info().unwrap();
64 let mut buf = vec![0; reader.output_buffer_size()];
65 let info = reader.next_frame(&mut buf).unwrap();
66
67 println!("{:?}", info.color_type);
68
69 let mut image: Vec<u32> = Vec::new();
70 for i in buf.chunks(3) {
71 image.push(0xff << 24 | ((i[0] as u32) << 16) | ((i[1] as u32) << 8) | (i[2] as u32))
72 }
73 let _bitmap = Image {
74 width: info.width as i32,
75 height: info.height as i32,
76 data: &image[..],
77 };
78
79 //dt.fill(Source::Solid(SolidSource{r: 0xff, g: 0xff, b: 0, a: 0xff}));
80 //dt.fill(Source::Bitmap(bitmap, Transform::create_scale(2., 2.)));
81
82 let gradient = Source::RadialGradient(
83 Gradient {
84 stops: vec![
85 GradientStop {
86 position: 0.2,
87 color: Color::new(0xff, 0x00, 0xff, 0x00),
88 },
89 GradientStop {
90 position: 0.8,
91 color: Color::new(0xff, 0xff, 0xff, 0xff),
92 },
93 GradientStop {
94 position: 1.,
95 color: Color::new(0xff, 0xff, 0x00, 0xff),
96 },
97 ],
98 },
99 Spread::Pad,
100 Transform::translation(-150., -150.),
101 );
102 dt.fill(&path, &gradient, &DrawOptions::new());
103
104 let mut pb = PathBuilder::new();
105 pb.move_to(200., 200.);
106 pb.line_to(300., 300.);
107 pb.line_to(200., 300.);
108
109 let path = pb.finish();
110 dt.stroke(
111 &path,
112 &gradient,
113 &StrokeStyle {
114 cap: LineCap::Butt,
115 join: LineJoin::Bevel,
116 width: 10.,
117 miter_limit: 2.,
118 dash_array: vec![10., 5.],
119 dash_offset: 3.,
120 },
121 &DrawOptions::new(),
122 );
123
124 let font = SystemSource::new()
125 .select_best_match(&[FamilyName::SansSerif], &Properties::new())
126 .unwrap()
127 .load()
128 .unwrap();
129
130 dt.draw_text(
131 &font,
132 24.,
133 "Hello",
134 Point::new(0., 100.),
135 &Source::Solid(SolidSource {
136 r: 0,
137 g: 0,
138 b: 0xff,
139 a: 0xff,
140 }),
141 &DrawOptions::new(),
142 );
143
144 dt.write_png("out.png").unwrap();
145}
Sourcepub fn fill_rect(
&mut self,
x: f32,
y: f32,
width: f32,
height: f32,
src: &Source<'_>,
options: &DrawOptions,
)
pub fn fill_rect( &mut self, x: f32, y: f32, width: f32, height: f32, src: &Source<'_>, options: &DrawOptions, )
Fills the rect x
, y,
, width
, height
with src
. If the result is an
integer aligned rectangle performance will be faster than filling a rectangular path.
Examples found in repository?
6fn main() {
7 let mut dt = DrawTarget::new(300, 100);
8 dt.clear(SolidSource::from_unpremultiplied_argb(
9 0xff, 0xcf, 0xcf, 0xcf,
10 ));
11
12 let font = SystemSource::new()
13 .select_best_match(
14 &[FamilyName::Title("Roboto".into())],
15 &Properties::new().weight(Weight::MEDIUM),
16 )
17 .unwrap()
18 .load()
19 .unwrap();
20 println!("{:?}", font);
21
22 //dt.set_transform(&Transform::create_translation(50.0, 0.0));
23 dt.set_transform(&Transform::rotation(euclid::Angle::degrees(15.0)));
24 let font = font_kit::loader::Loader::from_file(&mut std::fs::File::open("res/Box3.ttf").unwrap(), 0).unwrap();
25 dt.draw_text(
26 &font,
27 30.,
28 "3",
29 Point::new(0., 30.),
30 &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
31 &DrawOptions::new(),
32 );
33 dt.fill_rect(0., 35., 40., 5., &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
34 &DrawOptions::new() );
35
36 dt.write_png("out.png").unwrap();
37}
Sourcepub fn fill(&mut self, path: &Path, src: &Source<'_>, options: &DrawOptions)
pub fn fill(&mut self, path: &Path, src: &Source<'_>, options: &DrawOptions)
Fills path
with src
Examples found in repository?
1fn main() {
2 use raqote::*;
3
4let mut dt = DrawTarget::new(400, 400);
5
6let mut pb = PathBuilder::new();
7pb.rect(0., 0., 400., 400.);
8let path = pb.finish();
9
10let gradient = Source::new_sweep_gradient(
11 Gradient {
12 stops: vec![
13 GradientStop {
14 position: 0.,
15 color: Color::new(0xff, 0, 0, 0),
16 },
17 GradientStop {
18 position: 0.5,
19 color: Color::new(0xff, 0xff, 0xff, 0x0),
20 },
21 GradientStop {
22 position: 1.,
23 color: Color::new(0xff, 0, 0, 0x0),
24 },
25 ],
26 },
27 Point::new(150., 200.),
28 45.,
29 180.+45.,
30 Spread::Repeat,
31);
32dt.fill(&path, &gradient, &DrawOptions::new());
33
34
35
36dt.write_png("example.png");
37}
More examples
10fn main() {
11 let mut dt = DrawTarget::new(200, 200);
12
13 let gradient = Source::new_linear_gradient(
14 Gradient {
15 stops: vec![
16 GradientStop {
17 position: 0.0,
18 color: Color::new(0xff, 0xff, 0xff, 0xff),
19 },
20 GradientStop {
21 position: 0.9999,
22 color: Color::new(0xff, 0x0, 0x0, 0x0),
23 },
24 GradientStop {
25 position: 1.0,
26 color: Color::new(0xff, 0x0, 0x0, 0x0),
27 },
28 ],
29 },
30 Point::new(40., 0.),
31 Point::new(100., 0.),
32 Spread::Pad,
33 );
34
35 let mut pb = PathBuilder::new();
36 pb.rect(0., 0., 80., 80.);
37 let path = pb.finish();
38 dt.fill(&path, &gradient, &DrawOptions::default());
39
40 dt.write_png("out.png").unwrap();
41}
11fn main() {
12 let mut dt = DrawTarget::new(400, 400);
13
14 let mut pb = PathBuilder::new();
15 pb.move_to(340., 190.);
16 pb.arc(160., 190., 180., 0., 2. * 3.14159);
17 pb.close();
18 let path = pb.finish();
19 dt.push_clip(&path);
20
21 let mut pb = PathBuilder::new();
22 pb.move_to(0., 0.);
23 pb.line_to(200., 0.);
24 pb.line_to(200., 300.);
25 pb.line_to(0., 300.);
26 pb.close();
27 let path = pb.finish();
28 dt.fill(
29 &path,
30 &Source::Solid(SolidSource {
31 r: 0x80,
32 g: 0x80,
33 b: 0,
34 a: 0x80,
35 }),
36 &DrawOptions::new(),
37 );
38
39 let mut pb = PathBuilder::new();
40 pb.move_to(50., 50.);
41 pb.line_to(100., 70.);
42 pb.line_to(110., 150.);
43 pb.line_to(40., 180.);
44 pb.close();
45
46 /*
47 dt.move_to(100., 10.);
48 dt.quad_to(150., 40., 200., 10.);
49 dt.quad_to(120., 100., 80., 200.);
50 dt.quad_to(150., 180., 200., 200.);
51 dt.close();
52 */
53
54 pb.move_to(100., 10.);
55 pb.cubic_to(150., 40., 175., 0., 200., 10.);
56 pb.quad_to(120., 100., 80., 200.);
57 pb.quad_to(150., 180., 200., 200.);
58 pb.close();
59
60 let path = pb.finish();
61
62 let decoder = png::Decoder::new(File::open("photo.png").unwrap());
63 let mut reader = decoder.read_info().unwrap();
64 let mut buf = vec![0; reader.output_buffer_size()];
65 let info = reader.next_frame(&mut buf).unwrap();
66
67 println!("{:?}", info.color_type);
68
69 let mut image: Vec<u32> = Vec::new();
70 for i in buf.chunks(3) {
71 image.push(0xff << 24 | ((i[0] as u32) << 16) | ((i[1] as u32) << 8) | (i[2] as u32))
72 }
73 let _bitmap = Image {
74 width: info.width as i32,
75 height: info.height as i32,
76 data: &image[..],
77 };
78
79 //dt.fill(Source::Solid(SolidSource{r: 0xff, g: 0xff, b: 0, a: 0xff}));
80 //dt.fill(Source::Bitmap(bitmap, Transform::create_scale(2., 2.)));
81
82 let gradient = Source::RadialGradient(
83 Gradient {
84 stops: vec![
85 GradientStop {
86 position: 0.2,
87 color: Color::new(0xff, 0x00, 0xff, 0x00),
88 },
89 GradientStop {
90 position: 0.8,
91 color: Color::new(0xff, 0xff, 0xff, 0xff),
92 },
93 GradientStop {
94 position: 1.,
95 color: Color::new(0xff, 0xff, 0x00, 0xff),
96 },
97 ],
98 },
99 Spread::Pad,
100 Transform::translation(-150., -150.),
101 );
102 dt.fill(&path, &gradient, &DrawOptions::new());
103
104 let mut pb = PathBuilder::new();
105 pb.move_to(200., 200.);
106 pb.line_to(300., 300.);
107 pb.line_to(200., 300.);
108
109 let path = pb.finish();
110 dt.stroke(
111 &path,
112 &gradient,
113 &StrokeStyle {
114 cap: LineCap::Butt,
115 join: LineJoin::Bevel,
116 width: 10.,
117 miter_limit: 2.,
118 dash_array: vec![10., 5.],
119 dash_offset: 3.,
120 },
121 &DrawOptions::new(),
122 );
123
124 let font = SystemSource::new()
125 .select_best_match(&[FamilyName::SansSerif], &Properties::new())
126 .unwrap()
127 .load()
128 .unwrap();
129
130 dt.draw_text(
131 &font,
132 24.,
133 "Hello",
134 Point::new(0., 100.),
135 &Source::Solid(SolidSource {
136 r: 0,
137 g: 0,
138 b: 0xff,
139 a: 0xff,
140 }),
141 &DrawOptions::new(),
142 );
143
144 dt.write_png("out.png").unwrap();
145}
Sourcepub fn clear(&mut self, solid: SolidSource)
pub fn clear(&mut self, solid: SolidSource)
Fills the current clip with the solid color solid
Examples found in repository?
6fn main() {
7 let mut dt = DrawTarget::new(300, 100);
8 dt.clear(SolidSource::from_unpremultiplied_argb(
9 0xff, 0xcf, 0xcf, 0xcf,
10 ));
11
12 let font = SystemSource::new()
13 .select_best_match(
14 &[FamilyName::Title("Roboto".into())],
15 &Properties::new().weight(Weight::MEDIUM),
16 )
17 .unwrap()
18 .load()
19 .unwrap();
20 println!("{:?}", font);
21
22 //dt.set_transform(&Transform::create_translation(50.0, 0.0));
23 dt.set_transform(&Transform::rotation(euclid::Angle::degrees(15.0)));
24 let font = font_kit::loader::Loader::from_file(&mut std::fs::File::open("res/Box3.ttf").unwrap(), 0).unwrap();
25 dt.draw_text(
26 &font,
27 30.,
28 "3",
29 Point::new(0., 30.),
30 &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
31 &DrawOptions::new(),
32 );
33 dt.fill_rect(0., 35., 40., 5., &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
34 &DrawOptions::new() );
35
36 dt.write_png("out.png").unwrap();
37}
Sourcepub fn draw_text(
&mut self,
font: &Font,
point_size: f32,
text: &str,
start: Point,
src: &Source<'_>,
options: &DrawOptions,
)
pub fn draw_text( &mut self, font: &Font, point_size: f32, text: &str, start: Point, src: &Source<'_>, options: &DrawOptions, )
Examples found in repository?
6fn main() {
7 let mut dt = DrawTarget::new(300, 100);
8 dt.clear(SolidSource::from_unpremultiplied_argb(
9 0xff, 0xcf, 0xcf, 0xcf,
10 ));
11
12 let font = SystemSource::new()
13 .select_best_match(
14 &[FamilyName::Title("Roboto".into())],
15 &Properties::new().weight(Weight::MEDIUM),
16 )
17 .unwrap()
18 .load()
19 .unwrap();
20 println!("{:?}", font);
21
22 //dt.set_transform(&Transform::create_translation(50.0, 0.0));
23 dt.set_transform(&Transform::rotation(euclid::Angle::degrees(15.0)));
24 let font = font_kit::loader::Loader::from_file(&mut std::fs::File::open("res/Box3.ttf").unwrap(), 0).unwrap();
25 dt.draw_text(
26 &font,
27 30.,
28 "3",
29 Point::new(0., 30.),
30 &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
31 &DrawOptions::new(),
32 );
33 dt.fill_rect(0., 35., 40., 5., &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
34 &DrawOptions::new() );
35
36 dt.write_png("out.png").unwrap();
37}
More examples
11fn main() {
12 let mut dt = DrawTarget::new(400, 400);
13
14 let mut pb = PathBuilder::new();
15 pb.move_to(340., 190.);
16 pb.arc(160., 190., 180., 0., 2. * 3.14159);
17 pb.close();
18 let path = pb.finish();
19 dt.push_clip(&path);
20
21 let mut pb = PathBuilder::new();
22 pb.move_to(0., 0.);
23 pb.line_to(200., 0.);
24 pb.line_to(200., 300.);
25 pb.line_to(0., 300.);
26 pb.close();
27 let path = pb.finish();
28 dt.fill(
29 &path,
30 &Source::Solid(SolidSource {
31 r: 0x80,
32 g: 0x80,
33 b: 0,
34 a: 0x80,
35 }),
36 &DrawOptions::new(),
37 );
38
39 let mut pb = PathBuilder::new();
40 pb.move_to(50., 50.);
41 pb.line_to(100., 70.);
42 pb.line_to(110., 150.);
43 pb.line_to(40., 180.);
44 pb.close();
45
46 /*
47 dt.move_to(100., 10.);
48 dt.quad_to(150., 40., 200., 10.);
49 dt.quad_to(120., 100., 80., 200.);
50 dt.quad_to(150., 180., 200., 200.);
51 dt.close();
52 */
53
54 pb.move_to(100., 10.);
55 pb.cubic_to(150., 40., 175., 0., 200., 10.);
56 pb.quad_to(120., 100., 80., 200.);
57 pb.quad_to(150., 180., 200., 200.);
58 pb.close();
59
60 let path = pb.finish();
61
62 let decoder = png::Decoder::new(File::open("photo.png").unwrap());
63 let mut reader = decoder.read_info().unwrap();
64 let mut buf = vec![0; reader.output_buffer_size()];
65 let info = reader.next_frame(&mut buf).unwrap();
66
67 println!("{:?}", info.color_type);
68
69 let mut image: Vec<u32> = Vec::new();
70 for i in buf.chunks(3) {
71 image.push(0xff << 24 | ((i[0] as u32) << 16) | ((i[1] as u32) << 8) | (i[2] as u32))
72 }
73 let _bitmap = Image {
74 width: info.width as i32,
75 height: info.height as i32,
76 data: &image[..],
77 };
78
79 //dt.fill(Source::Solid(SolidSource{r: 0xff, g: 0xff, b: 0, a: 0xff}));
80 //dt.fill(Source::Bitmap(bitmap, Transform::create_scale(2., 2.)));
81
82 let gradient = Source::RadialGradient(
83 Gradient {
84 stops: vec![
85 GradientStop {
86 position: 0.2,
87 color: Color::new(0xff, 0x00, 0xff, 0x00),
88 },
89 GradientStop {
90 position: 0.8,
91 color: Color::new(0xff, 0xff, 0xff, 0xff),
92 },
93 GradientStop {
94 position: 1.,
95 color: Color::new(0xff, 0xff, 0x00, 0xff),
96 },
97 ],
98 },
99 Spread::Pad,
100 Transform::translation(-150., -150.),
101 );
102 dt.fill(&path, &gradient, &DrawOptions::new());
103
104 let mut pb = PathBuilder::new();
105 pb.move_to(200., 200.);
106 pb.line_to(300., 300.);
107 pb.line_to(200., 300.);
108
109 let path = pb.finish();
110 dt.stroke(
111 &path,
112 &gradient,
113 &StrokeStyle {
114 cap: LineCap::Butt,
115 join: LineJoin::Bevel,
116 width: 10.,
117 miter_limit: 2.,
118 dash_array: vec![10., 5.],
119 dash_offset: 3.,
120 },
121 &DrawOptions::new(),
122 );
123
124 let font = SystemSource::new()
125 .select_best_match(&[FamilyName::SansSerif], &Properties::new())
126 .unwrap()
127 .load()
128 .unwrap();
129
130 dt.draw_text(
131 &font,
132 24.,
133 "Hello",
134 Point::new(0., 100.),
135 &Source::Solid(SolidSource {
136 r: 0,
137 g: 0,
138 b: 0xff,
139 a: 0xff,
140 }),
141 &DrawOptions::new(),
142 );
143
144 dt.write_png("out.png").unwrap();
145}
pub fn draw_glyphs( &mut self, font: &Font, point_size: f32, ids: &[u32], positions: &[Point], src: &Source<'_>, options: &DrawOptions, )
Source§impl<Backing: AsRef<[u32]> + AsMut<[u32]>> DrawTarget<Backing>
impl<Backing: AsRef<[u32]> + AsMut<[u32]>> DrawTarget<Backing>
Sourcepub fn composite_surface<F: Fn(&[u32], &mut [u32]), SrcBacking: AsRef<[u32]>>(
&mut self,
src: &DrawTarget<SrcBacking>,
src_rect: IntRect,
dst: IntPoint,
f: F,
)
pub fn composite_surface<F: Fn(&[u32], &mut [u32]), SrcBacking: AsRef<[u32]>>( &mut self, src: &DrawTarget<SrcBacking>, src_rect: IntRect, dst: IntPoint, f: F, )
Draws src_rect
of src
at dst
. The current transform and clip are ignored
Sourcepub fn copy_surface<SrcBacking: AsRef<[u32]>>(
&mut self,
src: &DrawTarget<SrcBacking>,
src_rect: IntRect,
dst: IntPoint,
)
pub fn copy_surface<SrcBacking: AsRef<[u32]>>( &mut self, src: &DrawTarget<SrcBacking>, src_rect: IntRect, dst: IntPoint, )
Draws src_rect
of src
at dst
. The current transform and clip are ignored.
src_rect
is clamped to (0, 0, src.width, src.height).
Sourcepub fn blend_surface<SrcBacking: AsRef<[u32]>>(
&mut self,
src: &DrawTarget<SrcBacking>,
src_rect: IntRect,
dst: IntPoint,
blend: BlendMode,
)
pub fn blend_surface<SrcBacking: AsRef<[u32]>>( &mut self, src: &DrawTarget<SrcBacking>, src_rect: IntRect, dst: IntPoint, blend: BlendMode, )
Blends src_rect
of src
at dst
using blend
mode.
The current transform and clip are ignored.
src_rect
is clamped to (0, 0, src.width
, src.height
).
Sourcepub fn blend_surface_with_alpha<SrcBacking: AsRef<[u32]>>(
&mut self,
src: &DrawTarget<SrcBacking>,
src_rect: IntRect,
dst: IntPoint,
alpha: f32,
)
pub fn blend_surface_with_alpha<SrcBacking: AsRef<[u32]>>( &mut self, src: &DrawTarget<SrcBacking>, src_rect: IntRect, dst: IntPoint, alpha: f32, )
Blends src_rect
of src
at dst
using alpha
. The current transform and clip are ignored.
src_rect
is clamped to (0, 0, src.width
, src.height
).
Sourcepub fn get_data_mut(&mut self) -> &mut [u32]
pub fn get_data_mut(&mut self) -> &mut [u32]
Returns a mut reference to the underlying pixel data as ARGB with a representation like: (A << 24) | (R << 16) | (G << 8) | B
Sourcepub fn get_data_u8(&self) -> &[u8] ⓘ
pub fn get_data_u8(&self) -> &[u8] ⓘ
Returns a reference to the underlying pixel data as individual bytes with the order BGRA on little endian.
Sourcepub fn get_data_u8_mut(&mut self) -> &mut [u8] ⓘ
pub fn get_data_u8_mut(&mut self) -> &mut [u8] ⓘ
Returns a mut reference to the underlying pixel data as individual bytes with the order BGRA on little endian.
Sourcepub fn into_inner(self) -> Backing
pub fn into_inner(self) -> Backing
Take ownership of the buffer backing the DrawTarget
Sourcepub fn write_png<P: AsRef<Path>>(&self, path: P) -> Result<(), EncodingError>
pub fn write_png<P: AsRef<Path>>(&self, path: P) -> Result<(), EncodingError>
Saves the current pixel to a png file at path
Examples found in repository?
3fn main() {
4 let mut dt = DrawTarget::new(400, 400);
5
6 let mut pb = PathBuilder::new();
7 pb.move_to(200., 200.);
8 pb.line_to(300., 300.);
9 pb.line_to(200., 300.);
10
11 let path = pb.finish();
12 dt.stroke(
13 &path,
14 &Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
15 &StrokeStyle {
16 width: 100000., // <--
17 ..StrokeStyle::default()
18 },
19 &DrawOptions::new(),
20 );
21
22 dt.write_png("out.png").unwrap();
23}
More examples
4fn main() {
5 let mut dt = DrawTarget::new(400, 400);
6
7 let mut pb = PathBuilder::new();
8 pb.arc(0., 0., 20., 0., std::f32::consts::PI);
9
10 let path = pb.finish();
11 dt.set_transform(&Transform::translation(50., 50.));
12 dt.stroke(
13 &path,
14 &Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
15 &StrokeStyle {
16 width: 40., // <--
17 ..StrokeStyle::default()
18 },
19 &DrawOptions::new(),
20 );
21
22 dt.write_png("out.png").unwrap();
23}
1fn main() {
2 use raqote::*;
3
4let mut dt = DrawTarget::new(400, 400);
5
6let mut pb = PathBuilder::new();
7pb.rect(0., 0., 400., 400.);
8let path = pb.finish();
9
10let gradient = Source::new_sweep_gradient(
11 Gradient {
12 stops: vec![
13 GradientStop {
14 position: 0.,
15 color: Color::new(0xff, 0, 0, 0),
16 },
17 GradientStop {
18 position: 0.5,
19 color: Color::new(0xff, 0xff, 0xff, 0x0),
20 },
21 GradientStop {
22 position: 1.,
23 color: Color::new(0xff, 0, 0, 0x0),
24 },
25 ],
26 },
27 Point::new(150., 200.),
28 45.,
29 180.+45.,
30 Spread::Repeat,
31);
32dt.fill(&path, &gradient, &DrawOptions::new());
33
34
35
36dt.write_png("example.png");
37}
10fn main() {
11 let mut dt = DrawTarget::new(200, 200);
12
13 let gradient = Source::new_linear_gradient(
14 Gradient {
15 stops: vec![
16 GradientStop {
17 position: 0.0,
18 color: Color::new(0xff, 0xff, 0xff, 0xff),
19 },
20 GradientStop {
21 position: 0.9999,
22 color: Color::new(0xff, 0x0, 0x0, 0x0),
23 },
24 GradientStop {
25 position: 1.0,
26 color: Color::new(0xff, 0x0, 0x0, 0x0),
27 },
28 ],
29 },
30 Point::new(40., 0.),
31 Point::new(100., 0.),
32 Spread::Pad,
33 );
34
35 let mut pb = PathBuilder::new();
36 pb.rect(0., 0., 80., 80.);
37 let path = pb.finish();
38 dt.fill(&path, &gradient, &DrawOptions::default());
39
40 dt.write_png("out.png").unwrap();
41}
6fn main() {
7 let mut dt = DrawTarget::new(300, 100);
8 dt.clear(SolidSource::from_unpremultiplied_argb(
9 0xff, 0xcf, 0xcf, 0xcf,
10 ));
11
12 let font = SystemSource::new()
13 .select_best_match(
14 &[FamilyName::Title("Roboto".into())],
15 &Properties::new().weight(Weight::MEDIUM),
16 )
17 .unwrap()
18 .load()
19 .unwrap();
20 println!("{:?}", font);
21
22 //dt.set_transform(&Transform::create_translation(50.0, 0.0));
23 dt.set_transform(&Transform::rotation(euclid::Angle::degrees(15.0)));
24 let font = font_kit::loader::Loader::from_file(&mut std::fs::File::open("res/Box3.ttf").unwrap(), 0).unwrap();
25 dt.draw_text(
26 &font,
27 30.,
28 "3",
29 Point::new(0., 30.),
30 &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
31 &DrawOptions::new(),
32 );
33 dt.fill_rect(0., 35., 40., 5., &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
34 &DrawOptions::new() );
35
36 dt.write_png("out.png").unwrap();
37}
11fn main() {
12 let mut dt = DrawTarget::new(400, 400);
13
14 let mut pb = PathBuilder::new();
15 pb.move_to(340., 190.);
16 pb.arc(160., 190., 180., 0., 2. * 3.14159);
17 pb.close();
18 let path = pb.finish();
19 dt.push_clip(&path);
20
21 let mut pb = PathBuilder::new();
22 pb.move_to(0., 0.);
23 pb.line_to(200., 0.);
24 pb.line_to(200., 300.);
25 pb.line_to(0., 300.);
26 pb.close();
27 let path = pb.finish();
28 dt.fill(
29 &path,
30 &Source::Solid(SolidSource {
31 r: 0x80,
32 g: 0x80,
33 b: 0,
34 a: 0x80,
35 }),
36 &DrawOptions::new(),
37 );
38
39 let mut pb = PathBuilder::new();
40 pb.move_to(50., 50.);
41 pb.line_to(100., 70.);
42 pb.line_to(110., 150.);
43 pb.line_to(40., 180.);
44 pb.close();
45
46 /*
47 dt.move_to(100., 10.);
48 dt.quad_to(150., 40., 200., 10.);
49 dt.quad_to(120., 100., 80., 200.);
50 dt.quad_to(150., 180., 200., 200.);
51 dt.close();
52 */
53
54 pb.move_to(100., 10.);
55 pb.cubic_to(150., 40., 175., 0., 200., 10.);
56 pb.quad_to(120., 100., 80., 200.);
57 pb.quad_to(150., 180., 200., 200.);
58 pb.close();
59
60 let path = pb.finish();
61
62 let decoder = png::Decoder::new(File::open("photo.png").unwrap());
63 let mut reader = decoder.read_info().unwrap();
64 let mut buf = vec![0; reader.output_buffer_size()];
65 let info = reader.next_frame(&mut buf).unwrap();
66
67 println!("{:?}", info.color_type);
68
69 let mut image: Vec<u32> = Vec::new();
70 for i in buf.chunks(3) {
71 image.push(0xff << 24 | ((i[0] as u32) << 16) | ((i[1] as u32) << 8) | (i[2] as u32))
72 }
73 let _bitmap = Image {
74 width: info.width as i32,
75 height: info.height as i32,
76 data: &image[..],
77 };
78
79 //dt.fill(Source::Solid(SolidSource{r: 0xff, g: 0xff, b: 0, a: 0xff}));
80 //dt.fill(Source::Bitmap(bitmap, Transform::create_scale(2., 2.)));
81
82 let gradient = Source::RadialGradient(
83 Gradient {
84 stops: vec![
85 GradientStop {
86 position: 0.2,
87 color: Color::new(0xff, 0x00, 0xff, 0x00),
88 },
89 GradientStop {
90 position: 0.8,
91 color: Color::new(0xff, 0xff, 0xff, 0xff),
92 },
93 GradientStop {
94 position: 1.,
95 color: Color::new(0xff, 0xff, 0x00, 0xff),
96 },
97 ],
98 },
99 Spread::Pad,
100 Transform::translation(-150., -150.),
101 );
102 dt.fill(&path, &gradient, &DrawOptions::new());
103
104 let mut pb = PathBuilder::new();
105 pb.move_to(200., 200.);
106 pb.line_to(300., 300.);
107 pb.line_to(200., 300.);
108
109 let path = pb.finish();
110 dt.stroke(
111 &path,
112 &gradient,
113 &StrokeStyle {
114 cap: LineCap::Butt,
115 join: LineJoin::Bevel,
116 width: 10.,
117 miter_limit: 2.,
118 dash_array: vec![10., 5.],
119 dash_offset: 3.,
120 },
121 &DrawOptions::new(),
122 );
123
124 let font = SystemSource::new()
125 .select_best_match(&[FamilyName::SansSerif], &Properties::new())
126 .unwrap()
127 .load()
128 .unwrap();
129
130 dt.draw_text(
131 &font,
132 24.,
133 "Hello",
134 Point::new(0., 100.),
135 &Source::Solid(SolidSource {
136 r: 0,
137 g: 0,
138 b: 0xff,
139 a: 0xff,
140 }),
141 &DrawOptions::new(),
142 );
143
144 dt.write_png("out.png").unwrap();
145}