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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#pragma once
#include <mbgl/text/glyph.hpp>
#include <mbgl/text/glyph_manager_observer.hpp>
#include <mbgl/text/glyph_range.hpp>
#include <mbgl/text/local_glyph_rasterizer.hpp>
#include <mbgl/util/font_stack.hpp>
#include <mbgl/util/immutable.hpp>
#include <string>
#include <unordered_map>
namespace mbgl {
class FileSource;
class AsyncRequest;
class Response;
class GlyphRequestor {
public:
virtual void onGlyphsAvailable(GlyphMap) = 0;
protected:
virtual ~GlyphRequestor() = default;
};
class GlyphManager {
public:
GlyphManager(const GlyphManager&) = delete;
GlyphManager& operator=(const GlyphManager&) = delete;
explicit GlyphManager(std::unique_ptr<LocalGlyphRasterizer> = std::make_unique<LocalGlyphRasterizer>(optional<std::string>()));
~GlyphManager();
// Workers send a `getGlyphs` message to the main thread once they have determined
// their `GlyphDependencies`. If all glyphs are already locally available, GlyphManager
// will provide them to the requestor immediately. Otherwise, it makes a request on the
// FileSource is made for each range needed, and notifies the observer when all are
// complete.
void getGlyphs(GlyphRequestor&, GlyphDependencies, FileSource&);
void removeRequestor(GlyphRequestor&);
void setURL(const std::string& url) {
glyphURL = url;
}
void setObserver(GlyphManagerObserver*);
// Remove glyphs for all but the supplied font stacks.
void evict(const std::set<FontStack>&);
private:
Glyph generateLocalSDF(const FontStack& fontStack, GlyphID glyphID);
std::string glyphURL;
struct GlyphRequest {
bool parsed = false;
std::unique_ptr<AsyncRequest> req;
std::unordered_map<GlyphRequestor*, std::shared_ptr<GlyphDependencies>> requestors;
};
struct Entry {
std::map<GlyphRange, GlyphRequest> ranges;
std::map<GlyphID, Immutable<Glyph>> glyphs;
};
std::unordered_map<FontStack, Entry, FontStackHasher> entries;
void requestRange(GlyphRequest&, const FontStack&, const GlyphRange&, FileSource& fileSource);
void processResponse(const Response&, const FontStack&, const GlyphRange&);
void notify(GlyphRequestor&, const GlyphDependencies&);
GlyphManagerObserver* observer = nullptr;
std::unique_ptr<LocalGlyphRasterizer> localGlyphRasterizer;
};
} // namespace mbgl
|