summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libs/minikin/FontCollection.cpp13
-rw-r--r--libs/minikin/FontFamily.cpp8
-rw-r--r--libs/minikin/Layout.cpp11
3 files changed, 22 insertions, 10 deletions
diff --git a/libs/minikin/FontCollection.cpp b/libs/minikin/FontCollection.cpp
index 6115ecc..45e5d06 100644
--- a/libs/minikin/FontCollection.cpp
+++ b/libs/minikin/FontCollection.cpp
@@ -46,12 +46,6 @@ FontCollection::FontCollection(const vector<FontFamily*>& typefaces) :
const FontStyle defaultStyle;
for (size_t i = 0; i < nTypefaces; i++) {
FontFamily* family = typefaces[i];
- family->RefLocked();
- FontInstance dummy;
- mInstances.push_back(dummy); // emplace_back would be better
- FontInstance* instance = &mInstances.back();
- instance->mFamily = family;
- instance->mCoverage = new SparseBitSet;
MinikinFont* typeface = family->getClosestMatch(defaultStyle).font;
if (typeface == NULL) {
ALOGE("FontCollection: closest match was null");
@@ -59,6 +53,12 @@ FontCollection::FontCollection(const vector<FontFamily*>& typefaces) :
// checks upstream to prevent empty/invalid FontFamily objects
continue;
}
+ family->RefLocked();
+ FontInstance dummy;
+ mInstances.push_back(dummy); // emplace_back would be better
+ FontInstance* instance = &mInstances.back();
+ instance->mFamily = family;
+ instance->mCoverage = new SparseBitSet;
#ifdef VERBOSE_DEBUG
ALOGD("closest match = %p, family size = %d\n", typeface, family->getNumFonts());
#endif
@@ -75,6 +75,7 @@ FontCollection::FontCollection(const vector<FontFamily*>& typefaces) :
mMaxChar = max(mMaxChar, instance->mCoverage->length());
lastChar.push_back(instance->mCoverage->nextSetBit(0));
}
+ nTypefaces = mInstances.size();
size_t nPages = (mMaxChar + kPageMask) >> kLogCharsPerPage;
size_t offset = 0;
for (size_t i = 0; i < nPages; i++) {
diff --git a/libs/minikin/FontFamily.cpp b/libs/minikin/FontFamily.cpp
index 9106f63..ad8120f 100644
--- a/libs/minikin/FontFamily.cpp
+++ b/libs/minikin/FontFamily.cpp
@@ -119,9 +119,11 @@ static int computeMatch(FontStyle style1, FontStyle style2) {
}
static FontFakery computeFakery(FontStyle wanted, FontStyle actual) {
- // If desired weight is 2 or more grades higher than actual
- // (for example, medium 500 -> bold 700), then select fake bold.
- bool isFakeBold = (wanted.getWeight() - actual.getWeight()) >= 2;
+ // If desired weight is bold or darker, and 2 or more grades higher
+ // than actual (for example, medium 500 -> bold 700), then select
+ // fake bold.
+ int wantedWeight = wanted.getWeight();
+ bool isFakeBold = wantedWeight >= 7 && (wantedWeight - actual.getWeight()) >= 2;
bool isFakeItalic = wanted.getItalic() && !actual.getItalic();
return FontFakery(isFakeBold, isFakeItalic);
}
diff --git a/libs/minikin/Layout.cpp b/libs/minikin/Layout.cpp
index 709393d..762a7db 100644
--- a/libs/minikin/Layout.cpp
+++ b/libs/minikin/Layout.cpp
@@ -618,6 +618,12 @@ void Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_
cache.mCache.put(key, value);
}
+static void addFeatures(vector<hb_feature_t>* features) {
+ // hardcoded features, to be repaced with more flexible configuration
+ static hb_feature_t palt = { HB_TAG('p', 'a', 'l', 't'), 1, 0, ~0u };
+ features->push_back(palt);
+}
+
void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize,
bool isRtl, LayoutContext* ctx) {
hb_buffer_t* buffer = LayoutEngine::getInstance().hbBuffer;
@@ -627,6 +633,9 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t
std::reverse(items.begin(), items.end());
}
+ vector<hb_feature_t> features;
+ addFeatures(&features);
+
float x = mAdvance;
float y = 0;
for (size_t run_ix = 0; run_ix < items.size(); run_ix++) {
@@ -664,7 +673,7 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t
hb_buffer_set_language(buffer, hb_language_from_string(lang.c_str(), -1));
}
hb_buffer_add_utf16(buffer, buf, bufSize, srunstart + start, srunend - srunstart);
- hb_shape(hbFont, buffer, NULL, 0);
+ hb_shape(hbFont, buffer, features.empty() ? NULL : &features[0], features.size());
unsigned int numGlyphs;
hb_glyph_info_t* info = hb_buffer_get_glyph_infos(buffer, &numGlyphs);
hb_glyph_position_t* positions = hb_buffer_get_glyph_positions(buffer, NULL);