Add HarfBuzz Text Shaping and Font Fallback Support (#3611)
Co-authored-by: alan wei chen <alanchenboy@gmail.com>
6
.gitmodules
vendored
@@ -37,6 +37,12 @@
|
||||
[submodule "platform/windows/vendor/vcpkg"]
|
||||
path = platform/windows/vendor/vcpkg
|
||||
url = https://github.com/microsoft/vcpkg.git
|
||||
[submodule "vendor/harfbuzzFreetype/freetype"]
|
||||
path = vendor/freetype
|
||||
url=https://github.com/freetype/freetype.git
|
||||
[submodule "vendor/harfbuzzFreetype/harfbuzz"]
|
||||
path = vendor/harfbuzz
|
||||
url=https://github.com/harfbuzz/harfbuzz
|
||||
[submodule "vendor/boost"]
|
||||
path = vendor/boost
|
||||
url = https://github.com/maplibre/maplibre-gl-native-boost.git
|
||||
|
||||
44
BUILD.bazel
@@ -22,6 +22,7 @@ load(
|
||||
"MLN_OPENGL_SOURCE",
|
||||
"MLN_PRIVATE_GENERATED_STYLE_HEADERS",
|
||||
"MLN_PUBLIC_GENERATED_STYLE_HEADERS",
|
||||
"MLN_SHAPING_HARFBUZZ_SRCS",
|
||||
)
|
||||
load("//bazel:flags.bzl", "CPP_FLAGS", "MAPLIBRE_FLAGS")
|
||||
|
||||
@@ -85,6 +86,9 @@ cc_library(
|
||||
":drawable_renderer": MLN_OPENGL_SOURCE + MLN_DRAWABLES_SOURCE + MLN_DRAWABLES_GL_SOURCE,
|
||||
":metal_renderer": MLN_DRAWABLES_SOURCE + MLN_DRAWABLES_MTL_SOURCE,
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"//:harfbuzz_text_shaping": MLN_SHAPING_HARFBUZZ_SRCS,
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
hdrs = MLN_LAYER_PLUGIN_HEADERS + MLN_CORE_HEADERS + select({
|
||||
":drawable_renderer": MLN_OPENGL_HEADERS + MLN_DRAWABLES_HEADERS + MLN_DRAWABLES_GL_HEADERS,
|
||||
@@ -102,6 +106,9 @@ cc_library(
|
||||
}) + select({
|
||||
"@platforms//os:ios": ["GLES_SILENCE_DEPRECATION=1"],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"//:harfbuzz_text_shaping": ["MLN_TEXT_SHAPING_HARFBUZZ=1"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
includes = [
|
||||
"include",
|
||||
@@ -111,6 +118,12 @@ cc_library(
|
||||
"vendor/metal-cpp",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
"//:harfbuzz_text_shaping": [
|
||||
"vendor/freetype/include",
|
||||
"vendor/harfbuzz/src",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
local_defines = [
|
||||
r"MLN_VERSION_REV=\"standalone\"",
|
||||
@@ -147,6 +160,12 @@ cc_library(
|
||||
"//vendor:metal-cpp",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
":harfbuzz_text_shaping": [
|
||||
"//vendor:freetype",
|
||||
"//vendor:harfbuzz",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}) + select({
|
||||
":rust": [
|
||||
"//rustutils:rustutilslib",
|
||||
@@ -182,6 +201,31 @@ config_setting(
|
||||
},
|
||||
)
|
||||
|
||||
# Selects the shaping implementation to utilize in the core
|
||||
|
||||
string_flag(
|
||||
name = "shaping",
|
||||
build_setting_default = "harfbuzz",
|
||||
values = [
|
||||
"legacy",
|
||||
"harfbuzz",
|
||||
],
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "harfbuzz_text_shaping",
|
||||
flag_values = {
|
||||
":shaping": "harfbuzz",
|
||||
},
|
||||
)
|
||||
|
||||
config_setting(
|
||||
name = "legacy_text_shaping",
|
||||
flag_values = {
|
||||
":shaping": "legacy",
|
||||
},
|
||||
)
|
||||
|
||||
bool_flag(
|
||||
name = "use_rust",
|
||||
build_setting_default = False,
|
||||
|
||||
@@ -16,6 +16,7 @@ option(MLN_WITH_WERROR "Make all compilation warnings errors" ON)
|
||||
option(MLN_USE_UNORDERED_DENSE "Use ankerl dense containers for performance" ON)
|
||||
option(MLN_USE_TRACY "Enable Tracy instrumentation" OFF)
|
||||
option(MLN_USE_RUST "Use components in Rust" OFF)
|
||||
option(MLN_TEXT_SHAPING_HARFBUZZ "Use haffbuzz to shape complex text" ON)
|
||||
option(MLN_CORE_INCLUDE_DEPS "Include depdendencies in static build of core" OFF)
|
||||
option(MLN_CREATE_AUTORELEASEPOOL "Create autoreleasepool in render loop" OFF)
|
||||
|
||||
@@ -1333,6 +1334,35 @@ list(APPEND
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/style/layers/custom_drawable_layer.cpp
|
||||
)
|
||||
|
||||
# Harfbuzz text shaping
|
||||
set(SHAPE_TARGETS, "")
|
||||
list(APPEND
|
||||
SRC_FILES
|
||||
# Base text shaping files, which are always included. They don't depend on HarfBuzz if MLN_TEXT_SHAPING_HARFBUZZ is OFF.
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/text/harfbuzz.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/text/harfbuzz.hpp
|
||||
)
|
||||
if (MLN_TEXT_SHAPING_HARFBUZZ)
|
||||
message(STATUS "Configuring with HarfBuzz text shaping")
|
||||
list(APPEND
|
||||
SRC_FILES
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/text/harfbuzz_impl.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/text/harfbuzz_impl.hpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/text/freetype.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/mbgl/text/freetype.hpp
|
||||
)
|
||||
target_compile_definitions(
|
||||
mbgl-core
|
||||
PRIVATE MLN_TEXT_SHAPING_HARFBUZZ=1
|
||||
)
|
||||
include(${PROJECT_SOURCE_DIR}/vendor/freetype.cmake)
|
||||
include(${PROJECT_SOURCE_DIR}/vendor/harfbuzz.cmake)
|
||||
set(SHAPE_TARGETS
|
||||
freetype
|
||||
harfbuzz
|
||||
)
|
||||
endif()
|
||||
|
||||
target_sources(
|
||||
mbgl-core PRIVATE
|
||||
${INCLUDE_FILES}
|
||||
@@ -1436,6 +1466,7 @@ target_link_libraries(
|
||||
mbgl-vendor-wagyu
|
||||
$<$<BOOL:${MLN_WITH_METAL}>:mbgl-vendor-metal-cpp>
|
||||
$<IF:$<BOOL:${MLN_USE_RUST}>,mbgl-rustutils,mbgl-vendor-csscolorparser>
|
||||
${SHAPE_TARGETS} # from harfbuzz.cmake
|
||||
PUBLIC
|
||||
MapLibreNative::Base
|
||||
MapLibreNative::Base::Extras::expected-lite
|
||||
@@ -1476,6 +1507,7 @@ set(EXPORT_TARGETS
|
||||
mbgl-vendor-wagyu
|
||||
mbgl-vendor-metal-cpp
|
||||
unordered_dense
|
||||
${SHAPE_TARGETS} # from harfbuzz.cmake
|
||||
)
|
||||
|
||||
if(MLN_USE_RUST)
|
||||
|
||||
@@ -489,6 +489,8 @@ MLN_CORE_SOURCE = [
|
||||
"src/mbgl/text/shaping.hpp",
|
||||
"src/mbgl/text/tagged_string.cpp",
|
||||
"src/mbgl/text/tagged_string.hpp",
|
||||
"src/mbgl/text/harfbuzz.cpp",
|
||||
"src/mbgl/text/harfbuzz.hpp",
|
||||
"src/mbgl/tile/custom_geometry_tile.cpp",
|
||||
"src/mbgl/tile/custom_geometry_tile.hpp",
|
||||
"src/mbgl/tile/geojson_tile.cpp",
|
||||
@@ -1096,3 +1098,10 @@ MLN_DRAWABLES_MTL_HEADERS = [
|
||||
"include/mbgl/style/layers/mtl/custom_layer_render_parameters.hpp",
|
||||
"include/mbgl/shaders/mtl/widevector.hpp",
|
||||
]
|
||||
|
||||
MLN_SHAPING_HARFBUZZ_SRCS = [
|
||||
"src/mbgl/text/freetype.hpp",
|
||||
"src/mbgl/text/freetype.cpp",
|
||||
"src/mbgl/text/harfbuzz_impl.hpp",
|
||||
"src/mbgl/text/harfbuzz_impl.cpp",
|
||||
]
|
||||
|
||||
@@ -82,6 +82,7 @@ public:
|
||||
static Resource glyphs(const std::string& urlTemplate,
|
||||
const FontStack& fontStack,
|
||||
const std::pair<uint16_t, uint16_t>& glyphRange);
|
||||
static Resource fontFace(const std::string& url);
|
||||
static Resource spriteImage(const std::string& base, float pixelRatio);
|
||||
static Resource spriteJSON(const std::string& base, float pixelRatio);
|
||||
static Resource image(const std::string& url);
|
||||
|
||||
@@ -18,7 +18,40 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
using GlyphID = char16_t;
|
||||
union GlyphID {
|
||||
char32_t hash;
|
||||
struct {
|
||||
char16_t code;
|
||||
GlyphIDType type;
|
||||
} complex;
|
||||
|
||||
GlyphID(int codepoint) {
|
||||
complex.type = FontPBF;
|
||||
complex.code = codepoint;
|
||||
}
|
||||
GlyphID(uint32_t codepoint) {
|
||||
complex.type = FontPBF;
|
||||
complex.code = codepoint;
|
||||
}
|
||||
GlyphID(char16_t codepoint) {
|
||||
complex.type = FontPBF;
|
||||
complex.code = codepoint;
|
||||
}
|
||||
|
||||
GlyphID(char16_t index, GlyphIDType t) {
|
||||
complex.type = t;
|
||||
complex.code = index;
|
||||
}
|
||||
|
||||
operator char16_t() { return complex.code; }
|
||||
operator char32_t() { return hash; }
|
||||
bool operator<(const GlyphID &other) const { return hash < other.hash; }
|
||||
bool operator>(const GlyphID &other) const { return hash > other.hash; }
|
||||
|
||||
bool operator<(const uint16_t &other) const { return hash < other; }
|
||||
bool operator>(const uint16_t &other) const { return hash > other; }
|
||||
};
|
||||
|
||||
using GlyphIDs = std::set<GlyphID>;
|
||||
|
||||
// Note: this only works for the BMP
|
||||
@@ -32,7 +65,7 @@ struct GlyphMetrics {
|
||||
uint32_t advance = 0;
|
||||
};
|
||||
|
||||
inline bool operator==(const GlyphMetrics& lhs, const GlyphMetrics& rhs) {
|
||||
inline bool operator==(const GlyphMetrics &lhs, const GlyphMetrics &rhs) {
|
||||
return lhs.width == rhs.width && lhs.height == rhs.height && lhs.left == rhs.left && lhs.top == rhs.top &&
|
||||
lhs.advance == rhs.advance;
|
||||
}
|
||||
@@ -114,7 +147,7 @@ public:
|
||||
float right = 0;
|
||||
WritingModeType writingMode;
|
||||
explicit operator bool() const {
|
||||
return std::ranges::any_of(positionedLines, [](const auto& line) { return !line.positionedGlyphs.empty(); });
|
||||
return std::ranges::any_of(positionedLines, [](const auto &line) { return !line.positionedGlyphs.empty(); });
|
||||
}
|
||||
// The y offset *should* be part of the font metadata.
|
||||
static constexpr int32_t yOffset = -17;
|
||||
@@ -128,7 +161,50 @@ enum class WritingModeType : uint8_t {
|
||||
Vertical = 1 << 1,
|
||||
};
|
||||
|
||||
using GlyphDependencies = std::map<FontStack, GlyphIDs>;
|
||||
// style defined faces
|
||||
struct FontFace {
|
||||
using Range = std::pair<uint32_t, uint32_t>;
|
||||
GlyphIDType type; // an unique glyph id
|
||||
std::string name; // font face name
|
||||
std::string url; // font file url
|
||||
std::vector<Range> ranges; // unicode ranges
|
||||
|
||||
FontFace() = default;
|
||||
FontFace(const std::string &name_, const std::string &url_, const std::vector<Range> &ranges_)
|
||||
: type(FontPBF),
|
||||
name(name_),
|
||||
url(url_),
|
||||
ranges(ranges_) {}
|
||||
|
||||
FontFace(const std::string &name_, const std::string &url_, std::vector<Range> &&ranges_)
|
||||
: type(FontPBF),
|
||||
name(name_),
|
||||
url(url_),
|
||||
ranges(std::move(ranges_)) {}
|
||||
|
||||
auto valid() const -> bool { return !name.empty() && !url.empty() && !ranges.empty(); }
|
||||
};
|
||||
|
||||
using FontFaces = std::vector<FontFace>;
|
||||
|
||||
struct HBShapeRequest {
|
||||
std::u16string str;
|
||||
FontStack fontStack;
|
||||
GlyphIDType type;
|
||||
|
||||
HBShapeRequest(const std::u16string &str_, const FontStack &fontStack_, GlyphIDType type_)
|
||||
: str(str_),
|
||||
fontStack(fontStack_),
|
||||
type(type_) {}
|
||||
};
|
||||
|
||||
using HBShapeRequests = std::map<FontStack, std::map<GlyphIDType, std::set<std::u16string>>>;
|
||||
|
||||
struct GlyphDependencies {
|
||||
std::map<FontStack, GlyphIDs> glyphs;
|
||||
HBShapeRequests shapes;
|
||||
};
|
||||
|
||||
using GlyphRangeDependencies = std::map<FontStack, std::unordered_set<GlyphRange>>;
|
||||
|
||||
struct GlyphPosition {
|
||||
|
||||
@@ -4,10 +4,30 @@
|
||||
#include <cstdint>
|
||||
#include <unordered_set>
|
||||
#include <mbgl/util/hash.hpp>
|
||||
#include <mbgl/util/font_stack.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
using GlyphRange = std::pair<uint16_t, uint16_t>;
|
||||
enum GlyphIDType : uint16_t {
|
||||
FontPBF = 0x00,
|
||||
};
|
||||
|
||||
GlyphIDType genNewGlyphIDType(const std::string &url,
|
||||
const FontStack &fontStack,
|
||||
const std::vector<std::pair<uint32_t, uint32_t>> &pairs);
|
||||
|
||||
class GlyphRange {
|
||||
public:
|
||||
uint16_t first = 0;
|
||||
uint16_t second = 0;
|
||||
|
||||
GlyphIDType type = GlyphIDType::FontPBF;
|
||||
|
||||
GlyphRange(uint32_t first_, uint32_t second_, GlyphIDType type_ = FontPBF);
|
||||
|
||||
bool operator==(const GlyphRange &other) const;
|
||||
bool operator<(const GlyphRange &other) const;
|
||||
};
|
||||
|
||||
constexpr uint32_t GLYPHS_PER_GLYPH_RANGE = 256;
|
||||
constexpr uint32_t GLYPH_RANGES_PER_FONT_STACK = 256;
|
||||
@@ -20,7 +40,7 @@ namespace std {
|
||||
|
||||
template <>
|
||||
struct hash<mbgl::GlyphRange> {
|
||||
std::size_t operator()(const mbgl::GlyphRange& range) const { return mbgl::util::hash(range.first, range.second); }
|
||||
std::size_t operator()(const mbgl::GlyphRange &range) const { return mbgl::util::hash(range.first, range.second); }
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
#include <cstddef>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <string_view>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace mbgl {
|
||||
namespace util {
|
||||
@@ -36,5 +39,53 @@ inline constexpr auto to_array(std::tuple<Ts...>&& tuple) {
|
||||
std::forward<std::tuple<Ts...>>(tuple));
|
||||
}
|
||||
|
||||
/// Convert string to integral types
|
||||
template <typename T>
|
||||
std::enable_if_t<std::is_integral_v<T>, std::optional<T>> parse(std::string_view str, int base = 10) noexcept {
|
||||
static_assert(std::is_same_v<T, int32_t> || std::is_same_v<T, uint32_t> || std::is_same_v<T, int64_t> ||
|
||||
std::is_same_v<T, uint64_t>,
|
||||
"Unsupported integral type in mbgl::util::parse<T>.");
|
||||
char* end = nullptr;
|
||||
errno = 0;
|
||||
|
||||
if constexpr (std::is_same_v<T, int32_t>) {
|
||||
long val = std::strtol(str.data(), &end, base);
|
||||
if (errno == 0 && end == str.data() + str.size()) return static_cast<T>(val);
|
||||
} else if constexpr (std::is_same_v<T, uint32_t>) {
|
||||
unsigned long val = std::strtoul(str.data(), &end, base);
|
||||
if (errno == 0 && end == str.data() + str.size()) return static_cast<T>(val);
|
||||
} else if constexpr (std::is_same_v<T, int64_t>) {
|
||||
long long val = std::strtoll(str.data(), &end, base);
|
||||
if (errno == 0 && end == str.data() + str.size()) return static_cast<T>(val);
|
||||
} else if constexpr (std::is_same_v<T, uint64_t>) {
|
||||
unsigned long long val = std::strtoull(str.data(), &end, base);
|
||||
if (errno == 0 && end == str.data() + str.size()) return static_cast<T>(val);
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
/// Convert string to floating point types
|
||||
template <typename T>
|
||||
std::enable_if_t<std::is_floating_point_v<T>, std::optional<T>> parse(std::string_view str) noexcept {
|
||||
static_assert(std::is_same_v<T, float> || std::is_same_v<T, double> || std::is_same_v<T, long double>,
|
||||
"Unsupported floating point type in mbgl::util::parse<T>.");
|
||||
char* end = nullptr;
|
||||
errno = 0;
|
||||
|
||||
if constexpr (std::is_same_v<T, float>) {
|
||||
float val = std::strtof(str.data(), &end);
|
||||
if (errno == 0 && end == str.data() + str.size()) return val;
|
||||
} else if constexpr (std::is_same_v<T, double>) {
|
||||
double val = std::strtod(str.data(), &end);
|
||||
if (errno == 0 && end == str.data() + str.size()) return val;
|
||||
} else if constexpr (std::is_same_v<T, long double>) {
|
||||
long double val = std::strtold(str.data(), &end);
|
||||
if (errno == 0 && end == str.data() + str.size()) return val;
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"network": [
|
||||
[
|
||||
"probeNetwork - default - end",
|
||||
4,
|
||||
596680
|
||||
],
|
||||
[
|
||||
"probeNetwork - default - start",
|
||||
0,
|
||||
0
|
||||
]
|
||||
],
|
||||
"gfx": [
|
||||
[
|
||||
"probeGFX - default - end",
|
||||
1,
|
||||
13,
|
||||
9,
|
||||
1,
|
||||
[
|
||||
364011,
|
||||
364011
|
||||
],
|
||||
[
|
||||
90850,
|
||||
90850
|
||||
],
|
||||
[
|
||||
1211104,
|
||||
1211104
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"network": [
|
||||
[
|
||||
"probeNetwork - default - end",
|
||||
5,
|
||||
690397
|
||||
],
|
||||
[
|
||||
"probeNetwork - default - start",
|
||||
0,
|
||||
0
|
||||
]
|
||||
],
|
||||
"gfx": [
|
||||
[
|
||||
"probeGFX - default - end",
|
||||
1,
|
||||
13,
|
||||
9,
|
||||
1,
|
||||
[
|
||||
675950,
|
||||
675950
|
||||
],
|
||||
[
|
||||
97714,
|
||||
97714
|
||||
],
|
||||
[
|
||||
1302624,
|
||||
1302624
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"network": [
|
||||
[
|
||||
"probeNetwork - default - end",
|
||||
4,
|
||||
636079
|
||||
],
|
||||
[
|
||||
"probeNetwork - default - start",
|
||||
0,
|
||||
0
|
||||
]
|
||||
],
|
||||
"gfx": [
|
||||
[
|
||||
"probeGFX - default - end",
|
||||
1,
|
||||
13,
|
||||
9,
|
||||
1,
|
||||
[
|
||||
488883,
|
||||
488883
|
||||
],
|
||||
[
|
||||
106570,
|
||||
106570
|
||||
],
|
||||
[
|
||||
1420704,
|
||||
1420704
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
6414
metrics/integration/data/burmese.geojson
Normal file
6505
metrics/integration/data/devanagari.geojson
Normal file
11211
metrics/integration/data/khmer.geojson
Normal file
BIN
metrics/integration/render-tests/text-font/burmese/expected1.png
Normal file
|
After Width: | Height: | Size: 100 KiB |
BIN
metrics/integration/render-tests/text-font/burmese/expected2.png
Normal file
|
After Width: | Height: | Size: 98 KiB |
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"version": 8,
|
||||
"metadata": {
|
||||
"test": {
|
||||
"width": 512,
|
||||
"height": 512,
|
||||
"allowed": 0.0003
|
||||
}
|
||||
},
|
||||
"center": [
|
||||
-70.752954126,
|
||||
43.39004898677380
|
||||
],
|
||||
"zoom": 11,
|
||||
"sources": {
|
||||
"geojson": {
|
||||
"type": "geojson",
|
||||
"data": "local://data/burmese.geojson"
|
||||
}
|
||||
},
|
||||
"sprite": "local://sprites/sprite",
|
||||
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
|
||||
"font-faces": {
|
||||
"Noto Sans Regular": [
|
||||
{
|
||||
"url": "local://glyphs/Noto%20Sans%20Regular/khmer.ttf",
|
||||
"unicode-range": [
|
||||
"U+1780-17FF"
|
||||
]
|
||||
},
|
||||
{
|
||||
"url": "local://glyphs/Noto%20Sans%20Regular/myanmar.ttf",
|
||||
"unicode-range": [
|
||||
"U+1000-109F",
|
||||
"U+A9E0-0xA9FF",
|
||||
"U+AA60-0xAA7F"
|
||||
]
|
||||
},
|
||||
{
|
||||
"url": "local://glyphs/Noto%20Sans%20Regular/devanagari.ttf",
|
||||
"unicode-range": [
|
||||
"U+0900-097F",
|
||||
"U+A8E0-0xA8FF"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"layers": [
|
||||
{
|
||||
"id": "background",
|
||||
"type": "background",
|
||||
"paint": {
|
||||
"background-color": "white"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "icon",
|
||||
"type": "symbol",
|
||||
"source": "geojson",
|
||||
"layout": {
|
||||
"text-field": "{name}",
|
||||
"text-font": [
|
||||
"Noto Sans Regular"
|
||||
],
|
||||
"symbol-placement": "point"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
After Width: | Height: | Size: 78 KiB |
|
After Width: | Height: | Size: 77 KiB |
|
After Width: | Height: | Size: 77 KiB |
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"version": 8,
|
||||
"metadata": {
|
||||
"test": {
|
||||
"width": 512,
|
||||
"height": 512,
|
||||
"allowed": 0.0003
|
||||
}
|
||||
},
|
||||
"center": [
|
||||
-70.752954126,
|
||||
43.39004898677380
|
||||
],
|
||||
"zoom": 11,
|
||||
"sources": {
|
||||
"geojson": {
|
||||
"type": "geojson",
|
||||
"data": "local://data/devanagari.geojson"
|
||||
}
|
||||
},
|
||||
"sprite": "local://sprites/sprite",
|
||||
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
|
||||
"font-faces": {
|
||||
"Noto Sans Regular": [
|
||||
{
|
||||
"url": "local://glyphs/Noto%20Sans%20Regular/khmer.ttf",
|
||||
"unicode-range": [
|
||||
"U+1780-17FF"
|
||||
]
|
||||
},
|
||||
{
|
||||
"url": "local://glyphs/Noto%20Sans%20Regular/myanmar.ttf",
|
||||
"unicode-range": [
|
||||
"U+1000-109F",
|
||||
"U+A9E0-0xA9FF",
|
||||
"U+AA60-0xAA7F"
|
||||
]
|
||||
},
|
||||
{
|
||||
"url": "local://glyphs/Noto%20Sans%20Regular/devanagari.ttf",
|
||||
"unicode-range": [
|
||||
"U+0900-097F",
|
||||
"U+A8E0-0xA8FF"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"layers": [
|
||||
{
|
||||
"id": "background",
|
||||
"type": "background",
|
||||
"paint": {
|
||||
"background-color": "white"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "icon",
|
||||
"type": "symbol",
|
||||
"source": "geojson",
|
||||
"layout": {
|
||||
"text-field": "{name}",
|
||||
"text-font": [
|
||||
"Noto Sans Regular"
|
||||
],
|
||||
"symbol-placement": "point"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
metrics/integration/render-tests/text-font/khmer/expected1.png
Normal file
|
After Width: | Height: | Size: 87 KiB |
BIN
metrics/integration/render-tests/text-font/khmer/expected2.png
Normal file
|
After Width: | Height: | Size: 86 KiB |
69
metrics/integration/render-tests/text-font/khmer/style.json
Normal file
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"version": 8,
|
||||
"metadata": {
|
||||
"test": {
|
||||
"width": 512,
|
||||
"height": 512,
|
||||
"allowed": 0.0003
|
||||
}
|
||||
},
|
||||
"center": [
|
||||
-70.752954126,
|
||||
43.39004898677380
|
||||
],
|
||||
"zoom": 11,
|
||||
"sources": {
|
||||
"geojson": {
|
||||
"type": "geojson",
|
||||
"data": "local://data/khmer.geojson"
|
||||
}
|
||||
},
|
||||
"sprite": "local://sprites/sprite",
|
||||
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
|
||||
"font-faces": {
|
||||
"Noto Sans Regular": [
|
||||
{
|
||||
"url": "local://glyphs/Noto%20Sans%20Regular/khmer.ttf",
|
||||
"unicode-range": [
|
||||
"U+1780-17FF"
|
||||
]
|
||||
},
|
||||
{
|
||||
"url": "local://glyphs/Noto%20Sans%20Regular/myanmar.ttf",
|
||||
"unicode-range": [
|
||||
"U+1000-109F",
|
||||
"U+A9E0-0xA9FF",
|
||||
"U+AA60-0xAA7F"
|
||||
]
|
||||
},
|
||||
{
|
||||
"url": "local://glyphs/Noto%20Sans%20Regular/devanagari.ttf",
|
||||
"unicode-range": [
|
||||
"U+0900-097F",
|
||||
"U+A8E0-0xA8FF"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"layers": [
|
||||
{
|
||||
"id": "background",
|
||||
"type": "background",
|
||||
"paint": {
|
||||
"background-color": "white"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "icon",
|
||||
"type": "symbol",
|
||||
"source": "geojson",
|
||||
"layout": {
|
||||
"text-field": "{name}",
|
||||
"text-font": [
|
||||
"Noto Sans Regular"
|
||||
],
|
||||
"symbol-placement": "point"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"network": [
|
||||
[
|
||||
"probeNetwork - default - end",
|
||||
4,
|
||||
596680
|
||||
],
|
||||
[
|
||||
"probeNetwork - default - start",
|
||||
0,
|
||||
0
|
||||
]
|
||||
],
|
||||
"gfx": [
|
||||
[
|
||||
"probeGFX - default - end",
|
||||
1,
|
||||
13,
|
||||
9,
|
||||
1,
|
||||
[
|
||||
364011,
|
||||
364011
|
||||
],
|
||||
[
|
||||
90850,
|
||||
90850
|
||||
],
|
||||
[
|
||||
1211104,
|
||||
1211104
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"network": [
|
||||
[
|
||||
"probeNetwork - default - end",
|
||||
5,
|
||||
690397
|
||||
],
|
||||
[
|
||||
"probeNetwork - default - start",
|
||||
0,
|
||||
0
|
||||
]
|
||||
],
|
||||
"gfx": [
|
||||
[
|
||||
"probeGFX - default - end",
|
||||
1,
|
||||
13,
|
||||
9,
|
||||
1,
|
||||
[
|
||||
675950,
|
||||
675950
|
||||
],
|
||||
[
|
||||
97714,
|
||||
97714
|
||||
],
|
||||
[
|
||||
1302624,
|
||||
1302624
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"network": [
|
||||
[
|
||||
"probeNetwork - default - end",
|
||||
4,
|
||||
636079
|
||||
],
|
||||
[
|
||||
"probeNetwork - default - start",
|
||||
0,
|
||||
0
|
||||
]
|
||||
],
|
||||
"gfx": [
|
||||
[
|
||||
"probeGFX - default - end",
|
||||
1,
|
||||
13,
|
||||
9,
|
||||
1,
|
||||
[
|
||||
488883,
|
||||
488883
|
||||
],
|
||||
[
|
||||
106570,
|
||||
106570
|
||||
],
|
||||
[
|
||||
1420704,
|
||||
1420704
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"network": [
|
||||
[
|
||||
"probeNetwork - default - end",
|
||||
4,
|
||||
596680
|
||||
],
|
||||
[
|
||||
"probeNetwork - default - start",
|
||||
0,
|
||||
0
|
||||
]
|
||||
],
|
||||
"gfx": [
|
||||
[
|
||||
"probeGFX - default - end",
|
||||
1,
|
||||
13,
|
||||
9,
|
||||
1,
|
||||
[
|
||||
364011,
|
||||
364011
|
||||
],
|
||||
[
|
||||
90850,
|
||||
90850
|
||||
],
|
||||
[
|
||||
1211104,
|
||||
1211104
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"network": [
|
||||
[
|
||||
"probeNetwork - default - end",
|
||||
5,
|
||||
690397
|
||||
],
|
||||
[
|
||||
"probeNetwork - default - start",
|
||||
0,
|
||||
0
|
||||
]
|
||||
],
|
||||
"gfx": [
|
||||
[
|
||||
"probeGFX - default - end",
|
||||
1,
|
||||
13,
|
||||
9,
|
||||
1,
|
||||
[
|
||||
675950,
|
||||
675950
|
||||
],
|
||||
[
|
||||
97714,
|
||||
97714
|
||||
],
|
||||
[
|
||||
1302624,
|
||||
1302624
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"network": [
|
||||
[
|
||||
"probeNetwork - default - end",
|
||||
4,
|
||||
636079
|
||||
],
|
||||
[
|
||||
"probeNetwork - default - start",
|
||||
0,
|
||||
0
|
||||
]
|
||||
],
|
||||
"gfx": [
|
||||
[
|
||||
"probeGFX - default - end",
|
||||
1,
|
||||
13,
|
||||
9,
|
||||
1,
|
||||
[
|
||||
488883,
|
||||
488883
|
||||
],
|
||||
[
|
||||
106570,
|
||||
106570
|
||||
],
|
||||
[
|
||||
1420704,
|
||||
1420704
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"network": [
|
||||
[
|
||||
"probeNetwork - default - end",
|
||||
4,
|
||||
596680
|
||||
],
|
||||
[
|
||||
"probeNetwork - default - start",
|
||||
0,
|
||||
0
|
||||
]
|
||||
],
|
||||
"gfx": [
|
||||
[
|
||||
"probeGFX - default - end",
|
||||
1,
|
||||
13,
|
||||
9,
|
||||
1,
|
||||
[
|
||||
364011,
|
||||
364011
|
||||
],
|
||||
[
|
||||
90850,
|
||||
90850
|
||||
],
|
||||
[
|
||||
1211104,
|
||||
1211104
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"network": [
|
||||
[
|
||||
"probeNetwork - default - end",
|
||||
5,
|
||||
690397
|
||||
],
|
||||
[
|
||||
"probeNetwork - default - start",
|
||||
0,
|
||||
0
|
||||
]
|
||||
],
|
||||
"gfx": [
|
||||
[
|
||||
"probeGFX - default - end",
|
||||
1,
|
||||
13,
|
||||
9,
|
||||
1,
|
||||
[
|
||||
675950,
|
||||
675950
|
||||
],
|
||||
[
|
||||
97714,
|
||||
97714
|
||||
],
|
||||
[
|
||||
1302624,
|
||||
1302624
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"network": [
|
||||
[
|
||||
"probeNetwork - default - end",
|
||||
4,
|
||||
636079
|
||||
],
|
||||
[
|
||||
"probeNetwork - default - start",
|
||||
0,
|
||||
0
|
||||
]
|
||||
],
|
||||
"gfx": [
|
||||
[
|
||||
"probeGFX - default - end",
|
||||
1,
|
||||
13,
|
||||
9,
|
||||
1,
|
||||
[
|
||||
488883,
|
||||
488883
|
||||
],
|
||||
[
|
||||
106570,
|
||||
106570
|
||||
],
|
||||
[
|
||||
1420704,
|
||||
1420704
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"network": [
|
||||
[
|
||||
"probeNetwork - default - end",
|
||||
4,
|
||||
596680
|
||||
],
|
||||
[
|
||||
"probeNetwork - default - start",
|
||||
0,
|
||||
0
|
||||
]
|
||||
],
|
||||
"gfx": [
|
||||
[
|
||||
"probeGFX - default - end",
|
||||
1,
|
||||
13,
|
||||
9,
|
||||
1,
|
||||
[
|
||||
364011,
|
||||
364011
|
||||
],
|
||||
[
|
||||
90850,
|
||||
90850
|
||||
],
|
||||
[
|
||||
1211104,
|
||||
1211104
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"network": [
|
||||
[
|
||||
"probeNetwork - default - end",
|
||||
5,
|
||||
690397
|
||||
],
|
||||
[
|
||||
"probeNetwork - default - start",
|
||||
0,
|
||||
0
|
||||
]
|
||||
],
|
||||
"gfx": [
|
||||
[
|
||||
"probeGFX - default - end",
|
||||
1,
|
||||
13,
|
||||
9,
|
||||
1,
|
||||
[
|
||||
675950,
|
||||
675950
|
||||
],
|
||||
[
|
||||
97714,
|
||||
97714
|
||||
],
|
||||
[
|
||||
1302624,
|
||||
1302624
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"network": [
|
||||
[
|
||||
"probeNetwork - default - end",
|
||||
4,
|
||||
636079
|
||||
],
|
||||
[
|
||||
"probeNetwork - default - start",
|
||||
0,
|
||||
0
|
||||
]
|
||||
],
|
||||
"gfx": [
|
||||
[
|
||||
"probeGFX - default - end",
|
||||
1,
|
||||
13,
|
||||
9,
|
||||
1,
|
||||
[
|
||||
488883,
|
||||
488883
|
||||
],
|
||||
[
|
||||
106570,
|
||||
106570
|
||||
],
|
||||
[
|
||||
1420704,
|
||||
1420704
|
||||
]
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -207,6 +207,7 @@ objc_library(
|
||||
"libz",
|
||||
"libsqlite3",
|
||||
"libc++",
|
||||
"libbz2",
|
||||
],
|
||||
sdk_frameworks = [
|
||||
"MobileCoreServices",
|
||||
|
||||
@@ -44,7 +44,7 @@ LocalGlyphRasterizer::LocalGlyphRasterizer() {
|
||||
|
||||
PremultipliedImage LocalGlyphRasterizer::drawGlyphBitmap(const std::string& fontFamily,
|
||||
const bool bold,
|
||||
const GlyphID glyphID) {
|
||||
const char16_t glyphID) {
|
||||
UniqueEnv env{AttachEnv()};
|
||||
|
||||
static auto& javaClass = jni::Class<LocalGlyphRasterizer>::Singleton(*env);
|
||||
|
||||
@@ -224,10 +224,12 @@ OfflineRegionStatus OfflineDownload::getStatus() const {
|
||||
}
|
||||
|
||||
if (!parser.glyphURL.empty()) {
|
||||
uint32_t ttfCount = 0;
|
||||
if (parser.fontFaces) ttfCount = static_cast<uint32_t>(parser.fontFaces->size()); // custom faces
|
||||
result->requiredResourceCount += parser.fontStacks().size() *
|
||||
(std::visit([](auto& reg) { return reg.includeIdeographs; }, definition)
|
||||
? GLYPH_RANGES_PER_FONT_STACK
|
||||
: NON_IDEOGRAPH_GLYPH_RANGES_PER_FONT_STACK);
|
||||
? GLYPH_RANGES_PER_FONT_STACK + ttfCount
|
||||
: NON_IDEOGRAPH_GLYPH_RANGES_PER_FONT_STACK + ttfCount);
|
||||
}
|
||||
|
||||
if (!parser.sprites.empty()) {
|
||||
@@ -342,8 +344,15 @@ void OfflineDownload::activateDownload() {
|
||||
// Assumes that if a glyph range starts with fixed width/ideographic
|
||||
// characters, the entire range will be fixed width.
|
||||
if (includeIdeographs || !util::i18n::allowsFixedWidthGlyphGeneration(i * GLYPHS_PER_GLYPH_RANGE)) {
|
||||
queueResource(
|
||||
Resource::glyphs(parser.glyphURL, fontStack, getGlyphRange(i * GLYPHS_PER_GLYPH_RANGE)));
|
||||
auto range = getGlyphRange(i * GLYPHS_PER_GLYPH_RANGE);
|
||||
queueResource(Resource::glyphs(
|
||||
parser.glyphURL, fontStack, std::pair<uint16_t, uint16_t>{range.first, range.second}));
|
||||
}
|
||||
if (parser.fontFaces) {
|
||||
FontFaces& faces = *parser.fontFaces;
|
||||
for (const auto& face : faces) {
|
||||
queueResource(Resource::fontFace(face.url));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,8 +40,13 @@ LocalGlyphRasterizer::LocalGlyphRasterizer(const std::optional<std::string>& fon
|
||||
LocalGlyphRasterizer::~LocalGlyphRasterizer() {}
|
||||
|
||||
bool LocalGlyphRasterizer::canRasterizeGlyph(const FontStack&, GlyphID glyphID) {
|
||||
#ifdef MLN_TEXT_SHAPING_HARFBUZZ
|
||||
return impl->isConfigured() && impl->metrics->inFont(glyphID.complex.code) &&
|
||||
util::i18n::allowsFixedWidthGlyphGeneration(glyphID);
|
||||
#else
|
||||
return impl->isConfigured() && impl->metrics->inFont(glyphID) &&
|
||||
util::i18n::allowsFixedWidthGlyphGeneration(glyphID);
|
||||
#endif
|
||||
}
|
||||
|
||||
Glyph LocalGlyphRasterizer::rasterizeGlyph(const FontStack&, GlyphID glyphID) {
|
||||
@@ -53,7 +58,11 @@ Glyph LocalGlyphRasterizer::rasterizeGlyph(const FontStack&, GlyphID glyphID) {
|
||||
return glyph;
|
||||
}
|
||||
|
||||
#ifdef MLN_TEXT_SHAPING_HARFBUZZ
|
||||
glyph.metrics.width = impl->metrics->horizontalAdvance(glyphID.complex.code);
|
||||
#else
|
||||
glyph.metrics.width = impl->metrics->horizontalAdvance(glyphID);
|
||||
#endif
|
||||
glyph.metrics.height = impl->metrics->height();
|
||||
glyph.metrics.left = 3;
|
||||
glyph.metrics.top = -8;
|
||||
@@ -66,8 +75,13 @@ Glyph LocalGlyphRasterizer::rasterizeGlyph(const FontStack&, GlyphID glyphID) {
|
||||
QPainter painter(&image);
|
||||
painter.setFont(impl->font);
|
||||
painter.setRenderHints(QPainter::TextAntialiasing);
|
||||
|
||||
// Render at constant baseline, to align with glyphs that are rendered by node-fontnik.
|
||||
#ifdef MLN_TEXT_SHAPING_HARFBUZZ
|
||||
painter.drawText(QPointF(0, 20), QString(QChar(glyphID.complex.code)));
|
||||
#else
|
||||
painter.drawText(QPointF(0, 20), QString(QChar(glyphID)));
|
||||
#endif
|
||||
|
||||
auto img = std::make_unique<uint8_t[]>(image.sizeInBytes());
|
||||
memcpy(img.get(), image.constBits(), image.sizeInBytes());
|
||||
|
||||
@@ -61,7 +61,7 @@ GlyphAtlas DynamicTextureAtlas::uploadGlyphs(const GlyphMap& glyphs) {
|
||||
const auto& glyph = glyphEntry.second;
|
||||
|
||||
if (glyph.has_value() && glyph.value()->bitmap.valid()) {
|
||||
int32_t uniqueId = static_cast<int32_t>(sqrt(fontStack) / 2 + glyph.value()->id);
|
||||
int32_t uniqueId = static_cast<int32_t>(sqrt(fontStack) / 2 + glyph.value()->id.hash);
|
||||
const auto size = Size(glyph.value()->bitmap.size.width + 2 * padding,
|
||||
glyph.value()->bitmap.size.height + 2 * padding);
|
||||
const auto& texHandle = glyphAtlas.dynamicTexture->reserveSize(size, uniqueId);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <mbgl/style/image_impl.hpp>
|
||||
#include <mbgl/text/glyph.hpp>
|
||||
#include <mbgl/tile/geometry_tile_data.hpp>
|
||||
#include <mbgl/text/glyph_manager.hpp>
|
||||
#include <mbgl/util/containers.hpp>
|
||||
#include <memory>
|
||||
|
||||
@@ -13,6 +14,7 @@ class BucketParameters;
|
||||
class RenderLayer;
|
||||
class FeatureIndex;
|
||||
class LayerRenderData;
|
||||
class GlyphManager;
|
||||
|
||||
class Layout {
|
||||
public:
|
||||
@@ -27,6 +29,10 @@ public:
|
||||
|
||||
virtual void prepareSymbols(const GlyphMap&, const GlyphPositions&, const ImageMap&, const ImagePositions&) {}
|
||||
|
||||
virtual void finalizeSymbols(HBShapeResults&) {}
|
||||
|
||||
virtual bool needFinalizeSymbols() { return false; }
|
||||
|
||||
virtual bool hasSymbolInstances() const { return true; }
|
||||
|
||||
virtual bool hasDependencies() const = 0;
|
||||
@@ -35,6 +41,7 @@ public:
|
||||
class LayoutParameters {
|
||||
public:
|
||||
const BucketParameters& bucketParameters;
|
||||
std::shared_ptr<FontFaces> fontFaces;
|
||||
GlyphDependencies& glyphDependencies;
|
||||
ImageDependencies& imageDependencies;
|
||||
std::set<std::string>& availableImages;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <mbgl/renderer/layers/render_symbol_layer.hpp>
|
||||
#include <mbgl/text/get_anchors.hpp>
|
||||
#include <mbgl/text/shaping.hpp>
|
||||
#include <mbgl/text/glyph_manager.hpp>
|
||||
#include <mbgl/tile/geometry_tile_data.hpp>
|
||||
#include <mbgl/tile/tile.hpp>
|
||||
#include <mbgl/util/utf.hpp>
|
||||
@@ -82,6 +83,31 @@ inline Immutable<style::SymbolLayoutProperties::PossiblyEvaluated> createLayout(
|
||||
return layout;
|
||||
}
|
||||
|
||||
GlyphIDType getCharGlyphIDType(char16_t ch,
|
||||
const FontStack& stack,
|
||||
std::shared_ptr<FontFaces> faces,
|
||||
GlyphIDType lastCharType) {
|
||||
if (!faces) {
|
||||
return GlyphIDType::FontPBF;
|
||||
}
|
||||
|
||||
if (util::i18n::isVariationSelector1(ch)) {
|
||||
return lastCharType;
|
||||
}
|
||||
|
||||
for (const auto& name : stack) {
|
||||
for (auto& face : *faces) {
|
||||
if (face.name == name) {
|
||||
for (auto& range : face.ranges) {
|
||||
if (ch >= range.first && ch <= range.second) return face.type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return GlyphIDType::FontPBF;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
SymbolLayout::SymbolLayout(const BucketParameters& parameters,
|
||||
@@ -153,19 +179,72 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters,
|
||||
FontStack baseFontStack = layout->evaluate<TextFont>(zoom, ft, canonicalID);
|
||||
|
||||
ft.formattedText = TaggedString();
|
||||
for (const auto& section : formatted.sections) {
|
||||
std::map<std::size_t, std::size_t> sectionTable;
|
||||
|
||||
for (std::size_t sectionIndex = 0; sectionIndex < formatted.sections.size(); sectionIndex++) {
|
||||
const auto& section = formatted.sections[sectionIndex];
|
||||
|
||||
if (!section.image) {
|
||||
std::string u8string = section.text;
|
||||
if (textTransform == TextTransformType::Uppercase) {
|
||||
u8string = platform::uppercase(u8string);
|
||||
} else if (textTransform == TextTransformType::Lowercase) {
|
||||
u8string = platform::lowercase(u8string);
|
||||
}
|
||||
try {
|
||||
ft.formattedText->addTextSection(applyArabicShaping(util::convertUTF8ToUTF16(u8string)),
|
||||
section.fontScale ? *section.fontScale : 1.0,
|
||||
section.fontStack ? *section.fontStack : baseFontStack,
|
||||
section.textColor);
|
||||
std::string u8string = section.text;
|
||||
if (textTransform == TextTransformType::Uppercase) {
|
||||
u8string = platform::uppercase(u8string);
|
||||
} else if (textTransform == TextTransformType::Lowercase) {
|
||||
u8string = platform::lowercase(u8string);
|
||||
}
|
||||
|
||||
auto u16String = applyArabicShaping(util::convertUTF8ToUTF16(u8string));
|
||||
const char16_t* u16Char = u16String.data();
|
||||
std::u16string subString;
|
||||
auto sectionScale = section.fontScale ? *section.fontScale : 1.0;
|
||||
auto sectionFontStack = section.fontStack ? *section.fontStack : baseFontStack;
|
||||
|
||||
GlyphIDType subStringtype = getCharGlyphIDType(
|
||||
*u16Char, sectionFontStack, layoutParameters.fontFaces, GlyphIDType::FontPBF);
|
||||
|
||||
while (*u16Char) {
|
||||
const auto chType = getCharGlyphIDType(
|
||||
*u16Char, sectionFontStack, layoutParameters.fontFaces, subStringtype);
|
||||
if (chType != subStringtype) {
|
||||
if (subString.length()) {
|
||||
ft.formattedText->addTextSection(subString,
|
||||
sectionScale,
|
||||
sectionFontStack,
|
||||
subStringtype,
|
||||
false,
|
||||
section.textColor);
|
||||
sectionTable[ft.formattedText->getSections().size() - 1] = sectionIndex;
|
||||
if (subStringtype != GlyphIDType::FontPBF) {
|
||||
layoutParameters.glyphDependencies
|
||||
.shapes[section.fontStack ? *section.fontStack : baseFontStack]
|
||||
[subStringtype]
|
||||
.insert(subString);
|
||||
}
|
||||
}
|
||||
|
||||
subString.clear();
|
||||
subStringtype = chType;
|
||||
}
|
||||
|
||||
subString += *u16Char;
|
||||
|
||||
++u16Char;
|
||||
}
|
||||
|
||||
if (subString.length()) {
|
||||
ft.formattedText->addTextSection(subString,
|
||||
section.fontScale ? *section.fontScale : 1.0,
|
||||
section.fontStack ? *section.fontStack : baseFontStack,
|
||||
subStringtype,
|
||||
true,
|
||||
section.textColor);
|
||||
sectionTable[ft.formattedText->getSections().size() - 1] = sectionIndex;
|
||||
if (subStringtype != GlyphIDType::FontPBF) {
|
||||
layoutParameters.glyphDependencies
|
||||
.shapes[section.fontStack ? *section.fontStack : baseFontStack][subStringtype]
|
||||
.insert(subString);
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
mbgl::Log::Error(
|
||||
mbgl::Event::ParseTile,
|
||||
@@ -186,17 +265,23 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters,
|
||||
|
||||
// Loop through all characters of this text and collect unique codepoints.
|
||||
for (std::size_t j = 0; j < ft.formattedText->length(); j++) {
|
||||
const auto& section = formatted.sections[ft.formattedText->getSectionIndex(j)];
|
||||
if (section.image) continue;
|
||||
|
||||
const auto& sectionFontStack = section.fontStack;
|
||||
uint8_t sectionIndex = ft.formattedText->getSectionIndex(j);
|
||||
auto& section = ft.formattedText->getSections()[sectionIndex];
|
||||
if (section.imageID) continue;
|
||||
const auto& sectionFontStack = formatted.sections[sectionTable[sectionIndex]].fontStack;
|
||||
GlyphIDs& dependencies =
|
||||
layoutParameters.glyphDependencies[sectionFontStack ? *sectionFontStack : baseFontStack];
|
||||
char16_t codePoint = ft.formattedText->getCharCodeAt(j);
|
||||
dependencies.insert(codePoint);
|
||||
if (canVerticalizeText || (allowVerticalPlacement && ft.formattedText->allowsVerticalWritingMode())) {
|
||||
if (char16_t verticalChr = util::i18n::verticalizePunctuation(codePoint)) {
|
||||
dependencies.insert(verticalChr);
|
||||
layoutParameters.glyphDependencies.glyphs[sectionFontStack ? *sectionFontStack : baseFontStack];
|
||||
if (section.type != FontPBF) {
|
||||
dependencies.insert(GlyphID(0, section.type));
|
||||
needFinalizeSymbolsVal = true;
|
||||
} else {
|
||||
char16_t codePoint = ft.formattedText->getCharCodeAt(j);
|
||||
dependencies.insert(codePoint);
|
||||
if (canVerticalizeText ||
|
||||
(allowVerticalPlacement && ft.formattedText->allowsVerticalWritingMode())) {
|
||||
if (char16_t verticalChr = util::i18n::verticalizePunctuation(codePoint)) {
|
||||
dependencies.insert(verticalChr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -223,6 +308,74 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters,
|
||||
}
|
||||
}
|
||||
|
||||
void SymbolLayout::finalizeSymbols(HBShapeResults& results) {
|
||||
for (auto& feature : features) {
|
||||
if (feature.geometry.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (feature.formattedText && feature.formattedText->hasNeedHBShapeText() &&
|
||||
!feature.formattedText->hbShaped()) {
|
||||
auto shapedString = TaggedString();
|
||||
|
||||
const auto& sections = feature.formattedText->getSections();
|
||||
const auto& styleText = feature.formattedText->getStyledText();
|
||||
|
||||
std::u16string subString;
|
||||
auto sectionIndex = styleText.second[0];
|
||||
auto strLen = styleText.first.length();
|
||||
|
||||
auto applySubString = [&]() {
|
||||
if (subString.length()) {
|
||||
auto& section = sections[sectionIndex];
|
||||
if (GlyphIDType::FontPBF == section.type) {
|
||||
shapedString.addTextSection(subString,
|
||||
section.scale,
|
||||
section.fontStack,
|
||||
section.type,
|
||||
section.keySection,
|
||||
section.textColor);
|
||||
} else {
|
||||
auto& fontstackResults = results[section.fontStack];
|
||||
auto& typeResults = fontstackResults[section.type];
|
||||
auto& result = typeResults[subString];
|
||||
|
||||
shapedString.addTextSection(result.str,
|
||||
section.scale,
|
||||
section.fontStack,
|
||||
section.type,
|
||||
result.adjusts,
|
||||
section.keySection,
|
||||
section.textColor);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (size_t charIndex = 0; charIndex < strLen; ++charIndex) {
|
||||
auto& ch = styleText.first[charIndex];
|
||||
auto& sec = styleText.second[charIndex];
|
||||
|
||||
if (sectionIndex != sec) {
|
||||
applySubString();
|
||||
|
||||
subString.clear();
|
||||
sectionIndex = sec;
|
||||
}
|
||||
|
||||
subString += ch;
|
||||
}
|
||||
|
||||
applySubString();
|
||||
|
||||
shapedString.setHBShaped(true);
|
||||
feature.formattedText = shapedString;
|
||||
|
||||
} // feature.formattedText
|
||||
} // for (auto & feature : features ..
|
||||
|
||||
needFinalizeSymbolsVal = false;
|
||||
} // SymbolLayout::finalizeSymbols
|
||||
|
||||
bool SymbolLayout::hasDependencies() const {
|
||||
return !features.empty();
|
||||
}
|
||||
|
||||
@@ -33,6 +33,10 @@ public:
|
||||
|
||||
~SymbolLayout() final = default;
|
||||
|
||||
bool needFinalizeSymbols() override { return needFinalizeSymbolsVal; }
|
||||
|
||||
void finalizeSymbols(HBShapeResults&) override;
|
||||
|
||||
void prepareSymbols(const GlyphMap& glyphMap,
|
||||
const GlyphPositions&,
|
||||
const ImageMap&,
|
||||
@@ -146,6 +150,8 @@ private:
|
||||
BiDi bidi; // Consider moving this up to geometry tile worker to reduce
|
||||
// reinstantiation costs; use of BiDi/ubiditransform object must
|
||||
// be constrained to one thread
|
||||
|
||||
bool needFinalizeSymbolsVal = false;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -120,6 +120,7 @@ void Map::Impl::onUpdate() {
|
||||
timePoint,
|
||||
transform.getState(),
|
||||
style->impl->getGlyphURL(),
|
||||
style->impl->getFontFaces(),
|
||||
style->impl->areSpritesLoaded(),
|
||||
style->impl->getTransitionOptions(),
|
||||
style->impl->getLight()->impl,
|
||||
|
||||
@@ -201,6 +201,7 @@ std::unique_ptr<RenderTree> RenderOrchestrator::createRenderTree(
|
||||
.dynamicTextureAtlas = dynamicTextureAtlas};
|
||||
|
||||
glyphManager->setURL(updateParameters->glyphURL);
|
||||
glyphManager->setFontFaces(updateParameters->fontFaces);
|
||||
|
||||
// Update light.
|
||||
const bool lightChanged = renderLight.impl != updateParameters->light;
|
||||
@@ -1022,10 +1023,16 @@ void RenderOrchestrator::onGlyphsError(const FontStack& fontStack,
|
||||
std::exception_ptr error) {
|
||||
MLN_TRACE_FUNC();
|
||||
|
||||
Log::Error(Event::Style,
|
||||
"Failed to load glyph range " + std::to_string(glyphRange.first) + "-" +
|
||||
std::to_string(glyphRange.second) + " for font stack " + fontStackToString(fontStack) + ": " +
|
||||
util::toString(error));
|
||||
std::stringstream ss;
|
||||
ss << "Failed to load glyph range ";
|
||||
if (glyphRange.type == FontPBF) {
|
||||
ss << glyphRange.first << "-" << glyphRange.second;
|
||||
} else {
|
||||
ss << (int)glyphRange.type << "(font file)";
|
||||
}
|
||||
ss << " for font stack " << fontStackToString(fontStack) << ":( " << util::toString(error) << ")";
|
||||
auto errorDetail = ss.str();
|
||||
Log::Error(Event::Style, errorDetail);
|
||||
observer->onResourceError(error);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <mbgl/style/image.hpp>
|
||||
#include <mbgl/style/source.hpp>
|
||||
#include <mbgl/style/layer.hpp>
|
||||
#include <mbgl/text/glyph.hpp>
|
||||
#include <mbgl/util/chrono.hpp>
|
||||
#include <mbgl/util/immutable.hpp>
|
||||
|
||||
@@ -29,6 +30,7 @@ public:
|
||||
const TransformState transformState;
|
||||
|
||||
const std::string glyphURL;
|
||||
std::shared_ptr<FontFaces> fontFaces;
|
||||
const bool spriteLoaded;
|
||||
const style::TransitionOptions transitionOptions;
|
||||
const Immutable<style::Light::Impl> light;
|
||||
|
||||
@@ -80,6 +80,10 @@ Resource Resource::glyphs(const std::string& urlTemplate,
|
||||
})};
|
||||
}
|
||||
|
||||
Resource Resource::fontFace(const std::string& url) {
|
||||
return Resource{Resource::Kind::Glyphs, url};
|
||||
}
|
||||
|
||||
Resource Resource::tile(const std::string& urlTemplate,
|
||||
float pixelRatio,
|
||||
int32_t x,
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <mbgl/util/logging.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
#include <mbgl/util/convert.hpp>
|
||||
|
||||
#include <mapbox/geojsonvt.hpp>
|
||||
|
||||
@@ -116,6 +117,83 @@ StyleParseResult Parser::parse(const std::string& json) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MLN_TEXT_SHAPING_HARFBUZZ
|
||||
// Ignore font-faces if no harfbuzz
|
||||
if (document.HasMember("font-faces")) {
|
||||
const JSValue& faces = document["font-faces"];
|
||||
if (faces.IsObject()) {
|
||||
fontFaces = std::make_shared<FontFaces>();
|
||||
for (auto it = faces.MemberBegin(); it != faces.MemberEnd(); ++it) {
|
||||
const std::string& faceName = it->name.GetString();
|
||||
const JSValue& faceValue = it->value;
|
||||
|
||||
if (faceValue.IsArray()) {
|
||||
// If the face is an array, we assume it is a list of font file objects.
|
||||
for (const auto& fontFile : faceValue.GetArray()) {
|
||||
if (fontFile.IsObject()) {
|
||||
FontFace fontFace(faceName, "", {{0, 0x10FFFF}});
|
||||
|
||||
// Parse url
|
||||
if (fontFile.HasMember("url")) {
|
||||
const JSValue& url = fontFile["url"];
|
||||
if (url.IsString()) fontFace.url = url.GetString();
|
||||
}
|
||||
|
||||
// Parse unicode-range
|
||||
if (fontFile.HasMember("unicode-range")) {
|
||||
const JSValue& unicodeRange = fontFile["unicode-range"];
|
||||
fontFace.ranges.clear();
|
||||
if (unicodeRange.IsArray()) {
|
||||
for (auto& range : unicodeRange.GetArray()) {
|
||||
if (range.IsString()) {
|
||||
std::string rangeString = range.GetString();
|
||||
if (rangeString.length() > 2) {
|
||||
rangeString = rangeString.substr(2);
|
||||
std::string::size_type pos = rangeString.find('-');
|
||||
if (pos != std::string::npos) {
|
||||
std::string start = rangeString.substr(0, pos);
|
||||
std::string end = rangeString.substr(pos + 1);
|
||||
if (!start.empty() && !end.empty()) {
|
||||
auto startInt = util::parse<int>(start, 16);
|
||||
auto endInt = util::parse<int>(end, 16);
|
||||
if (startInt && endInt) {
|
||||
fontFace.ranges.emplace_back(*startInt, *endInt);
|
||||
} else {
|
||||
Log::Warning(
|
||||
Event::ParseStyle,
|
||||
"Invalid unicode-range in font-face: " + rangeString);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If valid, generate a unique glyph ID type for this font face
|
||||
// and add it to the font faces list.
|
||||
if (fontFace.valid()) {
|
||||
fontFace.type = genNewGlyphIDType(
|
||||
fontFace.url, FontStack{fontFace.name}, fontFace.ranges);
|
||||
fontFaces->emplace_back(std::move(fontFace));
|
||||
} else {
|
||||
Log::Warning(Event::ParseStyle, "Invalid font-face definition for: " + faceName);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (faceValue.IsString()) {
|
||||
FontFace fontFace(faceName, faceValue.GetString(), {{0, 0x10FFFF}});
|
||||
fontFace.type = genNewGlyphIDType(fontFace.url, FontStack{fontFace.name}, fontFace.ranges);
|
||||
fontFaces->emplace_back(std::move(fontFace));
|
||||
} else {
|
||||
Log::Warning(Event::ParseStyle, "font-face must be an object or array");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
// Call for side effect of logging warnings for invalid values.
|
||||
fontStacks();
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
#include <mbgl/style/sprite.hpp>
|
||||
#include <mbgl/style/source.hpp>
|
||||
#include <mbgl/style/light.hpp>
|
||||
|
||||
#include <mbgl/text/glyph.hpp>
|
||||
|
||||
#include <mbgl/util/constants.hpp>
|
||||
#include <mbgl/util/rapidjson.hpp>
|
||||
#include <mbgl/util/font_stack.hpp>
|
||||
@@ -29,6 +32,7 @@ public:
|
||||
|
||||
std::vector<Sprite> sprites;
|
||||
std::string glyphURL;
|
||||
std::shared_ptr<FontFaces> fontFaces;
|
||||
|
||||
std::vector<std::unique_ptr<Source>> sources;
|
||||
std::vector<std::unique_ptr<Layer>> layers;
|
||||
|
||||
@@ -134,7 +134,7 @@ void Style::Impl::parse(const std::string& json_) {
|
||||
std::make_exception_ptr(std::runtime_error("Unable to find resource provider for sprite url.")));
|
||||
}
|
||||
glyphURL = parser.glyphURL;
|
||||
|
||||
fontFaces = parser.fontFaces;
|
||||
loaded = true;
|
||||
observer->onStyleLoaded();
|
||||
}
|
||||
@@ -427,6 +427,10 @@ const std::string& Style::Impl::getGlyphURL() const {
|
||||
return glyphURL;
|
||||
}
|
||||
|
||||
std::shared_ptr<FontFaces> Style::Impl::getFontFaces() const {
|
||||
return fontFaces;
|
||||
}
|
||||
|
||||
Immutable<std::vector<Immutable<Image::Impl>>> Style::Impl::getImageImpls() const {
|
||||
return images;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include <mbgl/style/layer.hpp>
|
||||
#include <mbgl/style/collection.hpp>
|
||||
|
||||
#include <mbgl/text/glyph.hpp>
|
||||
|
||||
#include <mbgl/map/camera.hpp>
|
||||
|
||||
#include <mbgl/util/noncopyable.hpp>
|
||||
@@ -80,6 +82,7 @@ public:
|
||||
void removeImage(const std::string&);
|
||||
|
||||
const std::string& getGlyphURL() const;
|
||||
std::shared_ptr<FontFaces> getFontFaces() const;
|
||||
|
||||
using ImageImpls = std::vector<Immutable<Image::Impl>>;
|
||||
Immutable<ImageImpls> getImageImpls() const;
|
||||
@@ -104,6 +107,7 @@ private:
|
||||
std::unique_ptr<SpriteLoader> spriteLoader;
|
||||
|
||||
std::string glyphURL;
|
||||
std::shared_ptr<FontFaces> fontFaces;
|
||||
Immutable<ImageImpls> images = makeMutable<ImageImpls>();
|
||||
CollectionWithPersistentOrder<Source> sources;
|
||||
Collection<Layer> layers;
|
||||
|
||||
98
src/mbgl/text/freetype.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
#include "freetype.hpp"
|
||||
|
||||
#include <mbgl/text/glyph.hpp>
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
//
|
||||
// FreeTypeLibray
|
||||
//
|
||||
|
||||
#define SDF_FONT_SIZE 24
|
||||
|
||||
FreeTypeLibrary::FreeTypeLibrary() {
|
||||
FT_Init_FreeType(&library);
|
||||
}
|
||||
|
||||
FreeTypeLibrary::~FreeTypeLibrary() {
|
||||
FT_Done_FreeType(library);
|
||||
}
|
||||
|
||||
// FreeTypeFace
|
||||
|
||||
FreeTypeFace::FreeTypeFace(const std::string &fontFileName, const FreeTypeLibrary &lib) {
|
||||
FT_Error error = FT_New_Face(lib.library, fontFileName.c_str(), 0, &face);
|
||||
valid = (error == 0);
|
||||
if (!valid) return;
|
||||
|
||||
force_ucs2_charmap(face);
|
||||
FT_Set_Char_Size(face, 0, SDF_FONT_SIZE * 64, 72, 72);
|
||||
}
|
||||
|
||||
FreeTypeFace::FreeTypeFace(const char *fontData, size_t fontDataSize, const FreeTypeLibrary &lib) {
|
||||
memoryFile.resize(fontDataSize);
|
||||
std::memcpy(memoryFile.data(), fontData, fontDataSize);
|
||||
FT_Error error = FT_New_Memory_Face(lib.library, memoryFile.data(), (FT_Long)fontDataSize, 0, &face);
|
||||
valid = (error == 0);
|
||||
if (!valid) return;
|
||||
|
||||
force_ucs2_charmap(face);
|
||||
FT_Set_Char_Size(face, 0, SDF_FONT_SIZE * 64, 72, 72);
|
||||
}
|
||||
|
||||
FreeTypeFace::~FreeTypeFace() {
|
||||
if (valid) FT_Done_Face(face);
|
||||
}
|
||||
|
||||
int FreeTypeFace::force_ucs2_charmap(FT_Face ftf) {
|
||||
for (int i = 0; i < ftf->num_charmaps; i++) {
|
||||
if (((ftf->charmaps[i]->platform_id == 0) && (ftf->charmaps[i]->encoding_id == 3)) ||
|
||||
((ftf->charmaps[i]->platform_id == 3) && (ftf->charmaps[i]->encoding_id == 1))) {
|
||||
return FT_Set_Charmap(ftf, ftf->charmaps[i]);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
Glyph FreeTypeFace::rasterizeGlyph(const GlyphID &glyph) {
|
||||
Glyph fixedMetrics;
|
||||
|
||||
FT_Int32 flags = FT_LOAD_DEFAULT;
|
||||
|
||||
FT_Load_Glyph(face,
|
||||
(FT_UInt)glyph.complex.code, // the glyph_index in the font file
|
||||
flags);
|
||||
|
||||
FT_GlyphSlot slot = face->glyph;
|
||||
FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL);
|
||||
|
||||
const FT_Bitmap &ftBitmap = slot->bitmap;
|
||||
|
||||
fixedMetrics.id = glyph;
|
||||
|
||||
Size size(ftBitmap.width + Glyph::borderSize * 2, ftBitmap.rows + Glyph::borderSize * 2);
|
||||
|
||||
fixedMetrics.metrics.width = size.width;
|
||||
fixedMetrics.metrics.height = size.height;
|
||||
fixedMetrics.metrics.left = slot->bitmap_left;
|
||||
fixedMetrics.metrics.top = slot->bitmap_top - SDF_FONT_SIZE - Glyph::borderSize;
|
||||
fixedMetrics.metrics.advance = (uint32_t)(slot->metrics.horiAdvance / 64);
|
||||
|
||||
// Copy alpha values from RGBA bitmap into the AlphaImage output
|
||||
fixedMetrics.bitmap = AlphaImage(size);
|
||||
|
||||
for (uint32_t h = 0; h < ftBitmap.rows; ++h) {
|
||||
std::memcpy(&fixedMetrics.bitmap.data[size.width * (h + Glyph::borderSize) + Glyph::borderSize],
|
||||
&ftBitmap.buffer[ftBitmap.width * h],
|
||||
ftBitmap.width);
|
||||
}
|
||||
|
||||
return fixedMetrics;
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
51
src/mbgl/text/freetype.hpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/text/glyph.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
struct FT_FaceRec_;
|
||||
struct FT_LibraryRec_;
|
||||
|
||||
using FT_Face = FT_FaceRec_ *;
|
||||
using FT_Library = FT_LibraryRec_ *;
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class FreeTypeLibrary {
|
||||
public:
|
||||
friend class FreeTypeFace;
|
||||
FreeTypeLibrary();
|
||||
~FreeTypeLibrary();
|
||||
|
||||
private:
|
||||
FT_Library library = nullptr;
|
||||
};
|
||||
|
||||
// call back format: width, height, left, top, advance, bitmap data
|
||||
using GlyphCallBack = std::function<void(uint32_t, uint32_t, int, int, uint32_t, unsigned char *)>;
|
||||
|
||||
class FreeTypeFace {
|
||||
public:
|
||||
explicit FreeTypeFace(const std::string &fontFileName, const FreeTypeLibrary &lib);
|
||||
explicit FreeTypeFace(const char *fontData, size_t fontDataSize, const FreeTypeLibrary &lib);
|
||||
~FreeTypeFace();
|
||||
|
||||
Glyph rasterizeGlyph(const GlyphID &glyph);
|
||||
|
||||
bool isValid() const { return valid; }
|
||||
|
||||
FT_Face getFace() { return face; }
|
||||
|
||||
private:
|
||||
FT_Face face;
|
||||
int force_ucs2_charmap(FT_Face ftf);
|
||||
std::vector<uint8_t> memoryFile;
|
||||
|
||||
bool valid = false;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
@@ -1,14 +1,63 @@
|
||||
#include <mbgl/text/glyph.hpp>
|
||||
#include <mbgl/util/i18n.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
GlyphRange::GlyphRange(uint32_t first_, uint32_t second_, GlyphIDType type_)
|
||||
: first((uint16_t)first_),
|
||||
second((uint16_t)second_),
|
||||
type(type_) {}
|
||||
|
||||
bool GlyphRange::operator==(const GlyphRange &other) const {
|
||||
return first == other.first && second == other.second && type == other.type;
|
||||
}
|
||||
|
||||
bool GlyphRange::operator<(const GlyphRange &other) const {
|
||||
if (first < other.first) return true;
|
||||
if (first > other.first) return false;
|
||||
|
||||
if (second < other.second) return true;
|
||||
if (second > other.second) return false;
|
||||
|
||||
return type < other.type;
|
||||
}
|
||||
|
||||
GlyphIDType genNewGlyphIDType() {
|
||||
static short glyphType = GlyphIDType::FontPBF;
|
||||
++glyphType;
|
||||
if (glyphType == GlyphIDType::FontPBF) ++glyphType;
|
||||
return static_cast<GlyphIDType>(glyphType);
|
||||
}
|
||||
|
||||
GlyphIDType genNewGlyphIDType(const std::string &url,
|
||||
const FontStack &fontStack,
|
||||
const std::vector<std::pair<uint32_t, uint32_t>> &pairs) {
|
||||
static std::map<std::string, std::map<std::string, std::map<std::size_t, GlyphIDType>>> glyphTypes;
|
||||
|
||||
std::size_t hash = 0;
|
||||
for (auto &pair : pairs) {
|
||||
mbgl::util::hash_combine(hash, pair.first);
|
||||
mbgl::util::hash_combine(hash, pair.second);
|
||||
}
|
||||
|
||||
auto family = fontStackToString(fontStack);
|
||||
|
||||
auto type = glyphTypes[url][family][hash];
|
||||
if (type == GlyphIDType::FontPBF) {
|
||||
type = genNewGlyphIDType();
|
||||
glyphTypes[url][family][hash] = type;
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
// Note: this only works for the BMP
|
||||
GlyphRange getGlyphRange(GlyphID glyph) {
|
||||
unsigned start = (glyph / 256) * 256;
|
||||
unsigned start = (glyph.complex.code / 256) * 256;
|
||||
unsigned end = (start + 255);
|
||||
if (start > 65280) start = 65280;
|
||||
if (end > 65535) end = 65535;
|
||||
return {start, end};
|
||||
return {start, end, glyph.complex.type};
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
#include <mbgl/util/async_request.hpp>
|
||||
#include <mbgl/util/std.hpp>
|
||||
#include <mbgl/util/tiny_sdf.hpp>
|
||||
#include <mbgl/util/image.hpp>
|
||||
#include <mbgl/util/logging.hpp>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
@@ -16,11 +20,12 @@ GlyphManager::GlyphManager(std::unique_ptr<LocalGlyphRasterizer> localGlyphRaste
|
||||
: observer(&nullObserver),
|
||||
localGlyphRasterizer(std::move(localGlyphRasterizer_)) {}
|
||||
|
||||
GlyphManager::~GlyphManager() = default;
|
||||
GlyphManager::~GlyphManager() {
|
||||
hbShapers.clear(); // clear harfbuzz + freetype face before library;
|
||||
}
|
||||
|
||||
void GlyphManager::getGlyphs(GlyphRequestor& requestor, GlyphDependencies glyphDependencies, FileSource& fileSource) {
|
||||
auto dependencies = std::make_shared<GlyphDependencies>(std::move(glyphDependencies));
|
||||
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> readWriteLock(rwLock);
|
||||
// Figure out which glyph ranges need to be fetched. For each range that
|
||||
@@ -28,7 +33,7 @@ void GlyphManager::getGlyphs(GlyphRequestor& requestor, GlyphDependencies glyphD
|
||||
// shared pointer containing the dependencies. When the shared pointer
|
||||
// becomes unique, we know that all the dependencies for that requestor have
|
||||
// been fetched, and can notify it of completion.
|
||||
for (const auto& dependency : *dependencies) {
|
||||
for (const auto& dependency : dependencies->glyphs) {
|
||||
const FontStack& fontStack = dependency.first;
|
||||
Entry& entry = entries[fontStack];
|
||||
|
||||
@@ -75,12 +80,26 @@ void GlyphManager::requestRange(GlyphRequest& request,
|
||||
if (request.req) {
|
||||
return;
|
||||
}
|
||||
Resource res(Resource::Kind::Unknown, "");
|
||||
switch (range.type) {
|
||||
case GlyphIDType::FontPBF:
|
||||
res = Resource::glyphs(glyphURL, fontStack, std::pair<uint16_t, uint16_t>{range.first, range.second});
|
||||
break;
|
||||
default: {
|
||||
std::string url = getFontFaceURL(range.type);
|
||||
if (url.size()) {
|
||||
res = Resource::fontFace(url);
|
||||
} else {
|
||||
Log::Error(Event::Style, "Try download a glyph doesn't in current faces");
|
||||
}
|
||||
|
||||
} break;
|
||||
}
|
||||
|
||||
observer->onGlyphsRequested(fontStack, range);
|
||||
|
||||
request.req = fileSource.request(
|
||||
Resource::glyphs(glyphURL, fontStack, range),
|
||||
[this, fontStack, range](const Response& res) { processResponse(res, fontStack, range); });
|
||||
res, [this, fontStack, range](const Response& response) { processResponse(response, fontStack, range); });
|
||||
}
|
||||
|
||||
void GlyphManager::processResponse(const Response& res, const FontStack& fontStack, const GlyphRange& range) {
|
||||
@@ -103,7 +122,15 @@ void GlyphManager::processResponse(const Response& res, const FontStack& fontSta
|
||||
std::vector<Glyph> glyphs;
|
||||
|
||||
try {
|
||||
glyphs = parseGlyphPBF(range, *res.data);
|
||||
if (range.type == GlyphIDType::FontPBF) {
|
||||
glyphs = parseGlyphPBF(range, *res.data);
|
||||
} else {
|
||||
if (loadHBShaper(fontStack, range.type, *res.data)) {
|
||||
Glyph temp;
|
||||
temp.id = GlyphID(0, range.type);
|
||||
glyphs.emplace_back(std::move(temp));
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
observer->onGlyphsError(fontStack, range, std::current_exception());
|
||||
return;
|
||||
@@ -141,7 +168,7 @@ void GlyphManager::setObserver(GlyphManagerObserver* observer_) {
|
||||
void GlyphManager::notify(GlyphRequestor& requestor, const GlyphDependencies& glyphDependencies) {
|
||||
GlyphMap response;
|
||||
|
||||
for (const auto& dependency : glyphDependencies) {
|
||||
for (const auto& dependency : glyphDependencies.glyphs) {
|
||||
const FontStack& fontStack = dependency.first;
|
||||
const GlyphIDs& glyphIDs = dependency.second;
|
||||
|
||||
@@ -158,7 +185,7 @@ void GlyphManager::notify(GlyphRequestor& requestor, const GlyphDependencies& gl
|
||||
}
|
||||
}
|
||||
|
||||
requestor.onGlyphsAvailable(response);
|
||||
requestor.onGlyphsAvailable(response, glyphDependencies.shapes);
|
||||
}
|
||||
|
||||
void GlyphManager::removeRequestor(GlyphRequestor& requestor) {
|
||||
@@ -175,4 +202,68 @@ void GlyphManager::evict(const std::set<FontStack>& keep) {
|
||||
util::erase_if(entries, [&](const auto& entry) { return keep.count(entry.first) == 0; });
|
||||
}
|
||||
|
||||
std::shared_ptr<HBShaper> GlyphManager::getHBShaper(FontStack fontStack, GlyphIDType type) {
|
||||
if (hbShapers.find(fontStack) != hbShapers.end()) {
|
||||
auto& glyphs = hbShapers[fontStack];
|
||||
if (glyphs.find(type) != glyphs.end()) {
|
||||
return glyphs[type];
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool GlyphManager::loadHBShaper(const FontStack& fontStack, GlyphIDType type, const std::string& data) {
|
||||
auto shaper = std::make_shared<HBShaper>(type, data, ftLibrary);
|
||||
if (!shaper->valid()) return false;
|
||||
hbShapers[fontStack][type] = shaper;
|
||||
return true;
|
||||
}
|
||||
|
||||
Immutable<Glyph> GlyphManager::getGlyph(const FontStack& fontStack, GlyphID glyphID) {
|
||||
auto& entry = entries[fontStack];
|
||||
if (entry.glyphs.find(glyphID) != entry.glyphs.end()) return entry.glyphs.at(glyphID);
|
||||
|
||||
if (glyphID.complex.type != FontPBF) {
|
||||
auto shaper = getHBShaper(fontStack, glyphID.complex.type);
|
||||
if (shaper) {
|
||||
auto glyph = shaper->rasterizeGlyph(glyphID);
|
||||
|
||||
glyph.bitmap = util::transformRasterToSDF(glyph.bitmap, 8, .25);
|
||||
entry.glyphs.emplace(glyphID, makeMutable<Glyph>(std::move(glyph)));
|
||||
return entry.glyphs.at(glyphID);
|
||||
}
|
||||
}
|
||||
|
||||
Glyph empty;
|
||||
|
||||
return makeMutable<Glyph>(std::move(empty));
|
||||
}
|
||||
|
||||
void GlyphManager::hbShaping(const std::u16string& text,
|
||||
const FontStack& font,
|
||||
GlyphIDType type,
|
||||
std::vector<GlyphID>& glyphIDs,
|
||||
std::vector<HBShapeAdjust>& adjusts) {
|
||||
auto shaper = getHBShaper(font, type);
|
||||
if (shaper) {
|
||||
shaper->createComplexGlyphIDs(text, glyphIDs, adjusts);
|
||||
}
|
||||
}
|
||||
|
||||
std::string GlyphManager::getFontFaceURL(GlyphIDType type) {
|
||||
std::string url;
|
||||
|
||||
if (fontFaces) {
|
||||
for (auto& face : *fontFaces) {
|
||||
if (face.type == type) {
|
||||
url = face.url;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -11,15 +11,30 @@
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "harfbuzz.hpp"
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class FileSource;
|
||||
class AsyncRequest;
|
||||
class Response;
|
||||
|
||||
struct HBShapeResult {
|
||||
std::u16string str;
|
||||
|
||||
std::shared_ptr<std::vector<HBShapeAdjust>> adjusts;
|
||||
|
||||
HBShapeResult() {}
|
||||
|
||||
HBShapeResult(const std::u16string &str_, std::shared_ptr<std::vector<HBShapeAdjust>> adjusts_)
|
||||
: str(str_),
|
||||
adjusts(adjusts_) {}
|
||||
};
|
||||
using HBShapeResults = std::map<FontStack, std::map<GlyphIDType, std::map<std::u16string, HBShapeResult>>>;
|
||||
|
||||
class GlyphRequestor {
|
||||
public:
|
||||
virtual void onGlyphsAvailable(GlyphMap) = 0;
|
||||
virtual void onGlyphsAvailable(GlyphMap, HBShapeRequests) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~GlyphRequestor() = default;
|
||||
@@ -27,8 +42,8 @@ protected:
|
||||
|
||||
class GlyphManager {
|
||||
public:
|
||||
GlyphManager(const GlyphManager&) = delete;
|
||||
GlyphManager& operator=(const GlyphManager&) = delete;
|
||||
GlyphManager(const GlyphManager &) = delete;
|
||||
GlyphManager &operator=(const GlyphManager &) = delete;
|
||||
explicit GlyphManager(
|
||||
std::unique_ptr<LocalGlyphRasterizer> = std::make_unique<LocalGlyphRasterizer>(std::optional<std::string>()));
|
||||
~GlyphManager();
|
||||
@@ -38,24 +53,40 @@ public:
|
||||
// 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 getGlyphs(GlyphRequestor &, GlyphDependencies, FileSource &);
|
||||
void removeRequestor(GlyphRequestor &);
|
||||
|
||||
void setURL(const std::string& url) { glyphURL = url; }
|
||||
void setURL(const std::string &url) { glyphURL = url; }
|
||||
|
||||
void setObserver(GlyphManagerObserver*);
|
||||
void setObserver(GlyphManagerObserver *);
|
||||
|
||||
// Remove glyphs for all but the supplied font stacks.
|
||||
void evict(const std::set<FontStack>&);
|
||||
void evict(const std::set<FontStack> &);
|
||||
|
||||
Immutable<Glyph> getGlyph(const FontStack &, GlyphID);
|
||||
|
||||
void setFontFaces(std::shared_ptr<FontFaces> faces) { fontFaces = faces; }
|
||||
|
||||
std::shared_ptr<HBShaper> getHBShaper(FontStack, GlyphIDType);
|
||||
|
||||
void hbShaping(const std::u16string &text,
|
||||
const FontStack &font,
|
||||
GlyphIDType type,
|
||||
std::vector<GlyphID> &glyphIDs,
|
||||
std::vector<HBShapeAdjust> &adjusts);
|
||||
|
||||
std::shared_ptr<FontFaces> getFontFaces() { return fontFaces; }
|
||||
|
||||
std::string getFontFaceURL(GlyphIDType type);
|
||||
|
||||
private:
|
||||
Glyph generateLocalSDF(const FontStack& fontStack, GlyphID glyphID);
|
||||
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;
|
||||
std::unordered_map<GlyphRequestor *, std::shared_ptr<GlyphDependencies>> requestors;
|
||||
};
|
||||
|
||||
struct Entry {
|
||||
@@ -65,13 +96,19 @@ private:
|
||||
|
||||
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&);
|
||||
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;
|
||||
GlyphManagerObserver *observer = nullptr;
|
||||
|
||||
// Shaping objects
|
||||
std::unique_ptr<LocalGlyphRasterizer> localGlyphRasterizer;
|
||||
std::shared_ptr<FontFaces> fontFaces;
|
||||
|
||||
FreeTypeLibrary ftLibrary;
|
||||
std::map<FontStack, std::map<GlyphIDType, std::shared_ptr<HBShaper>>> hbShapers;
|
||||
bool loadHBShaper(const FontStack &fontStack, GlyphIDType type, const std::string &data);
|
||||
|
||||
std::recursive_mutex rwLock;
|
||||
};
|
||||
|
||||
52
src/mbgl/text/harfbuzz.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "harfbuzz.hpp"
|
||||
|
||||
#ifdef MLN_TEXT_SHAPING_HARFBUZZ
|
||||
#include "harfbuzz_impl.hpp"
|
||||
#endif
|
||||
|
||||
// TODO: return empty harfbuzz
|
||||
namespace mbgl {
|
||||
|
||||
#ifndef MLN_TEXT_SHAPING_HARFBUZZ
|
||||
|
||||
class HBShaper::Impl {
|
||||
public:
|
||||
Impl(GlyphIDType, const std::string &, const FreeTypeLibrary &) {}
|
||||
|
||||
bool valid() { return false; }
|
||||
|
||||
void createComplexGlyphIDs(const std::u16string &, std::vector<GlyphID> &, std::vector<HBShapeAdjust> &) {
|
||||
assert(false && "can't shaping text without harfbuzz.");
|
||||
}
|
||||
|
||||
Glyph rasterizeGlyph(const GlyphID &) {
|
||||
assert(false && "can't rasterize glyph without harfbuzz + freetype.");
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
HBShaper::HBShaper(GlyphIDType type, const std::string &fontFileData, const FreeTypeLibrary &lib) {
|
||||
impl = std::make_unique<Impl>(type, fontFileData, lib);
|
||||
}
|
||||
|
||||
HBShaper::~HBShaper() {
|
||||
impl.reset();
|
||||
}
|
||||
|
||||
void HBShaper::createComplexGlyphIDs(const std::u16string &text,
|
||||
std::vector<GlyphID> &glyphIDs,
|
||||
std::vector<HBShapeAdjust> &adjusts) {
|
||||
return impl->createComplexGlyphIDs(text, glyphIDs, adjusts);
|
||||
}
|
||||
|
||||
Glyph HBShaper::rasterizeGlyph(const GlyphID &glyph) {
|
||||
return impl->rasterizeGlyph(glyph);
|
||||
}
|
||||
|
||||
bool HBShaper::valid() {
|
||||
return impl->valid();
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
45
src/mbgl/text/harfbuzz.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/text/glyph.hpp>
|
||||
|
||||
#ifdef MLN_TEXT_SHAPING_HARFBUZZ
|
||||
#include "freetype.hpp"
|
||||
#endif
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
#ifndef MLN_TEXT_SHAPING_HARFBUZZ
|
||||
struct FreeTypeLibrary {};
|
||||
#endif
|
||||
|
||||
struct HBShapeAdjust {
|
||||
float x_offset;
|
||||
float y_offset;
|
||||
|
||||
float advance; // advanceX
|
||||
|
||||
HBShapeAdjust(float x, float y, float a)
|
||||
: x_offset(x),
|
||||
y_offset(y),
|
||||
advance(a) {}
|
||||
};
|
||||
|
||||
class HBShaper {
|
||||
public:
|
||||
explicit HBShaper(GlyphIDType type, const std::string &fontFileData, const FreeTypeLibrary &lib);
|
||||
~HBShaper();
|
||||
|
||||
void createComplexGlyphIDs(const std::u16string &text,
|
||||
std::vector<GlyphID> &glyphIDs,
|
||||
std::vector<HBShapeAdjust> &adjusts);
|
||||
Glyph rasterizeGlyph(const GlyphID &glyph);
|
||||
|
||||
bool valid();
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> impl;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
108
src/mbgl/text/harfbuzz_impl.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
#include "harfbuzz_impl.hpp"
|
||||
|
||||
#include <hb-ft.h>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
static hb_language_t getDefaultLanguage() {
|
||||
static hb_language_t language = hb_language_get_default();
|
||||
return language;
|
||||
}
|
||||
|
||||
static hb_script_t getUnicodeScript(hb_codepoint_t u) {
|
||||
static hb_unicode_funcs_t *unicode_funcs;
|
||||
|
||||
unicode_funcs = hb_unicode_funcs_get_default();
|
||||
|
||||
/* Make combining marks inherit the script of their bases, regardless of
|
||||
* their own script.
|
||||
*/
|
||||
if (hb_unicode_general_category(unicode_funcs, u) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
|
||||
return HB_SCRIPT_INHERITED;
|
||||
|
||||
return hb_unicode_script(unicode_funcs, u);
|
||||
}
|
||||
|
||||
HBShaper::Impl::Impl(GlyphIDType type_, const std::string &fontFileData, const FreeTypeLibrary &lib)
|
||||
: type(type_),
|
||||
face(fontFileData.data(), fontFileData.size(), lib) {
|
||||
if (!face.isValid()) return;
|
||||
|
||||
font = hb_ft_font_create(face.getFace(), NULL);
|
||||
buffer = hb_buffer_create();
|
||||
|
||||
hb_buffer_allocation_successful(buffer);
|
||||
}
|
||||
|
||||
HBShaper::Impl::~Impl() {
|
||||
if (!face.isValid()) return;
|
||||
hb_buffer_destroy(buffer);
|
||||
hb_font_destroy(font);
|
||||
}
|
||||
void HBShaper::Impl::createComplexGlyphIDs(const std::u16string &text,
|
||||
std::vector<GlyphID> &glyphIDs,
|
||||
std::vector<HBShapeAdjust> &adjusts) {
|
||||
if (text.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct TextPart {
|
||||
std::u16string text;
|
||||
hb_script_t script;
|
||||
};
|
||||
|
||||
std::vector<TextPart> textParts;
|
||||
textParts.emplace_back();
|
||||
auto *lastTextPart = &textParts.back();
|
||||
lastTextPart->text = text[0];
|
||||
lastTextPart->script = getUnicodeScript(text[0]);
|
||||
|
||||
for (std::size_t i = 1; i < text.size(); ++i) {
|
||||
auto ch = text[i];
|
||||
auto script = getUnicodeScript(text[i]);
|
||||
|
||||
if (lastTextPart->script == script || script == HB_SCRIPT_INHERITED) {
|
||||
lastTextPart->text += (ch);
|
||||
} else {
|
||||
textParts.emplace_back();
|
||||
lastTextPart = &textParts.back();
|
||||
lastTextPart->text = (ch);
|
||||
lastTextPart->script = script;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &textPart : textParts) {
|
||||
// Setup harfbuzz
|
||||
hb_buffer_reset(buffer);
|
||||
|
||||
hb_buffer_set_direction(buffer, HB_DIRECTION_LTR);
|
||||
hb_buffer_set_script(buffer, textPart.script);
|
||||
hb_buffer_set_language(buffer, getDefaultLanguage());
|
||||
size_t length = textPart.text.size();
|
||||
|
||||
hb_buffer_add_utf16(buffer, (const uint16_t *)textPart.text.c_str(), (int)length, 0, (int)length);
|
||||
|
||||
// harfbuzz shaping
|
||||
hb_shape(font, buffer, NULL, 0);
|
||||
|
||||
// Get Harfbuzz adjustion
|
||||
uint32_t glyphCount;
|
||||
hb_glyph_info_t *glyphInfo = hb_buffer_get_glyph_infos(buffer, &glyphCount);
|
||||
hb_glyph_position_t *glyphPos = hb_buffer_get_glyph_positions(buffer, &glyphCount);
|
||||
|
||||
glyphIDs.reserve(glyphCount);
|
||||
adjusts.reserve(glyphCount);
|
||||
|
||||
for (uint32_t i = 0; i < glyphCount; ++i) {
|
||||
glyphIDs.emplace_back(glyphInfo[i].codepoint, type);
|
||||
|
||||
float x_advance = static_cast<float>(glyphPos[i].x_advance / 64.0f);
|
||||
float x_offset = static_cast<float>(glyphPos[i].x_offset / 64.0f);
|
||||
float y_offset = static_cast<float>(-glyphPos[i].y_offset / 64.0f);
|
||||
|
||||
adjusts.emplace_back(x_offset, y_offset, x_advance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
36
src/mbgl/text/harfbuzz_impl.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "freetype.hpp"
|
||||
#include "harfbuzz.hpp"
|
||||
#include <map>
|
||||
|
||||
struct hb_font_t;
|
||||
struct hb_buffer_t;
|
||||
|
||||
using hb_font_t = hb_font_t;
|
||||
using hb_buffer_t = hb_buffer_t;
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class HBShaper::Impl {
|
||||
public:
|
||||
explicit Impl(GlyphIDType type_, const std::string &fontFileData, const FreeTypeLibrary &lib);
|
||||
~Impl();
|
||||
|
||||
void createComplexGlyphIDs(const std::u16string &text,
|
||||
std::vector<GlyphID> &glyphIDs,
|
||||
std::vector<HBShapeAdjust> &adjusts);
|
||||
|
||||
Glyph rasterizeGlyph(const GlyphID &glyph) { return face.rasterizeGlyph(glyph); }
|
||||
|
||||
bool valid() { return face.isValid(); }
|
||||
|
||||
private:
|
||||
GlyphIDType type;
|
||||
FreeTypeFace face;
|
||||
|
||||
hb_font_t *font;
|
||||
hb_buffer_t *buffer;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
@@ -246,6 +246,9 @@ float determineAverageLineWidth(const TaggedString& logicalInput,
|
||||
|
||||
for (std::size_t i = 0; i < logicalInput.length(); i++) {
|
||||
const SectionOptions& section = logicalInput.getSection(i);
|
||||
if (section.type != GlyphIDType::FontPBF) {
|
||||
continue;
|
||||
}
|
||||
char16_t codePoint = logicalInput.getCharCodeAt(i);
|
||||
totalWidth += getGlyphAdvance(codePoint, section, glyphMap, imagePositions, layoutTextSize, spacing);
|
||||
}
|
||||
@@ -440,17 +443,27 @@ void shapeLines(Shaping& shaping,
|
||||
for (std::size_t i = 0; i < line.length(); i++) {
|
||||
const std::size_t sectionIndex = line.getSectionIndex(i);
|
||||
const SectionOptions& section = line.sectionAt(sectionIndex);
|
||||
char16_t codePoint = line.getCharCodeAt(i);
|
||||
const HBShapeAdjust* adjust = nullptr;
|
||||
if (section.adjusts) {
|
||||
assert(section.startIndex >= 0);
|
||||
if (i >= (std::size_t)section.startIndex && i - section.startIndex < section.adjusts->size()) {
|
||||
adjust = &((*section.adjusts)[i - section.startIndex]);
|
||||
}
|
||||
}
|
||||
GlyphID codePoint(line.getCharCodeAt(i), section.type);
|
||||
|
||||
double baselineOffset = 0.0;
|
||||
Rect<uint16_t> rect;
|
||||
GlyphMetrics metrics;
|
||||
float advance = 0.0f;
|
||||
float xHBOffset = 0.0f;
|
||||
float yHBOffset = 0.0f;
|
||||
float verticalAdvance = util::ONE_EM;
|
||||
double sectionScale = section.scale;
|
||||
assert(sectionScale);
|
||||
|
||||
const bool vertical = !(
|
||||
writingMode == WritingModeType::Horizontal ||
|
||||
writingMode == WritingModeType::Horizontal || codePoint.complex.type != GlyphIDType::FontPBF ||
|
||||
// Don't verticalize glyphs that have no upright orientation
|
||||
// if vertical placement is disabled.
|
||||
(!allowVerticalPlacement && !util::i18n::hasUprightVerticalOrientation(codePoint)) ||
|
||||
@@ -482,6 +495,17 @@ void shapeLines(Shaping& shaping,
|
||||
metrics = (*glyph->second)->metrics;
|
||||
}
|
||||
advance = static_cast<float>(metrics.advance);
|
||||
|
||||
if (adjust) advance = adjust->advance;
|
||||
if (adjust) {
|
||||
xHBOffset = (float)(adjust->x_offset * section.scale);
|
||||
yHBOffset = (float)(adjust->y_offset * section.scale);
|
||||
}
|
||||
if (advance < 0.01f) {
|
||||
// Advance is 0, this glyph should align to the preview glyph remove spacing
|
||||
xHBOffset -= spacing;
|
||||
}
|
||||
|
||||
// We don't know the baseline, but since we're laying out
|
||||
// at 24 points, we can calculate how much it will move when
|
||||
// we scale up or down.
|
||||
@@ -522,8 +546,8 @@ void shapeLines(Shaping& shaping,
|
||||
|
||||
if (!vertical) {
|
||||
positionedGlyphs.emplace_back(codePoint,
|
||||
x,
|
||||
y + static_cast<float>(baselineOffset),
|
||||
x + xHBOffset,
|
||||
y + static_cast<float>(baselineOffset) + yHBOffset,
|
||||
vertical,
|
||||
section.fontStackHash,
|
||||
static_cast<float>(sectionScale),
|
||||
@@ -531,7 +555,10 @@ void shapeLines(Shaping& shaping,
|
||||
metrics,
|
||||
section.imageID,
|
||||
sectionIndex);
|
||||
x += advance * static_cast<float>(sectionScale) + spacing;
|
||||
if (advance > 0.01f) {
|
||||
// Only thce glyph with advance should increase spacing
|
||||
x += advance * static_cast<float>(sectionScale) + spacing;
|
||||
}
|
||||
} else {
|
||||
positionedGlyphs.emplace_back(codePoint,
|
||||
x,
|
||||
@@ -598,21 +625,123 @@ Shaping getShaping(const TaggedString& formattedString,
|
||||
bool allowVerticalPlacement) {
|
||||
assert(layoutTextSize);
|
||||
std::vector<TaggedString> reorderedLines;
|
||||
if (formattedString.sectionCount() == 1) {
|
||||
auto untaggedLines = bidi.processText(
|
||||
formattedString.rawText(),
|
||||
determineLineBreaks(formattedString, spacing, maxWidth, glyphMap, imagePositions, layoutTextSize));
|
||||
for (const auto& line : untaggedLines) {
|
||||
reorderedLines.emplace_back(line, formattedString.sectionAt(0));
|
||||
}
|
||||
} else {
|
||||
auto processedLines = bidi.processStyledText(
|
||||
formattedString.getStyledText(),
|
||||
determineLineBreaks(formattedString, spacing, maxWidth, glyphMap, imagePositions, layoutTextSize));
|
||||
for (const auto& line : processedLines) {
|
||||
reorderedLines.emplace_back(line, formattedString.getSections());
|
||||
if (formattedString.rawText().length()) {
|
||||
if (formattedString.sectionCount() == 1) {
|
||||
if (formattedString.getSection(0).type != GlyphIDType::FontPBF) {
|
||||
reorderedLines.emplace_back(formattedString);
|
||||
} else {
|
||||
auto untaggedLines = bidi.processText(
|
||||
formattedString.rawText(),
|
||||
determineLineBreaks(formattedString, spacing, maxWidth, glyphMap, imagePositions, layoutTextSize));
|
||||
for (const auto& line : untaggedLines) {
|
||||
reorderedLines.emplace_back(line, formattedString.sectionAt(0));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
StyledText subString;
|
||||
GlyphIDType sectionType = GlyphIDType::FontPBF;
|
||||
auto strLen = formattedString.getStyledText().first.length();
|
||||
|
||||
std::vector<SectionOptions> formattedSections = formattedString.getSections();
|
||||
if (formattedSections.size() > 0) sectionType = formattedSections[0].type;
|
||||
|
||||
std::vector<StyledText> pendStrings;
|
||||
|
||||
auto processAline = [&](StyledText line) {
|
||||
reorderedLines.emplace_back(line, formattedSections);
|
||||
|
||||
auto cutLens = (int32_t)line.first.length();
|
||||
|
||||
for (auto& sec : formattedSections) {
|
||||
sec.startIndex -= cutLens;
|
||||
}
|
||||
};
|
||||
|
||||
auto applyLineAndPendingStrings = [&](StyledText line) {
|
||||
if (pendStrings.empty()) {
|
||||
processAline(line);
|
||||
} else {
|
||||
StyledText combine;
|
||||
for (auto& pendString : pendStrings) {
|
||||
combine.first.append(pendString.first);
|
||||
combine.second.insert(combine.second.end(), pendString.second.begin(), pendString.second.end());
|
||||
}
|
||||
pendStrings.clear();
|
||||
combine.first.append(line.first);
|
||||
combine.second.insert(combine.second.end(), line.second.begin(), line.second.end());
|
||||
processAline(combine);
|
||||
}
|
||||
};
|
||||
|
||||
auto applySubString = [&]() {
|
||||
if (subString.first.length()) {
|
||||
if (GlyphIDType::FontPBF == sectionType) {
|
||||
auto processedLines = bidi.processStyledText(
|
||||
subString,
|
||||
determineLineBreaks({subString, formattedString.getSections()},
|
||||
spacing,
|
||||
maxWidth,
|
||||
glyphMap,
|
||||
imagePositions,
|
||||
layoutTextSize));
|
||||
|
||||
auto lastChar = u'x';
|
||||
if (!subString.first.empty()) lastChar = subString.first[subString.first.length() - 1];
|
||||
|
||||
if (u'\n' == lastChar) {
|
||||
for (const auto& line : processedLines) {
|
||||
applyLineAndPendingStrings(line);
|
||||
}
|
||||
} else {
|
||||
auto lineCount = processedLines.size();
|
||||
if (lineCount > 1) {
|
||||
for (size_t lineIndex = 0; lineIndex < lineCount - 1; ++lineIndex) {
|
||||
applyLineAndPendingStrings(processedLines[lineIndex]);
|
||||
}
|
||||
}
|
||||
if (lineCount) {
|
||||
pendStrings.push_back(processedLines[lineCount - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
pendStrings.push_back(subString);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (size_t charIndex = 0; charIndex < strLen; ++charIndex) {
|
||||
auto& ch = formattedString.getStyledText().first[charIndex];
|
||||
auto& sec = formattedString.getStyledText().second[charIndex];
|
||||
auto& secType = formattedSections[sec].type;
|
||||
|
||||
if (sectionType != secType) {
|
||||
applySubString();
|
||||
|
||||
subString.first.clear();
|
||||
subString.second.clear();
|
||||
|
||||
sectionType = secType;
|
||||
}
|
||||
|
||||
subString.first += ch;
|
||||
subString.second.emplace_back(sec);
|
||||
}
|
||||
|
||||
applySubString();
|
||||
|
||||
if (!pendStrings.empty()) {
|
||||
StyledText combine;
|
||||
for (auto& pendString : pendStrings) {
|
||||
combine.first.append(pendString.first);
|
||||
combine.second.insert(combine.second.end(), pendString.second.begin(), pendString.second.end());
|
||||
}
|
||||
pendStrings.clear();
|
||||
processAline(combine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Shaping shaping(translate[0], translate[1], writingMode);
|
||||
shapeLines(shaping,
|
||||
reorderedLines,
|
||||
|
||||
@@ -10,18 +10,38 @@ char16_t PUAend = u'\uF8FF';
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
void TaggedString::addTextSection(const std::u16string& sectionText,
|
||||
void TaggedString::addTextSection(const std::u16string §ionText,
|
||||
double scale,
|
||||
const FontStack& fontStack,
|
||||
const FontStack &fontStack,
|
||||
GlyphIDType type,
|
||||
bool keySection,
|
||||
std::optional<Color> textColor) {
|
||||
styledText.first += sectionText;
|
||||
sections.emplace_back(scale, fontStack, std::move(textColor));
|
||||
auto startIndex = static_cast<uint32_t>(styledText.first.size());
|
||||
sections.emplace_back(scale, fontStack, type, startIndex, std::move(textColor));
|
||||
styledText.second.resize(styledText.first.size(), static_cast<uint8_t>(sections.size() - 1));
|
||||
supportsVerticalWritingMode = std::nullopt;
|
||||
if (type != GlyphIDType::FontPBF) hasNeedShapeTextVal = true;
|
||||
sections[sections.size() - 1].keySection = keySection;
|
||||
}
|
||||
|
||||
void TaggedString::addImageSection(const std::string& imageID) {
|
||||
const auto& nextImageSectionCharCode = getNextImageSectionCharCode();
|
||||
void TaggedString::addTextSection(const std::u16string §ionText,
|
||||
double scale,
|
||||
const FontStack &fontStack,
|
||||
GlyphIDType type,
|
||||
std::shared_ptr<std::vector<HBShapeAdjust>> &adjusts,
|
||||
bool keySection,
|
||||
std::optional<Color> textColor) {
|
||||
sections.emplace_back(scale, fontStack, type, static_cast<uint32_t>(styledText.first.size()), std::move(textColor));
|
||||
styledText.first += sectionText;
|
||||
styledText.second.resize(styledText.first.size(), static_cast<uint8_t>(sections.size() - 1));
|
||||
if (type != GlyphIDType::FontPBF) hasNeedShapeTextVal = true;
|
||||
if (adjusts) sections[sections.size() - 1].adjusts = adjusts;
|
||||
sections[sections.size() - 1].keySection = keySection;
|
||||
}
|
||||
|
||||
void TaggedString::addImageSection(const std::string &imageID) {
|
||||
const auto &nextImageSectionCharCode = getNextImageSectionCharCode();
|
||||
if (!nextImageSectionCharCode) {
|
||||
Log::Warning(Event::Style, "Exceeded maximum number of images in a label.");
|
||||
return;
|
||||
@@ -47,12 +67,38 @@ std::optional<char16_t> TaggedString::getNextImageSectionCharCode() {
|
||||
|
||||
void TaggedString::trim() {
|
||||
std::size_t beginningWhitespace = styledText.first.find_first_not_of(u" \t\n\v\f\r");
|
||||
|
||||
for (size_t i = 0; (i < beginningWhitespace) && i < styledText.first.length(); ++i) {
|
||||
auto &sec = getSection(i);
|
||||
if (sec.type != FontPBF) {
|
||||
beginningWhitespace = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (beginningWhitespace == std::u16string::npos) {
|
||||
for (auto §ion : sections) {
|
||||
section.startIndex = 0;
|
||||
}
|
||||
// Entirely whitespace
|
||||
styledText.first.clear();
|
||||
styledText.second.clear();
|
||||
} else {
|
||||
std::size_t trailingWhitespace = styledText.first.find_last_not_of(u" \t\n\v\f\r") + 1;
|
||||
int trailingWhitespace = static_cast<int>(styledText.first.find_last_not_of(u" \t\n\v\f\r") + 1);
|
||||
|
||||
if (beginningWhitespace) {
|
||||
for (auto §ion : sections) {
|
||||
section.startIndex -= beginningWhitespace;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = static_cast<int>(styledText.first.length()) - 1; i >= trailingWhitespace; --i) {
|
||||
auto &sec = getSection(i);
|
||||
if (sec.type != FontPBF) {
|
||||
trailingWhitespace = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
styledText.first = styledText.first.substr(beginningWhitespace, trailingWhitespace - beginningWhitespace);
|
||||
styledText.second = std::vector<uint8_t>(styledText.second.begin() + beginningWhitespace,
|
||||
@@ -70,12 +116,26 @@ double TaggedString::getMaxScale() const {
|
||||
|
||||
void TaggedString::verticalizePunctuation() {
|
||||
// Relies on verticalization changing characters in place so that style indices don't need updating
|
||||
styledText.first = util::i18n::verticalizePunctuation(styledText.first);
|
||||
auto replaced = util::i18n::verticalizePunctuation(styledText.first);
|
||||
for (size_t i = 0; i < replaced.length(); ++i) {
|
||||
auto &sec = getSection(i);
|
||||
if (sec.type != GlyphIDType::FontPBF) replaced[i] = styledText.first[i];
|
||||
}
|
||||
styledText.first = replaced;
|
||||
}
|
||||
|
||||
bool TaggedString::allowsVerticalWritingMode() {
|
||||
if (!supportsVerticalWritingMode) {
|
||||
supportsVerticalWritingMode = util::i18n::allowsVerticalWritingMode(rawText());
|
||||
bool allows = false;
|
||||
for (size_t i = 0; i < styledText.first.length(); ++i) {
|
||||
auto chr = styledText.first[i];
|
||||
auto &sec = getSection(i);
|
||||
if (sec.type == GlyphIDType::FontPBF && util::i18n::hasUprightVerticalOrientation(chr)) {
|
||||
allows = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
supportsVerticalWritingMode = allows;
|
||||
}
|
||||
return *supportsVerticalWritingMode;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/text/bidi.hpp>
|
||||
#include <mbgl/text/harfbuzz.hpp>
|
||||
#include <mbgl/style/expression/formatted.hpp>
|
||||
#include <mbgl/util/font_stack.hpp>
|
||||
|
||||
@@ -9,21 +10,48 @@
|
||||
namespace mbgl {
|
||||
|
||||
struct SectionOptions {
|
||||
SectionOptions(double scale_, FontStack fontStack_, std::optional<Color> textColor_ = std::nullopt)
|
||||
SectionOptions(double scale_,
|
||||
FontStack fontStack_,
|
||||
GlyphIDType type_,
|
||||
uint32_t startIndex_,
|
||||
std::optional<Color> textColor_ = std::nullopt)
|
||||
: scale(scale_),
|
||||
fontStackHash(FontStackHasher()(fontStack_)),
|
||||
fontStack(std::move(fontStack_)),
|
||||
fontStack(fontStack_),
|
||||
fontStackHash(FontStackHasher()(std::move(fontStack_))),
|
||||
type(type_),
|
||||
startIndex(startIndex_),
|
||||
textColor(std::move(textColor_)) {}
|
||||
|
||||
SectionOptions(double scale_,
|
||||
FontStackHash fontStackHash_,
|
||||
GlyphIDType type_,
|
||||
uint32_t startIndex_,
|
||||
std::optional<Color> textColor_ = std::nullopt)
|
||||
: scale(scale_),
|
||||
fontStackHash(fontStackHash_),
|
||||
type(type_),
|
||||
startIndex(startIndex_),
|
||||
textColor(std::move(textColor_)) {}
|
||||
|
||||
explicit SectionOptions(std::string imageID_)
|
||||
: scale(1.0),
|
||||
type(GlyphIDType::FontPBF),
|
||||
imageID(std::move(imageID_)) {}
|
||||
|
||||
double scale;
|
||||
FontStackHash fontStackHash;
|
||||
FontStack fontStack;
|
||||
std::optional<Color> textColor;
|
||||
FontStackHash fontStackHash;
|
||||
|
||||
GlyphIDType type;
|
||||
|
||||
std::shared_ptr<std::vector<HBShapeAdjust>> adjusts;
|
||||
|
||||
int32_t startIndex;
|
||||
bool keySection = true;
|
||||
|
||||
std::optional<std::string> imageID;
|
||||
|
||||
std::optional<Color> textColor;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -70,6 +98,16 @@ struct TaggedString {
|
||||
void addTextSection(const std::u16string& text,
|
||||
double scale,
|
||||
const FontStack& fontStack,
|
||||
GlyphIDType type,
|
||||
bool keySection = true,
|
||||
std::optional<Color> textColor_ = std::nullopt);
|
||||
|
||||
void addTextSection(const std::u16string& text,
|
||||
double scale,
|
||||
const FontStack& fontStack,
|
||||
GlyphIDType type,
|
||||
std::shared_ptr<std::vector<HBShapeAdjust>>& adjusts,
|
||||
bool keySection = true,
|
||||
std::optional<Color> textColor_ = std::nullopt);
|
||||
|
||||
void addImageSection(const std::string& imageID);
|
||||
@@ -86,6 +124,12 @@ struct TaggedString {
|
||||
void verticalizePunctuation();
|
||||
bool allowsVerticalWritingMode();
|
||||
|
||||
bool hbShaped() const { return textHBShaped; }
|
||||
|
||||
void setHBShaped(bool shaped) { textHBShaped = shaped; }
|
||||
|
||||
bool hasNeedHBShapeText() const { return hasNeedShapeTextVal; }
|
||||
|
||||
private:
|
||||
std::optional<char16_t> getNextImageSectionCharCode();
|
||||
|
||||
@@ -96,6 +140,8 @@ private:
|
||||
// Max number of images within a text is 6400 U+E000–U+F8FF
|
||||
// that covers Basic Multilingual Plane Unicode Private Use Area (PUA).
|
||||
char16_t imageSectionID = 0u;
|
||||
bool textHBShaped = false;
|
||||
bool hasNeedShapeTextVal = false;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -202,7 +202,8 @@ GeometryTile::GeometryTile(const OverscaledTileID& id_,
|
||||
parameters.mode,
|
||||
parameters.pixelRatio,
|
||||
parameters.debugOptions & MapDebugOptions::Collision,
|
||||
parameters.dynamicTextureAtlas),
|
||||
parameters.dynamicTextureAtlas,
|
||||
parameters.glyphManager->getFontFaces()),
|
||||
fileSource(parameters.fileSource),
|
||||
glyphManager(parameters.glyphManager),
|
||||
imageManager(parameters.imageManager),
|
||||
@@ -373,10 +374,48 @@ void GeometryTile::onError(std::exception_ptr err, const uint64_t resultCorrelat
|
||||
observer->onTileError(*this, std::move(err));
|
||||
}
|
||||
|
||||
void GeometryTile::onGlyphsAvailable(GlyphMap glyphs) {
|
||||
void GeometryTile::onGlyphsAvailable(GlyphMap glyphMap, [[maybe_unused]] HBShapeRequests requests) {
|
||||
MLN_TRACE_FUNC();
|
||||
|
||||
worker.self().invoke(&GeometryTileWorker::onGlyphsAvailable, std::move(glyphs));
|
||||
HBShapeResults results;
|
||||
#ifdef MLN_TEXT_SHAPING_HARFBUZZ
|
||||
for (auto& fontStackIT : requests) {
|
||||
auto fontStack = fontStackIT.first;
|
||||
auto& fontTypes = fontStackIT.second;
|
||||
for (auto& typesIT : fontTypes) {
|
||||
auto type = typesIT.first;
|
||||
auto& strs = typesIT.second;
|
||||
|
||||
for (auto& str : strs) {
|
||||
std::vector<GlyphID> shapedGlyphIDs;
|
||||
std::shared_ptr<std::vector<HBShapeAdjust>> shapedAdjusts =
|
||||
std::make_shared<std::vector<HBShapeAdjust>>();
|
||||
glyphManager->hbShaping(str, fontStack, type, shapedGlyphIDs, *shapedAdjusts);
|
||||
std::u16string shapedstr;
|
||||
|
||||
shapedstr.reserve(shapedGlyphIDs.size());
|
||||
for (auto& glyphID : shapedGlyphIDs) {
|
||||
shapedstr += glyphID.complex.code;
|
||||
|
||||
auto fontStackHash = FontStackHasher()(fontStack);
|
||||
bool needShape = true;
|
||||
if (glyphMap.find(fontStackHash) != glyphMap.end()) {
|
||||
auto& glyphs = glyphMap[fontStackHash];
|
||||
if (glyphs.find(glyphID) != glyphs.end()) needShape = false;
|
||||
}
|
||||
if (needShape) {
|
||||
auto glyph = glyphManager->getGlyph(fontStack, glyphID);
|
||||
glyphMap[fontStackHash].emplace(glyph->id, glyph);
|
||||
}
|
||||
}
|
||||
|
||||
results[fontStack][type][str] = HBShapeResult{shapedstr,
|
||||
shapedAdjusts}; //.emplace(str, shapedstr, shapedAdjusts);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // MLN_TEXT_SHAPING_HARFBUZZ
|
||||
worker.self().invoke(&GeometryTileWorker::onGlyphsAvailable, std::move(glyphMap), std::move(results));
|
||||
}
|
||||
|
||||
void GeometryTile::getGlyphs(GlyphDependencies glyphDependencies) {
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
void setLayers(const std::vector<Immutable<style::LayerProperties>>&) override;
|
||||
void setShowCollisionBoxes(bool showCollisionBoxes) override;
|
||||
|
||||
void onGlyphsAvailable(GlyphMap) override;
|
||||
void onGlyphsAvailable(GlyphMap, HBShapeRequests) override;
|
||||
void onImagesAvailable(ImageMap, ImageMap, ImageVersionMap versionMap, uint64_t imageCorrelationID) override;
|
||||
|
||||
void getGlyphs(GlyphDependencies);
|
||||
|
||||
@@ -38,7 +38,8 @@ GeometryTileWorker::GeometryTileWorker(ActorRef<GeometryTileWorker> self_,
|
||||
const MapMode mode_,
|
||||
const float pixelRatio_,
|
||||
const bool showCollisionBoxes_,
|
||||
gfx::DynamicTextureAtlasPtr dynamicTextureAtlas_)
|
||||
gfx::DynamicTextureAtlasPtr dynamicTextureAtlas_,
|
||||
std::shared_ptr<FontFaces> fontFaces_)
|
||||
: self(std::move(self_)),
|
||||
parent(std::move(parent_)),
|
||||
scheduler(scheduler_),
|
||||
@@ -48,7 +49,8 @@ GeometryTileWorker::GeometryTileWorker(ActorRef<GeometryTileWorker> self_,
|
||||
mode(mode_),
|
||||
pixelRatio(pixelRatio_),
|
||||
showCollisionBoxes(showCollisionBoxes_),
|
||||
dynamicTextureAtlas(dynamicTextureAtlas_) {}
|
||||
dynamicTextureAtlas(dynamicTextureAtlas_),
|
||||
fontFaces(fontFaces_) {}
|
||||
|
||||
GeometryTileWorker::~GeometryTileWorker() {
|
||||
MLN_TRACE_FUNC();
|
||||
@@ -297,7 +299,7 @@ void GeometryTileWorker::coalesce() {
|
||||
self.invoke(&GeometryTileWorker::coalesced);
|
||||
}
|
||||
|
||||
void GeometryTileWorker::onGlyphsAvailable(GlyphMap newGlyphMap) {
|
||||
void GeometryTileWorker::onGlyphsAvailable(GlyphMap newGlyphMap, HBShapeResults results) {
|
||||
MLN_TRACE_FUNC();
|
||||
|
||||
for (auto& newFontGlyphs : newGlyphMap) {
|
||||
@@ -305,7 +307,7 @@ void GeometryTileWorker::onGlyphsAvailable(GlyphMap newGlyphMap) {
|
||||
Glyphs& newGlyphs = newFontGlyphs.second;
|
||||
|
||||
Glyphs& glyphs = glyphMap[fontStack];
|
||||
for (auto& pendingGlyphDependency : pendingGlyphDependencies) {
|
||||
for (auto& pendingGlyphDependency : pendingGlyphDependencies.glyphs) {
|
||||
// Linear lookup here to handle reverse of FontStackHash -> FontStack,
|
||||
// since dependencies need the full font stack name to make a request
|
||||
// There should not be many fontstacks to look through
|
||||
@@ -316,12 +318,39 @@ void GeometryTileWorker::onGlyphsAvailable(GlyphMap newGlyphMap) {
|
||||
std::optional<Immutable<Glyph>>& glyph = newGlyph.second;
|
||||
|
||||
if (pendingGlyphIDs.erase(glyphID)) {
|
||||
glyphs.emplace(glyphID, std::move(glyph));
|
||||
if (!(glyphID.complex.code == 0 && glyphID.complex.type != GlyphIDType::FontPBF)) {
|
||||
glyphs.emplace(glyphID, std::move(glyph));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!results.empty()) {
|
||||
pendingGlyphDependencies.shapes.clear();
|
||||
|
||||
for (auto& newFontGlyphs : newGlyphMap) {
|
||||
FontStackHash fontStack = newFontGlyphs.first;
|
||||
Glyphs& newGlyphs = newFontGlyphs.second;
|
||||
|
||||
Glyphs& glyphs = glyphMap[fontStack];
|
||||
for (auto& newGlyph : newGlyphs) {
|
||||
const GlyphID& glyphID = newGlyph.first;
|
||||
std::optional<Immutable<Glyph>>& glyph = newGlyph.second;
|
||||
|
||||
if (!(glyphID.complex.code == 0 && glyphID.complex.type != GlyphIDType::FontPBF))
|
||||
glyphs.emplace(glyphID, std::move(glyph));
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& layout : layouts) {
|
||||
if (layout && layout->needFinalizeSymbols()) {
|
||||
layout->finalizeSymbols(results);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
symbolDependenciesChanged();
|
||||
}
|
||||
|
||||
@@ -344,15 +373,25 @@ void GeometryTileWorker::onImagesAvailable(ImageMap newIconMap,
|
||||
void GeometryTileWorker::requestNewGlyphs(const GlyphDependencies& glyphDependencies) {
|
||||
MLN_TRACE_FUNC();
|
||||
|
||||
for (auto& fontDependencies : glyphDependencies) {
|
||||
for (auto& fontDependencies : glyphDependencies.glyphs) {
|
||||
auto fontGlyphs = glyphMap.find(FontStackHasher()(fontDependencies.first));
|
||||
for (auto glyphID : fontDependencies.second) {
|
||||
if (fontGlyphs == glyphMap.end() || fontGlyphs->second.find(glyphID) == fontGlyphs->second.end()) {
|
||||
pendingGlyphDependencies[fontDependencies.first].insert(glyphID);
|
||||
pendingGlyphDependencies.glyphs[fontDependencies.first].insert(glyphID);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!pendingGlyphDependencies.empty()) {
|
||||
for (auto& fontDependencies : glyphDependencies.shapes) {
|
||||
auto& fontStack = fontDependencies.first;
|
||||
for (const auto& typeDependencies : fontDependencies.second) {
|
||||
auto& type = typeDependencies.first;
|
||||
auto& strs = typeDependencies.second;
|
||||
for (auto& str : strs) {
|
||||
pendingGlyphDependencies.shapes[fontStack][type].insert(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!pendingGlyphDependencies.glyphs.empty()) {
|
||||
parent.invoke(&GeometryTile::getGlyphs, pendingGlyphDependencies);
|
||||
}
|
||||
}
|
||||
@@ -433,7 +472,9 @@ void GeometryTileWorker::parse() {
|
||||
// images/glyphs are available to add the features to the buckets.
|
||||
if (leaderImpl.getTypeInfo()->layout == LayerTypeInfo::Layout::Required) {
|
||||
std::unique_ptr<Layout> layout = LayerManager::get()->createLayout(
|
||||
{parameters, glyphDependencies, imageDependencies, availableImages}, std::move(geometryLayer), group);
|
||||
{parameters, fontFaces, glyphDependencies, imageDependencies, availableImages},
|
||||
std::move(geometryLayer),
|
||||
group);
|
||||
if (layout->hasDependencies()) {
|
||||
layouts.push_back(std::move(layout));
|
||||
} else {
|
||||
@@ -478,7 +519,7 @@ void GeometryTileWorker::parse() {
|
||||
}
|
||||
|
||||
bool GeometryTileWorker::hasPendingDependencies() const {
|
||||
for (auto& glyphDependency : pendingGlyphDependencies) {
|
||||
for (auto& glyphDependency : pendingGlyphDependencies.glyphs) {
|
||||
if (!glyphDependency.second.empty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <mbgl/tile/tile_id.hpp>
|
||||
#include <mbgl/style/image_impl.hpp>
|
||||
#include <mbgl/text/glyph.hpp>
|
||||
#include <mbgl/text/glyph_manager.hpp>
|
||||
#include <mbgl/actor/actor_ref.hpp>
|
||||
#include <mbgl/util/immutable.hpp>
|
||||
#include <mbgl/style/layer_properties.hpp>
|
||||
@@ -42,7 +43,8 @@ public:
|
||||
MapMode,
|
||||
float pixelRatio,
|
||||
bool showCollisionBoxes_,
|
||||
gfx::DynamicTextureAtlasPtr);
|
||||
gfx::DynamicTextureAtlasPtr,
|
||||
std::shared_ptr<FontFaces> fontFaces);
|
||||
~GeometryTileWorker();
|
||||
|
||||
void setLayers(std::vector<Immutable<style::LayerProperties>>,
|
||||
@@ -54,7 +56,8 @@ public:
|
||||
void reset(uint64_t correlationID_);
|
||||
void setShowCollisionBoxes(bool showCollisionBoxes_, uint64_t correlationID_);
|
||||
|
||||
void onGlyphsAvailable(GlyphMap newGlyphMap);
|
||||
void onGlyphsAvailable(GlyphMap glyphs, HBShapeResults requests);
|
||||
|
||||
void onImagesAvailable(ImageMap newIconMap,
|
||||
ImageMap newPatternMap,
|
||||
ImageVersionMap versionMap,
|
||||
@@ -118,6 +121,8 @@ private:
|
||||
bool firstLoad = true;
|
||||
|
||||
gfx::DynamicTextureAtlasPtr dynamicTextureAtlas;
|
||||
|
||||
std::shared_ptr<FontFaces> fontFaces;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <mbgl/util/i18n.hpp>
|
||||
#include <mbgl/util/utf.hpp>
|
||||
#include <mbgl/text/glyph.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
@@ -42,21 +43,22 @@ DEFINE_IS_IN_UNICODE_BLOCK(ArabicSupplement, 0x0750, 0x077F)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Syriac Supplement, 0x0860, 0x086F)
|
||||
DEFINE_IS_IN_UNICODE_BLOCK(ArabicExtendedA, 0x08A0, 0x08FF)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Devanagari, 0x0900, 0x097F)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Bengali, 0x0980, 0x09FF)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Gurmukhi, 0x0A00, 0x0A7F)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Gujarati, 0x0A80, 0x0AFF)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Oriya, 0x0B00, 0x0B7F)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Tamil, 0x0B80, 0x0BFF)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Telugu, 0x0C00, 0x0C7F)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Kannada, 0x0C80, 0x0CFF)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Malayalam, 0x0D00, 0x0D7F)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Sinhala, 0x0D80, 0x0DFF)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Thai, 0x0E00, 0x0E7F)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Lao, 0x0E80, 0x0EFF)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Tibetan, 0x0F00, 0x0FFF)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Bengali, 0x0980, 0x09FF)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Gurmukhi, 0x0A00, 0x0A7F)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Gujarati, 0x0A80, 0x0AFF)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Oriya, 0x0B00, 0x0B7F)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Tamil, 0x0B80, 0x0BFF)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Telugu, 0x0C00, 0x0C7F)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Kannada, 0x0C80, 0x0CFF)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Malayalam, 0x0D00, 0x0D7F)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Sinhala, 0x0D80, 0x0DFF)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Thai, 0x0E00, 0x0E7F)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Lao, 0x0E80, 0x0EFF)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Tibetan, 0x0F00, 0x0FFF)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Myanmar, 0x1000, 0x109F)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Georgian, 0x10A0, 0x10FF)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Georgian, 0x10A0, 0x10FF)
|
||||
DEFINE_IS_IN_UNICODE_BLOCK(HangulJamo, 0x1100, 0x11FF)
|
||||
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Ethiopic, 0x1200, 0x137F)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(EthiopicSupplement, 0x1380, 0x139F)
|
||||
// DEFINE_IS_IN_UNICODE_BLOCK(Cherokee, 0x13A0, 0x13FF)
|
||||
@@ -625,6 +627,11 @@ bool isWhitespace(char16_t chr) {
|
||||
return chr == u' ' || chr == u'\t' || chr == u'\n' || chr == u'\v' || chr == u'\f' || chr == u'\r';
|
||||
}
|
||||
|
||||
bool isVariationSelector1(char16_t chr) {
|
||||
return chr == 0xFE00;
|
||||
}
|
||||
|
||||
} // namespace i18n
|
||||
} // namespace util
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -79,6 +79,8 @@ bool isCharInComplexShapingScript(char16_t chr);
|
||||
|
||||
bool isWhitespace(char16_t chr);
|
||||
|
||||
bool isVariationSelector1(char16_t chr);
|
||||
|
||||
} // namespace i18n
|
||||
} // namespace util
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -1612,6 +1612,82 @@ TEST(Map, ObserveShaderRegistration) {
|
||||
EXPECT_EQ(observedRegistry, false);
|
||||
}
|
||||
|
||||
TEST(Map, ResourceError) {
|
||||
MapTest<> test;
|
||||
test.fileSource->glyphsResponse = [&](const Resource&) {
|
||||
Response response;
|
||||
response.error = std::make_unique<Response::Error>(Response::Error::Reason::Server, "Font file Server failed");
|
||||
return response;
|
||||
};
|
||||
|
||||
test.map.getStyle().loadJSON(
|
||||
R"(
|
||||
{
|
||||
"version": 8,
|
||||
"zoom": 0,
|
||||
"center": [-14.41400, 39.09187],
|
||||
"sources": {
|
||||
"mapbox": {
|
||||
"type": "geojson",
|
||||
"data": {
|
||||
"type": "FeatureCollection",
|
||||
"features": [
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "ជនជាប់សង្ស័យ"
|
||||
},
|
||||
"geometry": {
|
||||
"type": "LineString",
|
||||
"coordinates": [
|
||||
[
|
||||
-14.4195556640625,
|
||||
39.091699613104595
|
||||
],
|
||||
[
|
||||
102.3046875,
|
||||
39.36827914916014
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
|
||||
"fonts": "local://glyphs/{fontstack}/{language}.pbf",
|
||||
"layers": [
|
||||
{
|
||||
"id": "background",
|
||||
"type": "background",
|
||||
"paint": {
|
||||
"background-color": "white"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "lines-symbol",
|
||||
"type": "symbol",
|
||||
"source": "mapbox",
|
||||
"layout": {
|
||||
"text-field": "{name}",
|
||||
"symbol-placement": "point",
|
||||
"symbol-spacing": 150,
|
||||
"text-allow-overlap": true,
|
||||
"text-font": [ "abc" ],
|
||||
"text-size": 24
|
||||
}
|
||||
}
|
||||
]
|
||||
})");
|
||||
try {
|
||||
test.frontend.render(test.map);
|
||||
} catch (...) {
|
||||
auto error = std::current_exception(); // captur
|
||||
EXPECT_EQ(mbgl::util::toString(error), "Font file Server failed");
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Map, StencilOverflow) {
|
||||
MapTest<> test;
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ public:
|
||||
|
||||
class StubGlyphRequestor : public GlyphRequestor {
|
||||
public:
|
||||
void onGlyphsAvailable(GlyphMap glyphs) override {
|
||||
void onGlyphsAvailable(GlyphMap glyphs, HBShapeRequests) override {
|
||||
if (glyphsAvailable) glyphsAvailable(std::move(glyphs));
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ TEST(GlyphManager, LoadingSuccess) {
|
||||
|
||||
test.observer.glyphsLoaded = [&](const FontStack& fontStack, const GlyphRange& range) {
|
||||
ASSERT_EQ(fontStack, FontStack{{"Test Stack"}});
|
||||
ASSERT_EQ(range, GlyphRange(0, 255));
|
||||
ASSERT_EQ(range, GlyphRange(0, 255, GlyphIDType::FontPBF));
|
||||
};
|
||||
|
||||
test.requestor.glyphsAvailable = [&](GlyphMap glyphs) {
|
||||
@@ -196,7 +196,7 @@ TEST(GlyphManager, LoadingSuccess) {
|
||||
test.end();
|
||||
};
|
||||
|
||||
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{"Test Stack"}}, {u'a', u'å', u' '}}});
|
||||
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{{"Test Stack"}}, {u'a', u'å', u' '}}}, {}});
|
||||
}
|
||||
|
||||
TEST(GlyphManager, LoadingFail) {
|
||||
@@ -211,7 +211,7 @@ TEST(GlyphManager, LoadingFail) {
|
||||
test.observer.glyphsError =
|
||||
[&](const FontStack& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) {
|
||||
EXPECT_EQ(fontStack, FontStack({"Test Stack"}));
|
||||
EXPECT_EQ(glyphRange, GlyphRange(0, 255));
|
||||
EXPECT_EQ(glyphRange, GlyphRange(0, 255, GlyphIDType::FontPBF));
|
||||
|
||||
EXPECT_TRUE(error != nullptr);
|
||||
EXPECT_EQ(util::toString(error), "Failed by the test case");
|
||||
@@ -224,7 +224,7 @@ TEST(GlyphManager, LoadingFail) {
|
||||
test.end();
|
||||
};
|
||||
|
||||
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{"Test Stack"}}, {u'a', u'å'}}});
|
||||
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{{"Test Stack"}}, {u'a', u'å'}}}, {}});
|
||||
}
|
||||
|
||||
TEST(GlyphManager, LoadingCorrupted) {
|
||||
@@ -239,7 +239,7 @@ TEST(GlyphManager, LoadingCorrupted) {
|
||||
test.observer.glyphsError =
|
||||
[&](const FontStack& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) {
|
||||
EXPECT_EQ(fontStack, FontStack({"Test Stack"}));
|
||||
EXPECT_EQ(glyphRange, GlyphRange(0, 255));
|
||||
EXPECT_EQ(glyphRange, GlyphRange(0, 255, GlyphIDType::FontPBF));
|
||||
|
||||
EXPECT_TRUE(error != nullptr);
|
||||
EXPECT_EQ(util::toString(error), "unknown pbf field type exception");
|
||||
@@ -252,7 +252,7 @@ TEST(GlyphManager, LoadingCorrupted) {
|
||||
test.end();
|
||||
};
|
||||
|
||||
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{"Test Stack"}}, {u'a', u'å'}}});
|
||||
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{{"Test Stack"}}, {u'a', u'å'}}}, {}});
|
||||
}
|
||||
|
||||
TEST(GlyphManager, LoadingCancel) {
|
||||
@@ -267,7 +267,7 @@ TEST(GlyphManager, LoadingCancel) {
|
||||
FAIL() << "Should never be called";
|
||||
};
|
||||
|
||||
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{"Test Stack"}}, {u'a', u'å'}}});
|
||||
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{{"Test Stack"}}, {u'a', u'å'}}}, {}});
|
||||
}
|
||||
|
||||
TEST(GlyphManager, LoadLocalCJKGlyph) {
|
||||
@@ -293,7 +293,7 @@ TEST(GlyphManager, LoadLocalCJKGlyph) {
|
||||
ASSERT_EQ(testPositions.count(u'中'), 1u);
|
||||
|
||||
Immutable<Glyph> glyph = *testPositions.at(u'中');
|
||||
EXPECT_EQ(glyph->id, u'中');
|
||||
EXPECT_EQ(glyph->id.complex.code, u'中');
|
||||
EXPECT_EQ(glyph->metrics.width, 24ul);
|
||||
EXPECT_EQ(glyph->metrics.height, 24ul);
|
||||
EXPECT_EQ(glyph->metrics.left, 0);
|
||||
@@ -309,7 +309,7 @@ TEST(GlyphManager, LoadLocalCJKGlyph) {
|
||||
test.end();
|
||||
};
|
||||
|
||||
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{"Test Stack"}}, {u'中'}}});
|
||||
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{{"Test Stack"}}, {u'中'}}}, {}});
|
||||
}
|
||||
|
||||
TEST(GlyphManager, LoadLocalCJKGlyphAfterLoadingRangeFromURL) {
|
||||
@@ -336,16 +336,15 @@ TEST(GlyphManager, LoadLocalCJKGlyphAfterLoadingRangeFromURL) {
|
||||
// instead of using the glyph recieved from the range
|
||||
// for the ideagraphic mark
|
||||
test.glyphManager.getGlyphs(test.requestor,
|
||||
GlyphDependencies{
|
||||
{{{"Test Stack"}}, {u'テ'}} // 0x30c6
|
||||
},
|
||||
GlyphDependencies{{{{{"Test Stack"}}, {u'テ'}}}, // 0x30c6
|
||||
{}},
|
||||
test.fileSource);
|
||||
} else {
|
||||
ASSERT_EQ(testPositions.size(), 1u);
|
||||
ASSERT_EQ(testPositions.count(u'テ'), 1u);
|
||||
|
||||
Immutable<Glyph> glyph = *testPositions.at(u'テ');
|
||||
EXPECT_EQ(glyph->id, u'テ');
|
||||
EXPECT_EQ(glyph->id.complex.code, u'テ');
|
||||
EXPECT_EQ(glyph->metrics.width, 24ul);
|
||||
EXPECT_EQ(glyph->metrics.height, 24ul);
|
||||
EXPECT_EQ(glyph->metrics.left, 0);
|
||||
@@ -358,9 +357,8 @@ TEST(GlyphManager, LoadLocalCJKGlyphAfterLoadingRangeFromURL) {
|
||||
};
|
||||
|
||||
test.run("test/fixtures/resources/glyphs-12244-12543.pbf",
|
||||
GlyphDependencies{
|
||||
{{{"Test Stack"}}, {u'々'}} // 0x3005
|
||||
});
|
||||
GlyphDependencies{{{{{"Test Stack"}}, {u'々'}}}, // 0x3005
|
||||
{}});
|
||||
}
|
||||
|
||||
TEST(GlyphManager, LoadingInvalid) {
|
||||
@@ -380,7 +378,7 @@ TEST(GlyphManager, LoadingInvalid) {
|
||||
|
||||
test.observer.glyphsLoaded = [&](const FontStack& fontStack, const GlyphRange& range) {
|
||||
ASSERT_EQ(fontStack, FontStack{{"Test Stack"}});
|
||||
ASSERT_EQ(range, GlyphRange(0, 255));
|
||||
ASSERT_EQ(range, GlyphRange(0, 255, GlyphIDType::FontPBF));
|
||||
};
|
||||
|
||||
test.requestor.glyphsAvailable = [&](GlyphMap glyphs) {
|
||||
@@ -393,7 +391,7 @@ TEST(GlyphManager, LoadingInvalid) {
|
||||
test.end();
|
||||
};
|
||||
|
||||
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{"Test Stack"}}, {u'A', u'E'}}});
|
||||
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{{"Test Stack"}}, {u'A', u'E'}}}, {}});
|
||||
}
|
||||
|
||||
TEST(GlyphManager, ImmediateFileSource) {
|
||||
@@ -436,5 +434,5 @@ TEST(GlyphManager, ImmediateFileSource) {
|
||||
test.end();
|
||||
};
|
||||
|
||||
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{"Test Stack"}}, {u'a', u'å', u' '}}});
|
||||
test.run("test/fixtures/resources/glyphs.pbf", GlyphDependencies{{{{{"Test Stack"}}, {u'a', u'å', u' '}}}, {}});
|
||||
}
|
||||
|
||||
@@ -7,11 +7,12 @@ using namespace mbgl;
|
||||
|
||||
TEST(GlyphPBF, Parsing) {
|
||||
// The fake glyphs contain a number of invalid glyphs, which should be skipped by the parser.
|
||||
auto sdfs = parseGlyphPBF(GlyphRange{0, 255}, util::read_file("test/fixtures/resources/fake_glyphs-0-255.pbf"));
|
||||
auto sdfs = parseGlyphPBF(GlyphRange{0, 255, GlyphIDType::FontPBF},
|
||||
util::read_file("test/fixtures/resources/fake_glyphs-0-255.pbf"));
|
||||
EXPECT_TRUE(sdfs.size() == 1);
|
||||
|
||||
auto& sdf = sdfs[0];
|
||||
EXPECT_EQ(69u, sdf.id);
|
||||
EXPECT_EQ(69u, sdf.id.complex.code);
|
||||
AlphaImage expected({7, 7});
|
||||
expected.fill('x');
|
||||
EXPECT_EQ(expected, sdf.bitmap);
|
||||
|
||||
@@ -24,7 +24,7 @@ TEST(Shaping, ZWSP) {
|
||||
BiDi bidi;
|
||||
auto immutableGlyph = Immutable<Glyph>(makeMutable<Glyph>(std::move(glyph)));
|
||||
const std::vector<std::string> fontStack{{"font-stack"}};
|
||||
const SectionOptions sectionOptions(1.0f, fontStack);
|
||||
const SectionOptions sectionOptions(1.0f, fontStack, GlyphIDType::FontPBF, 0);
|
||||
const float layoutTextSize = 16.0f;
|
||||
const float layoutTextSizeAtBucketZoomLevel = 16.0f;
|
||||
GlyphMap glyphs = {{FontStackHasher()(fontStack), {{u'中', std::move(immutableGlyph)}}}};
|
||||
|
||||
@@ -6,22 +6,22 @@
|
||||
using namespace mbgl;
|
||||
|
||||
TEST(TaggedString, Trim) {
|
||||
TaggedString basic(u" \t\ntrim that and not this \n\t", SectionOptions(1.0f, {}));
|
||||
TaggedString basic(u" \t\ntrim that and not this \n\t", SectionOptions(1.0f, {}, GlyphIDType::FontPBF, 0));
|
||||
basic.trim();
|
||||
EXPECT_EQ(basic.rawText(), u"trim that and not this");
|
||||
|
||||
TaggedString twoSections;
|
||||
twoSections.addTextSection(u" \t\ntrim that", 1.5f, {});
|
||||
twoSections.addTextSection(u" and not this \n\t", 0.5f, {});
|
||||
twoSections.addTextSection(u" \t\ntrim that", 1.5f, {}, GlyphIDType::FontPBF, false, {});
|
||||
twoSections.addTextSection(u" and not this \n\t", 0.5f, {}, GlyphIDType::FontPBF, false, {});
|
||||
|
||||
twoSections.trim();
|
||||
EXPECT_EQ(twoSections.rawText(), u"trim that and not this");
|
||||
|
||||
TaggedString empty(u"\n\t\v \r \t\n", SectionOptions(1.0f, {}));
|
||||
TaggedString empty(u"\n\t\v \r \t\n", SectionOptions(1.0f, {}, GlyphIDType::FontPBF, 0));
|
||||
empty.trim();
|
||||
EXPECT_EQ(empty.rawText(), u"");
|
||||
|
||||
TaggedString noTrim(u"no trim!", SectionOptions(1.0f, {}));
|
||||
TaggedString noTrim(u"no trim!", SectionOptions(1.0f, {}, GlyphIDType::FontPBF, 0));
|
||||
noTrim.trim();
|
||||
EXPECT_EQ(noTrim.rawText(), u"no trim!");
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
: SymbolFeature(std::make_unique<StubGeometryTileFeature>(
|
||||
std::move(id_), type_, std::move(geometry_), std::move(properties_))) {
|
||||
if (text_) {
|
||||
formattedText = TaggedString(*text_, SectionOptions(1.0, {}));
|
||||
formattedText = TaggedString(*text_, SectionOptions(1.0, {}, GlyphIDType::FontPBF, 0));
|
||||
}
|
||||
icon = std::move(icon_);
|
||||
index = index_;
|
||||
|
||||
441
vendor/BUILD.bazel
vendored
@@ -236,6 +236,447 @@ cc_library(
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "freetype",
|
||||
srcs = [
|
||||
"freetype/builds/unix/ftsystem.c",
|
||||
"freetype/src/autofit/autofit.c",
|
||||
"freetype/src/base/ftbase.c",
|
||||
"freetype/src/base/ftbbox.c",
|
||||
"freetype/src/base/ftbdf.c",
|
||||
"freetype/src/base/ftbitmap.c",
|
||||
"freetype/src/base/ftcid.c",
|
||||
"freetype/src/base/ftdebug.c",
|
||||
"freetype/src/base/ftfstype.c",
|
||||
"freetype/src/base/ftgasp.c",
|
||||
"freetype/src/base/ftglyph.c",
|
||||
"freetype/src/base/ftgxval.c",
|
||||
"freetype/src/base/ftinit.c",
|
||||
"freetype/src/base/ftmm.c",
|
||||
"freetype/src/base/ftotval.c",
|
||||
"freetype/src/base/ftpatent.c",
|
||||
"freetype/src/base/ftpfr.c",
|
||||
"freetype/src/base/ftstroke.c",
|
||||
"freetype/src/base/ftsynth.c",
|
||||
"freetype/src/base/fttype1.c",
|
||||
"freetype/src/base/ftwinfnt.c",
|
||||
"freetype/src/bdf/bdf.c",
|
||||
"freetype/src/bzip2/ftbzip2.c",
|
||||
"freetype/src/cache/ftcache.c",
|
||||
"freetype/src/cff/cff.c",
|
||||
"freetype/src/cid/type1cid.c",
|
||||
"freetype/src/gxvalid/gxvalid.c",
|
||||
"freetype/src/gzip/ftgzip.c",
|
||||
"freetype/src/lzw/ftlzw.c",
|
||||
"freetype/src/otvalid/otvalid.c",
|
||||
"freetype/src/pcf/pcf.c",
|
||||
"freetype/src/pfr/pfr.c",
|
||||
"freetype/src/psaux/psaux.c",
|
||||
"freetype/src/pshinter/pshinter.c",
|
||||
"freetype/src/psnames/psnames.c",
|
||||
"freetype/src/raster/raster.c",
|
||||
"freetype/src/sdf/sdf.c",
|
||||
"freetype/src/sfnt/sfnt.c",
|
||||
"freetype/src/smooth/smooth.c",
|
||||
"freetype/src/svg/svg.c",
|
||||
"freetype/src/truetype/truetype.c",
|
||||
"freetype/src/type1/type1.c",
|
||||
"freetype/src/type42/type42.c",
|
||||
"freetype/src/winfonts/winfnt.c",
|
||||
],
|
||||
hdrs = glob([
|
||||
"freetype/include/**/*.h",
|
||||
"freetype/src/**/*.h",
|
||||
"freetype/src/**/*.c",
|
||||
"freetype/include/ft2build.h",
|
||||
]),
|
||||
copts = [
|
||||
"-Wno-covered-switch-default",
|
||||
"-DFT_CONFIG_OPTION_SYSTEM_ZLIB",
|
||||
"-DFT_CONFIG_CONFIG_H=<ftconfig.h>",
|
||||
# "-DFT_CONFIG_OPTION_USE_PNG",
|
||||
"-DFT2_BUILD_LIBRARY",
|
||||
"-DFT_CONFIG_MODULES_H=<ftmodule.h>",
|
||||
"-DHAVE_UNISTD_H=1",
|
||||
"-DHAVE_FCNTL_H=1",
|
||||
"-DHAVE_STDINT_H=1",
|
||||
"-DFT_DISABLE_BROTLI=ON",
|
||||
"-DFT_DISABLE_PNG=ON",
|
||||
"-Ifreetype/include",
|
||||
],
|
||||
includes = [
|
||||
"freetype/include",
|
||||
"freetype/include/freetype/config",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
],
|
||||
)
|
||||
|
||||
HARFBUZZ_HDRS = [
|
||||
"harfbuzz/src/hb-aat-layout.h",
|
||||
"harfbuzz/src/hb-blob.h",
|
||||
"harfbuzz/src/hb-buffer.h",
|
||||
"harfbuzz/src/hb-common.h",
|
||||
"harfbuzz/src/hb-deprecated.h",
|
||||
"harfbuzz/src/hb-face.h",
|
||||
"harfbuzz/src/hb-font.h",
|
||||
"harfbuzz/src/hb-map.h",
|
||||
"harfbuzz/src/hb-ot-font.h",
|
||||
"harfbuzz/src/hb-ot-layout.h",
|
||||
"harfbuzz/src/hb-ot-math.h",
|
||||
"harfbuzz/src/hb-ot-metrics.h",
|
||||
"harfbuzz/src/hb-ot-shape.h",
|
||||
"harfbuzz/src/hb-ot-var.h",
|
||||
"harfbuzz/src/hb-ot.h",
|
||||
"harfbuzz/src/hb-set.h",
|
||||
"harfbuzz/src/hb-shape-plan.h",
|
||||
"harfbuzz/src/hb-shape.h",
|
||||
"harfbuzz/src/hb-style.h",
|
||||
"harfbuzz/src/hb-subset.h",
|
||||
"harfbuzz/src/hb-unicode.h",
|
||||
"harfbuzz/src/hb-version.h",
|
||||
"harfbuzz/src/hb.h",
|
||||
"harfbuzz/src/hb-ft.h",
|
||||
"harfbuzz/src/OT/Color/CBDT/CBDT.hh",
|
||||
"harfbuzz/src/OT/Color/COLR/COLR.hh",
|
||||
"harfbuzz/src/OT/Color/COLR/colrv1-closure.hh",
|
||||
"harfbuzz/src/OT/Color/CPAL/CPAL.hh",
|
||||
"harfbuzz/src/OT/Color/sbix/sbix.hh",
|
||||
"harfbuzz/src/OT/Color/svg/svg.hh",
|
||||
"harfbuzz/src/OT/Layout/Common/Coverage.hh",
|
||||
"harfbuzz/src/OT/Layout/Common/CoverageFormat1.hh",
|
||||
"harfbuzz/src/OT/Layout/Common/CoverageFormat2.hh",
|
||||
"harfbuzz/src/OT/Layout/Common/RangeRecord.hh",
|
||||
"harfbuzz/src/OT/Layout/GDEF/GDEF.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/Anchor.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/AnchorFormat1.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/AnchorFormat2.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/AnchorFormat3.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/AnchorMatrix.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/ChainContextPos.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/Common.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/ContextPos.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/CursivePos.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/CursivePosFormat1.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/ExtensionPos.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/GPOS.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/LigatureArray.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/MarkArray.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/MarkBasePos.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/MarkBasePosFormat1.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/MarkLigPos.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/MarkLigPosFormat1.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/MarkMarkPos.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/MarkMarkPosFormat1.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/MarkRecord.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/PairPos.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/PairPosFormat1.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/PairPosFormat2.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/PairSet.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/PairValueRecord.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/PosLookup.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/PosLookupSubTable.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/SinglePos.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/SinglePosFormat1.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/SinglePosFormat2.hh",
|
||||
"harfbuzz/src/OT/Layout/GPOS/ValueFormat.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/AlternateSet.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/AlternateSubst.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/AlternateSubstFormat1.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/ChainContextSubst.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/Common.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/ContextSubst.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/ExtensionSubst.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/GSUB.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/Ligature.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/LigatureSet.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/LigatureSubst.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/LigatureSubstFormat1.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/MultipleSubst.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/MultipleSubstFormat1.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/ReverseChainSingleSubst.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/ReverseChainSingleSubstFormat1.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/Sequence.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/SingleSubst.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/SingleSubstFormat1.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/SingleSubstFormat2.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/SubstLookup.hh",
|
||||
"harfbuzz/src/OT/Layout/GSUB/SubstLookupSubTable.hh",
|
||||
"harfbuzz/src/OT/Layout/types.hh",
|
||||
"harfbuzz/src/OT/glyf/CompositeGlyph.hh",
|
||||
"harfbuzz/src/OT/glyf/Glyph.hh",
|
||||
"harfbuzz/src/OT/glyf/GlyphHeader.hh",
|
||||
"harfbuzz/src/OT/glyf/SimpleGlyph.hh",
|
||||
"harfbuzz/src/OT/glyf/SubsetGlyph.hh",
|
||||
"harfbuzz/src/OT/glyf/VarCompositeGlyph.hh",
|
||||
"harfbuzz/src/OT/glyf/composite-iter.hh",
|
||||
"harfbuzz/src/OT/glyf/coord-setter.hh",
|
||||
"harfbuzz/src/OT/glyf/glyf-helpers.hh",
|
||||
"harfbuzz/src/OT/glyf/glyf.hh",
|
||||
"harfbuzz/src/OT/glyf/loca.hh",
|
||||
"harfbuzz/src/OT/glyf/path-builder.hh",
|
||||
"harfbuzz/src/OT/name/name.hh",
|
||||
"harfbuzz/src/graph/classdef-graph.hh",
|
||||
"harfbuzz/src/graph/coverage-graph.hh",
|
||||
"harfbuzz/src/graph/graph.hh",
|
||||
"harfbuzz/src/graph/gsubgpos-context.cc",
|
||||
"harfbuzz/src/graph/gsubgpos-context.hh",
|
||||
"harfbuzz/src/graph/gsubgpos-graph.hh",
|
||||
"harfbuzz/src/graph/markbasepos-graph.hh",
|
||||
"harfbuzz/src/graph/pairpos-graph.hh",
|
||||
"harfbuzz/src/graph/serialize.hh",
|
||||
"harfbuzz/src/graph/split-helpers.hh",
|
||||
"harfbuzz/src/hb-aat-layout-ankr-table.hh",
|
||||
"harfbuzz/src/hb-aat-layout-bsln-table.hh",
|
||||
"harfbuzz/src/hb-aat-layout-common.hh",
|
||||
"harfbuzz/src/hb-aat-layout-feat-table.hh",
|
||||
"harfbuzz/src/hb-aat-layout-just-table.hh",
|
||||
"harfbuzz/src/hb-aat-layout-kerx-table.hh",
|
||||
"harfbuzz/src/hb-aat-layout-morx-table.hh",
|
||||
"harfbuzz/src/hb-aat-layout-opbd-table.hh",
|
||||
"harfbuzz/src/hb-aat-layout-trak-table.hh",
|
||||
"harfbuzz/src/hb-aat-layout.cc",
|
||||
"harfbuzz/src/hb-aat-layout.hh",
|
||||
"harfbuzz/src/hb-aat-ltag-table.hh",
|
||||
"harfbuzz/src/hb-aat-map.cc",
|
||||
"harfbuzz/src/hb-aat-map.hh",
|
||||
"harfbuzz/src/hb-aat.h",
|
||||
"harfbuzz/src/hb-algs.hh",
|
||||
"harfbuzz/src/hb-array.hh",
|
||||
"harfbuzz/src/hb-atomic.hh",
|
||||
"harfbuzz/src/hb-bimap.hh",
|
||||
"harfbuzz/src/hb-bit-page.hh",
|
||||
"harfbuzz/src/hb-bit-set-invertible.hh",
|
||||
"harfbuzz/src/hb-bit-set.hh",
|
||||
"harfbuzz/src/hb-blob.cc",
|
||||
"harfbuzz/src/hb-blob.hh",
|
||||
"harfbuzz/src/hb-buffer-deserialize-json.hh",
|
||||
"harfbuzz/src/hb-buffer-deserialize-text-glyphs.hh",
|
||||
"harfbuzz/src/hb-buffer-deserialize-text-unicode.hh",
|
||||
"harfbuzz/src/hb-buffer-serialize.cc",
|
||||
"harfbuzz/src/hb-buffer-verify.cc",
|
||||
"harfbuzz/src/hb-buffer.cc",
|
||||
"harfbuzz/src/hb-buffer.hh",
|
||||
"harfbuzz/src/hb-cache.hh",
|
||||
"harfbuzz/src/hb-cff-interp-common.hh",
|
||||
"harfbuzz/src/hb-cff-interp-cs-common.hh",
|
||||
"harfbuzz/src/hb-cff-interp-dict-common.hh",
|
||||
"harfbuzz/src/hb-cff1-interp-cs.hh",
|
||||
"harfbuzz/src/hb-cff2-interp-cs.hh",
|
||||
"harfbuzz/src/hb-common.cc",
|
||||
"harfbuzz/src/hb-config.hh",
|
||||
"harfbuzz/src/hb-cplusplus.hh",
|
||||
"harfbuzz/src/hb-debug.hh",
|
||||
"harfbuzz/src/hb-dispatch.hh",
|
||||
"harfbuzz/src/hb-draw.cc",
|
||||
"harfbuzz/src/hb-draw.h",
|
||||
"harfbuzz/src/hb-draw.hh",
|
||||
"harfbuzz/src/hb-face-builder.cc",
|
||||
"harfbuzz/src/hb-face.cc",
|
||||
"harfbuzz/src/hb-face.hh",
|
||||
"harfbuzz/src/hb-font.cc",
|
||||
"harfbuzz/src/hb-ft.cc",
|
||||
"harfbuzz/src/hb-font.hh",
|
||||
"harfbuzz/src/hb-iter.hh",
|
||||
"harfbuzz/src/hb-kern.hh",
|
||||
"harfbuzz/src/hb-limits.hh",
|
||||
"harfbuzz/src/hb-machinery.hh",
|
||||
"harfbuzz/src/hb-map.cc",
|
||||
"harfbuzz/src/hb-map.hh",
|
||||
"harfbuzz/src/hb-meta.hh",
|
||||
"harfbuzz/src/hb-ms-feature-ranges.hh",
|
||||
"harfbuzz/src/hb-multimap.hh",
|
||||
"harfbuzz/src/hb-mutex.hh",
|
||||
"harfbuzz/src/hb-null.hh",
|
||||
"harfbuzz/src/hb-number-parser.hh",
|
||||
"harfbuzz/src/hb-number.cc",
|
||||
"harfbuzz/src/hb-number.hh",
|
||||
"harfbuzz/src/hb-object.hh",
|
||||
"harfbuzz/src/hb-open-file.hh",
|
||||
"harfbuzz/src/hb-open-type.hh",
|
||||
"harfbuzz/src/hb-ot-cff-common.hh",
|
||||
"harfbuzz/src/hb-ot-cff1-std-str.hh",
|
||||
"harfbuzz/src/hb-ot-cff1-table.cc",
|
||||
"harfbuzz/src/hb-ot-cff1-table.hh",
|
||||
"harfbuzz/src/hb-ot-cff2-table.cc",
|
||||
"harfbuzz/src/hb-ot-cff2-table.hh",
|
||||
"harfbuzz/src/hb-ot-cmap-table.hh",
|
||||
"harfbuzz/src/hb-ot-color.cc",
|
||||
"harfbuzz/src/hb-ot-color.h",
|
||||
"harfbuzz/src/hb-ot-deprecated.h",
|
||||
"harfbuzz/src/hb-ot-face-table-list.hh",
|
||||
"harfbuzz/src/hb-ot-face.cc",
|
||||
"harfbuzz/src/hb-ot-face.hh",
|
||||
"harfbuzz/src/hb-ot-font.cc",
|
||||
"harfbuzz/src/hb-ot-gasp-table.hh",
|
||||
"harfbuzz/src/hb-ot-glyf-table.hh",
|
||||
"harfbuzz/src/hb-ot-hdmx-table.hh",
|
||||
"harfbuzz/src/hb-ot-head-table.hh",
|
||||
"harfbuzz/src/hb-ot-hhea-table.hh",
|
||||
"harfbuzz/src/hb-ot-hmtx-table.hh",
|
||||
"harfbuzz/src/hb-ot-kern-table.hh",
|
||||
"harfbuzz/src/hb-ot-layout-base-table.hh",
|
||||
"harfbuzz/src/hb-ot-layout-common.hh",
|
||||
"harfbuzz/src/hb-ot-layout-gdef-table.hh",
|
||||
"harfbuzz/src/hb-ot-layout-gpos-table.hh",
|
||||
"harfbuzz/src/hb-ot-layout-gsub-table.hh",
|
||||
"harfbuzz/src/hb-ot-layout-gsubgpos.hh",
|
||||
"harfbuzz/src/hb-ot-layout-jstf-table.hh",
|
||||
"harfbuzz/src/hb-ot-layout.cc",
|
||||
"harfbuzz/src/hb-ot-layout.hh",
|
||||
"harfbuzz/src/hb-ot-map.cc",
|
||||
"harfbuzz/src/hb-ot-map.hh",
|
||||
"harfbuzz/src/hb-ot-math-table.hh",
|
||||
"harfbuzz/src/hb-ot-math.cc",
|
||||
"harfbuzz/src/hb-ot-maxp-table.hh",
|
||||
"harfbuzz/src/hb-ot-meta-table.hh",
|
||||
"harfbuzz/src/hb-ot-meta.cc",
|
||||
"harfbuzz/src/hb-ot-meta.h",
|
||||
"harfbuzz/src/hb-ot-metrics.cc",
|
||||
"harfbuzz/src/hb-ot-metrics.hh",
|
||||
"harfbuzz/src/hb-ot-name-language-static.hh",
|
||||
"harfbuzz/src/hb-ot-name-language.hh",
|
||||
"harfbuzz/src/hb-ot-name-table.hh",
|
||||
"harfbuzz/src/hb-ot-name.cc",
|
||||
"harfbuzz/src/hb-ot-name.h",
|
||||
"harfbuzz/src/hb-ot-os2-table.hh",
|
||||
"harfbuzz/src/hb-ot-os2-unicode-ranges.hh",
|
||||
"harfbuzz/src/hb-ot-post-macroman.hh",
|
||||
"harfbuzz/src/hb-ot-post-table-v2subset.hh",
|
||||
"harfbuzz/src/hb-ot-post-table.hh",
|
||||
"harfbuzz/src/hb-ot-shape-fallback.cc",
|
||||
"harfbuzz/src/hb-ot-shape-fallback.hh",
|
||||
"harfbuzz/src/hb-ot-shape-normalize.cc",
|
||||
"harfbuzz/src/hb-ot-shape-normalize.hh",
|
||||
"harfbuzz/src/hb-ot-shape.cc",
|
||||
"harfbuzz/src/hb-ot-shape.hh",
|
||||
"harfbuzz/src/hb-ot-shaper-arabic-fallback.hh",
|
||||
"harfbuzz/src/hb-ot-shaper-arabic-joining-list.hh",
|
||||
"harfbuzz/src/hb-ot-shaper-arabic-pua.hh",
|
||||
"harfbuzz/src/hb-ot-shaper-arabic-table.hh",
|
||||
"harfbuzz/src/hb-ot-shaper-arabic.cc",
|
||||
"harfbuzz/src/hb-ot-shaper-arabic.hh",
|
||||
"harfbuzz/src/hb-ot-shaper-default.cc",
|
||||
"harfbuzz/src/hb-ot-shaper-hangul.cc",
|
||||
"harfbuzz/src/hb-ot-shaper-hebrew.cc",
|
||||
"harfbuzz/src/hb-ot-shaper-indic-machine.hh",
|
||||
"harfbuzz/src/hb-ot-shaper-indic-table.cc",
|
||||
"harfbuzz/src/hb-ot-shaper-indic.cc",
|
||||
"harfbuzz/src/hb-ot-shaper-indic.hh",
|
||||
"harfbuzz/src/hb-ot-shaper-khmer-machine.hh",
|
||||
"harfbuzz/src/hb-ot-shaper-khmer.cc",
|
||||
"harfbuzz/src/hb-ot-shaper-myanmar-machine.hh",
|
||||
"harfbuzz/src/hb-ot-shaper-myanmar.cc",
|
||||
"harfbuzz/src/hb-ot-shaper-syllabic.cc",
|
||||
"harfbuzz/src/hb-ot-shaper-syllabic.hh",
|
||||
"harfbuzz/src/hb-ot-shaper-thai.cc",
|
||||
"harfbuzz/src/hb-ot-shaper-use-machine.hh",
|
||||
"harfbuzz/src/hb-ot-shaper-use-table.hh",
|
||||
"harfbuzz/src/hb-ot-shaper-use.cc",
|
||||
"harfbuzz/src/hb-ot-shaper-vowel-constraints.cc",
|
||||
"harfbuzz/src/hb-ot-shaper-vowel-constraints.hh",
|
||||
"harfbuzz/src/hb-ot-shaper.hh",
|
||||
"harfbuzz/src/hb-ot-stat-table.hh",
|
||||
"harfbuzz/src/hb-ot-tag-table.hh",
|
||||
"harfbuzz/src/hb-ot-tag.cc",
|
||||
"harfbuzz/src/hb-ot-var-avar-table.hh",
|
||||
"harfbuzz/src/hb-ot-var-common.hh",
|
||||
"harfbuzz/src/hb-ot-var-cvar-table.hh",
|
||||
"harfbuzz/src/hb-ot-var-fvar-table.hh",
|
||||
"harfbuzz/src/hb-ot-var-gvar-table.hh",
|
||||
"harfbuzz/src/hb-ot-var-hvar-table.hh",
|
||||
"harfbuzz/src/hb-ot-var-mvar-table.hh",
|
||||
"harfbuzz/src/hb-ot-var.cc",
|
||||
"harfbuzz/src/hb-ot-vorg-table.hh",
|
||||
"harfbuzz/src/hb-outline.cc",
|
||||
"harfbuzz/src/hb-outline.hh",
|
||||
"harfbuzz/src/hb-paint-extents.cc",
|
||||
"harfbuzz/src/hb-paint-extents.hh",
|
||||
"harfbuzz/src/hb-paint.cc",
|
||||
"harfbuzz/src/hb-paint.h",
|
||||
"harfbuzz/src/hb-paint.hh",
|
||||
"harfbuzz/src/hb-pool.hh",
|
||||
"harfbuzz/src/hb-priority-queue.hh",
|
||||
"harfbuzz/src/hb-repacker.hh",
|
||||
"harfbuzz/src/hb-sanitize.hh",
|
||||
"harfbuzz/src/hb-serialize.hh",
|
||||
"harfbuzz/src/hb-set-digest.hh",
|
||||
"harfbuzz/src/hb-set.cc",
|
||||
"harfbuzz/src/hb-set.hh",
|
||||
"harfbuzz/src/hb-shape-plan.cc",
|
||||
"harfbuzz/src/hb-shape-plan.hh",
|
||||
"harfbuzz/src/hb-shape.cc",
|
||||
"harfbuzz/src/hb-shaper-impl.hh",
|
||||
"harfbuzz/src/hb-shaper-list.hh",
|
||||
"harfbuzz/src/hb-shaper.cc",
|
||||
"harfbuzz/src/hb-shaper.hh",
|
||||
"harfbuzz/src/hb-static.cc",
|
||||
"harfbuzz/src/hb-string-array.hh",
|
||||
"harfbuzz/src/hb-subset-accelerator.hh",
|
||||
"harfbuzz/src/hb-subset-cff-common.cc",
|
||||
"harfbuzz/src/hb-subset-cff-common.hh",
|
||||
"harfbuzz/src/hb-subset-cff1.cc",
|
||||
"harfbuzz/src/hb-subset-cff2.cc",
|
||||
"harfbuzz/src/hb-subset-input.cc",
|
||||
"harfbuzz/src/hb-subset-input.hh",
|
||||
"harfbuzz/src/hb-subset-instancer-solver.cc",
|
||||
"harfbuzz/src/hb-subset-instancer-solver.hh",
|
||||
"harfbuzz/src/hb-subset-plan-member-list.hh",
|
||||
"harfbuzz/src/hb-subset-plan.cc",
|
||||
"harfbuzz/src/hb-subset-plan.hh",
|
||||
"harfbuzz/src/hb-subset-repacker.cc",
|
||||
"harfbuzz/src/hb-subset-repacker.h",
|
||||
"harfbuzz/src/hb-subset.cc",
|
||||
"harfbuzz/src/hb-subset.hh",
|
||||
"harfbuzz/src/hb-ucd-table.hh",
|
||||
"harfbuzz/src/hb-ucd.cc",
|
||||
"harfbuzz/src/hb-unicode-emoji-table.hh",
|
||||
"harfbuzz/src/hb-unicode.cc",
|
||||
"harfbuzz/src/hb-unicode.hh",
|
||||
"harfbuzz/src/hb-utf.hh",
|
||||
"harfbuzz/src/hb-vector.hh",
|
||||
"harfbuzz/src/hb.hh",
|
||||
"harfbuzz/src/hb-ft-colr.hh",
|
||||
"harfbuzz/src/hb-coretext.cc",
|
||||
"harfbuzz/src/hb-directwrite.cc",
|
||||
"harfbuzz/src/hb-fallback-shape.cc",
|
||||
"harfbuzz/src/hb-gdi.cc",
|
||||
"harfbuzz/src/hb-glib.cc",
|
||||
"harfbuzz/src/hb-graphite2.cc",
|
||||
"harfbuzz/src/hb-style.cc",
|
||||
"harfbuzz/src/hb-uniscribe.cc",
|
||||
"harfbuzz/src/hb-wasm-api.cc",
|
||||
"harfbuzz/src/hb-wasm-shape.cc",
|
||||
]
|
||||
|
||||
HARFBUZZ_SRCS = [
|
||||
"harfbuzz/src/harfbuzz.cc",
|
||||
]
|
||||
|
||||
cc_library(
|
||||
name = "harfbuzz",
|
||||
srcs = HARFBUZZ_SRCS,
|
||||
hdrs = HARFBUZZ_HDRS + glob([
|
||||
"freetype/include/*",
|
||||
"freetype/include/freetype/*",
|
||||
"freetype/include/freetype/config/*",
|
||||
]),
|
||||
defines = [
|
||||
"HAVE_OT",
|
||||
"HAVE_FREETYPE",
|
||||
# "HAVE_CONFIG_OVERRIDE_H",
|
||||
# "HB_NO_FALLBACK_SHAPE",
|
||||
# "HB_NO_WIN1256",
|
||||
"HB_TINY",
|
||||
],
|
||||
includes = [
|
||||
"freetype/include",
|
||||
"harfbuzz/src",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "sqlite",
|
||||
srcs = ["sqlite/src/sqlite3.c"],
|
||||
|
||||
1
vendor/freetype
vendored
Submodule
24
vendor/freetype.cmake
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
if(TARGET freetype)
|
||||
return()
|
||||
endif()
|
||||
if (MLN_TEXT_SHAPING_HARFBUZZ)
|
||||
set(FT_DISABLE_BROTLI ON CACHE BOOL "freetype option")
|
||||
set(FT_REQUIRE_BROTLI OFF CACHE BOOL "freetype option")
|
||||
set(FT_DISABLE_ZLIB ON CACHE BOOL "freetype option")
|
||||
set(FT_REQUIRE_ZLIB OFF CACHE BOOL "freetype option")
|
||||
add_subdirectory(vendor/freetype)
|
||||
|
||||
set_target_properties(
|
||||
freetype
|
||||
PROPERTIES
|
||||
INTERFACE_MAPLIBRE_NAME "freetype"
|
||||
INTERFACE_MAPLIBRE_URL "https://github.com/freetype/freetype"
|
||||
INTERFACE_MAPLIBRE_AUTHOR "David Turner, Robert Wilhelm, Werner Lemberg and FreeType contributors"
|
||||
INTERFACE_MAPLIBRE_LICENSE ${PROJECT_SOURCE_DIR}/vendor/freetype/docs/FTL.TXT
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
mbgl-core SYSTEM
|
||||
PUBLIC vendor/freetype/include
|
||||
)
|
||||
endif()
|
||||
1
vendor/harfbuzz
vendored
Submodule
22
vendor/harfbuzz.cmake
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
if(TARGET harfbuzz)
|
||||
return()
|
||||
endif()
|
||||
if (MLN_TEXT_SHAPING_HARFBUZZ)
|
||||
add_subdirectory(vendor/harfbuzz)
|
||||
|
||||
target_compile_definitions(harfbuzz PRIVATE -DHAVE_FREETYPE)
|
||||
|
||||
set_target_properties(
|
||||
harfbuzz
|
||||
PROPERTIES
|
||||
INTERFACE_MAPLIBRE_NAME "harfbuzz"
|
||||
INTERFACE_MAPLIBRE_URL "https://github.com/harfbuzz/harfbuzz"
|
||||
INTERFACE_MAPLIBRE_AUTHOR ${PROJECT_SOURCE_DIR}/vendor/harfbuzz/AUTHORS
|
||||
INTERFACE_MAPLIBRE_LICENSE ${PROJECT_SOURCE_DIR}/vendor/harfbuzz/COPYING
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
mbgl-core SYSTEM
|
||||
PUBLIC vendor/harfbuzz/src
|
||||
)
|
||||
endif()
|
||||