1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "precompile.h"
#include <ctype.h>
#include <osl/diagnose.h>
#include "hwpfile.h"
#include "hbox.h"
#include "hpara.h"
#include "hutil.h"
#include "htags.h"
#include "drawdef.h"
#include "hcode.h"
int HBox::boxCount = 0;
HBox::HBox(hchar hch)
{
hh = hch;
boxCount++;
}
HBox::~HBox()
{
boxCount--;
}
int HBox::WSize(void)
{
static const int wsize[32] =
{
1, 4, 4, 4, 4, 4, 4, 42, /* dateform */
48, 4, 4, 4, 4, 1, 4, 4, /* hidden */
4, 4, 4, 4, 4, 4, 12, 5, /* chcompose */
3, 3, 123, 4, 32, 4, 2, 2
};
if (hh < 32)
return wsize[hh];
else
return 1;
}
hchar_string HBox::GetString()
{
hchar_string ret;
ret.push_back(hh);
return ret;
}
hunit HBox::Height(CharShape *csty)
{
return( csty->size );
}
// skip block
SkipData::SkipData(hchar hch)
: HBox(hch)
, data_block_len(0)
, dummy(0)
, data_block(0)
{
}
SkipData::~SkipData(void)
{
delete[]data_block;
}
// FieldCode [5]
FieldCode::FieldCode()
: HBox(CH_FIELD)
, location_info(0)
, str1(NULL)
, str2(NULL)
, str3(NULL)
, bin(NULL)
, m_pDate(NULL)
{
reserved1 = new char[4];
reserved2 = new char[22];
}
FieldCode::~FieldCode(void)
{
delete[] str1;
delete[] str2;
delete[] str3;
delete[] bin;
delete[] reserved1;
delete[] reserved2;
delete m_pDate;
}
// book mark(6)
Bookmark::Bookmark()
: HBox(CH_BOOKMARK)
, dummy(0)
, type(0)
{
}
Bookmark::~Bookmark(void)
{
}
// date format(7)
DateFormat::DateFormat()
: HBox(CH_DATE_FORM)
, dummy(0)
{
}
// date code(8)
DateCode::DateCode()
: HBox(CH_DATE_CODE)
, dummy(0)
, key(0)
{
}
#define _DATECODE_WEEK_DEFINES_
#include "datecode.h"
hchar_string DateCode::GetString()
{
hchar_string ret;
const hchar *fmt;
int i, num;
const char *form;
char cbuf[256];
bool is_pm, add_zero;
add_zero = false;
format[DATE_SIZE - 1] = 0;
fmt = format[0] ? format : defaultform;
for (; *fmt && ((int) ret.size() < DATE_SIZE); fmt++)
{
form = (add_zero) ? "%02d" : "%d";
add_zero = false;
is_pm = (date[HOUR] >= 12);
*cbuf = 0;
num = -1;
switch (*fmt)
{
case '0':
add_zero = true;
break;
case '1':
num = date[YEAR];
form = "%04d";
break;
case '!':
num = date[YEAR] % 100;
break;
case '2':
num = date[MONTH];
break;
case '@':
memcpy(cbuf, eng_mon + (date[MONTH] - 1) * 3, 3);
cbuf[3] = '.';
cbuf[4] = 0;
break;
case '*':
strcpy(cbuf, en_mon[date[MONTH] - 1]);
break;
case '3': /* 'D' is day of korean */
num = date[DAY];
break;
case '#':
num = date[DAY];
switch (date[DAY] % 10)
{
case 1:
form = "%dst";
break;
case 2:
form = "%dnd";
break;
case 3:
form = "%drd";
break;
default:
form = "%dth";
break;
}
break;
case '4':
num = date[HOUR] - ((date[HOUR] > 12) ? 12 : 0);
break;
case '$':
num = date[HOUR];
break;
case '5':
case '%':
num = date[MIN];
break;
case '6':
ret.push_back(kor_week[date[WEEK]]);
break;
case '^':
memcpy(cbuf, eng_week + date[WEEK] * 3, 3);
cbuf[3] = '.';
cbuf[4] = 0;
break;
case '_':
strcpy(cbuf, en_week[date[WEEK]]);
break;
case '7':
ret.push_back(0xB5A1);
ret.push_back((is_pm) ? 0xD281 : 0xB8E5);
break;
case '&':
strcpy(cbuf, (is_pm) ? "p.m." : "a.m.");
break;
case '+':
strcpy(cbuf, (is_pm) ? "P.M." : "A.M.");
break;
case '8': // 2.5 feature
case '9':
#if 0
// LATER
mkcurfilename(cbuf, *fmt);
for (i = 0; cbuf[i] != 0 && slen > 1; i++)
{ //for hangle filename
if (cbuf[i] & 0x80 && cbuf[i + 1] != 0)
{
*d++ = (cbuf[i] << 8) | cbuf[i + 1];
i++;
}
else
*d++ = cbuf[i];
slen--;
}
#endif
cbuf[0] = 0;
break;
case '~': // 3.0b feature
if (fmt[1] == 0)
break;
fmt++;
if (*fmt == '6')
{
ret.push_back(china_week[date[WEEK]]);
break;
}
break;
default:
if (*fmt == '\\' && *++fmt == 0)
goto done;
ret.push_back(*fmt);
}
if (num != -1)
sprintf(cbuf, form, num);
for (i = 0; 0 != cbuf[i]; i++)
{
ret.push_back(*(cbuf + i));
}
}
done:
return ret;
}
// tab(9)
Tab::Tab()
: HBox(CH_TAB)
, width(0)
, leader(0)
, dummy(0)
{
}
// floating box
FBox::FBox(hchar hch)
: HBox(hch)
, zorder(0)
, option(0)
, ctrl_ch(0)
, box_xs(0)
, box_ys(0)
, cap_xs(0)
, cap_ys(0)
, xs(0)
, ys(0)
, cap_margin(0)
, xpos_type(0)
, ypos_type(0)
, smart_linesp(0)
, boundsy(0)
, boundey(0)
, boundx(0)
, draw(0)
, pgx(0)
, pgy(0)
, pgno(0)
, showpg(0)
, prev(NULL)
, next(NULL)
{
}
FBox::~FBox()
{
}
// tbox(10) TABLE BOX MATH BUTTON HYPERTEXT
TxtBox::TxtBox()
: FBox(CH_TEXT_BOX)
, dummy(0)
, dummy1(0)
, cap_len(0)
, next(0)
, dummy2(0)
, reserved1(0)
, cap_pos(0)
, num(0)
, dummy3(0)
, baseline(0)
, type(0)
, nCell(0)
, protect(0)
, cell(0)
, m_pTable(NULL)
, plists(NULL)
{
reserved[0] = reserved[1] = 0;
}
TxtBox::~TxtBox(void)
{
delete[]cell;
for (int ii = 0; ii < nCell; ++ii)
{
std::list < HWPPara* >::iterator it = plists[ii].begin();
for (; it != plists[ii].end(); ++it)
{
HWPPara* pPara = *it;
delete pPara;
}
}
std::list < HWPPara* >::iterator it = caption.begin();
for (; it != caption.end(); ++it)
{
HWPPara* pPara = *it;
delete pPara;
}
delete[]plists;
}
hunit TxtBox::Height(CharShape * csty)
{
return (style.anchor_type == CHAR_ANCHOR) ? box_ys : csty->size;
}
// picture(11)
Picture::Picture()
: FBox(CH_PICTURE)
, dummy(0)
, follow_block_size(0)
, dummy1(0)
, dummy2(0)
, reserved1(0)
, cap_pos(0)
, num(0)
, pictype(0)
, follow(0)
, ishyper(false)
{
}
Picture::~Picture(void)
{
delete[]follow;
if( pictype == PICTYPE_DRAW && picinfo.picdraw.hdo )
delete (HWPDrawingObject *) picinfo.picdraw.hdo;
std::list < HWPPara* >::iterator it = caption.begin();
for (; it != caption.end(); ++it)
{
HWPPara* pPara = *it;
delete pPara;
}
}
int Picture::Type()
{
return pictype;
}
hunit Picture::Height(CharShape * sty)
{
return (style.anchor_type == CHAR_ANCHOR) ? box_ys : sty->size;
}
// line(14)
// hidden(15)
Hidden::~Hidden(void)
{
std::list < HWPPara* >::iterator it = plist.begin();
for (; it != plist.end(); ++it)
{
HWPPara* pPara = *it;
delete pPara;
}
}
// header/footer(16)
HeaderFooter::~HeaderFooter(void)
{
std::list < HWPPara* >::iterator it = plist.begin();
for (; it != plist.end(); ++it)
{
HWPPara* pPara = *it;
delete pPara;
}
}
// footnote(17)
Footnote::~Footnote(void)
{
std::list < HWPPara* >::iterator it = plist.begin();
for (; it != plist.end(); ++it)
{
HWPPara* pPara = *it;
delete pPara;
}
}
// auto number(18)
// new number(19)
// show page number (20)
// 홀수쪽시작/감추기 (21)
// mail merge(22)
hchar_string MailMerge::GetString()
{
return hchar_string();
}
// character compositon(23)
// hyphen(24)
// toc mark(25)
// index mark(26)
// outline(28)
#define OL_HANGL_JASO 0
#define OL_HANGL_KANATA 1
static hchar olHanglJaso(int num, int type)
{
static const unsigned char han_init[] =
{ 0x88, 0x90, 0x94, 0x9c, 0xa0, 0xa4, 0xac, 0xb4, 0xb8, 0xc0, 0xc4, 0xc8, 0xcc, 0xd0 };
static const unsigned char jung[] = { 3, 5, 7, 11, 13, 19, 20, 26, 27, 29, 30 };
static const unsigned char jung2[] = { 3, 7, 13, 20, 27, 29, 30 };
hchar hh = 0;
if (type == OL_HANGL_JASO)
{
num = num % (14 + (sizeof(jung) / sizeof(char)));
if (num < 14)
hh = (han_init[num] << 8) | 'A';
else
hh = (jung[num - 14] << 5) | 0x8401;
}
else
{
if (num < 14)
hh = (han_init[num] << 8) | 'a';
else
{
int j = (num / 14) % (sizeof(jung2) / sizeof(char));
num = num % 14;
hh = (han_init[num] << 8) | (jung2[j] << 5) | 1;
}
}
return hh;
}
static const hchar *GetOutlineStyleChars(int style)
{
static const hchar out_bul_style_entry[5][8] = // extern
{
{ // 0 OLSTY_BULLET1
0x2f18, 0x2f12, 0x2f08, 0x2f02, 0x2f06, 0x2f00, 0x2043, 0x0000
},
{ // 1
0x2f18, 0x2f12, 0x2f06, 0x2f00, 0x2f36, 0x2f30, 0x2043, 0x0000
},
{ // 2
0x2f26, 0x2f20, 0x2f06, 0x2f00, 0x2f16, 0x2f10, 0x2043, 0x0000
},
{ // 3
0x2f18, 0x2f16, 0x2f12, 0x2f10, 0x2f06, 0x2f00, 0x2043, 0x0000
},
{
0xAC61, 0xB677, 0xB861, 0xB8F7, 0xB781, 0x0000
},
};
if (style >= OLSTY_BULLET1 && style <= OLSTY_BULLET5)
return out_bul_style_entry[style - OLSTY_BULLET1];
return NULL;
}
static void getOutlineNumStr(int style, int level, int num, hchar * hstr)
{
enum
{
U_ROM = 0x01, L_ROM = 0x02, U_ENG = 0x04, L_ENG = 0x08,
HAN = 0x10, NUM = 0x20, L_BR = 0x40, R_BR = 0x80
};
static const unsigned char type_tbl[][MAX_OUTLINE_LEVEL] =
{
{
U_ROM, HAN, NUM, HAN | R_BR, L_BR | NUM | R_BR,
L_BR | HAN | R_BR, L_ROM | R_BR
},
{
U_ROM, U_ENG, NUM, L_ENG | R_BR, L_BR | NUM | R_BR,
L_BR | L_ENG | R_BR, L_ROM | R_BR
},
{
NUM, HAN, L_BR | NUM | R_BR, L_BR | HAN | R_BR, NUM |
R_BR, HAN | R_BR, L_ENG
}
};
char fmt = type_tbl[style - OLSTY_NUMSIG1][level];
char buf[80], *ptr;
if (num < 1)
num = 1;
if (fmt & L_BR)
*hstr++ = '(';
if (fmt & NUM)
{
sprintf(buf, "%d", num);
str2hstr(buf, hstr);
hstr += strlen(buf);
}
else if (fmt & (U_ROM | L_ROM))
{
num2roman(num, buf);
if (fmt & U_ROM)
{
ptr = buf;
while (*ptr)
{
*ptr = sal::static_int_cast<char>(toupper(*ptr));
ptr++;
}
}
str2hstr(buf, hstr);
hstr += strlen(buf);
}
else
{
num = (num - 1) % 26;
if (fmt & U_ENG)
*hstr++ = sal::static_int_cast<hchar>('A' + num);
else if (fmt & L_ENG)
*hstr++ = sal::static_int_cast<hchar>('a' + num);
else if (fmt & HAN)
*hstr++ = olHanglJaso(num, OL_HANGL_KANATA);
}
*hstr++ = (fmt & R_BR) ? ')' : '.';
*hstr = 0;
}
enum
{ OUTLINE_ON, OUTLINE_NUM };
/* level 은 0부터 시작. 즉 1.1.1. 의 레벨은 2이다.
number는 값이 그대로 들어가 있다. 즉, 1.2.1에는 1,2,1이 들어가 있다.
style 은 1부터 값이 들어가 있다. hbox.h에 정의된 데로..
*/
hchar_string Outline::GetUnicode() const
{
const hchar *p;
hchar buffer[255];
buffer[0] = 0;
if (kind == OUTLINE_NUM)
{
int levelnum;
switch (shape)
{
case OLSTY_NUMS1:
case OLSTY_NUMS2:
{
char cur_num_str[10], buf[80];
int i;
buf[0] = 0;
for (i = 0; i <= level; i++)
{
levelnum = ((number[i] < 1) ? 1 : number[i]);
if (shape == OLSTY_NUMS2 && i && i == level)
sprintf(cur_num_str, "%d%c", levelnum, 0);
else
sprintf(cur_num_str, "%d%c", levelnum, '.');
strcat(buf, cur_num_str);
}
str2hstr(buf, buffer);
return hstr2ucsstr(buffer);
}
case OLSTY_NUMSIG1:
case OLSTY_NUMSIG2:
case OLSTY_NUMSIG3:
{
getOutlineNumStr(shape, level, number[level], buffer);
return hstr2ucsstr(buffer);
}
case OLSTY_BULLET1:
case OLSTY_BULLET2:
case OLSTY_BULLET3:
case OLSTY_BULLET4:
case OLSTY_BULLET5:
{
p = GetOutlineStyleChars(shape);
buffer[0] = p[level];
buffer[1] = 0;
return hstr2ucsstr(buffer);
}
case OLSTY_USER:
case OLSTY_BULUSER:
{
char dest[80];
int l = 0;
int i = level;
if( deco[i][0] ){
buffer[l++] = deco[i][0];
}
/* level 은 0부터 시작. 즉 1.1.1. 의 레벨은 2이다.
number는 값이 그대로 들어가 있다. 즉, 1.2.1에는 1,2,1이 들어가 있다.
style 은 1부터 값이 들어가 있다. hbox.h에 정의된 데로..
*/
switch( user_shape[i] )
{
case 0:
buffer[l++] = '1' + number[i] - 1;
break;
case 1: /* 대문자로마 */
case 2: /* 소문자로마 */
num2roman(number[i], dest);
if( user_shape[i] == 1 ){
char *ptr = dest;
while( *ptr )
{
*ptr = sal::static_int_cast<char>(toupper(*ptr));
ptr++;
}
}
str2hstr(dest, buffer + l);
l += strlen(dest);
break;
case 3:
buffer[l++] = 'A' + number[i] -1;
break;
case 4:
buffer[l++] = 'a' + number[i] -1;
break;
case 5:
buffer[l++] = olHanglJaso(number[i] -1, OL_HANGL_KANATA);
break;
case 6:
buffer[l++] = olHanglJaso(number[i] -1, OL_HANGL_JASO);
break;
case 7: /* 한자 숫자 : 일반 숫자로 표현 */
buffer[l++] = '1' + number[i] -1;
break;
case 8: /* 원숫자 */
buffer[l++] = 0x2e00 + number[i];
break;
case 9: /* 원 알파벳 소문자 */
buffer[l++] = 0x2c20 + number[i];
break;
case 10: /* 원 가나다 */
buffer[l++] = 0x2c50 + number[i] -1;
break;
case 11: /* 원 ㄱ ㄴ */
buffer[l++] = 0x2c40 + number[i] -1;
break;
case 12: /* 이어진 숫자. */
{
char cur_num_str[10],buf[80];
int j;
buf[0] = 0;
for (j = 0; j <= level; j++)
{
levelnum = ((number[j] < 1) ? 1 : number[j]);
if ((j && j == level) || (j == level && deco[i][1]))
sprintf(cur_num_str, "%d%c", levelnum, 0);
else
sprintf(cur_num_str, "%d%c", levelnum, '.');
strcat(buf, cur_num_str);
}
str2hstr(buf, buffer + l);
l += strlen(buf);
break;
}
default:
buffer[l++] = user_shape[i];
break;
}
if( deco[i][1] ){
buffer[l++] = deco[i][1];
}
buffer[l] = 0;
return hstr2ucsstr(buffer);
}
}
}
return hstr2ucsstr(buffer);
}
/* 묶음 빈칸(30) */
/* 고정폭 빈칸(31) */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|