bump product version to 4.1.6.2
[LibreOffice.git] / hwpfilter / source / hbox.h
blob88d789825269e30f69e3cef7297306b5aaa6a44a
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 _HBOX_H_
21 #define _HBOX_H_
23 #include <list>
25 #include "hwplib.h"
26 #include "hwpfile.h"
27 #include "hinfo.h"
28 #include "hpara.h"
30 /**
31 * The HBox class is the base class for all date classes in hwp document.
32 * For example, there are special character, table, image, etc.
33 * It has one character. The ascii code value of special characters are smaller than 32. General character is greater than 32.
35 * @short Base class for characters
37 struct HBox
39 public:
40 hchar hh;
42 /**
43 * Construct a HBox object with parameter hch.
44 * @param hch 16bit character being able to have Korean character.
46 HBox( hchar hch );
47 virtual ~HBox();
48 /**
49 * @returns The Size of HBox object
51 virtual int WSize();
52 /**
53 * @returns The Height of HBox object as hunit value.
55 virtual hunit Height(CharShape *csty);
56 /**
57 * Read properties from HIODevice object like stream, file, memory.
59 * @param hwpf HWPFile Object having all information for a hwp file.
60 * @returns True if reading from stream is successful.
62 virtual int Read(HWPFile &hwpf);
64 virtual hchar_string GetString();
65 private:
66 static int boxCount;
69 /**
70 * @short Class for saving data to be skipped.
72 struct SkipData: public HBox
74 ulong data_block_len;
75 hchar dummy;
76 char *data_block;
78 SkipData(hchar);
79 virtual ~SkipData();
80 virtual int Read(HWPFile &hwpf);
82 struct DateCode;
83 struct FieldCode : public HBox
85 uchar type[2]; /* 2/0 - °è»ê½Ä, 3/0-¹®¼­¿ä¾à, 3/1-°³ÀÎÁ¤º¸, 3/2-¸¸µç³¯Â¥, 4/0-´©¸§Æ² */
86 char *reserved1;
87 unsigned short location_info; /* 0 - ³¡ÄÚµå, 1 - ½ÃÀÛÄÚµå */
88 char *reserved2;
89 hchar *str1;
90 hchar *str2;
91 hchar *str3;
92 char *bin;
94 DateCode *m_pDate;
96 FieldCode();
97 virtual ~FieldCode();
98 virtual int Read(HWPFile &hwpf);
101 * Kind of BOOKMARK
103 enum
105 BM_MARK,
106 BM_BEGIN,
107 BM_END
110 #define BMK_COMMENT_LEN 15
113 * @short Class for BOOKMARK
115 struct Bookmark: public HBox
117 hchar dummy;
118 hchar id[BMK_COMMENT_LEN + 1];
119 unsigned short type;
121 Bookmark();
122 virtual ~Bookmark();
123 virtual int Read(HWPFile &hwpf);
126 // date format(7)
127 const int DATE_SIZE = 40;
130 * @short Class for saving date format made by user
132 struct DateFormat: public HBox
134 hchar format[DATE_SIZE];
135 hchar dummy;
137 DateFormat();
138 virtual int Read(HWPFile &hwpf);
142 * @short Class for current date and time with specified format.
144 struct DateCode: public HBox
146 enum
148 YEAR, MONTH, WEEK, DAY, HOUR, MIN
151 hchar format[DATE_SIZE];
153 * year/month/week/day/hour/minute
155 short date[6];
156 hchar dummy;
157 unsigned char key;
159 DateCode();
160 virtual int Read(HWPFile &hwpf);
162 virtual hchar_string GetString();
166 * @short Tab object
168 struct Tab: public HBox
170 hunit width;
171 unsigned short leader;
172 hchar dummy;
174 Tab();
175 virtual int Read(HWPFile &hwpf);
178 // tbox(10) TABLE BOX MATH BUTTON HYPERTEXT
180 enum ttype { TBL_TYPE, TXT_TYPE, EQU_TYPE, BUTTON_TYPE, HYPERTEXT_TYPE };
181 enum /* TxtBox->margin[n][?] */
183 OUT_M, IN_M, CELL_M
185 enum /* TxtBox->margin[?][n] */
187 L_M, R_M, T_M, B_M
189 enum anchor { CHAR_ANCHOR, PARA_ANCHOR, PAGE_ANCHOR, PAPER_ANCHOR };
190 enum { TF_OCCUPY_SPACE, TF_TRANSPARENT,TF_ARROUND_TEXT };
191 enum
193 CAP_OUT_BOT, CAP_OUT_TOP, CAP_IN_BOT, CAP_IN_TOP,
194 CAP_LEFT_BOT, CAP_LEFT_TOP, CAP_RIGHT_BOT, CAP_RIGHT_TOP,
195 EQU_CAP_POS
199 * Definitions for frame's common 'option' member.
201 #define DRAW_FRAME 1 /* <-> no frame, bit 0 */
202 #define NORMAL_PIC 2 /* <-> reverse, bit 1 */
203 #define FIT_TO_COLUMN 4 /* fig_xs is columnlen */
204 #define UNKNOWN_FILE 8 /* need check reverse for pcx mono */
205 #define HYPERTEXT_FLAG 16
206 #define UNKNOWN_SIZE 32
207 #define FOPT_TEMP_BIT 0x00010000 /* temporary starts from 16th bits */
209 struct CellLine
211 unsigned char key;
212 unsigned char top; // 0 - ¶óÀξøÀ½, 1-single, 2-thick, 3-double
213 unsigned char bottom;
214 unsigned char left;
215 unsigned char right;
216 short color; // cell color
217 unsigned char shade; // <100%
220 * A cell has four properties to specify the position for itself in hwp.
221 * @li xpos - distance between left border of cell and left border of table
222 * @li ypos - distance between top border of cell and top border of table
223 * @li width - distance between left border of cell and right border of cell
224 * @li height - distance between top border of cell and bottom border of table
225 * This is differ from the format of other office in fact cell has two properties
226 * - rowindex and column index.
228 * @short Cell object
230 struct Cell // Cell
232 unsigned char key; // Index value of border style
233 short p;
234 short color; // cell color
235 short x, y; // [x,y] cell pos
236 short w, h; // [x,y] cell size
237 short txthigh, cellhigh; // used maximum
238 unsigned char flag, changed, used; // unused(file)
239 unsigned char ver_align; // vertical align {1=center}
240 unsigned char linetype[4]; // [left,right,top,bottom]
241 unsigned char shade; // <100%
242 unsigned char diagonal; // { 0=none,\=1,/=2,X=3}
243 unsigned char protect;
245 void Read( HWPFile &hwpf );
249 * @short Style for floating object
251 struct FBoxStyle
254 * Anchor type : paragraph , page, char
256 unsigned char anchor_type;
258 * Kind of wrap
260 unsigned char txtflow; /* ±×¸²ÇÇÇÔ. 0-2(ÀÚ¸®Â÷Áö,Åõ¸í,¾î¿ï¸²) */
262 * Horizontal alignment
264 short xpos; // left, right, center, xx
266 * Vertical alignment
268 short ypos; // page top, bottom, yy
270 * Every margin of border
271 * [0-2][] : out/in/cell margin
272 * [][0-3] : left/right/top/bottom
274 short margin[3][4]; // out : left, right, top, bottom
276 * Index of floating object
278 short boxnum; /* ½ºÅ¸¿ÀÇǽº¿¡¼­ ½ºÅ¸ÀÏ À̸§À¸·Î »ç¿ëµÉ ¼ýÀÚ */
280 * Type of floating object : line, txtbox, image, table, equalizer and button
282 unsigned char boxtype; // (L)ine, t(X)tbox, Picture - (G)
283 short cap_len; /* ĸ¼ÇÀÇ ±æÀÌ */
285 void *cell;
290 * This object is for floating object like table, image, line and so on.
292 * @short floating object
294 struct FBox: public HBox
296 int zorder;
297 short option; // draw frame
298 hchar ctrl_ch;
299 FBoxStyle style;
301 short box_xs, box_ys;
302 short cap_xs, cap_ys ;
303 short xs, ys; // ys = fig_ys + cap_ys + margin
304 // xs = fig_xs + cap_xs + margin
305 short cap_margin;
306 char xpos_type, ypos_type;
307 unsigned char smart_linesp;
309 /* ÀÌ ÀÚ·á´Â tbox³ª pic¿¡¼­´Â ÆÄÀÏ¿¡ ±â·ÏÇÏÁö ¾Ê°í ½ÇÇà½Ã¸¸ ÀÖÀ¸¸ç,
310 line¿¡¼­´Â ÆÄÀÏ¿¡ ±â·ÏÇÑ´Ù.
312 short boundsy, boundey;
313 unsigned char boundx, draw;
316 * Physical x,y position.
318 short pgx, pgy; // physical xpos, ypos
319 short pgno, showpg; // pageno where code is
321 FBox *prev, *next;
323 FBox( hchar hch );
324 virtual ~FBox();
327 struct Table;
329 * The TxtBox class saves object properties about table, textbox, equalizer or button
331 struct TxtBox: public FBox
333 hchar reserved[2];
334 hchar dummy;
336 short dummy1; // to not change structure size */
337 short cap_len;
338 short next;
339 short dummy2; // to not change structure size */
340 unsigned char reserved1;
342 * caption position
344 short cap_pos; // caption pos
345 short num; // numbering
347 short dummy3;
348 short baseline; //(for equ)
351 * The value of type indicates as the below: zero is table, one is
352 * textbox, two is equalizer and three is button.
354 short type; // 0-table, 1-textbox, 2-¼ö½Ä, 3-button
356 * nCell is greater than one only for table, otherwise it is 1.
358 short nCell; //:=1 offset 80
360 * If value of protect is 1, size of cell cann't change.
362 short protect; //1=size lock
364 Cell *cell;
365 Table *m_pTable;
367 * Paragraph list
369 std::list<HWPPara*> *plists;
371 * Caption
373 std::list<HWPPara*> caption;
375 TxtBox();
376 virtual ~TxtBox();
379 * @returns Count of cell.
381 virtual int NCell() { return nCell; }
383 * This is one of table, text-box, equalizer and button
384 * @returns Type of this object.
386 virtual int Type() { return type; }
388 virtual int Read(HWPFile &hwpf);
390 virtual hunit Height(CharShape *csty);
393 #define ALLOWED_GAP 5
394 #define INIT_SIZE 20
395 #define ADD_AMOUNT 10
397 struct Columns
399 int *data;
400 size_t nCount;
401 size_t nTotal;
402 Columns(){
403 nCount = 0;
404 nTotal = INIT_SIZE;
405 data = new int[nTotal];
407 ~Columns(){ delete[] data; }
409 void AddColumnsSize(){
410 int *tmp = data;
411 if (nTotal + ADD_AMOUNT < nTotal) // overflow
413 throw ::std::bad_alloc();
415 data = new int[nTotal + ADD_AMOUNT];
416 for (size_t i = 0 ; i < nTotal ; i++)
417 data[i] = tmp[i];
418 nTotal += ADD_AMOUNT;
419 delete[] tmp;
422 void insert(int pos){
423 if( nCount == 0 ){
424 data[nCount++] = pos;
425 return;
427 for (size_t i = 0 ; i < nCount; i++ ) {
428 if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
429 return; // Already exist;
430 if( pos < data[i] ){
431 if( nCount == nTotal )
432 AddColumnsSize();
433 for (size_t j = nCount ; j > i ; j--)
434 data[j] = data[j-1];
435 data[i] = pos;
436 nCount++;
437 return;
440 // last postion.
441 if( nCount == nTotal )
442 AddColumnsSize();
443 data[nCount++] = pos;
446 int getIndex(int pos)
448 if( pos == 0 )
449 return 0;
450 for (size_t i = 0 ; i < nCount; i++) {
451 if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
452 return i;
454 return -1;
458 struct Rows
460 int *data;
461 size_t nCount;
462 size_t nTotal;
463 Rows(){
464 nCount = 0;
465 nTotal = INIT_SIZE;
466 data = new int[nTotal];
468 ~Rows(){ delete[] data; }
470 void AddRowsSize(){
471 int *tmp = data;
472 if (nTotal + ADD_AMOUNT < nTotal) // overflow
474 throw ::std::bad_alloc();
476 data = new int[nTotal + ADD_AMOUNT];
477 for (size_t i = 0 ; i < nTotal ; i++)
478 data[i] = tmp[i];
479 nTotal += ADD_AMOUNT;
480 delete[] tmp;
483 void insert(int pos){
484 if( nCount == 0 ){
485 data[nCount++] = pos;
486 return;
488 for (size_t i = 0 ; i < nCount; i++) {
489 if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
490 return; // Already exist;
491 if( pos < data[i] ){
492 if( nCount == nTotal )
493 AddRowsSize();
494 for (size_t j = nCount ; j > i ; j--)
495 data[j] = data[j-1];
496 data[i] = pos;
497 nCount++;
498 return;
501 // last postion.
502 if( nCount == nTotal )
503 AddRowsSize();
504 data[nCount++] = pos;
507 int getIndex(int pos)
509 if( pos == 0 )
510 return 0;
511 for (size_t i = 0 ; i < nCount; i++) {
512 if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
513 return i;
515 return -1;
519 struct TCell
521 int nColumnIndex;
522 int nRowIndex;
523 int nColumnSpan;
524 int nRowSpan;
525 Cell *pCell;
528 struct Table
530 Table(){};
531 ~Table(){
532 std::list<TCell*>::iterator it = cells.begin();
533 for( ; it != cells.end(); ++it)
534 delete *it;
536 Columns columns;
537 Rows rows;
538 std::list<TCell*> cells;
539 TxtBox *box;
542 /* picture (11) ±×¸², OLE±×¸², »ðÀԱ׸², ±×¸®±â */
543 enum pictype
545 PICTYPE_FILE, PICTYPE_OLE, PICTYPE_EMBED,
546 PICTYPE_DRAW, PICTYPE_UNKNOWN
549 * @short External image file
551 struct PicDefFile
553 char path[256];
554 void *img;
555 bool skipfind;
559 * @short Embeded image file
561 struct PicDefEmbed
563 char embname[16];
567 * @short Win32 ole object
569 struct PicDefOle
571 char embname[16];
572 void *hwpole;
576 * @short Drawing object of hwp
578 struct PicDefDraw
580 void *hdo;
581 uint zorder;
582 ZZRect vrect;
583 int mbrcnt;
587 * @short For using common case
589 struct PicDefUnknown
591 char path[256];
594 typedef union
596 PicDefFile picfile;
597 PicDefEmbed picembed;
598 PicDefOle picole;
599 PicDefDraw picdraw;
600 PicDefUnknown picun;
601 } PicDef;
603 #define PIC_INFO_LEN 348
605 * There are four kinds of image.
606 * @li External image
607 * @li Embeded image
608 * @li Win32 ole object
609 * @li Drawing object of hwp
611 * @short Image object
613 struct Picture: public FBox
615 hchar reserved[2];
616 hchar dummy;
618 * follow_block_size is the size information of the Drawing object of hwp.
619 * It's value is greater than 0 if the pictype is PICTYPE_DRAW.
621 ulong follow_block_size; /* Ãß°¡Á¤º¸ ±æÀÌ. */
622 short dummy1; // to not change structure size */
623 short dummy2; // to not change structure size */
624 uchar reserved1;
626 * Position of caption
628 short cap_pos; // caption pos
630 * Index of current Picture object
632 short num; // numbering
635 * Type of this object
636 * It is one of external/ole/embeded/drawing picture
638 uchar pictype;
639 hunit skip[2];
641 * Ratio of magnification or reduction.
643 hunit scale[2];
644 PicDef picinfo;
645 char reserved3[9];
647 std::list<HWPPara*> caption;
649 * It's for the Drawing object
651 unsigned char *follow; /* ±×¸²Á¾·ù°¡ drawingÀ϶§, Ãß°¡Á¤º¸. */
653 bool ishyper;
655 Picture();
656 virtual ~Picture();
658 virtual int Type ();
659 virtual int Read (HWPFile &hwpf);
661 virtual hunit Height (CharShape *sty);
664 // line (14)
666 * @short Line
668 struct Line: public FBox
670 hchar reserved[2];
671 hchar dummy;
673 char reserved2[8];
675 short sx, sy, ex, ey;
676 short width, shade, color;
678 Line();
680 virtual int Read(HWPFile &hwpf);
683 // hidden(15)
685 * @short Hidden section
687 struct Hidden: public HBox
689 hchar reserved[2];
690 hchar dummy;
692 unsigned char info[8]; // h, next, dummy
693 std::list<HWPPara*> plist;
695 Hidden();
696 virtual ~Hidden();
698 virtual int Read(HWPFile &hwpf);
702 * @short Header or footer
704 struct HeaderFooter: public HBox
706 hchar reserved[2];
707 hchar dummy;
709 unsigned char info[8];
711 * Header or footer
713 unsigned char type;
714 unsigned char where;
715 unsigned char linenumber;
717 unsigned int m_nPageNumber;
720 * Paragraph list of header or footer
722 std::list<HWPPara*> plist;
724 HeaderFooter();
725 virtual ~HeaderFooter();
727 virtual int Read(HWPFile &hwpf);
731 * 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.
732 * @short Footnote or endnote
734 struct Footnote: public HBox
736 hchar reserved[2];
737 hchar dummy;
739 unsigned char info[8];
741 * The number of current footnote/endnote
743 unsigned short number;
745 * Set the type of Footnote either footnote or endnote.
747 unsigned short type;
749 * The width of the Footnote object.
751 hunit width;
753 * Paragraph list of Footnote objects
755 std::list<HWPPara*> plist;
757 Footnote();
758 virtual ~Footnote();
760 virtual int Read(HWPFile &hwpf);
763 // auto number(18)
765 * Kind of auto input number
767 enum
769 PGNUM_AUTO,
770 FNNUM_AUTO,
771 ENNUM_AUTO,
772 PICNUM_AUTO,
773 TBLNUM_AUTO,
774 EQUNUM_AUTO
778 * @short Input current index of page,comment,table and picture.
780 struct AutoNum: public HBox
782 unsigned short type;
783 unsigned short number;
784 hchar dummy;
786 AutoNum();
788 virtual int Read(HWPFile &hwpf);
792 * @short Input new number as current index of page,comment,table and picture.
794 struct NewNum: public HBox
796 unsigned short type;
797 unsigned short number;
798 hchar dummy;
800 NewNum();
802 virtual int Read(HWPFile &hwpf);
805 // page numger(20)
807 * @short Input page index in footer or header
809 struct ShowPageNum: public HBox
812 * Location of page number to be inserted.
814 unsigned short where;
815 unsigned int m_nPageNumber;
817 * Shape of page number to be inserted.
819 unsigned short shape;
820 hchar dummy;
822 ShowPageNum();
824 virtual int Read(HWPFile &hwpf);
827 /* Ȧ¼öÂʽÃÀÛ (21) */
828 #define HIDE_HD 1 /* bit 0 */
829 #define HIDE_FT 2 /* bit 1 */
830 #define HIDE_PGNUM 4 /* bit 2 */
831 #define HIDE_FRAME 8 /* bit 3 */
833 * Controls the display of page number, header, footer and border.
835 struct PageNumCtrl: public HBox
838 * object type
840 unsigned short kind;
842 * control command.
844 unsigned short what;
845 hchar dummy;
847 PageNumCtrl();
849 virtual int Read(HWPFile &hwpf);
852 // mail merge(22)
854 * Generates the mailing list automatically using address book and mail body format.
855 * @short Generates mailing list
857 struct MailMerge: public HBox
859 unsigned char field_name[20];
860 hchar dummy;
862 MailMerge();
864 virtual int Read(HWPFile &hwpf);
865 virtual hchar_string GetString();
868 // char compositon(23)
870 * The compose struct displays characters at position. The maximum character count for composition is three.
871 * @short Composition several characters
873 struct Compose: public HBox
875 hchar compose[3];
876 hchar dummy;
878 Compose();
880 virtual int Read(HWPFile &hwpf);
883 // hyphen(24)
885 * @short Hyphen
887 struct Hyphen: public HBox
890 * Width of hyphen
892 hchar width;
893 hchar dummy;
895 Hyphen();
897 virtual int Read(HWPFile &hwpf);
900 // toc mark(25)
902 * The TocMark class is for making the content of a table.
903 * When you set TocMark on current position, hwp makes it as toc automatically.
904 * @short Table of contents
906 struct TocMark: public HBox
908 hchar kind;
909 hchar dummy;
911 TocMark();
913 virtual int Read(HWPFile &hwpf);
916 // index mark(26)
918 * IndexMark marks the table of search.
919 * If you set IndexMark at current position, hwp make it as search index.
920 * @short Table of search
922 struct IndexMark: public HBox
924 hchar keyword1[60];
925 hchar keyword2[60];
926 unsigned short pgno;
927 hchar dummy;
929 IndexMark();
931 virtual int Read(HWPFile &hwpf);
934 // outline(28)
935 #define MAX_OUTLINE_LEVEL 7
937 enum
939 OLSTY_USER = 0,
940 OLSTY_NUMS1 = 1,
941 OLSTY_NUMS2 = 2,
942 OLSTY_NUMSIG1 = 3,
943 OLSTY_NUMSIG2 = 4,
944 OLSTY_NUMSIG3 = 5,
945 OLSTY_BULUSER = 128,
946 OLSTY_BULLET1 = 129,
947 OLSTY_BULLET2 = 130,
948 OLSTY_BULLET3 = 131,
949 OLSTY_BULLET4 = 132,
950 OLSTY_BULLET5 = 133
953 // value is in style->userchar[level];
954 enum
956 UDO_NUM,
957 UDO_UROM,
958 UDO_LROM,
959 UDO_UENG,
960 UDO_LENG,
961 UDO_SYLL,
962 UDO_JAMO,
963 UDO_HANJA,
964 UDO_SP_CNUM,
965 UDO_SP_CLENG,
966 UDO_SP_CSYLL,
967 UDO_SP_CJAMO,
968 N_UDO
971 * Number and format of title.
972 * @short Number and format of title
974 class Outline: public HBox
976 public:
978 * kind of numbering format
980 unsigned short kind;
981 unsigned char shape;
983 * level of number, Ex) The level of 1.3.2.4 is four
985 unsigned char level;
987 * value of level
989 unsigned short number[MAX_OUTLINE_LEVEL];
991 * shape of level
993 hchar user_shape[MAX_OUTLINE_LEVEL];
995 * decoration character for the level type
997 hchar deco[MAX_OUTLINE_LEVEL][2]; /* »ç¿ëÀÚ Á¤Àǽà ¾ÕµÚ ¹®ÀÚ */
998 hchar dummy;
1000 Outline();
1002 virtual int Read(HWPFile &hwpf);
1003 hchar_string GetUnicode() const;
1006 /* ¹­À½ ºóÄ­(30) */
1008 * The Special space to be treated non-space when a string is
1009 * cut at the end of line
1010 * @short Special space
1012 struct KeepSpace: public HBox
1014 hchar dummy;
1016 KeepSpace();
1018 virtual int Read(HWPFile &hwpf);
1021 /* °íÁ¤Æø ºóÄ­(31) */
1023 * @short Space with always same width not relation with fonts.
1025 struct FixedSpace: public HBox
1027 hchar dummy;
1029 FixedSpace();
1031 virtual int Read(HWPFile &hwpf);
1033 #endif /* _HBOX_H_ */
1035 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */