Skip to content

Commit

Permalink
Bug 1097499 part 9 - Transform full-width characters to non-full-widt…
Browse files Browse the repository at this point in the history
…h correspondents for combined text. r=jfkthame

MozReview-Commit-ID: CXntBz9HPJu
  • Loading branch information
upsuper committed Apr 21, 2016
1 parent 110bad0 commit 25ea8f7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
22 changes: 20 additions & 2 deletions layout/generic/nsTextFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1903,7 +1903,10 @@ BuildTextRunsScanner::BuildTextRunForFrames(void* aTextBuffer)
lastStyleContext = f->StyleContext();
// Detect use of text-transform or font-variant anywhere in the run
textStyle = f->StyleText();
if (NS_STYLE_TEXT_TRANSFORM_NONE != textStyle->mTextTransform) {
if (NS_STYLE_TEXT_TRANSFORM_NONE != textStyle->mTextTransform ||
// text-combine-upright requires converting from full-width
// characters to non-full-width correspendent in some cases.
lastStyleContext->IsTextCombined()) {
anyTextTransformStyle = true;
}
if (textStyle->HasTextEmphasis()) {
Expand Down Expand Up @@ -2134,9 +2137,14 @@ BuildTextRunsScanner::BuildTextRunForFrames(void* aTextBuffer)
uint32_t offset = iter.GetSkippedOffset();
iter.AdvanceOriginal(f->GetContentLength());
uint32_t end = iter.GetSkippedOffset();
if (sc != f->StyleContext()) {
// Text-combined frames have content-dependent transform, so we
// want to create new nsTransformedCharStyle for them anyway.
if (sc != f->StyleContext() || sc->IsTextCombined()) {
sc = f->StyleContext();
charStyle = new nsTransformedCharStyle(sc);
if (sc->IsTextCombined() && f->CountGraphemeClusters() > 1) {
charStyle->mForceNonFullWidth = true;
}
}
uint32_t j;
for (j = offset; j < end; ++j) {
Expand Down Expand Up @@ -9541,3 +9549,13 @@ nsTextFrame::GetJustificationAssignment() const
result.mGapsAtEnd = encoded & 0xFF;
return result;
}

uint32_t
nsTextFrame::CountGraphemeClusters() const
{
const nsTextFragment* frag = GetContent()->GetText();
MOZ_ASSERT(frag, "Text frame must have text fragment");
nsAutoString content;
frag->AppendTo(content, GetContentOffset(), GetContentLength());
return unicode::CountGraphemeClusters(content.Data(), content.Length());
}
2 changes: 2 additions & 0 deletions layout/generic/nsTextFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,8 @@ class nsTextFrame : public nsFrame {
void AssignJustificationGaps(const mozilla::JustificationAssignment& aAssign);
mozilla::JustificationAssignment GetJustificationAssignment() const;

uint32_t CountGraphemeClusters() const;

protected:
virtual ~nsTextFrame();

Expand Down
6 changes: 6 additions & 0 deletions layout/generic/nsTextRunTransformations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ nsCaseTransformTextRunFactory::TransformString(
nsIUGenCategory::nsUGenCategory cat;

uint8_t style = aAllUppercase ? NS_STYLE_TEXT_TRANSFORM_UPPERCASE : 0;
bool forceNonFullWidth = false;
const nsIAtom* lang = aLanguage;

LanguageSpecificCasingBehavior languageSpecificCasing = GetCasingFor(lang);
Expand All @@ -314,6 +315,7 @@ nsCaseTransformTextRunFactory::TransformString(
charStyle = aTextRun->mStyles[i];
style = aAllUppercase ? NS_STYLE_TEXT_TRANSFORM_UPPERCASE :
charStyle->mTextTransform;
forceNonFullWidth = charStyle->mForceNonFullWidth;

nsIAtom* newLang = charStyle->mExplicitLanguage
? charStyle->mLanguage : nullptr;
Expand Down Expand Up @@ -560,6 +562,10 @@ nsCaseTransformTextRunFactory::TransformString(
break;
}

if (forceNonFullWidth) {
ch = mozilla::unicode::GetFullWidthInverse(ch);
}

if (ch == uint32_t(-1)) {
aDeletedCharsArray.AppendElement(true);
mergeNeeded = true;
Expand Down
1 change: 1 addition & 0 deletions layout/generic/nsTextRunTransformations.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct nsTransformedCharStyle final {
uint8_t mTextTransform;
uint8_t mMathVariant;
bool mExplicitLanguage;
bool mForceNonFullWidth = false;

private:
~nsTransformedCharStyle() {}
Expand Down

0 comments on commit 25ea8f7

Please sign in to comment.