tinyvg_rs/
lib.rs

1pub mod header;
2pub mod common;
3pub mod color_table;
4pub mod commands;
5#[cfg(feature = "svg-to-tvg")]
6pub mod svg_to_tvg;
7
8use crate::color_table::{parse_color_table, ColorTable};
9use crate::commands::{parse_draw_commands, DrawCommand};
10use crate::header::{CoordinateRange, TinyVgHeader};
11use std::io::{Cursor};
12
13#[derive(Debug, PartialEq)]
14pub enum TinyVgParseError {
15    None,
16    InvalidHeader,
17    InvalidColorTable,
18    InvalidCommand,
19}
20
21#[derive(Debug)]
22pub struct TinyVg {
23    pub header: TinyVgHeader,
24    pub color_table: ColorTable,
25    pub draw_commands: Vec<DrawCommand>
26}
27
28impl TinyVg {
29
30    pub fn from_bytes(data: &[u8]) -> Result<TinyVg, TinyVgParseError> {
31        let mut cursor = Cursor::new(data);
32
33        let header = TinyVgHeader::parse(&mut cursor)?;
34        let color_table = parse_color_table(&mut cursor, &header)?;
35        let draw_commands: Vec<DrawCommand> = parse_draw_commands(&mut cursor, &header)?;
36
37        Ok(TinyVg {
38            header,
39            color_table,
40            draw_commands,
41        })
42    }
43}