MCPcopy Create free account
hub / github.com/Tencent/tgfx / ShapeText

Function ShapeText

test/src/utils/TextShaper.cpp:165–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163}
164
165static 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
193struct HBGlyph {
194 std::string text;

Callers 2

ShapeMethod · 0.85
onUpdateContentMethod · 0.85

Calls 10

CreateHBFontFunction · 0.85
c_strMethod · 0.80
lengthMethod · 0.80
getMethod · 0.45
dataMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected