From: BYVoid Date: Thu, 13 May 2010 09:41:57 +0000 (+0800) Subject: Bopomofo X-Git-Tag: 1.3.10~162^2~21 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=44eb3a3beaaf8a9ee66a633783b3e6dd03a9e1f1;p=platform%2Fupstream%2Fibus-libpinyin.git Bopomofo --- diff --git a/src/BopomofoEditor.cc b/src/BopomofoEditor.cc index af5757e..c5432aa 100644 --- a/src/BopomofoEditor.cc +++ b/src/BopomofoEditor.cc @@ -26,11 +26,11 @@ BopomofoEditor::insert (gint ch) if (G_UNLIKELY (m_text.length () >= MAX_PINYIN_LEN)) return TRUE; - gint key = get_bopomofo_keyboard_map(ch); + gint key = keyvalToBopomofo(ch); if (key >= BOPOMOFO_TONE_2 && key <= BOPOMOFO_TONE_5) { if (m_cursor == 0) return TRUE; /* invalid format: tone should not be the first character */ - key = get_bopomofo_keyboard_map(m_text.c_str()[m_cursor - 1]); + key = keyvalToBopomofo(m_text.c_str()[m_cursor - 1]); if (key >= BOPOMOFO_TONE_2 && key <= BOPOMOFO_TONE_5) return TRUE; /* invalid format: two tone character should not be together */ } @@ -260,10 +260,10 @@ BopomofoEditor::updatePinyin (void) else { bopomofo.clear(); for(String::iterator i = m_text.begin();i != m_text.end(); ++i) { - bopomofo += bopomofo_char[get_bopomofo_keyboard_map(*i)]; + bopomofo += bopomofo_char[keyvalToBopomofo(*i)]; } - m_pinyin_len = PinyinParser::parse_bopomofo(bopomofo, // bopomofo + m_pinyin_len = PinyinParser::parseBopomofo(bopomofo, // bopomofo m_cursor, // text length Config::option (), // option m_pinyin, // result @@ -290,7 +290,7 @@ BopomofoEditor::updateAuxiliaryText (void) for (String::iterator i = m_text.begin();i!=m_text.end();i++) { if (m_cursor == i - m_text.begin()) m_buffer << '|'; - m_buffer.appendUnichar(bopomofo_char[get_bopomofo_keyboard_map(*i)]); + m_buffer.appendUnichar(bopomofo_char[keyvalToBopomofo(*i)]); } if (m_cursor == m_text.length()) m_buffer << '|'; @@ -322,7 +322,7 @@ BopomofoEditor::commit (void) } while (*p != '\0') { - m_buffer.appendUnichar ((gunichar)bopomofo_char[get_bopomofo_keyboard_map(*p++)]); + m_buffer.appendUnichar ((gunichar)bopomofo_char[keyvalToBopomofo(*p++)]); } m_phrase_editor.commit (); @@ -333,8 +333,6 @@ BopomofoEditor::commit (void) void BopomofoEditor::updatePreeditText (void) { - PinyinEditor::updatePreeditText(); -#if 0 /* preedit text = selected phrases + highlight candidate + rest text */ if (G_UNLIKELY (m_phrase_editor.empty () && m_text.empty ())) { hidePreeditText (); @@ -379,22 +377,26 @@ BopomofoEditor::updatePreeditText (void) edit_end = m_buffer.utf8Length (); /* append rest text */ - m_buffer << textAfterPinyin (edit_end); + if (m_cursor >= MAX_PHRASE_LEN) { + for (const gchar *p=m_text.c_str() + MAX_PHRASE_LEN; *p ;++p) { + m_buffer.appendUnichar(bopomofo_char[keyvalToBopomofo(*p)]); + } + } } else { - guint candidate_end = edit_begin + candidate.len; - m_buffer << m_pinyin[edit_begin]->sheng << m_pinyin[edit_begin]->yun; - - for (guint i = edit_begin + 1; i < candidate_end; i++) { - m_buffer << ' ' << m_pinyin[i]->sheng << m_pinyin[i]->yun; + for (const gchar *p=m_text.c_str(); *p ;++p) { + if (p - m_text.c_str() == m_cursor) + m_buffer << ' '; + m_buffer.appendUnichar(bopomofo_char[keyvalToBopomofo(*p)]); } - m_buffer << ' ' << textAfterPinyin (candidate_end); edit_end = m_buffer.utf8Length (); } } } else { - m_buffer << textAfterPinyin (); + for (const gchar *p=m_text.c_str() + m_pinyin_len; *p ;++p) { + m_buffer.appendUnichar(bopomofo_char[keyvalToBopomofo(*p)]); + } } } @@ -410,7 +412,6 @@ BopomofoEditor::updatePreeditText (void) edit_begin, edit_end); } Editor::updatePreeditText (preedit_text, edit_begin, TRUE); -#endif } }; diff --git a/src/BopomofoEditor.h b/src/BopomofoEditor.h index 9516233..2ff9838 100644 --- a/src/BopomofoEditor.h +++ b/src/BopomofoEditor.h @@ -42,7 +42,7 @@ protected: gboolean processBopomofo (guint keyval, guint keycode, guint modifiers); - gint get_bopomofo_keyboard_map(gint ch) { + gint keyvalToBopomofo(gint ch) { switch(ch){ case IBUS_1: return BOPOMOFO_B; case IBUS_q: return BOPOMOFO_P; diff --git a/src/PinyinEditor.cc b/src/PinyinEditor.cc index 07fd16d..bef4112 100644 --- a/src/PinyinEditor.cc +++ b/src/PinyinEditor.cc @@ -400,7 +400,7 @@ PinyinEditor::updatePreeditText (void) for (guint i = edit_begin + 1; i < candidate_end; i++) { m_buffer << ' ' << m_pinyin[i]->sheng << m_pinyin[i]->yun; } - m_buffer << ' ' << textAfterPinyin (candidate_end); + m_buffer << '|' << textAfterPinyin (candidate_end); edit_end = m_buffer.utf8Length (); } } diff --git a/src/PinyinEngine.cc b/src/PinyinEngine.cc index d279e66..ec84bb5 100644 --- a/src/PinyinEngine.cc +++ b/src/PinyinEngine.cc @@ -10,7 +10,6 @@ #include "BopomofoEditor.h" #include "PinyinEngine.h" #include "HalfFullConverter.h" -#include "SimpTradConverter.h" #include "Config.h" #include "Text.h" #include "Util.h" diff --git a/src/PinyinParser.cc b/src/PinyinParser.cc index fe8e31b..e2c4f97 100644 --- a/src/PinyinParser.cc +++ b/src/PinyinParser.cc @@ -280,7 +280,7 @@ PinyinParser::isBopomofoToneChar (const wchar_t ch) } guint -PinyinParser::parse_bopomofo (const std::wstring &bopomofo, +PinyinParser::parseBopomofo (const std::wstring &bopomofo, gint len, guint option, PinyinArray &result, @@ -320,6 +320,8 @@ PinyinParser::parse_bopomofo (const std::wstring &bopomofo, if (G_UNLIKELY (bs_res != NULL)) break; } + if (G_UNLIKELY (bs_res == NULL)) + break; result.append(*bs_res,bpmf - bopomofo.begin() ,(*bs_res)->len); bpmf += i; } diff --git a/src/PinyinParser.h b/src/PinyinParser.h index ebf0815..4379741 100644 --- a/src/PinyinParser.h +++ b/src/PinyinParser.h @@ -16,7 +16,7 @@ public: PinyinArray &result, // store pinyin in result guint max); // max length of the result static const Pinyin * isPinyin (gint sheng, gint yun, guint option); - static guint parse_bopomofo (const std::wstring &bopomofo, + static guint parseBopomofo (const std::wstring &bopomofo, gint len, guint option, PinyinArray &result,