Skip to content

Commit

Permalink
parsing: Annotations parsing basically ok
Browse files Browse the repository at this point in the history
rendering is not and some paths are hardcoded
  • Loading branch information
hualet committed Jan 24, 2025
1 parent 3128561 commit e08f6ce
Show file tree
Hide file tree
Showing 5 changed files with 535 additions and 87 deletions.
57 changes: 57 additions & 0 deletions src/document.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use serde::{Deserialize};

use crate::elements::*;

/* Document.xml
<?xml version="1.0" encoding="UTF-8"?><ofd:Document xmlns:ofd="http://www.ofdspec.org/2016">
<ofd:CommonData>
Expand Down Expand Up @@ -151,4 +153,59 @@ impl PublicRes {
pub fn from_xml(xml: &str) -> Result<PublicRes, serde_xml_rs::Error> {
serde_xml_rs::from_str(xml)
}
}


/* Annotations.xml
<?xml version="1.0" encoding="UTF-8"?>
<ofd:Annotations xmlns:ofd="http://www.ofdspec.org/2016">
<ofd:Page PageID="1">
<ofd:FileLoc>Page_0/Annot_0.xml</ofd:FileLoc>
</ofd:Page>
</ofd:Annotations>
*/

#[derive(Deserialize, Debug, Default)]
#[serde(rename_all = "PascalCase")]
pub struct Annotations {
pub page: Vec<AnnotationPageNode>,
}

#[derive(Deserialize, Debug, Default)]
#[serde(rename_all = "PascalCase")]
pub struct AnnotationPageNode {
#[serde(rename = "PageID")]
pub page_id: u32,
#[serde(rename = "$value")]
pub file_loc: String,
}

impl Annotations {
pub fn from_xml(xml: &str) -> Result<Annotations, serde_xml_rs::Error> {
serde_xml_rs::from_str(xml)
}
}


/* Annot_0.xml
<?xml version="1.0" encoding="UTF-8"?>
<ofd:PageAnnot xmlns:ofd="http://www.ofdspec.org/2016">
<ofd:Annot Type="Stamp" Creator="OFD R&amp;W" LastModDate="2024-10-22" ID="173">
<ofd:Appearance Boundary="87.50 8.50 30 20">
<ofd:ImageObject ID="175" ResourceID="174" Boundary="0 0 30 20" CTM="30 0 0 20 0 0"/>
</ofd:Appearance>
</ofd:Annot>
</ofd:PageAnnot>
*/

#[derive(Deserialize, Debug, Default)]
#[serde(rename_all = "PascalCase")]
pub struct PageAnnot {
pub annot: Vec<Annot>,
}

impl PageAnnot {
pub fn from_xml(xml: &str) -> Result<PageAnnot, serde_xml_rs::Error> {
serde_xml_rs::from_str(xml)
}
}
Loading

0 comments on commit e08f6ce

Please sign in to comment.