1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
32 #include <rtl/character.hxx>
34 int HBox::boxCount
= 0;
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
67 SkipData::SkipData(hchar hch
)
78 FieldCode::FieldCode()
84 FieldCode::~FieldCode()
101 DateFormat::DateFormat()
115 static const hchar kor_week
[] =
117 0xB7A9, 0xB6A9, 0xD1C1, 0xAE81, 0xA1A2, 0x8B71, 0xC9A1
119 static const hchar china_week
[] =
121 0x4CC8, 0x4BE4, 0x525A, 0x48D8, 0x45AB, 0x4270, 0x50B4
123 static const char eng_week
[] = { "SunMonTueWedThuFriSat" };
124 static const char eng_mon
[] = { "JanFebMarAprMayJunJulAugSepOctNovDec" };
125 static const char * const en_mon
[] =
127 "January", "February", "March", "April", "May", "June", "July",
128 "August", "September", "October", "November", "December"
130 static const char * const en_week
[] =
132 "Sunday", "Monday", "Tuesday", "Wednesday",
133 "Thursday", "Friday", "Saturday"
136 hchar_string
DateCode::GetString()
143 bool is_pm
, add_zero
;
146 format
[DATE_SIZE
- 1] = 0;
147 fmt
= format
[0] ? format
: defaultform
;
149 for (; *fmt
&& (static_cast<int>(ret
.size()) < DATE_SIZE
); fmt
++)
151 form
= add_zero
? "%02d" : "%d";
154 is_pm
= (date
[HOUR
] >= 12);
168 num
= date
[YEAR
] % 100;
174 memcpy(cbuf
, eng_mon
+ (date
[MONTH
] - 1) * 3, 3);
179 strncat(cbuf
, en_mon
[date
[MONTH
] - 1], sizeof(cbuf
) - strlen(cbuf
) - 1);
181 case '3': /* 'D' is day of korean */
186 switch (date
[DAY
] % 10)
203 num
= date
[HOUR
] - ((date
[HOUR
] > 12) ? 12 : 0);
213 ret
.push_back(kor_week
[date
[WEEK
]]);
216 memcpy(cbuf
, eng_week
+ date
[WEEK
] * 3, 3);
221 strncat(cbuf
, en_week
[date
[WEEK
]], sizeof(cbuf
) - strlen(cbuf
) - 1);
224 ret
.push_back(0xB5A1);
225 ret
.push_back(is_pm
? 0xD281 : 0xB8E5);
228 strncat(cbuf
, is_pm
? "p.m." : "a.m.", sizeof(cbuf
) - strlen(cbuf
) - 1);
231 strncat(cbuf
, is_pm
? "P.M." : "A.M.", sizeof(cbuf
) - strlen(cbuf
) - 1);
233 case '8': // 2.5 feature
237 mkcurfilename(cbuf
, *fmt
);
238 for (i
= 0; cbuf
[i
] != 0 && slen
> 1; i
++)
239 { //for hangle filename
240 if (cbuf
[i
] & 0x80 && cbuf
[i
+ 1] != 0)
242 *d
++ = (cbuf
[i
] << 8) | cbuf
[i
+ 1];
252 case '~': // 3.0b feature
258 ret
.push_back(china_week
[date
[WEEK
]]);
263 if (*fmt
== '\\' && *++fmt
== 0)
268 sprintf(cbuf
, form
, num
);
269 for (i
= 0; 0 != cbuf
[i
]; i
++)
271 ret
.push_back(*(cbuf
+ i
));
288 FBox::FBox(hchar hch
)
318 // tbox(10) TABLE BOX MATH BUTTON HYPERTEXT
336 reserved
[0] = reserved
[1] = 0;
348 , follow_block_size(0)
361 if (pictype
== PICTYPE_DRAW
)
362 delete picinfo
.picdraw
.hdo
;
374 HeaderFooter::~HeaderFooter()
380 Footnote::~Footnote()
387 // show page number (20)
388 // Start/Hide odd-numbered side (21)
391 hchar_string
MailMerge::GetString()
393 return hchar_string();
397 // character composition(23)
403 #define OL_HANGL_JASO 0
404 #define OL_HANGL_KANATA 1
406 static hchar
olHanglJaso(int num
, int type
)
408 static const unsigned char han_init
[] =
409 { 0x88, 0x90, 0x94, 0x9c, 0xa0, 0xa4, 0xac, 0xb4, 0xb8, 0xc0, 0xc4, 0xc8, 0xcc, 0xd0 };
410 static const unsigned char jung
[] = { 3, 5, 7, 11, 13, 19, 20, 26, 27, 29, 30 };
411 static const unsigned char jung2
[] = { 3, 7, 13, 20, 27, 29, 30 };
415 if (type
== OL_HANGL_JASO
)
417 num
= num
% (14 + SAL_N_ELEMENTS(jung
));
420 hh
= (han_init
[num
] << 8) | 'A';
422 hh
= (jung
[num
- 14] << 5) | 0x8401;
427 hh
= (han_init
[num
] << 8) | 'a';
430 int j
= (num
/ 14) % SAL_N_ELEMENTS(jung2
);
433 hh
= (han_init
[num
] << 8) | (jung2
[j
] << 5) | 1;
440 static const hchar
*GetOutlineStyleChars(int style
)
442 static const hchar out_bul_style_entry
[5][8] = // extern
445 0x2f18, 0x2f12, 0x2f08, 0x2f02, 0x2f06, 0x2f00, 0x2043, 0x0000
448 0x2f18, 0x2f12, 0x2f06, 0x2f00, 0x2f36, 0x2f30, 0x2043, 0x0000
451 0x2f26, 0x2f20, 0x2f06, 0x2f00, 0x2f16, 0x2f10, 0x2043, 0x0000
454 0x2f18, 0x2f16, 0x2f12, 0x2f10, 0x2f06, 0x2f00, 0x2043, 0x0000
457 0xAC61, 0xB677, 0xB861, 0xB8F7, 0xB781, 0x0000
460 if (style
>= OLSTY_BULLET1
&& style
<= OLSTY_BULLET5
)
461 return out_bul_style_entry
[style
- OLSTY_BULLET1
];
466 static void getOutlineNumStr(int style
, int level
, int num
, hchar
* hstr
)
470 U_ROM
= 0x01, L_ROM
= 0x02, U_ENG
= 0x04, L_ENG
= 0x08,
471 HAN
= 0x10, NUM
= 0x20, L_BR
= 0x40, R_BR
= 0x80
473 static const unsigned char type_tbl
[][MAX_OUTLINE_LEVEL
] =
476 U_ROM
, HAN
, NUM
, HAN
| R_BR
, L_BR
| NUM
| R_BR
,
477 L_BR
| HAN
| R_BR
, L_ROM
| R_BR
480 U_ROM
, U_ENG
, NUM
, L_ENG
| R_BR
, L_BR
| NUM
| R_BR
,
481 L_BR
| L_ENG
| R_BR
, L_ROM
| R_BR
484 NUM
, HAN
, L_BR
| NUM
| R_BR
, L_BR
| HAN
| R_BR
, NUM
|
485 R_BR
, HAN
| R_BR
, L_ENG
488 char fmt
= type_tbl
[style
- OLSTY_NUMSIG1
][level
];
497 sprintf(buf
, "%d", num
);
501 else if (fmt
& (U_ROM
| L_ROM
))
509 *ptr
= sal::static_int_cast
<char>(
510 rtl::toAsciiUpperCase(static_cast<unsigned char>(*ptr
)));
519 num
= (num
- 1) % 26;
521 *hstr
++ = sal::static_int_cast
<hchar
>('A' + num
);
522 else if (fmt
& L_ENG
)
523 *hstr
++ = sal::static_int_cast
<hchar
>('a' + num
);
525 *hstr
++ = olHanglJaso(num
, OL_HANGL_KANATA
);
527 *hstr
++ = (fmt
& R_BR
) ? ')' : '.';
533 { OUTLINE_ON
, OUTLINE_NUM
};
535 /* level starts from zero. ex) '1.1.1.' is the level 2.
536 number has the value. ex) '1.2.1' has '1,2,1'
537 style has the value which starts from 1 according to the definition in hbox.h
539 hchar_string
Outline::GetUnicode() const
545 if (kind
== OUTLINE_NUM
)
553 char cur_num_str
[10], buf
[80];
557 for (i
= 0; i
<= level
; i
++)
559 levelnum
= ((number
[i
] < 1) ? 1 : number
[i
]);
560 if (shape
== OLSTY_NUMS2
&& i
&& i
== level
)
561 sprintf(cur_num_str
, "%d%c", levelnum
, 0);
563 sprintf(cur_num_str
, "%d%c", levelnum
, '.');
564 strcat(buf
, cur_num_str
);
566 str2hstr(buf
, buffer
);
567 return hstr2ucsstr(buffer
);
573 getOutlineNumStr(shape
, level
, number
[level
], buffer
);
574 return hstr2ucsstr(buffer
);
582 p
= GetOutlineStyleChars(shape
);
583 buffer
[0] = p
[level
];
585 return hstr2ucsstr(buffer
);
594 buffer
[l
++] = deco
[i
][0];
596 /* level starts from zero. ex) '1.1.1.' is the level 2.
597 number has the value. ex) '1.2.1' has '1,2,1'
598 style has the value which starts from 1 according to the definition in hbox.h
600 switch( user_shape
[i
] )
603 buffer
[l
++] = '1' + number
[i
] - 1;
605 case 1: /* Uppercase Roman */
606 case 2: /* Lowercase Roman */
607 num2roman(number
[i
], dest
);
608 if( user_shape
[i
] == 1 ){
612 *ptr
= sal::static_int_cast
<char>(rtl::toAsciiUpperCase(static_cast<unsigned char>(*ptr
)));
616 str2hstr(dest
, buffer
+ l
);
620 buffer
[l
++] = 'A' + number
[i
] -1;
623 buffer
[l
++] = 'a' + number
[i
] -1;
626 buffer
[l
++] = olHanglJaso(number
[i
] -1, OL_HANGL_KANATA
);
629 buffer
[l
++] = olHanglJaso(number
[i
] -1, OL_HANGL_JASO
);
631 case 7: /* Chinese numbers: the number represented by the general */
632 buffer
[l
++] = '1' + number
[i
] -1;
634 case 8: /* Circled numbers */
635 buffer
[l
++] = 0x2e00 + number
[i
];
637 case 9: /* Circled lowercase alphabet */
638 buffer
[l
++] = 0x2c20 + number
[i
];
640 case 10: /* Circled Korean Alphabet */
641 buffer
[l
++] = 0x2c50 + number
[i
] -1;
643 case 11: /* Circled Korean Characters */
644 buffer
[l
++] = 0x2c40 + number
[i
] -1;
646 case 12: /* Sequenced numbers. */
648 char cur_num_str
[10],buf
[80];
651 for (j
= 0; j
<= level
; j
++)
653 levelnum
= ((number
[j
] < 1) ? 1 : number
[j
]);
654 if ((j
&& j
== level
) || (j
== level
&& deco
[i
][1]))
655 sprintf(cur_num_str
, "%d%c", levelnum
, 0);
657 sprintf(cur_num_str
, "%d%c", levelnum
, '.');
658 strcat(buf
, cur_num_str
);
660 str2hstr(buf
, buffer
+ l
);
665 buffer
[l
++] = user_shape
[i
];
669 buffer
[l
++] = deco
[i
][1];
672 return hstr2ucsstr(buffer
);
676 return hstr2ucsstr(buffer
);
680 /* Bundle of spaces (30) */
681 /* Fixed-width spaces (31) */
683 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */