font_atlas/glyph_packer/
buffer2d.rs1pub trait Buffer2d: Sized {
2 type Pixel;
3
4 fn width(&self) -> u32;
5 fn height(&self) -> u32;
6
7 fn get(&self, x: u32, y: u32) -> Option<Self::Pixel>;
8 fn set(&mut self, x: u32, y: u32, _val: Self::Pixel);
9
10 fn patch<B: Buffer2d<Pixel=Self::Pixel>>
11 (&mut self, x: u32, y: u32, buf: &B) {
12 let (w, h) = buf.dimensions();
13
14 for sy in 0 .. h {
15 for sx in 0 .. w {
16
17 match buf.get(sx, sy) {
18 Some(val) => {
19 self.set(x + sx, y + sy, val);
20 },
21 _ => {},
22 }
23 }
24 }
25 }
26
27 fn patch_rotated<B: Buffer2d<Pixel=Self::Pixel>>
28 (&mut self, x: u32, y: u32, buf: &B) {
29 let (w, h) = buf.dimensions();
30
31 for sy in 0 .. h {
32 for sx in 0 .. w {
33 match buf.get(sx, sy) {
34 Some(val) => {
35 self.set(x + h - sy - 1, y + sx, val);
36 },
37 _ => {},
38 }
39 }
40 }
41 }
42
43 fn dimensions(&self) -> (u32, u32) {
44 (self.width(), self.height())
45 }
46}
47
48pub trait ResizeBuffer: Buffer2d {
49 fn resize(&mut self, width: u32, height: u32);
50}