diff options
author | Peng Wu <alexepico@gmail.com> | 2014-07-01 15:32:27 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2014-07-01 15:32:27 +0800 |
commit | b68d95fb69b043cfbb7319c308a040b5692749db (patch) | |
tree | 5b9a1e7bc24251afc32f740c02b39dd4689ff9d4 | |
parent | 70306d06f3eac8a6ee8754d981c724cc29db060b (diff) | |
download | ibus-libzhuyin-b68d95fb69b043cfbb7319c308a040b5692749db.tar.gz ibus-libzhuyin-b68d95fb69b043cfbb7319c308a040b5692749db.tar.xz ibus-libzhuyin-b68d95fb69b043cfbb7319c308a040b5692749db.zip |
write ZYZBopomofoSymbolSection.cc
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/ZYZBopomofoSymbolSection.cc | 72 | ||||
-rw-r--r-- | src/ZYZBuiltinSymbolSection.cc | 2 |
3 files changed, 75 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index a8534ff..b8e9fcb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -42,6 +42,7 @@ ibus_engine_libzhuyin_c_sources = \ ZYSymbols.cc \ ZYZBuiltinSymbolSection.cc \ ZYZPhoneticSection.cc \ + ZYZBopomofoSymbolSection.cc \ ZYFallbackEditor.cc \ ZYEngine.cc \ ZYZZhuyinEngine.cc \ @@ -67,6 +68,7 @@ ibus_engine_libzhuyin_h_sources = \ ZYZSymbolSection.h \ ZYZBuiltinSymbolSection.h \ ZYZPhoneticSection.h \ + ZYZBopomofoSymbolSection.h \ ZYPointer.h \ ZYProperty.h \ ZYRawEditor.h \ diff --git a/src/ZYZBopomofoSymbolSection.cc b/src/ZYZBopomofoSymbolSection.cc index acb91fd..4e9db8c 100644 --- a/src/ZYZBopomofoSymbolSection.cc +++ b/src/ZYZBopomofoSymbolSection.cc @@ -19,3 +19,75 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include "ZYZBopomofoSymbolSection.h" +#include <assert.h> +#include <zhuyin.h> + +namespace ZY { + +BopomofoSymbolSection::BopomofoSymbolSection (PhoneticEditor & editor, + ZhuyinProperties & props) : + SymbolSection (editor, props) +{ + m_type = "bopomofo"; +} + +BopomofoSymbolSection::~BopomofoSymbolSection () +{ +} + +bool +BopomofoSymbolSection::initCandidates (const String & lookup) +{ + assert (1 == lookup.length ()); + m_lookup = lookup; + const char key = lookup[0]; + + /* cache the choices. */ + gchar ** symbols = NULL; + assert (zhuyin_in_chewing_keyboard (instance, key, &symbols)); + size_t num = g_strv_length (symbols); + assert (num > 0); + for (size_t i = 0; i < num; ++i) { + m_candidates.push_back (symbols[i]); + } + g_strfreev (symbols); + + return true; +} + +bool +BopomofoSymbolSection::fillLookupTableByPage () +{ + LookupTable & lookup_table = getLookupTable (); + + guint len = m_candidates.size (); + + guint filled_nr = lookup_table.size (); + guint page_size = lookup_table.pageSize (); + + /* fill lookup table by libzhuyin get candidates. */ + guint need_nr = MIN (page_size, len - filled_nr); + g_assert (need_nr >=0); + if (need_nr == 0) + return FALSE; + + for (guint i = filled_nr; i < filled_nr + need_nr; i++) { + if (i >= len) /* no more candidates */ + break; + + Text text (m_candidates[i]); + lookup_table.appendCandidate (text); + } + + return TRUE; +} + +int +BopomofoSymbolSection::selectCandidate (guint index) +{ + m_choice = m_candidates[index]; + return g_utf8_strlen (m_choice, -1);; +} + +}; diff --git a/src/ZYZBuiltinSymbolSection.cc b/src/ZYZBuiltinSymbolSection.cc index 5576187..9309c1c 100644 --- a/src/ZYZBuiltinSymbolSection.cc +++ b/src/ZYZBuiltinSymbolSection.cc @@ -84,7 +84,7 @@ int BuiltinSymbolSection::selectCandidate (guint index) { m_choice = m_candidates[index]; - return 1; + return g_utf8_strlen (m_choice, -1); } }; |