📄 qunicodetables.cpp
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS. All rights reserved.**** This file is part of the Qtopia Environment.** ** This program is free software; you can redistribute it and/or modify it** under the terms of the GNU General Public License as published by the** Free Software Foundation; either version 2 of the License, or (at your** option) any later version.** ** A copy of the GNU GPL license version 2 is included in this package as ** LICENSE.GPL.**** This program is distributed in the hope that it will be useful, but** WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ** See the GNU General Public License for more details.**** In addition, as a special exception Trolltech gives permission to link** the code of this program with Qtopia applications copyrighted, developed** and distributed by Trolltech under the terms of the Qtopia Personal Use** License Agreement. You must comply with the GNU General Public License** in all respects for all of the code used other than the applications** licensed under the Qtopia Personal Use License Agreement. If you modify** this file, you may extend this exception to your version of the file,** but you are not obligated to do so. If you do not wish to do so, delete** this exception statement from your version.** ** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "qunicodetables_p.h"/* ------------------------------------------------------------------------- * unicode information * these tables are generated from the unicode reference file * ftp://ftp.unicode.org/Public/3.2-Update/UnicodeData.txt * * Lars * ------------------------------------------------------------------------- *//* Perl script to generate (run perl -x tools/qstringdata.cpp)#!perlsub numberize{ my(%r, $n, $id); for $id ( @_ ) { $i = $id; $i="" if $i eq "EMPTY"; $r{$i}=$n++; } return %r;}sub readUnicodeDataLine { $code = shift @_; for $n (qw{ name category combining_class bidi_category character_decomposition decimal_digit_value digit_value numeric_value mirrored oldname comment uppercase lowercase titlecase}) { $id = shift @_; $codes = "${n}_code"; if ( defined %$codes && defined $$codes{$id} ) { $id = $$codes{$id}; } ${$n}{$code}=$id; } $decomp = $character_decomposition{$code}; if ( length $decomp == 0 ) { $decomp = "<single>"; } if (substr($decomp, 0, 1) ne '<') { $decomp = "<canonical> " . $decomp; } @_ = split(" ", $decomp); $tag = shift @_; $tag = $character_decomposition_tag{$tag}; $decomp = join( ", 0x", @_ ); $decomp = "0x".$decomp; $decomposition{$code} = $decomp; $decomposition_tag{$code} = $tag; $decomposition_pos{$code} = $position; $len = scalar(@_); $decomposition_len{$code} = $len;# we use canonical decompositions longer than 1 char# we exlude Arabic ligatures from the table if($len > 1 and $tag == 1) {# ligature to add... $start = shift @_; $ligature{$start} = $ligature{$start}." ".$code; }# adjust position if($len != 0) { $position += $len + 3; }}# Code to integer mappings...#%category_code = numberize(qw{ EMPTY Mn Mc Me Nd Nl No Zs Zl Zp Cc Cf Cs Co Cn Lu Ll Lt Lm Lo Pc Pd Ps Pe Pi Pf Po Sm Sc Sk So});%bidi_category_code = numberize(qw{ L R EN ES ET AN CS B S WS ON LRE LRO AL RLE RLO PDF NSM BN});%character_decomposition_tag = numberize(qw{ <single> <canonical> <font> <noBreak> <initial> <medial> <final> <isolated> <circle> <super> <sub> <vertical> <wide> <narrow> <small> <square> <compat> <fraction>});%mirrored_code = numberize(qw{N Y});%joining_code = numberize(qw{U D R C});# we map AI and XX to AL for now, as we can't handle them any better%line_break_code = numberize(qw{OP CL QU GL NS EX SY IS PR PO NU AL ID IN HY BA BB B2 ZW CM SA BK CR LF SG CB SP});# Read data into hashes...#open IN, "UnicodeData.txt";$position = 1;while (<IN>) { @fields = split /;/; if ( length($fields[0]) < 5 ) { if ( $fields[1] =~ /, First>/ ) { $codeRangeBegin = $fields[0]; } elsif ( $fields[1] =~ /, Last>/ ) { for ( $i=hex($codeRangeBegin); $i<=hex($fields[0]); $i+=1 ) { @fields2 = @fields; $fields2[0] = sprintf "%lX", $i; readUnicodeDataLine @fields2; } } else { readUnicodeDataLine @fields; } }}open IN2, "ArabicShaping.txt";$position = 1;while (<IN2>) { @fields = split /;/; $code = shift @fields; $dummy = shift @fields; $join = shift @fields; $join =~ s/ //g; $join = $joining_code{$join}; $joining{$code}=$join;}open IN3, "LineBreak.txt";$position = 1;while (<IN3>) { @fields = split /;/; $code = shift @fields; $break = shift @fields; if (length($break) > 0) { chomp $break; $break =~ s/ .*$//; $from = $code; $to = $code; if ( length($code) > 5 ) { $from =~ s,\.\..*,,; $to =~ s/......//;# print "$from..$to = $break\n"; } if($break eq "AI") { $break = "AL"; } if($break eq "XX") { $break = "AL"; } for ( $i=hex($from); $i<=hex($to); $i+=1 ) { $breaks{sprintf("%04X",$i)}=$line_break_code{$break}; } }}# Build pages...#$rowtable_txt = "";$row_txt = "";$pos = 1;for $row ( 0..255 ) { $nonzero=0; $txt = ""; for $cell ( 0..255 ) { $code = sprintf("%02X%02X",$row,$cell); $info = $category{$code}; $info = 0 if !defined $info; $txt .= "\n " if $cell%8 == 0; $txt .= "$info, "; } $therow = $row{$txt}; if ( !defined $therow ) { $therow = sprintf("%d",$pos); $row_txt = $row_txt."$txt\n"; $row{$txt}=$therow; $pos += 1; $size += 256; } $rowtable_txt .= "\n " if $row%8 == 0; $rowtable_txt .= "$therow, ";}print "// START OF GENERATED DATA\n\n";print "#ifndef QT_NO_UNICODETABLES\n\n";# Print pages...#print "const Q_UINT8 QUnicodeTables::unicode_info[] = {";print $rowtable_txt;$size += 256;print "\n\n";print $row_txt;print "};\n\n";print "// $size bytes\n\n";# Build decomposition tables#$rowtable_txt = "";$row_txt = "";$table_txt = "const Q_UINT16 QUnicodeTables::decomposition_map[] = {\n 0,\n";$pos = 1;for $row ( 0..255 ) { $nonzero=0; $txt = ""; for $cell ( 0..255 ) { $code = sprintf("%02X%02X",$row,$cell); $txt .= "\n " if $cell%8 == 0; if( $decomposition_tag{$code} != 0 ) { $txt .= " $decomposition_pos{$code},"; $table_txt .= " $decomposition_tag{$code},"; $table_txt .= " 0x$code,"; $table_txt .= " $decomposition{$code}, 0,\n"; $size += 2 * $decomposition_len{$code} + 6; } else { $txt .= " 0,"; } } $therow = $row{$txt}; if ( !defined $therow ) { $therow = sprintf("%d",$pos); $row_txt = $row_txt."$txt\n"; $row{$txt}=$therow; $pos += 1; $size += 512; } $rowtable_txt .= "\n " if $row%8 == 0; $rowtable_txt .= "$therow, ";}# Print decomposition tables#print "$table_txt\n};\n\n";print "const Q_UINT16 QUnicodeTables::decomposition_info[] = {";print "$rowtable_txt\n";$size += 512;print $row_txt;print "};\n\n";print "// $size bytes\n\n";# build ligature tables#$size = 0;$position = 1;$pos = 1;$rowtable_txt = "";$row_txt = "";$table_txt = "const Q_UINT16 QUnicodeTables::ligature_map[] = {\n 0,\n";for $lig_row ( 0..255 ) { $nonzero=0; $txt = ""; for $cell ( 0..255 ) { $code = sprintf("%02X%02X",$lig_row,$cell); $txt .= "\n " if $cell%8 == 0; if( defined $ligature{$code} ) { $txt .= " $position,"; @ligature = split(" ", $ligature{$code});# we need to sort ligatures according to their length.# long ones have to come first! @ligature_sort = sort { $decomposition_len{$b} <=> $decomposition_len{$a} } @ligature;# now replace each code by its position in# the decomposition map. undef(@lig_pos); for $n (@ligature_sort) { push(@lig_pos, $decomposition_pos{$n}); }# debug info if( 0 ) { print "ligatures: $ligature{$code}\n"; $sort = join(" ", @ligature_sort); print "sorted : $sort\n"; } $lig = join(", ", @lig_pos); $table_txt .= " $lig, 0,\n"; $size += 2 * scalar(@ligature) + 2; $position += scalar(@ligature) + 1; } else { $txt .= " 0,"; } } $therow = $lig_row{$txt}; if ( !defined $therow ) { $therow = sprintf("%d",$pos); $row_txt = $row_txt."$txt\n"; $lig_row{$txt}=$therow; $pos += 1; $size += 512; } $rowtable_txt .= "\n " if $lig_row%8 == 0; $rowtable_txt .= "$therow, ";}# Print ligature tables#print "$table_txt\n};\n\n";print "const Q_UINT16 QUnicodeTables::ligature_info[] = {";print "$rowtable_txt\n\n";$size+=512;print $row_txt;print "};\n\n";print "// $size bytes\n\n";# Build direction/joining/mirrored pages...#$rowtable_txt = "";$row_txt = "";$pos = 1;for $dir_row ( 0..255 ) { $txt = ""; for $cell ( 0..255 ) { $code = sprintf("%02X%02X",$dir_row,$cell); $dir = $bidi_category{$code}; $dir = 0 if !defined $dir; $join = $joining{$code}; $join = 0 if !defined $join; $mirr = $mirrored{$code}; $mirr = 0 if !defined $mirr; $info = $dir + 32*$join + 128*$mirr; $txt .= "\n " if $cell%8 == 0; $txt .= "$info, "; } $therow = $dir_row{$txt}; if ( !defined $therow ) { $therow = sprintf("%d",$pos); $row_txt = $row_txt."$txt\n"; $dir_row{$txt}=$therow; $pos += 1; $size+=256; } $rowtable_txt .= "\n " if $dir_row%8 == 0; $rowtable_txt .= "$therow, ";}# Print pages...#print "const Q_UINT8 QUnicodeTables::direction_info[] = {";print "$rowtable_txt\n\n";$size+=256;print $row_txt;print "};\n\n";print "// $size bytes\n\n";# Build table of combining classes#$rowtable_txt = "";$row_txt = "";$pos = 1;for $combining_row ( 0..255 ) { $txt = ""; for $cell ( 0..255 ) { $code = sprintf("%02X%02X",$combining_row,$cell); $info = $combining_class{$code}; $info = 0 if !defined $info; $txt .= "\n " if $cell%8 == 0; $txt .= "$info, "; } $therow = $combining_row{$txt}; if ( !defined $therow ) { $therow = sprintf("%d",$pos); $row_txt = $row_txt."$txt\n"; $combining_row{$txt}=$therow; $pos += 1; $size += 256; } $rowtable_txt .= "\n " if $combining_row%8 == 0; $rowtable_txt .= "$therow, ";}# Print pages...#print "const Q_UINT8 QUnicodeTables::combining_info[] = {";print "$rowtable_txt\n\n";$size+=256;print $row_txt;print "};\n\n";print "// $size bytes\n\n";# Build case info
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -