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): 사각형 파싱 #88

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
27 changes: 24 additions & 3 deletions crates/hwp/src/hwp/paragraph/control/shape_object/rectangle.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use byteorder::ReadBytesExt;

use crate::hwp::{
paragraph::control::{
common_properties::CommonProperties, draw_text::DrawText,
Expand All @@ -7,6 +9,8 @@ use crate::hwp::{
version::Version,
};

use super::picture::Point;

/// 사각형
#[derive(Debug, Clone)]
pub struct ShapeRectangleControl {
Expand Down Expand Up @@ -43,7 +47,13 @@ impl ShapeRectangleControl {
}

#[derive(Debug, Clone)]
pub struct RectangleRecord {}
pub struct RectangleRecord {
/// 사각형 모서리 곡률(%) 직각은 0, 둥근 모양은 20, 반원은 50,
/// 그 외는 적당한 값을 % 단위로 사용한다.
pub ratio: u8,
/// 좌표
pub points: [Point; 4],
}

impl RectangleRecord {
pub fn from_record_cursor(cursor: &mut RecordCursor) -> Self {
Expand All @@ -53,7 +63,18 @@ impl RectangleRecord {
BodyTextRecord::HWPTAG_SHAPE_COMPONENT_RECTANGLE as u32
);

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

let ratio = reader.read_u8().unwrap();
let points = [
Point::from_reader(&mut reader),
Point::from_reader(&mut reader),
Point::from_reader(&mut reader),
Point::from_reader(&mut reader),
];

assert_eq!(record.size as u64, reader.position());

Self { ratio, points }
}
}