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>
28 #include <sal/types.h>
36 * The HBox class is the base class for all date classes in hwp document.
37 * For example, there are special character, table, image, etc.
38 * It has one character. The ascii code value of special characters are smaller than 32. General character is greater than 32.
40 * @short Base class for characters
48 * Construct a HBox object with parameter hch.
49 * @param hch 16bit character being able to have Korean character.
51 explicit HBox( hchar hch
);
54 * @returns The Size of HBox object
58 * Read properties from HIODevice object like stream, file, memory.
60 * @param hwpf HWPFile Object having all information for a hwp file.
61 * @returns True if reading from stream is successful.
63 virtual bool Read(HWPFile
&hwpf
);
70 * @short Class for skipping data.
72 struct SkipData
: public HBox
74 explicit SkipData(hchar
);
75 virtual ~SkipData() override
;
76 virtual bool Read(HWPFile
&hwpf
) override
;
80 struct FieldCode
: public HBox
82 uchar type
[2]; /* 2/0 - Formula, 3/0-document summary, 3/1 Personal Information, 3/2-creation date, 4/0-pressing mold */
83 std::array
<char, 4> reserved1
;
84 unsigned short location_info
; /* 0 - End code, 1 - start code */
85 std::array
<char, 22> reserved2
;
86 std::unique_ptr
<hchar
[]> str1
;
87 std::unique_ptr
<hchar
[]> str2
;
88 std::unique_ptr
<hchar
[]> str3
;
90 std::unique_ptr
<DateCode
> m_pDate
;
93 virtual ~FieldCode() override
;
94 virtual bool Read(HWPFile
&hwpf
) override
;
106 #define BMK_COMMENT_LEN 15
109 * @short Class for BOOKMARK
111 struct Bookmark
: public HBox
114 hchar id
[BMK_COMMENT_LEN
+ 1];
118 virtual ~Bookmark() override
;
119 virtual bool Read(HWPFile
&hwpf
) override
;
123 const int DATE_SIZE
= 40;
126 * @short Class for saving date format made by user
128 struct DateFormat
: public HBox
130 hchar format
[DATE_SIZE
];
134 virtual bool Read(HWPFile
&hwpf
) override
;
138 * @short Class for current date and time with specified format.
140 struct DateCode
: public HBox
144 YEAR
, MONTH
, WEEK
, DAY
, HOUR
, MIN
147 hchar format
[DATE_SIZE
];
149 * year/month/week/day/hour/minute
156 virtual bool Read(HWPFile
&hwpf
) override
;
158 hchar_string
GetString();
164 struct Tab
: public HBox
167 unsigned short leader
;
171 virtual bool Read(HWPFile
&hwpf
) override
;
174 // tbox(10) TABLE BOX MATH BUTTON HYPERTEXT
176 enum ttype
{ TBL_TYPE
, TXT_TYPE
, EQU_TYPE
, BUTTON_TYPE
, HYPERTEXT_TYPE
};
177 enum /* TxtBox->margin[n][?] */
181 enum /* TxtBox->margin[?][n] */
185 enum anchor
{ CHAR_ANCHOR
, PARA_ANCHOR
, PAGE_ANCHOR
, PAPER_ANCHOR
};
186 enum { TF_OCCUPY_SPACE
, TF_TRANSPARENT
,TF_AROUND_TEXT
};
189 CAP_OUT_BOT
, CAP_OUT_TOP
, CAP_IN_BOT
, CAP_IN_TOP
,
190 CAP_LEFT_BOT
, CAP_LEFT_TOP
, CAP_RIGHT_BOT
, CAP_RIGHT_TOP
,
197 unsigned char top
; // 0-No line, 1-single, 2-thick, 3-double
198 unsigned char bottom
;
201 short color
; // cell color
202 unsigned char shade
; // <100%
205 * A cell has four properties to specify the position for itself in hwp.
206 * @li xpos - distance between left border of cell and left border of table
207 * @li ypos - distance between top border of cell and top border of table
208 * @li width - distance between left border of cell and right border of cell
209 * @li height - distance between top border of cell and bottom border of table
210 * This is differ from the format of other office in fact cell has two properties
211 * - rowindex and column index.
217 unsigned char key
; // Index value of border style
219 short color
; // cell color
220 short x
, y
; // [x,y] cell pos
221 short w
, h
; // [x,y] cell size
222 short txthigh
, cellhigh
; // used maximum
223 unsigned char flag
, changed
, used
; // unused(file)
224 unsigned char ver_align
; // vertical align {1=center}
225 unsigned char linetype
[4]; // [left,right,top,bottom]
226 unsigned char shade
; // <100%
227 unsigned char diagonal
; // { 0=none,\=1,/=2,X=3}
228 unsigned char protect
;
230 bool Read(HWPFile
&hwpf
);
234 * @short Style for floating object
239 * Anchor type : paragraph , page, char
241 unsigned char anchor_type
;
245 unsigned char txtflow
; /* Avoid painting. 0-2 (seat occupied, transparency, harmony) */
247 * Horizontal alignment
249 short xpos
; // left, right, center, xx
253 short ypos
; // page top, bottom, yy
255 * Every margin of border
256 * [0-2][] : out/in/cell margin
257 * [][0-3] : left/right/top/bottom
259 short margin
[3][4] = {}; // out : left, right, top, bottom
261 * Index of floating object
263 short boxnum
; /* Numbers used as style-name in Libre Office */
265 * Type of floating object : line, txtbox, image, table, equalizer and button
267 unsigned char boxtype
; // (L)ine, t(X)tbox, Picture - (G)
268 short cap_len
; /* The length of the caption */
286 * This object is for floating object like table, image, line and so on.
288 * @short floating object
290 struct FBox
: public HBox
293 short option
; // draw frame
297 short box_xs
, box_ys
;
298 short cap_xs
, cap_ys
;
299 short xs
, ys
; // ys = fig_ys + cap_ys + margin
300 // xs = fig_xs + cap_xs + margin
302 char xpos_type
, ypos_type
;
303 unsigned char smart_linesp
;
305 /* In tbox or pic, this data exists in memory when running, isn't written to a file.
306 But in line, it will be written to a file.
308 short boundsy
, boundey
;
309 unsigned char boundx
, draw
;
312 * Physical x,y position.
314 short pgx
, pgy
; // physical xpos, ypos
315 short pgno
, showpg
; // pageno where code is
317 explicit FBox( hchar hch
);
318 virtual ~FBox() override
;
323 * The TxtBox class saves object properties about table, textbox, equalizer or button
325 struct TxtBox
: public FBox
330 short dummy1
; // to not change structure size */
333 short dummy2
; // to not change structure size */
334 unsigned char reserved1
;
338 short cap_pos
; // caption pos
339 short num
; // numbering
342 short baseline
; //(for equ)
345 * The value of type indicates as the below: zero is table, one is
346 * textbox, two is equalizer and three is button.
348 short type
; // 0-table, 1-textbox, 2-수식, 3-button
350 * nCell is greater than one only for table, otherwise it is 1.
352 short nCell
; //:=1 offset 80
354 * If value of protect is 1, size of cell can't change.
356 short protect
; //1=size lock
358 std::unique_ptr
<Cell
[]> cell
;
363 std::vector
<std::vector
<std::unique_ptr
<HWPPara
>>> plists
;
368 std::vector
<std::unique_ptr
<HWPPara
>> caption
;
371 virtual ~TxtBox() override
;
373 virtual bool Read(HWPFile
&hwpf
) override
;
376 #define ALLOWED_GAP 5
378 #define ADD_AMOUNT 10
382 std::unique_ptr
<int[]> data
;
388 data
.reset(new int[nTotal
]);
391 void AddColumnsSize(){
392 if (nTotal
+ ADD_AMOUNT
< nTotal
) // overflow
394 throw ::std::bad_alloc();
396 int* tmp
= new int[nTotal
+ ADD_AMOUNT
];
397 for (size_t i
= 0 ; i
< nTotal
; i
++)
399 nTotal
+= ADD_AMOUNT
;
403 void insert(int pos
){
405 data
[nCount
++] = pos
;
408 for (size_t i
= 0 ; i
< nCount
; i
++ ) {
409 if( pos
< data
[i
] + ALLOWED_GAP
&& pos
> data
[i
] - ALLOWED_GAP
)
410 return; // Already exist;
412 if( nCount
== nTotal
)
414 for (size_t j
= nCount
; j
> i
; j
--)
422 if( nCount
== nTotal
)
424 data
[nCount
++] = pos
;
427 int getIndex(int pos
)
431 for (size_t i
= 0 ; i
< nCount
; i
++) {
432 if( pos
< data
[i
] + ALLOWED_GAP
&& pos
> data
[i
] - ALLOWED_GAP
)
441 std::unique_ptr
<int[]> data
;
447 data
.reset( new int[nTotal
] );
451 if (nTotal
+ ADD_AMOUNT
< nTotal
) // overflow
453 throw ::std::bad_alloc();
455 int* tmp
= new int[nTotal
+ ADD_AMOUNT
];
456 for (size_t i
= 0 ; i
< nTotal
; i
++)
458 nTotal
+= ADD_AMOUNT
;
462 void insert(int pos
){
464 data
[nCount
++] = pos
;
467 for (size_t i
= 0 ; i
< nCount
; i
++) {
468 if( pos
< data
[i
] + ALLOWED_GAP
&& pos
> data
[i
] - ALLOWED_GAP
)
469 return; // Already exist;
471 if( nCount
== nTotal
)
473 for (size_t j
= nCount
; j
> i
; j
--)
481 if( nCount
== nTotal
)
483 data
[nCount
++] = pos
;
486 int getIndex(int pos
)
490 for (size_t i
= 0 ; i
< nCount
; i
++) {
491 if( pos
< data
[i
] + ALLOWED_GAP
&& pos
> data
[i
] - ALLOWED_GAP
)
509 Table() : box(nullptr) {};
513 std::vector
<std::unique_ptr
<TCell
>> cells
;
517 /* picture (11) graphics, OLE graphics, inserted graphics, drawing */
520 PICTYPE_FILE
, PICTYPE_OLE
, PICTYPE_EMBED
,
521 PICTYPE_DRAW
, PICTYPE_UNKNOWN
524 * @short External image file
534 * @short Embedded image file
542 * @short Win32 ole object
550 struct HWPDrawingObject
;
553 * @short Drawing object of hwp
557 HWPDrawingObject
*hdo
;
564 * @short For using common case
574 PicDefEmbed picembed
;
581 * There are four kinds of image.
584 * @li Win32 ole object
585 * @li Drawing object of hwp
587 * @short Image object
589 struct Picture
: public FBox
594 * follow_block_size is the size information of the Drawing object of hwp.
595 * It's value is greater than 0 if the pictype is PICTYPE_DRAW.
597 uint follow_block_size
; /* Additional information length. */
598 short dummy1
; // to not change structure size */
599 short dummy2
; // to not change structure size */
602 * Position of caption
604 short cap_pos
; // caption pos
606 * Index of current Picture object
608 short num
; // numbering
611 * Type of this object
612 * It is one of external/ole/embedded/drawing picture
617 * Ratio of magnification or reduction.
623 std::vector
<std::unique_ptr
<HWPPara
>> caption
;
625 * It's for the Drawing object
627 std::vector
<unsigned char> follow
; /* When the type of image is drawing, gives additional information. */
632 virtual ~Picture() override
;
634 virtual bool Read (HWPFile
&hwpf
) override
;
641 struct Line
: public FBox
648 short sx
, sy
, ex
, ey
;
649 short width
, shade
, color
;
653 virtual bool Read(HWPFile
&hwpf
) override
;
658 * @short Hidden section
660 struct Hidden
: public HBox
665 unsigned char info
[8]; // h, next, dummy
666 std::vector
<std::unique_ptr
<HWPPara
>> plist
;
669 virtual ~Hidden() override
;
671 virtual bool Read(HWPFile
&hwpf
) override
;
675 * @short Header or footer
677 struct HeaderFooter
: public HBox
682 unsigned char info
[8];
688 unsigned char linenumber
;
690 unsigned int m_nPageNumber
;
693 * Paragraph list of header or footer
695 std::vector
<std::unique_ptr
<HWPPara
>> plist
;
698 virtual ~HeaderFooter() override
;
700 virtual bool Read(HWPFile
&hwpf
) override
;
704 * 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.
705 * @short Footnote or endnote
707 struct Footnote
: public HBox
712 unsigned char info
[8];
714 * The number of current footnote/endnote
716 unsigned short number
;
718 * Set the type of Footnote either footnote or endnote.
722 * The width of the Footnote object.
726 * Paragraph list of Footnote objects
728 std::vector
<std::unique_ptr
<HWPPara
>> plist
;
731 virtual ~Footnote() override
;
733 virtual bool Read(HWPFile
&hwpf
) override
;
738 * Kind of auto input number
751 * @short Input current index of page,comment,table and picture.
753 struct AutoNum
: public HBox
756 unsigned short number
;
761 virtual bool Read(HWPFile
&hwpf
) override
;
765 * @short Input new number as current index of page,comment,table and picture.
767 struct NewNum
: public HBox
770 unsigned short number
;
775 virtual bool Read(HWPFile
&hwpf
) override
;
780 * @short Input page index in footer or header
782 struct ShowPageNum
: public HBox
785 * Location of page number to be inserted.
787 unsigned short where
;
788 unsigned int m_nPageNumber
;
790 * Shape of page number to be inserted.
792 unsigned short shape
;
797 virtual bool Read(HWPFile
&hwpf
) override
;
800 /* Start odd side (21) */
802 * Controls the display of page number, header, footer and border.
804 struct PageNumCtrl
: public HBox
818 virtual bool Read(HWPFile
&hwpf
) override
;
823 * Generates the mailing list automatically using address book and mail body format.
824 * @short Generates mailing list
826 struct MailMerge
: public HBox
828 unsigned char field_name
[20] = {};
833 virtual bool Read(HWPFile
&hwpf
) override
;
834 static hchar_string
GetString();
837 // char composition(23)
839 * The compose struct displays characters at position. The maximum character count for composition is three.
840 * @short Composition several characters
842 struct Compose
: public HBox
849 virtual bool Read(HWPFile
&hwpf
) override
;
856 struct Hyphen
: public HBox
866 virtual bool Read(HWPFile
&hwpf
) override
;
871 * The TocMark class is for making the content of a table.
872 * When you set TocMark on current position, hwp makes it as toc automatically.
873 * @short Table of contents
875 struct TocMark
: public HBox
882 virtual bool Read(HWPFile
&hwpf
) override
;
887 * IndexMark marks the table of search.
888 * If you set IndexMark at current position, hwp make it as search index.
889 * @short Table of search
891 struct IndexMark
: public HBox
893 hchar keyword1
[60] = {};
894 hchar keyword2
[60] = {};
900 virtual bool Read(HWPFile
&hwpf
) override
;
904 #define MAX_OUTLINE_LEVEL 7
922 // value is in style->userchar[level];
940 * Number and format of title.
941 * @short Number and format of title
943 class Outline
: public HBox
947 * kind of numbering format
952 * level of number, Ex) The level of 1.3.2.4 is four
958 unsigned short number
[MAX_OUTLINE_LEVEL
];
962 hchar user_shape
[MAX_OUTLINE_LEVEL
];
964 * decoration character for the level type
966 hchar deco
[MAX_OUTLINE_LEVEL
][2]; /* Prefix/postfix for Customize */
971 virtual bool Read(HWPFile
&hwpf
) override
;
972 hchar_string
GetUnicode() const;
975 /* Bundle of spaces (30) */
977 * The Special space to be treated non-space when a string is
978 * cut at the end of line
979 * @short Special space
981 struct KeepSpace
: public HBox
987 virtual bool Read(HWPFile
&hwpf
) override
;
990 /* Fixed-width spaces (31) */
992 * @short Space with always same width not relation with fonts.
994 struct FixedSpace
: public HBox
1000 virtual bool Read(HWPFile
&hwpf
) override
;
1002 #endif // INCLUDED_HWPFILTER_SOURCE_HBOX_H
1004 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */