Skip to content

Commit

Permalink
feat(hwp): Style 파싱 마무리 (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
hahnlee committed Oct 27, 2022
1 parent 72c4683 commit 9e10afc
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions crates/hwp/src/hwp/doc_info/style.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use byteorder::LittleEndian;
use byteorder::{LittleEndian, ReadBytesExt};
use num::FromPrimitive;
use num_derive::FromPrimitive;

use crate::hwp::{
record::{reader::RecordReader, tags::DocInfoRecord, FromRecord, Record},
utils::bits::get_value_range,
version::Version,
};

Expand All @@ -12,6 +15,21 @@ pub struct Style {
pub name: String,
/// 영문 스타일 이름
pub english_name: String,
/// 스타일 종류
pub kind: StyleKind,
/// 다음 스타일 아이디 참조값
/// 문단 스타일에서 사용자가 리턴키를 입력하여 다음 문단으로 이동했을때 적용할 스타일
pub next_style_id: u8,
/// 언어코드
/// https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/6c085406-a698-4e12-9d4d-c3b0ee3dbc4a
pub lang_id: u16,
/// 문단 모양 아이디 참조값(문단 모양의 아이디 속성)
pub paragraph_shape_id: u16,
/// 글자 모양 아이디(글자 모양의 아이디 속성)
pub char_shape_id: u16,
/// HWP 포맷문서에는 없지만 HWPX 포맷문서에 정의되어 있음
/// 양식모드에서 style 보호하기 여부
pub lock_form: u16,
}

impl FromRecord for Style {
Expand All @@ -22,9 +40,33 @@ impl FromRecord for Style {

let name = reader.read_string::<LittleEndian>().unwrap();
let english_name = reader.read_string::<LittleEndian>().unwrap();
let kind = StyleKind::from_u8(get_value_range(reader.read_u8().unwrap(), 0, 2)).unwrap();
let next_style_id = reader.read_u8().unwrap();
let lang_id = reader.read_u16::<LittleEndian>().unwrap();
let paragraph_shape_id = reader.read_u16::<LittleEndian>().unwrap();
let char_shape_id = reader.read_u16::<LittleEndian>().unwrap();

// TODO: (@hahnlee)
// NOTE: (@hahnlee) HWP 포맷문서에는 없지만 HWPX 포맷문서에 정의되어 있음
let lock_form = reader.read_u16::<LittleEndian>().unwrap();

Self { name, english_name }
Self {
name,
english_name,
kind,
next_style_id,
lang_id,
paragraph_shape_id,
char_shape_id,
lock_form,
}
}
}

#[repr(u8)]
#[derive(Debug, FromPrimitive)]
pub enum StyleKind {
/// 문단 스타일
Para,
/// 글자 스타일
Char,
}

0 comments on commit 9e10afc

Please sign in to comment.