Bump version to 24.04.3.4
[LibreOffice.git] / hwpfilter / source / hbox.h
blobf7813b225dd59e6150f34ec5ce919a43ef21c294
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 <memory>
28 #include <rtl/ustring.hxx>
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_AROUND_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 typedef std::vector<std::unique_ptr<HWPPara>> plist_t;
365 typedef std::vector<plist_t> plists_t;
366 plists_t plists;
369 * Caption
371 std::vector<std::unique_ptr<HWPPara>> caption;
373 TxtBox();
374 virtual ~TxtBox() override;
376 virtual bool Read(HWPFile &hwpf) override;
379 #define ALLOWED_GAP 5
380 #define INIT_SIZE 20
381 #define ADD_AMOUNT 10
383 struct Columns
385 std::unique_ptr<int[]> data;
386 size_t nCount;
387 size_t nTotal;
388 Columns(){
389 nCount = 0;
390 nTotal = INIT_SIZE;
391 data.reset(new int[nTotal]);
394 void AddColumnsSize(){
395 if (nTotal + ADD_AMOUNT < nTotal) // overflow
397 throw ::std::bad_alloc();
399 int* tmp = new int[nTotal + ADD_AMOUNT];
400 for (size_t i = 0 ; i < nTotal ; i++)
401 tmp[i] = data[i];
402 nTotal += ADD_AMOUNT;
403 data.reset(tmp);
406 void insert(int pos){
407 if( nCount == 0 ){
408 data[nCount++] = pos;
409 return;
411 for (size_t i = 0 ; i < nCount; i++ ) {
412 if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
413 return; // Already exist;
414 if( pos < data[i] ){
415 if( nCount == nTotal )
416 AddColumnsSize();
417 for (size_t j = nCount ; j > i ; j--)
418 data[j] = data[j-1];
419 data[i] = pos;
420 nCount++;
421 return;
424 // last position.
425 if( nCount == nTotal )
426 AddColumnsSize();
427 data[nCount++] = pos;
430 int getIndex(int pos)
432 if( pos == 0 )
433 return 0;
434 for (size_t i = 0 ; i < nCount; i++) {
435 if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
436 return i;
438 return -1;
442 struct Rows
444 std::unique_ptr<int[]> data;
445 size_t nCount;
446 size_t nTotal;
447 Rows(){
448 nCount = 0;
449 nTotal = INIT_SIZE;
450 data.reset( new int[nTotal] );
453 void AddRowsSize(){
454 if (nTotal + ADD_AMOUNT < nTotal) // overflow
456 throw ::std::bad_alloc();
458 int* tmp = new int[nTotal + ADD_AMOUNT];
459 for (size_t i = 0 ; i < nTotal ; i++)
460 tmp[i] = data[i];
461 nTotal += ADD_AMOUNT;
462 data.reset(tmp);
465 void insert(int pos){
466 if( nCount == 0 ){
467 data[nCount++] = pos;
468 return;
470 for (size_t i = 0 ; i < nCount; i++) {
471 if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
472 return; // Already exist;
473 if( pos < data[i] ){
474 if( nCount == nTotal )
475 AddRowsSize();
476 for (size_t j = nCount ; j > i ; j--)
477 data[j] = data[j-1];
478 data[i] = pos;
479 nCount++;
480 return;
483 // last position.
484 if( nCount == nTotal )
485 AddRowsSize();
486 data[nCount++] = pos;
489 int getIndex(int pos)
491 if( pos == 0 )
492 return 0;
493 for (size_t i = 0 ; i < nCount; i++) {
494 if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
495 return i;
497 return -1;
501 struct TCell
503 int nColumnIndex;
504 int nRowIndex;
505 int nColumnSpan;
506 int nRowSpan;
507 Cell *pCell;
510 struct Table
512 Table() : box(nullptr) {};
514 Columns columns;
515 Rows rows;
516 std::vector<std::unique_ptr<TCell>> cells;
517 TxtBox *box;
520 /* picture (11) graphics, OLE graphics, inserted graphics, drawing */
521 enum pictype
523 PICTYPE_FILE, PICTYPE_OLE, PICTYPE_EMBED,
524 PICTYPE_DRAW, PICTYPE_UNKNOWN
527 * @short External image file
529 struct PicDefFile
531 char path[256];
532 void *img;
533 bool skipfind;
537 * @short Embedded image file
539 struct PicDefEmbed
541 char embname[16];
545 * @short Win32 ole object
547 struct PicDefOle
549 char embname[16];
550 void *hwpole;
553 struct HWPDrawingObject;
556 * @short Drawing object of hwp
558 struct PicDefDraw
560 HWPDrawingObject *hdo;
561 uint zorder;
562 ZZRect vrect;
563 int mbrcnt;
567 * @short For using common case
569 struct PicDefUnknown
571 char path[256];
574 typedef union
576 PicDefFile picfile;
577 PicDefEmbed picembed;
578 PicDefOle picole;
579 PicDefDraw picdraw;
580 PicDefUnknown picun;
581 } PicDef;
584 * There are four kinds of image.
585 * @li External image
586 * @li Embedded image
587 * @li Win32 ole object
588 * @li Drawing object of hwp
590 * @short Image object
592 struct Picture: public FBox
594 hchar reserved[2];
595 hchar dummy;
597 * follow_block_size is the size information of the Drawing object of hwp.
598 * It's value is greater than 0 if the pictype is PICTYPE_DRAW.
600 uint follow_block_size; /* Additional information length. */
601 short dummy1; // to not change structure size */
602 short dummy2; // to not change structure size */
603 uchar reserved1;
605 * Position of caption
607 short cap_pos; // caption pos
609 * Index of current Picture object
611 short num; // numbering
614 * Type of this object
615 * It is one of external/ole/embedded/drawing picture
617 uchar pictype;
618 hunit skip[2];
620 * Ratio of magnification or reduction.
622 hunit scale[2];
623 PicDef picinfo;
624 char reserved3[9];
626 std::vector<std::unique_ptr<HWPPara>> caption;
628 * It's for the Drawing object
630 std::vector<unsigned char> follow; /* When the type of image is drawing, gives additional information. */
632 bool ishyper;
634 Picture();
635 virtual ~Picture() override;
637 virtual bool Read (HWPFile &hwpf) override;
640 // line (14)
642 * @short Line
644 struct Line: public FBox
646 hchar reserved[2];
647 hchar dummy;
649 char reserved2[8];
651 short sx, sy, ex, ey;
652 short width, shade, color;
654 Line();
656 virtual bool Read(HWPFile &hwpf) override;
659 // hidden(15)
661 * @short Hidden section
663 struct Hidden: public HBox
665 hchar reserved[2];
666 hchar dummy;
668 unsigned char info[8]; // h, next, dummy
669 std::vector<std::unique_ptr<HWPPara>> plist;
671 Hidden();
672 virtual ~Hidden() override;
674 virtual bool Read(HWPFile &hwpf) override;
678 * @short Header or footer
680 struct HeaderFooter: public HBox
682 hchar reserved[2];
683 hchar dummy;
685 unsigned char info[8];
687 * Header or footer
689 unsigned char type;
690 unsigned char where;
691 unsigned char linenumber;
693 unsigned int m_nPageNumber;
696 * Paragraph list of header or footer
698 std::vector<std::unique_ptr<HWPPara>> plist;
700 HeaderFooter();
701 virtual ~HeaderFooter() override;
703 virtual bool Read(HWPFile &hwpf) override;
707 * 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.
708 * @short Footnote or endnote
710 struct Footnote: public HBox
712 hchar reserved[2];
713 hchar dummy;
715 unsigned char info[8];
717 * The number of current footnote/endnote
719 unsigned short number;
721 * Set the type of Footnote either footnote or endnote.
723 unsigned short type;
725 * The width of the Footnote object.
727 hunit width;
729 * Paragraph list of Footnote objects
731 std::vector<std::unique_ptr<HWPPara>> plist;
733 Footnote();
734 virtual ~Footnote() override;
736 virtual bool Read(HWPFile &hwpf) override;
739 // auto number(18)
741 * Kind of auto input number
743 enum
745 PGNUM_AUTO,
746 FNNUM_AUTO,
747 ENNUM_AUTO,
748 PICNUM_AUTO,
749 TBLNUM_AUTO,
750 EQUNUM_AUTO
754 * @short Input current index of page,comment,table and picture.
756 struct AutoNum: public HBox
758 unsigned short type;
759 unsigned short number;
760 hchar dummy;
762 AutoNum();
764 virtual bool Read(HWPFile &hwpf) override;
768 * @short Input new number as current index of page,comment,table and picture.
770 struct NewNum: public HBox
772 unsigned short type;
773 unsigned short number;
774 hchar dummy;
776 NewNum();
778 virtual bool Read(HWPFile &hwpf) override;
781 // page number(20)
783 * @short Input page index in footer or header
785 struct ShowPageNum: public HBox
788 * Location of page number to be inserted.
790 unsigned short where;
791 unsigned int m_nPageNumber;
793 * Shape of page number to be inserted.
795 unsigned short shape;
796 hchar dummy;
798 ShowPageNum();
800 virtual bool Read(HWPFile &hwpf) override;
803 /* Start odd side (21) */
805 * Controls the display of page number, header, footer and border.
807 struct PageNumCtrl: public HBox
810 * object type
812 unsigned short kind;
814 * control command.
816 unsigned short what;
817 hchar dummy;
819 PageNumCtrl();
821 virtual bool Read(HWPFile &hwpf) override;
824 // mail merge(22)
826 * Generates the mailing list automatically using address book and mail body format.
827 * @short Generates mailing list
829 struct MailMerge: public HBox
831 unsigned char field_name[20] = {};
832 hchar dummy;
834 MailMerge();
836 virtual bool Read(HWPFile &hwpf) override;
837 static hchar_string GetString();
840 // char composition(23)
842 * The compose struct displays characters at position. The maximum character count for composition is three.
843 * @short Composition several characters
845 struct Compose: public HBox
847 hchar compose[3];
848 hchar dummy;
850 Compose();
852 virtual bool Read(HWPFile &hwpf) override;
855 // hyphen(24)
857 * @short Hyphen
859 struct Hyphen: public HBox
862 * Width of hyphen
864 hchar width;
865 hchar dummy;
867 Hyphen();
869 virtual bool Read(HWPFile &hwpf) override;
872 // toc mark(25)
874 * The TocMark class is for making the content of a table.
875 * When you set TocMark on current position, hwp makes it as toc automatically.
876 * @short Table of contents
878 struct TocMark: public HBox
880 hchar kind;
881 hchar dummy;
883 TocMark();
885 virtual bool Read(HWPFile &hwpf) override;
888 // index mark(26)
890 * IndexMark marks the table of search.
891 * If you set IndexMark at current position, hwp make it as search index.
892 * @short Table of search
894 struct IndexMark: public HBox
896 hchar keyword1[60] = {};
897 hchar keyword2[60] = {};
898 unsigned short pgno;
899 hchar dummy;
901 IndexMark();
903 virtual bool Read(HWPFile &hwpf) override;
906 // outline(28)
907 #define MAX_OUTLINE_LEVEL 7
909 enum
911 OLSTY_USER = 0,
912 OLSTY_NUMS1 = 1,
913 OLSTY_NUMS2 = 2,
914 OLSTY_NUMSIG1 = 3,
915 OLSTY_NUMSIG2 = 4,
916 OLSTY_NUMSIG3 = 5,
917 OLSTY_BULUSER = 128,
918 OLSTY_BULLET1 = 129,
919 OLSTY_BULLET2 = 130,
920 OLSTY_BULLET3 = 131,
921 OLSTY_BULLET4 = 132,
922 OLSTY_BULLET5 = 133
925 // value is in style->userchar[level];
926 enum
928 UDO_NUM,
929 UDO_UROM,
930 UDO_LROM,
931 UDO_UENG,
932 UDO_LENG,
933 UDO_SYLL,
934 UDO_JAMO,
935 UDO_HANJA,
936 UDO_SP_CNUM,
937 UDO_SP_CLENG,
938 UDO_SP_CSYLL,
939 UDO_SP_CJAMO,
940 N_UDO
943 * Number and format of title.
944 * @short Number and format of title
946 class Outline: public HBox
948 public:
950 * kind of numbering format
952 unsigned short kind;
953 unsigned char shape;
955 * level of number, Ex) The level of 1.3.2.4 is four
957 unsigned char level;
959 * value of level
961 unsigned short number[MAX_OUTLINE_LEVEL];
963 * shape of level
965 hchar user_shape[MAX_OUTLINE_LEVEL];
967 * decoration character for the level type
969 hchar deco[MAX_OUTLINE_LEVEL][2]; /* Prefix/postfix for Customize */
970 hchar dummy;
972 Outline();
974 virtual bool Read(HWPFile &hwpf) override;
975 OUString GetUnicode() const;
978 /* Bundle of spaces (30) */
980 * The Special space to be treated non-space when a string is
981 * cut at the end of line
982 * @short Special space
984 struct KeepSpace: public HBox
986 hchar dummy;
988 KeepSpace();
990 virtual bool Read(HWPFile &hwpf) override;
993 /* Fixed-width spaces (31) */
995 * @short Space with always same width not relation with fonts.
997 struct FixedSpace: public HBox
999 hchar dummy;
1001 FixedSpace();
1003 virtual bool Read(HWPFile &hwpf) override;
1005 #endif // INCLUDED_HWPFILTER_SOURCE_HBOX_H
1007 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */