nss: upgrade to release 3.73
[LibreOffice.git] / hwpfilter / source / hbox.h
blob869fedd8ba9062e67d9fa86765629be93388aef4
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 <sal/types.h>
30 #include "hwplib.h"
31 #include "hwpfile.h"
32 #include "hinfo.h"
33 #include "hpara.h"
35 /**
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
42 struct HBox
44 public:
45 hchar hh;
47 /**
48 * Construct a HBox object with parameter hch.
49 * @param hch 16bit character being able to have Korean character.
51 explicit HBox( hchar hch );
52 virtual ~HBox();
53 /**
54 * @returns The Size of HBox object
56 int WSize();
57 /**
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);
65 private:
66 static int boxCount;
69 /**
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;
79 struct DateCode;
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;
92 FieldCode();
93 virtual ~FieldCode() override;
94 virtual bool Read(HWPFile &hwpf) override;
96 /**
97 * Kind of BOOKMARK
99 enum
101 BM_MARK,
102 BM_BEGIN,
103 BM_END
106 #define BMK_COMMENT_LEN 15
109 * @short Class for BOOKMARK
111 struct Bookmark: public HBox
113 hchar dummy;
114 hchar id[BMK_COMMENT_LEN + 1];
115 unsigned short type;
117 Bookmark();
118 virtual ~Bookmark() override;
119 virtual bool Read(HWPFile &hwpf) override;
122 // date format(7)
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];
131 hchar dummy;
133 DateFormat();
134 virtual bool Read(HWPFile &hwpf) override;
138 * @short Class for current date and time with specified format.
140 struct DateCode: public HBox
142 enum
144 YEAR, MONTH, WEEK, DAY, HOUR, MIN
147 hchar format[DATE_SIZE];
149 * year/month/week/day/hour/minute
151 short date[6];
152 hchar dummy;
153 unsigned char key;
155 DateCode();
156 virtual bool Read(HWPFile &hwpf) override;
158 hchar_string GetString();
162 * @short Tab object
164 struct Tab: public HBox
166 hunit width;
167 unsigned short leader;
168 hchar dummy;
170 Tab();
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][?] */
179 OUT_M, IN_M, CELL_M
181 enum /* TxtBox->margin[?][n] */
183 L_M, R_M, T_M, B_M
185 enum anchor { CHAR_ANCHOR, PARA_ANCHOR, PAGE_ANCHOR, PAPER_ANCHOR };
186 enum { TF_OCCUPY_SPACE, TF_TRANSPARENT,TF_AROUND_TEXT };
187 enum
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,
191 EQU_CAP_POS
194 struct CellLine
196 unsigned char key;
197 unsigned char top; // 0-No line, 1-single, 2-thick, 3-double
198 unsigned char bottom;
199 unsigned char left;
200 unsigned char right;
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.
213 * @short Cell object
215 struct Cell // Cell
217 unsigned char key; // Index value of border style
218 short p;
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
236 struct FBoxStyle
239 * Anchor type : paragraph , page, char
241 unsigned char anchor_type;
243 * Kind of wrap
245 unsigned char txtflow; /* Avoid painting. 0-2 (seat occupied, transparency, harmony) */
247 * Horizontal alignment
249 short xpos; // left, right, center, xx
251 * Vertical alignment
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 */
270 void *cell;
272 FBoxStyle()
273 : anchor_type(0)
274 , txtflow(0)
275 , xpos(0)
276 , ypos(0)
277 , boxnum(0)
278 , boxtype(0)
279 , cap_len(0)
280 , cell(nullptr)
286 * This object is for floating object like table, image, line and so on.
288 * @short floating object
290 struct FBox: public HBox
292 int zorder;
293 short option; // draw frame
294 hchar ctrl_ch;
295 FBoxStyle style;
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
301 short cap_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;
321 struct Table;
323 * The TxtBox class saves object properties about table, textbox, equalizer or button
325 struct TxtBox: public FBox
327 hchar reserved[2];
328 hchar dummy;
330 short dummy1; // to not change structure size */
331 short cap_len;
332 short next_box;
333 short dummy2; // to not change structure size */
334 unsigned char reserved1;
336 * caption position
338 short cap_pos; // caption pos
339 short num; // numbering
341 short dummy3;
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;
359 Table *m_pTable;
361 * Paragraph list
363 std::vector<std::vector<std::unique_ptr<HWPPara>>> plists;
366 * Caption
368 std::vector<std::unique_ptr<HWPPara>> caption;
370 TxtBox();
371 virtual ~TxtBox() override;
373 virtual bool Read(HWPFile &hwpf) override;
376 #define ALLOWED_GAP 5
377 #define INIT_SIZE 20
378 #define ADD_AMOUNT 10
380 struct Columns
382 std::unique_ptr<int[]> data;
383 size_t nCount;
384 size_t nTotal;
385 Columns(){
386 nCount = 0;
387 nTotal = INIT_SIZE;
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++)
398 tmp[i] = data[i];
399 nTotal += ADD_AMOUNT;
400 data.reset(tmp);
403 void insert(int pos){
404 if( nCount == 0 ){
405 data[nCount++] = pos;
406 return;
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;
411 if( pos < data[i] ){
412 if( nCount == nTotal )
413 AddColumnsSize();
414 for (size_t j = nCount ; j > i ; j--)
415 data[j] = data[j-1];
416 data[i] = pos;
417 nCount++;
418 return;
421 // last position.
422 if( nCount == nTotal )
423 AddColumnsSize();
424 data[nCount++] = pos;
427 int getIndex(int pos)
429 if( pos == 0 )
430 return 0;
431 for (size_t i = 0 ; i < nCount; i++) {
432 if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
433 return i;
435 return -1;
439 struct Rows
441 std::unique_ptr<int[]> data;
442 size_t nCount;
443 size_t nTotal;
444 Rows(){
445 nCount = 0;
446 nTotal = INIT_SIZE;
447 data.reset( new int[nTotal] );
450 void AddRowsSize(){
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++)
457 tmp[i] = data[i];
458 nTotal += ADD_AMOUNT;
459 data.reset(tmp);
462 void insert(int pos){
463 if( nCount == 0 ){
464 data[nCount++] = pos;
465 return;
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;
470 if( pos < data[i] ){
471 if( nCount == nTotal )
472 AddRowsSize();
473 for (size_t j = nCount ; j > i ; j--)
474 data[j] = data[j-1];
475 data[i] = pos;
476 nCount++;
477 return;
480 // last position.
481 if( nCount == nTotal )
482 AddRowsSize();
483 data[nCount++] = pos;
486 int getIndex(int pos)
488 if( pos == 0 )
489 return 0;
490 for (size_t i = 0 ; i < nCount; i++) {
491 if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
492 return i;
494 return -1;
498 struct TCell
500 int nColumnIndex;
501 int nRowIndex;
502 int nColumnSpan;
503 int nRowSpan;
504 Cell *pCell;
507 struct Table
509 Table() : box(nullptr) {};
511 Columns columns;
512 Rows rows;
513 std::vector<std::unique_ptr<TCell>> cells;
514 TxtBox *box;
517 /* picture (11) graphics, OLE graphics, inserted graphics, drawing */
518 enum pictype
520 PICTYPE_FILE, PICTYPE_OLE, PICTYPE_EMBED,
521 PICTYPE_DRAW, PICTYPE_UNKNOWN
524 * @short External image file
526 struct PicDefFile
528 char path[256];
529 void *img;
530 bool skipfind;
534 * @short Embedded image file
536 struct PicDefEmbed
538 char embname[16];
542 * @short Win32 ole object
544 struct PicDefOle
546 char embname[16];
547 void *hwpole;
550 struct HWPDrawingObject;
553 * @short Drawing object of hwp
555 struct PicDefDraw
557 HWPDrawingObject *hdo;
558 uint zorder;
559 ZZRect vrect;
560 int mbrcnt;
564 * @short For using common case
566 struct PicDefUnknown
568 char path[256];
571 typedef union
573 PicDefFile picfile;
574 PicDefEmbed picembed;
575 PicDefOle picole;
576 PicDefDraw picdraw;
577 PicDefUnknown picun;
578 } PicDef;
581 * There are four kinds of image.
582 * @li External image
583 * @li Embedded image
584 * @li Win32 ole object
585 * @li Drawing object of hwp
587 * @short Image object
589 struct Picture: public FBox
591 hchar reserved[2];
592 hchar dummy;
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 */
600 uchar reserved1;
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
614 uchar pictype;
615 hunit skip[2];
617 * Ratio of magnification or reduction.
619 hunit scale[2];
620 PicDef picinfo = {};
621 char reserved3[9];
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. */
629 bool ishyper;
631 Picture();
632 virtual ~Picture() override;
634 virtual bool Read (HWPFile &hwpf) override;
637 // line (14)
639 * @short Line
641 struct Line: public FBox
643 hchar reserved[2];
644 hchar dummy;
646 char reserved2[8];
648 short sx, sy, ex, ey;
649 short width, shade, color;
651 Line();
653 virtual bool Read(HWPFile &hwpf) override;
656 // hidden(15)
658 * @short Hidden section
660 struct Hidden: public HBox
662 hchar reserved[2];
663 hchar dummy;
665 unsigned char info[8]; // h, next, dummy
666 std::vector<std::unique_ptr<HWPPara>> plist;
668 Hidden();
669 virtual ~Hidden() override;
671 virtual bool Read(HWPFile &hwpf) override;
675 * @short Header or footer
677 struct HeaderFooter: public HBox
679 hchar reserved[2];
680 hchar dummy;
682 unsigned char info[8];
684 * Header or footer
686 unsigned char type;
687 unsigned char where;
688 unsigned char linenumber;
690 unsigned int m_nPageNumber;
693 * Paragraph list of header or footer
695 std::vector<std::unique_ptr<HWPPara>> plist;
697 HeaderFooter();
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
709 hchar reserved[2];
710 hchar dummy;
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.
720 unsigned short type;
722 * The width of the Footnote object.
724 hunit width;
726 * Paragraph list of Footnote objects
728 std::vector<std::unique_ptr<HWPPara>> plist;
730 Footnote();
731 virtual ~Footnote() override;
733 virtual bool Read(HWPFile &hwpf) override;
736 // auto number(18)
738 * Kind of auto input number
740 enum
742 PGNUM_AUTO,
743 FNNUM_AUTO,
744 ENNUM_AUTO,
745 PICNUM_AUTO,
746 TBLNUM_AUTO,
747 EQUNUM_AUTO
751 * @short Input current index of page,comment,table and picture.
753 struct AutoNum: public HBox
755 unsigned short type;
756 unsigned short number;
757 hchar dummy;
759 AutoNum();
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
769 unsigned short type;
770 unsigned short number;
771 hchar dummy;
773 NewNum();
775 virtual bool Read(HWPFile &hwpf) override;
778 // page number(20)
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;
793 hchar dummy;
795 ShowPageNum();
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
807 * object type
809 unsigned short kind;
811 * control command.
813 unsigned short what;
814 hchar dummy;
816 PageNumCtrl();
818 virtual bool Read(HWPFile &hwpf) override;
821 // mail merge(22)
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] = {};
829 hchar dummy;
831 MailMerge();
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
844 hchar compose[3];
845 hchar dummy;
847 Compose();
849 virtual bool Read(HWPFile &hwpf) override;
852 // hyphen(24)
854 * @short Hyphen
856 struct Hyphen: public HBox
859 * Width of hyphen
861 hchar width;
862 hchar dummy;
864 Hyphen();
866 virtual bool Read(HWPFile &hwpf) override;
869 // toc mark(25)
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
877 hchar kind;
878 hchar dummy;
880 TocMark();
882 virtual bool Read(HWPFile &hwpf) override;
885 // index mark(26)
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] = {};
895 unsigned short pgno;
896 hchar dummy;
898 IndexMark();
900 virtual bool Read(HWPFile &hwpf) override;
903 // outline(28)
904 #define MAX_OUTLINE_LEVEL 7
906 enum
908 OLSTY_USER = 0,
909 OLSTY_NUMS1 = 1,
910 OLSTY_NUMS2 = 2,
911 OLSTY_NUMSIG1 = 3,
912 OLSTY_NUMSIG2 = 4,
913 OLSTY_NUMSIG3 = 5,
914 OLSTY_BULUSER = 128,
915 OLSTY_BULLET1 = 129,
916 OLSTY_BULLET2 = 130,
917 OLSTY_BULLET3 = 131,
918 OLSTY_BULLET4 = 132,
919 OLSTY_BULLET5 = 133
922 // value is in style->userchar[level];
923 enum
925 UDO_NUM,
926 UDO_UROM,
927 UDO_LROM,
928 UDO_UENG,
929 UDO_LENG,
930 UDO_SYLL,
931 UDO_JAMO,
932 UDO_HANJA,
933 UDO_SP_CNUM,
934 UDO_SP_CLENG,
935 UDO_SP_CSYLL,
936 UDO_SP_CJAMO,
937 N_UDO
940 * Number and format of title.
941 * @short Number and format of title
943 class Outline: public HBox
945 public:
947 * kind of numbering format
949 unsigned short kind;
950 unsigned char shape;
952 * level of number, Ex) The level of 1.3.2.4 is four
954 unsigned char level;
956 * value of level
958 unsigned short number[MAX_OUTLINE_LEVEL];
960 * shape of 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 */
967 hchar dummy;
969 Outline();
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
983 hchar dummy;
985 KeepSpace();
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
996 hchar dummy;
998 FixedSpace();
1000 virtual bool Read(HWPFile &hwpf) override;
1002 #endif // INCLUDED_HWPFILTER_SOURCE_HBOX_H
1004 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */