Current section
Files
Jump to
Current section
Files
native/rtfparser/src/header.rs
use std::collections::HashMap;
use crate::tokens::{ControlWord, Token};
pub type FontRef = u16;
pub type FontTable = HashMap<FontRef, Font>;
use rustler::{NifStruct, NifTaggedEnum};
#[derive(Default, Debug, Clone, PartialEq, NifStruct)]
#[module = "RtfParser.RtfHeader"]
pub struct RtfHeader {
pub character_set: CharacterSet,
pub font_table: FontTable,
pub stylesheet: StyleSheet,
}
#[derive(Hash, Default, Clone, Debug, PartialEq, NifStruct)]
#[module = "RtfParser.Font"]
pub struct Font {
pub name: String,
pub character_set: u8,
pub font_family: FontFamily,
}
#[allow(dead_code)]
#[derive(Debug, PartialEq, Default, Clone, NifTaggedEnum)]
pub enum CharacterSet {
#[default]
Ansi,
Mac,
Pc,
Pca,
Ansicpg(u16),
}
impl CharacterSet {
pub fn from(token: &Token) -> Option<Self> {
match token {
Token::ControlSymbol((ControlWord::Ansi, _)) => Some(Self::Ansi),
// TODO: implement the rest
_ => None,
}
}
}
#[allow(dead_code)]
#[derive(Debug, PartialEq, Hash, Clone, Default, NifTaggedEnum)]
pub enum FontFamily {
#[default]
Nil,
Roman,
Swiss,
Modern,
Script,
Decor,
Tech,
Bidi,
}
impl FontFamily {
pub fn from(string: &str) -> Option<Self> {
match string {
r"\fnil" => Some(Self::Nil),
r"\froman" => Some(Self::Roman),
r"\fswiss" => Some(Self::Swiss),
// TODO: implement the rest
_ => None,
}
}
}
#[derive(Default, Debug, Clone, PartialEq, NifStruct)]
#[module = "RtfParser.StyleSheet"]
pub struct StyleSheet;