diff options
Diffstat (limited to 'src/mbgl/text/tagged_string.cpp')
-rw-r--r-- | src/mbgl/text/tagged_string.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/mbgl/text/tagged_string.cpp b/src/mbgl/text/tagged_string.cpp new file mode 100644 index 0000000000..e199a7c962 --- /dev/null +++ b/src/mbgl/text/tagged_string.cpp @@ -0,0 +1,42 @@ +#include <mbgl/text/tagged_string.hpp> +#include <mbgl/util/i18n.hpp> + +#include <boost/algorithm/string.hpp> + +namespace mbgl { + +void TaggedString::addSection(const std::u16string& sectionText, double scale, FontStackHash fontStack) { + styledText.first += sectionText; + sections.emplace_back(scale, fontStack); + styledText.second.resize(styledText.first.size(), sections.size() - 1); +} + +void TaggedString::trim() { + auto whiteSpace = boost::algorithm::is_any_of(u" \t\n\v\f\r"); + std::size_t beginningWhitespace = styledText.first.find_first_not_of(u" \t\n\v\f\r"); + if (beginningWhitespace == std::u16string::npos) { + // Entirely whitespace + styledText.first.clear(); + styledText.second.clear(); + } else { + std::size_t trailingWhitespace = styledText.first.find_last_not_of(u" \t\n\v\f\r") + 1; + + styledText.first = styledText.first.substr(beginningWhitespace, trailingWhitespace - beginningWhitespace); + styledText.second = std::vector<uint8_t>(styledText.second.begin() + beginningWhitespace, styledText.second.begin() + trailingWhitespace); + } +} + +double TaggedString::getMaxScale() const { + double maxScale = 0.0; + for (std::size_t i = 0; i < styledText.first.length(); i++) { + maxScale = std::max(maxScale, getSection(i).scale); + } + return maxScale; +} + +void TaggedString::verticalizePunctuation() { + // Relies on verticalization changing characters in place so that style indices don't need updating + styledText.first = util::i18n::verticalizePunctuation(styledText.first); +} + +} // namespace mbgl |