Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hwp): 파싱 인터페이스 레퍼런스 기반으로 변경 #51

Merged
merged 1 commit into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/hwp/src/hwp/paragraph/control/bookmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct Bookmark {
}

impl Bookmark {
pub fn from_record(mut record: Record) -> Self {
pub fn from_record(record: &mut Record) -> Self {
let mut reader = record.get_data_reader();
let ctrl_id = reader.read_u32::<LittleEndian>().unwrap();

Expand Down
2 changes: 1 addition & 1 deletion crates/hwp/src/hwp/paragraph/control/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct ColumnControl {
}

impl ColumnControl {
pub fn from_record(record: Record) -> Self {
pub fn from_record(record: &mut Record) -> Self {
let mut reader = record.get_data_reader();

let ctrl_id = reader.read_u32::<LittleEndian>().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions crates/hwp/src/hwp/paragraph/control/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub struct Container {
}

impl Container {
pub fn from_record(mut record: Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(&mut record, version);
pub fn from_record(record: &mut Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(record, version);

// TODO: (@hahnlee) 남은 데이터 파싱하기
Self { common_properties }
Expand Down
4 changes: 2 additions & 2 deletions crates/hwp/src/hwp/paragraph/control/equation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ pub struct Equation {
}

impl Equation {
pub fn from_record(mut record: Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(&mut record, version);
pub fn from_record(record: &mut Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(record, version);

assert!(
record.is_next_child_id(BodyTextRecord::HWPTAG_EQEDIT as u32),
Expand Down
4 changes: 2 additions & 2 deletions crates/hwp/src/hwp/paragraph/control/footnote_endnote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ pub struct FootnoteEndnote {
}

impl FootnoteEndnote {
pub fn from_record(mut record: Record, version: &Version) -> Self {
pub fn from_record(record: &mut Record, version: &Version) -> Self {
let meta = record.next_child();
let mut reader = meta.get_data_reader();
let paragraph_list = ParagraphList::from_record(&mut reader, &mut record, version);
let paragraph_list = ParagraphList::from_record(&mut reader, record, version);

Self { paragraph_list }
}
Expand Down
4 changes: 2 additions & 2 deletions crates/hwp/src/hwp/paragraph/control/header_footer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ pub struct HeaderFooter {
}

impl HeaderFooter {
pub fn from_record(mut record: Record, version: &Version) -> HeaderFooter {
pub fn from_record(record: &mut Record, version: &Version) -> HeaderFooter {
let meta = record.next_child();
let mut reader = meta.get_data_reader();

let paragraph_list = ParagraphList::from_record(&mut reader, &mut record, version);
let paragraph_list = ParagraphList::from_record(&mut reader, record, version);
HeaderFooter { paragraph_list }
}
}
4 changes: 2 additions & 2 deletions crates/hwp/src/hwp/paragraph/control/hidden_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ pub struct HiddenComment {
}

impl HiddenComment {
pub fn from_record(mut record: Record, version: &Version) -> Self {
pub fn from_record(record: &mut Record, version: &Version) -> Self {
let meta = record.next_child();
let mut reader = meta.get_data_reader();
let paragraph_list = ParagraphList::from_record(&mut reader, &mut record, version);
let paragraph_list = ParagraphList::from_record(&mut reader, record, version);

Self { paragraph_list }
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hwp/src/hwp/paragraph/control/index_mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct IndexMark {
}

impl IndexMark {
pub fn from_record(record: Record) -> Self {
pub fn from_record(record: &mut Record) -> Self {
let mut reader = record.get_data_reader();

let ctrl_id = reader.read_u32::<LittleEndian>().unwrap();
Expand Down
4 changes: 1 addition & 3 deletions crates/hwp/src/hwp/paragraph/control/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub enum Control {
Unknown(UnknownControl),
}

pub fn parse_control(record: Record, version: &Version) -> Control {
pub fn parse_control(record: &mut Record, version: &Version) -> Control {
assert_eq!(
record.tag_id,
BodyTextRecord::HWPTAG_CTRL_HEADER as u32,
Expand Down Expand Up @@ -144,8 +144,6 @@ pub fn parse_control(record: Record, version: &Version) -> Control {
Control::Container(Container::from_record(record, version))
}

// TODO: (@hahnlee) 파싱하기
// 개체 이외 컨트롤
make_4chid!('c', 'o', 'l', 'd') => Control::Column(ColumnControl::from_record(record)),
make_4chid!('a', 't', 'n', 'o') => Control::AutoNumber(AutoNumber::from_record(record)),
make_4chid!('n', 'w', 'n', 'o') => Control::NewNumber(NewNumber::from_record(record)),
Expand Down
4 changes: 2 additions & 2 deletions crates/hwp/src/hwp/paragraph/control/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct AutoNumber {
}

impl AutoNumber {
pub fn from_record(record: Record) -> Self {
pub fn from_record(record: &mut Record) -> Self {
let mut reader = record.get_data_reader();
let ctrl_id = reader.read_u32::<LittleEndian>().unwrap();

Expand Down Expand Up @@ -107,7 +107,7 @@ pub struct NewNumber {
}

impl NewNumber {
pub fn from_record(record: Record) -> Self {
pub fn from_record(record: &mut Record) -> Self {
let mut reader = record.get_data_reader();
let ctrl_id = reader.read_u32::<LittleEndian>().unwrap();

Expand Down
4 changes: 2 additions & 2 deletions crates/hwp/src/hwp/paragraph/control/ole.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub struct Ole {
}

impl Ole {
pub fn from_record(mut record: Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(&mut record, version);
pub fn from_record(record: &mut Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(record, version);

// TODO: (@hahnlee) 남은 데이터 파싱하기
Self { common_properties }
Expand Down
2 changes: 1 addition & 1 deletion crates/hwp/src/hwp/paragraph/control/over_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct OverType {
}

impl OverType {
pub fn from_record(record: Record) -> Self {
pub fn from_record(record: &mut Record) -> Self {
let mut reader = record.get_data_reader();
let ctrl_id = reader.read_u32::<LittleEndian>().unwrap();

Expand Down
2 changes: 1 addition & 1 deletion crates/hwp/src/hwp/paragraph/control/page_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct PageDefinition {
}

impl PageDefinition {
pub fn from_record(record: Record) -> PageDefinition {
pub fn from_record(record: &mut Record) -> PageDefinition {
assert_eq!(
record.tag_id,
BodyTextRecord::HWPTAG_PAGE_DEF as u32,
Expand Down
2 changes: 1 addition & 1 deletion crates/hwp/src/hwp/paragraph/control/page_hiding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct PageHiding {
}

impl PageHiding {
pub fn from_record(record: Record) -> Self {
pub fn from_record(record: &mut Record) -> Self {
let mut reader = record.get_data_reader();

let ctrl_id = reader.read_u32::<LittleEndian>().unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct PageNumberControl {
}

impl PageNumberControl {
pub fn from_record(record: Record) -> Self {
pub fn from_record(record: &mut Record) -> Self {
let mut reader = record.get_data_reader();

let ctrl_id = reader.read_u32::<LittleEndian>().unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct PageNumberPosition {
}

impl PageNumberPosition {
pub fn from_record(record: Record) -> Self {
pub fn from_record(record: &mut Record) -> Self {
let mut reader = record.get_data_reader();

let ctrl_id = reader.read_u32::<LittleEndian>().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions crates/hwp/src/hwp/paragraph/control/picture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub struct Picture {
}

impl Picture {
pub fn from_record(mut record: Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(&mut record, version);
pub fn from_record(record: &mut Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(record, version);

// TODO: (@hahnlee) 남은 데이터 파싱하기
Self { common_properties }
Expand Down
15 changes: 6 additions & 9 deletions crates/hwp/src/hwp/paragraph/control/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct SectionControl {
}

impl SectionControl {
pub fn from_record(mut record: Record) -> SectionControl {
pub fn from_record(record: &mut Record) -> SectionControl {
let mut reader = record.get_data_reader();
// TODO: (@hahnlee) 관련파싱 추가하기
reader.read_u32::<LittleEndian>().unwrap();
Expand All @@ -44,9 +44,9 @@ impl SectionControl {
let mut unknown = Vec::new();
reader.read_to_end(&mut unknown).unwrap();

let page_definition = PageDefinition::from_record(record.next_child());
let footnote_shape = FootnoteEndnoteShape::from_record(record.next_child());
let endnote_shape = FootnoteEndnoteShape::from_record(record.next_child());
let page_definition = PageDefinition::from_record(&mut record.next_child());
let footnote_shape = FootnoteEndnoteShape::from_record(&mut record.next_child());
let endnote_shape = FootnoteEndnoteShape::from_record(&mut record.next_child());

// NOTE: (@hahnlee) 양쪽, 홀수, 짝수 정보가 반복됨.
// TODO: (@hahnlee) 항상 모든 모든 정보를 내려주는지 확인필요
Expand Down Expand Up @@ -97,11 +97,8 @@ pub struct FootnoteEndnoteShape {
}

impl FootnoteEndnoteShape {
pub fn from_record(record: Record) -> Self {
if record.tag_id != BodyTextRecord::HWPTAG_FOOTNOTE_SHAPE as u32 {
// TODO: (@hahnlee) Result 타입으로 바꾸는것 검토
panic!("다른 레코드 입니다 {}", record.tag_id);
}
pub fn from_record(record: &mut Record) -> Self {
assert_eq!(record.tag_id, BodyTextRecord::HWPTAG_FOOTNOTE_SHAPE as u32);

let mut reader = record.get_data_reader();

Expand Down
28 changes: 14 additions & 14 deletions crates/hwp/src/hwp/paragraph/control/shape_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub struct GenShapeObject {
}

impl GenShapeObject {
pub fn from_record(mut record: Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(&mut record, version);
pub fn from_record(record: &mut Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(record, version);

// TODO: (@hahnlee) children 파싱하기
GenShapeObject { common_properties }
Expand All @@ -26,8 +26,8 @@ pub struct ShapeLine {
}

impl ShapeLine {
pub fn from_record(mut record: Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(&mut record, version);
pub fn from_record(record: &mut Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(record, version);

// TODO: (@hahnlee) 남은 데이터 파싱하기
Self { common_properties }
Expand All @@ -42,8 +42,8 @@ pub struct ShapeRectangle {
}

impl ShapeRectangle {
pub fn from_record(mut record: Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(&mut record, version);
pub fn from_record(record: &mut Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(record, version);

// TODO: (@hahnlee) 남은 데이터 파싱하기
Self { common_properties }
Expand All @@ -58,8 +58,8 @@ pub struct ShapeEllipse {
}

impl ShapeEllipse {
pub fn from_record(mut record: Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(&mut record, version);
pub fn from_record(record: &mut Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(record, version);

// TODO: (@hahnlee) 남은 데이터 파싱하기
Self { common_properties }
Expand All @@ -74,8 +74,8 @@ pub struct ShapeArc {
}

impl ShapeArc {
pub fn from_record(mut record: Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(&mut record, version);
pub fn from_record(record: &mut Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(record, version);

// TODO: (@hahnlee) 남은 데이터 파싱하기
Self { common_properties }
Expand All @@ -90,8 +90,8 @@ pub struct ShapePolygon {
}

impl ShapePolygon {
pub fn from_record(mut record: Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(&mut record, version);
pub fn from_record(record: &mut Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(record, version);

// TODO: (@hahnlee) 남은 데이터 파싱하기
Self { common_properties }
Expand All @@ -106,8 +106,8 @@ pub struct ShapeCurve {
}

impl ShapeCurve {
pub fn from_record(mut record: Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(&mut record, version);
pub fn from_record(record: &mut Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(record, version);

// TODO: (@hahnlee) 남은 데이터 파싱하기
Self { common_properties }
Expand Down
2 changes: 1 addition & 1 deletion crates/hwp/src/hwp/paragraph/control/sub_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct SubText {
}

impl SubText {
pub fn from_record(record: Record) -> Self {
pub fn from_record(record: &mut Record) -> Self {
let mut reader = record.get_data_reader();

let ctrl_id = reader.read_u32::<LittleEndian>().unwrap();
Expand Down
6 changes: 3 additions & 3 deletions crates/hwp/src/hwp/paragraph/control/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub struct TableControl {
}

impl TableControl {
pub fn from_record(mut record: Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(&mut record, version);
pub fn from_record(record: &mut Record, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(record, version);

assert!(
record.is_next_child_id(BodyTextRecord::HWPTAG_TABLE as u32),
Expand All @@ -39,7 +39,7 @@ impl TableControl {
.reduce(|result, current| result + current)
.unwrap();
for _ in 0..cell_count {
cells.push(Cell::from_record(&mut record, version));
cells.push(Cell::from_record(record, version));
}

assert!(
Expand Down
2 changes: 1 addition & 1 deletion crates/hwp/src/hwp/paragraph/control/unknown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct UnknownControl {
}

impl UnknownControl {
pub fn from_record(record: Record) -> Self {
pub fn from_record(record: &mut Record) -> Self {
let mut reader = record.get_data_reader();

let ctrl_id = reader.read_u32::<LittleEndian>().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions crates/hwp/src/hwp/paragraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ impl Paragraph {
let control_count = char_list.extend_control_count();
let mut controls: Vec<Control> = Vec::with_capacity(control_count);
for _ in 0..control_count {
let child = record.next_child();
controls.push(parse_control(child, version));
let mut child = record.next_child();
controls.push(parse_control(&mut child, version));
}

let unknown = record.remain_children();
Expand Down
6 changes: 2 additions & 4 deletions crates/hwp/src/hwp/section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ impl Section {
pub fn from_distributed<T: Read>(stream: &mut T, header: &Header) -> Section {
let (tag_id, _, size, mut reader) = stream.read_record::<LittleEndian>().unwrap();

if tag_id != DocInfoRecord::HWPTAG_DISTRIBUTE_DOC_DATA as u32 || size != 256 {
// TODO: (@hahnlee) 옵셔널
panic!("올바르지 않은 정보");
}
assert_eq!(tag_id, DocInfoRecord::HWPTAG_DISTRIBUTE_DOC_DATA as u32);
assert_eq!(size, 256);

let mut data = [0u8; 256];
reader.read_exact(&mut data).unwrap();
Expand Down