30 #include "unicode/errorcode.h"
31 #include "unicode/normlzr.h"
32 #include "unicode/unistr.h"
33 #include "unicode/utypes.h"
39 return std::string(uni_ch.utf8(), uni_ch.utf8_len());
61 min_norm_length_(0), max_norm_length_(0) {}
63 void LigatureTable::Init() {
64 if (norm_to_lig_table_.empty()) {
69 icu::UnicodeString unicode_lig8(static_cast<UChar32>(lig));
70 icu::UnicodeString normed8_result;
71 icu::ErrorCode status;
72 icu::Normalizer::normalize(unicode_lig8, UNORM_NFKC, 0, normed8_result,
75 normed8_result.toUTF8String(normed8);
80 int lig_length = lig8.length();
81 int norm_length = normed8.size();
82 if (normed8 != lig8 && lig_length > 1 && norm_length > 1) {
83 norm_to_lig_table_[normed8] = lig8;
84 lig_to_norm_table_[lig8] = normed8;
85 if (min_lig_length_ == 0 || lig_length < min_lig_length_)
86 min_lig_length_ = lig_length;
87 if (lig_length > max_lig_length_)
88 max_lig_length_ = lig_length;
89 if (min_norm_length_ == 0 || norm_length < min_norm_length_)
90 min_norm_length_ = norm_length;
91 if (norm_length > max_norm_length_)
92 max_norm_length_ = norm_length;
100 if (min_norm_length_ == 0 || norm_length < min_norm_length_)
101 min_norm_length_ = norm_length;
102 if (norm_length > max_norm_length_)
103 max_norm_length_ = norm_length;
113 UNICHAR::const_iterator it_begin = UNICHAR::begin(str.c_str(), str.length());
114 UNICHAR::const_iterator it_end = UNICHAR::end(str.c_str(), str.length());
117 for (UNICHAR::const_iterator it = it_begin; it != it_end; ++it) {
118 len = it.get_utf8(tmp);
120 LigHash::const_iterator lig_it = lig_to_norm_table_.find(tmp);
121 if (lig_it != lig_to_norm_table_.end()) {
122 result += lig_it->second;
157 const PangoFontInfo* font)
const {
159 int len = str.size();
162 for (i = 0; i < len - min_norm_length_ + 1; i += step) {
164 for (
int liglen = max_norm_length_; liglen >= min_norm_length_; --liglen) {
165 if (i + liglen <= len) {
167 LigHash::const_iterator it = norm_to_lig_table_.find(lig_cand);
168 if (it != norm_to_lig_table_.end()) {
169 tlog(3,
"Considering %s -> %s\n", lig_cand.c_str(),
173 if (!font->CanRenderString(it->second.data(), it->second.length()))
178 result += it->second;
179 tlog(2,
"Substituted %s -> %s\n", lig_cand.c_str(),
190 result += str.substr(i, len - i);