write bopomofo editor
authorPeng Wu <alexepico@gmail.com>
Thu, 22 Sep 2011 07:18:37 +0000 (15:18 +0800)
committerPeng Wu <alexepico@gmail.com>
Thu, 22 Dec 2011 04:23:12 +0000 (12:23 +0800)
src/PYPBopomofoEditor.cc
src/PYPPinyinEditor.cc

index 3a2a70e..023634b 100644 (file)
@@ -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
index 8108002..5599416 100644 (file)
@@ -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;