1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_HWPFILTER_SOURCE_HBOX_H
21 #define INCLUDED_HWPFILTER_SOURCE_HBOX_H
23 #include <sal/config.h>
27 #include <sal/types.h>
35 * The HBox class is the base class for all date classes in hwp document.
36 * For example, there are special character, table, image, etc.
37 * It has one character. The ascii code value of special characters are smaller than 32. General character is greater than 32.
39 * @short Base class for characters
47 * Construct a HBox object with parameter hch.
48 * @param hch 16bit character being able to have Korean character.
53 * @returns The Size of HBox object
57 * @returns The Height of HBox object as hunit value.
59 virtual hunit
Height(CharShape
*csty
);
61 * Read properties from HIODevice object like stream, file, memory.
63 * @param hwpf HWPFile Object having all information for a hwp file.
64 * @returns True if reading from stream is successful.
66 virtual bool Read(HWPFile
&hwpf
);
68 virtual hchar_string
GetString();
74 * @short Class for saving data to be skipped.
76 struct SkipData
: public HBox
84 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
87 struct FieldCode
: public HBox
89 uchar type
[2]; /* 2/0 - 계산식, 3/0-문서요약, 3/1-개인정보, 3/2-만든날짜, 4/0-누름틀 */
91 unsigned short location_info
; /* 0 - 끝코드, 1 - 시작코드 */
101 virtual ~FieldCode();
102 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
114 #define BMK_COMMENT_LEN 15
117 * @short Class for BOOKMARK
119 struct Bookmark
: public HBox
122 hchar id
[BMK_COMMENT_LEN
+ 1];
127 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
131 const int DATE_SIZE
= 40;
134 * @short Class for saving date format made by user
136 struct DateFormat
: public HBox
138 hchar format
[DATE_SIZE
];
142 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
146 * @short Class for current date and time with specified format.
148 struct DateCode
: public HBox
152 YEAR
, MONTH
, WEEK
, DAY
, HOUR
, MIN
155 hchar format
[DATE_SIZE
];
157 * year/month/week/day/hour/minute
164 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
166 virtual hchar_string
GetString() SAL_OVERRIDE
;
172 struct Tab
: public HBox
175 unsigned short leader
;
179 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
182 // tbox(10) TABLE BOX MATH BUTTON HYPERTEXT
184 enum ttype
{ TBL_TYPE
, TXT_TYPE
, EQU_TYPE
, BUTTON_TYPE
, HYPERTEXT_TYPE
};
185 enum /* TxtBox->margin[n][?] */
189 enum /* TxtBox->margin[?][n] */
193 enum anchor
{ CHAR_ANCHOR
, PARA_ANCHOR
, PAGE_ANCHOR
, PAPER_ANCHOR
};
194 enum { TF_OCCUPY_SPACE
, TF_TRANSPARENT
,TF_ARROUND_TEXT
};
197 CAP_OUT_BOT
, CAP_OUT_TOP
, CAP_IN_BOT
, CAP_IN_TOP
,
198 CAP_LEFT_BOT
, CAP_LEFT_TOP
, CAP_RIGHT_BOT
, CAP_RIGHT_TOP
,
205 unsigned char top
; // 0 - 라인없음, 1-single, 2-thick, 3-double
206 unsigned char bottom
;
209 short color
; // cell color
210 unsigned char shade
; // <100%
213 * A cell has four properties to specify the position for itself in hwp.
214 * @li xpos - distance between left border of cell and left border of table
215 * @li ypos - distance between top border of cell and top border of table
216 * @li width - distance between left border of cell and right border of cell
217 * @li height - distance between top border of cell and bottom border of table
218 * This is differ from the format of other office in fact cell has two properties
219 * - rowindex and column index.
225 unsigned char key
; // Index value of border style
227 short color
; // cell color
228 short x
, y
; // [x,y] cell pos
229 short w
, h
; // [x,y] cell size
230 short txthigh
, cellhigh
; // used maximum
231 unsigned char flag
, changed
, used
; // unused(file)
232 unsigned char ver_align
; // vertical align {1=center}
233 unsigned char linetype
[4]; // [left,right,top,bottom]
234 unsigned char shade
; // <100%
235 unsigned char diagonal
; // { 0=none,\=1,/=2,X=3}
236 unsigned char protect
;
238 void Read( HWPFile
&hwpf
);
242 * @short Style for floating object
247 * Anchor type : paragraph , page, char
249 unsigned char anchor_type
;
253 unsigned char txtflow
; /* 그림피함. 0-2(자리차지,투명,어울림) */
255 * Horizontal alignment
257 short xpos
; // left, right, center, xx
261 short ypos
; // page top, bottom, yy
263 * Every margin of border
264 * [0-2][] : out/in/cell margin
265 * [][0-3] : left/right/top/bottom
267 short margin
[3][4]; // out : left, right, top, bottom
269 * Index of floating object
271 short boxnum
; /* 스타오피스에서 스타일 이름으로 사용될 숫자 */
273 * Type of floating object : line, txtbox, image, table, equalizer and button
275 unsigned char boxtype
; // (L)ine, t(X)tbox, Picture - (G)
276 short cap_len
; /* 캡션의 길이 */
290 memset(margin
, 0, sizeof(margin
));
295 * This object is for floating object like table, image, line and so on.
297 * @short floating object
299 struct FBox
: public HBox
302 short option
; // draw frame
306 short box_xs
, box_ys
;
307 short cap_xs
, cap_ys
;
308 short xs
, ys
; // ys = fig_ys + cap_ys + margin
309 // xs = fig_xs + cap_xs + margin
311 char xpos_type
, ypos_type
;
312 unsigned char smart_linesp
;
314 /* 이 자료는 tbox나 pic에서는 파일에 기록하지 않고 실행시만 있으며,
317 short boundsy
, boundey
;
318 unsigned char boundx
, draw
;
321 * Physical x,y position.
323 short pgx
, pgy
; // physical xpos, ypos
324 short pgno
, showpg
; // pageno where code is
334 * The TxtBox class saves object properties about table, textbox, equalizer or button
336 struct TxtBox
: public FBox
341 short dummy1
; // to not change structure size */
344 short dummy2
; // to not change structure size */
345 unsigned char reserved1
;
349 short cap_pos
; // caption pos
350 short num
; // numbering
353 short baseline
; //(for equ)
356 * The value of type indicates as the below: zero is table, one is
357 * textbox, two is equalizer and three is button.
359 short type
; // 0-table, 1-textbox, 2-수식, 3-button
361 * nCell is greater than one only for table, otherwise it is 1.
363 short nCell
; //:=1 offset 80
365 * If value of protect is 1, size of cell cann't change.
367 short protect
; //1=size lock
374 std::list
<HWPPara
*> *plists
;
378 std::list
<HWPPara
*> caption
;
384 * @returns Count of cell.
386 int NCell() { return nCell
; }
388 * This is one of table, text-box, equalizer and button
389 * @returns Type of this object.
391 int Type() { return type
; }
393 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
395 virtual hunit
Height(CharShape
*csty
) SAL_OVERRIDE
;
398 #define ALLOWED_GAP 5
400 #define ADD_AMOUNT 10
410 data
= new int[nTotal
];
412 ~Columns(){ delete[] data
; }
414 void AddColumnsSize(){
416 if (nTotal
+ ADD_AMOUNT
< nTotal
) // overflow
418 throw ::std::bad_alloc();
420 data
= new int[nTotal
+ ADD_AMOUNT
];
421 for (size_t i
= 0 ; i
< nTotal
; i
++)
423 nTotal
+= ADD_AMOUNT
;
427 void insert(int pos
){
429 data
[nCount
++] = pos
;
432 for (size_t i
= 0 ; i
< nCount
; i
++ ) {
433 if( pos
< data
[i
] + ALLOWED_GAP
&& pos
> data
[i
] - ALLOWED_GAP
)
434 return; // Already exist;
436 if( nCount
== nTotal
)
438 for (size_t j
= nCount
; j
> i
; j
--)
446 if( nCount
== nTotal
)
448 data
[nCount
++] = pos
;
451 int getIndex(int pos
)
455 for (size_t i
= 0 ; i
< nCount
; i
++) {
456 if( pos
< data
[i
] + ALLOWED_GAP
&& pos
> data
[i
] - ALLOWED_GAP
)
471 data
= new int[nTotal
];
473 ~Rows(){ delete[] data
; }
477 if (nTotal
+ ADD_AMOUNT
< nTotal
) // overflow
479 throw ::std::bad_alloc();
481 data
= new int[nTotal
+ ADD_AMOUNT
];
482 for (size_t i
= 0 ; i
< nTotal
; i
++)
484 nTotal
+= ADD_AMOUNT
;
488 void insert(int pos
){
490 data
[nCount
++] = pos
;
493 for (size_t i
= 0 ; i
< nCount
; i
++) {
494 if( pos
< data
[i
] + ALLOWED_GAP
&& pos
> data
[i
] - ALLOWED_GAP
)
495 return; // Already exist;
497 if( nCount
== nTotal
)
499 for (size_t j
= nCount
; j
> i
; j
--)
507 if( nCount
== nTotal
)
509 data
[nCount
++] = pos
;
512 int getIndex(int pos
)
516 for (size_t i
= 0 ; i
< nCount
; i
++) {
517 if( pos
< data
[i
] + ALLOWED_GAP
&& pos
> data
[i
] - ALLOWED_GAP
)
535 Table() : box(NULL
) {};
537 std::list
<TCell
*>::iterator it
= cells
.begin();
538 for( ; it
!= cells
.end(); ++it
)
544 std::list
<TCell
*> cells
;
548 /* picture (11) 그림, OLE그림, 삽입그림, 그리기 */
551 PICTYPE_FILE
, PICTYPE_OLE
, PICTYPE_EMBED
,
552 PICTYPE_DRAW
, PICTYPE_UNKNOWN
555 * @short External image file
565 * @short Embedded image file
573 * @short Win32 ole object
582 * @short Drawing object of hwp
593 * @short For using common case
603 PicDefEmbed picembed
;
610 * There are four kinds of image.
613 * @li Win32 ole object
614 * @li Drawing object of hwp
616 * @short Image object
618 struct Picture
: public FBox
623 * follow_block_size is the size information of the Drawing object of hwp.
624 * It's value is greater than 0 if the pictype is PICTYPE_DRAW.
626 uint follow_block_size
; /* 추가정보 길이. */
627 short dummy1
; // to not change structure size */
628 short dummy2
; // to not change structure size */
631 * Position of caption
633 short cap_pos
; // caption pos
635 * Index of current Picture object
637 short num
; // numbering
640 * Type of this object
641 * It is one of external/ole/embedded/drawing picture
646 * Ratio of magnification or reduction.
652 std::list
<HWPPara
*> caption
;
654 * It's for the Drawing object
656 unsigned char *follow
; /* 그림종류가 drawing일때, 추가정보. */
664 virtual bool Read (HWPFile
&hwpf
) SAL_OVERRIDE
;
666 virtual hunit
Height (CharShape
*sty
) SAL_OVERRIDE
;
673 struct Line
: public FBox
680 short sx
, sy
, ex
, ey
;
681 short width
, shade
, color
;
685 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
690 * @short Hidden section
692 struct Hidden
: public HBox
697 unsigned char info
[8]; // h, next, dummy
698 std::list
<HWPPara
*> plist
;
703 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
707 * @short Header or footer
709 struct HeaderFooter
: public HBox
714 unsigned char info
[8];
720 unsigned char linenumber
;
722 unsigned int m_nPageNumber
;
725 * Paragraph list of header or footer
727 std::list
<HWPPara
*> plist
;
730 virtual ~HeaderFooter();
732 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
736 * Both footnote and endnote are comment. Footnote is located at the end of paragraph; endnote is located at the end of page. The Footnote class represents footnote and endnote.
737 * @short Footnote or endnote
739 struct Footnote
: public HBox
744 unsigned char info
[8];
746 * The number of current footnote/endnote
748 unsigned short number
;
750 * Set the type of Footnote either footnote or endnote.
754 * The width of the Footnote object.
758 * Paragraph list of Footnote objects
760 std::list
<HWPPara
*> plist
;
765 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
770 * Kind of auto input number
783 * @short Input current index of page,comment,table and picture.
785 struct AutoNum
: public HBox
788 unsigned short number
;
793 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
797 * @short Input new number as current index of page,comment,table and picture.
799 struct NewNum
: public HBox
802 unsigned short number
;
807 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
812 * @short Input page index in footer or header
814 struct ShowPageNum
: public HBox
817 * Location of page number to be inserted.
819 unsigned short where
;
820 unsigned int m_nPageNumber
;
822 * Shape of page number to be inserted.
824 unsigned short shape
;
829 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
834 * Controls the display of page number, header, footer and border.
836 struct PageNumCtrl
: public HBox
850 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
855 * Generates the mailing list automatically using address book and mail body format.
856 * @short Generates mailing list
858 struct MailMerge
: public HBox
860 unsigned char field_name
[20];
865 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
866 virtual hchar_string
GetString() SAL_OVERRIDE
;
869 // char compositon(23)
871 * The compose struct displays characters at position. The maximum character count for composition is three.
872 * @short Composition several characters
874 struct Compose
: public HBox
881 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
888 struct Hyphen
: public HBox
898 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
903 * The TocMark class is for making the content of a table.
904 * When you set TocMark on current position, hwp makes it as toc automatically.
905 * @short Table of contents
907 struct TocMark
: public HBox
914 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
919 * IndexMark marks the table of search.
920 * If you set IndexMark at current position, hwp make it as search index.
921 * @short Table of search
923 struct IndexMark
: public HBox
932 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
936 #define MAX_OUTLINE_LEVEL 7
954 // value is in style->userchar[level];
972 * Number and format of title.
973 * @short Number and format of title
975 class Outline
: public HBox
979 * kind of numbering format
984 * level of number, Ex) The level of 1.3.2.4 is four
990 unsigned short number
[MAX_OUTLINE_LEVEL
];
994 hchar user_shape
[MAX_OUTLINE_LEVEL
];
996 * decoration character for the level type
998 hchar deco
[MAX_OUTLINE_LEVEL
][2]; /* 사용자 정의시 앞뒤 문자 */
1003 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
1004 hchar_string
GetUnicode() const;
1009 * The Special space to be treated non-space when a string is
1010 * cut at the end of line
1011 * @short Special space
1013 struct KeepSpace
: public HBox
1019 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
1024 * @short Space with always same width not relation with fonts.
1026 struct FixedSpace
: public HBox
1032 virtual bool Read(HWPFile
&hwpf
) SAL_OVERRIDE
;
1034 #endif // INCLUDED_HWPFILTER_SOURCE_HBOX_H
1036 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */