bump product version to 4.1.6.2
[LibreOffice.git] / hwpfilter / source / hbox.cxx
blob033df90642b58ec6f41123d54782674c1cae006d
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 #include "precompile.h"
22 #include <ctype.h>
24 #include <osl/diagnose.h>
26 #include "hwpfile.h"
27 #include "hbox.h"
28 #include "hpara.h"
29 #include "hutil.h"
30 #include "htags.h"
31 #include "drawdef.h"
32 #include "hcode.h"
34 int HBox::boxCount = 0;
36 HBox::HBox(hchar hch)
38 hh = hch;
39 boxCount++;
43 HBox::~HBox()
45 boxCount--;
49 int HBox::WSize(void)
51 static const int wsize[32] =
53 1, 4, 4, 4, 4, 4, 4, 42, /* dateform */
54 48, 4, 4, 4, 4, 1, 4, 4, /* hidden */
55 4, 4, 4, 4, 4, 4, 12, 5, /* chcompose */
56 3, 3, 123, 4, 32, 4, 2, 2
59 if (hh < 32)
60 return wsize[hh];
61 else
62 return 1;
66 hchar_string HBox::GetString()
68 hchar_string ret;
69 ret.push_back(hh);
70 return ret;
74 hunit HBox::Height(CharShape *csty)
76 return( csty->size );
80 // skip block
81 SkipData::SkipData(hchar hch):HBox(hch)
83 data_block = 0;
87 SkipData::~SkipData(void)
89 delete[]data_block;
93 // FieldCode [5]
94 FieldCode::FieldCode(void) : HBox(CH_FIELD)
96 str1 = 0;
97 str2 = 0;
98 str3 = 0;
99 bin = 0;
100 reserved1 = new char[4];
101 reserved2 = new char[22];
102 m_pDate = 0L;
106 FieldCode::~FieldCode(void)
108 delete[] str1;
109 delete[] str2;
110 delete[] str3;
111 delete[] bin;
112 delete[] reserved1;
113 delete[] reserved2;
114 if( m_pDate )
115 delete m_pDate;
119 // book mark(6)
120 Bookmark::Bookmark(void):HBox(CH_BOOKMARK)
125 Bookmark::~Bookmark(void)
130 // date format(7)
131 DateFormat::DateFormat(void):HBox(CH_DATE_FORM)
136 // date code(8)
138 DateCode::DateCode(void):HBox(CH_DATE_CODE)
143 #define _DATECODE_WEEK_DEFINES_
144 #include "datecode.h"
146 hchar_string DateCode::GetString()
148 hchar_string ret;
149 const hchar *fmt;
150 int i, num;
151 const char *form;
152 char cbuf[256];
153 bool is_pm, add_zero;
155 add_zero = false;
156 format[DATE_SIZE - 1] = 0;
157 fmt = format[0] ? format : defaultform;
159 for (; *fmt && ((int) ret.size() < DATE_SIZE); fmt++)
161 form = (add_zero) ? "%02d" : "%d";
163 add_zero = false;
164 is_pm = (date[HOUR] >= 12);
165 *cbuf = 0;
166 num = -1;
168 switch (*fmt)
170 case '0':
171 add_zero = true;
172 break;
173 case '1':
174 num = date[YEAR];
175 form = "%04d";
176 break;
177 case '!':
178 num = date[YEAR] % 100;
179 break;
180 case '2':
181 num = date[MONTH];
182 break;
183 case '@':
184 memcpy(cbuf, eng_mon + (date[MONTH] - 1) * 3, 3);
185 cbuf[3] = '.';
186 cbuf[4] = 0;
187 break;
188 case '*':
189 strcpy(cbuf, en_mon[date[MONTH] - 1]);
190 break;
191 case '3': /* 'D' is day of korean */
192 num = date[DAY];
193 break;
194 case '#':
195 num = date[DAY];
196 switch (date[DAY] % 10)
198 case 1:
199 form = "%dst";
200 break;
201 case 2:
202 form = "%dnd";
203 break;
204 case 3:
205 form = "%drd";
206 break;
207 default:
208 form = "%dth";
209 break;
211 break;
212 case '4':
213 num = date[HOUR] - ((date[HOUR] > 12) ? 12 : 0);
214 break;
215 case '$':
216 num = date[HOUR];
217 break;
218 case '5':
219 case '%':
220 num = date[MIN];
221 break;
222 case '6':
223 ret.push_back(kor_week[date[WEEK]]);
224 break;
225 case '^':
226 memcpy(cbuf, eng_week + date[WEEK] * 3, 3);
227 cbuf[3] = '.';
228 cbuf[4] = 0;
229 break;
230 case '_':
231 strcpy(cbuf, en_week[date[WEEK]]);
232 break;
233 case '7':
234 ret.push_back(0xB5A1);
235 ret.push_back((is_pm) ? 0xD281 : 0xB8E5);
236 break;
237 case '&':
238 strcpy(cbuf, (is_pm) ? "p.m." : "a.m.");
239 break;
240 case '+':
241 strcpy(cbuf, (is_pm) ? "P.M." : "A.M.");
242 break;
243 case '8': // 2.5 feature
244 case '9':
245 #if 0
246 // LATER
247 mkcurfilename(cbuf, *fmt);
248 for (i = 0; cbuf[i] != 0 && slen > 1; i++)
249 { //for hangle filename
250 if (cbuf[i] & 0x80 && cbuf[i + 1] != 0)
252 *d++ = (cbuf[i] << 8) | cbuf[i + 1];
253 i++;
255 else
256 *d++ = cbuf[i];
257 slen--;
259 #endif
260 cbuf[0] = 0;
261 break;
262 case '~': // 3.0b feature
263 if (fmt[1] == 0)
264 break;
265 fmt++;
266 if (*fmt == '6')
268 ret.push_back(china_week[date[WEEK]]);
269 break;
271 break;
272 default:
273 if (*fmt == '\\' && *++fmt == 0)
274 goto done;
275 ret.push_back(*fmt);
277 if (num != -1)
278 sprintf(cbuf, form, num);
279 for (i = 0; 0 != cbuf[i]; i++)
281 ret.push_back(*(cbuf + i));
284 done:
285 return ret;
289 // tab(9)
291 Tab::Tab(void):HBox(CH_TAB)
296 // floating box
297 FBox::FBox(hchar hch):HBox(hch)
299 prev = next = 0;
300 zorder = 0;
304 FBox::~FBox()
309 // tbox(10) TABLE BOX MATH BUTTON HYPERTEXT
311 TxtBox::TxtBox(void):FBox(CH_TEXT_BOX), cell(0), plists(0)
316 TxtBox::~TxtBox(void)
318 delete[]cell;
320 for (int ii = 0; ii < nCell; ++ii)
322 std::list < HWPPara* >::iterator it = plists[ii].begin();
323 for (; it != plists[ii].end(); ++it)
325 HWPPara* pPara = *it;
326 delete pPara;
330 std::list < HWPPara* >::iterator it = caption.begin();
331 for (; it != caption.end(); ++it)
333 HWPPara* pPara = *it;
334 delete pPara;
337 delete[]plists;
341 hunit TxtBox::Height(CharShape * csty)
343 return (style.anchor_type == CHAR_ANCHOR) ? box_ys : csty->size;
347 // picture(11)
349 Picture::Picture(void):FBox(CH_PICTURE)
351 follow = 0;
352 ishyper = false;
356 Picture::~Picture(void)
358 delete[]follow;
359 if( pictype == PICTYPE_DRAW && picinfo.picdraw.hdo )
360 delete (HWPDrawingObject *) picinfo.picdraw.hdo;
362 std::list < HWPPara* >::iterator it = caption.begin();
363 for (; it != caption.end(); ++it)
365 HWPPara* pPara = *it;
366 delete pPara;
371 int Picture::Type()
373 return pictype;
377 hunit Picture::Height(CharShape * sty)
379 return (style.anchor_type == CHAR_ANCHOR) ? box_ys : sty->size;
383 // line(14)
384 // hidden(15)
385 Hidden::~Hidden(void)
387 std::list < HWPPara* >::iterator it = plist.begin();
388 for (; it != plist.end(); ++it)
390 HWPPara* pPara = *it;
391 delete pPara;
396 // header/footer(16)
397 HeaderFooter::~HeaderFooter(void)
399 std::list < HWPPara* >::iterator it = plist.begin();
400 for (; it != plist.end(); ++it)
402 HWPPara* pPara = *it;
403 delete pPara;
408 // footnote(17)
409 Footnote::~Footnote(void)
411 std::list < HWPPara* >::iterator it = plist.begin();
412 for (; it != plist.end(); ++it)
414 HWPPara* pPara = *it;
415 delete pPara;
420 // auto number(18)
421 // new number(19)
422 // show page number (20)
423 // Ȧ¼öÂʽÃÀÛ/°¨Ãß±â (21)
425 // mail merge(22)
426 hchar_string MailMerge::GetString()
428 return hchar_string();
432 // character compositon(23)
433 // hyphen(24)
434 // toc mark(25)
435 // index mark(26)
436 // outline(28)
438 #define OL_HANGL_JASO 0
439 #define OL_HANGL_KANATA 1
441 static hchar olHanglJaso(int num, int type)
443 static const unsigned char han_init[] =
444 { 0x88, 0x90, 0x94, 0x9c, 0xa0, 0xa4, 0xac, 0xb4, 0xb8, 0xc0, 0xc4, 0xc8, 0xcc, 0xd0 };
445 static const unsigned char jung[] = { 3, 5, 7, 11, 13, 19, 20, 26, 27, 29, 30 };
446 static const unsigned char jung2[] = { 3, 7, 13, 20, 27, 29, 30 };
448 hchar hh = 0;
450 if (type == OL_HANGL_JASO)
452 num = num % (14 + (sizeof(jung) / sizeof(char)));
454 if (num < 14)
455 hh = (han_init[num] << 8) | 'A';
456 else
457 hh = (jung[num - 14] << 5) | 0x8401;
459 else
461 if (num < 14)
462 hh = (han_init[num] << 8) | 'a';
463 else
465 int j = (num / 14) % (sizeof(jung2) / sizeof(char));
467 num = num % 14;
468 hh = (han_init[num] << 8) | (jung2[j] << 5) | 1;
471 return hh;
475 static const hchar *GetOutlineStyleChars(int style)
477 static const hchar out_bul_style_entry[5][8] = // extern
479 { // 0 OLSTY_BULLET1
480 0x2f18, 0x2f12, 0x2f08, 0x2f02, 0x2f06, 0x2f00, 0x2043, 0x0000
482 { // 1
483 0x2f18, 0x2f12, 0x2f06, 0x2f00, 0x2f36, 0x2f30, 0x2043, 0x0000
485 { // 2
486 0x2f26, 0x2f20, 0x2f06, 0x2f00, 0x2f16, 0x2f10, 0x2043, 0x0000
488 { // 3
489 0x2f18, 0x2f16, 0x2f12, 0x2f10, 0x2f06, 0x2f00, 0x2043, 0x0000
491 { //
492 0xAC61, 0xB677, 0xB861, 0xB8F7, 0xB781, 0x0000
495 if (style >= OLSTY_BULLET1 && style <= OLSTY_BULLET5)
496 return out_bul_style_entry[style - OLSTY_BULLET1];
497 return NULL;
501 static void getOutlineNumStr(int style, int level, int num, hchar * hstr)
503 enum
505 U_ROM = 0x01, L_ROM = 0x02, U_ENG = 0x04, L_ENG = 0x08,
506 HAN = 0x10, NUM = 0x20, L_BR = 0x40, R_BR = 0x80
508 static const unsigned char type_tbl[][MAX_OUTLINE_LEVEL] =
511 U_ROM, HAN, NUM, HAN | R_BR, L_BR | NUM | R_BR,
512 L_BR | HAN | R_BR, L_ROM | R_BR
515 U_ROM, U_ENG, NUM, L_ENG | R_BR, L_BR | NUM | R_BR,
516 L_BR | L_ENG | R_BR, L_ROM | R_BR
519 NUM, HAN, L_BR | NUM | R_BR, L_BR | HAN | R_BR, NUM |
520 R_BR, HAN | R_BR, L_ENG
523 char fmt = type_tbl[style - OLSTY_NUMSIG1][level];
524 char buf[80], *ptr;
526 if (num < 1)
527 num = 1;
528 if (fmt & L_BR)
529 *hstr++ = '(';
530 if (fmt & NUM)
532 sprintf(buf, "%d", num);
533 str2hstr(buf, hstr);
534 hstr += strlen(buf);
536 else if (fmt & (U_ROM | L_ROM))
538 num2roman(num, buf);
539 if (fmt & U_ROM)
541 ptr = buf;
542 while (*ptr)
544 *ptr = sal::static_int_cast<char>(toupper(*ptr));
545 ptr++;
548 str2hstr(buf, hstr);
549 hstr += strlen(buf);
551 else
553 num = (num - 1) % 26;
554 if (fmt & U_ENG)
555 *hstr++ = sal::static_int_cast<hchar>('A' + num);
556 else if (fmt & L_ENG)
557 *hstr++ = sal::static_int_cast<hchar>('a' + num);
558 else if (fmt & HAN)
559 *hstr++ = olHanglJaso(num, OL_HANGL_KANATA);
561 *hstr++ = (fmt & R_BR) ? ')' : '.';
562 *hstr = 0;
566 enum
567 { OUTLINE_ON, OUTLINE_NUM };
569 /* level Àº 0ºÎÅÍ ½ÃÀÛ. Áï 1.1.1. ÀÇ ·¹º§Àº 2ÀÌ´Ù.
570 number´Â °ªÀÌ ±×´ë·Î µé¾î°¡ ÀÖ´Ù. Áï, 1.2.1¿¡´Â 1,2,1ÀÌ µé¾î°¡ ÀÖ´Ù.
571 style Àº 1ºÎÅÍ °ªÀÌ µé¾î°¡ ÀÖ´Ù. hbox.h¿¡ Á¤ÀÇµÈ µ¥·Î..
573 hchar_string Outline::GetUnicode() const
575 const hchar *p;
576 hchar buffer[255];
578 buffer[0] = 0;
579 if (kind == OUTLINE_NUM)
581 int levelnum;
582 switch (shape)
584 case OLSTY_NUMS1:
585 case OLSTY_NUMS2:
587 char cur_num_str[10], buf[80];
588 int i;
590 buf[0] = 0;
591 for (i = 0; i <= level; i++)
593 levelnum = ((number[i] < 1) ? 1 : number[i]);
594 if (shape == OLSTY_NUMS2 && i && i == level)
595 sprintf(cur_num_str, "%d%c", levelnum, 0);
596 else
597 sprintf(cur_num_str, "%d%c", levelnum, '.');
598 strcat(buf, cur_num_str);
600 str2hstr(buf, buffer);
601 return hstr2ucsstr(buffer);
603 case OLSTY_NUMSIG1:
604 case OLSTY_NUMSIG2:
605 case OLSTY_NUMSIG3:
607 getOutlineNumStr(shape, level, number[level], buffer);
608 return hstr2ucsstr(buffer);
610 case OLSTY_BULLET1:
611 case OLSTY_BULLET2:
612 case OLSTY_BULLET3:
613 case OLSTY_BULLET4:
614 case OLSTY_BULLET5:
616 p = GetOutlineStyleChars(shape);
617 buffer[0] = p[level];
618 buffer[1] = 0;
619 return hstr2ucsstr(buffer);
621 case OLSTY_USER:
622 case OLSTY_BULUSER:
624 char dest[80];
625 int l = 0;
626 int i = level;
627 if( deco[i][0] ){
628 buffer[l++] = deco[i][0];
630 /* level Àº 0ºÎÅÍ ½ÃÀÛ. Áï 1.1.1. ÀÇ ·¹º§Àº 2ÀÌ´Ù.
631 number´Â °ªÀÌ ±×´ë·Î µé¾î°¡ ÀÖ´Ù. Áï, 1.2.1¿¡´Â 1,2,1ÀÌ µé¾î°¡ ÀÖ´Ù.
632 style Àº 1ºÎÅÍ °ªÀÌ µé¾î°¡ ÀÖ´Ù. hbox.h¿¡ Á¤ÀÇµÈ µ¥·Î..
634 switch( user_shape[i] )
636 case 0:
637 buffer[l++] = '1' + number[i] - 1;
638 break;
639 case 1: /* ´ë¹®Àڷθ¶ */
640 case 2: /* ¼Ò¹®Àڷθ¶ */
641 num2roman(number[i], dest);
642 if( user_shape[i] == 1 ){
643 char *ptr = dest;
644 while( *ptr )
646 *ptr = sal::static_int_cast<char>(toupper(*ptr));
647 ptr++;
650 str2hstr(dest, buffer + l);
651 l += strlen(dest);
652 break;
653 case 3:
654 buffer[l++] = 'A' + number[i] -1;
655 break;
656 case 4:
657 buffer[l++] = 'a' + number[i] -1;
658 break;
659 case 5:
660 buffer[l++] = olHanglJaso(number[i] -1, OL_HANGL_KANATA);
661 break;
662 case 6:
663 buffer[l++] = olHanglJaso(number[i] -1, OL_HANGL_JASO);
664 break;
665 case 7: /* ÇÑÀÚ ¼ýÀÚ : ÀÏ¹Ý ¼ýÀڷΠǥÇö */
666 buffer[l++] = '1' + number[i] -1;
667 break;
668 case 8: /* ¿ø¼ýÀÚ */
669 buffer[l++] = 0x2e00 + number[i];
670 break;
671 case 9: /* ¿ø ¾ËÆĺª ¼Ò¹®ÀÚ */
672 buffer[l++] = 0x2c20 + number[i];
673 break;
674 case 10: /* ¿ø °¡³ª´Ù */
675 buffer[l++] = 0x2c50 + number[i] -1;
676 break;
677 case 11: /* ¿ø ¤¡ ¤¤ */
678 buffer[l++] = 0x2c40 + number[i] -1;
679 break;
680 case 12: /* À̾îÁø ¼ýÀÚ. */
682 char cur_num_str[10],buf[80];
683 int j;
684 buf[0] = 0;
685 for (j = 0; j <= level; j++)
687 levelnum = ((number[j] < 1) ? 1 : number[j]);
688 if ((j && j == level) || (j == level && deco[i][1]))
689 sprintf(cur_num_str, "%d%c", levelnum, 0);
690 else
691 sprintf(cur_num_str, "%d%c", levelnum, '.');
692 strcat(buf, cur_num_str);
694 str2hstr(buf, buffer + l);
695 l += strlen(buf);
696 break;
698 default:
699 buffer[l++] = user_shape[i];
700 break;
702 if( deco[i][1] ){
703 buffer[l++] = deco[i][1];
705 buffer[l] = 0;
706 return hstr2ucsstr(buffer);
710 return hstr2ucsstr(buffer);
714 /* ¹­À½ ºóÄ­(30) */
715 /* °íÁ¤Æø ºóÄ­(31) */
717 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */