diff options
author | Peng Wu <alexepico@gmail.com> | 2014-04-18 14:40:44 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2014-04-18 14:40:44 +0800 |
commit | a5a42cca8e034205561338905c573d992b4e0abd (patch) | |
tree | 4822494d9d1037645e42fb35968a2ce479946f35 /src/ZYZPhoneticSection.cc | |
parent | 1332a6ac060631e76ae64650e1e4997b90bae2e4 (diff) | |
download | ibus-libzhuyin-a5a42cca8e034205561338905c573d992b4e0abd.tar.gz ibus-libzhuyin-a5a42cca8e034205561338905c573d992b4e0abd.tar.xz ibus-libzhuyin-a5a42cca8e034205561338905c573d992b4e0abd.zip |
update PhoneticSection::fillLookupTableByPage
Diffstat (limited to 'src/ZYZPhoneticSection.cc')
-rw-r--r-- | src/ZYZPhoneticSection.cc | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/src/ZYZPhoneticSection.cc b/src/ZYZPhoneticSection.cc index ed3505e..b7a0e2d 100644 --- a/src/ZYZPhoneticSection.cc +++ b/src/ZYZPhoneticSection.cc @@ -20,6 +20,8 @@ */ #include "ZYZPhoneticSection.h" +#include "ZYZhuyinProperties.h" +#include "ZYTradSimpConverter.h" namespace ZY { @@ -48,24 +50,44 @@ PhoneticSection::initCandidates (zhuyin_instance_t * instance, bool PhoneticSection::fillLookupTableByPage () { - /* clear lookup table. */ LookupTable & lookup_table = getLookupTable (); - lookup_table.clear (); - guint num = 0; - zhuyin_get_n_candidate (m_instance, &num); + guint len = 0; + zhuyin_get_n_candidate (m_instance, &len); + + 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; + + String word; + for (guint i = filled_nr; i < filled_nr + need_nr; i++) { + if (i >= len) /* no more candidates */ + break; - for (size_t i = 0; i < num; ++i) { lookup_candidate_t * candidate = NULL; zhuyin_get_candidate (m_instance, i, &candidate); - const gchar * str = NULL; - zhuyin_get_candidate_string (m_instance, candidate, &str); + const gchar * phrase_string = NULL; + zhuyin_get_candidate_string (m_instance, candidate, &phrase_string); - lookup_table.appendCandidate (Text (str)); + /* show get candidates. */ + if (G_LIKELY (m_props.modeTrad ())) { + word = phrase_string; + } else { /* Simplified Chinese */ + word.truncate (0); + TradSimpConverter::tradToSimp (phrase_string, word); + } + + Text text (word); + lookup_table.appendCandidate (text); } - return true; + return TRUE; } int |