/*!
  Construct encoding class

 Find out which encodings the iconv on this system supports.
 We try several possible names for each encoding.
 If any name is successfully opened it becomes the only name for this encoding.
 If no name is successfully opened the encoding is removed from the table.
 */
UT_Encoding::UT_Encoding()
{
	if (s_Init) //only do this once
	{
		const XAP_StringSet * pSS = XAP_App::getApp()->getStringSet();
		
		// Test all the encodings in our master table
		// Build a list of only those supported by the current iconv
		UT_uint32 iCheckIndex = 0;
		UT_uint32 iOkayIndex = 0;

		while (iCheckIndex < G_N_ELEMENTS(s_Table))
		{
			const gchar * szName = pSS->getValue(s_Table[iCheckIndex].id);
			const gchar * szEnc;
			UT_uint32 iAltIndex;
			bool bFound = false;

			UT_DEBUGMSG(("Encoding '%s' = ",s_Table[iCheckIndex].encs[0]));
			for (iAltIndex = 0; (szEnc = s_Table[iCheckIndex].encs[iAltIndex]); ++iAltIndex)
			{
				UT_iconv_t iconv_handle = UT_iconv_open(szEnc,szEnc);
				if (UT_iconv_isValid(iconv_handle))
				{
					bFound = true;
					UT_iconv_close(iconv_handle);
					s_Table[iOkayIndex].encs[0] = szEnc;
					s_Table[iOkayIndex].encs[1] = 0;
					s_Table[iOkayIndex].desc = szName;
					s_Table[iOkayIndex].id = s_Table[iCheckIndex].id;
					UT_DEBUGMSG(("'%s' (alias %d)\n",szEnc,iAltIndex+1));
					++iOkayIndex;
					break;
				}
			}
			if (bFound == false)
			{
				UT_DEBUGMSG(("** Not supported **\n"));
			}
			++iCheckIndex;
		}
		s_iCount = iOkayIndex;

		qsort(s_Table, s_iCount, sizeof(enc_entry), s_compareQ);

		s_Init = false;
	}
}
Exemplo n.º 2
0
void ev_Win32Keyboard::remapKeyboard(HKL hKeyboardLayout)
{
    char  szCodePage[16];

    if( m_iconv != UT_ICONV_INVALID )
    {
        UT_iconv_close( m_iconv );
        m_iconv = UT_ICONV_INVALID;
    }
    if( hKeyboardLayout != 0 )
    {
        strcpy( szCodePage, "CP" );
        if( GetLocaleInfo( LOWORD( hKeyboardLayout ),
                           LOCALE_IDEFAULTANSICODEPAGE,
                           &szCodePage[2],
                           sizeof( szCodePage ) / sizeof( szCodePage[0] ) - 2 ))
        {
            // Unicode locale?
            // NT-based systems (at least XP) always produce unicode input irrespective of
            // the ANSI locale -- see WM_CHAR on MSDN and bug 9374
            //
            // (It would be more efficient to do the NT test before calling
            // GetLocaleInfo(), but for maintanence reasons it is better here.)

            if( UT_IsWinNT() || !strcmp( szCodePage, "CP0" ) )
            {
                const char *szUCS2Name
                    = XAP_EncodingManager::get_instance()->getNativeUnicodeEncodingName();

                UT_ASSERT(szUCS2Name);
                m_bIsUnicodeInput = true;
                strcpy( szCodePage, szUCS2Name );
            }
            else
                m_bIsUnicodeInput = false;

            UT_DEBUGMSG(("New keyboard codepage: %s\n",szCodePage));

            m_iconv = UT_iconv_open( "UCS-4-INTERNAL", szCodePage );
        }

        m_hKeyboardLayout = hKeyboardLayout;
    }
}