-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hwp): GenShapeObject 파싱 준비 (#83)
- Loading branch information
Showing
9 changed files
with
117 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
crates/hwp/src/hwp/paragraph/control/shape_object/content.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use hwp_macro::make_4chid; | ||
|
||
use crate::hwp::{ | ||
paragraph::control::element_properties::ElementProperties, record::RecordCursor, | ||
unknown::UnknownRecord, | ||
}; | ||
|
||
use super::container::ContainerContent; | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum GenShapeObjectContent { | ||
Container(ContainerContent), | ||
Unknown(UnknownRecord), | ||
} | ||
|
||
pub fn parse_content( | ||
properties: &ElementProperties, | ||
cursor: &mut RecordCursor, | ||
) -> GenShapeObjectContent { | ||
match properties.ctrl_id { | ||
make_4chid!('$', 'c', 'o', 'n') => GenShapeObjectContent::Container( | ||
ContainerContent::from_record_cursor(properties, cursor), | ||
), | ||
_ => GenShapeObjectContent::Unknown(UnknownRecord::from_record_cursor(cursor)), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
pub mod arc; | ||
pub mod container; | ||
pub mod content; | ||
pub mod curve; | ||
pub mod ellipse; | ||
pub mod gen_shape_object; | ||
pub mod line; | ||
pub mod ole; | ||
pub mod picture; | ||
pub mod polygon; | ||
pub mod rectangle; |
5 changes: 3 additions & 2 deletions
5
crates/hwp/src/hwp/paragraph/control/ole.rs → ...hwp/paragraph/control/shape_object/ole.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use std::io::Read; | ||
|
||
use crate::hwp::record::{Record, RecordCursor}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct UnknownRecord { | ||
/// 태그 ID | ||
pub tag_id: u32, | ||
/// 데이터 | ||
pub data: Vec<u8>, | ||
/// 레코드 | ||
pub children: Vec<Record>, | ||
} | ||
|
||
impl UnknownRecord { | ||
pub fn from_record_cursor(cursor: &mut RecordCursor) -> Self { | ||
let record = cursor.current(); | ||
let mut reader = record.get_data_reader(); | ||
|
||
let tag_id = record.tag_id; | ||
let mut data = Vec::new(); | ||
reader.read_to_end(&mut data).unwrap(); | ||
|
||
let children = cursor.collect_children(record.level); | ||
|
||
Self { | ||
tag_id, | ||
data, | ||
children, | ||
} | ||
} | ||
} |