Struct raqote::DrawTarget

source ·
pub struct DrawTarget<Backing = Vec<u32>> { /* private fields */ }
Expand description

The main type used for drawing

Implementations§

source§

impl DrawTarget

source

pub fn new(width: i32, height: i32) -> DrawTarget

Examples found in repository?
examples/stroke.rs (line 4)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() {
    let mut dt = DrawTarget::new(400, 400);

    let mut pb = PathBuilder::new();
    pb.move_to(200., 200.);
    pb.line_to(300., 300.);
    pb.line_to(200., 300.);

    let path = pb.finish();
    dt.stroke(
        &path,
        &Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
        &StrokeStyle {
            width: 100000., // <--
            ..StrokeStyle::default()
        },
        &DrawOptions::new(),
    );

    dt.write_png("out.png").unwrap();
}
More examples
Hide additional examples
examples/stroke-arc.rs (line 5)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() {
    let mut dt = DrawTarget::new(400, 400);

    let mut pb = PathBuilder::new();
    pb.arc(0., 0., 20., 0., std::f32::consts::PI);

    let path = pb.finish();
    dt.set_transform(&Transform::translation(50., 50.));
    dt.stroke(
        &path,
        &Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
        &StrokeStyle {
            width: 40., // <--
            ..StrokeStyle::default()
        },
        &DrawOptions::new(),
    );

    dt.write_png("out.png").unwrap();
}
examples/sweep-gradient.rs (line 4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
fn main() {
    use raqote::*;

let mut dt = DrawTarget::new(400, 400);

let mut pb = PathBuilder::new();
pb.rect(0., 0., 400., 400.);
let path = pb.finish();

let gradient = Source::new_sweep_gradient(
    Gradient {
        stops: vec![
            GradientStop {
                position: 0.,
                color: Color::new(0xff, 0, 0, 0),
            },
            GradientStop {
                position: 0.5,
                color: Color::new(0xff, 0xff, 0xff, 0x0),
            },
            GradientStop {
                position: 1.,
                color: Color::new(0xff, 0, 0, 0x0),
            },
        ],
    },
    Point::new(150., 200.),
    45.,
    180.+45.,
    Spread::Repeat,
);
dt.fill(&path, &gradient, &DrawOptions::new());



dt.write_png("example.png");
}
examples/pad.rs (line 11)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
fn main() {
    let mut dt = DrawTarget::new(200, 200);
    
    let gradient = Source::new_linear_gradient(
        Gradient {
            stops: vec![
                GradientStop {
                    position: 0.0,
                    color: Color::new(0xff, 0xff, 0xff, 0xff),
                },
                GradientStop {
                    position: 0.9999,
                    color: Color::new(0xff, 0x0, 0x0, 0x0),
                },
                GradientStop {
                    position: 1.0,
                    color: Color::new(0xff, 0x0, 0x0, 0x0),
                },
            ],
        },
        Point::new(40., 0.),
        Point::new(100., 0.),
        Spread::Pad,
    );

    let mut pb = PathBuilder::new();
    pb.rect(0., 0., 80., 80.);
    let path = pb.finish();
    dt.fill(&path, &gradient, &DrawOptions::default());

    dt.write_png("out.png").unwrap();
}
examples/text.rs (line 7)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
fn main() {
    let mut dt = DrawTarget::new(300, 100);
    dt.clear(SolidSource::from_unpremultiplied_argb(
        0xff, 0xcf, 0xcf, 0xcf,
    ));

    let font = SystemSource::new()
        .select_best_match(
            &[FamilyName::Title("Roboto".into())],
            &Properties::new().weight(Weight::MEDIUM),
        )
        .unwrap()
        .load()
        .unwrap();
    println!("{:?}", font);

    //dt.set_transform(&Transform::create_translation(50.0, 0.0));
    dt.set_transform(&Transform::rotation(euclid::Angle::degrees(15.0)));
    let font = font_kit::loader::Loader::from_file(&mut std::fs::File::open("res/Box3.ttf").unwrap(), 0).unwrap();
    dt.draw_text(
        &font,
        30.,
        "3",
        Point::new(0., 30.),
        &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
        &DrawOptions::new(),
    );
    dt.fill_rect(0., 35., 40., 5., &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
    &DrawOptions::new() );

    dt.write_png("out.png").unwrap();
}
examples/capabilities.rs (line 12)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
fn main() {
    let mut dt = DrawTarget::new(400, 400);

    let mut pb = PathBuilder::new();
    pb.move_to(340., 190.);
    pb.arc(160., 190., 180., 0., 2. * 3.14159);
    pb.close();
    let path = pb.finish();
    dt.push_clip(&path);

    let mut pb = PathBuilder::new();
    pb.move_to(0., 0.);
    pb.line_to(200., 0.);
    pb.line_to(200., 300.);
    pb.line_to(0., 300.);
    pb.close();
    let path = pb.finish();
    dt.fill(
        &path,
        &Source::Solid(SolidSource {
            r: 0x80,
            g: 0x80,
            b: 0,
            a: 0x80,
        }),
        &DrawOptions::new(),
    );

    let mut pb = PathBuilder::new();
    pb.move_to(50., 50.);
    pb.line_to(100., 70.);
    pb.line_to(110., 150.);
    pb.line_to(40., 180.);
    pb.close();

    /*
    dt.move_to(100., 10.);
    dt.quad_to(150., 40., 200., 10.);
    dt.quad_to(120., 100., 80., 200.);
    dt.quad_to(150., 180., 200., 200.);
    dt.close();
    */

    pb.move_to(100., 10.);
    pb.cubic_to(150., 40., 175., 0., 200., 10.);
    pb.quad_to(120., 100., 80., 200.);
    pb.quad_to(150., 180., 200., 200.);
    pb.close();

    let path = pb.finish();

    let decoder = png::Decoder::new(File::open("photo.png").unwrap());
    let mut reader = decoder.read_info().unwrap();
    let mut buf = vec![0; reader.output_buffer_size()];
    let info = reader.next_frame(&mut buf).unwrap();

    println!("{:?}", info.color_type);

    let mut image: Vec<u32> = Vec::new();
    for i in buf.chunks(3) {
        image.push(0xff << 24 | ((i[0] as u32) << 16) | ((i[1] as u32) << 8) | (i[2] as u32))
    }
    let _bitmap = Image {
        width: info.width as i32,
        height: info.height as i32,
        data: &image[..],
    };

    //dt.fill(Source::Solid(SolidSource{r: 0xff, g: 0xff, b: 0, a: 0xff}));
    //dt.fill(Source::Bitmap(bitmap, Transform::create_scale(2., 2.)));

    let gradient = Source::RadialGradient(
        Gradient {
            stops: vec![
                GradientStop {
                    position: 0.2,
                    color: Color::new(0xff, 0x00, 0xff, 0x00),
                },
                GradientStop {
                    position: 0.8,
                    color: Color::new(0xff, 0xff, 0xff, 0xff),
                },
                GradientStop {
                    position: 1.,
                    color: Color::new(0xff, 0xff, 0x00, 0xff),
                },
            ],
        },
        Spread::Pad,
        Transform::translation(-150., -150.),
    );
    dt.fill(&path, &gradient, &DrawOptions::new());

    let mut pb = PathBuilder::new();
    pb.move_to(200., 200.);
    pb.line_to(300., 300.);
    pb.line_to(200., 300.);

    let path = pb.finish();
    dt.stroke(
        &path,
        &gradient,
        &StrokeStyle {
            cap: LineCap::Butt,
            join: LineJoin::Bevel,
            width: 10.,
            miter_limit: 2.,
            dash_array: vec![10., 5.],
            dash_offset: 3.,
        },
        &DrawOptions::new(),
    );

    let font = SystemSource::new()
        .select_best_match(&[FamilyName::SansSerif], &Properties::new())
        .unwrap()
        .load()
        .unwrap();

    dt.draw_text(
        &font,
        24.,
        "Hello",
        Point::new(0., 100.),
        &Source::Solid(SolidSource {
            r: 0,
            g: 0,
            b: 0xff,
            a: 0xff,
        }),
        &DrawOptions::new(),
    );

    dt.write_png("out.png").unwrap();
}
source

pub fn from_vec(width: i32, height: i32, vec: Vec<u32>) -> DrawTarget

Use a previously used vector for the bitmap and extend it to the given size(if needed)

source

pub fn into_vec(self) -> Vec<u32>

Take ownership of the buffer backing the DrawTarget

source§

impl<Backing: AsRef<[u32]> + AsMut<[u32]>> DrawTarget<Backing>

source

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).

