Commit c591f214 authored by h.joshi@samsung.com's avatar h.joshi@samsung.com

Adding Locale (language attribute) information to font and using the

same while shaping Complex text. More than one langauge can point to
single Script and single font can have support for different languages.

BUG=372502

Review URL: https://codereview.chromium.org/276573010

git-svn-id: svn://svn.chromium.org/blink/trunk@175124 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent d93c202b
......@@ -87,7 +87,6 @@ crbug.com/371916 [ Debug ] http/tests/security/contentSecurityPolicy/xsl-allowed
# Pixel tests for RTL iframe scrollbar is erroneous. Cannot observe on actual browser.
crbug.com/338794 crbug.com/192172 compositing/rtl/rtl-iframe-absolute-overflow.html [ Pass Failure ]
crbug.com/338794 compositing/rtl/rtl-iframe-absolute-overflow-scrolled.html [ Pass Failure ]
crbug.com/338794 compositing/rtl/rtl-iframe-fixed-overflow.html [ Pass Failure ]
crbug.com/338794 crbug.com/192172 compositing/rtl/rtl-iframe-fixed-overflow-scrolled.html [ Pass Failure ]
crbug.com/338794 virtual/softwarecompositing/rtl/rtl-iframe-absolute-overflow-scrolled.html [ Pass Failure ]
crbug.com/338794 crbug.com/192172 virtual/softwarecompositing/rtl/rtl-iframe-fixed-overflow.html [ Pass Failure ]
......@@ -5828,3 +5827,10 @@ Bug(eae) [ XP ] virtual/threaded/compositing/visibility/visibility-image-layers-
Bug(eae) [ XP ] virtual/threaded/compositing/visibility/visibility-image-layers.html [ NeedsManualRebaseline ]
Bug(eae) [ Win ] virtual/threaded/transitions/move-after-transition.html [ NeedsManualRebaseline ]
Bug(eae) [ XP ] virtual/threaded/transitions/svg-text-shadow-transition.html [ NeedsManualRebaseline ]
# Following test case needs to be rebased after https://codereview.chromium.org/276573010.
crbug.com/372502 fast/text/shaping/same-script-different-lang.html [ NeedsRebaseline ]
crbug.com/372502 virtual/windows-directwrite/fast/text/shaping/same-script-different-lang.html [ NeedsRebaseline ]
crbug.com/372502 compositing/rtl/rtl-iframe-fixed-overflow.html [ NeedsRebaseline ]
crbug.com/372502 virtual/mac-antialiasedtext/fast/text/shaping/same-script-different-lang.html [ NeedsRebaseline ]
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<title>Language Attribute Test</title>
<style type="text/css">
@font-face {
font-family: NotoX;
src: url("../../../third_party/NotoSans/NotoSansDevanagari-Regular-uni091D.ttf") format("truetype");
}
</style>
</head>
<body>
<h3>The glyph for JHA should look different for Nepali and Hindi, depending on the lang attribute.</h3>
<p lang="hi" style="font-family: NotoX">Hindi:JHA &#x091D; </p><br>
<p lang="ne" style="font-family: NotoX">Nepali:JHA &#x091D; </p><br>
</body>
</html>
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x198
RenderBlock {HTML} at (0,0) size 800x198.44
RenderBody {BODY} at (8,18.72) size 784x171.72
RenderBlock {H3} at (0,0) size 784x23
RenderText {#text} at (0,0) size 764x22
text run at (0,0) width 764: "The glyph for JHA should look different for Nepali and Hindi, depending on the lang attribute."
RenderBlock {P} at (0,41.72) size 784x21
RenderText {#text} at (0,0) size 86x21
text run at (0,0) width 86: "Hindi:JHA \x{91D}"
RenderBlock (anonymous) at (0,78.72) size 784x20
RenderBR {BR} at (0,0) size 0x19
RenderBlock {P} at (0,114.72) size 784x21
RenderText {#text} at (0,0) size 98x21
text run at (0,0) width 98: "Nepali:JHA \x{91D}"
RenderBlock (anonymous) at (0,151.72) size 784x20
RenderBR {BR} at (0,0) size 0x19
......@@ -31,6 +31,7 @@
#include "core/frame/Settings.h"
#include "core/rendering/RenderTheme.h"
#include "core/rendering/RenderView.h"
#include "platform/fonts/FontDescription.h"
#include "platform/text/LocaleToScriptMapping.h"
namespace WebCore {
......@@ -457,6 +458,7 @@ void FontBuilder::setScript(const String& locale)
{
FontDescriptionChangeScope scope(this);
scope.fontDescription().setLocale(locale);
scope.fontDescription().setScript(localeToScriptCodeForFontSelection(locale));
}
......
......@@ -39,6 +39,7 @@ namespace WebCore {
struct SameSizeAsFontDescription {
FontFamily familyList;
RefPtr<FontFeatureSettings> m_featureSettings;
String locale;
float sizes[4];
// FXIME: Make them fit into one word.
uint32_t bitfields;
......
......@@ -54,7 +54,8 @@ public:
enum LigaturesState { NormalLigaturesState, DisabledLigaturesState, EnabledLigaturesState };
FontDescription()
: m_specifiedSize(0)
: m_locale("en")
, m_specifiedSize(0)
, m_computedSize(0)
, m_letterSpacing(0)
, m_wordSpacing(0)
......@@ -111,6 +112,7 @@ public:
FontSmoothingMode fontSmoothing() const { return static_cast<FontSmoothingMode>(m_fontSmoothing); }
TextRenderingMode textRendering() const { return static_cast<TextRenderingMode>(m_textRendering); }
UScriptCode script() const { return static_cast<UScriptCode>(m_script); }
const String& locale() const { return m_locale; }
bool isSyntheticBold() const { return m_syntheticBold; }
bool isSyntheticItalic() const { return m_syntheticItalic; }
bool useSubpixelPositioning() const { return m_subpixelTextPosition; }
......@@ -148,6 +150,7 @@ public:
void setNonCJKGlyphOrientation(NonCJKGlyphOrientation orientation) { m_nonCJKGlyphOrientation = orientation; }
void setWidthVariant(FontWidthVariant widthVariant) { m_widthVariant = widthVariant; }
void setScript(UScriptCode s) { m_script = s; }
void setLocale(const String& locale) { m_locale = locale; }
void setSyntheticBold(bool syntheticBold) { m_syntheticBold = syntheticBold; }
void setSyntheticItalic(bool syntheticItalic) { m_syntheticItalic = syntheticItalic; }
void setFeatureSettings(PassRefPtr<FontFeatureSettings> settings) { m_featureSettings = settings; }
......@@ -166,6 +169,7 @@ public:
private:
FontFamily m_familyList; // The list of font families to be used.
RefPtr<FontFeatureSettings> m_featureSettings;
String m_locale;
void updateTypesettingFeatures() const;
......
......@@ -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());
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment