diff options
Diffstat (limited to 'src/mbgl/text/tagged_string.hpp')
-rw-r--r-- | src/mbgl/text/tagged_string.hpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/mbgl/text/tagged_string.hpp b/src/mbgl/text/tagged_string.hpp index 476c2225f0..c40c253753 100644 --- a/src/mbgl/text/tagged_string.hpp +++ b/src/mbgl/text/tagged_string.hpp @@ -1,17 +1,22 @@ #pragma once -#include <mbgl/text/glyph.hpp> #include <mbgl/text/bidi.hpp> +#include <mbgl/style/expression/formatted.hpp> +#include <mbgl/util/font_stack.hpp> namespace mbgl { +using style::expression::FormattedSectionID; + struct SectionOptions { - SectionOptions(double scale_, FontStackHash fontStackHash_) - : scale(scale_), fontStackHash(fontStackHash_) + SectionOptions(double scale_, FontStack fontStack_, const optional<FormattedSectionID>& id_ = {}) + : scale(scale_), fontStackHash(FontStackHasher()(fontStack_)), fontStack(std::move(fontStack_)), id(std::move(id_)) {} double scale; FontStackHash fontStackHash; + FontStack fontStack; + optional<FormattedSectionID> id; }; /** @@ -34,7 +39,7 @@ struct TaggedString { TaggedString(std::u16string text_, SectionOptions options) : styledText(std::move(text_), - std::vector<uint8_t>(text_.size(), 0)) { + std::vector<std::size_t>(text_.size(), 0)) { sections.push_back(std::move(options)); } @@ -71,7 +76,11 @@ struct TaggedString { return styledText; } - void addSection(const std::u16string& text, double scale, FontStackHash fontStack); + void addSection(const std::u16string& text, + double scale, + FontStack fontStack, + const optional<FormattedSectionID>& id = {}); + const SectionOptions& sectionAt(std::size_t index) const { return sections.at(index); } @@ -80,7 +89,7 @@ struct TaggedString { return sections; } - uint8_t getSectionIndex(std::size_t characterIndex) const { + std::size_t getSectionIndex(std::size_t characterIndex) const { return styledText.second.at(characterIndex); } @@ -88,7 +97,9 @@ struct TaggedString { void trim(); void verticalizePunctuation(); - + + bool hasMultipleUniqueSections() const noexcept; + private: StyledText styledText; std::vector<SectionOptions> sections; |