From 3114947224fd42013954da6c4cef28d31b1238e7 Mon Sep 17 00:00:00 2001 From: Chris Loer Date: Tue, 28 Nov 2017 14:03:28 -0800 Subject: LocalGlyphRasterizer takes a void* configuration input. If nothing is set, it doesn't rasterize glyphs locally. --- platform/darwin/src/local_glyph_rasterizer.mm | 22 ++++++++++++++-------- src/mbgl/text/local_glyph_rasterizer.hpp | 2 +- test/text/glyph_manager.test.cpp | 4 ---- 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(CTFontCreateWithFontDescriptor(*descriptor, 0.0, NULL)); + impl = std::make_unique(CTFontCreateWithFontDescriptor(*descriptor, 0.0, NULL)); + } else { + impl = std::make_unique((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); } -- cgit v1.2.1