| 46 | return {TextDecorationDottedUnderline}; |
| 47 | case Valdi::TextDecoration::Strikethrough: |
| 48 | return {TextDecorationStrikethrough}; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | static TextBackgroundPadding snapDrawingPaddingFromValdiPadding(const Valdi::TextBackgroundPadding& padding) { |
| 53 | return TextBackgroundPadding{padding.left, padding.top, padding.right, padding.bottom}; |
| 54 | } |
| 55 | |
| 56 | static BorderRadius snapDrawingBorderRadiusFromValdiDimension(const Valdi::Dimension& dimension) { |
| 57 | return BorderRadius::makeOval(static_cast<Scalar>(dimension.value), |
| 58 | dimension.unit == Valdi::Dimension::Unit::Percent); |
| 59 | } |
| 60 | |
| 61 | Valdi::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 |
nothing calls this directly
no test coverage detected