Qt 4.8
Classes | Macros | Functions | Variables
qbig5codec.cpp File Reference
#include "qbig5codec.h"

Go to the source code of this file.

Classes

struct  B5Index
 
struct  B5Map
 
struct  Summary16
 

Macros

#define InRange(c, lower, upper)   (((c) >= (lower)) && ((c) <= (upper)))
 
#define IsFirstByte(c)   (InRange((c), 0x81, 0xFE))
 
#define IsLatin(c)   ((c) < 0x80)
 
#define IsSecondByte(c)   (IsSecondByteRange1(c) || IsSecondByteRange2(c))
 
#define IsSecondByteRange1(c)   (InRange((c), 0x40, 0x7E))
 
#define IsSecondByteRange2(c)   (InRange((c), 0xA1, 0xFE))
 
#define QValidChar(u)   ((u) ? QChar((ushort)(u)) : QChar(QChar::ReplacementCharacter))
 

Functions

static int qt_Big5hkscsToUnicode (const uchar *s, uint *pwc)
 
static int qt_Big5ToUnicode (const uchar *buf, uint *u)
 
static int qt_UnicodeToBig5 (ushort ch, uchar *buf)
 
static int qt_UnicodeToBig5hkscs (uint wc, uchar *r)
 

Variables

static const B5Map b5_8140_to_uc_map []
 
static const B5Map b5_8E40_to_uc_map []
 
static const B5Map b5_C6A1_to_uc_map []
 
static const B5Map b5_FA40_to_uc_map []
 
static B5Index b5_map_table [5]
 
static const uchar big5hkscs_to_charset [24908][2]
 
static ushort const big5hkscs_to_ucs []
 
static const Summary16 big5hkscs_uni2index_page00 [70]
 
static const Summary16 big5hkscs_uni2index_page1e [13]
 
static const Summary16 big5hkscs_uni2index_page20 [116]
 
static const Summary16 big5hkscs_uni2index_page200 [2335]
 
static const Summary16 big5hkscs_uni2index_page294 [32]
 
static const Summary16 big5hkscs_uni2index_page297 [251]
 
static const Summary16 big5hkscs_uni2index_page2e [1819]
 
static const Summary16 big5hkscs_uni2index_page2f8 [30]
 
static const Summary16 big5hkscs_uni2index_pagee0 [419]
 
static const Summary16 big5hkscs_uni2index_pagefe [31]
 
static const B5Map uc_to_b5_map []
 

Macro Definition Documentation

◆ InRange

#define InRange (   c,
  lower,
  upper 
)    (((c) >= (lower)) && ((c) <= (upper)))

Definition at line 50 of file qbig5codec.cpp.

◆ IsFirstByte

#define IsFirstByte (   c)    (InRange((c), 0x81, 0xFE))

◆ IsLatin

#define IsLatin (   c)    ((c) < 0x80)

◆ IsSecondByte

#define IsSecondByte (   c)    (IsSecondByteRange1(c) || IsSecondByteRange2(c))

◆ IsSecondByteRange1

#define IsSecondByteRange1 (   c)    (InRange((c), 0x40, 0x7E))

Definition at line 53 of file qbig5codec.cpp.

◆ IsSecondByteRange2

#define IsSecondByteRange2 (   c)    (InRange((c), 0xA1, 0xFE))

Definition at line 54 of file qbig5codec.cpp.

◆ QValidChar

#define QValidChar (   u)    ((u) ? QChar((ushort)(u)) : QChar(QChar::ReplacementCharacter))

Function Documentation

◆ qt_Big5hkscsToUnicode()

static int qt_Big5hkscsToUnicode ( const uchar s,
uint pwc 
)
static

Definition at line 4839 of file qbig5codec.cpp.

Referenced by QBig5hkscsCodec::convertToUnicode(), and qt_Big5ToUnicode().

