1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
/* vim:set et ts=4 sts=4:
*
* ibus-libzhuyin - New Zhuyin engine based on libzhuyin for IBus
*
* Copyright (c) 2014 Peng Wu <alexepico@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "ZYZZhuyinEditor.h"
#include "ZYConfig.h"
#include "ZYLibZhuyin.h"
using namespace ZY;
ZhuyinEditor::ZhuyinEditor (ZhuyinProperties & props, Config & config)
: PhoneticEditor (props, config)
{
m_instance = LibZhuyinBackEnd::instance ().allocZhuyinInstance ();
}
ZhuyinEditor::~ZhuyinEditor (void)
{
LibZhuyinBackEnd::instance ().freeZhuyinInstance (m_instance);
m_instance = NULL;
}
void
ZhuyinEditor::commit (void)
{
if (G_UNLIKELY (m_preedit_text.empty ()))
return;
for (size_t i = 0; i < m_instances.size (); ++i) {
zhuyin_train (m_instances[i]);
}
LibZhuyinBackEnd::instance ().modified ();
PhoneticEditor::commit (m_preedit_text.c_str ());
reset ();
}
void
ZhuyinEditor::reset (void)
{
PhoneticEditor::reset ();
}
void
ZhuyinEditor::updateZhuyin (void)
{
String & enhanced_text = m_text;
resizeInstances ();
size_t index = 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);
zhuyin_instance_t * instance = m_instances[index];
zhuyin_parse_more_chewings (instance, section.c_str ());
zhuyin_guess_sentence (instance);
++index;
}
if (SYMBOL_SECTION == type) {
String type, lookup, choice;
get_symbol_section (enhanced_text, start_pos, end_pos,
type, lookup, choice);
}
start_pos = end_pos;
}
return;
}
void
ZhuyinEditor::updateAuxiliaryText (void)
{
/* libchewing doesn't use the auxiliary text, always hide. */
return;
}
void
ZhuyinEditor::updatePreeditText (void)
{
if (G_UNLIKELY (m_text.empty ())) {
hidePreeditText ();
return;
}
String & enhanced_text = m_text;
assert (FALSE);
}
void
ZhuyinEditor::update (void)
{
updateLookupTable ();
updatePreeditText ();
updateAuxiliaryText ();
}
|