summaryrefslogtreecommitdiff
path: root/src/mbgl/layout/symbol_instance.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/layout/symbol_instance.cpp')
-rw-r--r--src/mbgl/layout/symbol_instance.cpp175
1 files changed, 104 insertions, 71 deletions
diff --git a/src/mbgl/layout/symbol_instance.cpp b/src/mbgl/layout/symbol_instance.cpp
index 809aa2f451..6e2cc5af0c 100644
--- a/src/mbgl/layout/symbol_instance.cpp
+++ b/src/mbgl/layout/symbol_instance.cpp
@@ -9,45 +9,36 @@ using namespace style;
namespace {
const Shaping& getAnyShaping(const ShapedTextOrientations& shapedTextOrientations) {
- if (shapedTextOrientations.right) return shapedTextOrientations.right;
- if (shapedTextOrientations.center) return shapedTextOrientations.center;
- if (shapedTextOrientations.left) return shapedTextOrientations.left;
- if (shapedTextOrientations.vertical) return shapedTextOrientations.vertical;
+ if (shapedTextOrientations.right)
+ return shapedTextOrientations.right;
+ if (shapedTextOrientations.center)
+ return shapedTextOrientations.center;
+ if (shapedTextOrientations.left)
+ return shapedTextOrientations.left;
+ if (shapedTextOrientations.vertical)
+ return shapedTextOrientations.vertical;
return shapedTextOrientations.horizontal;
}
} // namespace
-SymbolInstance::SymbolInstance(Anchor& anchor_,
- GeometryCoordinates line_,
- const ShapedTextOrientations& shapedTextOrientations,
- optional<PositionedIcon> shapedIcon,
- const SymbolLayoutProperties::Evaluated& layout,
- const float layoutTextSize,
- const float textBoxScale_,
- const float textPadding,
- const SymbolPlacementType textPlacement,
- const std::array<float, 2> textOffset_,
- const float iconBoxScale,
- const float iconPadding,
- const std::array<float, 2> iconOffset_,
- const GlyphPositions& positions,
- const IndexedSubfeature& indexedFeature,
- const std::size_t layoutFeatureIndex_,
- const std::size_t dataFeatureIndex_,
- std::u16string key_,
- const float overscaling,
- const float rotate,
- float radialTextOffset_) :
- anchor(anchor_),
- line(line_),
+SymbolInstanceCommonData::SymbolInstanceCommonData(const GeometryCoordinates& line_,
+ const ShapedTextOrientations& shapedTextOrientations,
+ optional<PositionedIcon> shapedIcon,
+ const style::SymbolLayoutProperties::Evaluated& layout,
+ const float layoutTextSize,
+ const float textBoxScale_,
+ const style::SymbolPlacementType textPlacement,
+ const std::array<float, 2> textOffset_,
+ const std::array<float, 2> iconOffset_,
+ const GlyphPositions& positions,
+ const std::size_t layoutFeatureIndex_,
+ const std::size_t dataFeatureIndex_,
+ std::u16string key_,
+ float radialTextOffset_)
+ : line(line_),
hasText(false),
hasIcon(shapedIcon),
-
- // Create the collision features that will be used to check whether this symbol instance can be placed
- // As a collision approximation, we can use either the vertical or any of the horizontal versions of the feature
- textCollisionFeature(line_, anchor, getAnyShaping(shapedTextOrientations), textBoxScale_, textPadding, textPlacement, indexedFeature, overscaling, rotate),
- iconCollisionFeature(line_, anchor, shapedIcon, iconBoxScale, iconPadding, indexedFeature, rotate),
writingModes(WritingModeType::None),
layoutFeatureIndex(layoutFeatureIndex_),
dataFeatureIndex(dataFeatureIndex_),
@@ -56,51 +47,93 @@ SymbolInstance::SymbolInstance(Anchor& anchor_,
key(std::move(key_)),
textBoxScale(textBoxScale_),
radialTextOffset(radialTextOffset_),
- singleLine(shapedTextOrientations.singleLine) {
-
- // Create the quads used for rendering the icon and glyphs.
- if (shapedIcon) {
- iconQuad = getIconQuad(*shapedIcon, layout, layoutTextSize, shapedTextOrientations.horizontal);
- }
-
- bool singleLineInitialized = false;
- const auto initHorizontalGlyphQuads = [&] (SymbolQuads& quads, const Shaping& shaping) {
- writingModes |= WritingModeType::Horizontal;
- if (!singleLine) {
- quads = getGlyphQuads(shaping, textOffset, layout, textPlacement, positions);
- return;
+ singleLine(shapedTextOrientations.singleLine){
+
+ // Create the quads used for rendering the icon and glyphs.
+ if (shapedIcon) {
+ iconQuad =
+ getIconQuad(*shapedIcon, layout, layoutTextSize, shapedTextOrientations.horizontal);
}
- if (!singleLineInitialized) {
- rightJustifiedGlyphQuads = getGlyphQuads(shaping, textOffset, layout, textPlacement, positions);
- singleLineInitialized = true;
+
+ bool singleLineInitialized = false;
+ const auto initHorizontalGlyphQuads = [&](SymbolQuads& quads, const Shaping& shaping) {
+ writingModes |= WritingModeType::Horizontal;
+ if (!singleLine) {
+ quads = getGlyphQuads(shaping, textOffset, layout, textPlacement, positions);
+ return;
+ }
+ if (!singleLineInitialized) {
+ rightJustifiedGlyphQuads =
+ getGlyphQuads(shaping, textOffset, layout, textPlacement, positions);
+ singleLineInitialized = true;
+ }
+ };
+
+ if (shapedTextOrientations.right) {
+ initHorizontalGlyphQuads(rightJustifiedGlyphQuads, shapedTextOrientations.right);
}
- };
-
- if (shapedTextOrientations.right) {
- initHorizontalGlyphQuads(rightJustifiedGlyphQuads, shapedTextOrientations.right);
- }
-
- if (shapedTextOrientations.center) {
- initHorizontalGlyphQuads(centerJustifiedGlyphQuads, shapedTextOrientations.center);
- }
-
- if (shapedTextOrientations.left) {
- initHorizontalGlyphQuads(leftJustifiedGlyphQuads, shapedTextOrientations.left);
- }
-
- if (shapedTextOrientations.vertical) {
- writingModes |= WritingModeType::Vertical;
- verticalGlyphQuads = getGlyphQuads(shapedTextOrientations.vertical, textOffset, layout, textPlacement, positions);
+
+ if (shapedTextOrientations.center) {
+ initHorizontalGlyphQuads(centerJustifiedGlyphQuads, shapedTextOrientations.center);
+ }
+
+ if (shapedTextOrientations.left) {
+ initHorizontalGlyphQuads(leftJustifiedGlyphQuads, shapedTextOrientations.left);
+ }
+
+ if (shapedTextOrientations.vertical) {
+ writingModes |= WritingModeType::Vertical;
+ verticalGlyphQuads = getGlyphQuads(shapedTextOrientations.vertical, textOffset, layout,
+ textPlacement, positions);
+ }
+
+ // 'hasText' depends on finding at least one glyph in the shaping that's also in the
+ // GlyphPositionMap
+ hasText = !rightJustifiedGlyphQuads.empty() || !centerJustifiedGlyphQuads.empty() ||
+ !leftJustifiedGlyphQuads.empty() || !verticalGlyphQuads.empty();
}
-
- // 'hasText' depends on finding at least one glyph in the shaping that's also in the GlyphPositionMap
- hasText = !rightJustifiedGlyphQuads.empty() || !centerJustifiedGlyphQuads.empty() || !leftJustifiedGlyphQuads.empty() || !verticalGlyphQuads.empty();
+
+SymbolInstance::SymbolInstance(const Anchor& anchor_,
+ std::shared_ptr<SymbolInstanceCommonData> data_,
+ const ShapedTextOrientations& shapedTextOrientations,
+ optional<PositionedIcon> shapedIcon,
+ const float textPadding,
+ const style::SymbolPlacementType textPlacement,
+ const float iconBoxScale,
+ const float iconPadding,
+ const IndexedSubfeature& indexedFeature,
+ const float overscaling,
+ const float rotate)
+ : anchor(std::move(anchor_)),
+ commonData(std::move(data_)),
+ // Create the collision features that will be used to check whether this symbol instance can
+ // be placedc As a collision approximation, we can use either the vertical or any of the
+ // horizontal versions of the feature
+ textCollisionFeature(commonData->line,
+ anchor,
+ getAnyShaping(shapedTextOrientations),
+ commonData->textBoxScale,
+ textPadding,
+ textPlacement,
+ indexedFeature,
+ overscaling,
+ rotate),
+ iconCollisionFeature(commonData->line,
+ anchor,
+ shapedIcon,
+ iconBoxScale,
+ iconPadding,
+ indexedFeature,
+ rotate) {
}
optional<size_t> SymbolInstance::getDefaultHorizontalPlacedTextIndex() const {
- if (placedRightTextIndex) return placedRightTextIndex;
- if (placedCenterTextIndex) return placedCenterTextIndex;
- if (placedLeftTextIndex) return placedLeftTextIndex;
+ if (placedRightTextIndex)
+ return placedRightTextIndex;
+ if (placedCenterTextIndex)
+ return placedCenterTextIndex;
+ if (placedLeftTextIndex)
+ return placedLeftTextIndex;
return nullopt;
}
} // namespace mbgl