From 1e35d09df19bbb9bef5c29673106975d96aeb74d Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 5 Jun 2014 22:40:15 -0700 Subject: [PATCH] Add baseFont method to FontCollection This patch adds a method to retrieve the base font from a FontCollection, which is useful when querying global font metrics. Part of the fix for bug 15467288 "Inconsistent line heights on Minikin builds" Change-Id: I268ae5128d0852a020d746bc22af81fc1a623228 --- engine/src/flutter/include/minikin/FontCollection.h | 3 +++ engine/src/flutter/libs/minikin/FontCollection.cpp | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index 78ab2aae7b9..508a129a99f 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -57,6 +57,9 @@ public: void itemize(const uint16_t *string, size_t string_length, FontStyle style, std::vector* result) const; + // Get the base font for the given style, useful for font-wide metrics. + MinikinFont* baseFont(FontStyle style); + uint32_t getId() const; private: static const int kLogCharsPerPage = 8; diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 1713b476e0b..c13670e74a8 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -185,6 +185,14 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty } } +MinikinFont* FontCollection::baseFont(FontStyle style) { + if (mInstances.empty()) { + return NULL; + } + return mInstances[0].mFamily->getClosestMatch(style); +} + + uint32_t FontCollection::getId() const { return mId; }