summaryrefslogtreecommitdiff
path: root/src/mbgl/text/glyph_atlas.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/text/glyph_atlas.cpp')
-rw-r--r--src/mbgl/text/glyph_atlas.cpp79
1 files changed, 40 insertions, 39 deletions
diff --git a/src/mbgl/text/glyph_atlas.cpp b/src/mbgl/text/glyph_atlas.cpp
index a08455ec63..6636c23f34 100644
--- a/src/mbgl/text/glyph_atlas.cpp
+++ b/src/mbgl/text/glyph_atlas.cpp
@@ -6,58 +6,59 @@ namespace mbgl {
static constexpr uint32_t padding = 1;
-GlyphAtlas makeGlyphAtlas(const Glyphs& glyphs) {
+GlyphAtlas makeGlyphAtlas(const GlyphMap& glyphs) {
GlyphAtlas result;
mapbox::ShelfPack::ShelfPackOptions options;
options.autoResize = true;
mapbox::ShelfPack pack(0, 0, options);
- std::vector<mapbox::Bin> bins;
- bins.reserve(glyphs.size());
+ for (const auto& glyphMapEntry : glyphs) {
+ const FontStack& fontStack = glyphMapEntry.first;
+ GlyphPositionMap& positions = result.positions[fontStack];
- for (const auto& entry : glyphs) {
- if (entry.second && (*entry.second)->bitmap.valid()) {
- const Glyph& glyph = **entry.second;
- bins.emplace_back(glyph.id,
- glyph.bitmap.size.width + 2 * padding,
- glyph.bitmap.size.height + 2 * padding);
- }
- }
-
- mapbox::ShelfPack::PackOptions packOptions;
- packOptions.inPlace = true;
- pack.pack(bins, packOptions);
+ for (const auto& entry : glyphMapEntry.second) {
+ if (entry.second && (*entry.second)->bitmap.valid()) {
+ const Glyph& glyph = **entry.second;
- result.image = AlphaImage({
- static_cast<uint32_t>(pack.width()),
- static_cast<uint32_t>(pack.height())
- });
+ const mapbox::Bin& bin = *pack.packOne(-1,
+ glyph.bitmap.size.width + 2 * padding,
+ glyph.bitmap.size.height + 2 * padding);
- for (const auto& bin : bins) {
- const Glyph& glyph = **glyphs.at(bin.id);
+ result.image.resize({
+ static_cast<uint32_t>(pack.width()),
+ static_cast<uint32_t>(pack.height())
+ });
- AlphaImage::copy(glyph.bitmap,
- result.image,
- { 0, 0 },
- {
- bin.x + padding,
- bin.y + padding
- },
- glyph.bitmap.size);
+ AlphaImage::copy(glyph.bitmap,
+ result.image,
+ { 0, 0 },
+ {
+ bin.x + padding,
+ bin.y + padding
+ },
+ glyph.bitmap.size);
- result.positions.emplace(glyph.id,
- GlyphPosition {
- Rect<uint16_t> {
- static_cast<uint16_t>(bin.x),
- static_cast<uint16_t>(bin.y),
- static_cast<uint16_t>(bin.w),
- static_cast<uint16_t>(bin.h)
- },
- glyph.metrics
- });
+ positions.emplace(glyph.id,
+ GlyphPosition {
+ Rect<uint16_t> {
+ static_cast<uint16_t>(bin.x),
+ static_cast<uint16_t>(bin.y),
+ static_cast<uint16_t>(bin.w),
+ static_cast<uint16_t>(bin.h)
+ },
+ glyph.metrics
+ });
+ }
+ }
}
+// pack.shrink();
+// result.image.resize({
+// static_cast<uint32_t>(pack.width()),
+// static_cast<uint32_t>(pack.height())
+// });
+
return result;
}