diff options
author | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2019-03-13 13:08:37 +0200 |
---|---|---|
committer | Bruno de Oliveira Abinader <bruno@mapbox.com> | 2019-03-13 13:19:15 +0200 |
commit | ffa74deeb3b2e37a04c35bea35925a3929396b53 (patch) | |
tree | ca5a6786c4e2d94e415a413f47718bb4366d1742 | |
parent | 7d1911572000d1353c1c0109402431323fcd8639 (diff) | |
download | qtlocation-mapboxgl-ffa74deeb3b2e37a04c35bea35925a3929396b53.tar.gz |
[core] Add localFontFamily to MapOptions
-rw-r--r-- | include/mbgl/map/map_options.hpp | 16 | ||||
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java | 4 | ||||
-rwxr-xr-x | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java | 11 | ||||
-rwxr-xr-x | platform/android/src/native_map_view.cpp | 9 | ||||
-rwxr-xr-x | platform/android/src/native_map_view.hpp | 5 | ||||
-rw-r--r-- | platform/default/src/mbgl/map/map_snapshotter.cpp | 6 | ||||
-rw-r--r-- | platform/ios/src/MGLMapView.mm | 3 | ||||
-rw-r--r-- | platform/macos/src/MGLMapView.mm | 4 | ||||
-rw-r--r-- | platform/qt/src/qmapboxgl.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/map/map.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/map/map_impl.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/map/map_impl.hpp | 3 | ||||
-rw-r--r-- | src/mbgl/map/map_options.cpp | 10 | ||||
-rw-r--r-- | test/text/local_glyph_rasterizer.test.cpp | 14 |
14 files changed, 72 insertions, 23 deletions
diff --git a/include/mbgl/map/map_options.hpp b/include/mbgl/map/map_options.hpp index 13772332a8..454a06b928 100644 --- a/include/mbgl/map/map_options.hpp +++ b/include/mbgl/map/map_options.hpp @@ -131,6 +131,22 @@ public: */ bool crossSourceCollisions() const; + /** + * @brief Sets the local font family, which is the local font family name for client-side + * rendering of CJK glyphs. Default font for local ideograph font family is "PingFang". + * + * @param localFontFamily Local font family. + * @return reference to MapOptions for chaining options together. + */ + MapOptions& withLocalFontFamily(std::string localFontFamily); + + /** + * @brief Gets the previously set (or default) local font family. + * + * @return local font family. + */ + const std::string& localFontFamily() const; + private: class Impl; std::shared_ptr<Impl> impl_; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index f87c6a854a..8600b73744 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -305,8 +305,10 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { } boolean crossSourceCollisions = mapboxMapOptions.getCrossSourceCollisions(); + String localFontFamily = options.getLocalIdeographFontFamily(); + nativeMapView = new NativeMapView( - getContext(), getPixelRatio(), crossSourceCollisions, this, mapChangeReceiver, mapRenderer + getContext(), getPixelRatio(), crossSourceCollisions, this, mapChangeReceiver, mapRenderer, localFontFamily ); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java index 10942d521c..7d0f7aa2fc 100755 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java @@ -85,21 +85,21 @@ final class NativeMapView implements NativeMap { public NativeMapView(@NonNull final Context context, final boolean crossSourceCollisions, final ViewCallback viewCallback, final StateCallback stateCallback, - final MapRenderer mapRenderer) { + final MapRenderer mapRenderer, final String localFontFamily) { this(context, context.getResources().getDisplayMetrics().density, crossSourceCollisions, viewCallback, - stateCallback, mapRenderer); + stateCallback, mapRenderer, localFontFamily); } public NativeMapView(final Context context, final float pixelRatio, final boolean crossSourceCollisions, final ViewCallback viewCallback, final StateCallback stateCallback, - final MapRenderer mapRenderer) { + final MapRenderer mapRenderer, final String localFontFamily) { this.mapRenderer = mapRenderer; this.viewCallback = viewCallback; this.fileSource = FileSource.getInstance(context); this.pixelRatio = pixelRatio; this.thread = Thread.currentThread(); this.stateCallback = stateCallback; - nativeInitialize(this, fileSource, mapRenderer, pixelRatio, crossSourceCollisions); + nativeInitialize(this, fileSource, mapRenderer, pixelRatio, crossSourceCollisions, localFontFamily); } // @@ -1069,7 +1069,8 @@ final class NativeMapView implements NativeMap { FileSource fileSource, MapRenderer mapRenderer, float pixelRatio, - boolean crossSourceCollisions); + boolean crossSourceCollisions, + String localFontFamily); @Keep private native void nativeDestroy(); diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index 83a158efa9..5d75931043 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -62,7 +62,8 @@ NativeMapView::NativeMapView(jni::JNIEnv& _env, const jni::Object<FileSource>& jFileSource, const jni::Object<MapRenderer>& jMapRenderer, jni::jfloat _pixelRatio, - jni::jboolean _crossSourceCollisions) + jni::jboolean _crossSourceCollisions, + const jni::String& _localFontFamily) : javaPeer(_env, _obj) , mapRenderer(MapRenderer::getNativePeer(_env, jMapRenderer)) , pixelRatio(_pixelRatio) @@ -87,6 +88,10 @@ NativeMapView::NativeMapView(jni::JNIEnv& _env, .withViewportMode(ViewportMode::Default) .withCrossSourceCollisions(_crossSourceCollisions); + if (_localFontFamily) { + options.withLocalFontFamily(jni::Make<std::string>(_env, _localFontFamily)); + } + // Create the core map map = std::make_unique<mbgl::Map>(*rendererFrontend, *this, mbgl::Size{ static_cast<uint32_t>(width), @@ -1036,7 +1041,7 @@ void NativeMapView::registerNative(jni::JNIEnv& env) { // Register the peer jni::RegisterNativePeer<NativeMapView>(env, javaClass, "nativePtr", - jni::MakePeer<NativeMapView, const jni::Object<NativeMapView>&, const jni::Object<FileSource>&, const jni::Object<MapRenderer>&, jni::jfloat, jni::jboolean>, + jni::MakePeer<NativeMapView, const jni::Object<NativeMapView>&, const jni::Object<FileSource>&, const jni::Object<MapRenderer>&, jni::jfloat, jni::jboolean, const jni::String&>, "nativeInitialize", "nativeDestroy", METHOD(&NativeMapView::resizeView, "nativeResizeView"), diff --git a/platform/android/src/native_map_view.hpp b/platform/android/src/native_map_view.hpp index d695a91ce0..61a6f02695 100755 --- a/platform/android/src/native_map_view.hpp +++ b/platform/android/src/native_map_view.hpp @@ -51,8 +51,9 @@ public: const jni::Object<NativeMapView>&, const jni::Object<FileSource>&, const jni::Object<MapRenderer>&, - jni::jfloat, - jni::jboolean); + jni::jfloat pixelRatio, + jni::jboolean crossSourceCollisions, + const jni::String& localFontFamily); virtual ~NativeMapView(); diff --git a/platform/default/src/mbgl/map/map_snapshotter.cpp b/platform/default/src/mbgl/map/map_snapshotter.cpp index 56bc9bdb88..9b4df1e1cc 100644 --- a/platform/default/src/mbgl/map/map_snapshotter.cpp +++ b/platform/default/src/mbgl/map/map_snapshotter.cpp @@ -58,7 +58,11 @@ MapSnapshotter::Impl::Impl(FileSource* fileSource, const optional<std::string> localFontFamily) : scheduler(std::move(scheduler_)) , frontend(size, pixelRatio, *fileSource, *scheduler, programCacheDir, GLContextMode::Unique, localFontFamily) - , map(frontend, MapObserver::nullObserver(), size, pixelRatio, *fileSource, *scheduler, MapOptions().withMapMode(MapMode::Static)) { + , map(frontend, MapObserver::nullObserver(), size, pixelRatio, *fileSource, *scheduler, + [&localFontFamily]() -> MapOptions { + MapOptions options = MapOptions().withMapMode(MapMode::Static); + return localFontFamily ? options.withLocalFontFamily(*localFontFamily) : options; + }()) { if (style.first) { map.getStyle().loadJSON(style.second); diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index f6ebd8bced..366cffc8c0 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -481,7 +481,8 @@ public: mapOptions.withMapMode(mbgl::MapMode::Continuous) .withConstrainMode(mbgl::ConstrainMode::None) .withViewportMode(mbgl::ViewportMode::Default) - .withCrossSourceCollisions(enableCrossSourceCollisions); + .withCrossSourceCollisions(enableCrossSourceCollisions) + .withLocalFontFamily(config.localFontFamilyName); NSAssert(!_mbglMap, @"_mbglMap should be NULL"); _mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, self.size, config.scaleFactor, *[config fileSource], *_mbglThreadPool, mapOptions); diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 7edf34574d..51be79e876 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -294,7 +294,9 @@ public: mapOptions.withMapMode(mbgl::MapMode::Continuous) .withConstrainMode(mbgl::ConstrainMode::None) .withViewportMode(mbgl::ViewportMode::Default) - .withCrossSourceCollisions(enableCrossSourceCollisions); + .withCrossSourceCollisions(enableCrossSourceCollisions) + .withLocalFontFamily(config.localFontFamilyName); + _mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, self.size, config.scaleFactor, *config.fileSource, *_mbglThreadPool, mapOptions); // Install the OpenGL layer. Interface Builder’s synchronous drawing means diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index a3ec1bf0e4..2b5f8965ce 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -1775,6 +1775,10 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin .withConstrainMode(static_cast<mbgl::ConstrainMode>(settings.constrainMode())) .withViewportMode(static_cast<mbgl::ViewportMode>(settings.viewportMode())); + if (!m_localFontFamily.isEmpty()) { + options.withLocalFontFamily(m_localFontFamily.toStdString()); + } + // Setup the Map object mapObj = std::make_unique<mbgl::Map>( *this, // RendererFrontend diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 556038d2d8..d661936145 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -44,7 +44,8 @@ Map::Map(RendererFrontend& rendererFrontend, options.mapMode(), options.constrainMode(), options.viewportMode(), - options.crossSourceCollisions())) {} + options.crossSourceCollisions(), + options.localFontFamily())) {} Map::~Map() = default; diff --git a/src/mbgl/map/map_impl.cpp b/src/mbgl/map/map_impl.cpp index 863604f99c..71f85c76f0 100644 --- a/src/mbgl/map/map_impl.cpp +++ b/src/mbgl/map/map_impl.cpp @@ -16,7 +16,8 @@ Map::Impl::Impl(Map& map_, MapMode mode_, ConstrainMode constrainMode_, ViewportMode viewportMode_, - bool crossSourceCollisions_) + bool crossSourceCollisions_, + const optional<std::string> localFontFamily_) : map(map_), observer(mapObserver), rendererFrontend(frontend), diff --git a/src/mbgl/map/map_impl.hpp b/src/mbgl/map/map_impl.hpp index 32dc728b70..b7cd18cdae 100644 --- a/src/mbgl/map/map_impl.hpp +++ b/src/mbgl/map/map_impl.hpp @@ -38,7 +38,8 @@ public: MapMode, ConstrainMode, ViewportMode, - bool crossSourceCollisions); + bool crossSourceCollisions, + const optional<std::string> localFontFamily_); ~Impl() final; diff --git a/src/mbgl/map/map_options.cpp b/src/mbgl/map/map_options.cpp index 118fcaf3df..97d997fa55 100644 --- a/src/mbgl/map/map_options.cpp +++ b/src/mbgl/map/map_options.cpp @@ -14,6 +14,7 @@ public: std::string assetRoot; uint64_t maximumSize{mbgl::util::DEFAULT_MAX_CACHE_SIZE}; bool crossSourceCollisions = true; + std::string localFontFamily = "PingFang"; }; MapOptions::MapOptions() : impl_(std::make_shared<MapOptions::Impl>()) {} @@ -82,4 +83,13 @@ bool MapOptions::crossSourceCollisions() const { return impl_->crossSourceCollisions; } +MapOptions& MapOptions::withLocalFontFamily(std::string localFontFamily) { + impl_->localFontFamily = std::move(localFontFamily); + return *this; +} + +const std::string& MapOptions::localFontFamily() const { + return impl_->localFontFamily; +} + } // namespace mbgl diff --git a/test/text/local_glyph_rasterizer.test.cpp b/test/text/local_glyph_rasterizer.test.cpp index 20f825c935..d630690a60 100644 --- a/test/text/local_glyph_rasterizer.test.cpp +++ b/test/text/local_glyph_rasterizer.test.cpp @@ -32,18 +32,18 @@ namespace { class LocalGlyphRasterizerTest { public: - LocalGlyphRasterizerTest(const optional<std::string> fontFamily) - : frontend(pixelRatio, fileSource, threadPool, optional<std::string>(), GLContextMode::Unique, fontFamily) - { - } - util::RunLoop loop; StubFileSource fileSource; ThreadPool threadPool { 4 }; float pixelRatio { 1 }; HeadlessFrontend frontend; - Map map { frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource, - threadPool, MapOptions().withMapMode(MapMode::Static)}; + Map map; + + LocalGlyphRasterizerTest(const optional<std::string> font) + : frontend(pixelRatio, fileSource, threadPool, optional<std::string>(), GLContextMode::Unique, font) + , map(frontend, MapObserver::nullObserver(), frontend.getSize(), pixelRatio, fileSource, + threadPool, [&font]() { MapOptions o; o.withMapMode(MapMode::Static); return font ? o.withLocalFontFamily(*font) : o; }()) + {} void checkRendering(const char * name) { test::checkImage(std::string("test/fixtures/local_glyphs/") + name, |