From 1b42eb60f128db705cec29af7f8e49d28669e0c0 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Wed, 24 Jun 2015 09:35:04 +0900 Subject: [PATCH] Bug 1175789 Draw underline as overline when it's in vertical writing mode and the language is Japanese or Korean r=dbaron --- layout/generic/nsTextFrame.cpp | 38 ++++++-- .../1175789-underline-overline-1-ref.html | 91 +++++++++++++++++++ .../1175789-underline-overline-1.html | 91 +++++++++++++++++++ layout/reftests/writing-mode/reftest.list | 1 + 4 files changed, 215 insertions(+), 6 deletions(-) create mode 100644 layout/reftests/writing-mode/1175789-underline-overline-1-ref.html create mode 100644 layout/reftests/writing-mode/1175789-underline-overline-1.html diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index 09e78688a255..cfbe500dc05e 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -4805,6 +4805,18 @@ LazyGetLineBaselineOffset(nsIFrame* aChildFrame, nsBlockFrame* aBlockFrame) } } +static bool IsUnderlineRight(nsIFrame* aFrame) +{ + nsIAtom* langAtom = aFrame->StyleFont()->mLanguage; + if (!langAtom) { + return false; + } + nsAtomString langStr(langAtom); + return (StringBeginsWith(langStr, NS_LITERAL_STRING("ja")) || + StringBeginsWith(langStr, NS_LITERAL_STRING("ko"))) && + (langStr.Length() == 2 || langStr[2] == '-'); +} + void nsTextFrame::GetTextDecorations( nsPresContext* aPresContext, @@ -4903,11 +4915,19 @@ nsTextFrame::GetTextDecorations( color = nsLayoutUtils::GetColor(f, eCSSProperty_text_decoration_color); } - if (textDecorations & NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE) { + bool swapUnderlineAndOverline = vertical && IsUnderlineRight(f); + const uint8_t kUnderline = + swapUnderlineAndOverline ? NS_STYLE_TEXT_DECORATION_LINE_OVERLINE : + NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE; + const uint8_t kOverline = + swapUnderlineAndOverline ? NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE : + NS_STYLE_TEXT_DECORATION_LINE_OVERLINE; + + if (textDecorations & kUnderline) { aDecorations.mUnderlines.AppendElement( nsTextFrame::LineDecoration(f, baselineOffset, color, style)); } - if (textDecorations & NS_STYLE_TEXT_DECORATION_LINE_OVERLINE) { + if (textDecorations & kOverline) { aDecorations.mOverlines.AppendElement( nsTextFrame::LineDecoration(f, baselineOffset, color, style)); } @@ -5261,7 +5281,7 @@ static void DrawSelectionDecorations(gfxContext* aContext, const gfxPoint& aPt, gfxFloat aICoordInFrame, gfxFloat aWidth, gfxFloat aAscent, const gfxFont::Metrics& aFontMetrics, nsTextFrame::DrawPathCallbacks* aCallbacks, - bool aVertical) + bool aVertical, uint8_t aDecoration) { gfxPoint pt(aPt); gfxSize size(aWidth, @@ -5339,8 +5359,10 @@ static void DrawSelectionDecorations(gfxContext* aContext, size.height *= relativeSize; PaintDecorationLine(aFrame, aContext, aDirtyRect, color, nullptr, pt, (aVertical ? (pt.y - aPt.y) : (pt.x - aPt.x)) + aICoordInFrame, - size, aAscent, aFontMetrics.underlineOffset, - NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE, style, eSelectionDecoration, + size, aAscent, + aDecoration == NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE ? + aFontMetrics.underlineOffset : aFontMetrics.maxAscent, + aDecoration, style, eSelectionDecoration, aCallbacks, aVertical, descentLimit); } @@ -5805,6 +5827,10 @@ nsTextFrame::PaintTextSelectionDecorations(gfxContext* aCtx, gfxFont* firstFont = aProvider.GetFontGroup()->GetFirstValidFont(); bool verticalRun = mTextRun->IsVertical(); + bool rightUnderline = verticalRun && IsUnderlineRight(this); + const uint8_t kDecoration = + rightUnderline ? NS_STYLE_TEXT_DECORATION_LINE_OVERLINE : + NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE; bool useVerticalMetrics = verticalRun && mTextRun->UseCenterBaseline(); gfxFont::Metrics decorationMetrics(firstFont->GetMetrics(useVerticalMetrics ? @@ -5851,7 +5877,7 @@ nsTextFrame::PaintTextSelectionDecorations(gfxContext* aCtx, DrawSelectionDecorations(aCtx, dirtyRect, aSelectionType, this, aTextPaintStyle, selectedStyle, pt, xInFrame, width, mAscent / app, decorationMetrics, - aCallbacks, verticalRun); + aCallbacks, verticalRun, kDecoration); } iterator.UpdateWithAdvance(advance); } diff --git a/layout/reftests/writing-mode/1175789-underline-overline-1-ref.html b/layout/reftests/writing-mode/1175789-underline-overline-1-ref.html new file mode 100644 index 000000000000..b788d6bae8a5 --- /dev/null +++ b/layout/reftests/writing-mode/1175789-underline-overline-1-ref.html @@ -0,0 +1,91 @@ + + + + Bug 1175789 - underline and overline in various language + + + +
+
lang="en-US"
+
+
+ underline
+ overline +
+
+ underline
+ overline +
+
+
lang="ja"
+
+
+ underline
+ overline +
+
+ underline
+ overline +
+
+
lang="ko"
+
+
+ underline
+ overline +
+
+ underline
+ overline +
+
+
lang="ja-JP"
+
+
+ underline
+ overline +
+
+ underline
+ overline +
+
+
lang="ko-KR"
+
+
+ underline
+ overline +
+
+ underline
+ overline +
+
+
lang="zh"
+
+
+ underline
+ overline +
+
+ underline
+ overline +
+
+
+ + diff --git a/layout/reftests/writing-mode/1175789-underline-overline-1.html b/layout/reftests/writing-mode/1175789-underline-overline-1.html new file mode 100644 index 000000000000..1044a9dca5ab --- /dev/null +++ b/layout/reftests/writing-mode/1175789-underline-overline-1.html @@ -0,0 +1,91 @@ + + + + Bug 1175789 - underline and overline in various language + + + +
+
lang="en-US"
+
+
+ underline
+ overline +
+
+ underline
+ overline +
+
+
lang="ja"
+
+
+ underline
+ overline +
+
+ underline
+ overline +
+
+
lang="ko"
+
+
+ underline
+ overline +
+
+ underline
+ overline +
+
+
lang="ja-JP"
+
+
+ underline
+ overline +
+
+ underline
+ overline +
+
+
lang="ko-KR"
+
+
+ underline
+ overline +
+
+ underline
+ overline +
+
+
lang="zh"
+
+
+ underline
+ overline +
+
+ underline
+ overline +
+
+
+ + diff --git a/layout/reftests/writing-mode/reftest.list b/layout/reftests/writing-mode/reftest.list index 609ea75ae788..43ae5947b691 100644 --- a/layout/reftests/writing-mode/reftest.list +++ b/layout/reftests/writing-mode/reftest.list @@ -149,6 +149,7 @@ fails == 1147834-relative-overconstrained-vertical-rl-rtl.html 1147834-top-left- == 1172774-percent-padding-3.html 1172774-percent-vertical-ref.html == 1172774-percent-padding-4.html 1172774-percent-vertical-ref.html == 1174450-intrinsic-sizing.html 1174450-intrinsic-sizing-ref.html +== 1175789-underline-overline-1.html 1175789-underline-overline-1-ref.html # Suite of tests from GĂ©rard Talbot in bug 1079151 include abspos/reftest.list