[ios,macos] Darwin implementation of a CoreText-based LocalGlyphRasterizer.

- Changing font weight does not currently appear to be working.
 - Glyph metric extraction code not working; currently unused.
This commit is contained in:
Chris Loer
2017-11-27 12:50:28 -08:00
committed by Chris Loer
parent 1661af1cb4
commit cb380064bb
15 changed files with 309 additions and 28 deletions

View File

@@ -10,9 +10,10 @@ Renderer::Renderer(RendererBackend& backend,
FileSource& fileSource_,
Scheduler& scheduler_,
GLContextMode contextMode_,
const optional<std::string> programCacheDir_)
const optional<std::string> programCacheDir_,
const optional<std::string> localFontFamily_)
: impl(std::make_unique<Impl>(backend, pixelRatio_, fileSource_, scheduler_,
contextMode_, std::move(programCacheDir_))) {
contextMode_, std::move(programCacheDir_), std::move(localFontFamily_))) {
}
Renderer::~Renderer() {

View File

@@ -42,7 +42,8 @@ Renderer::Impl::Impl(RendererBackend& backend_,
FileSource& fileSource_,
Scheduler& scheduler_,
GLContextMode contextMode_,
const optional<std::string> programCacheDir_)
const optional<std::string> programCacheDir_,
const optional<std::string> localFontFamily_)
: backend(backend_)
, scheduler(scheduler_)
, fileSource(fileSource_)
@@ -50,7 +51,7 @@ Renderer::Impl::Impl(RendererBackend& backend_,
, contextMode(contextMode_)
, pixelRatio(pixelRatio_)
, programCacheDir(programCacheDir_)
, glyphManager(std::make_unique<GlyphManager>(fileSource))
, glyphManager(std::make_unique<GlyphManager>(fileSource, std::make_unique<LocalGlyphRasterizer>(localFontFamily_)))
, imageManager(std::make_unique<ImageManager>())
, lineAtlas(std::make_unique<LineAtlas>(Size{ 256, 512 }))
, imageImpls(makeMutable<std::vector<Immutable<style::Image::Impl>>>())

View File

@@ -38,7 +38,7 @@ class Renderer::Impl : public GlyphManagerObserver,
public RenderSourceObserver{
public:
Impl(RendererBackend&, float pixelRatio_, FileSource&, Scheduler&, GLContextMode,
const optional<std::string> programCacheDir);
const optional<std::string> programCacheDir, const optional<std::string> localFontFamily);
~Impl() final;
void markContextLost() {

View File

@@ -25,7 +25,7 @@ public:
class GlyphManager : public util::noncopyable {
public:
GlyphManager(FileSource&, std::unique_ptr<LocalGlyphRasterizer> = std::make_unique<LocalGlyphRasterizer>());
GlyphManager(FileSource&, std::unique_ptr<LocalGlyphRasterizer> = std::make_unique<LocalGlyphRasterizer>(optional<std::string>()));
~GlyphManager();
// Workers send a `getGlyphs` message to the main thread once they have determined

View File

@@ -32,11 +32,15 @@ namespace mbgl {
class LocalGlyphRasterizer {
public:
virtual ~LocalGlyphRasterizer() = default;
virtual ~LocalGlyphRasterizer();
LocalGlyphRasterizer(const optional<std::string> fontFamily = optional<std::string>());
// virtual so that test harness can override platform-specific behavior
virtual bool canRasterizeGlyph(const FontStack&, GlyphID);
virtual Glyph rasterizeGlyph(const FontStack&, GlyphID);
private:
class Impl;
std::unique_ptr<Impl> impl;
};
} // namespace mbgl

View File

@@ -392,6 +392,11 @@ bool allowsIdeographicBreaking(char16_t chr) {
// || isInCJKCompatibilityIdeographsSupplement(chr));
}
bool allowsFixedWidthGlyphGeneration(char16_t chr) {
// Mirrors conservative set of characters used in glyph_manager.js/_tinySDF
return isInCJKUnifiedIdeographs(chr) || isInHangulSyllables(chr);
}
bool allowsVerticalWritingMode(const std::u16string& string) {
for (char32_t chr : string) {
if (hasUprightVerticalOrientation(chr)) {

View File

@@ -23,6 +23,10 @@ bool allowsIdeographicBreaking(const std::u16string& string);
by the given Unicode codepoint due to ideographic breaking. */
bool allowsIdeographicBreaking(char16_t chr);
/** Conservative set of characters expected to have relatively fixed sizes and
advances */
bool allowsFixedWidthGlyphGeneration(char16_t chr);
/** Returns whether any substring of the given string can be drawn as vertical
text with upright glyphs. */
bool allowsVerticalWritingMode(const std::u16string& string);