| 74 | } |
| 75 | |
| 76 | bool TextBlock::serialize(HalFile& file) const { |
| 77 | // Focus annotations are optional; vectors are either empty (no splits in this block) |
| 78 | // or sized in lockstep with words[]. |
| 79 | const bool hasFocus = !wordFocusBoundary.empty(); |
| 80 | if (words.size() != wordXpos.size() || words.size() != wordStyles.size() || |
| 81 | (hasFocus && (words.size() != wordFocusBoundary.size() || words.size() != wordFocusSuffixX.size()))) { |
| 82 | LOG_ERR("TXB", "Serialization failed: size mismatch (words=%u, xpos=%u, styles=%u, boundary=%u, suffixX=%u)\n", |
| 83 | static_cast<uint32_t>(words.size()), static_cast<uint32_t>(wordXpos.size()), |
| 84 | static_cast<uint32_t>(wordStyles.size()), static_cast<uint32_t>(wordFocusBoundary.size()), |
| 85 | static_cast<uint32_t>(wordFocusSuffixX.size())); |
| 86 | return false; |
| 87 | } |
| 88 | |
| 89 | // Word data |
| 90 | serialization::writePod(file, static_cast<uint16_t>(words.size())); |
| 91 | for (const auto& w : words) serialization::writeString(file, w); |
| 92 | for (auto x : wordXpos) serialization::writePod(file, x); |
| 93 | for (auto s : wordStyles) serialization::writePod(file, s); |
| 94 | // Focus block: 1-byte presence flag, followed by per-word vectors only when present. |
| 95 | // Saves 3 bytes/word when focus reading is disabled or no word on this line was split. |
| 96 | serialization::writePod(file, static_cast<uint8_t>(hasFocus ? 1 : 0)); |
| 97 | if (hasFocus) { |
| 98 | for (auto b : wordFocusBoundary) serialization::writePod(file, b); |
| 99 | for (auto sx : wordFocusSuffixX) serialization::writePod(file, sx); |
| 100 | } |
| 101 | |
| 102 | // Style (alignment + margins/padding/indent) |
| 103 | serialization::writePod(file, blockStyle.alignment); |
| 104 | serialization::writePod(file, blockStyle.textAlignDefined); |
| 105 | serialization::writePod(file, blockStyle.marginTop); |
| 106 | serialization::writePod(file, blockStyle.marginBottom); |
| 107 | serialization::writePod(file, blockStyle.marginLeft); |
| 108 | serialization::writePod(file, blockStyle.marginRight); |
| 109 | serialization::writePod(file, blockStyle.paddingTop); |
| 110 | serialization::writePod(file, blockStyle.paddingBottom); |
| 111 | serialization::writePod(file, blockStyle.paddingLeft); |
| 112 | serialization::writePod(file, blockStyle.paddingRight); |
| 113 | serialization::writePod(file, blockStyle.textIndent); |
| 114 | serialization::writePod(file, blockStyle.textIndentDefined); |
| 115 | serialization::writePod(file, blockStyle.isRtl); |
| 116 | serialization::writePod(file, blockStyle.directionDefined); |
| 117 | |
| 118 | return true; |
| 119 | } |
| 120 | |
| 121 | std::unique_ptr<TextBlock> TextBlock::deserialize(HalFile& file) { |
| 122 | uint16_t wc; |
nothing calls this directly
no test coverage detected