Support fontFeatureSettings
Bug: 15246510 Change-Id: I544915d29b2be4fb9f82f1989188a3a918c50fbc
This commit is contained in:
@@ -17,6 +17,8 @@
|
|||||||
#ifndef MINIKIN_FONT_H
|
#ifndef MINIKIN_FONT_H
|
||||||
#define MINIKIN_FONT_H
|
#define MINIKIN_FONT_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <minikin/MinikinRefCounted.h>
|
#include <minikin/MinikinRefCounted.h>
|
||||||
#include <minikin/FontFamily.h>
|
#include <minikin/FontFamily.h>
|
||||||
|
|
||||||
@@ -28,10 +30,15 @@ namespace android {
|
|||||||
class MinikinFont;
|
class MinikinFont;
|
||||||
|
|
||||||
// Possibly move into own .h file?
|
// Possibly move into own .h file?
|
||||||
// Note: if you add a field here, also update LayoutCacheKey
|
// Note: if you add a field here, either add it to LayoutCacheKey or to skipCache()
|
||||||
struct MinikinPaint {
|
struct MinikinPaint {
|
||||||
MinikinPaint() : font(0), size(0), scaleX(0), skewX(0), letterSpacing(0), paintFlags(0),
|
MinikinPaint() : font(0), size(0), scaleX(0), skewX(0), letterSpacing(0), paintFlags(0),
|
||||||
fakery() { }
|
fakery(), fontFeatureSettings() { }
|
||||||
|
|
||||||
|
bool skipCache() const {
|
||||||
|
return !fontFeatureSettings.empty();
|
||||||
|
}
|
||||||
|
|
||||||
MinikinFont *font;
|
MinikinFont *font;
|
||||||
float size;
|
float size;
|
||||||
float scaleX;
|
float scaleX;
|
||||||
@@ -39,6 +46,7 @@ struct MinikinPaint {
|
|||||||
float letterSpacing;
|
float letterSpacing;
|
||||||
uint32_t paintFlags;
|
uint32_t paintFlags;
|
||||||
FontFakery fakery;
|
FontFakery fakery;
|
||||||
|
std::string fontFeatureSettings;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MinikinRect {
|
struct MinikinRect {
|
||||||
|
|||||||
@@ -578,7 +578,8 @@ void Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_
|
|||||||
bool isRtl, LayoutContext* ctx, size_t bufStart) {
|
bool isRtl, LayoutContext* ctx, size_t bufStart) {
|
||||||
LayoutCache& cache = LayoutEngine::getInstance().layoutCache;
|
LayoutCache& cache = LayoutEngine::getInstance().layoutCache;
|
||||||
LayoutCacheKey key(mCollection, ctx->paint, ctx->style, buf, start, count, bufSize, isRtl);
|
LayoutCacheKey key(mCollection, ctx->paint, ctx->style, buf, start, count, bufSize, isRtl);
|
||||||
Layout* value = cache.mCache.get(key);
|
bool skipCache = ctx->paint.skipCache();
|
||||||
|
Layout* value = skipCache ? NULL : cache.mCache.get(key);
|
||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
value = new Layout();
|
value = new Layout();
|
||||||
value->setFontCollection(mCollection);
|
value->setFontCollection(mCollection);
|
||||||
@@ -589,19 +590,29 @@ void Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_
|
|||||||
value->doLayoutRun(key.textBuf(), start, count, bufSize, isRtl, ctx);
|
value->doLayoutRun(key.textBuf(), start, count, bufSize, isRtl, ctx);
|
||||||
}
|
}
|
||||||
appendLayout(value, bufStart);
|
appendLayout(value, bufStart);
|
||||||
cache.mCache.put(key, value);
|
if (!skipCache)
|
||||||
|
cache.mCache.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addFeatures(vector<hb_feature_t>* features) {
|
static void addFeatures(const string &str, vector<hb_feature_t>* features) {
|
||||||
// hardcoded features, to be repaced with more flexible configuration
|
if (!str.size())
|
||||||
static hb_feature_t palt = { HB_TAG('p', 'a', 'l', 't'), 1, 0, ~0u };
|
return;
|
||||||
|
|
||||||
// Don't enable "palt" for now, pending implementation of more of the
|
const char* start = str.c_str();
|
||||||
// W3C Japanese layout recommendations. See:
|
const char* end = start + str.size();
|
||||||
// http://www.w3.org/TR/2012/NOTE-jlreq-20120403/
|
|
||||||
#if 0
|
while (start < end) {
|
||||||
features->push_back(palt);
|
static hb_feature_t feature;
|
||||||
#endif
|
const char* p = strchr(start, ',');
|
||||||
|
if (!p)
|
||||||
|
p = end;
|
||||||
|
/* We do not allow setting features on ranges. As such, reject any
|
||||||
|
* setting that has non-universal range. */
|
||||||
|
if (hb_feature_from_string (start, p - start, &feature)
|
||||||
|
&& feature.start == 0 && feature.end == (unsigned int) -1)
|
||||||
|
features->push_back(feature);
|
||||||
|
start = p + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize,
|
void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize,
|
||||||
@@ -626,7 +637,7 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t
|
|||||||
features.push_back(no_liga);
|
features.push_back(no_liga);
|
||||||
features.push_back(no_clig);
|
features.push_back(no_clig);
|
||||||
}
|
}
|
||||||
addFeatures(&features);
|
addFeatures(ctx->paint.fontFeatureSettings, &features);
|
||||||
|
|
||||||
double size = ctx->paint.size;
|
double size = ctx->paint.size;
|
||||||
double scaleX = ctx->paint.scaleX;
|
double scaleX = ctx->paint.scaleX;
|
||||||
|
|||||||
Reference in New Issue
Block a user