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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#include <mbgl/test/util.hpp>
#include <mbgl/test/stub_file_source.hpp>
#include <mbgl/test/map_adapter.hpp>
#include <mbgl/map/map_options.hpp>
#include <mbgl/util/io.hpp>
#include <mbgl/util/run_loop.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/renderer/renderer.hpp>
#include <mbgl/gl/headless_frontend.hpp>
#include <mbgl/util/default_thread_pool.hpp>
#include <mbgl/style/style.hpp>
/*
LoadLocalCJKGlyph in glyph_manager.test.cpp exercises the platform-independent
part of LocalGlyphRasterizer. This test actually exercises platform-dependent
font loading code for whatever platform it runs on. Different platforms have
different default fonts, so adding a new platform requires new "expected"
fixtures.
At the time of writing, we don't run `mbgl-test` on iOS or Android, so the only
supported test platform is macOS. Supporting Android would require adding a new
test case (probably using the "Droid" font family). iOS should theoretically
work -- the "PingFang" font family used below is expected to be available on
all iOS devices, and we use a relatively high image diff tolerance (0.05) to
account for small changes between the many possible variants of the PingFang
family.
*/
using namespace mbgl;
namespace {
class LocalGlyphRasterizerTest {
public:
LocalGlyphRasterizerTest(const optional<std::string> fontFamily)
: frontend(pixelRatio, threadPool, optional<std::string>(), GLContextMode::Unique, fontFamily)
{
}
util::RunLoop loop;
std::shared_ptr<StubFileSource> fileSource = std::make_shared<StubFileSource>();
ThreadPool threadPool { 4 };
float pixelRatio { 1 };
HeadlessFrontend frontend;
MapAdapter map { frontend, MapObserver::nullObserver(), pixelRatio, fileSource,
threadPool, MapOptions().withMapMode(MapMode::Static).withSize(frontend.getSize())};
void checkRendering(const char * name) {
test::checkImage(std::string("test/fixtures/local_glyphs/") + name,
frontend.render(map), 0.05, 0.1);
}
};
} // end namespace
// Enabling Qt requires adding a CJK-compatible font in the CI image.
#if defined(__APPLE__)
TEST(LocalGlyphRasterizer, PingFang) {
LocalGlyphRasterizerTest test(std::string("PingFang"));
test.fileSource->glyphsResponse = [&] (const Resource& resource) {
EXPECT_EQ(Resource::Kind::Glyphs, resource.kind);
Response response;
response.data = std::make_shared<std::string>(util::read_file("test/fixtures/resources/glyphs.pbf"));
return response;
};
test.map.getStyle().loadJSON(util::read_file("test/fixtures/local_glyphs/mixed.json"));
#if defined(__APPLE__)
test.checkRendering("ping_fang");
#elif defined(__QT__)
test.checkRendering("ping_fang_qt");
#endif // defined(__APPLE__)
}
#endif // defined(__APPLE__)
TEST(LocalGlyphRasterizer, NoLocal) {
// Expectation: without any local fonts set, and without any CJK glyphs provided,
// the output should just contain basic latin characters.
LocalGlyphRasterizerTest test({});
test.fileSource->glyphsResponse = [&] (const Resource& resource) {
EXPECT_EQ(Resource::Kind::Glyphs, resource.kind);
Response response;
response.data = std::make_shared<std::string>(util::read_file("test/fixtures/resources/glyphs.pbf"));
return response;
};
test.map.getStyle().loadJSON(util::read_file("test/fixtures/local_glyphs/mixed.json"));
test.checkRendering("no_local");
}
|