Bug 1347819 - change nsFont::languageOverride to store uint32_t directly. r=jfkthame

Since font-language-override can only have a single three-letter tag, and it is
eventually converted to uint32_t while creating gfxFontStyle, we should be able
to move the conversion ahead, to an earlier stage.

In this patch, we move the ParseFontLanguageOverride to nsRuleNode, so we could
do the nsString-to-uint32_t conversion during computing time.

MozReview-Commit-ID: LA4Bv3wV7K
This commit is contained in:
Jeremy Chen
2017-03-23 21:59:55 +08:00
parent 4e5cd24a3d
commit 38e7820d15
8 changed files with 57 additions and 35 deletions

View File

@@ -29,6 +29,7 @@
#include "nsAlgorithm.h" // for clamped()
#include "nscore.h"
#include "nsCRT.h" // for IsAscii()
#include "nsIWidget.h"
#include "nsIPresShell.h"
#include "nsFontMetrics.h"
@@ -4035,11 +4036,13 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
aFont->mFont.languageOverride = aParentFont->mFont.languageOverride;
} else if (eCSSUnit_Normal == languageOverrideValue->GetUnit() ||
eCSSUnit_Initial == languageOverrideValue->GetUnit()) {
aFont->mFont.languageOverride.Truncate();
aFont->mFont.languageOverride = NO_FONT_LANGUAGE_OVERRIDE;
} else if (eCSSUnit_System_Font == languageOverrideValue->GetUnit()) {
aFont->mFont.languageOverride = systemFont.languageOverride;
} else if (eCSSUnit_String == languageOverrideValue->GetUnit()) {
languageOverrideValue->GetStringValue(aFont->mFont.languageOverride);
nsAutoString lang;
languageOverrideValue->GetStringValue(lang);
aFont->mFont.languageOverride = ParseFontLanguageOverride(lang);
}
// -moz-min-font-size-ratio: percent, inherit
@@ -4408,6 +4411,26 @@ nsRuleNode::ComputeFontData(void* aStartStruct,
COMPUTE_END_INHERITED(Font, font)
}
/*static*/ uint32_t
nsRuleNode::ParseFontLanguageOverride(const nsAString& aLangTag)
{
if (!aLangTag.Length() || aLangTag.Length() > 4) {
return NO_FONT_LANGUAGE_OVERRIDE;
}
uint32_t index, result = 0;
for (index = 0; index < aLangTag.Length(); ++index) {
char16_t ch = aLangTag[index];
if (!nsCRT::IsAscii(ch)) { // valid tags are pure ASCII
return NO_FONT_LANGUAGE_OVERRIDE;
}
result = (result << 8) + ch;
}
while (index++ < 4) {
result = (result << 8) + 0x20;
}
return result;
}
template <typename T>
inline uint32_t ListLength(const T* aList)
{