update symbol placement to be more like js

This commit is contained in:
Konstantin Käfer
2014-08-04 18:24:22 +02:00
parent 9dd50a29e1
commit 36181b0922
18 changed files with 576 additions and 573 deletions

View File

@@ -7,7 +7,7 @@
namespace mbgl {
Anchors interpolate(const std::vector<Coordinate> &vertices, float spacing,
float minScale = 0.0f, int start = 0);
float minScale, float maxScale, float tilePixelRatio, int start = 0);
}
#endif

View File

@@ -4,7 +4,7 @@
#include <mbgl/map/vector_tile.hpp>
#include <mbgl/style/filter_expression.hpp>
#include <mbgl/text/glyph.hpp>
#include <mbgl/text/placement.hpp>
#include <mbgl/text/collision.hpp>
#include <cstdint>
#include <iosfwd>
@@ -61,7 +61,7 @@ private:
std::shared_ptr<SpriteAtlas> spriteAtlas;
std::shared_ptr<Sprite> sprite;
Placement placement;
Collision collision;
};
}

View File

@@ -86,7 +86,7 @@ private:
const FilterExpression& filterExpression;
};
std::ostream& operator<<(std::ostream&, const GlyphPlacement& placement);
std::ostream& operator<<(std::ostream&, const PositionedGlyph& placement);
class VectorTileLayer {
public:

View File

@@ -21,7 +21,7 @@ class Style;
class TextShader;
class IconShader;
class DotShader;
class Placement;
class Collision;
class SpriteAtlas;
class Sprite;
class GlyphAtlas;
@@ -35,13 +35,23 @@ public:
std::string sprite;
};
class Symbol {
public:
vec2<float> tl, tr, bl, br;
Rect<uint16_t> tex;
float angle;
float minScale = 0.0f;
float maxScale = std::numeric_limits<float>::infinity();
CollisionAnchor anchor;
};
typedef std::vector<Symbol> Symbols;
class SymbolBucket : public Bucket {
public:
SymbolBucket(
TextVertexBuffer &textVertexBuffer,
IconVertexBuffer& iconVertexBuffer,
TriangleElementsBuffer &triangleElementsBuffer,
const StyleBucketSymbol &properties, Placement &placement);
SymbolBucket(const StyleBucketSymbol &properties, Collision &collision);
virtual void render(Painter &painter, std::shared_ptr<StyleLayer> layer_desc, const Tile::ID &id);
virtual bool hasData() const;
@@ -55,29 +65,31 @@ public:
void addGlyphs(const PlacedGlyphs &glyphs, float placementZoom, PlacementRange placementRange,
float zoom);
void drawGlyphs(TextShader &shader);
void drawIcons(IconShader& shader);
void drawIcons(DotShader& shader);
private:
std::vector<SymbolFeature> processFeatures(const VectorTileLayer &layer, const FilterExpression &filter, GlyphStore &glyphStore, const Sprite &sprite);
void addFeature(const pbf &geom_pbf, const Shaping &shaping, const Rect<uint16_t> &image);
void addFeature(const std::vector<Coordinate> &line, const Shaping &shaping, const Rect<uint16_t> &image);
void addFeature(const pbf &geom_pbf, const Shaping &shaping, const GlyphPositions &face, const Rect<uint16_t> &image);
void addFeature(const std::vector<Coordinate> &line, const Shaping &shaping, const GlyphPositions &face, const Rect<uint16_t> &image);
void addGlyph(uint64_t tileid, const std::string stackname, const std::u32string &string,
// Adds placed items to the buffer.
template <typename Buffer>
void addSymbols(Buffer &buffer, const PlacedGlyphs &symbols, float scale, PlacementRange placementRange);
// Adds glyphs to the glyph atlas so that they have a left/top/width/height coordinates associated to them that we can use for writing to a buffer.
void addGlyphsToAtlas(uint64_t tileid, const std::string stackname, const std::u32string &string,
const FontStack &fontStack, GlyphAtlas &glyphAtlas, GlyphPositions &face);
void addFeature(const pbf &geom_pbf, const GlyphPositions &face, const Shaping &shaping);
public:
const StyleBucketSymbol &properties;
private:
Placement &placement;
Collision &collision;
struct {
TextVertexBuffer vertices;

View File

@@ -48,6 +48,7 @@ public:
RotationAlignmentType rotation_alignment = RotationAlignmentType::Viewport;
float max_size = 1.0f;
std::string image;
float rotate = 0.0f;
float padding = 2.0f;
bool keep_upright = false;
vec2<float> offset = {0, 0};

View File

@@ -11,20 +11,17 @@ public:
Collision(float zoom, float tileExtent, float tileSize, float placementDepth = 1);
~Collision();
PlacementProperty place(const GlyphBoxes &boxes, const CollisionAnchor &anchor,
float minPlacementScale, float maxPlacementScale, float padding,
bool horizontal, bool allowOverlap, bool ignorePlacement);
float getPlacementScale(const GlyphBoxes &glyphs, float minPlacementScale,
float maxPlacementScale, float pad);
PlacementRange getPlacementRange(const GlyphBoxes &glyphs,
float placementScale, bool horizontal);
void insert(const GlyphBoxes &glyphs, const CollisionAnchor &anchor,
float placementScale, const PlacementRange &placementRange,
bool horizontal, float padding);
float getPlacementScale(const GlyphBoxes &glyphs, float minPlacementScale);
PlacementRange getPlacementRange(const GlyphBoxes &glyphs, float placementScale,
bool horizontal);
void insert(const GlyphBoxes &glyphs, const CollisionAnchor &anchor, float placementScale,
const PlacementRange &placementRange, bool horizontal);
private:
void *hTree;
void *cTree;
public:
const float tilePixelRatio;
const float zoom;
const float maxPlacementScale;

View File

@@ -44,18 +44,17 @@ struct Glyph {
typedef std::map<uint32_t, Glyph> GlyphPositions;
class GlyphPlacement {
class PositionedGlyph {
public:
inline explicit GlyphPlacement(uint32_t face, uint32_t glyph, uint32_t x, uint32_t y)
: face(face), glyph(glyph), x(x), y(y) {}
inline explicit PositionedGlyph(uint32_t glyph, uint32_t x, uint32_t y)
: glyph(glyph), x(x), y(y) {}
uint32_t face = 0;
uint32_t glyph = 0;
int32_t x = 0;
int32_t y = 0;
};
typedef std::vector<GlyphPlacement> Shaping;
typedef std::vector<PositionedGlyph> Shaping;
}
#endif

View File

@@ -1,36 +1,30 @@
#ifndef MBGL_TEXT_PLACEMENT
#define MBGL_TEXT_PLACEMENT
#include <mbgl/text/collision.hpp>
#include <mbgl/geometry/geometry.hpp>
#include <mbgl/util/vec.hpp>
#include <mbgl/text/types.hpp>
#include <mbgl/text/glyph.hpp>
#include <vector>
#include <mbgl/util/vec.hpp>
namespace mbgl {
class SymbolBucket;
struct Anchor;
class StyleBucketSymbol;
class Placement {
public:
Placement(int8_t zoom, float placementDepth);
static Placement getIcon(Anchor &anchor, const Rect<uint16_t> &image, float iconBoxScale,
const std::vector<Coordinate> &line, const StyleBucketSymbol &props);
void addFeature(SymbolBucket &bucket, const std::vector<Coordinate> &line,
const StyleBucketSymbol &info,
const GlyphPositions &face,
const Shaping &shaping);
static Placement getGlyphs(Anchor &anchor, const vec2<float> &origin, const Shaping &shaping,
const GlyphPositions &face, float boxScale, bool horizontal,
const std::vector<Coordinate> &line, const StyleBucketSymbol &props);
private:
const int8_t zoom;
Collision collision;
const float zOffset;
const float maxPlacementScale;
static const float globalMinScale;
public:
static const int tileExtent;
static const int glyphSize;
static const float minScale;
GlyphBoxes boxes;
PlacedGlyphs shapes;
float minScale;
};
}

View File

@@ -37,16 +37,23 @@ struct CollisionRect {
// These are the glyph boxes that we want to have placed.
struct GlyphBox {
explicit GlyphBox() {}
explicit GlyphBox(const CollisionRect &box, float minScale) : box(box), minScale(minScale) {}
explicit GlyphBox(const CollisionRect &box, float minScale, float maxScale,
const CollisionAnchor &anchor)
: anchor(anchor), box(box), minScale(minScale), maxScale(maxScale) {}
explicit GlyphBox(const CollisionRect &box,
const CollisionAnchor &anchor,
float minScale,
float maxScale,
float padding)
: box(box), anchor(anchor), minScale(minScale), maxScale(maxScale), padding(padding) {}
explicit GlyphBox(const CollisionRect &box,
float minScale,
float padding)
: box(box), minScale(minScale), padding(padding) {}
CollisionAnchor anchor;
CollisionRect box;
boost::optional<CollisionRect> hBox;
CollisionAnchor anchor;
float minScale = 0.0f;
float maxScale = std::numeric_limits<float>::infinity();
float padding = 0.0f;
boost::optional<CollisionRect> hBox;
};
typedef std::vector<GlyphBox> GlyphBoxes;
@@ -56,19 +63,23 @@ typedef std::vector<GlyphBox> GlyphBoxes;
struct PlacedGlyph {
explicit PlacedGlyph(const vec2<float> &tl, const vec2<float> &tr,
const vec2<float> &bl, const vec2<float> &br,
const Rect<uint16_t> &tex, float angle, const GlyphBox &glyphBox)
const Rect<uint16_t> &tex, float angle, const vec2<float> &anchor,
float minScale, float maxScale)
: tl(tl),
tr(tr),
bl(bl),
br(br),
tex(tex),
angle(angle),
glyphBox(glyphBox) {}
anchor(anchor),
minScale(minScale),
maxScale(maxScale) {}
vec2<float> tl, tr, bl, br;
Rect<uint16_t> tex;
float angle;
GlyphBox glyphBox;
vec2<float> anchor;
float minScale, maxScale;
};
typedef std::vector<PlacedGlyph> PlacedGlyphs;