summaryrefslogtreecommitdiff
path: root/src/mbgl/text
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/text')
-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.cpp7
-rw-r--r--src/mbgl/text/tagged_string.hpp20
6 files changed, 34 insertions, 17 deletions
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..8c4e3b02e8 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, optional<Color> textColor) {
styledText.first += sectionText;
- sections.emplace_back(scale, fontStack);
+ sections.emplace_back(scale, fontStack, std::move(textColor));
styledText.second.resize(styledText.first.size(), sections.size() - 1);
}
@@ -26,7 +27,7 @@ void TaggedString::trim() {
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;
}
diff --git a/src/mbgl/text/tagged_string.hpp b/src/mbgl/text/tagged_string.hpp
index 476c2225f0..2607e10889 100644
--- a/src/mbgl/text/tagged_string.hpp
+++ b/src/mbgl/text/tagged_string.hpp
@@ -1,17 +1,23 @@
#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 {
struct SectionOptions {
- SectionOptions(double scale_, FontStackHash fontStackHash_)
- : scale(scale_), fontStackHash(fontStackHash_)
+ SectionOptions(double scale_, FontStack fontStack_, optional<Color> textColor_ = nullopt)
+ : scale(scale_),
+ fontStackHash(FontStackHasher()(fontStack_)),
+ fontStack(std::move(fontStack_)),
+ textColor(std::move(textColor_))
{}
double scale;
FontStackHash fontStackHash;
+ FontStack fontStack;
+ optional<Color> textColor;
};
/**
@@ -71,7 +77,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,
+ optional<Color> textColor_ = nullopt);
+
const SectionOptions& sectionAt(std::size_t index) const {
return sections.at(index);
}
@@ -88,7 +98,7 @@ struct TaggedString {
void trim();
void verticalizePunctuation();
-
+
private:
StyledText styledText;
std::vector<SectionOptions> sections;