Towards CSS removal
Extract language from FontStyle during shaping. Don't attach CSS to LayoutContext. Change-Id: Ie621d3415410178d0d15fa7b810eb8e412342ab6
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#define MINIKIN_FONT_FAMILY_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <utils/TypeHelpers.h>
|
||||
|
||||
@@ -39,6 +40,9 @@ public:
|
||||
FontLanguage(const char* buf, size_t size);
|
||||
|
||||
bool operator==(const FontLanguage other) const { return mBits == other.mBits; }
|
||||
operator bool() const { return mBits != 0; }
|
||||
|
||||
std::string getString() const;
|
||||
|
||||
// 0 = no match, 1 = language matches, 2 = language and script match
|
||||
int match(const FontLanguage other) const;
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace android {
|
||||
FontLanguage::FontLanguage(const char* buf, size_t size) {
|
||||
uint32_t bits = 0;
|
||||
size_t i;
|
||||
for (i = 0; i < size && buf[i] != '-' && buf[i] != '_'; i++) {
|
||||
for (i = 0; i < size; i++) {
|
||||
uint16_t c = buf[i];
|
||||
if (c == '-' || c == '_') break;
|
||||
}
|
||||
@@ -60,6 +60,28 @@ FontLanguage::FontLanguage(const char* buf, size_t size) {
|
||||
mBits = bits;
|
||||
}
|
||||
|
||||
std::string FontLanguage::getString() const {
|
||||
char buf[16];
|
||||
size_t i = 0;
|
||||
if (mBits & kBaseLangMask) {
|
||||
buf[i++] = (mBits >> 8) & 0xFFu;
|
||||
buf[i++] = mBits & 0xFFu;
|
||||
}
|
||||
if (mBits & kScriptMask) {
|
||||
if (!i)
|
||||
buf[i++] = 'x';
|
||||
buf[i++] = '-';
|
||||
buf[i++] = 'H';
|
||||
buf[i++] = 'a';
|
||||
buf[i++] = 'n';
|
||||
if (mBits & kHansFlag)
|
||||
buf[i++] = 's';
|
||||
else
|
||||
buf[i++] = 't';
|
||||
}
|
||||
return std::string(buf, i);
|
||||
}
|
||||
|
||||
int FontLanguage::match(const FontLanguage other) const {
|
||||
int result = 0;
|
||||
if ((mBits & kBaseLangMask) == (other.mBits & kBaseLangMask)) {
|
||||
|
||||
@@ -170,7 +170,6 @@ hash_t LayoutCacheKey::hash() const {
|
||||
struct LayoutContext {
|
||||
MinikinPaint paint;
|
||||
FontStyle style;
|
||||
CssProperties props;
|
||||
std::vector<hb_font_t*> hbFonts; // parallel to mFaces
|
||||
};
|
||||
|
||||
@@ -502,19 +501,21 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bu
|
||||
AutoMutex _l(gMinikinLock);
|
||||
LayoutContext ctx;
|
||||
|
||||
ctx.props.parse(css);
|
||||
ctx.style = styleFromCss(ctx.props);
|
||||
CssProperties props;
|
||||
props.parse(css);
|
||||
|
||||
ctx.paint.size = ctx.props.value(fontSize).getDoubleValue();
|
||||
ctx.paint.scaleX = ctx.props.hasTag(fontScaleX)
|
||||
? ctx.props.value(fontScaleX).getDoubleValue() : 1;
|
||||
ctx.paint.skewX = ctx.props.hasTag(fontSkewX)
|
||||
? ctx.props.value(fontSkewX).getDoubleValue() : 0;
|
||||
ctx.paint.letterSpacing = ctx.props.hasTag(letterSpacing)
|
||||
? ctx.props.value(letterSpacing).getDoubleValue() : 0;
|
||||
ctx.paint.paintFlags = ctx.props.hasTag(paintFlags)
|
||||
? ctx.props.value(paintFlags).getUintValue() : 0;
|
||||
int bidiFlags = ctx.props.hasTag(minikinBidi) ? ctx.props.value(minikinBidi).getIntValue() : 0;
|
||||
ctx.style = styleFromCss(props);
|
||||
|
||||
ctx.paint.size = props.value(fontSize).getDoubleValue();
|
||||
ctx.paint.scaleX = props.hasTag(fontScaleX)
|
||||
? props.value(fontScaleX).getDoubleValue() : 1;
|
||||
ctx.paint.skewX = props.hasTag(fontSkewX)
|
||||
? props.value(fontSkewX).getDoubleValue() : 0;
|
||||
ctx.paint.letterSpacing = props.hasTag(letterSpacing)
|
||||
? props.value(letterSpacing).getDoubleValue() : 0;
|
||||
ctx.paint.paintFlags = props.hasTag(paintFlags)
|
||||
? props.value(paintFlags).getUintValue() : 0;
|
||||
int bidiFlags = props.hasTag(minikinBidi) ? props.value(minikinBidi).getIntValue() : 0;
|
||||
bool isRtl = (bidiFlags & kDirection_Mask) != 0;
|
||||
bool doSingleRun = true;
|
||||
|
||||
@@ -697,8 +698,9 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t
|
||||
hb_buffer_reset(buffer);
|
||||
hb_buffer_set_script(buffer, script);
|
||||
hb_buffer_set_direction(buffer, isRtl? HB_DIRECTION_RTL : HB_DIRECTION_LTR);
|
||||
if (ctx->props.hasTag(cssLang)) {
|
||||
string lang = ctx->props.value(cssLang).getStringValue();
|
||||
FontLanguage language = ctx->style.getLanguage();
|
||||
if (language) {
|
||||
string lang = language.getString();
|
||||
hb_buffer_set_language(buffer, hb_language_from_string(lang.c_str(), -1));
|
||||
}
|
||||
hb_buffer_add_utf16(buffer, buf, bufSize, srunstart + start, srunend - srunstart);
|
||||
|
||||
Reference in New Issue
Block a user