From: Peng Wu Date: Thu, 22 Sep 2011 07:18:37 +0000 (+0800) Subject: write bopomofo editor X-Git-Tag: 1.4.0~140 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=aea71c5a524cb814cb1697ed4b97a944eb899db6;p=platform%2Fupstream%2Fibus-libpinyin.git write bopomofo editor --- 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;