Index: Source/platform/fonts/harfbuzz/HarfBuzzShaper.cpp |
diff --git a/Source/platform/fonts/harfbuzz/HarfBuzzShaper.cpp b/Source/platform/fonts/harfbuzz/HarfBuzzShaper.cpp |
index c6bfb7ffa305822398e76a2257cbc1168df55e66..55443416093302e15ff55c234b142402102a83fd 100644 |
--- a/Source/platform/fonts/harfbuzz/HarfBuzzShaper.cpp |
+++ b/Source/platform/fonts/harfbuzz/HarfBuzzShaper.cpp |
@@ -86,12 +86,13 @@ typedef std::map<std::wstring, CachedShapingResults*> CachedShapingResultsMap; |
typedef std::list<CachedShapingResultsLRUNode*> CachedShapingResultsLRU; |
struct CachedShapingResults { |
- CachedShapingResults(hb_buffer_t* harfBuzzBuffer, const Font* runFont, hb_direction_t runDir); |
+ CachedShapingResults(hb_buffer_t* harfBuzzBuffer, const Font* runFont, hb_direction_t runDir, const String& newLocale); |
~CachedShapingResults(); |
hb_buffer_t* buffer; |
Font font; |
hb_direction_t dir; |
+ String locale; |
CachedShapingResultsLRU::iterator lru; |
}; |
@@ -102,10 +103,11 @@ struct CachedShapingResultsLRUNode { |
CachedShapingResultsMap::iterator entry; |
}; |
-CachedShapingResults::CachedShapingResults(hb_buffer_t* harfBuzzBuffer, const Font* fontData, hb_direction_t dirData) |
+CachedShapingResults::CachedShapingResults(hb_buffer_t* harfBuzzBuffer, const Font* fontData, hb_direction_t dirData, const String& newLocale) |
: buffer(harfBuzzBuffer) |
, font(*fontData) |
, dir(dirData) |
+ , locale(newLocale) |
{ |
} |
@@ -792,6 +794,9 @@ bool HarfBuzzShaper::shapeHarfBuzzRuns() |
HarfBuzzScopedPtr<hb_buffer_t> harfBuzzBuffer(hb_buffer_create(), hb_buffer_destroy); |
HarfBuzzRunCache& runCache = harfBuzzRunCache(); |
+ const FontDescription& fontDescription = m_font->fontDescription(); |
+ const String& localeString = fontDescription.locale(); |
+ CString locale = localeString.latin1(); |
for (unsigned i = 0; i < m_harfBuzzRuns.size(); ++i) { |
unsigned runIndex = m_run.rtl() ? m_harfBuzzRuns.size() - i - 1 : i; |
@@ -805,6 +810,7 @@ bool HarfBuzzShaper::shapeHarfBuzzRuns() |
if (!face) |
return false; |
+ hb_buffer_set_language(harfBuzzBuffer.get(), hb_language_from_string(locale.data(), locale.length())); |
hb_buffer_set_script(harfBuzzBuffer.get(), currentRun->script()); |
hb_buffer_set_direction(harfBuzzBuffer.get(), currentRun->rtl() ? HB_DIRECTION_RTL : HB_DIRECTION_LTR); |
@@ -816,7 +822,7 @@ bool HarfBuzzShaper::shapeHarfBuzzRuns() |
CachedShapingResults* cachedResults = runCache.find(key); |
if (cachedResults) { |
- if (cachedResults->dir == props.direction && cachedResults->font == *m_font) { |
+ if (cachedResults->dir == props.direction && cachedResults->font == *m_font && cachedResults->locale == localeString) { |
currentRun->applyShapeResult(cachedResults->buffer); |
setGlyphPositionsForHarfBuzzRun(currentRun, cachedResults->buffer); |
@@ -835,7 +841,7 @@ bool HarfBuzzShaper::shapeHarfBuzzRuns() |
static const uint16_t preContext = ' '; |
hb_buffer_add_utf16(harfBuzzBuffer.get(), &preContext, 1, 1, 0); |
- if (m_font->fontDescription().variant() && u_islower(m_normalizedBuffer[currentRun->startIndex()])) { |
+ if (fontDescription.variant() && u_islower(m_normalizedBuffer[currentRun->startIndex()])) { |
String upperText = String(m_normalizedBuffer.get() + currentRun->startIndex(), currentRun->numCharacters()).upper(); |
ASSERT(!upperText.is8Bit()); // m_normalizedBuffer is 16 bit, therefore upperText is 16 bit, even after we call makeUpper(). |
hb_buffer_add_utf16(harfBuzzBuffer.get(), toUint16(upperText.characters16()), currentRun->numCharacters(), 0, currentRun->numCharacters()); |
@@ -843,7 +849,7 @@ bool HarfBuzzShaper::shapeHarfBuzzRuns() |
hb_buffer_add_utf16(harfBuzzBuffer.get(), toUint16(m_normalizedBuffer.get() + currentRun->startIndex()), currentRun->numCharacters(), 0, currentRun->numCharacters()); |
} |
- if (m_font->fontDescription().orientation() == Vertical) |
+ if (fontDescription.orientation() == Vertical) |
face->setScriptForVerticalGlyphSubstitution(harfBuzzBuffer.get()); |
HarfBuzzScopedPtr<hb_font_t> harfBuzzFont(face->createFont(), hb_font_destroy); |
@@ -852,7 +858,7 @@ bool HarfBuzzShaper::shapeHarfBuzzRuns() |
currentRun->applyShapeResult(harfBuzzBuffer.get()); |
setGlyphPositionsForHarfBuzzRun(currentRun, harfBuzzBuffer.get()); |
- runCache.insert(key, new CachedShapingResults(harfBuzzBuffer.get(), m_font, props.direction)); |
+ runCache.insert(key, new CachedShapingResults(harfBuzzBuffer.get(), m_font, props.direction, localeString)); |
harfBuzzBuffer.set(hb_buffer_create()); |
} |