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

Method parse

valdi/src/valdi/snap_drawing/Utils/AttributedTextParser.cpp:48–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46 return {TextDecorationDottedUnderline};
47 case Valdi::TextDecoration::Strikethrough:
48 return {TextDecorationStrikethrough};
49 }
50}
51
52static TextBackgroundPadding snapDrawingPaddingFromValdiPadding(const Valdi::TextBackgroundPadding& padding) {
53 return TextBackgroundPadding{padding.left, padding.top, padding.right, padding.bottom};
54}
55
56static BorderRadius snapDrawingBorderRadiusFromValdiDimension(const Valdi::Dimension& dimension) {
57 return BorderRadius::makeOval(static_cast<Scalar>(dimension.value),
58 dimension.unit == Valdi::Dimension::Unit::Percent);
59}
60
61Valdi::Result<Valdi::Ref<AttributedText>> AttributedTextParser::parse(FontManager& fontManager,
62 const Valdi::Value& value) {
63 auto textAttributeValue = value.getTypedRef<Valdi::TextAttributeValue>();
64 if (textAttributeValue == nullptr) {
65 return Valdi::Error(STRING_FORMAT("Value '{}' is not an AttributedText object", value.toString()));
66 }
67
68 AttributedText::Parts parts;
69
70 auto length = textAttributeValue->getPartsSize();
71 parts.reserve(length);
72
73 for (size_t i = 0; i < length; i++) {
74 auto& part = parts.emplace_back();
75
76 const auto& style = textAttributeValue->getStyleAtIndex(i);
77
78 part.content = textAttributeValue->getContentAtIndex(i);
79
80 if (style.font) {
81 auto fontResult = fontManager.getFontForName(style.font.value(), 1.0);
82 if (!fontResult) {
83 return fontResult.moveError();
84 }
85 part.style.font = {fontResult.moveValue()};
86 }
87
88 if (style.color) {
89 part.style.color = {snapDrawingColorFromValdiColor(style.color.value().value)};
90 }
91

Callers

nothing calls this directly

Calls 9

parseTextDecorationFunction · 0.85
getFontForNameMethod · 0.80
toStringMethod · 0.65
valueMethod · 0.65
ErrorInterface · 0.50
getPartsSizeMethod · 0.45
reserveMethod · 0.45
getContentAtIndexMethod · 0.45

Tested by

no test coverage detected