Converting bidi utilities to non-XPCOM interfaces. Bug 120818; r=mkaply, nhotta; sr=attinasi

This commit is contained in:
smontagu@netscape.com 2007-06-28 13:02:43 -07:00
parent 69188b92fe
commit 6d642552f6
6 changed files with 3215 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,343 @@
#!/usr/local/bin/perl
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (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.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is IBM
# Corporation. Portions created by IBM are
# Copyright (C) 2000 IBM Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
######################################################################
#
# Initial global variable
#
######################################################################
%gcount = ();
%pat = ();
%map = (
"L" => "1", # Left-to-Right
"R" => "2", # Right-to-Left
"AL" => "3", # Right-to-Left Arabic
"AN" => "4", # Arabic Number
"EN" => "5", # European Number
"ES" => "6", # European Number Separator
"ET" => "7", # European Number Terminator
"CS" => "8", # Common Number Separator
"ON" => "9", # Other Neutrals
"NSM" => "10", # Non-Spacing Mark
"BN" => "11", # Boundary Neutral
"B" => "12", # Paragraph Separator
"S" => "13", # Segment Separator
"WS" => "14", # Whitespace
"LRE" => "15", # Left-to-Right Embedding
"RLE" => "15", # Right-to-Left Embedding
"PDF" => "15", # Pop Directional Format
"LRO" => "15", # Left-to-Right Override
"RLO" => "15" # Right-to-Left Override
);
%special = ();
######################################################################
#
# Open the unicode database file
#
######################################################################
open ( UNICODATA , "< UnicodeData-Latest.txt")
|| die "cannot find UnicodeData-Latest.txt";
######################################################################
#
# Open the output file
#
######################################################################
open ( OUT , "> ../base/src/bidicattable.h")
|| die "cannot open output ../base/src/bidicattable.h file";
######################################################################
#
# Generate license and header
#
######################################################################
$npl = <<END_OF_NPL;
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "MPL"); you may not use this file except in
* compliance with the MPL. You may obtain a copy of the MPL at
* http://www.mozilla.org/MPL/
*
* Software distributed under the MPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the MPL
* for the specific language governing rights and limitations under the
* MPL.
*
* The Initial Developer of the Original Code is IBM
* Corporation. Portions created by IBM are
* Copyright (C) 2000 IBM Corporation. All
* Rights Reserved.
*/
/*
DO NOT EDIT THIS DOCUMENT !!! THIS DOCUMENT IS GENERATED BY
mozilla/intl/unicharutil/tools/genbidicattable.pl
*/
END_OF_NPL
print OUT $npl;
print OUT "\n\n#include \"nscore.h\" \n\n";
%bidicategory = ();
%sh = ();
%sl = ();
%sc = ();
######################################################################
#
# Process the file line by line
#
######################################################################
while(<UNICODATA>) {
chop;
######################################################################
#
# Get value from fields
#
######################################################################
@f = split(/;/ , $_);
$c = $f[0]; # The unicode value
$n = $f[1]; # The unicode name
$g = $f[2]; # The General Category
$b = $f[4]; # The Bidi Category
if(( substr($n, 0, 1) ne "<") || ($n eq "<control>"))
{
#
# print $g;
#
$gcount{$b}++;
$bidicategory{$c} = $b;
} else {
# Handle special block
@pair=split(/, /, $n );
$catnum = $map{$b};
# printf "[%s][%s] => %d\n", $pair[0], $pair[1], $catnum;
if( $pair[1] eq "First>") {
$sl{$pair[0]} = $c;
$sc{$pair[0]} = $catnum;
} elsif ( $pair[1] eq "Last>") {
$sh{$pair[0]} = $c;
if($sc{$pair[0]} ne $catnum)
{
print "WARNING !!!! error in handling special block\n\n";
}
} else {
print "WARNING !!!! error in handling special block\n\n";
}
}
}
# XXX - How can this be made more flexible as new blocks are added to the UCDB?
@range = (
0x0000, 0x07ff,
0x0900, 0x18ff,
0x1e00, 0x28ff,
0x2e80, 0x33ff,
0xa000, 0xa4ff,
0xf900, 0xffff
);
$totaldata = 0;
$tt=($#range+1) / 2;
@patarray = ();
# This should improve performance: put all the patterns like 0x11111111, 0x22222222 etc at the beginning of the table.
# Since there are a lot of blocks with the same category, we should be able to save a lot of time extracting the digits
for (0..15) {
$pattern = "0x".(sprintf("%X", $_) x 8);
$patarray[$_] = $pattern;
$pat{$pattern} = $_;
}
$newidx = 0x10;
for($t = 1; $t <= $tt; $t++)
{
$tl = $range[($t-1) * 2];
$th = $range[($t-1) * 2 + 1];
$ts = ( $th - $tl ) >> 3;
$totaldata += $ts + 1;
printf OUT "static PRUint8 gBidiCatIdx%d[%d] = {\n", $t, $ts + 1;
for($i = ($tl >> 3); $i <= ($th >> 3) ; $i ++ )
{
$data = 0;
for($j = 0; $j < 8 ; $j++)
{
#defaults for unassigned characters -- see table 3.7 in the Unicode Bidi Algorithm
$test = ($i << 3) + $j;
if ((($test >= 0x0590) && ($test <= 0x5FF))
|| (($test >= 0xFB1D) && ($test <= 0xFB4F)))
{
$default = $map{"R"};
} elsif ((($test >= 0x0600) && ($test <= 0x7BF))
|| (($test >= 0xFB50) && ($test <= 0xFDFF))
|| (($test >= 0xFE70) && ($test <= 0xFEFF)))
{
$default = $map{"AL"};
} else
{
$default = $map{"L"};
}
$k = sprintf("%04X", (($i << 3) + $j));
$cat = $bidicategory{$k};
if( $cat eq "")
{
$data = $data + ($default << (4*$j));
} else {
$data = $data + ($map{$cat} << (4*$j));
}
}
$pattern = sprintf("0x%08X", $data);
$idx = $pat{$pattern};
unless( exists($pat{$pattern})){
$idx = $newidx++;
$patarray[$idx] = $pattern;
$pat{$pattern} = $idx;
}
printf OUT " %3d, /* U+%04X - U+%04X : %s */\n" ,
$idx, ($i << 3),((($i +1)<< 3)-1), $pattern ;
}
printf OUT "};\n\n";
if($t ne $tt)
{
$tl = $range[($t-1) * 2 + 1] + 1;
$th = $range[$t * 2] - 1;
for($i = ($tl >> 3); $i <= ($th >> 3) ; $i ++ )
{
$data = 0;
for($j = 0; $j < 8 ; $j++)
{
$k = sprintf("%04X", (($i << 3) + $j));
$cat = $bidicategory{$k};
if( $cat ne "")
{
$data = $data + ($map{$cat} << (4*$j));
}
}
$pattern = sprintf("0x%08X", $data);
if($data ne 0)
{
print "WARNING, Unicode Database now contain characters" .
"which we have not consider, change this program !!!\n\n";
printf "Problem- U+%04X - U+%04X range\n", ($i << 3),((($i +1)<< 3)-1);
}
}
}
}
if($newidx > 255)
{
die "We have more than 255 patterns !!! - $newidx\n\n" .
"This program is now broken!!!\n\n\n";
}
printf OUT "static PRUint32 gBidiCatPat[$newidx] = {\n";
for($i = 0 ; $i < $newidx; $i++)
{
printf OUT " %s, /* $i */\n", $patarray[$i] ;
}
printf OUT "};\n\n";
$totaldata += $newidx * 4;
printf OUT "static eBidiCategory GetBidiCat(PRUnichar u)\n{\n";
printf OUT " PRUint32 pat;\n";
printf OUT " PRUint16 patidx;\n\n";
printf OUT " /* Handle blocks which use index table mapping */ \n\n";
for($t = 1; $t <= $tt; $t++)
{
$tl = $range[($t-1) * 2];
$th = $range[($t-1) * 2 + 1];
if ($tl == 0) {
printf OUT " /* Handle U+%04X to U+%04X */\n", $tl, $th;
printf OUT " if (u<=((PRUnichar)0x%04X)) {\n", $th;
printf OUT " patidx = gBidiCatIdx%d [( u >> 3 )];\n", $t;
} elsif ($th == 0xFFFF) {
printf OUT " /* Handle U+%04X to U+%04X */\n", $tl, $th;
printf OUT " if (((PRUnichar)0x%04X)<=u) {\n", $tl;
printf OUT " patidx = gBidiCatIdx%d [( (u -(PRUnichar) 0x%04X) >> 3 )];\n", $t, $tl;
} else {
printf OUT " /* Handle U+%04X to U+%04X */\n", $tl, $th;
printf OUT " if ((((PRUnichar)0x%04X)<=u)&&(u<=((PRUnichar)0x%04X))) {\n", $tl, $th;
printf OUT " patidx = gBidiCatIdx%d [( (u -(PRUnichar) 0x%04X) >> 3 )];\n", $t, $tl;
}
printf OUT " if (patidx < 0x10)\n";
printf OUT " return (eBidiCategory)patidx;\n";
printf OUT " else {\n";
printf OUT " pat = gBidiCatPat[patidx];\n";
printf OUT " return (eBidiCategory)((pat >> ((u % 8) * 4)) & 0x0F);\n";
printf OUT " }\n";
printf OUT " }\n\n";
}
@special = keys(%sh);
$sp = 0;
foreach $s ( sort(@special) ) {
# don't bother to define the special blocks unless they have a different
# value from the default they would be given if they were undefined
unless ($sc{$s} == $map{"L"}) {
unless ($sp++) {
%by_value = reverse %map;
printf OUT " /* Handle blocks which share the same category */\n\n";
}
printf OUT " /* Handle %s block */\n", substr($s, 1);
printf OUT " if((((PRUnichar)0x%s)<=u)&&(u<=((PRUnichar)0x%s))) \n", $sl{$s}, $sh{$s};
printf OUT " return eBidiCat_$by_value{$sc{$s}}; \n\n";
}
}
printf OUT " return eBidiCat_L; /* UNDEFINE = L */\n};\n";
printf OUT "/* total data size = $totaldata */\n";
print "total = $totaldata\n";
######################################################################
#
# Close files
#
######################################################################
close(UNIDATA);
close(OUT);

View File

@ -0,0 +1,114 @@
#!/usr/local/bin/perl
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (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.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is IBM code.
#
# The Initial Developer of the Original Code is IBM.
# Portions created by IBM are
# Copyright (C) International Business Machines
# Corporation, 2000. All Rights Reserved.
#
# Contributor(s): Simon Montagu
#
# This program generates the header file symmtable.h from the Unicode
# informative data file BidiMirroring.txt.
# See the comments in that file for details of its structure and contents.
#
# At the moment we only handle cases where there is another Unicode
# character whose glyph can serve as at least an adequate version of
# the mirror image of the original character's glyph. This leaves open
# the problem of how to provide mirrored glyphs for characters where
# this is not the case.
# Process the input file
$ucp = "[0-9a-fA-F]{4}"; # Unicode code point (4 successive hex digits) as a pattern to match
open ( UNICODATA , "< BidiMirroring.txt")
|| die "Cannot find BidiMirroring.txt.\
The file should be avaiable here:\
http://www.unicode.org/Public/UNIDATA/BidiMirroring.txt\n";
while (<UNICODATA>) {
chop;
if (/^($ucp); ($ucp) # (.+)/) { # If the line looks like this pattern
# (example: 0028; 0029 # LEFT PARENTHESIS)
@table[hex($1)]=hex($1) ^ hex($2); # Enter the character XOR its symmetric pair in the table
@isblock[hex(substr($1, 0, 2))]=1; # Remember this block
}
}
close(UNICODATA);
# Generate license and header
open ( OUT , "> ../base/src/symmtable.h")
|| die "cannot open output ../base/src/symmtable.h file";
$npl = <<END_OF_NPL;
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is IBM code.
*
* The Initial Developer of the Original Code is IBM.
* Portions created by IBM are
* Copyright (C) International Business Machines
* Corporation, 2000. All Rights Reserved.
*/
/*
DO NOT EDIT THIS DOCUMENT !!! THIS DOCUMENT IS GENERATED BY
mozilla/intl/unicharutil/tools/gensymmtable.pl
*/
END_OF_NPL
print OUT $npl;
# Generate data tables
foreach $block (0 .. 0xff) {
if (@isblock[$block]) {
printf OUT "\n/* Block U%02X__ */\n", $block;
printf OUT "const static PRUint8 symmtable_%02X[256] = {\n", $block;
print OUT "/* ";
foreach $byte (0 .. 0xf) {
printf OUT " _%X ", $byte;
}
print OUT "*/\n";
foreach $row (0 .. 0xf) {
printf OUT "/* %X_ */ ", $row;
foreach $byte (0 .. 0xf) {
$ix = ($block << 8) | ($row << 4) | ($byte);
printf OUT ("%#4x, ", @table[$ix]);
}
print OUT "\n";
}
print OUT "};\n";
}
}
# Generate conversion method
print OUT "\nstatic PRUnichar Mirrored(PRUnichar u)\n{\n";
print OUT " switch (u & 0xFF00) {\n";
print OUT " // XOR the character with the bitmap in the conversion table to give the symmetric equivalent\n";
foreach $block (0 .. 0xff) {
if (1==@isblock[$block]) {
printf OUT " case %#x:\n", $block * 256;
printf OUT " u ^= symmtable_%02X[u & 0xff];\n", $block;
print OUT " break;\n";
}
}
print OUT " }\n return u;\n}\n";
close(OUT);

View File

@ -0,0 +1,462 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* IBM Corporation. Portions created by IBM are
* Copyright (C) 2000 IBM Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Maha Abou El Rous <mahar@eg.ibm.com>
* Lina Kemmel <lkemmel@il.ibm.com>
* Simon Montagu <smontagu@netscape.com>
* Roozbeh Pournader <roozbeh@sharif.edu>
*/
#ifdef IBMBIDI
#include "nsBidiUtils.h"
#define FE_TO_06_OFFSET 0xfe70
static PRUnichar FE_TO_06 [][2] = {
{0x064b,0x0000},{0x064b,0x0640},{0x064c,0x0000},
{0x0000,0x0000},{0x064d,0x0000},{0x0000,0x0000},
{0x064e,0x0000},{0x064e,0x0640},{0x064f,0x0000},
{0x064f,0x0640},{0x0650,0x0000},{0x0650,0x0640},
{0x0651,0x0000},{0x0651,0x0640},{0x0652,0x0000},
{0x0652,0x0640},{0x0621,0x0000},{0x0622,0x0000},
{0x0622,0x0000},{0x0623,0x0000},{0x0623,0x0000},
{0x0624,0x0000},{0x0624,0x0000},{0x0625,0x0000},
{0x0625,0x0000},{0x0626,0x0000},{0x0626,0x0000},
{0x0626,0x0000},{0x0626,0x0000},{0x0627,0x0000},
{0x0627,0x0000},{0x0628,0x0000},{0x0628,0x0000},
{0x0628,0x0000},{0x0628,0x0000},{0x0629,0x0000},
{0x0629,0x0000},{0x062a,0x0000},{0x062a,0x0000},
{0x062a,0x0000},{0x062a,0x0000},{0x062b,0x0000},
{0x062b,0x0000},{0x062b,0x0000},{0x062b,0x0000},
{0x062c,0x0000},{0x062c,0x0000},{0x062c,0x0000},
{0x062c,0x0000},{0x062d,0x0000},{0x062d,0x0000},
{0x062d,0x0000},{0x062d,0x0000},{0x062e,0x0000},
{0x062e,0x0000},{0x062e,0x0000},{0x062e,0x0000},
{0x062f,0x0000},{0x062f,0x0000},{0x0630,0x0000},
{0x0630,0x0000},{0x0631,0x0000},{0x0631,0x0000},
{0x0632,0x0000},{0x0632,0x0000},{0x0633,0x0000},
{0x0633,0x0000},{0x0633,0x0000},{0x0633,0x0000},
{0x0634,0x0000},{0x0634,0x0000},{0x0634,0x0000},
{0x0634,0x0000},{0x0635,0x0000},{0x0635,0x0000},
{0x0635,0x0000},{0x0635,0x0000},{0x0636,0x0000},
{0x0636,0x0000},{0x0636,0x0000},{0x0636,0x0000},
{0x0637,0x0000},{0x0637,0x0000},{0x0637,0x0000},
{0x0637,0x0000},{0x0638,0x0000},{0x0638,0x0000},
{0x0638,0x0000},{0x0638,0x0000},{0x0639,0x0000},
{0x0639,0x0000},{0x0639,0x0000},{0x0639,0x0000},
{0x063a,0x0000},{0x063a,0x0000},{0x063a,0x0000},
{0x063a,0x0000},{0x0641,0x0000},{0x0641,0x0000},
{0x0641,0x0000},{0x0641,0x0000},{0x0642,0x0000},
{0x0642,0x0000},{0x0642,0x0000},{0x0642,0x0000},
{0x0643,0x0000},{0x0643,0x0000},{0x0643,0x0000},
{0x0643,0x0000},{0x0644,0x0000},{0x0644,0x0000},
{0x0644,0x0000},{0x0644,0x0000},{0x0645,0x0000},
{0x0645,0x0000},{0x0645,0x0000},{0x0645,0x0000},
{0x0646,0x0000},{0x0646,0x0000},{0x0646,0x0000},
{0x0646,0x0000},{0x0647,0x0000},{0x0647,0x0000},
{0x0647,0x0000},{0x0647,0x0000},{0x0648,0x0000},
{0x0648,0x0000},{0x0649,0x0000},{0x0649,0x0000},
{0x064a,0x0000},{0x064a,0x0000},{0x064a,0x0000},
{0x064a,0x0000},{0x0644,0x0622},{0x0644,0x0622},
{0x0644,0x0623},{0x0644,0x0623},{0x0644,0x0625},
{0x0644,0x0625},{0x0644,0x0627},{0x0644,0x0627}
};
static PRUnichar FB_TO_06 [] = {
0x0671,0x0671,0x067B,0x067B,0x067B,0x067B,0x067E,0x067E, //FB50-FB57
0x067E,0x067E,0x0680,0x0680,0x0680,0x0680,0x067A,0x067A, //FB58-FB5F
0x067A,0x067A,0x067F,0x067F,0x067F,0x067F,0x0679,0x0679, //FB60-FB67
0x0679,0x0679,0x06A4,0x06A4,0x06A4,0x06A4,0x06A6,0x06A6, //FB68-FB6F
0x06A6,0x06A6,0x0684,0x0684,0x0684,0x0684,0x0683,0x0683, //FB70-FB77
0x0683,0x0683,0x0686,0x0686,0x0686,0x0686,0x0687,0x0687, //FB78-FB7F
0x0687,0x0687,0x068D,0x068D,0x068C,0x068C,0x068E,0x068E, //FB80-FB87
0x0688,0x0688,0x0698,0x0698,0x0691,0x0691,0x06A9,0x06A9, //FB88-FB8F
0x06A9,0x06A9,0x06AF,0x06AF,0x06AF,0x06AF,0x06B3,0x06B3, //FB90-FB97
0x06B3,0x06B3,0x06B1,0x06B1,0x06B1,0x06B1,0x06BA,0x06BA, //FB98-FB9F
0x06BB,0x06BB,0x06BB,0x06BB,0x06C0,0x06C0,0x06C1,0x06C1, //FBA0-FBA7
0x06C1,0x06C1,0x06BE,0x06BE,0x06BE,0x06BE,0x06D2,0x06D2, //FBA8-FBAF
0x06D3,0x06D3,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //FBB0-FBB7
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //FBB8-FBBF
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //FBC0-FBC7
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //FBC8-FBCF
0x0000,0x0000,0x0000,0x06AD,0x06AD,0x06AD,0x06AD,0x06C7, //FBD0-FBD7
0x06C7,0x06C6,0x06C6,0x06C8,0x06C8,0x0677,0x06CB,0x06CB, //FBD8-FBDF
0x06C5,0x06C5,0x06C9,0x06C9,0x06D0,0x06D0,0x06D0,0x06D0, //FBE0-FBE7
0x0649,0x0649,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //FBE8-FBEF
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, //FBF0-FBF7
0x0000,0x0000,0x0000,0x0000,0x06CC,0x06CC,0x06CC,0x06CC //FBF8-FBFF
};
#define PresentationToOriginal(c, order) \
(((0xFE70 <= (c) && (c) <= 0xFEFC)) ? \
FE_TO_06[(c)- FE_TO_06_OFFSET][order] : \
(((0xFB50 <= (c) && (c) <= 0xFBFF) && (order) == 0) ? \
FB_TO_06[(c)-0xFB50] : (PRUnichar) 0x0000))
//============ Begin Arabic Basic to Presentation Form B Code ============
// Note: the following code are moved from gfx/src/windows/nsRenderingContextWin.cpp
static PRUint8 gArabicMap1[] = {
0x81, 0x83, 0x85, 0x87, 0x89, 0x8D, // 0622-0627
0x8F, 0x93, 0x95, 0x99, 0x9D, 0xA1, 0xA5, 0xA9, // 0628-062F
0xAB, 0xAD, 0xAF, 0xB1, 0xB5, 0xB9, 0xBD, 0xC1, // 0630-0637
0xC5, 0xC9, 0xCD // 0638-063A
};
static PRUint8 gArabicMap2[] = {
0xD1, 0xD5, 0xD9, 0xDD, 0xE1, 0xE5, 0xE9, // 0641-0647
0xED, 0xEF, 0xF1 // 0648-064A
};
static PRUint8 gArabicMapEx[] = {
0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0671-0677
0x00, 0x66, 0x5E, 0x52, 0x00, 0x00, 0x56, 0x62, // 0678-067F
0x5A, 0x00, 0x00, 0x76, 0x72, 0x00, 0x7A, 0x7E, // 0680-0687
0x88, 0x00, 0x00, 0x00, 0x84, 0x82, 0x86, 0x00, // 0688-068F
0x00, 0x8C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0690-0697
0x8A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0698-069F
0x00, 0x00, 0x00, 0x00, 0x6A, 0x00, 0x6E, 0x00, // 06A0-06A7
0x00, 0x8E, 0x00, 0x00, 0x00, 0xD3, 0x00, 0x92, // 06A8-06AF
0x00, 0x9A, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, // 06B0-06B7
0x00, 0x00, 0x00, 0xA0, 0x00, 0x00, 0xAA, 0x00, // 06B8-06BF
0xA4, 0xA6, 0x00, 0x00, 0x00, 0xE0, 0xD9, 0xD7, // 06C0-06C7
0xDB, 0xE2, 0x00, 0xDE, 0xFC, 0x00, 0x00, 0x00, // 06C8-06CF
0xE4, 0x00, 0xAE, 0xB0 // 06D0-06D3
};
#define PresentationFormB(c, form) \
(((0x0622<=(c)) && ((c)<=0x063A)) ? \
(0xFE00|(gArabicMap1[(c)-0x0622] + (form))) : \
(((0x0641<=(c)) && ((c)<=0x064A)) ? \
(0xFE00|(gArabicMap2[(c)-0x0641] + (form))) : \
(((0x0671<=(c)) && ((c))<=0x06D3) && gArabicMapEx[(c)-0x0671]) ? \
(0xFB00|(gArabicMapEx[(c)-0x0671] + (form))) : (c)))
enum {
eIsolated, // or Char N
eFinal, // or Char R
eInitial, // or Char L
eMedial // or Char M
} eArabicForm;
enum {
eTr = 0, // Transparent
eRJ = 1, // Right-Joining
eLJ = 2, // Left-Joining
eDJ = 3, // Dual-Joining
eNJ = 4, // Non-Joining
eJC = 7, // Joining Causing
eRightJCMask = 2, // bit of Right-Join Causing
eLeftJCMask = 1 // bit of Left-Join Causing
} eArabicJoiningClass;
#define RightJCClass(j) (eRightJCMask&(j))
#define LeftJCClass(j) (eLeftJCMask&(j))
#define DecideForm(jl,j,jr) \
(((eRJ == (j)) && RightJCClass(jr)) ? eFinal \
: \
((eDJ == (j)) ? \
((RightJCClass(jr)) ? \
(((LeftJCClass(jl)) ? eMedial \
: eFinal)) \
: \
(((LeftJCClass(jl)) ? eInitial \
: eIsolated)) \
) : eIsolated)) \
// All letters without an equivalen in the FB50 block are 'eNJ' here. This
// should be fixed after finding some better mechanism for handling Arabic.
static PRInt8 gJoiningClass[] = {
eNJ, eRJ, eRJ, eRJ, eRJ, eDJ, eRJ, // 0621-0627
eDJ, eRJ, eDJ, eDJ, eDJ, eDJ, eDJ, eRJ, // 0628-062F
eRJ, eRJ, eRJ, eDJ, eDJ, eDJ, eDJ, eDJ, // 0630-0637
eDJ, eDJ, eDJ, eNJ, eNJ, eNJ, eNJ, eNJ, // 0638-063F
eJC, eDJ, eDJ, eDJ, eDJ, eDJ, eDJ, eDJ, // 0640-0647
eRJ, eRJ, eDJ, eTr, eTr, eTr, eTr, eTr, // 0648-064F
eTr, eTr, eTr, eTr, eTr, eTr, eNJ, eNJ, // 0650-0657
eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, // 0658-065F
eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, // 0660-0667
eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, // 0668-066F
eTr, eRJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, // 0670-0677
eNJ, eDJ, eDJ, eDJ, eNJ, eNJ, eDJ, eDJ, // 0678-067F
eDJ, eNJ, eNJ, eDJ, eDJ, eNJ, eDJ, eDJ, // 0680-0687
eRJ, eNJ, eNJ, eNJ, eRJ, eRJ, eRJ, eNJ, // 0688-068F
eNJ, eRJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, // 0690-0697
eRJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, // 0698-069F
eNJ, eNJ, eNJ, eNJ, eDJ, eNJ, eDJ, eNJ, // 06A0-06A7
eNJ, eDJ, eNJ, eNJ, eNJ, eDJ, eNJ, eDJ, // 06A8-06AF
eNJ, eDJ, eNJ, eDJ, eNJ, eNJ, eNJ, eNJ, // 06B0-06B7
eNJ, eNJ, eNJ, eDJ, eNJ, eNJ, eDJ, eNJ, // 06B8-06BF
eRJ, eDJ, eNJ, eNJ, eNJ, eRJ, eRJ, eRJ, // 06C0-06C7
eRJ, eRJ, eNJ, eRJ, eDJ, eNJ, eNJ, eNJ, // 06C8-06CF
eDJ, eNJ, eRJ, eRJ, eNJ, eNJ, eTr, eTr, // 06D0-06D7
eTr, eTr, eTr, eTr, eTr, eTr, eTr, eTr, // 06D8-06DF
eTr, eTr, eTr, eTr, eTr, eNJ, eNJ, eTr, // 06E0-06E7
eTr, eNJ, eTr, eTr, eTr, eTr, eNJ, eNJ, // 06E8-06EF
eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, // 06F0-06F7
eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ, eNJ // 06F8-06FF
};
#define GetJoiningClass(c) \
(((0x0621 <= (c)) && ((c) <= 0x06FF)) ? \
(gJoiningClass[(c) - 0x0621]) : \
((0x200D == (c)) ? eJC : eTr))
static PRUint16 gArabicLigatureMap[] =
{
0x82DF, // 0xFE82 0xFEDF -> 0xFEF5
0x82E0, // 0xFE82 0xFEE0 -> 0xFEF6
0x84DF, // 0xFE84 0xFEDF -> 0xFEF7
0x84E0, // 0xFE84 0xFEE0 -> 0xFEF8
0x88DF, // 0xFE88 0xFEDF -> 0xFEF9
0x88E0, // 0xFE88 0xFEE0 -> 0xFEFA
0x8EDF, // 0xFE8E 0xFEDF -> 0xFEFB
0x8EE0 // 0xFE8E 0xFEE0 -> 0xFEFC
};
nsresult ArabicShaping(const PRUnichar* aString, PRUint32 aLen,
PRUnichar* aBuf, PRUint32 *aBufLen)
{
const PRUnichar* src = aString;
const PRUnichar* p;
PRUnichar* dest = aBuf;
PRUnichar formB;
PRInt8 leftJ, thisJ, rightJ;
PRInt8 leftNoTrJ, rightNoTrJ;
thisJ = eNJ;
rightJ = GetJoiningClass(*(src));
while(src<aString+aLen-1) {
leftJ = thisJ;
if ((eTr != leftJ) || ((leftJ == eTr) &&
( ( (src-1) >= aString ) && !IS_ARABIC_CHAR(*(src-1)))))
leftNoTrJ = thisJ;
if(src-2 >= (aString)){
for(p=src-2; (p >= (aString))&& (eTr == leftNoTrJ) && (IS_ARABIC_CHAR(*(p+1))) ; p--)
leftNoTrJ = GetJoiningClass(*(p)) ;
}
thisJ = rightJ;
rightJ = rightNoTrJ = GetJoiningClass(*(src+1)) ;
if(src+2 <= (aString+aLen-1)){
for(p=src+2; (p <= (aString+aLen-1))&&(eTr == rightNoTrJ) && (IS_ARABIC_CHAR(*(src+1))); p++)
rightNoTrJ = GetJoiningClass(*(p)) ;
}
formB = PresentationFormB(*src, DecideForm(leftNoTrJ, thisJ, rightNoTrJ));
*dest++ = formB;
src++;
}
if((eTr != thisJ) ||
((thisJ == eTr) && (((src-1)>=aString) && (!IS_ARABIC_CHAR(*(src-1))))))
leftNoTrJ = thisJ;
if(src-2 >= (aString)){
for(p=src-2; (src-2 >= (aString)) && (eTr == leftNoTrJ) && (IS_ARABIC_CHAR(*(p+1))); p--)
leftNoTrJ = GetJoiningClass(*(p)) ;
}
formB = PresentationFormB(*src, DecideForm(leftNoTrJ, rightJ, eNJ));
*dest++ = formB;
src++;
PRUnichar *lSrc = aBuf;
PRUnichar *lDest = aBuf;
while(lSrc < (dest-1)) {
PRUnichar next = *(lSrc+1);
if(((0xFEDF == next) || (0xFEE0 == next)) &&
(0xFE80 == (0xFFF1 & *lSrc))) {
PRBool done = PR_FALSE;
PRUint16 key = ((*lSrc) << 8) | ( 0x00FF & next);
PRUint16 i;
for(i=0;i<8;i++) {
if(key == gArabicLigatureMap[i]) {
done = PR_TRUE;
*lDest++ = 0x200B;//ZERO WIDTH SPACE
*lDest++ = 0xFEF5 + i;
lSrc+=2;
break;
}
}
if(! done)
*lDest++ = *lSrc++;
}
else
*lDest++ = *lSrc++;
}
if(lSrc < dest)
*lDest++ = *lSrc++;
*aBufLen = lDest - aBuf;
return NS_OK;
}
nsresult Conv_FE_06(const nsString& aSrc, nsString& aDst)
{
PRUnichar *aSrcUnichars = (PRUnichar *)aSrc.get();
PRUint32 i, size = aSrc.Length();
aDst.Truncate();
for (i=0;i<size;i++) { // i : Source
aSrcUnichars[i];
if (aSrcUnichars[i] == 0x0000)
break; // no need to convert char after the NULL
if (IS_FE_CHAR(aSrcUnichars[i])) {
//ahmed for lamalf
PRUnichar ch = (PresentationToOriginal(aSrcUnichars[i], 1));
if(ch)
aDst += ch;
ch=(PresentationToOriginal(aSrcUnichars[i], 0));
if(ch)
aDst += ch;
else //if it is 00, just output what we have in FExx
aDst += aSrcUnichars[i];
} else {
aDst += aSrcUnichars[i]; // copy it even if it is not in FE range
}
}// for : loop the buffer
return NS_OK;
}
nsresult Conv_FE_06_WithReverse(const nsString& aSrc, nsString& aDst)
{
PRUnichar *aSrcUnichars = (PRUnichar *)aSrc.get();
PRBool foundArabic = PR_FALSE;
PRUint32 i,endArabic, beginArabic, size = aSrc.Length();
aDst.Truncate();
for (endArabic=0;endArabic<size;endArabic++) {
if (aSrcUnichars[endArabic] == 0x0000)
break; // no need to convert char after the NULL
while( (IS_FE_CHAR(aSrcUnichars[endArabic]))||
(IS_ARABIC_CHAR(aSrcUnichars[endArabic]))||
(IS_ARABIC_DIGIT(aSrcUnichars[endArabic]))||
(aSrcUnichars[endArabic]==0x0020))
{
if(! foundArabic ) {
beginArabic=endArabic;
foundArabic= PR_TRUE;
}
endArabic++;
}
if(foundArabic) {
endArabic--;
for (i=endArabic; i>=beginArabic; i--) {
if(IS_FE_CHAR(aSrcUnichars[i])) {
//ahmed for the bug of lamalf
aDst += PresentationToOriginal(aSrcUnichars[i], 0);
if (PresentationToOriginal(aSrcUnichars[i], 1)) {
// Two characters, we have to resize the buffer :(
aDst += PresentationToOriginal(aSrcUnichars[i], 1);
} // if expands to 2 char
} else {
// do we need to check the following if ?
if((IS_ARABIC_CHAR(aSrcUnichars[i]))||
(IS_ARABIC_DIGIT(aSrcUnichars[i]))||
(aSrcUnichars[i]==0x0020))
aDst += aSrcUnichars[i];
}
}
} else {
aDst += aSrcUnichars[endArabic];
}
foundArabic=PR_FALSE;
}// for : loop the buffer
return NS_OK;
}
nsresult Conv_06_FE_WithReverse(const nsString& aSrc,
nsString& aDst,
PRUint32 aDir)
{
PRUnichar *aSrcUnichars = (PRUnichar *)aSrc.get();
PRUint32 i,beginArabic, endArabic, size = aSrc.Length();
aDst.Truncate();
PRBool foundArabic = PR_FALSE;
for (endArabic=0;endArabic<size;endArabic++) {
if (aSrcUnichars[endArabic] == 0x0000)
break; // no need to convert char after the NULL
while( (IS_06_CHAR(aSrcUnichars[endArabic])) ||
(IS_ARABIC_CHAR(aSrcUnichars[endArabic])) ||
(aSrcUnichars[endArabic]==0x0020) ||
(IS_ARABIC_DIGIT(aSrcUnichars[endArabic])) )
{
if(! foundArabic) {
beginArabic=endArabic;
foundArabic=PR_TRUE;
}
endArabic++;
}
if(foundArabic) {
endArabic--;
PRUnichar buf[8192];
PRUint32 len=8192;
//reverse the buffer for shaping
for(i=beginArabic; i<=endArabic; i++) {
buf[i-beginArabic]=aSrcUnichars[endArabic-i+beginArabic];
}
for(i=0; i<=endArabic-beginArabic; i++) {
aSrcUnichars[i+beginArabic]=buf[i];
}
ArabicShaping(&aSrcUnichars[beginArabic], endArabic-beginArabic+1, buf, &len);
// to reverse the numerals
PRUint32 endNumeral, beginNumeral;
for (endNumeral=0;endNumeral<=len-1;endNumeral++){
PRBool foundNumeral = PR_FALSE;
while((endNumeral < len) && (IS_ARABIC_DIGIT(buf[endNumeral])) ) {
if(!foundNumeral)
{
foundNumeral=PR_TRUE;
beginNumeral=endNumeral;
}
endNumeral++;
}
if(foundNumeral){
endNumeral--;
PRUnichar numbuf[20];
for(i=beginNumeral; i<=endNumeral; i++){
numbuf[i-beginNumeral]=buf[endNumeral-i+beginNumeral];
}
for(i=0;i<=endNumeral-beginNumeral;i++){
buf[i+beginNumeral]=numbuf[i];
}
}
}
if(aDir==1){//ltr
for (i=0;i<=len-1;i++){
aDst+= buf[i];
}
}
else if(aDir==2){//rtl
for (i=0;i<=len-1;i++){
aDst+= buf[len-1-i];
}
}
} else {
aDst += aSrcUnichars[endArabic];
}
foundArabic=PR_FALSE;
}// for : loop the buffer
return NS_OK;
}
#endif //IBMBIDI

View File

@ -0,0 +1,200 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* IBM Corporation. Portions created by IBM are
* Copyright (C) 2000 IBM Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Maha Abou El Rous <mahar@eg.ibm.com>
* Lina Kemmel <lkemmel@il.ibm.com>
* Simon Montagu <smontagu@netscape.com>
*
*/
#ifndef nsBidiUtils_h__
#define nsBidiUtils_h__
#include "nsCOMPtr.h"
#include "nsString.h"
/**
* Perform Arabic shaping on a Unichar string
* @param aString is the input string
* @param aLen is the length of aStrong
* @param aBuf receives the shaped output
* @param aBuflen receives the length of aBuf
*/
nsresult ArabicShaping(const PRUnichar* aString, PRUint32 aLen,
PRUnichar* aBuf, PRUint32* aBufLen);
/**
* Scan an nsString, converting characters in the FExx range (Arabic presentation forms) to the equivalent characters in the 06xx
* range
* @param aSrc is the input string
* @param aDst is the output string
*/
nsresult Conv_FE_06(const nsString& aSrc, nsString& aDst);
/**
* Scan an nsString, converting characters in the FExx range (Arabic presentation forms) to the equivalent characters in the 06xx
* range, and also reverse the string
* @param aSrc is the input string
* @param aDst is the output string
*/
nsresult Conv_FE_06_WithReverse(const nsString& aSrc, nsString& aDst);
/**
* Scan an nsString, converting characters in the 06xx range to the equivalent characters in the 0Fxx range (Arabic presentation
* forms), with the option to reverse the string
* @param aSrc is the input string
* @param aDst is the output string
* @param aDir indicates whether the string should be reversed
* IBMBIDI_TEXTDIRECTION_LTR: do not reverse the string
* IBMBIDI_TEXTDIRECTION_RTL: reverse the string
*/
nsresult Conv_06_FE_WithReverse(const nsString& aSrc, nsString& aDst, PRUint32 aDir);
// --------------------------------------------------
// IBMBIDI
// --------------------------------------------------
//
// These values are shared with Preferences dialog
// ------------------
// If Pref values are to be changed
// in the XUL file of Prefs. the values
// Must be changed here too..
// ------------------
//
#define IBMBIDI_TEXTDIRECTION_STR "bidi.direction"
#define IBMBIDI_TEXTTYPE_STR "bidi.texttype"
#define IBMBIDI_CONTROLSTEXTMODE_STR "bidi.controlstextmode"
#define IBMBIDI_CLIPBOARDTEXTMODE_STR "bidi.clipboardtextmode"
#define IBMBIDI_NUMERAL_STR "bidi.numeral"
#define IBMBIDI_SUPPORTMODE_STR "bidi.support"
#define IBMBIDI_CHARSET_STR "bidi.characterset"
#define IBMBIDI_TEXTDIRECTION 1
#define IBMBIDI_TEXTTYPE 2
#define IBMBIDI_CONTROLSTEXTMODE 3
#define IBMBIDI_CLIPBOARDTEXTMODE 4
#define IBMBIDI_NUMERAL 5
#define IBMBIDI_SUPPORTMODE 6
#define IBMBIDI_CHARSET 7
// ------------------
// Text Direction
// ------------------
// bidi.direction
#define IBMBIDI_TEXTDIRECTION_LTR 1 // 1 = directionLTRBidi *
#define IBMBIDI_TEXTDIRECTION_RTL 2 // 2 = directionRTLBidi
// ------------------
// Text Type
// ------------------
// bidi.texttype
#define IBMBIDI_TEXTTYPE_CHARSET 1 // 1 = charsettexttypeBidi *
#define IBMBIDI_TEXTTYPE_LOGICAL 2 // 2 = logicaltexttypeBidi
#define IBMBIDI_TEXTTYPE_VISUAL 3 // 3 = visualtexttypeBidi
// ------------------
// Controls Text Mode
// ------------------
// bidi.controlstextmode
#define IBMBIDI_CONTROLSTEXTMODE_LOGICAL 1 // 1 = logicalcontrolstextmodeBidiCmd *
#define IBMBIDI_CONTROLSTEXTMODE_VISUAL 2 // 2 = visualcontrolstextmodeBidi
#define IBMBIDI_CONTROLSTEXTMODE_CONTAINER 3 // 3 = containercontrolstextmodeBidi
// ------------------
// Clipboard Text Mode
// ------------------
// bidi.clipboardtextmode
#define IBMBIDI_CLIPBOARDTEXTMODE_LOGICAL 1 // 1 = logicalclipboardtextmodeBidi
#define IBMBIDI_CLIPBOARDTEXTMODE_VISUAL 2 // 2 = visualclipboardtextmodeBidi
#define IBMBIDI_CLIPBOARDTEXTMODE_SOURCE 3 // 3 = sourceclipboardtextmodeBidi *
// ------------------
// Numeral Style
// ------------------
// bidi.numeral
#define IBMBIDI_NUMERAL_REGULAR 1 // 1 = regularcontextnumeralBidi *
#define IBMBIDI_NUMERAL_HINDICONTEXT 2 // 2 = hindicontextnumeralBidi
#define IBMBIDI_NUMERAL_ARABIC 3 // 3 = arabicnumeralBidi
#define IBMBIDI_NUMERAL_HINDI 4 // 4 = hindinumeralBidi
// ------------------
// Support Mode
// ------------------
// bidi.support
#define IBMBIDI_SUPPORTMODE_MOZILLA 1 // 1 = mozillaBidisupport *
#define IBMBIDI_SUPPORTMODE_OSBIDI 2 // 2 = OsBidisupport
#define IBMBIDI_SUPPORTMODE_DISABLE 3 // 3 = disableBidisupport
// ------------------
// Charset Mode
// ------------------
// bidi.characterset
#define IBMBIDI_CHARSET_BIDI 1 // 1 = doccharactersetBidi *
#define IBMBIDI_CHARSET_DEFAULT 2 // 2 = defaultcharactersetBidi
#define IBMBIDI_DEFAULT_BIDI_OPTIONS \
((IBMBIDI_TEXTDIRECTION_LTR<<0) | \
(IBMBIDI_TEXTTYPE_CHARSET<<4) | \
(IBMBIDI_CONTROLSTEXTMODE_LOGICAL<<8) | \
(IBMBIDI_CLIPBOARDTEXTMODE_SOURCE<<12) | \
(IBMBIDI_NUMERAL_REGULAR<<16) | \
(IBMBIDI_SUPPORTMODE_MOZILLA<<20) | \
(IBMBIDI_CHARSET_BIDI<<24))
#define GET_BIDI_OPTION_DIRECTION(bo) (((bo)>>0) & 0x0000000F) /* 4 bits for DIRECTION */
#define GET_BIDI_OPTION_TEXTTYPE(bo) (((bo)>>4) & 0x0000000F) /* 4 bits for TEXTTYPE */
#define GET_BIDI_OPTION_CONTROLSTEXTMODE(bo) (((bo)>>8) & 0x0000000F) /* 4 bits for CONTROLTEXTMODE */
#define GET_BIDI_OPTION_CLIPBOARDTEXTMODE(bo) (((bo)>>12) & 0x0000000F) /* 4 bits for CLIPBOARDTEXTMODE */
#define GET_BIDI_OPTION_NUMERAL(bo) (((bo)>>16) & 0x0000000F) /* 4 bits for NUMERAL */
#define GET_BIDI_OPTION_SUPPORT(bo) (((bo)>>20) & 0x0000000F) /* 4 bits for SUPPORT */
#define GET_BIDI_OPTION_CHARACTERSET(bo) (((bo)>>24) & 0x0000000F) /* 4 bits for CHARACTERSET */
#define SET_BIDI_OPTION_DIRECTION(bo, dir) {(bo)=((bo) & 0xFFFFFFF0)|(((dir)& 0x0000000F)<<0);}
#define SET_BIDI_OPTION_TEXTTYPE(bo, tt) {(bo)=((bo) & 0xFFFFFF0F)|(((tt)& 0x0000000F)<<4);}
#define SET_BIDI_OPTION_CONTROLSTEXTMODE(bo, cotm) {(bo)=((bo) & 0xFFFFF0FF)|(((cotm)& 0x0000000F)<<8);}
#define SET_BIDI_OPTION_CLIPBOARDTEXTMODE(bo, cltm) {(bo)=((bo) & 0xFFFF0FFF)|(((cltm)& 0x0000000F)<<12);}
#define SET_BIDI_OPTION_NUMERAL(bo, num) {(bo)=((bo) & 0xFFF0FFFF)|(((num)& 0x0000000F)<<16);}
#define SET_BIDI_OPTION_SUPPORT(bo, sup) {(bo)=((bo) & 0xFF0FFFFF)|(((sup)& 0x0000000F)<<20);}
#define SET_BIDI_OPTION_CHARACTERSET(bo, cs) {(bo)=((bo) & 0xF0FFFFFF)|(((cs)& 0x0000000F)<<24);}
/* Constants related to the position of numerics in the codepage */
#define START_HINDI_DIGITS 0x0660
#define END_HINDI_DIGITS 0x0669
#define START_ARABIC_DIGITS 0x0030
#define END_ARABIC_DIGITS 0x0039
#define START_FARSI_DIGITS 0x06f0
#define END_FARSI_DIGITS 0x06f9
#define IS_HINDI_DIGIT(u) ( ( (u) >= START_HINDI_DIGITS ) && ( (u) <= END_HINDI_DIGITS ) )
#define IS_ARABIC_DIGIT(u) ( ( (u) >= START_ARABIC_DIGITS ) && ( (u) <= END_ARABIC_DIGITS ) )
#define IS_FARSI_DIGIT(u) ( ( (u) >= START_FARSI_DIGITS ) && ( (u) <= END_FARSI_DIGITS ) )
#define IS_BIDI_DIACRITIC(u) ( \
( (u) >= 0x0591 && (u) <= 0x05A1) || ( (u) >= 0x05A3 && (u) <= 0x05B9) \
|| ( (u) >= 0x05BB && (u) <= 0x05BD) || ( (u) == 0x05BF) || ( (u) == 0x05C1) \
|| ( (u) == 0x05C2) || ( (u) == 0x05C4) \
|| ( (u) >= 0x064B && (u) <= 0x0652) || ( (u) == 0x0670) \
|| ( (u) >= 0x06D7 && (u) <= 0x06E4) || ( (u) == 0x06E7) || ( (u) == 0x06E8) \
|| ( (u) >= 0x06EA && (u) <= 0x06ED) )
#define IS_HEBREW_CHAR(c) (((0x0590 <= (c)) && ((c)<= 0x05FF)) || (((c) >= 0xfb1d) && ((c) <= 0xfb4f)))
#define IS_06_CHAR(c) ((0x0600 <= (c)) && ((c)<= 0x06FF))
#define IS_FE_CHAR(c) (((0xfb50 <= (c)) && ((c)<= 0xfbFF)) \
|| ((0xfe70 <= (c)) && ((c)<= 0xfeFC)))
#define IS_ARABIC_CHAR(c) ((0x0600 <= (c)) && ((c)<= 0x06FF))
#define IS_ARABIC_ALPHABETIC(c) (IS_ARABIC_CHAR(c) && !(IS_HINDI_DIGIT(c) || IS_FARSI_DIGIT(c)))
#define CHAR_IS_BIDI(c) ( (IS_HINDI_DIGIT(c) ) || (IS_HEBREW_CHAR(c) ) \
|| (IS_06_CHAR(c) ) || (IS_FE_CHAR(c) ) )
#endif /* nsBidiUtils_h__ */

View File

@ -0,0 +1,151 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is IBM code.
*
* The Initial Developer of the Original Code is IBM.
* Portions created by IBM are
* Copyright (C) International Business Machines
* Corporation, 2000. All Rights Reserved.
*/
/*
DO NOT EDIT THIS DOCUMENT !!! THIS DOCUMENT IS GENERATED BY
mozilla/intl/unicharutil/tools/gensymmtable.pl
*/
/* Block U00__ */
const static PRUint8 symmtable_00[256] = {
/* _0 _1 _2 _3 _4 _5 _6 _7 _8 _9 _A _B _C _D _E _F */
/* 0_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 1_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 2_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0x1, 0x1, 0, 0, 0, 0, 0, 0,
/* 3_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2, 0, 0x2, 0,
/* 4_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 5_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x6, 0, 0x6, 0, 0,
/* 6_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 7_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x6, 0, 0x6, 0, 0,
/* 8_ */ 0, 0, 0, 0, 0, 0,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 0, 0, 0, 0, 0, 0, 0, 0,
/* 7_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 8_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 9_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* A_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* B_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* C_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* D_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* E_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* F_ */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
static PRUnichar Mirrored(PRUnichar u)
{
switch (u & 0xFF00) {
// XOR the character with the bitmap in the conversion table to give the symmetric equivalent
case 0:
u ^= symmtable_00[u & 0xff];
break;
case 0x2000:
u ^= symmtable_20[u & 0xff];
break;
case 0x2200:
u ^= symmtable_22[u & 0xff];
break;
case 0x2300:
u ^= symmtable_23[u & 0xff];
break;
case 0x3000:
u ^= symmtable_30[u & 0xff];
break;
}
return u;
}