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): 곡선 파싱 #92

Merged
merged 1 commit into from
Nov 11, 2022
Merged
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
39 changes: 35 additions & 4 deletions crates/hwp/src/hwp/paragraph/control/shape_object/curve.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use byteorder::{LittleEndian, ReadBytesExt};
use num::FromPrimitive;
use num_derive::FromPrimitive;

use crate::hwp::{
paragraph::control::{
common_properties::CommonProperties, draw_text::DrawText,
element_properties::ElementProperties,
element_properties::ElementProperties, shape_object::picture::Point,
},
record::{tags::BodyTextRecord, Record, RecordCursor},
version::Version,
Expand Down Expand Up @@ -43,7 +47,12 @@ impl ShapeCurveControl {
}

#[derive(Debug, Clone)]
pub struct CurveRecord {}
pub struct CurveRecord {
/// 좌표
pub points: Vec<Point>,
/// 세그먼트 타입
pub segment_kinds: Vec<SegmentKind>,
}

impl CurveRecord {
pub fn from_record_cursor(cursor: &mut RecordCursor) -> Self {
Expand All @@ -53,7 +62,29 @@ impl CurveRecord {
BodyTextRecord::HWPTAG_SHAPE_COMPONENT_CURVE as u32
);

// TODO: (@hahnlee)
Self {}
let mut reader = record.get_data_reader();

let count = reader.read_u32::<LittleEndian>().unwrap();
let mut points = vec![];
for _ in 0..count {
points.push(Point::from_reader(&mut reader));
}

let mut segment_kinds = vec![];
for _ in 0..count - 1 {
segment_kinds.push(SegmentKind::from_u8(reader.read_u8().unwrap()).unwrap());
}

Self {
points,
segment_kinds,
}
}
}

#[repr(u8)]
#[derive(Debug, Clone, PartialEq, Eq, FromPrimitive)]
pub enum SegmentKind {
Line,
Curve,
}