#ifndef MBGL_TEXT_GLYPH_STORE #define MBGL_TEXT_GLYPH_STORE #include #include #include #include #include #include #include #include #include #include #include namespace mbgl { class FileSource; class Environment; class SDFGlyph { public: uint32_t id = 0; // A signed distance field of the glyph with a border of 3 pixels. std::string bitmap; // Glyph metrics GlyphMetrics metrics; }; class FontStack { public: void insert(uint32_t id, const SDFGlyph &glyph); const std::map &getMetrics() const; const std::map &getSDFs() const; const Shaping getShaping(const std::u32string &string, float maxWidth, float lineHeight, float horizontalAlign, float verticalAlign, float justify, float spacing, const vec2 &translate) const; void lineWrap(Shaping &shaping, float lineHeight, float maxWidth, float horizontalAlign, float verticalAlign, float justify) const; private: std::map bitmaps; std::map metrics; std::map sdfs; mutable std::mutex mtx; }; class GlyphPBF { public: GlyphPBF(const std::string &glyphURL, const std::string &fontStack, GlyphRange glyphRange, Environment &env); private: GlyphPBF(const GlyphPBF &) = delete; GlyphPBF(GlyphPBF &&) = delete; GlyphPBF &operator=(const GlyphPBF &) = delete; GlyphPBF &operator=(GlyphPBF &&) = delete; public: void parse(FontStack &stack); std::shared_future getFuture(); private: std::string data; std::promise promise; std::shared_future future; std::mutex mtx; }; // Manages Glyphrange PBF loading. class GlyphStore { public: GlyphStore(Environment &); // Block until all specified GlyphRanges of the specified font stack are loaded. void waitForGlyphRanges(const std::string &fontStack, const std::set &glyphRanges); uv::exclusive getFontStack(const std::string &fontStack); void setURL(const std::string &url); private: // Loads an individual glyph range from the font stack and adds it to rangeSets std::shared_future loadGlyphRange(const std::string &fontStack, std::map> &rangeSets, GlyphRange range); FontStack &createFontStack(const std::string &fontStack); std::string glyphURL; Environment &env; std::unordered_map>> ranges; std::unordered_map> stacks; std::unique_ptr mtx; }; } #endif