blob: 2236bce38cc13f6172e404ad3d8d2f614e0f667f (
plain)
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
|
#ifndef MBGL_TEXT_GLYPH_STORE
#define MBGL_TEXT_GLYPH_STORE
#include <mbgl/text/font_stack.hpp>
#include <mbgl/text/glyph.hpp>
#include <mbgl/util/exclusive.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/work_queue.hpp>
#include <exception>
#include <set>
#include <string>
#include <unordered_map>
namespace mbgl {
class GlyphPBF;
// The GlyphStore manages the loading and storage of Glyphs
// and creation of FontStack objects. The GlyphStore lives
// on the MapThread but can be queried from any thread.
class GlyphStore : private util::noncopyable {
public:
class Observer {
public:
virtual ~Observer() = default;
virtual void onGlyphsLoaded(const std::string& /* fontStack */, const GlyphRange&) {};
virtual void onGlyphsError(const std::string& /* fontStack */, const GlyphRange&, std::exception_ptr) {};
};
GlyphStore();
~GlyphStore();
util::exclusive<FontStack> getFontStack(const std::string& fontStack);
// Returns true if the set of GlyphRanges are available and parsed or false
// if they are not. For the missing ranges, a request on the FileSource is
// made and when the glyph if finally parsed, it gets added to the respective
// FontStack and a signal is emitted to notify the observers. This method
// can be called from any thread.
bool hasGlyphRanges(const std::string& fontStack, const std::set<GlyphRange>& glyphRanges);
void setURL(const std::string &url) {
glyphURL = url;
}
std::string getURL() const {
return glyphURL;
}
void setObserver(Observer* observer);
private:
void requestGlyphRange(const std::string& fontStackName, const GlyphRange& range);
std::string glyphURL;
std::unordered_map<std::string, std::map<GlyphRange, std::unique_ptr<GlyphPBF>>> ranges;
std::mutex rangesMutex;
std::unordered_map<std::string, std::unique_ptr<FontStack>> stacks;
std::mutex stacksMutex;
util::WorkQueue workQueue;
Observer nullObserver;
Observer* observer = &nullObserver;
};
} // namespace mbgl
#endif
|