4840 {
4841  uchar c1 = s[0];
4842  if ((c1 >= 0x81 && c1 <= 0xfe)) {
4843  uchar c2 = s[1];
4844  if ((c2 >= 0x40 && c2 < 0x7f) || (c2 >= 0xa1 && c2 < 0xff)) {
4845  uint i = 157 * (c1 - 0x81) + (c2 - (c2 >= 0xa1 ? 0x62 : 0x40));
4846  ushort wc = 0xfffd;
4847  if (i < 19782)
4848  wc = big5hkscs_to_ucs[i];
4849  if (wc != 0xfffd) {
4850  *pwc = (uint) wc;
4851  return 2;
4852  }
4853  }
4854  return 0;
4855  } else if (c1 < 0x80) {
4856  *pwc = (uint) c1;
4857  return 1;
4858  }
4859  return 0;
4860 }
unsigned char uchar
Definition: qglobal.h:994
static ushort const big5hkscs_to_ucs[]
unsigned int uint
Definition: qglobal.h:996
unsigned short ushort
Definition: qglobal.h:995

◆ qt_Big5ToUnicode()

static int qt_Big5ToUnicode ( const uchar buf,
uint u 
)
static

Definition at line 1667 of file qbig5codec.cpp.

Referenced by QBig5Codec::convertToUnicode().

1668 {
1669  //for this conversion only first 4 tables are used.
1670  for(int i = 0; i < 4; i++) {
1671  int start = 0;
1672  int end = b5_map_table[i].tableSize - 1;
1673 
1674  uint b5 = (buf[0] << 8) + buf[1];
1675  while (start <= end) {
1676  int middle = (end + start + 1)/2;
1677  if (b5_map_table[i].table[middle].x == b5) {
1678  *u = b5_map_table[i].table[middle].y;
1679  return 2;
1680  } else if (b5_map_table[i].table[middle].x > b5) {
1681  end = middle - 1;
1682  } else {
1683  start = middle + 1;
1684  }
1685  }
1686  }
1687  return qt_Big5hkscsToUnicode(buf, u);
1688 }
ushort tableSize
Definition: qbig5codec.cpp:77
quint16 u
ushort y
Definition: qbig5codec.cpp:72
unsigned int uint
Definition: qglobal.h:996
const B5Map * table
Definition: qbig5codec.cpp:76
static B5Index b5_map_table[5]
static int qt_Big5hkscsToUnicode(const uchar *s, uint *pwc)
static const KeyPair *const end

◆ qt_UnicodeToBig5()

static int qt_UnicodeToBig5 ( ushort  ch,
uchar buf 
)
static

Definition at line 1690 of file qbig5codec.cpp.

Referenced by QBig5Codec::convertFromUnicode().

1691 {
1692  //all the tables are individually sorted on Y
1693  for(int i = 0; i < 5; i++) {
1694  int start = 0;
1695  int end = b5_map_table[i].tableSize - 1;
1696 
1697  while (start <= end) {
1698  int middle = (end + start + 1)/2;
1699  if (b5_map_table[i].table[middle].y == ch) {
1700  buf[0] = b5_map_table[i].table[middle].x >> 8;
1701  buf[1] = b5_map_table[i].table[middle].x & 0xff;
1702  return 2;
1703  } else if (b5_map_table[i].table[middle].y > ch) {
1704  end = middle - 1;
1705  } else {
1706  start = middle + 1;
1707  }
1708  }
1709  }
1710  return qt_UnicodeToBig5hkscs(ch, buf);
1711 }
ushort tableSize
Definition: qbig5codec.cpp:77
static int qt_UnicodeToBig5hkscs(uint wc, uchar *r)
const B5Map * table
Definition: qbig5codec.cpp:76
ushort x
Definition: qbig5codec.cpp:71
static B5Index b5_map_table[5]
static const KeyPair *const end

◆ qt_UnicodeToBig5hkscs()

int qt_UnicodeToBig5hkscs ( uint  wc,
uchar r 
)
static

Definition at line 12731 of file qbig5codec.cpp.

Referenced by QBig5hkscsCodec::convertFromUnicode(), QFontBig5Codec::convertFromUnicode(), QFontBig5hkscsCodec::convertFromUnicode(), and qt_UnicodeToBig5().

12732 {
12733  const Summary16 *summary = NULL;
12734  if (wc < 0x80) {
12735  r[0] = (uchar) wc;
12736  return 1;
12737  }
12738  if (wc < 0x0460)
12739  summary = &big5hkscs_uni2index_page00[(wc>>4)];
12740  else if (wc >= 0x1e00 && wc < 0x1ed0)
12741  summary = &big5hkscs_uni2index_page1e[(wc>>4)-0x1e0];
12742  else if (wc >= 0x2000 && wc < 0x2740)
12743  summary = &big5hkscs_uni2index_page20[(wc>>4)-0x200];
12744  else if (wc >= 0x2e00 && wc < 0x9fb0)
12745  summary = &big5hkscs_uni2index_page2e[(wc>>4)-0x2e0];
12746  else if (wc >= 0xe000 && wc < 0xfa30)
12747  summary = &big5hkscs_uni2index_pagee0[(wc>>4)-0xe00];
12748  else if (wc >= 0xfe00 && wc < 0xfff0)
12749  summary = &big5hkscs_uni2index_pagefe[(wc>>4)-0xfe0];
12750  else if (wc >= 0x20000 && wc < 0x291f0)
12751  summary = &big5hkscs_uni2index_page200[(wc>>4)-0x2000];
12752  else if (wc >= 0x29400 && wc < 0x29600)
12753  summary = &big5hkscs_uni2index_page294[(wc>>4)-0x2940];
12754  else if (wc >= 0x29700 && wc < 0x2a6b0)
12755  summary = &big5hkscs_uni2index_page297[(wc>>4)-0x2970];
12756  else if (wc >= 0x2f800 && wc < 0x2f9e0)
12757  summary = &big5hkscs_uni2index_page2f8[(wc>>4)-0x2f80];
12758  if (summary) {
12759  ushort used = summary->used;
12760  uint i = wc & 0x0f;
12761  if (used & ((ushort) 1 << i)) {
12762  const uchar *c;
12763  /* Keep in `used' only the bits 0..i-1. */
12764  used &= ((ushort) 1 << i) - 1;
12765  /* Add `summary->index' and the number of bits set in `used'. */
12766  used = (used & 0x5555) + ((used & 0xaaaa) >> 1);
12767  used = (used & 0x3333) + ((used & 0xcccc) >> 2);
12768  used = (used & 0x0f0f) + ((used & 0xf0f0) >> 4);
12769  used = (used & 0x00ff) + (used >> 8);
12770  c = big5hkscs_to_charset[summary->index + used];
12771  if (c [1] != 0) {
12772  r[0] = c[0];
12773  r[1] = c[1];
12774  return 2;
12775  } else { // (c [1] == 0)
12776  r[0] = c[0];
12777  return 1;
12778  }
12779  }
12780  }
12781  return 0;
12782 }
static const Summary16 big5hkscs_uni2index_page2e[1819]
static const Summary16 big5hkscs_uni2index_pagefe[31]
unsigned char c[8]
Definition: qnumeric_p.h:62
static const Summary16 big5hkscs_uni2index_page297[251]
static const Summary16 big5hkscs_uni2index_page294[32]
unsigned char uchar
Definition: qglobal.h:994
static const Summary16 big5hkscs_uni2index_page1e[13]
static const Summary16 big5hkscs_uni2index_page200[2335]
unsigned int uint
Definition: qglobal.h:996
static const Summary16 big5hkscs_uni2index_pagee0[419]
ushort index
ushort used
unsigned short ushort
Definition: qglobal.h:995
static const uchar big5hkscs_to_charset[24908][2]
static const Summary16 big5hkscs_uni2index_page20[116]
static const Summary16 big5hkscs_uni2index_page2f8[30]
static const Summary16 big5hkscs_uni2index_page00[70]

Variable Documentation

◆ b5_8140_to_uc_map

const B5Map b5_8140_to_uc_map[]
static

Definition at line 82 of file qbig5codec.cpp.

◆ b5_8E40_to_uc_map

const B5Map b5_8E40_to_uc_map[]
static

Definition at line 596 of file qbig5codec.cpp.

◆ b5_C6A1_to_uc_map

const B5Map b5_C6A1_to_uc_map[]
static

Definition at line 1345 of file qbig5codec.cpp.

◆ b5_FA40_to_uc_map

const B5Map b5_FA40_to_uc_map[]
static

Definition at line 1451 of file qbig5codec.cpp.

◆ b5_map_table

B5Index b5_map_table[5]
static
Initial value:
= {
{uc_to_b5_map , sizeof(uc_to_b5_map)/sizeof(B5Map)}
}
static const B5Map b5_FA40_to_uc_map[]
static const B5Map b5_C6A1_to_uc_map[]
static const B5Map uc_to_b5_map[]
static const B5Map b5_8140_to_uc_map[]
Definition: qbig5codec.cpp:82
static const B5Map b5_8E40_to_uc_map[]
Definition: qbig5codec.cpp:596

Definition at line 1659 of file qbig5codec.cpp.

◆ big5hkscs_to_charset

const uchar big5hkscs_to_charset[24908][2]
static

Definition at line 4874 of file qbig5codec.cpp.

Referenced by qt_UnicodeToBig5hkscs().

◆ big5hkscs_to_ucs

ushort const big5hkscs_to_ucs[]
static

Definition at line 2062 of file qbig5codec.cpp.

Referenced by qt_Big5hkscsToUnicode().

◆ big5hkscs_uni2index_page00

const Summary16 big5hkscs_uni2index_page00[70]
static
Initial value:
= {
{ 0, 0x0000 }, { 0, 0x0000 }, { 0, 0x0000 }, { 0, 0x0000 },
{ 0, 0x0000 }, { 0, 0x0000 }, { 0, 0x0000 }, { 0, 0x0000 },
{ 0, 0x0000 }, { 0, 0x0000 }, { 0, 0xE7EE }, { 12, 0x87BF },
{ 23, 0xFFFF }, { 39, 0xFFFF }, { 55, 0xFFFF }, { 71, 0xFFFF },
{ 87, 0x0003 }, { 89, 0x0C0C }, { 93, 0x0800 }, { 94, 0x0000 },
{ 94, 0x3800 }, { 97, 0x0008 }, { 98, 0x0800 }, { 99, 0x0000 },
{ 99, 0x0000 }, { 99, 0x0000 }, { 99, 0x0000 }, { 99, 0x0000 },
{ 99, 0x6000 }, { 101, 0x1557 }, { 109, 0x0000 }, { 109, 0x0000 },
{ 109, 0x0000 }, { 109, 0x0000 }, { 109, 0x0000 }, { 109, 0x0000 },
{ 109, 0x0000 }, { 109, 0x0813 }, { 113, 0x0402 }, { 115, 0x0020 },
{ 116, 0x0408 }, { 118, 0x0000 }, { 118, 0x0000 }, { 118, 0x0000 },
{ 118, 0x2EC0 }, { 124, 0x0200 }, { 125, 0x0000 }, { 125, 0x0000 },
{ 125, 0x0020 }, { 126, 0x0000 }, { 126, 0x0000 }, { 126, 0x0000 },
{ 126, 0x0000 }, { 126, 0x0000 }, { 126, 0x0000 }, { 126, 0x0000 },
{ 126, 0x0000 }, { 126, 0xFFFE }, { 141, 0x03FB }, { 150, 0xFFFE },
{ 165, 0x03FB }, { 174, 0x0000 }, { 174, 0x0000 }, { 174, 0x0000 },
{ 174, 0x0002 }, { 175, 0xFFFF }, { 191, 0xFFFF }, { 207, 0xFFFF },
{ 223, 0xFFFF }, { 239, 0x0002 },
}

Definition at line 11105 of file qbig5codec.cpp.

◆ big5hkscs_uni2index_page1e

const Summary16 big5hkscs_uni2index_page1e[13]
static
Initial value:
= {
{ 240, 0x0000 }, { 240, 0x0000 }, { 240, 0x0000 }, { 240, 0x0000 },
{ 240, 0x0000 }, { 240, 0x0000 }, { 240, 0x0000 }, { 240, 0x0000 },
{ 240, 0x0000 }, { 240, 0x0000 }, { 240, 0x0000 }, { 240, 0xC000 },
{ 242, 0x0003 },
}

Definition at line 11130 of file qbig5codec.cpp.

◆ big5hkscs_uni2index_page20

const Summary16 big5hkscs_uni2index_page20[116]
static

Definition at line 11137 of file qbig5codec.cpp.

◆ big5hkscs_uni2index_page200

const Summary16 big5hkscs_uni2index_page200[2335]
static

Definition at line 11893 of file qbig5codec.cpp.

◆ big5hkscs_uni2index_page294

const Summary16 big5hkscs_uni2index_page294[32]
static
Initial value:
= {
{ 24798, 0x0000 }, { 24798, 0x2000 }, { 24799, 0x0001 }, { 24800, 0x8008 },
{ 24802, 0x0100 }, { 24803, 0x0000 }, { 24803, 0x0000 }, { 24803, 0x0000 },
{ 24803, 0x0000 }, { 24803, 0x0000 }, { 24803, 0x0000 }, { 24803, 0x0000 },
{ 24803, 0x0000 }, { 24803, 0x0601 }, { 24806, 0x00A0 }, { 24808, 0x0000 },
{ 24808, 0x0000 }, { 24808, 0x0000 }, { 24808, 0x0000 }, { 24808, 0x0000 },
{ 24808, 0x0000 }, { 24808, 0x0000 }, { 24808, 0x0000 }, { 24808, 0x0000 },
{ 24808, 0x0000 }, { 24808, 0x4000 }, { 24809, 0x0000 }, { 24809, 0x0101 },
{ 24811, 0x0000 }, { 24811, 0x0080 }, { 24812, 0x0200 }, { 24813, 0x0010 },
}

Definition at line 12625 of file qbig5codec.cpp.

◆ big5hkscs_uni2index_page297

const Summary16 big5hkscs_uni2index_page297[251]
static

Definition at line 12637 of file qbig5codec.cpp.

◆ big5hkscs_uni2index_page2e

const Summary16 big5hkscs_uni2index_page2e[1819]
static

Definition at line 11176 of file qbig5codec.cpp.

◆ big5hkscs_uni2index_page2f8

const Summary16 big5hkscs_uni2index_page2f8[30]
static
Initial value:
= {
{ 24897, 0x0000 }, { 24897, 0x0000 }, { 24897, 0x0020 }, { 24898, 0x0800 },
{ 24899, 0x0001 }, { 24900, 0x0000 }, { 24900, 0x0000 }, { 24900, 0x0100 },
{ 24901, 0x0000 }, { 24901, 0x0010 }, { 24902, 0x0040 }, { 24903, 0x0000 },
{ 24903, 0x2000 }, { 24904, 0x0000 }, { 24904, 0x0000 }, { 24904, 0x0000 },
{ 24904, 0x0000 }, { 24904, 0x0000 }, { 24904, 0x0000 }, { 24904, 0x0000 },
{ 24904, 0x0000 }, { 24904, 0x0000 }, { 24904, 0x0000 }, { 24904, 0x0000 },
{ 24904, 0x0000 }, { 24904, 0x0010 }, { 24905, 0x0000 }, { 24905, 0x1004 },
{ 24907, 0x0000 }, { 24907, 0x0010 },
}

Definition at line 12718 of file qbig5codec.cpp.

◆ big5hkscs_uni2index_pagee0

const Summary16 big5hkscs_uni2index_pagee0[419]
static

Definition at line 11747 of file qbig5codec.cpp.

◆ big5hkscs_uni2index_pagefe

const Summary16 big5hkscs_uni2index_pagefe[31]
static
Initial value:
= {
{ 23103, 0x0000 }, { 23103, 0x0000 }, { 23103, 0x0000 }, { 23103, 0xFFFB },
{ 23118, 0xFE1F }, { 23130, 0xFEF7 }, { 23144, 0x0F7F }, { 23155, 0x0000 },
{ 23155, 0x0000 }, { 23155, 0x0000 }, { 23155, 0x0000 }, { 23155, 0x0000 },
{ 23155, 0x0000 }, { 23155, 0x0000 }, { 23155, 0x0000 }, { 23155, 0x0000 },
{ 23155, 0xFFFE }, { 23170, 0xFFFF }, { 23186, 0xFFFF }, { 23202, 0xFFFF },
{ 23218, 0xFFFF }, { 23234, 0x7FFF }, { 23249, 0x0010 }, { 23250, 0x0000 },
{ 23250, 0x0000 }, { 23250, 0x0000 }, { 23250, 0x0000 }, { 23250, 0x0000 },
{ 23250, 0x0000 }, { 23250, 0x0000 }, { 23250, 0x203F },
}

Definition at line 11881 of file qbig5codec.cpp.

◆ uc_to_b5_map

const B5Map uc_to_b5_map[]
static
Initial value:
= {
{0xa2a4,0x2550}, {0xa2a5,0x255e}, {0xa2a7,0x2561}, {0xa2a6,0x256a},
{0xa27e,0x256d}, {0xa2a1,0x256e}, {0xa2a3,0x256f}, {0xa2a2,0x2570}
}

Definition at line 1653 of file qbig5codec.cpp.