[core, macos, ios] Unit tests for LocalGlyphRasterizer
Core test uses stubbed "glyph.pbf" without Chinese glyphs Darwin test relies on locally available "PingFang" font. Android test relies on locally available "Droid" font. 'expected.png' is NOT correct b/c I haven't figured out how to run unit tests on Android yet.
This commit is contained in:
@@ -113,6 +113,7 @@ set(MBGL_TEST_FILES
|
||||
|
||||
# text
|
||||
test/text/cross_tile_symbol_index.test.cpp
|
||||
test/text/local_glyph_rasterizer.test.cpp
|
||||
test/text/glyph_manager.test.cpp
|
||||
test/text/glyph_pbf.test.cpp
|
||||
test/text/quads.test.cpp
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
HeadlessFrontend::HeadlessFrontend(float pixelRatio_, FileSource& fileSource, Scheduler& scheduler, const optional<std::string> programCacheDir, GLContextMode mode)
|
||||
: HeadlessFrontend({ 256, 256 }, pixelRatio_, fileSource, scheduler, programCacheDir, mode) {
|
||||
HeadlessFrontend::HeadlessFrontend(float pixelRatio_, FileSource& fileSource, Scheduler& scheduler, const optional<std::string> programCacheDir, GLContextMode mode, const optional<std::string> localFontFamily)
|
||||
: HeadlessFrontend({ 256, 256 }, pixelRatio_, fileSource, scheduler, programCacheDir, mode, localFontFamily) {
|
||||
}
|
||||
|
||||
HeadlessFrontend::HeadlessFrontend(Size size_, float pixelRatio_, FileSource& fileSource, Scheduler& scheduler, const optional<std::string> programCacheDir, GLContextMode mode)
|
||||
HeadlessFrontend::HeadlessFrontend(Size size_, float pixelRatio_, FileSource& fileSource, Scheduler& scheduler, const optional<std::string> programCacheDir, GLContextMode mode, const optional<std::string> localFontFamily)
|
||||
: size(size_),
|
||||
pixelRatio(pixelRatio_),
|
||||
backend({ static_cast<uint32_t>(size.width * pixelRatio),
|
||||
@@ -22,7 +22,7 @@ HeadlessFrontend::HeadlessFrontend(Size size_, float pixelRatio_, FileSource& fi
|
||||
renderer->render(*updateParameters);
|
||||
}
|
||||
}),
|
||||
renderer(std::make_unique<Renderer>(backend, pixelRatio, fileSource, scheduler, mode, programCacheDir)) {
|
||||
renderer(std::make_unique<Renderer>(backend, pixelRatio, fileSource, scheduler, mode, programCacheDir, localFontFamily)) {
|
||||
}
|
||||
|
||||
HeadlessFrontend::~HeadlessFrontend() = default;
|
||||
|
||||
@@ -19,8 +19,8 @@ class TransformState;
|
||||
|
||||
class HeadlessFrontend : public RendererFrontend {
|
||||
public:
|
||||
HeadlessFrontend(float pixelRatio_, FileSource&, Scheduler&, const optional<std::string> programCacheDir = {}, GLContextMode mode = GLContextMode::Unique);
|
||||
HeadlessFrontend(Size, float pixelRatio_, FileSource&, Scheduler&, const optional<std::string> programCacheDir = {}, GLContextMode mode = GLContextMode::Unique);
|
||||
HeadlessFrontend(float pixelRatio_, FileSource&, Scheduler&, const optional<std::string> programCacheDir = {}, GLContextMode mode = GLContextMode::Unique, const optional<std::string> localFontFamily = {});
|
||||
HeadlessFrontend(Size, float pixelRatio_, FileSource&, Scheduler&, const optional<std::string> programCacheDir = {}, GLContextMode mode = GLContextMode::Unique, const optional<std::string> localFontFamily = {});
|
||||
~HeadlessFrontend() override;
|
||||
|
||||
void reset() override;
|
||||
|
||||
BIN
test/fixtures/local_glyphs/droid/expected.png
vendored
Normal file
BIN
test/fixtures/local_glyphs/droid/expected.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
196
test/fixtures/local_glyphs/mixed.json
vendored
Normal file
196
test/fixtures/local_glyphs/mixed.json
vendored
Normal file
@@ -0,0 +1,196 @@
|
||||
{
|
||||
"version": 8,
|
||||
"zoom": 0,
|
||||
"center": [-14.41400, 39.09187],
|
||||
"sources": {
|
||||
"mapbox": {
|
||||
"type": "geojson",
|
||||
"data": {
|
||||
"type": "FeatureCollection",
|
||||
"features": [
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "身什戰 1"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "LineString",
|
||||
"coordinates": [
|
||||
[
|
||||
-14.4195556640625,
|
||||
39.091699613104595
|
||||
],
|
||||
[
|
||||
102.3046875,
|
||||
39.36827914916014
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "two 身什戰"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "LineString",
|
||||
"coordinates": [
|
||||
[
|
||||
-14.403076171875,
|
||||
39.10022600175347
|
||||
],
|
||||
[
|
||||
103.35937499999999,
|
||||
65.80277639340238
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "身什戰33"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "LineString",
|
||||
"coordinates": [
|
||||
[
|
||||
-14.414062499999998,
|
||||
39.091699613104595
|
||||
],
|
||||
[
|
||||
-14.765625,
|
||||
82.21421714106776
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "身什戰"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "LineString",
|
||||
"coordinates": [
|
||||
[
|
||||
-14.408569335937498,
|
||||
39.091699613104595
|
||||
],
|
||||
[
|
||||
-130.78125,
|
||||
39.095962936305476
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "身什戰 five"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "LineString",
|
||||
"coordinates": [
|
||||
[
|
||||
-14.414062499999998,
|
||||
39.095962936305476
|
||||
],
|
||||
[
|
||||
-16.5234375,
|
||||
-58.81374171570779
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "six 身什戰"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "LineString",
|
||||
"coordinates": [
|
||||
[
|
||||
-14.4195556640625,
|
||||
39.10022600175347
|
||||
],
|
||||
[
|
||||
-130.4296875,
|
||||
64.47279382008166
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "身什戰 seven"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "LineString",
|
||||
"coordinates": [
|
||||
[
|
||||
-14.4195556640625,
|
||||
39.0831721934762
|
||||
],
|
||||
[
|
||||
33.75,
|
||||
81.87364125482827
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "eight 身什戰"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "LineString",
|
||||
"coordinates": [
|
||||
[
|
||||
-14.447021484374998,
|
||||
39.104488809440475
|
||||
],
|
||||
[
|
||||
-66.4453125,
|
||||
82.26169873683153
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
|
||||
"layers": [
|
||||
{
|
||||
"id": "background",
|
||||
"type": "background",
|
||||
"paint": {
|
||||
"background-color": "white"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "lines-symbol",
|
||||
"type": "symbol",
|
||||
"source": "mapbox",
|
||||
"layout": {
|
||||
"text-field": "{name}",
|
||||
"symbol-placement": "line",
|
||||
"symbol-spacing": 150,
|
||||
"text-allow-overlap": true,
|
||||
"text-font": [ "NotoCJK" ]
|
||||
}
|
||||
}, {
|
||||
"id": "lines",
|
||||
"type": "line",
|
||||
"source": "mapbox",
|
||||
"paint": {
|
||||
"line-opacity": 0.25
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
test/fixtures/local_glyphs/no_local/expected.png
vendored
Normal file
BIN
test/fixtures/local_glyphs/no_local/expected.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.4 KiB |
BIN
test/fixtures/local_glyphs/ping_fang/expected.png
vendored
Normal file
BIN
test/fixtures/local_glyphs/ping_fang/expected.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
86
test/text/local_glyph_rasterizer.test.cpp
Normal file
86
test/text/local_glyph_rasterizer.test.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
#include <mbgl/test/util.hpp>
|
||||
#include <mbgl/test/stub_file_source.hpp>
|
||||
#include <mbgl/map/map.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>
|
||||
|
||||
using namespace mbgl;
|
||||
|
||||
namespace {
|
||||
|
||||
class LocalGlyphRasterizerTest {
|
||||
public:
|
||||
LocalGlyphRasterizerTest(const optional<std::string> fontFamily)
|
||||
: frontend(pixelRatio, fileSource, threadPool, optional<std::string>(), GLContextMode::Unique, fontFamily)
|
||||
{
|
||||
}
|
||||
|
||||
util::RunLoop loop;
|
||||
StubFileSource fileSource;
|
||||
ThreadPool threadPool { 4 };
|
||||
float pixelRatio { 1 };
|
||||
HeadlessFrontend frontend;
|
||||
Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource,
|
||||
threadPool, MapMode::Static};
|
||||
|
||||
void checkRendering(const char * name) {
|
||||
test::checkImage(std::string("test/fixtures/local_glyphs/") + name,
|
||||
frontend.render(map), 0.0002, 0.1);
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace
|
||||
|
||||
#ifdef __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"));
|
||||
test.checkRendering("ping_fang");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
#if ANDROID
|
||||
|
||||
TEST(LocalGlyphRasterizer, Droid) {
|
||||
LocalGlyphRasterizerTest test(std::string("Droid"));
|
||||
|
||||
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("droid");
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user