From 677ed0ebaba00a8ac449268bcb6df55c8b9cb895 Mon Sep 17 00:00:00 2001 From: artemp Date: Tue, 21 Feb 2017 12:43:54 +0100 Subject: [PATCH] refactor to make it easier to run multiple tests --- test/unit/text/shaping.cpp | 89 ++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 41 deletions(-) diff --git a/test/unit/text/shaping.cpp b/test/unit/text/shaping.cpp index f6336ec2b..74301d979 100644 --- a/test/unit/text/shaping.cpp +++ b/test/unit/text/shaping.cpp @@ -4,6 +4,41 @@ #include #include +namespace { + +void test_shaping( mapnik::font_set const& fontset, mapnik::face_manager& fm, + std::vector> const& expected, char const* str) +{ + mapnik::transcoder tr("utf8"); + std::map width_map; + mapnik::text_itemizer itemizer; + auto props = std::make_unique(); + props->fontset = fontset; + props->text_size = 32; + + double scale_factor = 1; + auto ustr = tr.transcode(str); + auto length = ustr.length(); + itemizer.add_text(ustr, props); + + mapnik::text_line line(0, length); + mapnik::harfbuzz_shaper::shape_text(line, itemizer, + width_map, + fm, + scale_factor); + + std::size_t index = 0; + for (auto const& g : line) + { + unsigned glyph_index, char_index; + CHECK(index < expected.size()); + std::tie(glyph_index, char_index) = expected[index++]; + REQUIRE(glyph_index == g.glyph_index); + REQUIRE(char_index == g.char_index); + } +} +} + TEST_CASE("shaping") { mapnik::freetype_engine::register_font("test/data/fonts/NotoSans-Regular.ttc"); @@ -13,54 +48,26 @@ TEST_CASE("shaping") { fontset.add_face_name(name); } - mapnik::transcoder tr("utf8"); - std::map width_map; - double scale_factor = 1; + mapnik::font_library fl; mapnik::freetype_engine::font_file_mapping_type font_file_mapping; mapnik::freetype_engine::font_memory_cache_type font_memory_cache; mapnik::face_manager fm(fl, font_file_mapping, font_memory_cache); - mapnik::text_itemizer itemizer; - auto props = std::make_unique(); - props->fontset = fontset; - props->text_size = 64; - - std::vector> expected = - {{0, 0}, {0, 3}, {0, 4}, {0, 7}, {3, 8}, {11, 9}, {68, 10}, {69, 11}, {70, 12}, {12, 13}}; - // with default NotoSans-Regular.ttc and NotoNaskhArabic-Regular.ttf ^^^ - - //std::vector> expected = - // {{977,0}, {1094,3}, {1038,4}, {1168,4}, {9,7}, {3,8}, {11,9}, {68,10}, {69,11}, {70,12}, {12,13}}; - // expected results if "NotoSansTibetan-Regular.ttf is registered^^ - auto ustr = tr.transcode("སྤུ་ཧྲེང (abc)"); - auto length = ustr.length(); - itemizer.add_text(ustr, props); + { + std::vector> expected = + {{0, 0}, {0, 3}, {0, 4}, {0, 7}, {3, 8}, {11, 9}, {68, 10}, {69, 11}, {70, 12}, {12, 13}}; + // with default NotoSans-Regular.ttc and NotoNaskhArabic-Regular.ttf ^^^ + //std::vector> expected = + // {{977,0}, {1094,3}, {1038,4}, {1168,4}, {9,7}, {3,8}, {11,9}, {68,10}, {69,11}, {70,12}, {12,13}}; + // expected results if "NotoSansTibetan-Regular.ttf is registered^^ + test_shaping(fontset, fm, expected, "སྤུ་ཧྲེང (abc)"); + } { - mapnik::text_line line(0, length); - mapnik::harfbuzz_shaper::shape_text(line, itemizer, - width_map, - fm, - scale_factor); - - std::size_t index = 0; - for (auto const& g : line) - { - unsigned glyph_index, char_index; - std::tie(glyph_index, char_index) = expected[index++]; - REQUIRE(glyph_index == g.glyph_index); - REQUIRE(char_index == g.char_index); - } + std::vector> expected = + {{0, 0}, {0, 3}, {0, 4}, {0, 7}, {3, 8}, {11, 9}, {0, 10}, {0, 11}, {0, 12}, {12, 13}}; + test_shaping(fontset, fm, expected, "སྤུ་ཧྲེང (普兰镇)"); } -#if 0 - { - mapnik::text_line line(0, length); - mapnik::icu_shaper::shape_text(line,itemizer, - width_map, - fm, - scale_factor); - } -#endif }