curvirgoです。

Yoshiyuki Masutomi wrote:
> 1byte文字列と2byte文字列を分割して変換するようにしてみました。
どうでも良いような変更ですが、直そうと思っていて忘れていた所を一部変更しました。
--- furigana.orig/furigana_impl.cxx	2006-10-05 02:11:44.000000000 +0900
+++ furigana/furigana_impl.cxx	2006-10-06 07:36:20.246266800 +0900
@@ -38,12 +38,12 @@
 #include <mecab.h>
 #endif
 #if defined(WIN) || defined(WNT)
-//#define _WIN32_WINNT
 #include <windows.h>
 #include <imm.h>
 #endif
 #include <string.h>
 #include <stdio.h>
+#define TO_UNICODE(c1,c2) (sal_Unicode)((c2>=0?c2:c2+0x100)*0x100+(c1>=0?c1:c1+0x100)) 
 
 using namespace ::rtl;
 using namespace ::com::sun::star;
@@ -79,6 +79,8 @@
 	    throw (RuntimeException);
 	virtual OUString SAL_CALL getFurigana( OUString const &aStr )
 	    throw (RuntimeException);
+	virtual OUString SAL_CALL getImmFurigana( OUString const &aStr )
+	    throw (RuntimeException);
 	virtual OUString SAL_CALL convertIntoHalfWidth( OUString const &aStr )
 	    throw (RuntimeException);
 	virtual OUString SAL_CALL convertIntoFullWidth( OUString const &aStr )
@@ -182,17 +184,10 @@
 			}
 		}
 	}
-
 	delete tagger;
 #endif
 #if defined(WIN) || defined(WNT)
-	HIMC hIMC;
-	HKL hKL;
-	DWORD aConversionListSize;
-	LPCANDIDATELIST aConversionList;
-
-	hIMC = ImmCreateContext();
-	hKL = GetKeyboardLayout(0);
+	OUStringBuffer aZenkaku, aHankaku;
 
 	for(int i=0;i<aStrList.getLength();i++)
 	{
@@ -200,28 +195,78 @@
 		{
 			if( aStrList[i][j].getLength() != 0 )
 			{
-				OStringBuffer aStr = OStringBuffer(OUStringToOString(aStrList[i][j], RTL_TEXTENCODING_SHIFT_JIS));
-				aStr.append(static_cast< char >(0));
-
-				aConversionListSize = ImmGetConversionList(hKL, hIMC, aStr.getStr(), NULL, 0, GCL_REVERSECONVERSION);
-				aConversionList = (LPCANDIDATELIST)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, aConversionListSize);
-				ImmGetConversionList(hKL, hIMC, aStr.getStr(), aConversionList, aConversionListSize, GCL_REVERSECONVERSION);
-
-				const char *result = (const char *)aConversionList + aConversionList->dwOffset[0];
-				res += OUString(result, strlen(result), RTL_TEXTENCODING_SHIFT_JIS);
-
-				HeapFree(GetProcessHeap(), 0, aConversionList);
+				const sal_Unicode *src = aStrList[i][j];
+				int len = aStrList[i][j].getLength();
+				for(int k=0;k<len;k++)
+				{
+					if( ( src[k] >= 0x0021 && src[k] <= 0x007e ) || ( src[k] >= 0xff66 && src[k] <= 0xff9f ) )
+					{
+						// ascii characters & hankaku katakana
+						aHankaku.append((sal_Unicode)src[k]);
+						if( aZenkaku.getLength() > 0 )
+							res += getImmFurigana( aZenkaku.makeStringAndClear() );
+					}
+					else
+					{
+						aZenkaku.append((sal_Unicode)src[k]);
+						if( aHankaku.getLength() > 0 )
+							res += aHankaku.makeStringAndClear();
+					}
+				}
+				if( aZenkaku.getLength() > 0 )
+					res += getImmFurigana( aZenkaku.makeStringAndClear() );
+				if( aHankaku.getLength() > 0 )
+					res += aHankaku.makeStringAndClear();
 			}
 		}
 	}
+#endif
+	return res;
+    }
+
+    OUString FuriganaImpl::getImmFurigana( OUString const &aStr )
+	throw (RuntimeException)
+    {
+	OUString res;
+	HIMC hIMC;
+	HKL hKL;
+	DWORD aConversionListSize;
+	LPCANDIDATELIST aConversionList;
+	OSVERSIONINFO aOSVersionInfo;
+	OUStringBuffer buf;
 
+	hIMC = ImmCreateContext();
+	hKL = GetKeyboardLayout(0);
+	aOSVersionInfo.dwOSVersionInfoSize = sizeof(aOSVersionInfo);
+	GetVersionEx(&aOSVersionInfo);
+
+	OStringBuffer mStr = OStringBuffer(OUStringToOString(aStr.getStr(), RTL_TEXTENCODING_MS_932));
+	mStr.append(static_cast< char >(0));
+	if(aOSVersionInfo.dwPlatformId < 2)
+	{
+		aConversionListSize = ImmGetConversionListW(hKL, hIMC, (LPCWSTR)mStr.getStr(), NULL, 0, GCL_REVERSECONVERSION);
+		aConversionList = (LPCANDIDATELIST)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, aConversionListSize);
+		ImmGetConversionListW(hKL, hIMC, (LPCWSTR)mStr.getStr(), aConversionList, aConversionListSize, GCL_REVERSECONVERSION);
+		const char *result = (const char *)aConversionList + aConversionList->dwOffset[0];
+		for(unsigned int k=0;k<strlen(result);k+=2)
+			buf.append(TO_UNICODE(result[k],result[k+1]));
+		res += buf.makeStringAndClear();
+	}
+	else
+	{
+		aConversionListSize = ImmGetConversionListA(hKL, hIMC, mStr.getStr(), NULL, 0, GCL_REVERSECONVERSION);
+		aConversionList = (LPCANDIDATELIST)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, aConversionListSize);
+		ImmGetConversionListA(hKL, hIMC, mStr.getStr(), aConversionList, aConversionListSize, GCL_REVERSECONVERSION);
+		const char *result = (const char *)aConversionList + aConversionList->dwOffset[0];
+		res += OUString(result, strlen(result), RTL_TEXTENCODING_MS_932);
+	}
+	HeapFree(GetProcessHeap(), 0, aConversionList);
 	ImmDestroyContext(hIMC);
 
 	res = convertIntoKatakana( res ); // for MS-IME
 	res = convertIntoFullWidth_Impl( res, sal_False ); // for ATOK
-#endif
 
-	return res;
+	return OUString( res.getStr() );
     }
 
     OUString FuriganaImpl::getFurigana( OUString const &aStr )

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

メールによる返信