Commit 4976429e authored by xji@chromium.org's avatar xji@chromium.org

If script text is in right-to-left directionality, it got truncated because...

If script text is in right-to-left directionality, it got truncated because the width calculated in SizeStringInt() and DrawStringInt() are different since they are passed in different flags. DrawStringInt() was passed in an extra flag DT_RTLREADING through FORCE_RTL_DIRECTIONALITY.

Fix by passing in the same flag for size calculation and drawing.

BUG=104117
TEST=manual. JS alert a text begins with Hebrew letter followed by a punctuation, such as "A?". It should not be truncated.

Review URL: http://codereview.chromium.org/9569025

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124736 0039d316-1c4b-4281-b951-d872f2087c98
parent 27d6e85b
......@@ -215,7 +215,7 @@ int Label::GetHeightForWidth(int w) {
w = std::max(0, w - GetInsets().width());
int h = font_.GetHeight();
gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h,
ComputeMultiLineFlags());
ComputeDrawStringFlags());
return h + GetInsets().height();
}
......@@ -290,7 +290,7 @@ gfx::Size Label::GetTextSize() const {
int h = font_.GetHeight();
// For single-line strings, ignore the available width and calculate how
// wide the text wants to be.
int flags = ComputeMultiLineFlags();
int flags = ComputeDrawStringFlags();
if (!is_multi_line_)
flags |= gfx::Canvas::NO_ELLIPSIS;
gfx::CanvasSkia::SizeStringInt(text_, font_, &w, &h, flags);
......@@ -426,11 +426,22 @@ gfx::Rect Label::GetTextBounds() const {
return gfx::Rect(text_origin, text_size);
}
int Label::ComputeMultiLineFlags() const {
int Label::ComputeDrawStringFlags() const {
int flags = 0;
if (directionality_mode_ == AUTO_DETECT_DIRECTIONALITY) {
base::i18n::TextDirection direction =
base::i18n::GetFirstStrongCharacterDirection(GetText());
if (direction == base::i18n::RIGHT_TO_LEFT)
flags |= gfx::Canvas::FORCE_RTL_DIRECTIONALITY;
else
flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY;
}
if (!is_multi_line_)
return 0;
return flags;
int flags = gfx::Canvas::MULTI_LINE;
flags |= gfx::Canvas::MULTI_LINE;
#if !defined(OS_WIN)
// Don't elide multiline labels on Linux.
// Todo(davemoore): Do we depend on eliding multiline text?
......@@ -452,6 +463,7 @@ int Label::ComputeMultiLineFlags() const {
flags |= gfx::Canvas::TEXT_ALIGN_RIGHT;
break;
}
return flags;
}
......@@ -492,16 +504,7 @@ void Label::CalculateDrawStringParams(string16* paint_text,
}
*text_bounds = GetTextBounds();
*flags = ComputeMultiLineFlags();
if (directionality_mode_ == AUTO_DETECT_DIRECTIONALITY) {
base::i18n::TextDirection direction =
base::i18n::GetFirstStrongCharacterDirection(GetText());
if (direction == base::i18n::RIGHT_TO_LEFT)
*flags |= gfx::Canvas::FORCE_RTL_DIRECTIONALITY;
else
*flags |= gfx::Canvas::FORCE_LTR_DIRECTIONALITY;
}
*flags = ComputeDrawStringFlags();
}
} // namespace views
......@@ -237,7 +237,7 @@ class VIEWS_EXPORT Label : public View {
// Returns where the text is drawn, in the receivers coordinate system.
gfx::Rect GetTextBounds() const;
int ComputeMultiLineFlags() const;
int ComputeDrawStringFlags() const;
gfx::Rect GetAvailableRect() const;
......
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