curvirgoです。
どこにぶら下げるか悩んだのでここにします。
[EMAIL PROTECTED]
Windows版MeCabをインストールし、インストール先のbinディレクトリをコマンドサーチパス(環境変数PATH)に加えてから、
make -f Makefile.win32
を実行することによってMeCab版をビルドし、
make -f Makefile.win32 imm
を実行することによりimm版(IMEの逆変換機能を用いた物)をビルドするようになっています。
あまりきれいではないのが難点ですが...
とりあえず、Windows版としてはこの辺で0.3としても良いのかなと思っています。
0.3ではimm版とMeCab版が提供できます。
ただ、imm版とMeCab版では振り仮名変換の結果が違ってしまいますが、これはしょうがないでしょう。
ということでわかるとは思いますが、いまのコードでWindowsのMeCab版は動作するのを確認しました。
--- furigana.orig/furigana_impl.cxx 2006-10-05 02:11:44.000000000 +0900
+++ furigana/furigana_impl.cxx 2006-10-06 21:21:22.109375000 +0900
@@ -34,14 +34,17 @@
#include <com/sun/star/beans/PropertyValue.hpp>
#include <jp/sourceforge/waooo/addin/XFurigana.hpp>
-#if defined(UNX)
-#include <mecab.h>
-#endif
#if defined(WIN) || defined(WNT)
-//#define _WIN32_WINNT
#include <windows.h>
+#endif
+
+#if defined(__USE_IMM__)
#include <imm.h>
+#define TO_UNICODE(c1,c2) (sal_Unicode)((c2>=0?c2:c2+0x100)*0x100+(c1>=0?c1:c1+0x100))
+#else
+#include <mecab.h>
#endif
+
#include <string.h>
#include <stdio.h>
@@ -79,6 +82,10 @@
throw (RuntimeException);
virtual OUString SAL_CALL getFurigana( OUString const &aStr )
throw (RuntimeException);
+#if defined(__USE_IMM__)
+ virtual OUString SAL_CALL getImmFurigana( OUString const &aStr )
+ throw (RuntimeException);
+#endif
virtual OUString SAL_CALL convertIntoHalfWidth( OUString const &aStr )
throw (RuntimeException);
virtual OUString SAL_CALL convertIntoFullWidth( OUString const &aStr )
@@ -158,12 +165,51 @@
{
sal_Unicode developers_name[] =
{0x30ca, 0x30ab, 0x30e2, 0x30c8, 0x30bf, 0x30ab, 0x30b7,
- 0xff06, 0x30de, 0x30b9, 0x30c8, 0x30df, 0x30e8, 0x30b7,
- 0x30e6, 0x30ad, 0x0000};
+ 0x0028, 0x0020, 0x0042, 0x0061, 0x0073, 0x0065, 0x0020,
+ 0x0026, 0x0020, 0x0066, 0x006F, 0x0072, 0x004C, 0x0069,
+ 0x006E, 0x0075, 0x0078, 0x0029, 0x0020, 0x0026, 0x0020,
+ 0x30de, 0x30b9, 0x30c8, 0x30df, 0x30e8, 0x30b7, 0x30e6,
+ 0x30ad, 0x0028, 0x0066, 0x006F, 0x0072, 0x0020, 0x0057,
+ 0x0069, 0x006E, 0x0064, 0x006F, 0x0077, 0x0073, 0x0029,
+ 0x0000};
return OUString(developers_name);
}
-#if defined(UNX)
+#if defined(__USE_IMM__)
+ OUStringBuffer aZenkaku, aHankaku;
+
+ for(int i=0;i<aStrList.getLength();i++)
+ {
+ for(int j=0;j<aStrList[i].getLength();j++)
+ {
+ if( aStrList[i][j].getLength() != 0 )
+ {
+ const sal_Unicode *src = aStrList[i][j];
+ int len = aStrList[i][j].getLength();
+ for(int k=0;k<len;k++)
+ {
+ if( ( src[k] >= 0x0020 && src[k] <= 0x007e ) || ( src[k] >= 0xff66 && src[k] <= 0xff9f ) || src[k] == 0x3000 )
+ {
+ // ascii characters & hankaku katakana & zenkaku space
+ 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();
+ }
+ }
+ }
+#else
// mecab
MeCab::Tagger *tagger = MeCab::createTagger("-Oyomi");
@@ -173,56 +219,74 @@
{
if( aStrList[i][j].getLength() != 0 )
{
+#if defined(WIN) || defined(WNT)
+ OStringBuffer aStr = OStringBuffer(OUStringToOString(aStrList[i][j], RTL_TEXTENCODING_MS_932));
+#else
OStringBuffer aStr = OStringBuffer(OUStringToOString(aStrList[i][j], RTL_TEXTENCODING_EUC_JP));
+#endif
aStr.append(static_cast< char >(0));
const char *result = tagger->parse(aStr.getStr());
// "strlen(result)-1" trims '\n' at the tail end
+#if defined(WIN) || defined(WNT)
+ res += OUString(result, strlen(result)-1, RTL_TEXTENCODING_MS_932);
+#else
res += OUString(result, strlen(result)-1, RTL_TEXTENCODING_EUC_JP);
+#endif
}
}
}
-
delete tagger;
#endif
-#if defined(WIN) || defined(WNT)
+ return res;
+ }
+
+#if defined(__USE_IMM__)
+ 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);
- for(int i=0;i<aStrList.getLength();i++)
+ 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
{
- for(int j=0;j<aStrList[i].getLength();j++)
- {
- 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);
- }
- }
+ 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() );
}
+#endif
OUString FuriganaImpl::getFurigana( OUString const &aStr )
throw (RuntimeException)
--- furigana.orig/Makefile.win32 2006-10-01 00:53:27.000000000 +0900
+++ furigana/Makefile.win32 2006-10-06 23:18:40.781250000 +0900
@@ -14,11 +14,14 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+VERSION=0.3
+
# base directories
#OO_SDK_HOME=
#OFFICE_PROGRAM_PATH=
PLATFORM=windows
SDKBINDIR=$(OO_SDK_HOME)/$(PLATFORM)/bin
+MECABDIR=C:\Progra~1\MeCab
# tools
IDLC=$(SDKBINDIR)/idlc
@@ -28,16 +31,24 @@
LINK=link
ZIP=zip
-all: furigana.uno.pkg
-
-furigana.urd: furigana.idl
- $(IDLC) -C -I$(OO_SDK_HOME)/idl furigana.idl
-
-furigana.rdb: furigana.urd
- $(REGMERGE) $@ /UCR furigana.urd
-
-furigana_impl.obj: furigana.rdb furigana_impl.cxx
- cppumaker -BUCR -Tjp.sourceforge.waooo.addin.XFurigana \
+CPP_OPT=-Zm500 -Zc:forScope -MD -GR -c -nologo -Gs -Gy -Ob1 -Oxs -Oy- -Gd \
+ -I. -I$(OO_SDK_HOME)\include -I/cygdrive/c/progra~1/java/JDK15~1.0_0/include/win32 \
+ -I/cygdrive/c/progra~1/java/JDK15~1.0_0/include -I/cygdrive/c/PROGRA~1/MICROS~4/include \
+ -I/cygdrive/c/PROGRA~1/MICROS~1.NET/Vc7/include -I/cygdrive/c/PROGRA~1/DIRECT~1/include \
+ -Zi -Wall -wd4061 -wd4100 -wd4127 -wd4191 -wd4217 -wd4251 -wd4275 -wd4290 -wd4294 -wd4355 \
+ -wd4511 -wd4512 -wd4514 -wd4611 -wd4625 -wd4626 -wd4640 -wd4668 -wd4675 -wd4710 -wd4711 \
+ -wd4716 -wd4786 -wd4800 -wd4820 -wd4503 -wd4255 -DWNT -DWNT -DNT351 -DMSC -DM1310 -DINTEL \
+ -D_X86_=1 -DFULL_DESK -DSTLPORT_VERSION=400 -DWINVER=0x400 -D_WIN32_IE=0x400 -D_MT \
+ -DCPPU_ENV=msci -DSUPD=680 -DPRODUCT -DNDEBUG -DPRODUCT_FULL -DOSL_DEBUG_LEVEL=0 -DOPTIMIZE \
+ -DEXCEPTIONS_OFF -DCUI -DSOLAR_JAVA -DOOD680=OOD680 -DSHAREDLIB -D_DLL_ -DWIN32 -D_MT \
+ -D_DLL -DWIN32 -D_MT -D_DLL
+LINK_LIB=$(OO_SDK_HOME)/windows/lib/icppu.lib \
+ $(OO_SDK_HOME)/windows/lib/icppuhelper.lib \
+ $(OO_SDK_HOME)/windows/lib/isal.lib \
+ User32.lib \
+ Msvcrt.lib \
+ Kernel32.lib
+CPPUMAKER_OPT=-BUCR -Tjp.sourceforge.waooo.addin.XFurigana \
-Tcom.sun.star.sheet.XAddIn \
-Tcom.sun.star.lang.XComponent \
-Tcom.sun.star.lang.XServiceName \
@@ -53,23 +64,45 @@
-Tcom.sun.star.lang.XInitialization \
-Tcom.sun.star.lang.IllegalArgumentException \
-Tcom.sun.star.beans.PropertyValue \
- -Tcom.sun.star.container.XHierarchicalNameAccess \
- "$(OFFICE_PROGRAM_PATH)/types.rdb" furigana.rdb
+ -Tcom.sun.star.container.XHierarchicalNameAccess
- $(CPP) -Zm500 -Zc:forScope -MD -GR -c -nologo -Gs -Gy -Ob1 -Oxs -Oy- -Gd -I. -I$(OO_SDK_HOME)\include -I/cygdrive/c/progra~1/java/JDK15~1.0_0/include/win32 -I/cygdrive/c/progra~1/java/JDK15~1.0_0/include -I/cygdrive/c/PROGRA~1/MICROS~4/include -I/cygdrive/c/PROGRA~1/MICROS~1.NET/Vc7/include -I/cygdrive/c/PROGRA~1/DIRECT~1/include -Zi -Wall -wd4061 -wd4100 -wd4127 -wd4191 -wd4217 -wd4251 -wd4275 -wd4290 -wd4294 -wd4355 -wd4511 -wd4512 -wd4514 -wd4611 -wd4625 -wd4626 -wd4640 -wd4668 -wd4675 -wd4710 -wd4711 -wd4716 -wd4786 -wd4800 -wd4820 -wd4503 -wd4255 -DWNT -DWNT -DNT351 -DMSC -DM1310 -DINTEL -D_X86_=1 -DFULL_DESK -DSTLPORT_VERSION=400 -DWINVER=0x400 -D_WIN32_IE=0x400 -D_MT -DCPPU_ENV=msci -DSUPD=680 -DPRODUCT -DNDEBUG -DPRODUCT_FULL -DOSL_DEBUG_LEVEL=0 -DOPTIMIZE -DEXCEPTIONS_OFF -DCUI -DSOLAR_JAVA -DOOD680=OOD680 -DSHAREDLIB -D_DLL_ -DWIN32 -D_MT -D_DLL -DWIN32 -D_MT -D_DLL -Fofurigana_impl.obj furigana_impl.cxx
+all: furigana-$(VERSION)-Win32.uno.pkg
+
+imm: furigana-$(VERSION)-Win32-imm.uno.pkg
+
+furigana.urd: furigana.idl
+ $(IDLC) -C -I$(OO_SDK_HOME)/idl furigana.idl
+
+furigana.rdb: furigana.urd
+ $(REGMERGE) $@ /UCR furigana.urd
+
+furigana_impl.obj: furigana.rdb furigana_impl.cxx
+ cppumaker $(CPPUMAKER_OPT) "$(OFFICE_PROGRAM_PATH)/types.rdb" furigana.rdb
+ $(CPP) $(CPP_OPT) -I$(MECABDIR)\sdk -Fofurigana_impl.obj furigana_impl.cxx
+
+furigana_impl-imm.obj: furigana.rdb furigana_impl.cxx
+ cppumaker $(CPPUMAKER_OPT) "$(OFFICE_PROGRAM_PATH)/types.rdb" furigana.rdb
+ $(CPP) $(CPP_OPT) -D__USE_IMM__ -Fofurigana_impl.obj furigana_impl.cxx
libfurigana.uno.dll: furigana_impl.obj
- $(LINK) /OPT:NOREF /NODEFAULTLIB /RELEASE /DEBUG:full /SUBSYSTEM:CONSOLE /DLL -out:libfurigana.uno.dll $(OO_SDK_HOME)/windows/lib/icppu.lib $(OO_SDK_HOME)/windows/lib/icppuhelper.lib $(OO_SDK_HOME)/windows/lib/isal.lib Imm32.lib User32.lib Msvcrt.lib Kernel32.lib furigana_impl.obj
+ $(LINK) /OPT:NOREF /NODEFAULTLIB /RELEASE /DEBUG:full /SUBSYSTEM:CONSOLE /DLL -out:libfurigana.uno.dll $(LINK_LIB) $(MECABDIR)\sdk\\libmecab.lib furigana_impl.obj
+
+libfurigana-imm.uno.dll: furigana_impl-imm.obj
+ $(LINK) /OPT:NOREF /NODEFAULTLIB /RELEASE /DEBUG:full /SUBSYSTEM:CONSOLE /DLL -out:libfurigana.uno.dll $(LINK_LIB) Imm32.lib furigana_impl.obj
+
+furigana-$(VERSION)-Win32.uno.pkg: furigana.rdb libfurigana.uno.dll META-INF/manifest.xml
+ $(REGCOMP) -register -r furigana.rdb -c libfurigana.uno.dll
+ $(ZIP) $@ META-INF/manifest.xml furigana.rdb libfurigana.uno.dll DESCRIPTION DESCRIPTION.ja Messages.xcu Messages.xcs
-furigana.uno.pkg: furigana.rdb libfurigana.uno.dll META-INF/manifest.xml
+furigana-$(VERSION)-Win32-imm.uno.pkg: furigana.rdb libfurigana-imm.uno.dll META-INF/manifest.xml
$(REGCOMP) -register -r furigana.rdb -c libfurigana.uno.dll
$(ZIP) $@ META-INF/manifest.xml furigana.rdb libfurigana.uno.dll DESCRIPTION DESCRIPTION.ja Messages.xcu Messages.xcs
install: furigana.uno.pkg
- $(OFFICE_PROGRAM_PATH)/unopkg add furigana.uno.pkg
+ $(OFFICE_PROGRAM_PATH)/unopkg add furigana-$(VERSION)-$(PLATFORM).uno.pkg
uninstall:
- $(OFFICE_PROGRAM_PATH)/unopkg remove furigana.uno.pkg
+ $(OFFICE_PROGRAM_PATH)/unopkg remove furigana-$(VERSION)-$(PLATFORM).uno.pkg
clean:
rm -rf com jp *.rdb *.urd *.pkg *.o *.so *.lib *.pdb *.exp *.obj *.dll
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]