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): 묶음개체 글상자 #93

Merged
merged 1 commit into from
Nov 11, 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
27 changes: 20 additions & 7 deletions crates/hwp/src/hwp/paragraph/control/shape_object/container.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::hwp::{
paragraph::control::{
common_properties::CommonProperties, element_properties::ElementProperties,
common_properties::CommonProperties, draw_text::DrawText,
element_properties::ElementProperties,
},
record::{Record, RecordCursor},
record::{tags::BodyTextRecord, Record, RecordCursor},
version::Version,
};

Expand All @@ -23,7 +24,7 @@ impl ContainerControl {
pub fn from_record(record: &mut Record, cursor: &mut RecordCursor, version: &Version) -> Self {
let common_properties = CommonProperties::from_record(record, cursor, version);
let element_properties = ElementProperties::from_record_cursor(cursor, false);
let content = ContainerContent::from_record_cursor(&element_properties, cursor);
let content = ContainerContent::from_record_cursor(&element_properties, cursor, version);

Self {
common_properties,
Expand All @@ -39,13 +40,17 @@ pub struct ContainerContent {
}

impl ContainerContent {
pub fn from_record_cursor(properties: &ElementProperties, cursor: &mut RecordCursor) -> Self {
pub fn from_record_cursor(
properties: &ElementProperties,
cursor: &mut RecordCursor,
version: &Version,
) -> Self {
let children = properties
.children_ids
.as_ref()
.unwrap()
.into_iter()
.map(|_| ContainerElement::from_record_cursor(cursor))
.map(|_| ContainerElement::from_record_cursor(cursor, version))
.collect();

Self { children }
Expand All @@ -58,16 +63,24 @@ pub struct ContainerElement {
pub element_properties: ElementProperties,
/// 컨텐츠
pub content: ShapeObjectContent,
/// 글상자
pub draw_text: Option<DrawText>,
}

impl ContainerElement {
pub fn from_record_cursor(cursor: &mut RecordCursor) -> Self {
pub fn from_record_cursor(cursor: &mut RecordCursor, version: &Version) -> Self {
let element_properties = ElementProperties::from_record_cursor(cursor, false);
let content = parse_content(&element_properties, cursor);
let draw_text = if cursor.record_id(BodyTextRecord::HWPTAG_LIST_HEADER as u32) {
Some(DrawText::from_record_cursor(cursor, version))
} else {
None
};
let content = parse_content(&element_properties, cursor, version);

Self {
element_properties,
content,
draw_text,
}
}
}
9 changes: 5 additions & 4 deletions crates/hwp/src/hwp/paragraph/control/shape_object/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use hwp_macro::make_4chid;

use crate::hwp::{
paragraph::control::element_properties::ElementProperties, record::RecordCursor,
unknown::UnknownRecord,
unknown::UnknownRecord, version::Version,
};

use super::{
Expand All @@ -29,14 +29,15 @@ pub enum ShapeObjectContent {
pub fn parse_content(
properties: &ElementProperties,
cursor: &mut RecordCursor,
version: &Version,
) -> ShapeObjectContent {
match properties.ctrl_id {
make_4chid!('$', 'a', 'r', 'c') => {
ShapeObjectContent::Arc(ArcRecord::from_record_cursor(cursor))
}
make_4chid!('$', 'c', 'o', 'n') => {
ShapeObjectContent::Container(ContainerContent::from_record_cursor(properties, cursor))
}
make_4chid!('$', 'c', 'o', 'n') => ShapeObjectContent::Container(
ContainerContent::from_record_cursor(properties, cursor, version),
),
make_4chid!('$', 'c', 'u', 'r') => {
ShapeObjectContent::Curve(CurveRecord::from_record_cursor(cursor))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl GenShapeObjectControl {
None
};

let content = parse_content(&element_properties, cursor);
let content = parse_content(&element_properties, cursor, version);

Self {
common_properties,
Expand Down
Binary file not shown.
17 changes: 17 additions & 0 deletions crates/hwp/tests/integration/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,20 @@ fn check_image_fill() {

assert_eq!(hwp.body_texts.sections.len(), 1);
}

#[test]
fn check_group_with_draw_text() {
let path = get_tests_path("integration/project/files/group_with_draw_text.hwp");
let file = fs::read(path).unwrap();

let hwp = HWP::from_bytes(&file);

assert_eq!(hwp.header.version.to_string(), "5.1.0.1");
assert_eq!(hwp.header.flags.compressed, true);
assert_eq!(hwp.header.flags.distributed, false);

assert_eq!(hwp.header.license.ccl, false);
assert_eq!(hwp.header.license.replication_restrictions, false);

assert_eq!(hwp.body_texts.sections.len(), 1);
}