TQtSymbolCodec.cxx

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** $Id: TQtSymbolCodec.cxx,v 1.6 2009/07/01 04:27:52 fine Exp $
00003 **
00004 ** Implementation of QTextCodec class
00005 **
00006 ** Created : 20050125
00007 **
00008 **
00009 **********************************************************************/
00010 
00011 #include "TQtSymbolCodec.h"
00012 #include <QByteArray>
00013 
00014 #ifndef QT_NO_CODEC_SYMBOL
00015 
00016 // NOT REVISED
00017 
00018 static const uchar unkn = '?'; // BLACK SQUARE (94) would be better
00019 
00020 static const ushort greek_symbol_to_unicode[64] = {
00021 //
00022 //  upper case letters:
00023 //  ----------------
00024 //   Alpha   Beta     Chi   Delta   Epsilon   Phi    Gamma    Eta
00025     0x0391, 0x0392, 0x03A7, 0x0394, 0x0395, 0x03A6, 0x0393, 0x0397,
00026 //   Iota   Theta(S) Kappa  Lambda    Mu      Nu    Omicron   Pi
00027     0x0399, 0x03D1, 0x039A, 0x039B, 0x039C, 0x039D, 0x039F, 0x03A0,
00028 //  Theta    Rho    Sigma    Tau    Upsilon Stigma   Omega     Xi
00029     0x0398, 0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03DB, 0x03A9, 0x039E,
00030 //   Psi     Zeta   Sigma
00031     0x03A8, 0x0396, 0x03EA, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
00032 //
00033 //  lower case letters:
00034 //  ----------------
00035 //   Alpha   Beta    Chi    Delta   Epsilon   Phi    Gamma    Eta
00036     0x03B1, 0x03B2, 0x03C7, 0x03B4, 0x03B5, 0x03D5, 0x03B3, 0x03B7,
00037 //   Iota   Phi (2) Kappa   Lambda    Mu      Nu    Omicron   Pi
00038     0x03B9, 0x03C6, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BF, 0x03C0,
00039 //  Theta    Rho    Sigma    Tau    Upsilon OmegaPi Omega     Xi
00040     0x03B8, 0x03C1, 0x03C3, 0x03C4, 0x03C5, 0x03D6, 0x03B9, 0x03BE,
00041 //   Psi     Zeta   Sigma
00042     0x03C8, 0x03B6, 0x03EA, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD
00043 };
00044 
00045 static const ushort symbol_to_unicode[96] = {
00046 //
00047 //  upper case letters:
00048 //  ----------------
00049 // UPSILON  NUMBER  LessEq   Div   INFINITY ???????  CLUB   DIAMOND     
00050     0x03D2, 0x0374, 0x2264, 0x2215, 0x221E, 0x0395, 0x2663, 0x2666,
00051 //   HEART  SPADE   <--->   <---             -->             RING
00052     0x2665, 0x2660, 0x2194, 0x2190, 0x2191, 0x2192, 0x2193, 0x2218,
00053 //  Theta    Rho    Great    ????   Propor  diff    bullet   ????
00054     0x0398, 0x03A1, 0x2265, 0x03A4, 0x221D, 0x2202, 0x2219, 0x03A8,
00055 //   NonEq  Ident    ????   ellips   div     minus  ?????   aleph
00056     0x2260, 0x2261, 0xFFFD, 0x22EF, 0x2223, 0x2212, 0xFFFD, 0xFFFD,
00057 //
00058 //  lower case letters:
00059 //  ----------------
00060 //   Alpha   Beta    Chi    Delta   Epsilon   Phi    Gamma    Eta
00061     0x03B1, 0x03B2, 0x03C7, 0x03B4, 0x03B5, 0x03D5, 0x03B3, 0x03B7,
00062 //   Iota   Phi (2) Kappa   Lambda    Mu      Nu    Omicron   Pi
00063     0x03B9, 0x03C6, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BF, 0x03C0,
00064 //  Theta    Rho    Sigma    Tau    Upsilon OmegaPi Omega     Xi
00065     0x03B8, 0x03C1, 0x03C3, 0x03C4, 0x03C5, 0x03D6, 0x03B9, 0x03BE,
00066 //   Psi     Zeta   arrow    Tau    Upsilon  ????   Omega     Xi
00067     0x03C8, 0x03B6, 0x21D4, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD,
00068 //  lower case letters:
00069 //  ----------------
00070 //   Alpha   Beta    Chi    Delta   Sigma     Phi    Gamma    Eta
00071     0x03B1, 0x03B2, 0x03C7, 0x03B4, 0x2211, 0x03D5, 0x03B3, 0x03B7,
00072 //   Iota   Phi (2) Kappa   Lambda    Mu      Nu    Omicron   Pi
00073     0x03B9, 0x03C6, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BF, 0x03C0,
00074 //  Theta   Integr  Sigma    Tau    Upsilon OmegaPi Omega     Xi
00075     0x03B8, 0x222b, 0x03C3, 0x03C4, 0x03C5, 0x03D6, 0x03B9, 0x03BE,
00076 //   Psi     Zeta   Sigma    Tau    Upsilon  ????   Omega     Xi
00077     0x03C8, 0x03B6, 0x03EA, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD, 0xFFFD
00078 };
00079 
00080 
00081 static const uchar unicode_to_symbol_00[32] = {
00082     0xA0, unkn, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
00083     0xA8, 0xA9, 0xD7, 0xAB, 0xAC, 0xAD, 0xAE, unkn,
00084     0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7,
00085     0xB8, 0xB9, 0xF7, 0xBB, 0xBC, 0xBD, 0xBE, unkn,
00086 };
00087 
00088 static const uchar unicode_to_symbol_05[32] = {
00089     0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
00090     0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
00091     0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
00092     0xF8, 0xF9, 0xFA, unkn, unkn, unkn, unkn, unkn
00093 };
00094 
00095 /*!
00096     \class QSymbolCodec qsymbolcodec.h
00097     \reentrant
00098     \ingroup i18n
00099 
00100     \brief The QSymbolCodec class provides conversion to and from
00101     visually ordered Microsoft Symbol.ttf.
00102 
00103 
00104     This codec has the name "symbol". 
00105 */
00106 
00107 //_______________________________________________________________________
00108 /*! \reimp */
00109 int QSymbolCodec::mibEnum() const
00110 {
00111     return 2001;
00112 }
00113 
00114 //_______________________________________________________________________
00115 /*! \reimp */
00116 QByteArray QSymbolCodec::name() const
00117 {
00118     return mimeName(); // "symbol";
00119 }
00120 
00121 //_______________________________________________________________________
00122 /*! \reimp */ 
00123 const char* QSymbolCodec::mimeName() const
00124 {
00125    //   Returns the codec's mime name.
00126   return "symbol";
00127 }
00128 
00129 //_______________________________________________________________________
00130 /*! \reimp */ 
00131 QString QSymbolCodec::toUnicode(const char* chars, int len ) const
00132 {
00133    QString r;
00134    const unsigned char * c = (const unsigned char *)chars;
00135 
00136    if( len == 0 ) return QString::null;
00137 
00138    // Test, if the user gives us a directionality.
00139    // We use 0xFE and 0xFF in ISO8859-8 for that.
00140    // These chars are undefined in the charset, and are mapped to
00141    // RTL overwrite
00142 
00143    for( int i=0; i<len; i++ ) {
00144       if ( 64 < c[i] && c[i] <= 64+32 )
00145          r[i] = greek_symbol_to_unicode[c[i]-65];
00146       else if (64+32+1 <= c[i] && c[i] < 64+32+32+1)
00147          r[i] = greek_symbol_to_unicode[c[i]-65-32]+32;
00148       else if (161 <= c[i] )
00149          r[i] = symbol_to_unicode[c[i]-161];
00150       else
00151          r[i]= c[i];
00152    }
00153    return r;
00154 }
00155 //_______________________________________________________________________
00156 QByteArray QSymbolCodec::fromUnicode(const QString& uc, int& lenInOut) const
00157 {
00158    // process only len chars...
00159    qWarning( "Method <QSymbolCodec::fromUnicode> has not been implemated yet");
00160    int l;
00161    if( lenInOut > 0 )
00162       l = qMin((int)uc.length(),lenInOut);
00163    else
00164       l = (int)uc.length();
00165    QByteArray rstr;
00166 
00167    return rstr;
00168 }
00169 
00170 //_______________________________________________________________________
00171 /*! \reimp */
00172 QByteArray QSymbolCodec::convertFromUnicode( const QChar *input, int number, ConverterState *) const
00173 {  return  fromUnicode(input, number) ;                         }
00174 
00175  //_______________________________________________________________________
00176 /*! \reimp */
00177 QString    QSymbolCodec::convertToUnicode(const char *chars, int len, ConverterState *) const
00178 {  return toUnicode(chars,len);                                                    }
00179 
00180 //_______________________________________________________________________
00181 /*! \reimp */
00182 int QSymbolCodec::heuristicContentMatch(const char* chars, int len) const
00183 {
00184    const unsigned char * c = (const unsigned char *)chars;
00185    int score = 0;
00186    for (int i=0; i<len; i++) {
00187       if( c[i] > 64 && c[i] < 255 ) 
00188          //         if ( symbol_to_unicode[c[i] - 0x80] != 0xFFFD)
00189          score++;
00190       else
00191          return -1;
00192    }
00193    return score;
00194 }
00195 
00196 #endif

Generated on Tue Jul 5 14:14:36 2011 for ROOT_528-00b_version by  doxygen 1.5.1