| 163 | } |
| 164 | |
| 165 | static std::vector<std::tuple<uint32_t, uint32_t, uint32_t>> ShapeText( |
| 166 | const std::string& text, const std::shared_ptr<Typeface>& typeface) { |
| 167 | auto hbFont = CreateHBFont(typeface); |
| 168 | if (hbFont == nullptr) { |
| 169 | return {}; |
| 170 | } |
| 171 | |
| 172 | auto hbBuffer = std::shared_ptr<hb_buffer_t>(hb_buffer_create(), hb_buffer_destroy); |
| 173 | if (!hb_buffer_allocation_successful(hbBuffer.get())) { |
| 174 | LOGI("TextShaper::shape text = %s, alloc harfbuzz(%p) failure", text.c_str(), hbBuffer.get()); |
| 175 | return {}; |
| 176 | } |
| 177 | hb_buffer_add_utf8(hbBuffer.get(), text.data(), -1, 0, -1); |
| 178 | hb_buffer_guess_segment_properties(hbBuffer.get()); |
| 179 | hb_shape(hbFont.get(), hbBuffer.get(), nullptr, 0); |
| 180 | unsigned count = 0; |
| 181 | auto infos = hb_buffer_get_glyph_infos(hbBuffer.get(), &count); |
| 182 | std::vector<std::tuple<uint32_t, uint32_t, uint32_t>> result; |
| 183 | for (unsigned i = 0; i < count; ++i) { |
| 184 | auto length = (i + 1 == count ? text.length() : infos[i + 1].cluster) - infos[i].cluster; |
| 185 | if (length == 0) { |
| 186 | continue; |
| 187 | } |
| 188 | result.emplace_back(infos[i].codepoint, infos[i].cluster, length); |
| 189 | } |
| 190 | return result; |
| 191 | } |
| 192 | |
| 193 | struct HBGlyph { |
| 194 | std::string text; |