summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2014-04-22 14:38:14 +0800
committerPeng Wu <alexepico@gmail.com>2014-04-22 14:38:14 +0800
commit63b1437ddfcf0b5551d935dc268c40b3ab67c53d (patch)
tree7f75a1c121e21631109f70aa8756deb0be77f215
parentcd75934a98b2e1ca6dc7ff124d9f99e4286f9473 (diff)
downloadibus-libzhuyin-63b1437ddfcf0b5551d935dc268c40b3ab67c53d.tar.gz
ibus-libzhuyin-63b1437ddfcf0b5551d935dc268c40b3ab67c53d.tar.xz
ibus-libzhuyin-63b1437ddfcf0b5551d935dc268c40b3ab67c53d.zip
write resizeInstances method
-rw-r--r--src/ZYEnhancedText.cc25
-rw-r--r--src/ZYEnhancedText.h3
-rw-r--r--src/ZYZPhoneticEditor.cc25
-rw-r--r--src/ZYZPhoneticEditor.h2
4 files changed, 55 insertions, 0 deletions
diff --git a/src/ZYEnhancedText.cc b/src/ZYEnhancedText.cc
index 2a3092f..25692cd 100644
--- a/src/ZYEnhancedText.cc
+++ b/src/ZYEnhancedText.cc
@@ -304,4 +304,29 @@ erase_input_sequence(String & enhanced_text, size_t offset, size_t length)
return true;
}
+size_t
+get_number_of_phonetic_sections (String & enhanced_text)
+{
+ size_t num = 0;
+ size_t start_pos = 0, end_pos = 0;
+
+ while (end_pos != enhanced_text.size ()) {
+ section_t type = probe_section_quick (enhanced_text, start_pos);
+
+ if (PHONETIC_SECTION == type) {
+ String section;
+ get_phonetic_section (enhanced_text, start_pos, end_pos, section);
+ ++num;
+ }
+
+ if (SYMBOL_SECTION == type) {
+ String type, lookup, choice;
+ get_symbol_section (enhanced_text, start_pos, end_pos,
+ type, lookup, choice);
+ }
+ }
+
+ return num;
+}
+
};
diff --git a/src/ZYEnhancedText.h b/src/ZYEnhancedText.h
index 2c0a590..c1ff10a 100644
--- a/src/ZYEnhancedText.h
+++ b/src/ZYEnhancedText.h
@@ -64,6 +64,9 @@ insert_symbol(String & enhanced_text, size_t offset,
bool
erase_input_sequence(String & enhanced_text, size_t offset, size_t length);
+size_t
+get_number_of_phonetic_sections (String & enhanced_text);
+
};
#endif
diff --git a/src/ZYZPhoneticEditor.cc b/src/ZYZPhoneticEditor.cc
index b11511f..931bb13 100644
--- a/src/ZYZPhoneticEditor.cc
+++ b/src/ZYZPhoneticEditor.cc
@@ -414,4 +414,29 @@ PhoneticEditor::moveCursorToEnd (void)
return TRUE;
}
+void
+PhoneticEditor::resizeInstances (void)
+{
+ size_t num = get_number_of_phonetic_sections (m_text);
+
+ /* re-allocate the zhuyin instances */
+ if (num > m_instances.size ()) { /* need more instances. */
+ for (size_t i = m_instances.size (); i < num; ++i) {
+ /* allocate one instance */
+ zhuyin_instance_t * instance = NULL;
+ assert (NULL != instance);
+ m_instances.push_back (instance);
+ }
+ }
+
+ if (num < m_instances.size ()) { /* free some instances. */
+ for (size_t i = num; i < m_instances.size (); ++i) {
+ zhuyin_free_instance (m_instances[i]);
+ m_instances[i] = NULL;
+ }
+ m_instances.resize (num);
+ }
+}
+
+
};
diff --git a/src/ZYZPhoneticEditor.h b/src/ZYZPhoneticEditor.h
index 94afb60..d9d421b 100644
--- a/src/ZYZPhoneticEditor.h
+++ b/src/ZYZPhoneticEditor.h
@@ -82,6 +82,8 @@ protected:
virtual void updatePreeditText (void) = 0;
virtual void updateZhuyin (void) = 0;
+ void resizeInstances (void);
+
/* varibles */
LookupTable m_lookup_table;
String m_buffer;