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>
29 #include <sal/types.h>
37 * The HBox class is the base class for all date classes in hwp document.
38 * For example, there are special character, table, image, etc.
39 * It has one character. The ascii code value of special characters are smaller than 32. General character is greater than 32.
41 * @short Base class for characters
49 * Construct a HBox object with parameter hch.
50 * @param hch 16bit character being able to have Korean character.
52 explicit HBox( hchar hch
);
55 * @returns The Size of HBox object
59 * Read properties from HIODevice object like stream, file, memory.
61 * @param hwpf HWPFile Object having all information for a hwp file.
62 * @returns True if reading from stream is successful.
64 virtual bool Read(HWPFile
&hwpf
);
71 * @short Class for skipping data.
73 struct SkipData
: public HBox
75 explicit SkipData(hchar
);
76 virtual ~SkipData() override
;
77 virtual bool Read(HWPFile
&hwpf
) override
;
81 struct FieldCode
: public HBox
83 uchar type
[2]; /* 2/0 - Formula, 3/0-document summary, 3/1 Personal Information, 3/2-creation date, 4/0-pressing mold */
84 std::array
<char, 4> reserved1
;
85 unsigned short location_info
; /* 0 - End code, 1 - start code */
86 std::array
<char, 22> reserved2
;
87 std::unique_ptr
<hchar
[]> str1
;
88 std::unique_ptr
<hchar
[]> str2
;
89 std::unique_ptr
<hchar
[]> str3
;
91 std::unique_ptr
<DateCode
> m_pDate
;
94 virtual ~FieldCode() override
;
95 virtual bool Read(HWPFile
&hwpf
) override
;
107 #define BMK_COMMENT_LEN 15
110 * @short Class for BOOKMARK
112 struct Bookmark
: public HBox
115 hchar id
[BMK_COMMENT_LEN
+ 1];
119 virtual ~Bookmark() override
;
120 virtual bool Read(HWPFile
&hwpf
) override
;
124 const int DATE_SIZE
= 40;
127 * @short Class for saving date format made by user
129 struct DateFormat
: public HBox
131 hchar format
[DATE_SIZE
];
135 virtual bool Read(HWPFile
&hwpf
) override
;
139 * @short Class for current date and time with specified format.
141 struct DateCode
: public HBox
145 YEAR
, MONTH
, WEEK
, DAY
, HOUR
, MIN
148 hchar format
[DATE_SIZE
];
150 * year/month/week/day/hour/minute
157 virtual bool Read(HWPFile
&hwpf
) override
;
159 hchar_string
GetString();
165 struct Tab
: public HBox
168 unsigned short leader
;
172 virtual bool Read(HWPFile
&hwpf
) override
;
175 // tbox(10) TABLE BOX MATH BUTTON HYPERTEXT
177 enum ttype
{ TBL_TYPE
, TXT_TYPE
, EQU_TYPE
, BUTTON_TYPE
, HYPERTEXT_TYPE
};
178 enum /* TxtBox->margin[n][?] */
182 enum /* TxtBox->margin[?][n] */
186 enum anchor
{ CHAR_ANCHOR
, PARA_ANCHOR
, PAGE_ANCHOR
, PAPER_ANCHOR
};
187 enum { TF_OCCUPY_SPACE
, TF_TRANSPARENT
,TF_ARROUND_TEXT
};
190 CAP_OUT_BOT
, CAP_OUT_TOP
, CAP_IN_BOT
, CAP_IN_TOP
,
191 CAP_LEFT_BOT
, CAP_LEFT_TOP
, CAP_RIGHT_BOT
, CAP_RIGHT_TOP
,
198 unsigned char top
; // 0-No line, 1-single, 2-thick, 3-double
199 unsigned char bottom
;
202 short color
; // cell color
203 unsigned char shade
; // <100%
206 * A cell has four properties to specify the position for itself in hwp.
207 * @li xpos - distance between left border of cell and left border of table
208 * @li ypos - distance between top border of cell and top border of table
209 * @li width - distance between left border of cell and right border of cell
210 * @li height - distance between top border of cell and bottom border of table
211 * This is differ from the format of other office in fact cell has two properties
212 * - rowindex and column index.
218 unsigned char key
; // Index value of border style
220 short color
; // cell color
221 short x
, y
; // [x,y] cell pos
222 short w
, h
; // [x,y] cell size
223 short txthigh
, cellhigh
; // used maximum
224 unsigned char flag
, changed
, used
; // unused(file)
225 unsigned char ver_align
; // vertical align {1=center}
226 unsigned char linetype
[4]; // [left,right,top,bottom]
227 unsigned char shade
; // <100%
228 unsigned char diagonal
; // { 0=none,\=1,/=2,X=3}
229 unsigned char protect
;
231 bool Read(HWPFile
&hwpf
);
235 * @short Style for floating object
240 * Anchor type : paragraph , page, char
242 unsigned char anchor_type
;
246 unsigned char txtflow
; /* Avoid painting. 0-2 (seat occupied, transparency, harmony) */
248 * Horizontal alignment
250 short xpos
; // left, right, center, xx
254 short ypos
; // page top, bottom, yy
256 * Every margin of border
257 * [0-2][] : out/in/cell margin
258 * [][0-3] : left/right/top/bottom
260 short margin
[3][4] = {}; // out : left, right, top, bottom
262 * Index of floating object
264 short boxnum
; /* Numbers used as style-name in Libre Office */
266 * Type of floating object : line, txtbox, image, table, equalizer and button
268 unsigned char boxtype
; // (L)ine, t(X)tbox, Picture - (G)
269 short cap_len
; /* The length of the caption */
287 * This object is for floating object like table, image, line and so on.
289 * @short floating object
291 struct FBox
: public HBox
294 short option
; // draw frame
298 short box_xs
, box_ys
;
299 short cap_xs
, cap_ys
;
300 short xs
, ys
; // ys = fig_ys + cap_ys + margin
301 // xs = fig_xs + cap_xs + margin
303 char xpos_type
, ypos_type
;
304 unsigned char smart_linesp
;
306 /* In tbox or pic, this data exists in memory when running, isn't written to a file.
307 But in line, it will be written to a file.
309 short boundsy
, boundey
;
310 unsigned char boundx
, draw
;
313 * Physical x,y position.
315 short pgx
, pgy
; // physical xpos, ypos
316 short pgno
, showpg
; // pageno where code is
318 explicit FBox( hchar hch
);
319 virtual ~FBox() override
;
324 * The TxtBox class saves object properties about table, textbox, equalizer or button
326 struct TxtBox
: public FBox
331 short dummy1
; // to not change structure size */
334 short dummy2
; // to not change structure size */
335 unsigned char reserved1
;
339 short cap_pos
; // caption pos
340 short num
; // numbering
343 short baseline
; //(for equ)
346 * The value of type indicates as the below: zero is table, one is
347 * textbox, two is equalizer and three is button.
349 short type
; // 0-table, 1-textbox, 2-수식, 3-button
351 * nCell is greater than one only for table, otherwise it is 1.
353 short nCell
; //:=1 offset 80
355 * If value of protect is 1, size of cell can't change.
357 short protect
; //1=size lock
359 std::unique_ptr
<Cell
[]> cell
;
364 std::vector
<std::vector
<std::unique_ptr
<HWPPara
>>> plists
;
369 std::vector
<std::unique_ptr
<HWPPara
>> caption
;
372 virtual ~TxtBox() override
;
374 virtual bool Read(HWPFile
&hwpf
) override
;
377 #define ALLOWED_GAP 5
379 #define ADD_AMOUNT 10
383 std::unique_ptr
<int[]> data
;
389 data
.reset(new int[nTotal
]);
392 void AddColumnsSize(){
393 if (nTotal
+ ADD_AMOUNT
< nTotal
) // overflow
395 throw ::std::bad_alloc();
397 int* tmp
= new int[nTotal
+ ADD_AMOUNT
];
398 for (size_t i
= 0 ; i
< nTotal
; i
++)
400 nTotal
+= ADD_AMOUNT
;
404 void insert(int pos
){
406 data
[nCount
++] = pos
;
409 for (size_t i
= 0 ; i
< nCount
; i
++ ) {
410 if( pos
< data
[i
] + ALLOWED_GAP
&& pos
> data
[i
] - ALLOWED_GAP
)
411 return; // Already exist;
413 if( nCount
== nTotal
)
415 for (size_t j
= nCount
; j
> i
; j
--)
423 if( nCount
== nTotal
)
425 data
[nCount
++] = pos
;
428 int getIndex(int pos
)
432 for (size_t i
= 0 ; i
< nCount
; i
++) {
433 if( pos
< data
[i
] + ALLOWED_GAP
&& pos
> data
[i
] - ALLOWED_GAP
)
442 std::unique_ptr
<int[]> data
;
448 data
.reset( new int[nTotal
] );
452 if (nTotal
+ ADD_AMOUNT
< nTotal
) // overflow
454 throw ::std::bad_alloc();
456 int* tmp
= new int[nTotal
+ ADD_AMOUNT
];
457 for (size_t i
= 0 ; i
< nTotal
; i
++)
459 nTotal
+= ADD_AMOUNT
;
463 void insert(int pos
){
465 data
[nCount
++] = pos
;
468 for (size_t i
= 0 ; i
< nCount
; i
++) {
469 if( pos
< data
[i
] + ALLOWED_GAP
&& pos
> data
[i
] - ALLOWED_GAP
)
470 return; // Already exist;
472 if( nCount
== nTotal
)
474 for (size_t j
= nCount
; j
> i
; j
--)
482 if( nCount
== nTotal
)
484 data
[nCount
++] = pos
;
487 int getIndex(int pos
)
491 for (size_t i
= 0 ; i
< nCount
; i
++) {
492 if( pos
< data
[i
] + ALLOWED_GAP
&& pos
> data
[i
] - ALLOWED_GAP
)
510 Table() : box(nullptr) {};
514 std::vector
<std::unique_ptr
<TCell
>> cells
;
518 /* picture (11) graphics, OLE graphics, inserted graphics, drawing */
521 PICTYPE_FILE
, PICTYPE_OLE
, PICTYPE_EMBED
,
522 PICTYPE_DRAW
, PICTYPE_UNKNOWN
525 * @short External image file
535 * @short Embedded image file
543 * @short Win32 ole object
551 struct HWPDrawingObject
;
554 * @short Drawing object of hwp
558 HWPDrawingObject
*hdo
;
565 * @short For using common case
575 PicDefEmbed picembed
;
582 * There are four kinds of image.
585 * @li Win32 ole object
586 * @li Drawing object of hwp
588 * @short Image object
590 struct Picture
: public FBox
595 * follow_block_size is the size information of the Drawing object of hwp.
596 * It's value is greater than 0 if the pictype is PICTYPE_DRAW.
598 uint follow_block_size
; /* Additional information length. */
599 short dummy1
; // to not change structure size */
600 short dummy2
; // to not change structure size */
603 * Position of caption
605 short cap_pos
; // caption pos
607 * Index of current Picture object
609 short num
; // numbering
612 * Type of this object
613 * It is one of external/ole/embedded/drawing picture
618 * Ratio of magnification or reduction.
624 std::vector
<std::unique_ptr
<HWPPara
>> caption
;
626 * It's for the Drawing object
628 std::vector
<unsigned char> follow
; /* When the type of image is drawing, gives additional information. */
633 virtual ~Picture() override
;
635 virtual bool Read (HWPFile
&hwpf
) override
;
642 struct Line
: public FBox
649 short sx
, sy
, ex
, ey
;
650 short width
, shade
, color
;
654 virtual bool Read(HWPFile
&hwpf
) override
;
659 * @short Hidden section
661 struct Hidden
: public HBox
666 unsigned char info
[8]; // h, next, dummy
667 std::vector
<std::unique_ptr
<HWPPara
>> plist
;
670 virtual ~Hidden() override
;
672 virtual bool Read(HWPFile
&hwpf
) override
;
676 * @short Header or footer
678 struct HeaderFooter
: public HBox
683 unsigned char info
[8];
689 unsigned char linenumber
;
691 unsigned int m_nPageNumber
;
694 * Paragraph list of header or footer
696 std::vector
<std::unique_ptr
<HWPPara
>> plist
;
699 virtual ~HeaderFooter() override
;
701 virtual bool Read(HWPFile
&hwpf
) override
;
705 * 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.
706 * @short Footnote or endnote
708 struct Footnote
: public HBox
713 unsigned char info
[8];
715 * The number of current footnote/endnote
717 unsigned short number
;
719 * Set the type of Footnote either footnote or endnote.
723 * The width of the Footnote object.
727 * Paragraph list of Footnote objects
729 std::vector
<std::unique_ptr
<HWPPara
>> plist
;
732 virtual ~Footnote() override
;
734 virtual bool Read(HWPFile
&hwpf
) override
;
739 * Kind of auto input number
752 * @short Input current index of page,comment,table and picture.
754 struct AutoNum
: public HBox
757 unsigned short number
;
762 virtual bool Read(HWPFile
&hwpf
) override
;
766 * @short Input new number as current index of page,comment,table and picture.
768 struct NewNum
: public HBox
771 unsigned short number
;
776 virtual bool Read(HWPFile
&hwpf
) override
;
781 * @short Input page index in footer or header
783 struct ShowPageNum
: public HBox
786 * Location of page number to be inserted.
788 unsigned short where
;
789 unsigned int m_nPageNumber
;
791 * Shape of page number to be inserted.
793 unsigned short shape
;
798 virtual bool Read(HWPFile
&hwpf
) override
;
801 /* Start odd side (21) */
803 * Controls the display of page number, header, footer and border.
805 struct PageNumCtrl
: public HBox
819 virtual bool Read(HWPFile
&hwpf
) override
;
824 * Generates the mailing list automatically using address book and mail body format.
825 * @short Generates mailing list
827 struct MailMerge
: public HBox
829 unsigned char field_name
[20] = {};
834 virtual bool Read(HWPFile
&hwpf
) override
;
835 static hchar_string
GetString();
838 // char composition(23)
840 * The compose struct displays characters at position. The maximum character count for composition is three.
841 * @short Composition several characters
843 struct Compose
: public HBox
850 virtual bool Read(HWPFile
&hwpf
) override
;
857 struct Hyphen
: public HBox
867 virtual bool Read(HWPFile
&hwpf
) override
;
872 * The TocMark class is for making the content of a table.
873 * When you set TocMark on current position, hwp makes it as toc automatically.
874 * @short Table of contents
876 struct TocMark
: public HBox
883 virtual bool Read(HWPFile
&hwpf
) override
;
888 * IndexMark marks the table of search.
889 * If you set IndexMark at current position, hwp make it as search index.
890 * @short Table of search
892 struct IndexMark
: public HBox
894 hchar keyword1
[60] = {};
895 hchar keyword2
[60] = {};
901 virtual bool Read(HWPFile
&hwpf
) override
;
905 #define MAX_OUTLINE_LEVEL 7
923 // value is in style->userchar[level];
941 * Number and format of title.
942 * @short Number and format of title
944 class Outline
: public HBox
948 * kind of numbering format
953 * level of number, Ex) The level of 1.3.2.4 is four
959 unsigned short number
[MAX_OUTLINE_LEVEL
];
963 hchar user_shape
[MAX_OUTLINE_LEVEL
];
965 * decoration character for the level type
967 hchar deco
[MAX_OUTLINE_LEVEL
][2]; /* Prefix/postfix for Customize */
972 virtual bool Read(HWPFile
&hwpf
) override
;
973 hchar_string
GetUnicode() const;
976 /* Bundle of spaces (30) */
978 * The Special space to be treated non-space when a string is
979 * cut at the end of line
980 * @short Special space
982 struct KeepSpace
: public HBox
988 virtual bool Read(HWPFile
&hwpf
) override
;
991 /* Fixed-width spaces (31) */
993 * @short Space with always same width not relation with fonts.
995 struct FixedSpace
: public HBox
1001 virtual bool Read(HWPFile
&hwpf
) override
;
1003 #endif // INCLUDED_HWPFILTER_SOURCE_HBOX_H
1005 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */