summaryrefslogtreecommitdiff
path: root/src/mbgl/text
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/text')
-rw-r--r--src/mbgl/text/bidi.hpp2
-rw-r--r--src/mbgl/text/glyph.hpp8
-rw-r--r--src/mbgl/text/quads.cpp2
-rw-r--r--src/mbgl/text/quads.hpp7
-rw-r--r--src/mbgl/text/shaping.cpp7
-rw-r--r--src/mbgl/text/tagged_string.cpp24
-rw-r--r--src/mbgl/text/tagged_string.hpp25
7 files changed, 54 insertions, 21 deletions
diff --git a/src/mbgl/text/bidi.hpp b/src/mbgl/text/bidi.hpp
index 5ce2887db8..8680e6f7e5 100644
--- a/src/mbgl/text/bidi.hpp
+++ b/src/mbgl/text/bidi.hpp
@@ -18,7 +18,7 @@ std::u16string applyArabicShaping(const std::u16string&);
// the styling options to use for rendering that code point
// The data structure is intended to accomodate the reordering/interleaving
// of formatting that can happen when BiDi rearranges inputs
-using StyledText = std::pair<std::u16string, std::vector<uint8_t>>;
+using StyledText = std::pair<std::u16string, std::vector<std::size_t>>;
class BiDi : private util::noncopyable {
public:
diff --git a/src/mbgl/text/glyph.hpp b/src/mbgl/text/glyph.hpp
index 034784dc24..c97b242c10 100644
--- a/src/mbgl/text/glyph.hpp
+++ b/src/mbgl/text/glyph.hpp
@@ -19,7 +19,7 @@ namespace mbgl {
using GlyphID = char16_t;
using GlyphIDs = std::set<GlyphID>;
-
+
// Note: this only works for the BMP
GlyphRange getGlyphRange(GlyphID glyph);
@@ -59,8 +59,8 @@ using GlyphMap = std::map<FontStackHash, Glyphs>;
class PositionedGlyph {
public:
- explicit PositionedGlyph(GlyphID glyph_, float x_, float y_, bool vertical_, FontStackHash font_, float scale_)
- : glyph(glyph_), x(x_), y(y_), vertical(vertical_), font(font_), scale(scale_)
+ explicit PositionedGlyph(GlyphID glyph_, float x_, float y_, bool vertical_, FontStackHash font_, float scale_, std::size_t sectionIndex_ = 0)
+ : glyph(glyph_), x(x_), y(y_), vertical(vertical_), font(font_), scale(scale_), sectionIndex(sectionIndex_)
{}
GlyphID glyph = 0;
@@ -70,6 +70,8 @@ public:
FontStackHash font = 0;
float scale = 0.0;
+ // Maps positioned glyph to TaggedString section
+ std::size_t sectionIndex;
};
enum class WritingModeType : uint8_t;
diff --git a/src/mbgl/text/quads.cpp b/src/mbgl/text/quads.cpp
index 9d582f14d6..ec0045caad 100644
--- a/src/mbgl/text/quads.cpp
+++ b/src/mbgl/text/quads.cpp
@@ -172,7 +172,7 @@ SymbolQuads getGlyphQuads(const Shaping& shapedText,
br = util::matrixMultiply(matrix, br);
}
- quads.emplace_back(tl, tr, bl, br, rect, shapedText.writingMode, glyphOffset);
+ quads.emplace_back(tl, tr, bl, br, rect, shapedText.writingMode, glyphOffset, positionedGlyph.sectionIndex);
}
return quads;
diff --git a/src/mbgl/text/quads.hpp b/src/mbgl/text/quads.hpp
index 44a35a5014..f41a4fec66 100644
--- a/src/mbgl/text/quads.hpp
+++ b/src/mbgl/text/quads.hpp
@@ -20,14 +20,16 @@ public:
Point<float> br_,
Rect<uint16_t> tex_,
WritingModeType writingMode_,
- Point<float> glyphOffset_)
+ Point<float> glyphOffset_,
+ size_t sectionIndex_ = 0)
: tl(std::move(tl_)),
tr(std::move(tr_)),
bl(std::move(bl_)),
br(std::move(br_)),
tex(std::move(tex_)),
writingMode(writingMode_),
- glyphOffset(glyphOffset_) {}
+ glyphOffset(glyphOffset_),
+ sectionIndex(sectionIndex_){}
Point<float> tl;
Point<float> tr;
@@ -36,6 +38,7 @@ public:
Rect<uint16_t> tex;
WritingModeType writingMode;
Point<float> glyphOffset;
+ size_t sectionIndex;
};
using SymbolQuads = std::vector<SymbolQuad>;
diff --git a/src/mbgl/text/shaping.cpp b/src/mbgl/text/shaping.cpp
index 3a6335955b..02dbf146e1 100644
--- a/src/mbgl/text/shaping.cpp
+++ b/src/mbgl/text/shaping.cpp
@@ -299,7 +299,8 @@ void shapeLines(Shaping& shaping,
std::size_t lineStartIndex = shaping.positionedGlyphs.size();
for (std::size_t i = 0; i < line.length(); i++) {
- const SectionOptions& section = line.getSection(i);
+ const std::size_t sectionIndex = line.getSectionIndex(i);
+ const SectionOptions& section = line.sectionAt(sectionIndex);
char16_t codePoint = line.getCharCodeAt(i);
auto glyphs = glyphMap.find(section.fontStackHash);
if (glyphs == glyphMap.end()) {
@@ -318,10 +319,10 @@ void shapeLines(Shaping& shaping,
const Glyph& glyph = **it->second;
if (writingMode == WritingModeType::Horizontal || !util::i18n::hasUprightVerticalOrientation(codePoint)) {
- shaping.positionedGlyphs.emplace_back(codePoint, x, y + baselineOffset, false, section.fontStackHash, section.scale);
+ shaping.positionedGlyphs.emplace_back(codePoint, x, y + baselineOffset, false, section.fontStackHash, section.scale, sectionIndex);
x += glyph.metrics.advance * section.scale + spacing;
} else {
- shaping.positionedGlyphs.emplace_back(codePoint, x, baselineOffset, true, section.fontStackHash, section.scale);
+ shaping.positionedGlyphs.emplace_back(codePoint, x, baselineOffset, true, section.fontStackHash, section.scale, sectionIndex);
x += verticalHeight * section.scale + spacing;
}
}
diff --git a/src/mbgl/text/tagged_string.cpp b/src/mbgl/text/tagged_string.cpp
index 851e011c4f..3755ad3a28 100644
--- a/src/mbgl/text/tagged_string.cpp
+++ b/src/mbgl/text/tagged_string.cpp
@@ -1,11 +1,12 @@
#include <mbgl/text/tagged_string.hpp>
+#include <mbgl/math/minmax.hpp>
#include <mbgl/util/i18n.hpp>
namespace mbgl {
-void TaggedString::addSection(const std::u16string& sectionText, double scale, FontStackHash fontStack) {
+void TaggedString::addSection(const std::u16string& sectionText, double scale, FontStack fontStack, const optional<FormattedSectionID>& id) {
styledText.first += sectionText;
- sections.emplace_back(scale, fontStack);
+ sections.emplace_back(scale, fontStack, id);
styledText.second.resize(styledText.first.size(), sections.size() - 1);
}
@@ -19,14 +20,14 @@ void TaggedString::trim() {
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);
+ styledText.second = std::vector<std::size_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);
+ maxScale = util::max(maxScale, getSection(i).scale);
}
return maxScale;
}
@@ -36,4 +37,19 @@ void TaggedString::verticalizePunctuation() {
styledText.first = util::i18n::verticalizePunctuation(styledText.first);
}
+bool TaggedString::hasMultipleUniqueSections() const noexcept {
+ if (sections.size() < 2) {
+ return false;
+ }
+
+ const auto& id = sections.at(0).id;
+ for (std::size_t i = 1; i < sections.size(); ++i) {
+ if (id != sections.at(i).id) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
} // namespace mbgl
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;