1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hbox.cpp,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompile.h"
43 int HBox::boxCount
= 0;
60 static int wsize
[32] =
62 1, 4, 4, 4, 4, 4, 4, 42, /* dateform */
63 48, 4, 4, 4, 4, 1, 4, 4, /* hidden */
64 4, 4, 4, 4, 4, 4, 12, 5, /* chcompose */
65 3, 3, 123, 4, 32, 4, 2, 2
75 int HBox::GetString(hchar
* hstr
, int )
83 hunit
HBox::Height(CharShape
*csty
)
90 SkipBlock::SkipBlock(hchar hch
):HBox(hch
)
96 SkipBlock::~SkipBlock(void)
103 FieldCode::FieldCode(void) : HBox(CH_FIELD
)
109 reserved1
= new char[4];
110 reserved2
= new char[22];
115 FieldCode::~FieldCode(void)
129 Bookmark::Bookmark(void):HBox(CH_BOOKMARK
)
134 Bookmark::~Bookmark(void)
140 DateFormat::DateFormat(void):HBox(CH_DATE_FORM
)
147 DateCode::DateCode(void):HBox(CH_DATE_CODE
)
152 #define _DATECODE_WEEK_DEFINES_
153 #include "datecode.h"
155 int DateCode::GetString(hchar
* hstr
, int slen
)
161 bool is_pm
, add_zero
;
164 format
[DATE_SIZE
- 1] = 0;
165 fmt
= format
[0] ? format
: defaultform
;
168 for (; *fmt
&& ((int) (d
- hstr
) < DATE_SIZE
) && slen
> 1; fmt
++)
170 form
= (add_zero
) ? "%02d" : "%d";
173 is_pm
= (date
[HOUR
] >= 12);
187 num
= date
[YEAR
] % 100;
193 memcpy(cbuf
, eng_mon
+ (date
[MONTH
] - 1) * 3, 3);
198 strcpy(cbuf
, en_mon
[date
[MONTH
] - 1]);
200 case '3': /* 'D' is day of korean */
205 switch (date
[DAY
] % 10)
222 num
= date
[HOUR
] - ((date
[HOUR
] > 12) ? 12 : 0);
232 *d
++ = kor_week
[date
[WEEK
]];
236 memcpy(cbuf
, eng_week
+ date
[WEEK
] * 3, 3);
241 strcpy(cbuf
, en_week
[date
[WEEK
]]);
247 *d
++ = (is_pm
) ? 0xD281 : 0xB8E5;
251 strcpy(cbuf
, (is_pm
) ? "p.m." : "a.m.");
254 strcpy(cbuf
, (is_pm
) ? "P.M." : "A.M.");
256 case '8': // 2.5 feature
260 mkcurfilename(cbuf
, *fmt
);
261 for (i
= 0; cbuf
[i
] != 0 && slen
> 1; i
++)
262 { //for hangle filename
263 if (cbuf
[i
] & 0x80 && cbuf
[i
+ 1] != 0)
265 *d
++ = (cbuf
[i
] << 8) | cbuf
[i
+ 1];
275 case '~': // 3.0b feature
281 *d
++ = china_week
[date
[WEEK
]];
287 if (*fmt
== '\\' && *++fmt
== 0)
293 sprintf(cbuf
, form
, num
);
294 for (i
= 0; 0 != cbuf
[i
] && slen
> 1; i
++)
302 return hstrlen(hstr
);
308 Tab::Tab(void):HBox(CH_TAB
)
314 FBox::FBox(hchar hch
):HBox(hch
)
326 // tbox(10) TABLE BOX MATH BUTTON HYPERTEXT
328 TxtBox::TxtBox(void):FBox(CH_TEXT_BOX
), cell(0), plists(0)
333 TxtBox::~TxtBox(void)
337 for (int ii
= 0; ii
< nCell
; ++ii
)
339 LinkedListIterator
< HWPPara
> it(&plists
[ii
]);
340 for (; it
.current(); it
++)
344 LinkedListIterator
< HWPPara
> it(&caption
);
345 for (; it
.current(); it
++)
352 hunit
TxtBox::Height(CharShape
* csty
)
354 return (style
.anchor_type
== CHAR_ANCHOR
) ? box_ys
: csty
->size
;
360 Picture::Picture(void):FBox(CH_PICTURE
)
367 Picture::~Picture(void)
370 if( pictype
== PICTYPE_DRAW
&& picinfo
.picdraw
.hdo
)
371 delete (HWPDrawingObject
*) picinfo
.picdraw
.hdo
;
373 LinkedListIterator
< HWPPara
> it(&caption
);
374 for (; it
.current(); it
++)
385 hunit
Picture::Height(CharShape
* sty
)
387 return (style
.anchor_type
== CHAR_ANCHOR
) ? box_ys
: sty
->size
;
393 Hidden::~Hidden(void)
395 LinkedListIterator
< HWPPara
> it(&plist
);
396 for (; it
.current(); it
++)
402 HeaderFooter::~HeaderFooter(void)
404 LinkedListIterator
< HWPPara
> it(&plist
);
405 for (; it
.current(); it
++)
411 Footnote::~Footnote(void)
413 LinkedListIterator
< HWPPara
> it(&plist
);
414 for (; it
.current(); it
++)
421 // show page number (20)
422 // Ȧ¼öÂʽÃÀÛ/°¨Ãß±â (21)
425 int MailMerge::GetString(hchar
* hstr
, int )
432 // character compositon(23)
438 #define OL_HANGL_JASO 0
439 #define OL_HANGL_KANATA 1
441 static hchar
olHanglJaso(int num
, int type
)
443 static unsigned char han_init
[] =
444 { "\x88\x90\x94\x9c\xa0\xa4\xac\xb4\xb8\xc0\xc4\xc8\xcc\xd0" };
445 static unsigned char jung
[] = { 3, 5, 7, 11, 13, 19, 20, 26, 27, 29, 30 };
446 static unsigned char jung2
[] = { 3, 7, 13, 20, 27, 29, 30 };
451 if (type
== OL_HANGL_JASO
)
453 num
= num
% (14 + (sizeof(jung
) / sizeof(char)));
456 hh
= (han_init
[num
] << 8) | 'A';
458 hh
= (jung
[num
- 14] << 5) | 0x8401;
463 hh
= (han_init
[num
] << 8) | 'a';
466 j
= (num
/ 14) % (sizeof(jung2
) / sizeof(char));
469 hh
= (han_init
[num
] << 8) | (jung2
[j
] << 5) | 1;
476 static hchar
*GetOutlineStyleChars(int style
)
478 static hchar out_bul_style_entry
[5][8] = // extern
481 0x2f18, 0x2f12, 0x2f08, 0x2f02, 0x2f06, 0x2f00, 0x2043, 0x0000
484 0x2f18, 0x2f12, 0x2f06, 0x2f00, 0x2f36, 0x2f30, 0x2043, 0x0000
487 0x2f26, 0x2f20, 0x2f06, 0x2f00, 0x2f16, 0x2f10, 0x2043, 0x0000
490 0x2f18, 0x2f16, 0x2f12, 0x2f10, 0x2f06, 0x2f00, 0x2043, 0x0000
493 0xAC61, 0xB677, 0xB861, 0xB8F7, 0xB781, 0x0000
496 if (style
>= OLSTY_BULLET1
&& style
<= OLSTY_BULLET5
)
497 return out_bul_style_entry
[style
- OLSTY_BULLET1
];
502 static void getOutlineNumStr(int style
, int level
, int num
, hchar
* hstr
)
506 U_ROM
= 0x01, L_ROM
= 0x02, U_ENG
= 0x04, L_ENG
= 0x08,
507 HAN
= 0x10, NUM
= 0x20, L_BR
= 0x40, R_BR
= 0x80
509 static unsigned char type_tbl
[][MAX_OUTLINE_LEVEL
] =
512 U_ROM
, HAN
, NUM
, HAN
| R_BR
, L_BR
| NUM
| R_BR
,
513 L_BR
| HAN
| R_BR
, L_ROM
| R_BR
516 U_ROM
, U_ENG
, NUM
, L_ENG
| R_BR
, L_BR
| NUM
| R_BR
,
517 L_BR
| L_ENG
| R_BR
, L_ROM
| R_BR
520 NUM
, HAN
, L_BR
| NUM
| R_BR
, L_BR
| HAN
| R_BR
, NUM
|
521 R_BR
, HAN
| R_BR
, L_ENG
524 char fmt
= type_tbl
[style
- OLSTY_NUMSIG1
][level
];
533 sprintf(buf
, "%d", num
);
537 else if (fmt
& (U_ROM
| L_ROM
))
545 *ptr
= sal::static_int_cast
<char>(toupper(*ptr
));
554 num
= (num
- 1) % 26;
556 *hstr
++ = sal::static_int_cast
<hchar
>('A' + num
);
557 else if (fmt
& L_ENG
)
558 *hstr
++ = sal::static_int_cast
<hchar
>('a' + num
);
560 *hstr
++ = olHanglJaso(num
, OL_HANGL_KANATA
);
562 *hstr
++ = (fmt
& R_BR
) ? ')' : '.';
568 { OUTLINE_ON
, OUTLINE_NUM
};
570 /* level Àº 0ºÎÅÍ ½ÃÀÛ. Áï 1.1.1. ÀÇ ·¹º§Àº 2ÀÌ´Ù.
571 number´Â °ªÀÌ ±×´ë·Î µé¾î°¡ ÀÖ´Ù. Áï, 1.2.1¿¡´Â 1,2,1ÀÌ µé¾î°¡ ÀÖ´Ù.
572 style Àº 1ºÎÅÍ °ªÀÌ µé¾î°¡ ÀÖ´Ù. hbox.h¿¡ Á¤ÀÇµÈ µ¥·Î..
574 hchar
*Outline::GetUnicode(hchar
* hstr
, int)
581 if (kind
== OUTLINE_NUM
)
588 char cur_num_str
[10], buf
[80];
592 for (i
= 0; i
<= level
; i
++)
594 levelnum
= ((number
[i
] < 1) ? 1 : number
[i
]);
595 if (shape
== OLSTY_NUMS2
&& i
&& i
== level
)
596 sprintf(cur_num_str
, "%d%c", levelnum
, 0);
598 sprintf(cur_num_str
, "%d%c", levelnum
, '.');
599 strcat(buf
, cur_num_str
);
601 str2hstr(buf
, buffer
);
602 return hstr2ucsstr(buffer
, hstr
);
608 getOutlineNumStr(shape
, level
, number
[level
], buffer
);
609 return hstr2ucsstr(buffer
, hstr
);
617 p
= GetOutlineStyleChars(shape
);
618 buffer
[0] = p
[level
];
620 return hstr2ucsstr(buffer
, hstr
);
629 buffer
[l
++] = deco
[i
][0];
631 /* level Àº 0ºÎÅÍ ½ÃÀÛ. Áï 1.1.1. ÀÇ ·¹º§Àº 2ÀÌ´Ù.
632 number´Â °ªÀÌ ±×´ë·Î µé¾î°¡ ÀÖ´Ù. Áï, 1.2.1¿¡´Â 1,2,1ÀÌ µé¾î°¡ ÀÖ´Ù.
633 style Àº 1ºÎÅÍ °ªÀÌ µé¾î°¡ ÀÖ´Ù. hbox.h¿¡ Á¤ÀÇµÈ µ¥·Î..
635 switch( user_shape
[i
] )
638 buffer
[l
++] = '1' + number
[i
] - 1;
640 case 1: /* ´ë¹®Àڷθ¶ */
641 case 2: /* ¼Ò¹®Àڷθ¶ */
642 num2roman(number
[i
], dest
);
643 if( user_shape
[i
] == 1 ){
647 *ptr
= sal::static_int_cast
<char>(toupper(*ptr
));
651 str2hstr(dest
, buffer
+ l
);
655 buffer
[l
++] = 'A' + number
[i
] -1;
658 buffer
[l
++] = 'a' + number
[i
] -1;
661 buffer
[l
++] = olHanglJaso(number
[i
] -1, OL_HANGL_KANATA
);
664 buffer
[l
++] = olHanglJaso(number
[i
] -1, OL_HANGL_JASO
);
666 case 7: /* ÇÑÀÚ ¼ýÀÚ : ÀÏ¹Ý ¼ýÀڷΠǥÇö */
667 buffer
[l
++] = '1' + number
[i
] -1;
670 buffer
[l
++] = 0x2e00 + number
[i
];
672 case 9: /* ¿ø ¾ËÆĺª ¼Ò¹®ÀÚ */
673 buffer
[l
++] = 0x2c20 + number
[i
];
675 case 10: /* ¿ø °¡³ª´Ù */
676 buffer
[l
++] = 0x2c50 + number
[i
] -1;
678 case 11: /* ¿ø ¤¡ ¤¤ */
679 buffer
[l
++] = 0x2c40 + number
[i
] -1;
681 case 12: /* À̾îÁø ¼ýÀÚ. */
683 char cur_num_str
[10],buf
[80];
686 for (j
= 0; j
<= level
; j
++)
688 levelnum
= ((number
[j
] < 1) ? 1 : number
[j
]);
689 if ((j
&& j
== level
) || (j
== level
&& deco
[i
][1]))
690 sprintf(cur_num_str
, "%d%c", levelnum
, 0);
692 sprintf(cur_num_str
, "%d%c", levelnum
, '.');
693 strcat(buf
, cur_num_str
);
695 str2hstr(buf
, buffer
+ l
);
700 buffer
[l
++] = user_shape
[i
];
704 buffer
[l
++] = deco
[i
][1];
707 return hstr2ucsstr(buffer
, hstr
);
711 return hstr2ucsstr(buffer
, hstr
);
716 /* °íÁ¤Æø ºóÄ(31) */