source

pub fn width(&self) -> i32

source

pub fn height(&self) -> i32

source

pub fn set_transform(&mut self, transform: &Transform)

sets a transform that will be applied to all drawing operations

Examples found in repository?
examples/stroke-arc.rs (line 11)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() {
    let mut dt = DrawTarget::new(400, 400);

    let mut pb = PathBuilder::new();
    pb.arc(0., 0., 20., 0., std::f32::consts::PI);

    let path = pb.finish();
    dt.set_transform(&Transform::translation(50., 50.));
    dt.stroke(
        &path,
        &Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
        &StrokeStyle {
            width: 40., // <--
            ..StrokeStyle::default()
        },
        &DrawOptions::new(),
    );

    dt.write_png("out.png").unwrap();
}
More examples
Hide additional examples
examples/text.rs (line 23)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
fn main() {
    let mut dt = DrawTarget::new(300, 100);
    dt.clear(SolidSource::from_unpremultiplied_argb(
        0xff, 0xcf, 0xcf, 0xcf,
    ));

    let font = SystemSource::new()
        .select_best_match(
            &[FamilyName::Title("Roboto".into())],
            &Properties::new().weight(Weight::MEDIUM),
        )
        .unwrap()
        .load()
        .unwrap();
    println!("{:?}", font);

    //dt.set_transform(&Transform::create_translation(50.0, 0.0));
    dt.set_transform(&Transform::rotation(euclid::Angle::degrees(15.0)));
    let font = font_kit::loader::Loader::from_file(&mut std::fs::File::open("res/Box3.ttf").unwrap(), 0).unwrap();
    dt.draw_text(
        &font,
        30.,
        "3",
        Point::new(0., 30.),
        &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
        &DrawOptions::new(),
    );
    dt.fill_rect(0., 35., 40., 5., &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
    &DrawOptions::new() );

    dt.write_png("out.png").unwrap();
}
source

pub fn get_transform(&self) -> &Transform

gets the current transform

source

pub fn push_clip_rect(&mut self, rect: IntRect)

source

pub fn pop_clip(&mut self)

source

pub fn push_clip(&mut self, path: &Path)

Examples found in repository?
examples/capabilities.rs (line 19)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
fn main() {
    let mut dt = DrawTarget::new(400, 400);

    let mut pb = PathBuilder::new();
    pb.move_to(340., 190.);
    pb.arc(160., 190., 180., 0., 2. * 3.14159);
    pb.close();
    let path = pb.finish();
    dt.push_clip(&path);

    let mut pb = PathBuilder::new();
    pb.move_to(0., 0.);
    pb.line_to(200., 0.);
    pb.line_to(200., 300.);
    pb.line_to(0., 300.);
    pb.close();
    let path = pb.finish();
    dt.fill(
        &path,
        &Source::Solid(SolidSource {
            r: 0x80,
            g: 0x80,
            b: 0,
            a: 0x80,
        }),
        &DrawOptions::new(),
    );

    let mut pb = PathBuilder::new();
    pb.move_to(50., 50.);
    pb.line_to(100., 70.);
    pb.line_to(110., 150.);
    pb.line_to(40., 180.);
    pb.close();

    /*
    dt.move_to(100., 10.);
    dt.quad_to(150., 40., 200., 10.);
    dt.quad_to(120., 100., 80., 200.);
    dt.quad_to(150., 180., 200., 200.);
    dt.close();
    */

    pb.move_to(100., 10.);
    pb.cubic_to(150., 40., 175., 0., 200., 10.);
    pb.quad_to(120., 100., 80., 200.);
    pb.quad_to(150., 180., 200., 200.);
    pb.close();

    let path = pb.finish();

    let decoder = png::Decoder::new(File::open("photo.png").unwrap());
    let mut reader = decoder.read_info().unwrap();
    let mut buf = vec![0; reader.output_buffer_size()];
    let info = reader.next_frame(&mut buf).unwrap();

    println!("{:?}", info.color_type);

    let mut image: Vec<u32> = Vec::new();
    for i in buf.chunks(3) {
        image.push(0xff << 24 | ((i[0] as u32) << 16) | ((i[1] as u32) << 8) | (i[2] as u32))
    }
    let _bitmap = Image {
        width: info.width as i32,
        height: info.height as i32,
        data: &image[..],
    };

    //dt.fill(Source::Solid(SolidSource{r: 0xff, g: 0xff, b: 0, a: 0xff}));
    //dt.fill(Source::Bitmap(bitmap, Transform::create_scale(2., 2.)));

    let gradient = Source::RadialGradient(
        Gradient {
            stops: vec![
                GradientStop {
                    position: 0.2,
                    color: Color::new(0xff, 0x00, 0xff, 0x00),
                },
                GradientStop {
                    position: 0.8,
                    color: Color::new(0xff, 0xff, 0xff, 0xff),
                },
                GradientStop {
                    position: 1.,
                    color: Color::new(0xff, 0xff, 0x00, 0xff),
                },
            ],
        },
        Spread::Pad,
        Transform::translation(-150., -150.),
    );
    dt.fill(&path, &gradient, &DrawOptions::new());

    let mut pb = PathBuilder::new();
    pb.move_to(200., 200.);
    pb.line_to(300., 300.);
    pb.line_to(200., 300.);

    let path = pb.finish();
    dt.stroke(
        &path,
        &gradient,
        &StrokeStyle {
            cap: LineCap::Butt,
            join: LineJoin::Bevel,
            width: 10.,
            miter_limit: 2.,
            dash_array: vec![10., 5.],
            dash_offset: 3.,
        },
        &DrawOptions::new(),
    );

    let font = SystemSource::new()
        .select_best_match(&[FamilyName::SansSerif], &Properties::new())
        .unwrap()
        .load()
        .unwrap();

    dt.draw_text(
        &font,
        24.,
        "Hello",
        Point::new(0., 100.),
        &Source::Solid(SolidSource {
            r: 0,
            g: 0,
            b: 0xff,
            a: 0xff,
        }),
        &DrawOptions::new(),
    );

    dt.write_png("out.png").unwrap();
}
source

pub fn push_layer(&mut self, opacity: f32)

Pushes a new layer as the drawing target. This is used for implementing group opacity effects.

source

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.

source

pub fn pop_layer(&mut self)

Draws the most recently pushed layer to the drawing target with the pushed opacity applied.

source

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.

source

pub fn draw_image_at( &mut self, x: f32, y: f32, image: &Image<'_>, options: &DrawOptions )

Draws an image at x, y

source

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

source

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?
examples/stroke.rs (lines 12-20)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() {
    let mut dt = DrawTarget::new(400, 400);

    let mut pb = PathBuilder::new();
    pb.move_to(200., 200.);
    pb.line_to(300., 300.);
    pb.line_to(200., 300.);

    let path = pb.finish();
    dt.stroke(
        &path,
        &Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
        &StrokeStyle {
            width: 100000., // <--
            ..StrokeStyle::default()
        },
        &DrawOptions::new(),
    );

    dt.write_png("out.png").unwrap();
}
More examples
Hide additional examples
examples/stroke-arc.rs (lines 12-20)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() {
    let mut dt = DrawTarget::new(400, 400);

    let mut pb = PathBuilder::new();
    pb.arc(0., 0., 20., 0., std::f32::consts::PI);

    let path = pb.finish();
    dt.set_transform(&Transform::translation(50., 50.));
    dt.stroke(
        &path,
        &Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
        &StrokeStyle {
            width: 40., // <--
            ..StrokeStyle::default()
        },
        &DrawOptions::new(),
    );

    dt.write_png("out.png").unwrap();
}
examples/capabilities.rs (lines 110-122)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
fn main() {
    let mut dt = DrawTarget::new(400, 400);

    let mut pb = PathBuilder::new();
    pb.move_to(340., 190.);
    pb.arc(160., 190., 180., 0., 2. * 3.14159);
    pb.close();
    let path = pb.finish();
    dt.push_clip(&path);

    let mut pb = PathBuilder::new();
    pb.move_to(0., 0.);
    pb.line_to(200., 0.);
    pb.line_to(200., 300.);
    pb.line_to(0., 300.);
    pb.close();
    let path = pb.finish();
    dt.fill(
        &path,
        &Source::Solid(SolidSource {
            r: 0x80,
            g: 0x80,
            b: 0,
            a: 0x80,
        }),
        &DrawOptions::new(),
    );

    let mut pb = PathBuilder::new();
    pb.move_to(50., 50.);
    pb.line_to(100., 70.);
    pb.line_to(110., 150.);
    pb.line_to(40., 180.);
    pb.close();

    /*
    dt.move_to(100., 10.);
    dt.quad_to(150., 40., 200., 10.);
    dt.quad_to(120., 100., 80., 200.);
    dt.quad_to(150., 180., 200., 200.);
    dt.close();
    */

    pb.move_to(100., 10.);
    pb.cubic_to(150., 40., 175., 0., 200., 10.);
    pb.quad_to(120., 100., 80., 200.);
    pb.quad_to(150., 180., 200., 200.);
    pb.close();

    let path = pb.finish();

    let decoder = png::Decoder::new(File::open("photo.png").unwrap());
    let mut reader = decoder.read_info().unwrap();
    let mut buf = vec![0; reader.output_buffer_size()];
    let info = reader.next_frame(&mut buf).unwrap();

    println!("{:?}", info.color_type);

    let mut image: Vec<u32> = Vec::new();
    for i in buf.chunks(3) {
        image.push(0xff << 24 | ((i[0] as u32) << 16) | ((i[1] as u32) << 8) | (i[2] as u32))
    }
    let _bitmap = Image {
        width: info.width as i32,
        height: info.height as i32,
        data: &image[..],
    };

    //dt.fill(Source::Solid(SolidSource{r: 0xff, g: 0xff, b: 0, a: 0xff}));
    //dt.fill(Source::Bitmap(bitmap, Transform::create_scale(2., 2.)));

    let gradient = Source::RadialGradient(
        Gradient {
            stops: vec![
                GradientStop {
                    position: 0.2,
                    color: Color::new(0xff, 0x00, 0xff, 0x00),
                },
                GradientStop {
                    position: 0.8,
                    color: Color::new(0xff, 0xff, 0xff, 0xff),
                },
                GradientStop {
                    position: 1.,
                    color: Color::new(0xff, 0xff, 0x00, 0xff),
                },
            ],
        },
        Spread::Pad,
        Transform::translation(-150., -150.),
    );
    dt.fill(&path, &gradient, &DrawOptions::new());

    let mut pb = PathBuilder::new();
    pb.move_to(200., 200.);
    pb.line_to(300., 300.);
    pb.line_to(200., 300.);

    let path = pb.finish();
    dt.stroke(
        &path,
        &gradient,
        &StrokeStyle {
            cap: LineCap::Butt,
            join: LineJoin::Bevel,
            width: 10.,
            miter_limit: 2.,
            dash_array: vec![10., 5.],
            dash_offset: 3.,
        },
        &DrawOptions::new(),
    );

    let font = SystemSource::new()
        .select_best_match(&[FamilyName::SansSerif], &Properties::new())
        .unwrap()
        .load()
        .unwrap();

    dt.draw_text(
        &font,
        24.,
        "Hello",
        Point::new(0., 100.),
        &Source::Solid(SolidSource {
            r: 0,
            g: 0,
            b: 0xff,
            a: 0xff,
        }),
        &DrawOptions::new(),
    );

    dt.write_png("out.png").unwrap();
}
source

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?
examples/text.rs (lines 33-34)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
fn main() {
    let mut dt = DrawTarget::new(300, 100);
    dt.clear(SolidSource::from_unpremultiplied_argb(
        0xff, 0xcf, 0xcf, 0xcf,
    ));

    let font = SystemSource::new()
        .select_best_match(
            &[FamilyName::Title("Roboto".into())],
            &Properties::new().weight(Weight::MEDIUM),
        )
        .unwrap()
        .load()
        .unwrap();
    println!("{:?}", font);

    //dt.set_transform(&Transform::create_translation(50.0, 0.0));
    dt.set_transform(&Transform::rotation(euclid::Angle::degrees(15.0)));
    let font = font_kit::loader::Loader::from_file(&mut std::fs::File::open("res/Box3.ttf").unwrap(), 0).unwrap();
    dt.draw_text(
        &font,
        30.,
        "3",
        Point::new(0., 30.),
        &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
        &DrawOptions::new(),
    );
    dt.fill_rect(0., 35., 40., 5., &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
    &DrawOptions::new() );

    dt.write_png("out.png").unwrap();
}
source

pub fn fill(&mut self, path: &Path, src: &Source<'_>, options: &DrawOptions)

Fills path with src

Examples found in repository?
examples/sweep-gradient.rs (line 32)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
fn main() {
    use raqote::*;

let mut dt = DrawTarget::new(400, 400);

let mut pb = PathBuilder::new();
pb.rect(0., 0., 400., 400.);
let path = pb.finish();

let gradient = Source::new_sweep_gradient(
    Gradient {
        stops: vec![
            GradientStop {
                position: 0.,
                color: Color::new(0xff, 0, 0, 0),
            },
            GradientStop {
                position: 0.5,
                color: Color::new(0xff, 0xff, 0xff, 0x0),
            },
            GradientStop {
                position: 1.,
                color: Color::new(0xff, 0, 0, 0x0),
            },
        ],
    },
    Point::new(150., 200.),
    45.,
    180.+45.,
    Spread::Repeat,
);
dt.fill(&path, &gradient, &DrawOptions::new());



dt.write_png("example.png");
}
More examples
Hide additional examples
examples/pad.rs (line 38)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
fn main() {
    let mut dt = DrawTarget::new(200, 200);
    
    let gradient = Source::new_linear_gradient(
        Gradient {
            stops: vec![
                GradientStop {
                    position: 0.0,
                    color: Color::new(0xff, 0xff, 0xff, 0xff),
                },
                GradientStop {
                    position: 0.9999,
                    color: Color::new(0xff, 0x0, 0x0, 0x0),
                },
                GradientStop {
                    position: 1.0,
                    color: Color::new(0xff, 0x0, 0x0, 0x0),
                },
            ],
        },
        Point::new(40., 0.),
        Point::new(100., 0.),
        Spread::Pad,
    );

    let mut pb = PathBuilder::new();
    pb.rect(0., 0., 80., 80.);
    let path = pb.finish();
    dt.fill(&path, &gradient, &DrawOptions::default());

    dt.write_png("out.png").unwrap();
}
examples/capabilities.rs (lines 28-37)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
fn main() {
    let mut dt = DrawTarget::new(400, 400);

    let mut pb = PathBuilder::new();
    pb.move_to(340., 190.);
    pb.arc(160., 190., 180., 0., 2. * 3.14159);
    pb.close();
    let path = pb.finish();
    dt.push_clip(&path);

    let mut pb = PathBuilder::new();
    pb.move_to(0., 0.);
    pb.line_to(200., 0.);
    pb.line_to(200., 300.);
    pb.line_to(0., 300.);
    pb.close();
    let path = pb.finish();
    dt.fill(
        &path,
        &Source::Solid(SolidSource {
            r: 0x80,
            g: 0x80,
            b: 0,
            a: 0x80,
        }),
        &DrawOptions::new(),
    );

    let mut pb = PathBuilder::new();
    pb.move_to(50., 50.);
    pb.line_to(100., 70.);
    pb.line_to(110., 150.);
    pb.line_to(40., 180.);
    pb.close();

    /*
    dt.move_to(100., 10.);
    dt.quad_to(150., 40., 200., 10.);
    dt.quad_to(120., 100., 80., 200.);
    dt.quad_to(150., 180., 200., 200.);
    dt.close();
    */

    pb.move_to(100., 10.);
    pb.cubic_to(150., 40., 175., 0., 200., 10.);
    pb.quad_to(120., 100., 80., 200.);
    pb.quad_to(150., 180., 200., 200.);
    pb.close();

    let path = pb.finish();

    let decoder = png::Decoder::new(File::open("photo.png").unwrap());
    let mut reader = decoder.read_info().unwrap();
    let mut buf = vec![0; reader.output_buffer_size()];
    let info = reader.next_frame(&mut buf).unwrap();

    println!("{:?}", info.color_type);

    let mut image: Vec<u32> = Vec::new();
    for i in buf.chunks(3) {
        image.push(0xff << 24 | ((i[0] as u32) << 16) | ((i[1] as u32) << 8) | (i[2] as u32))
    }
    let _bitmap = Image {
        width: info.width as i32,
        height: info.height as i32,
        data: &image[..],
    };

    //dt.fill(Source::Solid(SolidSource{r: 0xff, g: 0xff, b: 0, a: 0xff}));
    //dt.fill(Source::Bitmap(bitmap, Transform::create_scale(2., 2.)));

    let gradient = Source::RadialGradient(
        Gradient {
            stops: vec![
                GradientStop {
                    position: 0.2,
                    color: Color::new(0xff, 0x00, 0xff, 0x00),
                },
                GradientStop {
                    position: 0.8,
                    color: Color::new(0xff, 0xff, 0xff, 0xff),
                },
                GradientStop {
                    position: 1.,
                    color: Color::new(0xff, 0xff, 0x00, 0xff),
                },
            ],
        },
        Spread::Pad,
        Transform::translation(-150., -150.),
    );
    dt.fill(&path, &gradient, &DrawOptions::new());

    let mut pb = PathBuilder::new();
    pb.move_to(200., 200.);
    pb.line_to(300., 300.);
    pb.line_to(200., 300.);

    let path = pb.finish();
    dt.stroke(
        &path,
        &gradient,
        &StrokeStyle {
            cap: LineCap::Butt,
            join: LineJoin::Bevel,
            width: 10.,
            miter_limit: 2.,
            dash_array: vec![10., 5.],
            dash_offset: 3.,
        },
        &DrawOptions::new(),
    );

    let font = SystemSource::new()
        .select_best_match(&[FamilyName::SansSerif], &Properties::new())
        .unwrap()
        .load()
        .unwrap();

    dt.draw_text(
        &font,
        24.,
        "Hello",
        Point::new(0., 100.),
        &Source::Solid(SolidSource {
            r: 0,
            g: 0,
            b: 0xff,
            a: 0xff,
        }),
        &DrawOptions::new(),
    );

    dt.write_png("out.png").unwrap();
}
source

pub fn clear(&mut self, solid: SolidSource)

Fills the current clip with the solid color solid

Examples found in repository?
examples/text.rs (lines 8-10)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
fn main() {
    let mut dt = DrawTarget::new(300, 100);
    dt.clear(SolidSource::from_unpremultiplied_argb(
        0xff, 0xcf, 0xcf, 0xcf,
    ));

    let font = SystemSource::new()
        .select_best_match(
            &[FamilyName::Title("Roboto".into())],
            &Properties::new().weight(Weight::MEDIUM),
        )
        .unwrap()
        .load()
        .unwrap();
    println!("{:?}", font);

    //dt.set_transform(&Transform::create_translation(50.0, 0.0));
    dt.set_transform(&Transform::rotation(euclid::Angle::degrees(15.0)));
    let font = font_kit::loader::Loader::from_file(&mut std::fs::File::open("res/Box3.ttf").unwrap(), 0).unwrap();
    dt.draw_text(
        &font,
        30.,
        "3",
        Point::new(0., 30.),
        &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
        &DrawOptions::new(),
    );
    dt.fill_rect(0., 35., 40., 5., &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
    &DrawOptions::new() );

    dt.write_png("out.png").unwrap();
}
source

pub fn draw_text( &mut self, font: &Font, point_size: f32, text: &str, start: Point, src: &Source<'_>, options: &DrawOptions )

Examples found in repository?
examples/text.rs (lines 25-32)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
fn main() {
    let mut dt = DrawTarget::new(300, 100);
    dt.clear(SolidSource::from_unpremultiplied_argb(
        0xff, 0xcf, 0xcf, 0xcf,
    ));

    let font = SystemSource::new()
        .select_best_match(
            &[FamilyName::Title("Roboto".into())],
            &Properties::new().weight(Weight::MEDIUM),
        )
        .unwrap()
        .load()
        .unwrap();
    println!("{:?}", font);

    //dt.set_transform(&Transform::create_translation(50.0, 0.0));
    dt.set_transform(&Transform::rotation(euclid::Angle::degrees(15.0)));
    let font = font_kit::loader::Loader::from_file(&mut std::fs::File::open("res/Box3.ttf").unwrap(), 0).unwrap();
    dt.draw_text(
        &font,
        30.,
        "3",
        Point::new(0., 30.),
        &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
        &DrawOptions::new(),
    );
    dt.fill_rect(0., 35., 40., 5., &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
    &DrawOptions::new() );

    dt.write_png("out.png").unwrap();
}
More examples
Hide additional examples
examples/capabilities.rs (lines 130-142)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
fn main() {
    let mut dt = DrawTarget::new(400, 400);

    let mut pb = PathBuilder::new();
    pb.move_to(340., 190.);
    pb.arc(160., 190., 180., 0., 2. * 3.14159);
    pb.close();
    let path = pb.finish();
    dt.push_clip(&path);

    let mut pb = PathBuilder::new();
    pb.move_to(0., 0.);
    pb.line_to(200., 0.);
    pb.line_to(200., 300.);
    pb.line_to(0., 300.);
    pb.close();
    let path = pb.finish();
    dt.fill(
        &path,
        &Source::Solid(SolidSource {
            r: 0x80,
            g: 0x80,
            b: 0,
            a: 0x80,
        }),
        &DrawOptions::new(),
    );

    let mut pb = PathBuilder::new();
    pb.move_to(50., 50.);
    pb.line_to(100., 70.);
    pb.line_to(110., 150.);
    pb.line_to(40., 180.);
    pb.close();

    /*
    dt.move_to(100., 10.);
    dt.quad_to(150., 40., 200., 10.);
    dt.quad_to(120., 100., 80., 200.);
    dt.quad_to(150., 180., 200., 200.);
    dt.close();
    */

    pb.move_to(100., 10.);
    pb.cubic_to(150., 40., 175., 0., 200., 10.);
    pb.quad_to(120., 100., 80., 200.);
    pb.quad_to(150., 180., 200., 200.);
    pb.close();

    let path = pb.finish();

    let decoder = png::Decoder::new(File::open("photo.png").unwrap());
    let mut reader = decoder.read_info().unwrap();
    let mut buf = vec![0; reader.output_buffer_size()];
    let info = reader.next_frame(&mut buf).unwrap();

    println!("{:?}", info.color_type);

    let mut image: Vec<u32> = Vec::new();
    for i in buf.chunks(3) {
        image.push(0xff << 24 | ((i[0] as u32) << 16) | ((i[1] as u32) << 8) | (i[2] as u32))
    }
    let _bitmap = Image {
        width: info.width as i32,
        height: info.height as i32,
        data: &image[..],
    };

    //dt.fill(Source::Solid(SolidSource{r: 0xff, g: 0xff, b: 0, a: 0xff}));
    //dt.fill(Source::Bitmap(bitmap, Transform::create_scale(2., 2.)));

    let gradient = Source::RadialGradient(
        Gradient {
            stops: vec![
                GradientStop {
                    position: 0.2,
                    color: Color::new(0xff, 0x00, 0xff, 0x00),
                },
                GradientStop {
                    position: 0.8,
                    color: Color::new(0xff, 0xff, 0xff, 0xff),
                },
                GradientStop {
                    position: 1.,
                    color: Color::new(0xff, 0xff, 0x00, 0xff),
                },
            ],
        },
        Spread::Pad,
        Transform::translation(-150., -150.),
    );
    dt.fill(&path, &gradient, &DrawOptions::new());

    let mut pb = PathBuilder::new();
    pb.move_to(200., 200.);
    pb.line_to(300., 300.);
    pb.line_to(200., 300.);

    let path = pb.finish();
    dt.stroke(
        &path,
        &gradient,
        &StrokeStyle {
            cap: LineCap::Butt,
            join: LineJoin::Bevel,
            width: 10.,
            miter_limit: 2.,
            dash_array: vec![10., 5.],
            dash_offset: 3.,
        },
        &DrawOptions::new(),
    );

    let font = SystemSource::new()
        .select_best_match(&[FamilyName::SansSerif], &Properties::new())
        .unwrap()
        .load()
        .unwrap();

    dt.draw_text(
        &font,
        24.,
        "Hello",
        Point::new(0., 100.),
        &Source::Solid(SolidSource {
            r: 0,
            g: 0,
            b: 0xff,
            a: 0xff,
        }),
        &DrawOptions::new(),
    );

    dt.write_png("out.png").unwrap();
}
source

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>

source

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

source

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).

source

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 dstusing blend mode. The current transform and clip are ignored. src_rect is clamped to (0, 0, src.width, src.height).

source

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).

source

pub fn get_data(&self) -> &[u32]

Returns a reference to the underlying pixel data

source

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

source

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.

source

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.

source

pub fn into_inner(self) -> Backing

Take ownership of the buffer backing the DrawTarget

source

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?
examples/stroke.rs (line 22)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() {
    let mut dt = DrawTarget::new(400, 400);

    let mut pb = PathBuilder::new();
    pb.move_to(200., 200.);
    pb.line_to(300., 300.);
    pb.line_to(200., 300.);

    let path = pb.finish();
    dt.stroke(
        &path,
        &Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
        &StrokeStyle {
            width: 100000., // <--
            ..StrokeStyle::default()
        },
        &DrawOptions::new(),
    );

    dt.write_png("out.png").unwrap();
}
More examples
Hide additional examples
examples/stroke-arc.rs (line 22)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fn main() {
    let mut dt = DrawTarget::new(400, 400);

    let mut pb = PathBuilder::new();
    pb.arc(0., 0., 20., 0., std::f32::consts::PI);

    let path = pb.finish();
    dt.set_transform(&Transform::translation(50., 50.));
    dt.stroke(
        &path,
        &Source::Solid(SolidSource::from_unpremultiplied_argb(0xFF, 0, 0x80, 0)),
        &StrokeStyle {
            width: 40., // <--
            ..StrokeStyle::default()
        },
        &DrawOptions::new(),
    );

    dt.write_png("out.png").unwrap();
}
examples/sweep-gradient.rs (line 36)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
fn main() {
    use raqote::*;

let mut dt = DrawTarget::new(400, 400);

let mut pb = PathBuilder::new();
pb.rect(0., 0., 400., 400.);
let path = pb.finish();

let gradient = Source::new_sweep_gradient(
    Gradient {
        stops: vec![
            GradientStop {
                position: 0.,
                color: Color::new(0xff, 0, 0, 0),
            },
            GradientStop {
                position: 0.5,
                color: Color::new(0xff, 0xff, 0xff, 0x0),
            },
            GradientStop {
                position: 1.,
                color: Color::new(0xff, 0, 0, 0x0),
            },
        ],
    },
    Point::new(150., 200.),
    45.,
    180.+45.,
    Spread::Repeat,
);
dt.fill(&path, &gradient, &DrawOptions::new());



dt.write_png("example.png");
}
examples/pad.rs (line 40)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
fn main() {
    let mut dt = DrawTarget::new(200, 200);
    
    let gradient = Source::new_linear_gradient(
        Gradient {
            stops: vec![
                GradientStop {
                    position: 0.0,
                    color: Color::new(0xff, 0xff, 0xff, 0xff),
                },
                GradientStop {
                    position: 0.9999,
                    color: Color::new(0xff, 0x0, 0x0, 0x0),
                },
                GradientStop {
                    position: 1.0,
                    color: Color::new(0xff, 0x0, 0x0, 0x0),
                },
            ],
        },
        Point::new(40., 0.),
        Point::new(100., 0.),
        Spread::Pad,
    );

    let mut pb = PathBuilder::new();
    pb.rect(0., 0., 80., 80.);
    let path = pb.finish();
    dt.fill(&path, &gradient, &DrawOptions::default());

    dt.write_png("out.png").unwrap();
}
examples/text.rs (line 36)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
fn main() {
    let mut dt = DrawTarget::new(300, 100);
    dt.clear(SolidSource::from_unpremultiplied_argb(
        0xff, 0xcf, 0xcf, 0xcf,
    ));

    let font = SystemSource::new()
        .select_best_match(
            &[FamilyName::Title("Roboto".into())],
            &Properties::new().weight(Weight::MEDIUM),
        )
        .unwrap()
        .load()
        .unwrap();
    println!("{:?}", font);

    //dt.set_transform(&Transform::create_translation(50.0, 0.0));
    dt.set_transform(&Transform::rotation(euclid::Angle::degrees(15.0)));
    let font = font_kit::loader::Loader::from_file(&mut std::fs::File::open("res/Box3.ttf").unwrap(), 0).unwrap();
    dt.draw_text(
        &font,
        30.,
        "3",
        Point::new(0., 30.),
        &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
        &DrawOptions::new(),
    );
    dt.fill_rect(0., 35., 40., 5., &Source::Solid(SolidSource::from_unpremultiplied_argb(255, 0, 180, 0)),
    &DrawOptions::new() );

    dt.write_png("out.png").unwrap();
}
examples/capabilities.rs (line 144)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
fn main() {
    let mut dt = DrawTarget::new(400, 400);

    let mut pb = PathBuilder::new();
    pb.move_to(340., 190.);
    pb.arc(160., 190., 180., 0., 2. * 3.14159);
    pb.close();
    let path = pb.finish();
    dt.push_clip(&path);

    let mut pb = PathBuilder::new();
    pb.move_to(0., 0.);
    pb.line_to(200., 0.);
    pb.line_to(200., 300.);
    pb.line_to(0., 300.);
    pb.close();
    let path = pb.finish();
    dt.fill(
        &path,
        &Source::Solid(SolidSource {
            r: 0x80,
            g: 0x80,
            b: 0,
            a: 0x80,
        }),
        &DrawOptions::new(),
    );

    let mut pb = PathBuilder::new();
    pb.move_to(50., 50.);
    pb.line_to(100., 70.);
    pb.line_to(110., 150.);
    pb.line_to(40., 180.);
    pb.close();

    /*
    dt.move_to(100., 10.);
    dt.quad_to(150., 40., 200., 10.);
    dt.quad_to(120., 100., 80., 200.);
    dt.quad_to(150., 180., 200., 200.);
    dt.close();
    */

    pb.move_to(100., 10.);
    pb.cubic_to(150., 40., 175., 0., 200., 10.);
    pb.quad_to(120., 100., 80., 200.);
    pb.quad_to(150., 180., 200., 200.);
    pb.close();

    let path = pb.finish();

    let decoder = png::Decoder::new(File::open("photo.png").unwrap());
    let mut reader = decoder.read_info().unwrap();
    let mut buf = vec![0; reader.output_buffer_size()];
    let info = reader.next_frame(&mut buf).unwrap();

    println!("{:?}", info.color_type);

    let mut image: Vec<u32> = Vec::new();
    for i in buf.chunks(3) {
        image.push(0xff << 24 | ((i[0] as u32) << 16) | ((i[1] as u32) << 8) | (i[2] as u32))
    }
    let _bitmap = Image {
        width: info.width as i32,
        height: info.height as i32,
        data: &image[..],
    };

    //dt.fill(Source::Solid(SolidSource{r: 0xff, g: 0xff, b: 0, a: 0xff}));
    //dt.fill(Source::Bitmap(bitmap, Transform::create_scale(2., 2.)));

    let gradient = Source::RadialGradient(
        Gradient {
            stops: vec![
                GradientStop {
                    position: 0.2,
                    color: Color::new(0xff, 0x00, 0xff, 0x00),
                },
                GradientStop {
                    position: 0.8,
                    color: Color::new(0xff, 0xff, 0xff, 0xff),
                },
                GradientStop {
                    position: 1.,
                    color: Color::new(0xff, 0xff, 0x00, 0xff),
                },
            ],
        },
        Spread::Pad,
        Transform::translation(-150., -150.),
    );
    dt.fill(&path, &gradient, &DrawOptions::new());

    let mut pb = PathBuilder::new();
    pb.move_to(200., 200.);
    pb.line_to(300., 300.);
    pb.line_to(200., 300.);

    let path = pb.finish();
    dt.stroke(
        &path,
        &gradient,
        &StrokeStyle {
            cap: LineCap::Butt,
            join: LineJoin::Bevel,
            width: 10.,
            miter_limit: 2.,
            dash_array: vec![10., 5.],
            dash_offset: 3.,
        },
        &DrawOptions::new(),
    );

    let font = SystemSource::new()
        .select_best_match(&[FamilyName::SansSerif], &Properties::new())
        .unwrap()
        .load()
        .unwrap();

    dt.draw_text(
        &font,
        24.,
        "Hello",
        Point::new(0., 100.),
        &Source::Solid(SolidSource {
            r: 0,
            g: 0,
            b: 0xff,
            a: 0xff,
        }),
        &DrawOptions::new(),
    );

    dt.write_png("out.png").unwrap();
}

Auto Trait Implementations§

§

impl<Backing = Vec<u32>> !Freeze for DrawTarget<Backing>

§

impl<Backing = Vec<u32>> !RefUnwindSafe for DrawTarget<Backing>

§

impl<Backing = Vec<u32>> !Send for DrawTarget<Backing>

§

impl<Backing = Vec<u32>> !Sync for DrawTarget<Backing>

§

impl<Backing> Unpin for DrawTarget<Backing>
where Backing: Unpin,

§

impl<Backing> UnwindSafe for DrawTarget<Backing>
where Backing: UnwindSafe,

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, 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.