MCPcopy Create free account
hub / github.com/Snapchat/Valdi / shape

Method shape

snap_drawing/src/snap_drawing/cpp/Text/TextShaperHarfbuzz.cpp:277–351  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

275 auto direction = ubidi_getVisualRun(line.ptr, visualIndex, &logicalStart, &logicalLength);
276
277 if (logicalLength == 0) {
278 continue;
279 }
280
281 auto isSegmentRTL = isBiDiLevelRightToLeft(direction);
282
283 auto segmentStart = static_cast<size_t>(paragraphStart + logicalStart);
284 auto segmentEnd = static_cast<size_t>(paragraphStart + logicalStart + logicalLength);
285
286 doAppendSegment(paragraph,
287 unicodeText,
288 utf16Index.getUTF32Index(segmentStart),
289 utf16Index.getUTF32Index(segmentEnd),
290 isSegmentRTL);
291 }
292 }
293
294 return out;
295}
296
297size_t TextShaperHarfbuzz::shape(const Character* unicodeText,
298 size_t length,
299 Font& font,
300 bool isRightToLeft,
301 Scalar letterSpacing,
302 TextScript script,
303 std::vector<ShapedGlyph>& out) {
304 std::lock_guard<Valdi::Mutex> lock(_mutex);
305
306 auto* buffer = _buffer.get();
307 if (buffer == nullptr) {
308 return 0;
309 }
310
311 auto* hbFont = font.getHBFont().get();
312 if (hbFont == nullptr) {
313 return 0;
314 }
315
316 hb_buffer_set_content_type(buffer, HB_BUFFER_CONTENT_TYPE_UNICODE);
317 hb_buffer_add_utf32(buffer, reinterpret_cast<const uint32_t*>(unicodeText), static_cast<int>(length), 0, -1);
318 hb_buffer_set_script(buffer, static_cast<hb_script_t>(script.code));
319 hb_buffer_set_direction(buffer, isRightToLeft ? HB_DIRECTION_RTL : HB_DIRECTION_LTR);
320 hb_buffer_guess_segment_properties(buffer);
321
322 const hb_feature_t* features = nullptr;
323 unsigned int featuresSize = 0;
324 // Disable default-on non-required ligature features if letter-spacing
325 // See http://dev.w3.org/csswg/css-text-3/#letter-spacing-property
326 // "When the effective spacing between two characters is not zero (due to
327 // either justification or a non-zero value of letter-spacing), user agents
328 // should not apply optional ligatures."
329 if (letterSpacing != 0.0) {
330 static hb_feature_t kNoLigaFeatures[] = {{HB_TAG('l', 'i', 'g', 'a'), 0, 0, ~0u},
331 {HB_TAG('c', 'l', 'i', 'g'), 0, 0, ~0u}};
332 features = kNoLigaFeatures;
333 featuresSize = static_cast<unsigned int>(sizeof(kNoLigaFeatures) / sizeof(hb_feature_t));
334 }

Callers

nothing calls this directly

Calls 9

getSkValueMethod · 0.80
setCharacterMethod · 0.80
getMethod · 0.65
getSizeMethod · 0.45
getScaleXMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected