| 67 | } |
| 68 | |
| 69 | Valdi::Value TextLayout::toJSONValue() const { |
| 70 | Valdi::Value out; |
| 71 | out.setMapValue("maxSize", snap::drawing::toJSONValue(_maxSize)); |
| 72 | |
| 73 | auto entries = Valdi::ValueArray::make(_entries.size()); |
| 74 | |
| 75 | for (size_t i = 0; i < _entries.size(); i++) { |
| 76 | const auto& entry = _entries[i]; |
| 77 | |
| 78 | Valdi::Value entryJson; |
| 79 | entryJson.setMapValue("bounds", snap::drawing::toJSONValue(entry.bounds)); |
| 80 | |
| 81 | if (!entry.segments.empty()) { |
| 82 | auto segments = Valdi::ValueArray::make(entry.segments.size()); |
| 83 | for (size_t j = 0; j < entry.segments.size(); j++) { |
| 84 | const auto& segment = entry.segments[j]; |
| 85 | Valdi::Value segmentJson; |
| 86 | |
| 87 | segmentJson.setMapValue("bounds", snap::drawing::toJSONValue(segment.bounds)); |
| 88 | segmentJson.setMapValue("font", Valdi::Value(segment.font->getDescription())); |
| 89 | segmentJson.setMapValue("characters", Valdi::Value(segment.characters)); |
| 90 | |
| 91 | segments->emplace(j, std::move(segmentJson)); |
| 92 | } |
| 93 | |
| 94 | entryJson.setMapValue("segments", Valdi::Value(segments)); |
| 95 | } |
| 96 | |
| 97 | if (entry.color) { |
| 98 | entryJson.setMapValue("color", Valdi::Value(entry.color.value().toString())); |
| 99 | } |
| 100 | |
| 101 | entries->emplace(i, std::move(entryJson)); |
| 102 | } |
| 103 | |
| 104 | out.setMapValue("entries", Valdi::Value(entries)); |
| 105 | |
| 106 | auto visualEntries = Valdi::ValueArray::make(_visualEntries.size()); |
| 107 | for (size_t i = 0; i < _visualEntries.size(); i++) { |
| 108 | const auto& visualEntry = _visualEntries[i]; |
| 109 | |
| 110 | Valdi::Value visualEntryJson; |
| 111 | visualEntryJson.setMapValue("bounds", snap::drawing::toJSONValue(visualEntry.bounds)); |
| 112 | visualEntryJson.setMapValue("predraw", Valdi::Value(visualEntry.predraw)); |
| 113 | if (visualEntry.kind == TextLayoutVisualEntryKindBackground) { |
| 114 | visualEntryJson.setMapValue("kind", Valdi::Value("background")); |
| 115 | } |
| 116 | if (!visualEntry.borderRadius.isEmpty()) { |
| 117 | visualEntryJson.setMapValue("borderRadius", Valdi::Value(visualEntry.borderRadius.toString())); |
| 118 | } |
| 119 | if (visualEntry.style == TextLayoutDecorationStyleDashed) { |
| 120 | visualEntryJson.setMapValue("style", Valdi::Value("dashed")); |
| 121 | } else if (visualEntry.style == TextLayoutDecorationStyleDotted) { |
| 122 | visualEntryJson.setMapValue("style", Valdi::Value("dotted")); |
| 123 | } |
| 124 | |
| 125 | if (visualEntry.color) { |
| 126 | visualEntryJson.setMapValue("color", Valdi::Value(visualEntry.color.value().toString())); |