This repository was archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathglyph_atlas.cpp
More file actions
62 lines (49 loc) · 2.27 KB
/
Copy pathglyph_atlas.cpp
File metadata and controls
62 lines (49 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <mbgl/text/glyph_atlas.hpp>
#include <mapbox/shelf-pack.hpp>
namespace mbgl {
static constexpr uint32_t padding = 1;
GlyphAtlas makeGlyphAtlas(const GlyphMap& glyphs) {
GlyphAtlas result;
mapbox::ShelfPack::ShelfPackOptions options;
options.autoResize = true;
mapbox::ShelfPack pack(0, 0, options);
for (const auto& glyphMapEntry : glyphs) {
FontStackHash fontStack = glyphMapEntry.first;
GlyphPositionData& positions = result.positions[fontStack];
positions.ascender = glyphMapEntry.second.ascender;
positions.descender = glyphMapEntry.second.descender;
for (const auto& entry : glyphMapEntry.second.glyphs) {
if (entry.second && (*entry.second)->bitmap.valid()) {
const Glyph& glyph = **entry.second;
const mapbox::Bin& bin = *pack.packOne(-1,
glyph.bitmap.size.width + 2 * padding,
glyph.bitmap.size.height + 2 * padding);
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);
positions.glyphPositionMap.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;
}
} // namespace mbgl