use crate::id::{ChapterId, DiagramId, FormulaId, PictureId};
use std::fmt;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Version {
pub major: u8,
pub minor: u8,
}
impl fmt::Display for Version {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}.{}", self.major, self.minor)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct Size {
pub width: u32,
pub height: u32,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Position {
pub chapter: ChapterId,
pub offset: u32,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ChapterEntry<'a> {
pub id: ChapterId,
pub path: &'a str,
pub decoded_len: u64,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct PictureEntry<'a> {
pub id: PictureId,
pub path: &'a str,
pub size: Size,
pub decoded_len: u64,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct DiagramEntry<'a> {
pub id: DiagramId,
pub path: &'a str,
pub decoded_len: u64,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct FormulaEntry<'a> {
pub id: FormulaId,
pub path: &'a str,
pub decoded_len: u64,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TocEntry {
pub level: u8,
pub title: String,
pub position: Position,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LandmarkEntry {
pub kind: String,
pub title: String,
pub position: Position,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Anchor {
pub offset: u32,
pub name: String,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Destination {
External,
Chapter(Position),
Picture(PictureId),
Diagram(DiagramId),
Formula(FormulaId),
ExtraAnchor(ChapterId),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ResourceKind {
Service,
Text,
Picture,
ChapterAnchors,
Landmarks,
Diagram,
Formula,
Unknown(u8),
}
impl From<u8> for ResourceKind {
fn from(code: u8) -> Self {
match code {
0 => Self::Service,
1 => Self::Text,
2 => Self::Picture,
3 => Self::ChapterAnchors,
4 => Self::Landmarks,
5 => Self::Diagram,
6 => Self::Formula,
other => Self::Unknown(other),
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Resource<'a> {
pub number: u32,
pub kind: ResourceKind,
pub path: &'a str,
pub size: Option<Size>,
pub decoded_len: u64,
}