2 #*************************************************************************
4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 # Copyright 2000, 2010 Oracle and/or its affiliates.
8 # OpenOffice.org - a multi-platform office productivity suite
10 # This file is part of OpenOffice.org.
12 # OpenOffice.org is free software: you can redistribute it and/or modify
13 # it under the terms of the GNU Lesser General Public License version 3
14 # only, as published by the Free Software Foundation.
16 # OpenOffice.org is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU Lesser General Public License version 3 for more details
20 # (a copy is included in the LICENSE file that accompanied this code).
22 # You should have received a copy of the GNU Lesser General Public License
23 # version 3 along with OpenOffice.org. If not, see
24 # <http://www.openoffice.org/license.html>
25 # for a copy of the LGPLv3 License.
27 #*************************************************************************
29 # The following files must be available in a ./input subdir:
31 # <http://www.unicode.org/Public/UNIDATA/Unihan.txt>:
32 # "Unicode version: 3.1.1 Table version: 1.1 Date: 28 June 2001"
33 # contains descriptions for:
34 # U+3400..4DFF CJK Unified Ideographs Extension A
35 # U+4E00..9FFF CJK Unified Ideographs
36 # U+F900..FAFF CJK Compatibility Ideographs
37 # U+20000..2F7FF CJK Unified Ideographs Extension B
38 # U+2F800..2FFFF CJK Compatibility Ideographs Supplement
40 # <http://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/CNS11643.TXT>:
41 # "Unicode version: 1.1 Table version: 0.0d1 Date: 21 October 1994"
42 # contains mappings for CNS 11643-1986
44 # <http://kanji.zinbun.kyoto-u.ac.jp/~yasuoka/ftp/CJKtable/Uni2CNS.Z>:
45 # "Unicode version: 1.1 Table version: 0.49 Date: 26 March 1998"
46 # contains mappings for CNS 11643-1992 that are incompatible with
54 return $utf32 >= 0 && $utf32 <= 0x10FFFF
55 && !($utf32 >= 0xD800 && $utf32 <= 0xDFFF)
56 && !($utf32 >= 0xFDD0 && $utf32 <= 0xFDEF)
57 && ($utf32 & 0xFFFF) < 0xFFFE;
63 return sprintf("U+%04X", $utf32);
66 sub isValidCns116431992
71 return $plane >= 1 && $plane <= 16
72 && $row >= 1 && $row <= 94
73 && $column >= 1 && $column <= 94;
81 return sprintf("%d-%02d/%02d", $plane, $row, $column);
88 return sprintf("%d/%d bytes (%.1f%%)",
91 $used * 100 / $space);
96 my $column_width = $_[0];
97 my $columns_per_line = $_[1];
100 for ($i = int($end / $columns_per_line) * $columns_per_line;
104 for ($j = 0; $j < $column_width; ++$j)
106 $output = $output . " ";
112 $count_Unihan_txt = 0;
113 $count_CNS11643_TXT = 0;
118 $filename = "Unihan.txt";
119 open IN
, ("input/" . $filename) or die "Cannot read " . $filename;
122 if (/^U\+([0-9A-F]+)\tkCNS1992\t([0-9A-F])-([0-9A-F][0-9A-F])([0-9A-F][0-9A-F])$/)
124 $utf32 = oct("0x" . $1);
125 $cns_plane = oct("0x" . $2);
126 $cns_row = oct("0x" . $3) - 0x20;
127 $cns_column = oct("0x" . $4) - 0x20;
129 or die "Bad UTF32 char U+" . printUtf32
($utf32);
130 isValidCns116431992
($cns_plane, $cns_row, $cns_column)
131 or die "Bad CNS11643-1992 char "
132 . printCns116431992
($cns_plane,
135 if (!defined($cns_map[$cns_plane][$cns_row][$cns_column]))
137 $cns_map[$cns_plane][$cns_row][$cns_column] = $utf32;
138 $cns_plane_used[$cns_plane] = 1;
143 ($cns_map[$cns_plane][$cns_row][$cns_column] == $utf32)
145 . printCns116431992
($cns_plane,
149 . printUtf32
($cns_map[$cns_plane]
153 . printUtf32
($utf32);
156 elsif (/^U\+([0-9A-F]+)\tkIRG_TSource\t([0-9A-F])-([0-9A-F][0-9A-F])([0-9A-F][0-9A-F])$/)
158 $utf32 = oct("0x" . $1);
159 $cns_plane = oct("0x" . $2);
160 $cns_row = oct("0x" . $3) - 0x20;
161 $cns_column = oct("0x" . $4) - 0x20;
163 or die "Bad UTF32 char U+" . printUtf32
($utf32);
164 isValidCns116431992
($cns_plane, $cns_row, $cns_column)
165 or die "Bad CNS11643-1992 char "
166 . printCns116431992
($cns_plane,
169 if (!defined($cns_map[$cns_plane][$cns_row][$cns_column]))
171 $cns_map[$cns_plane][$cns_row][$cns_column] = $utf32;
172 $cns_plane_used[$cns_plane] = 1;
177 ($cns_map[$cns_plane][$cns_row][$cns_column] == $utf32)
178 or print "WARNING! Mapping ",
179 printCns116431992
($cns_plane,
183 printUtf32
($cns_map[$cns_plane]
191 elsif (/^U\+([0-9A-F]+)\tkCNS1992\t.*$/)
201 $filename = "CNS11643.TXT";
202 open IN
, ("input/" . $filename) or die "Cannot read " . $filename;
205 if (/0x([0-9A-F])([0-9A-F][0-9A-F])([0-9A-F][0-9A-F])\t0x([0-9A-F]+)\t\#.*$/)
207 $utf32 = oct("0x" . $4);
208 $cns_plane = oct("0x" . $1);
209 $cns_row = oct("0x" . $2) - 0x20;
210 $cns_column = oct("0x" . $3) - 0x20;
212 or die "Bad UTF32 char U+" . printUtf32
($utf32);
213 isValidCns116431992
($cns_plane, $cns_row, $cns_column)
214 or die "Bad CNS11643-1992 char "
215 . printCns116431992
($cns_plane,
220 if (!defined($cns_map[$cns_plane][$cns_row][$cns_column]))
222 $cns_map[$cns_plane][$cns_row][$cns_column] = $utf32;
223 $cns_plane_used[$cns_plane] = 1;
224 ++$count_CNS11643_TXT;
228 ($cns_map[$cns_plane][$cns_row][$cns_column] == $utf32)
230 . printCns116431992
($cns_plane,
234 . printUtf32
($cns_map[$cns_plane]
238 . printUtf32
($utf32);
248 $filename = "Uni2CNS";
249 open IN
, ("input/" . $filename) or die "Cannot read " . $filename;
252 if (/([0-9A-F]+)\t([0-9A-F])-([0-9A-F][0-9A-F])([0-9A-F][0-9A-F])\t.*$/)
254 $utf32 = oct("0x" . $1);
255 $cns_plane = oct("0x" . $2);
256 $cns_row = oct("0x" . $3) - 0x20;
257 $cns_column = oct("0x" . $4) - 0x20;
259 or die "Bad UTF32 char U+" . printUtf32
($utf32);
260 isValidCns116431992
($cns_plane, $cns_row, $cns_column)
261 or die "Bad CNS11643-1992 char "
262 . printCns116431992
($cns_plane,
265 if (!defined($cns_map[$cns_plane][$cns_row][$cns_column]))
267 $cns_map[$cns_plane][$cns_row][$cns_column] = $utf32;
268 $cns_plane_used[$cns_plane] = 1;
273 # ($cns_map[$cns_plane][$cns_row][$cns_column] == $utf32)
275 # . printCns116431992($cns_plane,
279 # . printUtf32($cns_map[$cns_plane]
283 # . printUtf32($utf32);
287 print printCns116431992
($cns_plane, $cns_row, $cns_column),
295 for ($cns_plane = 1; $cns_plane <= 16; ++$cns_plane)
297 if (defined($cns_plane_used[$cns_plane]))
299 for ($cns_row = 1; $cns_row <= 94; ++$cns_row)
301 for ($cns_column = 1; $cns_column <= 94; ++$cns_column)
303 if (defined($cns_map[$cns_plane][$cns_row][$cns_column]))
305 $utf32 = $cns_map[$cns_plane][$cns_row][$cns_column];
306 $uni_plane = $utf32 >> 16;
307 $uni_page = ($utf32 >> 8) & 0xFF;
308 $uni_index = $utf32 & 0xFF;
309 if (!defined($uni_plane_used[$uni_plane])
310 || !defined($uni_page_used[$uni_plane][$uni_page])
311 || !defined($uni_map[$uni_plane]
315 $uni_map[$uni_plane][$uni_page][$uni_index]
319 $uni_plane_used[$uni_plane] = 1;
320 $uni_page_used[$uni_plane][$uni_page] = 1;
324 $cns1 = $uni_map[$uni_plane][$uni_page][$uni_index];
325 $cns1_plane = $cns1 >> 16;
326 $cns1_row = ($cns1 >> 8) & 0xFF;
327 $cns1_column = $cns1 & 0xFF;
329 # Do not map from Unicode to Fictious Character Set
330 # Extensions (Lunde, p. 131), if possible:
332 && ($cns_row == 66 && $cns_column > 38
338 printCns116431992
($cns_plane,
341 " ignored, favouring ",
342 printCns116431992
($cns1_plane,
347 elsif ($cns1_plane == 3
348 && ($cns1_row == 66 && $cns1_column > 38
351 $uni_map[$uni_plane][$uni_page][$uni_index]
358 printCns116431992
($cns1_plane,
361 " ignored, favouring ",
362 printCns116431992
($cns_plane,
369 print "WARNING! Mapping ",
372 printCns116431992
($cns1_plane,
376 printCns116431992
($cns_plane,
387 if (defined($uni_plane_used[0]) && defined($uni_page_used[0][0]))
389 for ($utf32 = 0; $utf32 <= 0x7F; ++$utf32)
391 if (defined($uni_map[0][0][$uni_index]))
393 $cns = $uni_map[0][0][$utf32];
397 . printCns116431992
($cns >> 16,
404 $filename = lc($id) . ".tab";
405 open OUT
, ("> " . $filename) or die "Cannot write " . $filename;
408 $filename = lc($id). ".pl";
409 open IN
, $filename or die "Cannot read ". $filename;
420 print OUT
"/", $1, "\n";
425 print OUT
" ", substr($1, 0, length($1) - 1), "/\n";
430 print OUT
" *", $1, "\n";
434 print OUT
" *", $1, "\n";
445 "#ifndef _SAL_TYPES_H_\n",
446 "#include \"sal/types.h\"\n",
450 print OUT
"static sal_uInt16 const aImpl", $id, "ToUnicodeData[] = {\n";
452 for ($cns_plane = 1; $cns_plane <= 16; ++$cns_plane)
454 if (defined($cns_plane_used[$cns_plane]))
458 for ($cns_row = 1; $cns_row <= 94; ++$cns_row)
461 for ($cns_column = 1; $cns_column <= 94; ++$cns_column)
463 if (defined($cns_map[$cns_plane][$cns_row][$cns_column]))
465 if ($cns_row_first == -1)
467 $cns_row_first = $cns_column;
469 $cns_row_last = $cns_column;
472 if ($cns_row_first != -1)
474 $cns_data_offsets[$cns_plane][$cns_row] = $cns_data_index;
476 print OUT
" /* plane ", $cns_plane, ", row ", $cns_row,
479 $cns_row_surrogates_first = -1;
481 $cns_row_surrogates = 0;
483 print OUT
" ", $cns_row_first, " | (", $cns_row_last,
484 " << 8), /* first, last */\n";
487 print OUT
" ", printSpaces
(7, 10, $cns_row_first);
489 for ($cns_column = $cns_row_first;
490 $cns_column <= $cns_row_last;
498 if (defined($cns_map[$cns_plane][$cns_row][$cns_column]))
500 $utf32 = $cns_map[$cns_plane][$cns_row][$cns_column];
502 if ($utf32 <= 0xFFFF)
504 printf OUT
"0x%04X,", $utf32;
508 ++$cns_row_surrogates;
509 printf OUT
"0x%04X,",
510 (0xD800 | (($utf32 - 0x10000) >> 10));
511 if ($cns_row_surrogates_first == -1)
513 $cns_row_surrogates_first = $cns_column;
515 $cns_row_surrogates_last = $cns_column;
520 printf OUT
"0xffff,";
523 if ($cns_column % 10 == 9)
534 if ($cns_row_surrogates_first != -1)
536 print OUT
" ", $cns_row_surrogates_first,
537 ", /* first low-surrogate */\n";
541 printSpaces
(7, 10, $cns_row_surrogates_first);
543 for ($cns_column = $cns_row_surrogates_first;
544 $cns_column <= $cns_row_surrogates_last;
553 if (defined($cns_map[$cns_plane]
558 = $cns_map[$cns_plane][$cns_row][$cns_column];
560 if ($utf32 <= 0xFFFF)
566 printf OUT
"0x%04X,",
568 | (($utf32 - 0x10000) & 0x3FF));
571 if ($cns_column % 10 == 9)
583 $cns_chars += $cns_row_chars;
584 $cns_data_space[$cns_plane][$cns_row]
586 - $cns_data_offsets[$cns_plane][$cns_row]) * 2;
587 $cns_data_used[$cns_plane][$cns_row]
588 = (1 + $cns_row_chars
589 + ($cns_row_surrogates == 0 ?
590 0 : 1 + $cns_row_surrogates)) * 2;
594 print OUT
" /* plane ", $cns_plane, ", row ", $cns_row,
596 $cns_data_offsets[$cns_plane][$cns_row] = -1;
610 print OUT
"static sal_Int32 const aImpl", $id, "ToUnicodeRowOffsets[] = {\n";
611 for ($cns_plane = 1; $cns_plane <= 16; ++$cns_plane)
613 if (defined ($cns_plane_used[$cns_plane]))
615 $cns_rowoffsets_used[$cns_plane] = 0;
616 for ($cns_row = 1; $cns_row <= 94; ++$cns_row)
618 if ($cns_data_offsets[$cns_plane][$cns_row] == -1)
620 print OUT
" -1, /* plane ",
629 $cns_data_offsets[$cns_plane][$cns_row],
635 printStats
($cns_data_used[$cns_plane][$cns_row],
636 $cns_data_space[$cns_plane][$cns_row]),
638 $cns_rowoffsets_used[$cns_plane] += 4;
644 print OUT
" /* plane ", $cns_plane, ": --- */\n";
649 print OUT
"static sal_Int32 const aImpl",
651 "ToUnicodePlaneOffsets[] = {\n";
653 for ($cns_plane = 1; $cns_plane <= 16; ++$cns_plane)
655 if (defined ($cns_plane_used[$cns_plane]))
662 printStats
($cns_rowoffsets_used[$cns_plane], 94 * 4),
667 print OUT
" -1, /* plane ", $cns_plane, " */\n";
672 print OUT
"static sal_uInt8 const aImplUnicodeTo", $id, "Data[] = {\n";
674 for ($uni_plane = 0; $uni_plane <= 16; ++$uni_plane)
676 if (defined($uni_plane_used[$uni_plane]))
678 for ($uni_page = 0; $uni_page <= 255; ++$uni_page)
680 if (defined($uni_page_used[$uni_plane][$uni_page]))
682 $uni_data_offsets[$uni_plane][$uni_page] = $uni_data_index;
683 print OUT
" /* plane ", $uni_plane, ", page ", $uni_page,
686 $uni_page_first = -1;
687 for ($uni_index = 0; $uni_index <= 255; ++$uni_index)
689 if (defined($uni_map[$uni_plane][$uni_page][$uni_index]))
691 if ($uni_page_first == -1)
693 $uni_page_first = $uni_index;
695 $uni_page_last = $uni_index;
699 $uni_data_used[$uni_plane][$uni_page] = 0;
701 print OUT
" ", $uni_page_first, ", ", $uni_page_last,
702 ", /* first, last */\n";
703 $uni_data_index += 2;
704 $uni_data_used[$uni_plane][$uni_page] += 2;
706 print OUT
" ", printSpaces
(9, 8, $uni_page_first);
708 for ($uni_index = $uni_page_first;
709 $uni_index <= $uni_page_last;
717 if (defined($uni_map[$uni_plane][$uni_page][$uni_index]))
719 $cns = $uni_map[$uni_plane][$uni_page][$uni_index];
720 printf OUT
"%2d,%2d,%2d,",
724 $uni_data_used[$uni_plane][$uni_page] += 3;
728 print OUT
" 0, 0, 0,";
730 $uni_data_index += 3;
731 if ($uni_index % 8 == 7)
742 $uni_data_space[$uni_plane][$uni_page]
744 - $uni_data_offsets[$uni_plane][$uni_page];
748 $uni_data_offsets[$uni_plane][$uni_page] = -1;
749 print OUT
" /* plane ", $uni_plane, ", page ", $uni_page,
756 print OUT
" /* plane ", $uni_plane, ": --- */\n";
761 print OUT
"static sal_Int32 const aImplUnicodeTo", $id, "PageOffsets[] = {\n";
762 for ($uni_plane = 0; $uni_plane <= 16; ++$uni_plane)
764 if (defined($uni_plane_used[$uni_plane]))
766 $uni_pageoffsets_used[$uni_plane] = 0;
767 $uni_data_used_sum[$uni_plane] = 0;
768 $uni_data_space_sum[$uni_plane] = 0;
769 for ($uni_page = 0; $uni_page <= 255; ++$uni_page)
771 $offset = $uni_data_offsets[$uni_plane][$uni_page];
774 print OUT
" -1, /* plane ",
789 printStats
($uni_data_used[$uni_plane][$uni_page],
790 $uni_data_space[$uni_plane][$uni_page]),
792 $uni_pageoffsets_used[$uni_plane] += 4;
793 $uni_data_used_sum[$uni_plane]
794 += $uni_data_used[$uni_plane][$uni_page];
795 $uni_data_space_sum[$uni_plane]
796 += $uni_data_space[$uni_plane][$uni_page];
802 print OUT
" /* plane ", $uni_plane, ": --- */\n";
807 print OUT
"static sal_Int32 const aImplUnicodeTo",
809 "PlaneOffsets[] = {\n";
810 $uni_page_offset = 0;
811 $uni_planeoffsets_used = 0;
812 $uni_pageoffsets_used_sum = 0;
813 $uni_pageoffsets_space_sum = 0;
814 $uni_data_used_sum2 = 0;
815 $uni_data_space_sum2 = 0;
816 for ($uni_plane = 0; $uni_plane <= 16; ++$uni_plane)
818 if (defined ($uni_plane_used[$uni_plane]))
825 printStats
($uni_pageoffsets_used[$uni_plane], 256 * 4),
827 printStats
($uni_data_used_sum[$uni_plane],
828 $uni_data_space_sum[$uni_plane]),
830 $uni_planeoffsets_used += 4;
831 $uni_pageoffsets_used_sum += $uni_pageoffsets_used[$uni_plane];
832 $uni_pageoffsets_space_sum += 256 * 4;
833 $uni_data_used_sum2 += $uni_data_used_sum[$uni_plane];
834 $uni_data_space_sum2 += $uni_data_space_sum[$uni_plane];
838 print OUT
" -1, /* plane ", $uni_plane, " */\n";
842 printStats
($uni_planeoffsets_used, 17 * 4),
844 printStats
($uni_pageoffsets_used_sum, $uni_pageoffsets_space_sum),
846 printStats
($uni_data_used_sum2, $uni_data_space_sum2),
851 print "Unihan.txt = ", $count_Unihan_txt,
852 ", CNS11643.TXT = ", $count_CNS11643_TXT,
853 ", Uni2CNS = ", $count_Uni2CNS,
855 ($count_Unihan_txt + $count_CNS11643_TXT + $count_Uni2CNS),