Skip to content

Commit

Permalink
Add textFitWidth and textFitHeight Properties to Sprites (#2780)
Browse files Browse the repository at this point in the history
Co-authored-by: Xiaolian Qin <[email protected]>
  • Loading branch information
qqz003 and Xiaolian Qin authored Sep 13, 2024
1 parent 814e101 commit cb38119
Show file tree
Hide file tree
Showing 58 changed files with 2,116 additions and 103 deletions.
31 changes: 27 additions & 4 deletions include/mbgl/style/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ namespace style {
using ImageStretch = std::pair<float, float>;
using ImageStretches = std::vector<ImageStretch>;

enum class TextFit {
stretchOrShrink,
stretchOnly,
proportional
};

class ImageContent {
public:
float left;
Expand All @@ -34,15 +40,26 @@ class Image {
bool sdf,
ImageStretches stretchX = {},
ImageStretches stretchY = {},
const std::optional<ImageContent>& content = std::nullopt);
const std::optional<ImageContent>& content = std::nullopt,
const std::optional<TextFit>& textFitWidth = std::nullopt,
const std::optional<TextFit>& textFitHeight = std::nullopt);
Image(std::string id,
PremultipliedImage&& image,
float pixelRatio,
ImageStretches stretchX = {},
ImageStretches stretchY = {},
const std::optional<ImageContent>& content = std::nullopt)
: Image(std::move(id), std::move(image), pixelRatio, false, std::move(stretchX), std::move(stretchY), content) {
}
const std::optional<ImageContent>& content = std::nullopt,
const std::optional<TextFit>& textFitWidth = std::nullopt,
const std::optional<TextFit>& textFitHeight = std::nullopt)
: Image(std::move(id),
std::move(image),
pixelRatio,
false,
std::move(stretchX),
std::move(stretchY),
content,
textFitWidth,
textFitHeight) {}
Image(const Image&);

std::string getID() const;
Expand All @@ -63,6 +80,12 @@ class Image {
/// The space where text can be fit into this image.
const std::optional<ImageContent>& getContent() const;

/// The constraints on the horizontal scaling of the image when `icon-text-fit` is used
const std::optional<TextFit>& getTextFitWidth() const;

/// The constraints on the vertical scaling of the image when `icon-text-fit` is used
const std::optional<TextFit>& getTextFitHeight() const;

class Impl;
Immutable<Impl> baseImpl;
explicit Image(Immutable<Impl> baseImpl_)
Expand Down
Binary file modified metrics/cache-style.db
Binary file not shown.
1 change: 1 addition & 0 deletions metrics/ignores/platform-all.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"render-tests/fill-pattern/update-feature-state": "https://github.com/mapbox/mapbox-gl-native/issues/15895",
"render-tests/geojson/inline-linestring-fill": "current behavior is arbitrary",
"render-tests/icon-text-fit/text-variable-anchor-overlap": "https://github.com/mapbox/mapbox-gl-native/issues/15809",
"render-tests/icon-text-fit/textFit-grid-long": "Needs to be investigated and fixed.",
"render-tests/mixed-zoom/z10-z11": "https://github.com/mapbox/mapbox-gl-native/issues/10397",
"render-tests/raster-masking/overlapping-zoom": "https://github.com/mapbox/mapbox-gl-native/issues/10195",
"render-tests/real-world/bangkok": "https://github.com/mapbox/mapbox-gl-native/issues/10412",
Expand Down
85 changes: 85 additions & 0 deletions metrics/integration/geojson/grid-tall.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {
"cell": "top-left"
},
"geometry": {
"type": "Point",
"coordinates": [ -70, 60 ]
}
}, {
"type": "Feature",
"properties": {
"cell": "top-middle"
},
"geometry": {
"type": "Point",
"coordinates": [ 0, 60 ]
}
}, {
"type": "Feature",
"properties": {
"cell": "top-right"
},
"geometry": {
"type": "Point",
"coordinates": [ 70, 60 ]
}
}, {
"type": "Feature",
"properties": {
"cell": "middle-left"
},
"geometry": {
"type": "Point",
"coordinates": [ -70, 0 ]
}
}, {
"type": "Feature",
"properties": {
"cell": "middle-middle"
},
"geometry": {
"type": "Point",
"coordinates": [ 0, 0 ]
}
}, {
"type": "Feature",
"properties": {
"cell": "middle-right"
},
"geometry": {
"type": "Point",
"coordinates": [ 70, 0 ]
}
}, {
"type": "Feature",
"properties": {
"cell": "bottom-left"
},
"geometry": {
"type": "Point",
"coordinates": [ -70, -60 ]
}
}, {
"type": "Feature",
"properties": {
"cell": "bottom-middle"
},
"geometry": {
"type": "Point",
"coordinates": [ 0, -60 ]
}
}, {
"type": "Feature",
"properties": {
"cell": "bottom-right"
},
"geometry": {
"type": "Point",
"coordinates": [ 70, -60 ]
}
}]
}
85 changes: 85 additions & 0 deletions metrics/integration/geojson/grid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {
"cell": "top-left"
},
"geometry": {
"type": "Point",
"coordinates": [ -70, 35 ]
}
}, {
"type": "Feature",
"properties": {
"cell": "top-middle"
},
"geometry": {
"type": "Point",
"coordinates": [ 0, 35 ]
}
}, {
"type": "Feature",
"properties": {
"cell": "top-right"
},
"geometry": {
"type": "Point",
"coordinates": [ 70, 35 ]
}
}, {
"type": "Feature",
"properties": {
"cell": "middle-left"
},
"geometry": {
"type": "Point",
"coordinates": [ -70, 0 ]
}
}, {
"type": "Feature",
"properties": {
"cell": "middle-middle"
},
"geometry": {
"type": "Point",
"coordinates": [ 0, 0 ]
}
}, {
"type": "Feature",
"properties": {
"cell": "middle-right"
},
"geometry": {
"type": "Point",
"coordinates": [ 70, 0 ]
}
}, {
"type": "Feature",
"properties": {
"cell": "bottom-left"
},
"geometry": {
"type": "Point",
"coordinates": [ -70, -35 ]
}
}, {
"type": "Feature",
"properties": {
"cell": "bottom-middle"
},
"geometry": {
"type": "Point",
"coordinates": [ 0, -35 ]
}
}, {
"type": "Feature",
"properties": {
"cell": "bottom-right"
},
"geometry": {
"type": "Point",
"coordinates": [ 70, -35 ]
}
}]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit cb38119

Please sign in to comment.