fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / hwpfilter / source / hbox.h
blobc1e5f18db7772d13279fce80f8d7d10f6a67396b
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 <list>
27 #include <sal/types.h>
29 #include "hwplib.h"
30 #include "hwpfile.h"
31 #include "hinfo.h"
32 #include "hpara.h"
34 /**
35 * The HBox class is the base class for all date classes in hwp document.
36 * For example, there are special character, table, image, etc.
37 * It has one character. The ascii code value of special characters are smaller than 32. General character is greater than 32.
39 * @short Base class for characters
41 struct HBox
43 public:
44 hchar hh;
46 /**
47 * Construct a HBox object with parameter hch.
48 * @param hch 16bit character being able to have Korean character.
50 HBox( hchar hch );
51 virtual ~HBox();
52 /**
53 * @returns The Size of HBox object
55 int WSize();
56 /**
57 * @returns The Height of HBox object as hunit value.
59 virtual hunit Height(CharShape *csty);
60 /**
61 * Read properties from HIODevice object like stream, file, memory.
63 * @param hwpf HWPFile Object having all information for a hwp file.
64 * @returns True if reading from stream is successful.
66 virtual bool Read(HWPFile &hwpf);
68 virtual hchar_string GetString();
69 private:
70 static int boxCount;
73 /**
74 * @short Class for saving data to be skipped.
76 struct SkipData: public HBox
78 uint data_block_len;
79 hchar dummy;
80 char *data_block;
82 SkipData(hchar);
83 virtual ~SkipData();
84 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
86 struct DateCode;
87 struct FieldCode : public HBox
89 uchar type[2]; /* 2/0 - 계산식, 3/0-문서요약, 3/1-개인정보, 3/2-만든날짜, 4/0-누름틀 */
90 char *reserved1;
91 unsigned short location_info; /* 0 - 끝코드, 1 - 시작코드 */
92 char *reserved2;
93 hchar *str1;
94 hchar *str2;
95 hchar *str3;
96 char *bin;
98 DateCode *m_pDate;
100 FieldCode();
101 virtual ~FieldCode();
102 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
105 * Kind of BOOKMARK
107 enum
109 BM_MARK,
110 BM_BEGIN,
111 BM_END
114 #define BMK_COMMENT_LEN 15
117 * @short Class for BOOKMARK
119 struct Bookmark: public HBox
121 hchar dummy;
122 hchar id[BMK_COMMENT_LEN + 1];
123 unsigned short type;
125 Bookmark();
126 virtual ~Bookmark();
127 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
130 // date format(7)
131 const int DATE_SIZE = 40;
134 * @short Class for saving date format made by user
136 struct DateFormat: public HBox
138 hchar format[DATE_SIZE];
139 hchar dummy;
141 DateFormat();
142 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
146 * @short Class for current date and time with specified format.
148 struct DateCode: public HBox
150 enum
152 YEAR, MONTH, WEEK, DAY, HOUR, MIN
155 hchar format[DATE_SIZE];
157 * year/month/week/day/hour/minute
159 short date[6];
160 hchar dummy;
161 unsigned char key;
163 DateCode();
164 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
166 virtual hchar_string GetString() SAL_OVERRIDE;
170 * @short Tab object
172 struct Tab: public HBox
174 hunit width;
175 unsigned short leader;
176 hchar dummy;
178 Tab();
179 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
182 // tbox(10) TABLE BOX MATH BUTTON HYPERTEXT
184 enum ttype { TBL_TYPE, TXT_TYPE, EQU_TYPE, BUTTON_TYPE, HYPERTEXT_TYPE };
185 enum /* TxtBox->margin[n][?] */
187 OUT_M, IN_M, CELL_M
189 enum /* TxtBox->margin[?][n] */
191 L_M, R_M, T_M, B_M
193 enum anchor { CHAR_ANCHOR, PARA_ANCHOR, PAGE_ANCHOR, PAPER_ANCHOR };
194 enum { TF_OCCUPY_SPACE, TF_TRANSPARENT,TF_ARROUND_TEXT };
195 enum
197 CAP_OUT_BOT, CAP_OUT_TOP, CAP_IN_BOT, CAP_IN_TOP,
198 CAP_LEFT_BOT, CAP_LEFT_TOP, CAP_RIGHT_BOT, CAP_RIGHT_TOP,
199 EQU_CAP_POS
202 struct CellLine
204 unsigned char key;
205 unsigned char top; // 0 - 라인없음, 1-single, 2-thick, 3-double
206 unsigned char bottom;
207 unsigned char left;
208 unsigned char right;
209 short color; // cell color
210 unsigned char shade; // <100%
213 * A cell has four properties to specify the position for itself in hwp.
214 * @li xpos - distance between left border of cell and left border of table
215 * @li ypos - distance between top border of cell and top border of table
216 * @li width - distance between left border of cell and right border of cell
217 * @li height - distance between top border of cell and bottom border of table
218 * This is differ from the format of other office in fact cell has two properties
219 * - rowindex and column index.
221 * @short Cell object
223 struct Cell // Cell
225 unsigned char key; // Index value of border style
226 short p;
227 short color; // cell color
228 short x, y; // [x,y] cell pos
229 short w, h; // [x,y] cell size
230 short txthigh, cellhigh; // used maximum
231 unsigned char flag, changed, used; // unused(file)
232 unsigned char ver_align; // vertical align {1=center}
233 unsigned char linetype[4]; // [left,right,top,bottom]
234 unsigned char shade; // <100%
235 unsigned char diagonal; // { 0=none,\=1,/=2,X=3}
236 unsigned char protect;
238 void Read( HWPFile &hwpf );
242 * @short Style for floating object
244 struct FBoxStyle
247 * Anchor type : paragraph , page, char
249 unsigned char anchor_type;
251 * Kind of wrap
253 unsigned char txtflow; /* 그림피함. 0-2(자리차지,투명,어울림) */
255 * Horizontal alignment
257 short xpos; // left, right, center, xx
259 * Vertical alignment
261 short ypos; // page top, bottom, yy
263 * Every margin of border
264 * [0-2][] : out/in/cell margin
265 * [][0-3] : left/right/top/bottom
267 short margin[3][4]; // out : left, right, top, bottom
269 * Index of floating object
271 short boxnum; /* 스타오피스에서 스타일 이름으로 사용될 숫자 */
273 * Type of floating object : line, txtbox, image, table, equalizer and button
275 unsigned char boxtype; // (L)ine, t(X)tbox, Picture - (G)
276 short cap_len; /* 캡션의 길이 */
278 void *cell;
280 FBoxStyle()
281 : anchor_type(0)
282 , txtflow(0)
283 , xpos(0)
284 , ypos(0)
285 , boxnum(0)
286 , boxtype(0)
287 , cap_len(0)
288 , cell(NULL)
290 memset(margin, 0, sizeof(margin));
295 * This object is for floating object like table, image, line and so on.
297 * @short floating object
299 struct FBox: public HBox
301 int zorder;
302 short option; // draw frame
303 hchar ctrl_ch;
304 FBoxStyle style;
306 short box_xs, box_ys;
307 short cap_xs, cap_ys ;
308 short xs, ys; // ys = fig_ys + cap_ys + margin
309 // xs = fig_xs + cap_xs + margin
310 short cap_margin;
311 char xpos_type, ypos_type;
312 unsigned char smart_linesp;
314 /* 이 자료는 tbox나 pic에서는 파일에 기록하지 않고 실행시만 있으며,
315 line에서는 파일에 기록한다.
317 short boundsy, boundey;
318 unsigned char boundx, draw;
321 * Physical x,y position.
323 short pgx, pgy; // physical xpos, ypos
324 short pgno, showpg; // pageno where code is
326 FBox *prev, *next;
328 FBox( hchar hch );
329 virtual ~FBox();
332 struct Table;
334 * The TxtBox class saves object properties about table, textbox, equalizer or button
336 struct TxtBox: public FBox
338 hchar reserved[2];
339 hchar dummy;
341 short dummy1; // to not change structure size */
342 short cap_len;
343 short next;
344 short dummy2; // to not change structure size */
345 unsigned char reserved1;
347 * caption position
349 short cap_pos; // caption pos
350 short num; // numbering
352 short dummy3;
353 short baseline; //(for equ)
356 * The value of type indicates as the below: zero is table, one is
357 * textbox, two is equalizer and three is button.
359 short type; // 0-table, 1-textbox, 2-수식, 3-button
361 * nCell is greater than one only for table, otherwise it is 1.
363 short nCell; //:=1 offset 80
365 * If value of protect is 1, size of cell cann't change.
367 short protect; //1=size lock
369 Cell *cell;
370 Table *m_pTable;
372 * Paragraph list
374 std::list<HWPPara*> *plists;
376 * Caption
378 std::list<HWPPara*> caption;
380 TxtBox();
381 virtual ~TxtBox();
384 * @returns Count of cell.
386 int NCell() { return nCell; }
388 * This is one of table, text-box, equalizer and button
389 * @returns Type of this object.
391 int Type() { return type; }
393 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
395 virtual hunit Height(CharShape *csty) SAL_OVERRIDE;
398 #define ALLOWED_GAP 5
399 #define INIT_SIZE 20
400 #define ADD_AMOUNT 10
402 struct Columns
404 int *data;
405 size_t nCount;
406 size_t nTotal;
407 Columns(){
408 nCount = 0;
409 nTotal = INIT_SIZE;
410 data = new int[nTotal];
412 ~Columns(){ delete[] data; }
414 void AddColumnsSize(){
415 int *tmp = data;
416 if (nTotal + ADD_AMOUNT < nTotal) // overflow
418 throw ::std::bad_alloc();
420 data = new int[nTotal + ADD_AMOUNT];
421 for (size_t i = 0 ; i < nTotal ; i++)
422 data[i] = tmp[i];
423 nTotal += ADD_AMOUNT;
424 delete[] tmp;
427 void insert(int pos){
428 if( nCount == 0 ){
429 data[nCount++] = pos;
430 return;
432 for (size_t i = 0 ; i < nCount; i++ ) {
433 if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
434 return; // Already exist;
435 if( pos < data[i] ){
436 if( nCount == nTotal )
437 AddColumnsSize();
438 for (size_t j = nCount ; j > i ; j--)
439 data[j] = data[j-1];
440 data[i] = pos;
441 nCount++;
442 return;
445 // last position.
446 if( nCount == nTotal )
447 AddColumnsSize();
448 data[nCount++] = pos;
451 int getIndex(int pos)
453 if( pos == 0 )
454 return 0;
455 for (size_t i = 0 ; i < nCount; i++) {
456 if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
457 return i;
459 return -1;
463 struct Rows
465 int *data;
466 size_t nCount;
467 size_t nTotal;
468 Rows(){
469 nCount = 0;
470 nTotal = INIT_SIZE;
471 data = new int[nTotal];
473 ~Rows(){ delete[] data; }
475 void AddRowsSize(){
476 int *tmp = data;
477 if (nTotal + ADD_AMOUNT < nTotal) // overflow
479 throw ::std::bad_alloc();
481 data = new int[nTotal + ADD_AMOUNT];
482 for (size_t i = 0 ; i < nTotal ; i++)
483 data[i] = tmp[i];
484 nTotal += ADD_AMOUNT;
485 delete[] tmp;
488 void insert(int pos){
489 if( nCount == 0 ){
490 data[nCount++] = pos;
491 return;
493 for (size_t i = 0 ; i < nCount; i++) {
494 if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
495 return; // Already exist;
496 if( pos < data[i] ){
497 if( nCount == nTotal )
498 AddRowsSize();
499 for (size_t j = nCount ; j > i ; j--)
500 data[j] = data[j-1];
501 data[i] = pos;
502 nCount++;
503 return;
506 // last position.
507 if( nCount == nTotal )
508 AddRowsSize();
509 data[nCount++] = pos;
512 int getIndex(int pos)
514 if( pos == 0 )
515 return 0;
516 for (size_t i = 0 ; i < nCount; i++) {
517 if( pos < data[i] + ALLOWED_GAP && pos > data[i] - ALLOWED_GAP )
518 return i;
520 return -1;
524 struct TCell
526 int nColumnIndex;
527 int nRowIndex;
528 int nColumnSpan;
529 int nRowSpan;
530 Cell *pCell;
533 struct Table
535 Table() : box(NULL) {};
536 ~Table() {
537 std::list<TCell*>::iterator it = cells.begin();
538 for( ; it != cells.end(); ++it)
539 delete *it;
542 Columns columns;
543 Rows rows;
544 std::list<TCell*> cells;
545 TxtBox *box;
548 /* picture (11) 그림, OLE그림, 삽입그림, 그리기 */
549 enum pictype
551 PICTYPE_FILE, PICTYPE_OLE, PICTYPE_EMBED,
552 PICTYPE_DRAW, PICTYPE_UNKNOWN
555 * @short External image file
557 struct PicDefFile
559 char path[256];
560 void *img;
561 bool skipfind;
565 * @short Embedded image file
567 struct PicDefEmbed
569 char embname[16];
573 * @short Win32 ole object
575 struct PicDefOle
577 char embname[16];
578 void *hwpole;
582 * @short Drawing object of hwp
584 struct PicDefDraw
586 void *hdo;
587 uint zorder;
588 ZZRect vrect;
589 int mbrcnt;
593 * @short For using common case
595 struct PicDefUnknown
597 char path[256];
600 typedef union
602 PicDefFile picfile;
603 PicDefEmbed picembed;
604 PicDefOle picole;
605 PicDefDraw picdraw;
606 PicDefUnknown picun;
607 } PicDef;
610 * There are four kinds of image.
611 * @li External image
612 * @li Embedded image
613 * @li Win32 ole object
614 * @li Drawing object of hwp
616 * @short Image object
618 struct Picture: public FBox
620 hchar reserved[2];
621 hchar dummy;
623 * follow_block_size is the size information of the Drawing object of hwp.
624 * It's value is greater than 0 if the pictype is PICTYPE_DRAW.
626 uint follow_block_size; /* 추가정보 길이. */
627 short dummy1; // to not change structure size */
628 short dummy2; // to not change structure size */
629 uchar reserved1;
631 * Position of caption
633 short cap_pos; // caption pos
635 * Index of current Picture object
637 short num; // numbering
640 * Type of this object
641 * It is one of external/ole/embedded/drawing picture
643 uchar pictype;
644 hunit skip[2];
646 * Ratio of magnification or reduction.
648 hunit scale[2];
649 PicDef picinfo;
650 char reserved3[9];
652 std::list<HWPPara*> caption;
654 * It's for the Drawing object
656 unsigned char *follow; /* 그림종류가 drawing일때, 추가정보. */
658 bool ishyper;
660 Picture();
661 virtual ~Picture();
663 int Type ();
664 virtual bool Read (HWPFile &hwpf) SAL_OVERRIDE;
666 virtual hunit Height (CharShape *sty) SAL_OVERRIDE;
669 // line (14)
671 * @short Line
673 struct Line: public FBox
675 hchar reserved[2];
676 hchar dummy;
678 char reserved2[8];
680 short sx, sy, ex, ey;
681 short width, shade, color;
683 Line();
685 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
688 // hidden(15)
690 * @short Hidden section
692 struct Hidden: public HBox
694 hchar reserved[2];
695 hchar dummy;
697 unsigned char info[8]; // h, next, dummy
698 std::list<HWPPara*> plist;
700 Hidden();
701 virtual ~Hidden();
703 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
707 * @short Header or footer
709 struct HeaderFooter: public HBox
711 hchar reserved[2];
712 hchar dummy;
714 unsigned char info[8];
716 * Header or footer
718 unsigned char type;
719 unsigned char where;
720 unsigned char linenumber;
722 unsigned int m_nPageNumber;
725 * Paragraph list of header or footer
727 std::list<HWPPara*> plist;
729 HeaderFooter();
730 virtual ~HeaderFooter();
732 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
736 * 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.
737 * @short Footnote or endnote
739 struct Footnote: public HBox
741 hchar reserved[2];
742 hchar dummy;
744 unsigned char info[8];
746 * The number of current footnote/endnote
748 unsigned short number;
750 * Set the type of Footnote either footnote or endnote.
752 unsigned short type;
754 * The width of the Footnote object.
756 hunit width;
758 * Paragraph list of Footnote objects
760 std::list<HWPPara*> plist;
762 Footnote();
763 virtual ~Footnote();
765 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
768 // auto number(18)
770 * Kind of auto input number
772 enum
774 PGNUM_AUTO,
775 FNNUM_AUTO,
776 ENNUM_AUTO,
777 PICNUM_AUTO,
778 TBLNUM_AUTO,
779 EQUNUM_AUTO
783 * @short Input current index of page,comment,table and picture.
785 struct AutoNum: public HBox
787 unsigned short type;
788 unsigned short number;
789 hchar dummy;
791 AutoNum();
793 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
797 * @short Input new number as current index of page,comment,table and picture.
799 struct NewNum: public HBox
801 unsigned short type;
802 unsigned short number;
803 hchar dummy;
805 NewNum();
807 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
810 // page numger(20)
812 * @short Input page index in footer or header
814 struct ShowPageNum: public HBox
817 * Location of page number to be inserted.
819 unsigned short where;
820 unsigned int m_nPageNumber;
822 * Shape of page number to be inserted.
824 unsigned short shape;
825 hchar dummy;
827 ShowPageNum();
829 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
832 /* 홀수쪽시작 (21) */
834 * Controls the display of page number, header, footer and border.
836 struct PageNumCtrl: public HBox
839 * object type
841 unsigned short kind;
843 * control command.
845 unsigned short what;
846 hchar dummy;
848 PageNumCtrl();
850 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
853 // mail merge(22)
855 * Generates the mailing list automatically using address book and mail body format.
856 * @short Generates mailing list
858 struct MailMerge: public HBox
860 unsigned char field_name[20];
861 hchar dummy;
863 MailMerge();
865 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
866 virtual hchar_string GetString() SAL_OVERRIDE;
869 // char compositon(23)
871 * The compose struct displays characters at position. The maximum character count for composition is three.
872 * @short Composition several characters
874 struct Compose: public HBox
876 hchar compose[3];
877 hchar dummy;
879 Compose();
881 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
884 // hyphen(24)
886 * @short Hyphen
888 struct Hyphen: public HBox
891 * Width of hyphen
893 hchar width;
894 hchar dummy;
896 Hyphen();
898 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
901 // toc mark(25)
903 * The TocMark class is for making the content of a table.
904 * When you set TocMark on current position, hwp makes it as toc automatically.
905 * @short Table of contents
907 struct TocMark: public HBox
909 hchar kind;
910 hchar dummy;
912 TocMark();
914 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
917 // index mark(26)
919 * IndexMark marks the table of search.
920 * If you set IndexMark at current position, hwp make it as search index.
921 * @short Table of search
923 struct IndexMark: public HBox
925 hchar keyword1[60];
926 hchar keyword2[60];
927 unsigned short pgno;
928 hchar dummy;
930 IndexMark();
932 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
935 // outline(28)
936 #define MAX_OUTLINE_LEVEL 7
938 enum
940 OLSTY_USER = 0,
941 OLSTY_NUMS1 = 1,
942 OLSTY_NUMS2 = 2,
943 OLSTY_NUMSIG1 = 3,
944 OLSTY_NUMSIG2 = 4,
945 OLSTY_NUMSIG3 = 5,
946 OLSTY_BULUSER = 128,
947 OLSTY_BULLET1 = 129,
948 OLSTY_BULLET2 = 130,
949 OLSTY_BULLET3 = 131,
950 OLSTY_BULLET4 = 132,
951 OLSTY_BULLET5 = 133
954 // value is in style->userchar[level];
955 enum
957 UDO_NUM,
958 UDO_UROM,
959 UDO_LROM,
960 UDO_UENG,
961 UDO_LENG,
962 UDO_SYLL,
963 UDO_JAMO,
964 UDO_HANJA,
965 UDO_SP_CNUM,
966 UDO_SP_CLENG,
967 UDO_SP_CSYLL,
968 UDO_SP_CJAMO,
969 N_UDO
972 * Number and format of title.
973 * @short Number and format of title
975 class Outline: public HBox
977 public:
979 * kind of numbering format
981 unsigned short kind;
982 unsigned char shape;
984 * level of number, Ex) The level of 1.3.2.4 is four
986 unsigned char level;
988 * value of level
990 unsigned short number[MAX_OUTLINE_LEVEL];
992 * shape of level
994 hchar user_shape[MAX_OUTLINE_LEVEL];
996 * decoration character for the level type
998 hchar deco[MAX_OUTLINE_LEVEL][2]; /* 사용자 정의시 앞뒤 문자 */
999 hchar dummy;
1001 Outline();
1003 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
1004 hchar_string GetUnicode() const;
1007 /* 묶음 빈칸(30) */
1009 * The Special space to be treated non-space when a string is
1010 * cut at the end of line
1011 * @short Special space
1013 struct KeepSpace: public HBox
1015 hchar dummy;
1017 KeepSpace();
1019 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
1022 /* 고정폭 빈칸(31) */
1024 * @short Space with always same width not relation with fonts.
1026 struct FixedSpace: public HBox
1028 hchar dummy;
1030 FixedSpace();
1032 virtual bool Read(HWPFile &hwpf) SAL_OVERRIDE;
1034 #endif // INCLUDED_HWPFILTER_SOURCE_HBOX_H
1036 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */