summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-09-22 15:18:37 +0800
committerPeng Wu <alexepico@gmail.com>2011-12-22 12:23:12 +0800
commitaea71c5a524cb814cb1697ed4b97a944eb899db6 (patch)
tree14c02794b5db9ba15b0de24bb7ba732c7730b9c8
parent3b2103d9293ce891f4b47173f60b194916046b18 (diff)
downloadibus-libpinyin-aea71c5a524cb814cb1697ed4b97a944eb899db6.tar.gz
ibus-libpinyin-aea71c5a524cb814cb1697ed4b97a944eb899db6.tar.xz
ibus-libpinyin-aea71c5a524cb814cb1697ed4b97a944eb899db6.zip
write bopomofo editor
-rw-r--r--src/PYPBopomofoEditor.cc35
-rw-r--r--src/PYPPinyinEditor.cc10
2 files changed, 40 insertions, 5 deletions
diff --git a/src/PYPBopomofoEditor.cc b/src/PYPBopomofoEditor.cc
index 3a2a70e..023634b 100644
--- a/src/PYPBopomofoEditor.cc
+++ b/src/PYPBopomofoEditor.cc
@@ -22,6 +22,8 @@
#include "PYConfig.h"
#include "PYPinyinProperties.h"
#include "PYSimpTradConverter.h"
+#include "PYHalfFullConverter.h"
+
namespace PY {
#include "PYBopomofoKeyboard.h"
@@ -259,7 +261,38 @@ LibPinyinBopomofoEditor::keyvalToBopomofo(gint ch)
void
LibPinyinBopomofoEditor::commit ()
{
- g_assert (FALSE);
+ if (G_UNLIKELY (m_text.empty ()))
+ return;
+
+ m_buffer.clear ();
+
+ /* sentence candidate */
+ char *tmp = NULL;
+ pinyin_get_sentence(m_instance, &tmp);
+ if (m_props.modeSimp ()) {
+ m_buffer << tmp;
+ } else {
+ SimpTradConverter::simpToTrad (tmp, m_buffer);
+ }
+ g_free (tmp);
+
+ /* text after pinyin */
+ const gchar *p = m_text.c_str() + m_pinyin_len;
+ while (*p != '\0') {
+ if (keyvalToBopomofo (*p)) {
+ m_buffer << keyvalToBopomofo (*p);
+ } else {
+ if (G_UNLIKELY (m_props.modeFull ())) {
+ m_buffer.appendUnichar (HalfFullConverter::toFull (*p++));
+ } else {
+ m_buffer << p;
+ }
+ }
+ }
+
+ pinyin_train(m_instance);
+ LibPinyinPhoneticEditor::commit ((const gchar *)m_buffer);
+ reset();
}
void
diff --git a/src/PYPPinyinEditor.cc b/src/PYPPinyinEditor.cc
index 8108002..5599416 100644
--- a/src/PYPPinyinEditor.cc
+++ b/src/PYPPinyinEditor.cc
@@ -200,8 +200,7 @@ LibPinyinPinyinEditor::processKeyEvent (guint keyval, guint keycode,
void
LibPinyinPinyinEditor::commit ()
{
-
- if (G_UNLIKELY (m_buffer.empty ()))
+ if (G_UNLIKELY (m_text.empty ()))
return;
m_buffer.clear ();
@@ -209,9 +208,12 @@ LibPinyinPinyinEditor::commit ()
/* sentence candidate */
char *tmp = NULL;
pinyin_get_sentence(m_instance, &tmp);
- m_buffer << tmp;
+ if (m_props.modeSimp ()) {
+ m_buffer << tmp;
+ } else {
+ SimpTradConverter::simpToTrad (tmp, m_buffer);
+ }
g_free (tmp);
- tmp = NULL;
/* text after pinyin */
const gchar *p = m_text.c_str() + m_pinyin_len;