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): valid zone 추가 #47

Merged
merged 2 commits into from
Oct 23, 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
6 changes: 3 additions & 3 deletions crates/hwp/src/hwp/doc_info/id_mappings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct IDMappings {
/// 사용자 글꼴
pub user_fonts: Vec<Font>,
/// 테두리/배경
pub border_fils: Vec<BorderFill>,
pub border_fills: Vec<BorderFill>,
// /// 글자 모양
pub char_shapes: Vec<CharShape>,
/// 탭 정의
Expand Down Expand Up @@ -86,7 +86,7 @@ impl IDMappings {
let symbol_fonts = reader.read_i32::<LittleEndian>().unwrap() as usize;
let user_fonts = reader.read_i32::<LittleEndian>().unwrap() as usize;

let border_fils = reader.read_i32::<LittleEndian>().unwrap() as usize;
let border_fills = reader.read_i32::<LittleEndian>().unwrap() as usize;
let char_shapes = reader.read_i32::<LittleEndian>().unwrap() as usize;
let tab_definitions = reader.read_i32::<LittleEndian>().unwrap() as usize;
let numberings = reader.read_i32::<LittleEndian>().unwrap() as usize;
Expand Down Expand Up @@ -121,7 +121,7 @@ impl IDMappings {
etc_fonts: read_items(record, version, etc_fonts),
symbol_fonts: read_items(record, version, symbol_fonts),
user_fonts: read_items(record, version, user_fonts),
border_fils: read_items(record, version, border_fils),
border_fills: read_items(record, version, border_fills),
char_shapes: read_items(record, version, char_shapes),
tab_definitions: read_items(record, version, tab_definitions),
numberings: read_items(record, version, numberings),
Expand Down
44 changes: 40 additions & 4 deletions crates/hwp/src/hwp/paragraph/control/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ impl TableControl {

let table_record = TableRecord::from_record(&mut record.next_child(), version);
let mut cells = Vec::new();
let cell_count = table_record.row_count.clone().into_iter().reduce(|result, current| result + current).unwrap();
let cell_count = table_record
.row_count
.clone()
.into_iter()
.reduce(|result, current| result + current)
.unwrap();
for _ in 0..cell_count {
cells.push(Cell::from_record(&mut record, version));
}
Expand Down Expand Up @@ -61,6 +66,8 @@ pub struct TableRecord {
/// row에 몇개의 column이 있는지 기록 (표준문서의 Row Size)
pub row_count: Vec<u16>,
pub border_fill_id: u16,
/// 영역 속성 (5.0.1.0 이상)
pub valid_zones: Vec<ValidZone>,
}

#[repr(u32)]
Expand Down Expand Up @@ -108,13 +115,15 @@ impl TableRecord {
let border_fill_id = reader.read_u16::<LittleEndian>().unwrap();

// TODO: (@hahnlee) 영역 속성
if version.ge(&Version::from_str("5.0.1.0")) {
let mut valid_zones = vec![];
if *version >= Version::from_str("5.0.1.0") {
let size = reader.read_u16::<LittleEndian>().unwrap();
for _ in 0..size {
let mut buf = [0u8; 10];
reader.read_exact(&mut buf).unwrap();
valid_zones.push(ValidZone::from_reader(&mut reader));
}
}

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

Self {
page_break,
Expand All @@ -125,6 +134,7 @@ impl TableRecord {
padding,
row_count,
border_fill_id,
valid_zones,
}
}

Expand All @@ -133,6 +143,32 @@ impl TableRecord {
}
}

#[derive(Debug, Clone)]
pub struct ValidZone {
/// 시작 열 주소
pub start_column: u16,
/// 시작 행 주소
pub start_row: u16,
/// 끝 열 주소
pub end_column: u16,
/// 끝 행 주소
pub end_row: u16,
/// 테두리 채우기 ID
pub border_fill_id: u16,
}

impl ValidZone {
pub fn from_reader<T: Read>(reader: &mut T) -> Self {
Self {
start_column: reader.read_u16::<LittleEndian>().unwrap(),
start_row: reader.read_u16::<LittleEndian>().unwrap(),
end_column: reader.read_u16::<LittleEndian>().unwrap(),
end_row: reader.read_u16::<LittleEndian>().unwrap(),
border_fill_id: reader.read_u16::<LittleEndian>().unwrap(),
}
}
}

#[derive(Debug, Clone)]
pub struct Cell {
/// 문단 리스트
Expand Down