summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2019-01-02 16:36:26 -0400
committerBruno de Oliveira Abinader <bruno@mapbox.com>2019-01-04 17:27:41 -0400
commit963dd5e567362b9bf9448d7d2da746d6892a91b2 (patch)
treeb9a585352f5c677f1256ef08df6fd90de689ea37
parent513b50eee80cb72fe38fd42dd99527c3b6ef7800 (diff)
downloadqtlocation-mapboxgl-963dd5e567362b9bf9448d7d2da746d6892a91b2.tar.gz
[Qt] Support local font family in QMapboxGLSettings
-rw-r--r--platform/qt/include/qmapboxgl.hpp4
-rw-r--r--platform/qt/src/qmapboxgl.cpp25
-rw-r--r--platform/qt/src/qmapboxgl_map_renderer.cpp5
-rw-r--r--platform/qt/src/qmapboxgl_map_renderer.hpp3
-rw-r--r--platform/qt/src/qmapboxgl_p.hpp2
5 files changed, 35 insertions, 4 deletions
diff --git a/platform/qt/include/qmapboxgl.hpp b/platform/qt/include/qmapboxgl.hpp
index 1af62c7491..470947383d 100644
--- a/platform/qt/include/qmapboxgl.hpp
+++ b/platform/qt/include/qmapboxgl.hpp
@@ -69,6 +69,9 @@ public:
QString apiBaseUrl() const;
void setApiBaseUrl(const QString &);
+ QString localFontFamily() const;
+ void setLocalFontFamily(const QString &);
+
std::function<std::string(const std::string &&)> resourceTransform() const;
void setResourceTransform(const std::function<std::string(const std::string &&)> &);
@@ -83,6 +86,7 @@ private:
QString m_assetPath;
QString m_accessToken;
QString m_apiBaseUrl;
+ QString m_localFontFamily;
std::function<std::string(const std::string &&)> m_resourceTransform;
};
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index e292bbd195..0984d0a9db 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -446,6 +446,27 @@ void QMapboxGLSettings::setApiBaseUrl(const QString& url)
}
/*!
+ Returns the local font family. Returns an empty string if no local font family is set.
+*/
+QString QMapboxGLSettings::localFontFamily() const
+{
+ return m_localFontFamily;
+}
+
+/*!
+ Sets the local font family.
+
+ Rendering Chinese/Japanese/Korean (CJK) ideographs and precomposed Hangul Syllables requires
+ downloading large amounts of font data, which can significantly slow map load times. Use the
+ localIdeographFontFamily setting to speed up map load times by using locally available fonts
+ instead of font data fetched from the server.
+*/
+void QMapboxGLSettings::setLocalFontFamily(const QString &family)
+{
+ m_localFontFamily = family;
+}
+
+/*!
Returns resource transformation callback used to transform requested URLs.
*/
std::function<std::string(const std::string &&)> QMapboxGLSettings::resourceTransform() const
@@ -1723,6 +1744,7 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin
, m_threadPool(mbgl::sharedThreadPool())
, m_mode(settings.contextMode())
, m_pixelRatio(pixelRatio_)
+ , m_localFontFamily(settings.localFontFamily())
{
// Setup the FileSource
m_fileSourceObj->setAccessToken(settings.accessToken().toStdString());
@@ -1802,7 +1824,8 @@ void QMapboxGLPrivate::createRenderer()
m_pixelRatio,
*m_fileSourceObj,
*m_threadPool,
- m_mode
+ m_mode,
+ m_localFontFamily
);
connect(m_mapRenderer.get(), SIGNAL(needsRendering()), this, SLOT(requestRendering()));
diff --git a/platform/qt/src/qmapboxgl_map_renderer.cpp b/platform/qt/src/qmapboxgl_map_renderer.cpp
index 8c554dab7e..31b518e6d0 100644
--- a/platform/qt/src/qmapboxgl_map_renderer.cpp
+++ b/platform/qt/src/qmapboxgl_map_renderer.cpp
@@ -25,8 +25,9 @@ static auto *getScheduler() {
};
QMapboxGLMapRenderer::QMapboxGLMapRenderer(qreal pixelRatio,
- mbgl::DefaultFileSource &fs, mbgl::ThreadPool &tp, QMapboxGLSettings::GLContextMode mode)
- : m_renderer(std::make_unique<mbgl::Renderer>(m_backend, pixelRatio, fs, tp, static_cast<mbgl::GLContextMode>(mode)))
+ mbgl::DefaultFileSource &fs, mbgl::ThreadPool &tp, QMapboxGLSettings::GLContextMode mode, const QString &localFontFamily)
+ : m_renderer(std::make_unique<mbgl::Renderer>(m_backend, pixelRatio, fs, tp, static_cast<mbgl::GLContextMode>(mode), mbgl::optional<std::string> {},
+ localFontFamily.isEmpty() ? mbgl::nullopt : mbgl::optional<std::string> { localFontFamily.toStdString() }))
, m_forceScheduler(needsToForceScheduler())
{
// If we don't have a Scheduler on this thread, which
diff --git a/platform/qt/src/qmapboxgl_map_renderer.hpp b/platform/qt/src/qmapboxgl_map_renderer.hpp
index 0b17542e2f..a59cf74997 100644
--- a/platform/qt/src/qmapboxgl_map_renderer.hpp
+++ b/platform/qt/src/qmapboxgl_map_renderer.hpp
@@ -28,7 +28,8 @@ class QMapboxGLMapRenderer : public QObject
public:
QMapboxGLMapRenderer(qreal pixelRatio, mbgl::DefaultFileSource &,
- mbgl::ThreadPool &, QMapboxGLSettings::GLContextMode);
+ mbgl::ThreadPool &, QMapboxGLSettings::GLContextMode,
+ const QString &localFontFamily);
virtual ~QMapboxGLMapRenderer();
void render();
diff --git a/platform/qt/src/qmapboxgl_p.hpp b/platform/qt/src/qmapboxgl_p.hpp
index f13c548592..7157df0aba 100644
--- a/platform/qt/src/qmapboxgl_p.hpp
+++ b/platform/qt/src/qmapboxgl_p.hpp
@@ -65,5 +65,7 @@ private:
QMapboxGLSettings::GLContextMode m_mode;
qreal m_pixelRatio;
+ QString m_localFontFamily;
+
std::atomic_flag m_renderQueued = ATOMIC_FLAG_INIT;
};