summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Loer <chris.loer@gmail.com>2017-11-28 14:03:28 -0800
committerChris Loer <chris.loer@gmail.com>2017-11-28 14:03:28 -0800
commit3114947224fd42013954da6c4cef28d31b1238e7 (patch)
treed4136dfa0c4d6d66e3278e1e908603ef48306917
parente5c4d9653dd2d34c4c7809c7ca3e429adb151ed4 (diff)
downloadqtlocation-mapboxgl-3114947224fd42013954da6c4cef28d31b1238e7.tar.gz
LocalGlyphRasterizer takes a void* configuration input. If nothing is set, it doesn't rasterize glyphs locally.
-rw-r--r--platform/darwin/src/local_glyph_rasterizer.mm22
-rw-r--r--src/mbgl/text/local_glyph_rasterizer.hpp2
-rw-r--r--test/text/glyph_manager.test.cpp4
3 files changed, 15 insertions, 13 deletions
diff --git a/platform/darwin/src/local_glyph_rasterizer.mm b/platform/darwin/src/local_glyph_rasterizer.mm
index 944fca48c3..44658b7504 100644
--- a/platform/darwin/src/local_glyph_rasterizer.mm
+++ b/platform/darwin/src/local_glyph_rasterizer.mm
@@ -34,16 +34,18 @@ public:
CTFontRefHandle font;
};
-LocalGlyphRasterizer::LocalGlyphRasterizer(void*)
+LocalGlyphRasterizer::LocalGlyphRasterizer(void* configuration)
{
- NSDictionary *fontAttributes =
- [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithFloat:24.0], (NSString *)kCTFontSizeAttribute,
- nil];
+ if (configuration) {
+ NSMutableDictionary *fontAttributes = CFBridgingRelease((CFDictionaryRef)configuration);
+ fontAttributes[(NSString *)kCTFontSizeAttribute] = [NSNumber numberWithFloat:24.0];
- CTFontDescriptorRefHandle descriptor(CTFontDescriptorCreateWithAttributes((CFDictionaryRef)fontAttributes));
+ CTFontDescriptorRefHandle descriptor(CTFontDescriptorCreateWithAttributes((CFDictionaryRef)fontAttributes));
- impl = std::make_unique<Impl>(CTFontCreateWithFontDescriptor(*descriptor, 0.0, NULL));
+ impl = std::make_unique<Impl>(CTFontCreateWithFontDescriptor(*descriptor, 0.0, NULL));
+ } else {
+ impl = std::make_unique<Impl>((CTFontRef)NULL);
+ }
}
LocalGlyphRasterizer::~LocalGlyphRasterizer()
@@ -52,7 +54,7 @@ LocalGlyphRasterizer::~LocalGlyphRasterizer()
bool LocalGlyphRasterizer::canRasterizeGlyph(const FontStack&, GlyphID glyphID) {
// TODO: This is a rough approximation of the set of glyphs that will work with fixed glyph metrics
// Either narrow this down to be conservative, or actually extract glyph metrics in rasterizeGlyph
- return util::i18n::allowsIdeographicBreaking(glyphID);
+ return *(impl->font) && util::i18n::allowsIdeographicBreaking(glyphID);
}
// TODO: In theory we should be able to transform user-coordinate bounding box and advance
@@ -133,6 +135,10 @@ PremultipliedImage drawGlyphBitmap(GlyphID glyphID, CTFontRef font, Size size) {
Glyph LocalGlyphRasterizer::rasterizeGlyph(const FontStack&, GlyphID glyphID) {
Glyph fixedMetrics;
+ if (!*(impl->font)) {
+ return fixedMetrics;
+ }
+
fixedMetrics.id = glyphID;
Size size(35, 35);
diff --git a/src/mbgl/text/local_glyph_rasterizer.hpp b/src/mbgl/text/local_glyph_rasterizer.hpp
index 753ebe372a..f43676dfa4 100644
--- a/src/mbgl/text/local_glyph_rasterizer.hpp
+++ b/src/mbgl/text/local_glyph_rasterizer.hpp
@@ -33,7 +33,7 @@ namespace mbgl {
class LocalGlyphRasterizer {
public:
virtual ~LocalGlyphRasterizer();
- LocalGlyphRasterizer(void* configuration);
+ LocalGlyphRasterizer(void* configuration = nullptr);
// virtual so that test harness can override platform-specific behavior
virtual bool canRasterizeGlyph(const FontStack&, GlyphID);
diff --git a/test/text/glyph_manager.test.cpp b/test/text/glyph_manager.test.cpp
index a50e42236f..a96e1b970c 100644
--- a/test/text/glyph_manager.test.cpp
+++ b/test/text/glyph_manager.test.cpp
@@ -19,10 +19,6 @@ static constexpr const size_t stubBitmapLength = 900;
class StubLocalGlyphRasterizer : public LocalGlyphRasterizer {
public:
- StubLocalGlyphRasterizer()
- : LocalGlyphRasterizer(0)
- {}
-
bool canRasterizeGlyph(const FontStack&, GlyphID glyphID) {
return util::i18n::allowsIdeographicBreaking(glyphID);
}