From a5bb91190edbea0be0e78a8511b3c920b6e99c4e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 24 Jul 2014 20:26:03 -0400 Subject: Towards CSS removal Extract language from FontStyle during shaping. Don't attach CSS to LayoutContext. Change-Id: Ie621d3415410178d0d15fa7b810eb8e412342ab6 --- libs/minikin/FontFamily.cpp | 24 +++++++++++++++++++++++- libs/minikin/Layout.cpp | 34 ++++++++++++++++++---------------- 2 files changed, 41 insertions(+), 17 deletions(-) (limited to 'libs/minikin') diff --git a/libs/minikin/FontFamily.cpp b/libs/minikin/FontFamily.cpp index ad8120f..ab6ba20 100644 --- a/libs/minikin/FontFamily.cpp +++ b/libs/minikin/FontFamily.cpp @@ -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)) { diff --git a/libs/minikin/Layout.cpp b/libs/minikin/Layout.cpp index 0715c76..6611f06 100644 --- a/libs/minikin/Layout.cpp +++ b/libs/minikin/Layout.cpp @@ -170,7 +170,6 @@ hash_t LayoutCacheKey::hash() const { struct LayoutContext { MinikinPaint paint; FontStyle style; - CssProperties props; std::vector 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); - - 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; + CssProperties props; + props.parse(css); + + 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); -- cgit v1.2.3