diff --git a/scim-wnn/configure.ac b/scim-wnn/configure.ac index 739d00f..e65e9e1 100644 --- a/scim-wnn/configure.ac +++ b/scim-wnn/configure.ac @@ -89,6 +89,12 @@ fi fi +AC_CHECK_HEADER([anthy/anthy.h], [ + LIBS="$LIBS -lanthy -lanthydic" +],[]) +if echo $LIBS | grep "anthy" > /dev/null; then + AC_DEFINE([HAVE_LIBANTHY],[1],[Anthy]) +fi # Checks for header files. AC_HEADER_STDC diff --git a/scim-wnn/m4/Makefile b/scim-wnn/m4/Makefile index 4e49632..b58c7ef 100644 --- a/scim-wnn/m4/Makefile +++ b/scim-wnn/m4/Makefile @@ -120,7 +120,7 @@ LIBICONV = LIBINTL = LIBOBJS = -LIBS = -lwnn -lcrypt +LIBS = -lwnn -lcrypt -lanthy -lanthydic LIBTOOL = $(SHELL) $(top_builddir)/libtool LIBTOOL_DEPS = ./ltmain.sh LN_S = ln -s diff --git a/scim-wnn/src/Makefile.am b/scim-wnn/src/Makefile.am index 94ecb46..4071a9f 100644 --- a/scim-wnn/src/Makefile.am +++ b/scim-wnn/src/Makefile.am @@ -26,13 +26,13 @@ -DSCIM_WNN_ICON_FILE=\"@SCIM_ICONDIR@/scim-wnn.png\" noinst_HEADERS = scim_wnn_imengine.h wnnproto.h romkan.h romkan_table.h \ - wnnconversion.h scim_wnn_def.h preeditor.h kanainput.h convertor.h + wnnconversion.h scim_wnn_def.h preeditor.h kanainput.h convertor.h anthyconversion.h moduledir = @SCIM_MODULEDIR@/IMEngine module_LTLIBRARIES = wnn.la wnn_la_SOURCES = scim_wnn_imengine.cpp romkan.cpp wnnconversion.cpp \ - preeditor.cpp kanainput.cpp convertor.cpp + preeditor.cpp kanainput.cpp convertor.cpp anthyconversion.cpp wnn_la_CFLAGS = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ wnn_la_CXXFLAGS = @SCIM_CFLAGS@ @SCIM_DEBUG_FLAGS@ diff --git a/scim-wnn/src/anthyconversion.cpp b/scim-wnn/src/anthyconversion.cpp new file mode 100644 index 0000000..a4a9e7d --- /dev/null +++ b/scim-wnn/src/anthyconversion.cpp @@ -0,0 +1,159 @@ +/*************************************************************************** + * Copyright (C) 2004 by TAM(Teppei Tamra) * + * tam-t@par.odn.ne.jp * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include "anthyconversion.h" + +#ifdef HAVE_LIBANTHY + + +AnthyConversion::AnthyConversion(ConfigPointer cfg) : Convertor(cfg) +{ + m_iconv.set_encoding ("EUC-JP"); + pos = 0; + anthy_init(); + context = anthy_create_context(); +} + + +AnthyConversion::~AnthyConversion() +{ +} + +bool AnthyConversion::isConnected() { + return(true); +} + +void AnthyConversion::reset(){ + anthy_init(); + context = anthy_create_context(); + return; +} + +void AnthyConversion::setYomiText(WideString yomi) { + yomiText = yomi; +} + +int AnthyConversion::ren_conversion() { + String y; + m_iconv.convert(y,yomiText); + anthy_set_string(context,y.c_str()); + struct anthy_conv_stat stat; + anthy_get_stat(context,&stat); + pos = 0; + buildResult(); + + return(stat.nr_segment); +} + +WideString AnthyConversion::getText() { + WideString text; + for(unsigned int i = 0;i < convResult.size();i ++) { + text += convResult[i].kouho[convResult[i].pos]; + } + return(text); +} + +int AnthyConversion::setPos(int p){ + if ((p < convResult.size()) && (p >= 0)) pos = p; + return(pos); +} + +int AnthyConversion::getPos() { + return(pos); +} + +ResultList AnthyConversion::getResultList(int p,int kt){ + if (p == -1) p = pos; + if ((kt != 0) || (p >= convResult.size())) return(ResultList()); + return(convResult[p]); +} + +ResultList AnthyConversion::getYosokuList(const WideString &str) { + return(ResultList()); +} + +bool AnthyConversion::select(int p) { + if (p < convResult[pos].count) { + convResult[pos].pos = p; + } +} + +AttributeList AnthyConversion::getAttributeList() { + AttributeList attr; + int l = 0; + for(unsigned int i = 0;i < convResult.size();i ++) { + if (pos == i) { + Attribute a(l,convResult[i].kouho[convResult[i].pos].length(),SCIM_ATTR_DECORATE,SCIM_ATTR_DECORATE_REVERSE); + attr.push_back(a); + } + l += convResult[i].kouho[convResult[i].pos].length(); + } + return(attr); +} + +bool AnthyConversion::resizeRegion(int w) { + return(false); +} + +void AnthyConversion::updateFrequency() { + return; +} + +bool AnthyConversion::connect() { + return(true); +} +void AnthyConversion::disconnect() { + return; +} + +int AnthyConversion::getCaretPos() { + int l = 0; + for(unsigned int i = 0;i < convResult.size();i ++) { + if (pos == i) return(l); + l += convResult[i].kouho[convResult[i].pos].length(); + } + return(0); +} + +void AnthyConversion::buildResult() { + struct anthy_conv_stat stat; + anthy_get_stat(context,&stat); + convResult.clear(); + for(int i = 0;i < stat.nr_segment;i ++) { + ResultList l; + l.kType = 0; + struct anthy_segment_stat sstat; + anthy_get_segment_stat(context,0,&sstat); + l.count = sstat.nr_candidate; + l.pos = 0; + for(int j = 0;j < sstat.nr_candidate;j ++) { + char res[256]; + int c = anthy_get_segment(context,i,j,0,0); + if (c > 255) c = 255; + anthy_get_segment(context,i,j,res,c + 1); + WideString w; + m_iconv.convert(w,String(res)); + l.kouho.push_back(w); + } + convResult.push_back(l); + } +} + +#endif + diff --git a/scim-wnn/src/anthyconversion.h b/scim-wnn/src/anthyconversion.h new file mode 100644 index 0000000..b4968b4 --- /dev/null +++ b/scim-wnn/src/anthyconversion.h @@ -0,0 +1,80 @@ +/*************************************************************************** + * Copyright (C) 2004 by TAM(Teppei Tamra) * + * tam-t@par.odn.ne.jp * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef ANTHYCONVERSION_H +#define ANTHYCONVERSION_H + +#ifdef HAVE_CONFIG_H +#include +#endif + +#ifdef HAVE_LIBANTHY + +#define Uses_SCIM_CONFIG_BASE + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +using namespace scim; + +/** +@author TAM (Teppei Tamra) +*/ +class AnthyConversion : public Convertor { +public: + AnthyConversion(ConfigPointer cfg); + + ~AnthyConversion(); + virtual bool isConnected(); + virtual void reset(); + virtual void setYomiText(WideString yomi); + virtual int ren_conversion(); + virtual WideString getText(); + virtual int setPos(int p); + virtual int getPos(); + virtual ResultList getResultList(int p = -1 ,int kt = 0); + virtual ResultList getYosokuList(const WideString &str); + virtual bool select(int p); + virtual AttributeList getAttributeList(); + virtual bool resizeRegion(int w); + virtual void updateFrequency(); + virtual bool connect(); + virtual void disconnect(); + virtual int getCaretPos(); +protected: + void buildResult(); +protected: + anthy_context_t context; + IConvert m_iconv; + WideString yomiText; + vector convResult; + int pos; + +}; + +#endif + +#endif diff --git a/scim-wnn/src/scim_wnn_imengine.cpp b/scim-wnn/src/scim_wnn_imengine.cpp index f2aa179..742fbc4 100644 --- a/scim-wnn/src/scim_wnn_imengine.cpp +++ b/scim-wnn/src/scim_wnn_imengine.cpp @@ -185,6 +185,7 @@ preeditors.push_back(new Romkan(_scim_config)); preeditors.push_back(new KanaInput(_scim_config)); m_preeditor = preeditors.at(0); + wnn = 0; init(); } @@ -208,14 +209,20 @@ // @todo if connected to jserver, should disconnect this. - wnn = new WnnConversion(_scim_config); - alp = _scim_config->read(String(SCIM_CONFIG_WNN_ALP),SCIM_DEFAULT_WNN_ALP); mini_status = _scim_config->read(String(SCIM_CONFIG_WNN_MINISTATUS),SCIM_DEFAULT_WNN_MINISTATUS); numkeyselect = _scim_config->read(String(SCIM_CONFIG_WNN_NUMKEY_SELECT),SCIM_DEFAULT_WNN_NUMKEY_SELECT); yosoku = _scim_config->read(String(SCIM_CONFIG_WNN_YOSOKU),SCIM_DEFAULT_WNN_YOSOKU); sType = _scim_config->read(String(SCIM_CONFIG_WNN_SERVERTYPE),String(SCIM_DEFAULT_WNN_SERVERTYPE)); + #ifdef HAVE_LIBANTHY + if (sType == "Anthy") + wnn = new AnthyConversion(_scim_config); + else + #endif + wnn = new WnnConversion(_scim_config); + + defaultPreEditor = _scim_config->read(String(SCIM_CONFIG_WNN_DEFAULT_PREEDITOR),String(SCIM_DEFAULT_WNN_DEFAULT_PREEDITOR)); auto_conversion = _scim_config->read(String(SCIM_CONFIG_WNN_AUTO_CONVERSION),SCIM_DEFAULT_WNN_AUTO_CONVERSION);; diff --git a/scim-wnn/src/scim_wnn_imengine.h b/scim-wnn/src/scim_wnn_imengine.h index 47d3a5b..aa866c0 100644 --- a/scim-wnn/src/scim_wnn_imengine.h +++ b/scim-wnn/src/scim_wnn_imengine.h @@ -26,6 +26,7 @@ #include #include #include +#include #define Uses_SCIM_ICONV #include #include