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

Method buildSegments

snap_drawing/src/snap_drawing/cpp/Text/TextLayoutBuilder.cpp:916–950  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

914 }
915 }
916
917 if (iterator.hasRange()) {
918 auto& currentShapeableSegment = output.emplace_back(entry, &paragraph, &paragraphSegment);
919 currentShapeableSegment.charactersStart = iterator.rangeStart();
920 currentShapeableSegment.charactersEnd = iterator.rangeEnd();
921 currentShapeableSegment.resolvedFont = currentFont != nullptr ? currentFont : entry->specs.font;
922 }
923}
924
925TextLayoutBuilderResolvedShapeableSegments TextLayoutBuilder::resolveShapeableSegments() const {
926 TextLayoutBuilderResolvedShapeableSegments output;
927
928 /**
929 Directional layout algorithm is as follow:
930 - Resolve the text direction segments using the TextShaper
931 - For each directional segment:
932 - Resolve the shapeable segments, which are parts of the strings that can be processed by a single font.
933 - For each shapeable segment:
934 - Shape the segment
935 - If the segment is RTL, flip the emitted glyphs, to process them in the logical order
936 - Layout the shaped glyphs across lines
937 - If the directional segment is RTL, and that the overall layout is LTR, flip the emitted sentences across
938 lines.
939 - If the directional segment is LTR, and that the overall layout is RTL, flip the emitted sentences across
940 lines.
941 - If the overall layout is RTL, flip all the emitted sentences across lines.
942 - When emitting the final text blob, the glyphs for each emitted RTL segment are added in reverse order, which is
943 the natural display order for those segments.
944
945 Example string: "123 He Yo 4567 YO 89"
946 The string above is an example of a bidi string in LTR and RTL.
947 The numbers represent RTL region and the letters represent LTR regions.
948 We make the assumption that "1", "23", "He", "Yo", "456", "7" need different fonts.
949 We also simulate a line breaking in the example.
950
951 Algorithm in LTR:
952 Direction segments: [123], [He Yo], [4567], [YO], [89]
953 Shapeable segments: [1] [23] [He] [Yo] [456] [7] [YO] [89]

Callers

nothing calls this directly

Calls 4

withFontMethod · 0.80
reserveMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected