Esempio n. 1
0
//  73	
//  74	    /*
//  75	     * This method converts the unicode to this font index.
//  76	     * Note: ConversionBufferFullException is not handled
//  77	     *       since this class is only used for character display.
//  78	     */
//  79	    public int convert(char[] input, int inStart, int inEnd,
//  80	                       byte[] output, int outStart, int outEnd)
//  81	        throws MalformedInputException, UnknownCharacterException
//  82	    {
NS_IMETHODIMP nsUnicodeToX11Johab::Convert(
      const PRUnichar * input, PRInt32 * aSrcLength,
      char * output, PRInt32 * aDestLength)
{
//  83	        charOff = inStart;
//  84	        byteOff = outStart;
                charOff = byteOff = 0;
/*  85	*/
/*  86	*/      for (; charOff < *aSrcLength; charOff++)
/*  87	*/      {
/*  88	*/          PRUnichar ch = input[charOff];
/*  89	*/          if (0xac00 <= ch && ch <= 0xd7a3)
/*  90	*/          {
/*  91	*/              if ( state != START )
/*  92	*/                  composeHangul(output);
/*  93	*/              ch -= 0xac00;
/*  94	*/              l = (ch / 588);        // 588 = 21*28
/*  95	*/              v = ( ch / 28 ) % 21  + 1;
/*  96	*/              t = ch % 28;
/*  97	*/              composeHangul(output);
/*  98	*/          } else if (0x1100 <= ch && ch <= 0x115f)
/*  99	*/          {  // leading consonants (19 + 71 + 1)
/* 100	*/              if ( state != START )
/* 101	*/                  composeHangul(output);
/* 102	*/              l = ch - 0x1100;
/* 103	*/              state = LEADING_CONSONANT;
/* 104	*/          } else if (1160 <= ch && ch <= 0x11a2)
/* 105	*/          {  // vowels (1 + 21 + 45)
/* 106	*/              v = ch - 0x1160;
/* 107	*/              state = VOWEL;
/* 108	*/          } else if (0x11a8 <= ch && ch <= 0x11f9)
/* 109	*/          {  // modern trailing consonants (27)
/* 110	*/              t = ch - 0x11a7;
/* 111	*/              composeHangul(output);
// 112	            } else
// 113	            {
// 114	                throw new UnknownCharacterException();
/* 115	*/           }
/* 116	*/       }
/* 117	*/
/* 118	*/       if ( state != START )
/* 119	*/           composeHangul( output );
/* 120	*/
// 121	         return byteOff - outStart;
// 122	     }
                 *aDestLength = byteOff;
                 return NS_OK;
}
NS_IMETHODIMP 
nsUnicodeToJamoTTF::Finish(char* aDest, PRInt32* aDestLength)
{
  mByteOff = 0;
  if (mJamoCount != 0)
    composeHangul(aDest);

  *aDestLength = mByteOff;

  mByteOff = 0;
  mJamoCount = 0;
  return NS_OK;
}
Esempio n. 3
0
// 123	
// 124	    public int flush(byte output[], int i, int j)
// 125	        throws MalformedInputException
// 126	    {
NS_IMETHODIMP nsUnicodeToX11Johab::Finish(
      char * output, PRInt32 * aDestLength)
{
/* 127	*/      byteOff = 0;
/* 128	*/      PRInt32 len = 0;
/* 129	*/      if ( state != START )
/* 130	*/      {
/* 131	*/          composeHangul( output );
/* 132	*/          len = byteOff;
/* 133	*/      }
/* 134	*/      byteOff = charOff = 0;
// 135	        return len;
                *aDestLength = len;
// 136	    }
// 137	
   return NS_OK;
}
Esempio n. 4
0
static int doKCCompose( DWORD * output, int * output_size )
{
    DWORD startCh;
    QWORD qwPair;
    int lastClass;
    int decompPos;
    int startPos = 0;
    int compPos = 1;
    DWORD nComposeResult, nComposeItem;

    startCh = output[0];

    lastClass = lookup_canonical(startCh);

    if ( lastClass != 0 )
    {
        lastClass = 256;
    }

    /* walk across the string */

    for (decompPos=1; decompPos < *output_size; decompPos++)
    {
        int chClass;
        int composite;

        DWORD ch = output[decompPos];

        chClass = lookup_canonical(ch);

        nComposeResult = composeHangul( startCh, ch, &nComposeItem );

        /* if not Hangul, check our lookup table */
        if ( !nComposeResult )
        {
            qwPair = startCh;
            qwPair = qwPair << 32;
            qwPair = qwPair | ch;
            nComposeResult = lookup_composite(qwPair, &nComposeItem);
        }

        if ( !nComposeResult )
        {
            composite = 0xffff; /* 65535 */
        } else
        {
            composite = nComposeItem;
        }

        if (composite != 0xffff && (lastClass < chClass || lastClass == 0))
        {

            output[startPos] = (DWORD)composite;
            startCh = (DWORD)composite;

        } else {

            if (chClass == 0)
            {
                startPos = compPos;
                startCh = ch;
            }

            lastClass = chClass;
            output[compPos++] = ch;
        }
    }

    if (compPos > *output_size)
    {
        return XCODE_NAMEPREP_BUFFER_OVERFLOW_ERROR;
    }

    *output_size = compPos;

    return XCODE_SUCCESS;
}
NS_IMETHODIMP 
nsUnicodeToJamoTTF::Convert(const PRUnichar * aSrc, 
                            PRInt32 * aSrcLength, char * aDest, 
                            PRInt32 * aDestLength)
{
  nsresult rv = NS_OK;
  mByteOff = 0;

  // This should never happen, but it happens under MS Windows, somehow...
  if (mJamoCount > mJamosMaxLength) 
  {
    NS_WARNING("mJamoCount > mJamoMaxLength on entering Convert()");
    Reset();
  }

  for (PRInt32 charOff = 0; charOff < *aSrcLength; charOff++)
  {
    PRUnichar ch = aSrc[charOff];

    // Syllable boundary check. Ref. : Unicode 3.2 section 3.11 
    if (mJamoCount != 0 &&
        gIsBoundary[CHAR_CLASS(mJamos[mJamoCount - 1])][CHAR_CLASS(ch)])
    {
      composeHangul(aDest);
      mJamoCount = 0;
    }
    // Ignore tone marks other than the first in a sequence of tone marks.
    else if (mJamoCount != 0 && IS_TONE(mJamos[mJamoCount - 1]) && IS_TONE(ch))
    {
      --mJamoCount; 
      composeHangul(aDest);
      mJamoCount = 0;

      // skip over tone marks from the second on in a series.
      while (IS_TONE(ch) && ++charOff < *aSrcLength)
        ch = aSrc[charOff]; 

      if (!IS_TONE(ch)) 
      {
        mJamos[mJamoCount++] = ch; 
        continue;
      }
      else
        break;
    }

    if (mJamoCount == mJamosMaxLength)
    {
      mJamosMaxLength++;
      if (mJamos == mJamosStatic)
      {
        mJamos = (PRUnichar *) PR_Malloc(sizeof(PRUnichar) * mJamosMaxLength);
        if (!mJamos)
          return  NS_ERROR_OUT_OF_MEMORY;
        memcpy(mJamos, mJamosStatic, sizeof(PRUnichar) * mJamoCount);
      }
      else
      {
        mJamos = (PRUnichar *) PR_Realloc(mJamos, 
                               sizeof(PRUnichar) * mJamosMaxLength);
        if (!mJamos)
          return  NS_ERROR_OUT_OF_MEMORY;
      }
    }

    mJamos[mJamoCount++] = ch;
  }
    
  if (mJamoCount != 0)
    composeHangul(aDest);
  mJamoCount = 0;
  *aDestLength = mByteOff;

  return rv;
}