Clean up GlyphAtlas
This commit is contained in:
@@ -18,26 +18,43 @@ GlyphAtlas::GlyphAtlas(uint16_t width_, uint16_t height_)
|
||||
dirty(true) {
|
||||
}
|
||||
|
||||
Rect<uint16_t> GlyphAtlas::addGlyph(uint64_t tile_id, const std::string& face_name,
|
||||
const SDFGlyph& glyph)
|
||||
void GlyphAtlas::addGlyphs(uint64_t tileID,
|
||||
const std::u32string& text,
|
||||
const std::string& stackName,
|
||||
const FontStack& fontStack,
|
||||
GlyphPositions& face)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
return addGlyph_impl(tile_id, face_name, glyph);
|
||||
|
||||
const std::map<uint32_t, SDFGlyph>& sdfs = fontStack.getSDFs();
|
||||
|
||||
for (uint32_t chr : text)
|
||||
{
|
||||
auto sdf_it = sdfs.find(chr);
|
||||
if (sdf_it == sdfs.end()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const SDFGlyph& sdf = sdf_it->second;
|
||||
Rect<uint16_t> rect = addGlyph(tileID, stackName, sdf);
|
||||
face.emplace(chr, Glyph{rect, sdf.metrics});
|
||||
}
|
||||
}
|
||||
|
||||
Rect<uint16_t> GlyphAtlas::addGlyph_impl(uint64_t tile_id, const std::string& face_name,
|
||||
Rect<uint16_t> GlyphAtlas::addGlyph(uint64_t tileID,
|
||||
const std::string& stackName,
|
||||
const SDFGlyph& glyph)
|
||||
{
|
||||
// Use constant value for now.
|
||||
const uint8_t buffer = 3;
|
||||
|
||||
std::map<uint32_t, GlyphValue>& face = index[face_name];
|
||||
std::map<uint32_t, GlyphValue>& face = index[stackName];
|
||||
std::map<uint32_t, GlyphValue>::iterator it = face.find(glyph.id);
|
||||
|
||||
// The glyph is already in this texture.
|
||||
if (it != face.end()) {
|
||||
GlyphValue& value = it->second;
|
||||
value.ids.insert(tile_id);
|
||||
value.ids.insert(tileID);
|
||||
return value.rect;
|
||||
}
|
||||
|
||||
@@ -68,7 +85,7 @@ Rect<uint16_t> GlyphAtlas::addGlyph_impl(uint64_t tile_id, const std::string& fa
|
||||
assert(rect.x + rect.w <= width);
|
||||
assert(rect.y + rect.h <= height);
|
||||
|
||||
face.emplace(glyph.id, GlyphValue { rect, tile_id });
|
||||
face.emplace(glyph.id, GlyphValue { rect, tileID });
|
||||
|
||||
// Copy the bitmap
|
||||
char *target = data.get();
|
||||
@@ -86,23 +103,6 @@ Rect<uint16_t> GlyphAtlas::addGlyph_impl(uint64_t tile_id, const std::string& fa
|
||||
return rect;
|
||||
}
|
||||
|
||||
void GlyphAtlas::addGlyphs(uint64_t tileid, std::u32string const& text, std::string const& stackname, FontStack const& fontStack, GlyphPositions & face)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
|
||||
std::map<uint32_t, SDFGlyph> const& sdfs = fontStack.getSDFs();
|
||||
for (uint32_t chr : text)
|
||||
{
|
||||
auto sdf_it = sdfs.find(chr);
|
||||
if (sdf_it != sdfs.end())
|
||||
{
|
||||
SDFGlyph const& sdf = sdf_it->second;
|
||||
Rect<uint16_t> rect = addGlyph_impl(tileid, stackname, sdf);
|
||||
face.emplace(chr, Glyph{rect, sdf.metrics});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GlyphAtlas::removeGlyphs(uint64_t tile_id) {
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
|
||||
|
||||
@@ -15,6 +15,19 @@ namespace mbgl {
|
||||
|
||||
class GlyphAtlas : public util::noncopyable {
|
||||
public:
|
||||
GlyphAtlas(uint16_t width, uint16_t height);
|
||||
|
||||
void addGlyphs(uint64_t tileID,
|
||||
const std::u32string& text,
|
||||
const std::string& stackName,
|
||||
const FontStack&,
|
||||
GlyphPositions&);
|
||||
void removeGlyphs(uint64_t tile_id);
|
||||
|
||||
void bind();
|
||||
|
||||
const uint16_t width = 0;
|
||||
const uint16_t height = 0;
|
||||
|
||||
private:
|
||||
struct GlyphValue {
|
||||
@@ -24,23 +37,10 @@ private:
|
||||
std::set<uint64_t> ids;
|
||||
};
|
||||
|
||||
Rect<uint16_t> addGlyph_impl(uint64_t tile_id, const std::string& face_name,
|
||||
const SDFGlyph& glyph);
|
||||
public:
|
||||
GlyphAtlas(uint16_t width, uint16_t height);
|
||||
Rect<uint16_t> addGlyph(uint64_t tileID,
|
||||
const std::string& stackName,
|
||||
const SDFGlyph&);
|
||||
|
||||
Rect<uint16_t> addGlyph(uint64_t tile_id, const std::string& face_name,
|
||||
const SDFGlyph& glyph);
|
||||
void addGlyphs(uint64_t tileid, std::u32string const& text, std::string const& stackname,
|
||||
FontStack const& fontStack, GlyphPositions & face);
|
||||
void removeGlyphs(uint64_t tile_id);
|
||||
void bind();
|
||||
|
||||
public:
|
||||
const uint16_t width = 0;
|
||||
const uint16_t height = 0;
|
||||
|
||||
private:
|
||||
std::mutex mtx;
|
||||
BinPack<uint16_t> bin;
|
||||
std::map<std::string, std::map<uint32_t, GlyphValue>> index;
|
||||
|
||||
Reference in New Issue
Block a user