Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / hwpfilter / source / hbox.h
blob344c5594e2e0c8cd52beccb6780c87d742f69c1e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
25 #include <array>
26 #include <list>
27 #include <memory>
29 #include <sal/types.h>
31 #include "hwplib.h"
32 #include "hwpfile.h"
33 #include "hinfo.h"
34 #include "hpara.h"
36 /**
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
43 struct HBox
45 public:
46 hchar hh;
48 /**
49 * Construct a HBox object with parameter hch.
50 * @param hch 16bit character being able to have Korean character.
52 explicit HBox( hchar hch );
53 virtual ~HBox();
54 /**
55 * @returns The Size of HBox object
57 int WSize();
58 /**
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);
66 private:
67 static int boxCount;
70 /**
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;
80 struct DateCode;
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;
93 FieldCode();
94 virtual ~FieldCode() override;
95 virtual bool Read(HWPFile &hwpf) override;
97 /**
98 * Kind of BOOKMARK
100 enum
102 BM_MARK,
103 BM_BEGIN,
104 BM_END
107 #define BMK_COMMENT_LEN 15
110 * @short Class for BOOKMARK
112 struct Bookmark: public HBox
114 hchar dummy;
115 hchar id[BMK_COMMENT_LEN + 1];
116 unsigned short type;
118 Bookmark();
119 virtual ~Bookmark() override;
120 virtual bool Read(HWPFile &hwpf) override;
123 // date format(7)
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];
132 hchar dummy;
134 DateFormat();
135 virtual bool Read(HWPFile &hwpf) override;
139 * @short Class for current date and time with specified format.
141 struct DateCode: public HBox
143 enum
145 YEAR, MONTH, WEEK, DAY, HOUR, MIN
148 hchar format[DATE_SIZE];
150 * year/month/week/day/hour/minute
152 short date[6];
153 hchar dummy;
154 unsigned char key;
156 DateCode();
157 virtual bool Read(HWPFile &hwpf) override;
159 hchar_string GetString();
163 * @short Tab object
165 struct Tab: public HBox
167 hunit width;
168 unsigned short leader;
169 hchar dummy;
171 Tab();
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][?] */
180 OUT_M, IN_M, CELL_M
182 enum /* TxtBox->margin[?][n] */
184 L_M, R_M, T_M, B_M
186 enum anchor { CHAR_ANCHOR, PARA_ANCHOR, PAGE_ANCHOR, PAPER_ANCHOR };
187 enum { TF_OCCUPY_SPACE, TF_TRANSPARENT,TF_ARROUND_TEXT };
188 enum
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,
192 EQU_CAP_POS
195 struct CellLine
197 unsigned char key;
198 unsigned char top; // 0-No line, 1-single, 2-thick, 3-double
199 unsigned char bottom;
200 unsigned char left;
201 unsigned char right;
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.
214 * @short Cell object
216 struct Cell // Cell
218 unsigned char key; // Index value of border style
219 short p;
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
237 struct FBoxStyle
240 * Anchor type : paragraph , page, char
242 unsigned char anchor_type;
244 * Kind of wrap
246 unsigned char txtflow; /* Avoid painting. 0-2 (seat occupied, transparency, harmony) */
248 * Horizontal alignment
250 short xpos; // left, right, center, xx
252 * Vertical alignment
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 */
271 void *cell;
273 FBoxStyle()
274 : anchor_type(0)
275 , txtflow(0)
276 , xpos(0)
277 , ypos(0)
278 , boxnum(0)
279 , boxtype(0)
280 , cap_len(0)
281 , cell(nullptr)
287 * This object is for floating object like table, image, line and so on.
289 * @short floating object
291 struct FBox: public HBox
293 int zorder;
294 short option; // draw frame
295 hchar ctrl_ch;
296 FBoxStyle style;
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
302 short cap_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;
322 struct Table;
324 * The TxtBox class saves object properties about table, textbox, equalizer or button
326 struct TxtBox: public FBox
328 hchar reserved[2];
329 hchar dummy;
331 short dummy1; // to not change structure size */
332 short cap_len;
333 short next_box;
334 short dummy2; // to not change structure size */
335 unsigned char reserved1;
337 * caption position
339 short cap_pos; // caption pos
340 short num; // numbering
342 short dummy3;
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;
360 Table *m_pTable;
362 * Paragraph list
364 std::vector<std::vector<std::unique_ptr<HWPPara>>> plists;
367 * Caption
369 std::vector<std::unique_ptr<HWPPara>> caption;
371 TxtBox();
372 virtual ~TxtBox() override;
374 virtual bool Read(HWPFile &hwpf) override;
377 #define ALLOWED_GAP 5
378 #define INIT_SIZE 20
379 #define ADD_AMOUNT 10
381 struct Columns
383 std::unique_ptr<int[]> data;
384 size_t nCount;
385 size_t nTotal;
386 Columns(){
387 nCount = 0;
388 nTotal = INIT_SIZE;
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++)
399 tmp[i] = data[i];
400 nTotal += ADD_AMOUNT;
401 data.reset(tmp);
404 void insert(int pos){
405 if( nCount == 0 ){
406 data[nCount++] = pos;
407 return;
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;
412 if( pos < data[i] ){
413 if( nCount == nTotal )
414 AddColumnsSize();
415 for (size_t j = nCount ; j > i ; j--)
416 data[j] = data[j-1];
417 data[i] = pos;
418 nCount++;
419 return;
422 // last position.
423 if( nCount == nTotal )
424 AddColumnsSize();
425 data[nCount++] = pos;
428 int getIndex(int pos)
430 if( pos == 0 )
431 return 0;
432 for (size_t i = 0 ; i < nCount; i++) {
433 if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
434 return i;
436 return -1;
440 struct Rows
442 std::unique_ptr<int[]> data;
443 size_t nCount;
444 size_t nTotal;
445 Rows(){
446 nCount = 0;
447 nTotal = INIT_SIZE;
448 data.reset( new int[nTotal] );
451 void AddRowsSize(){
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++)
458 tmp[i] = data[i];
459 nTotal += ADD_AMOUNT;
460 data.reset(tmp);
463 void insert(int pos){
464 if( nCount == 0 ){
465 data[nCount++] = pos;
466 return;
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;
471 if( pos < data[i] ){
472 if( nCount == nTotal )
473 AddRowsSize();
474 for (size_t j = nCount ; j > i ; j--)
475 data[j] = data[j-1];
476 data[i] = pos;
477 nCount++;
478 return;
481 // last position.
482 if( nCount == nTotal )
483 AddRowsSize();
484 data[nCount++] = pos;
487 int getIndex(int pos)
489 if( pos == 0 )
490 return 0;
491 for (size_t i = 0 ; i < nCount; i++) {
492 if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
493 return i;
495 return -1;
499 struct TCell
501 int nColumnIndex;
502 int nRowIndex;
503 int nColumnSpan;
504 int nRowSpan;
505 Cell *pCell;
508 struct Table
510 Table() : box(nullptr) {};
512 Columns columns;
513 Rows rows;
514 std::vector<std::unique_ptr<TCell>> cells;
515 TxtBox *box;
518 /* picture (11) graphics, OLE graphics, inserted graphics, drawing */
519 enum pictype
521 PICTYPE_FILE, PICTYPE_OLE, PICTYPE_EMBED,
522 PICTYPE_DRAW, PICTYPE_UNKNOWN
525 * @short External image file
527 struct PicDefFile
529 char path[256];
530 void *img;
531 bool skipfind;
535 * @short Embedded image file
537 struct PicDefEmbed
539 char embname[16];
543 * @short Win32 ole object
545 struct PicDefOle
547 char embname[16];
548 void *hwpole;
551 struct HWPDrawingObject;
554 * @short Drawing object of hwp
556 struct PicDefDraw
558 HWPDrawingObject *hdo;
559 uint zorder;
560 ZZRect vrect;
561 int mbrcnt;
565 * @short For using common case
567 struct PicDefUnknown
569 char path[256];
572 typedef union
574 PicDefFile picfile;
575 PicDefEmbed picembed;
576 PicDefOle picole;
577 PicDefDraw picdraw;
578 PicDefUnknown picun;
579 } PicDef;
582 * There are four kinds of image.
583 * @li External image
584 * @li Embedded image
585 * @li Win32 ole object
586 * @li Drawing object of hwp
588 * @short Image object
590 struct Picture: public FBox
592 hchar reserved[2];
593 hchar dummy;
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 */
601 uchar reserved1;
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
615 uchar pictype;
616 hunit skip[2];
618 * Ratio of magnification or reduction.
620 hunit scale[2];
621 PicDef picinfo = {};
622 char reserved3[9];
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. */
630 bool ishyper;
632 Picture();
633 virtual ~Picture() override;
635 virtual bool Read (HWPFile &hwpf) override;
638 // line (14)
640 * @short Line
642 struct Line: public FBox
644 hchar reserved[2];
645 hchar dummy;
647 char reserved2[8];
649 short sx, sy, ex, ey;
650 short width, shade, color;
652 Line();
654 virtual bool Read(HWPFile &hwpf) override;
657 // hidden(15)
659 * @short Hidden section
661 struct Hidden: public HBox
663 hchar reserved[2];
664 hchar dummy;
666 unsigned char info[8]; // h, next, dummy
667 std::vector<std::unique_ptr<HWPPara>> plist;
669 Hidden();
670 virtual ~Hidden() override;
672 virtual bool Read(HWPFile &hwpf) override;
676 * @short Header or footer
678 struct HeaderFooter: public HBox
680 hchar reserved[2];
681 hchar dummy;
683 unsigned char info[8];
685 * Header or footer
687 unsigned char type;
688 unsigned char where;
689 unsigned char linenumber;
691 unsigned int m_nPageNumber;
694 * Paragraph list of header or footer
696 std::vector<std::unique_ptr<HWPPara>> plist;
698 HeaderFooter();
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
710 hchar reserved[2];
711 hchar dummy;
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.
721 unsigned short type;
723 * The width of the Footnote object.
725 hunit width;
727 * Paragraph list of Footnote objects
729 std::vector<std::unique_ptr<HWPPara>> plist;
731 Footnote();
732 virtual ~Footnote() override;
734 virtual bool Read(HWPFile &hwpf) override;
737 // auto number(18)
739 * Kind of auto input number
741 enum
743 PGNUM_AUTO,
744 FNNUM_AUTO,
745 ENNUM_AUTO,
746 PICNUM_AUTO,
747 TBLNUM_AUTO,
748 EQUNUM_AUTO
752 * @short Input current index of page,comment,table and picture.
754 struct AutoNum: public HBox
756 unsigned short type;
757 unsigned short number;
758 hchar dummy;
760 AutoNum();
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
770 unsigned short type;
771 unsigned short number;
772 hchar dummy;
774 NewNum();
776 virtual bool Read(HWPFile &hwpf) override;
779 // page number(20)
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;
794 hchar dummy;
796 ShowPageNum();
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
808 * object type
810 unsigned short kind;
812 * control command.
814 unsigned short what;
815 hchar dummy;
817 PageNumCtrl();
819 virtual bool Read(HWPFile &hwpf) override;
822 // mail merge(22)
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] = {};
830 hchar dummy;
832 MailMerge();
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
845 hchar compose[3];
846 hchar dummy;
848 Compose();
850 virtual bool Read(HWPFile &hwpf) override;
853 // hyphen(24)
855 * @short Hyphen
857 struct Hyphen: public HBox
860 * Width of hyphen
862 hchar width;
863 hchar dummy;
865 Hyphen();
867 virtual bool Read(HWPFile &hwpf) override;
870 // toc mark(25)
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
878 hchar kind;
879 hchar dummy;
881 TocMark();
883 virtual bool Read(HWPFile &hwpf) override;
886 // index mark(26)
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] = {};
896 unsigned short pgno;
897 hchar dummy;
899 IndexMark();
901 virtual bool Read(HWPFile &hwpf) override;
904 // outline(28)
905 #define MAX_OUTLINE_LEVEL 7
907 enum
909 OLSTY_USER = 0,
910 OLSTY_NUMS1 = 1,
911 OLSTY_NUMS2 = 2,
912 OLSTY_NUMSIG1 = 3,
913 OLSTY_NUMSIG2 = 4,
914 OLSTY_NUMSIG3 = 5,
915 OLSTY_BULUSER = 128,
916 OLSTY_BULLET1 = 129,
917 OLSTY_BULLET2 = 130,
918 OLSTY_BULLET3 = 131,
919 OLSTY_BULLET4 = 132,
920 OLSTY_BULLET5 = 133
923 // value is in style->userchar[level];
924 enum
926 UDO_NUM,
927 UDO_UROM,
928 UDO_LROM,
929 UDO_UENG,
930 UDO_LENG,
931 UDO_SYLL,
932 UDO_JAMO,
933 UDO_HANJA,
934 UDO_SP_CNUM,
935 UDO_SP_CLENG,
936 UDO_SP_CSYLL,
937 UDO_SP_CJAMO,
938 N_UDO
941 * Number and format of title.
942 * @short Number and format of title
944 class Outline: public HBox
946 public:
948 * kind of numbering format
950 unsigned short kind;
951 unsigned char shape;
953 * level of number, Ex) The level of 1.3.2.4 is four
955 unsigned char level;
957 * value of level
959 unsigned short number[MAX_OUTLINE_LEVEL];
961 * shape of 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 */
968 hchar dummy;
970 Outline();
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
984 hchar dummy;
986 KeepSpace();
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
997 hchar dummy;
999 FixedSpace();
1001 virtual bool Read(HWPFile &hwpf) override;
1003 #endif // INCLUDED_HWPFILTER_SOURCE_HBOX_H
1005 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */