Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(274)

Unified Diff: ui/gfx/render_text.cc

Issue 660953002: Type conversion fixes, text rendering edition. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/canvas_skia.cc ('k') | ui/gfx/render_text_harfbuzz.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/render_text.cc
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index 8c516c10b54503745e969bab90a2e7e1b24b058b..8acb060ac2922bde4ef08a2595b664400528f5e9 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -18,6 +18,7 @@
#include "third_party/skia/include/core/SkTypeface.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "ui/gfx/canvas.h"
+#include "ui/gfx/geometry/safe_integer_conversions.h"
#include "ui/gfx/insets.h"
#include "ui/gfx/render_text_harfbuzz.h"
#include "ui/gfx/scoped_canvas.h"
@@ -269,8 +270,10 @@ void SkiaTextRenderer::EndDiagonalStrike() {
}
void SkiaTextRenderer::DrawUnderline(int x, int y, int width) {
- SkRect r = SkRect::MakeLTRB(x, y + underline_position_, x + width,
- y + underline_position_ + underline_thickness_);
+ SkScalar x_scalar = SkIntToScalar(x);
+ SkRect r = SkRect::MakeLTRB(
+ x_scalar, y + underline_position_, x_scalar + width,
+ y + underline_position_ + underline_thickness_);
if (underline_thickness_ == kUnderlineMetricsNotSet) {
const SkScalar text_size = paint_.getTextSize();
r.fTop = SkScalarMulAdd(text_size, kUnderlineOffset, y);
@@ -283,7 +286,9 @@ void SkiaTextRenderer::DrawStrike(int x, int y, int width) const {
const SkScalar text_size = paint_.getTextSize();
const SkScalar height = SkScalarMul(text_size, kLineThickness);
const SkScalar offset = SkScalarMulAdd(text_size, kStrikeThroughOffset, y);
- const SkRect r = SkRect::MakeLTRB(x, offset, x + width, offset + height);
+ SkScalar x_scalar = SkIntToScalar(x);
+ const SkRect r =
+ SkRect::MakeLTRB(x_scalar, offset, x_scalar + width, offset + height);
canvas_skia_->drawRect(r, paint_);
}
@@ -314,7 +319,7 @@ void SkiaTextRenderer::DiagonalStrike::Draw() {
const int clip_height = height + 2 * thickness;
paint_.setAntiAlias(true);
- paint_.setStrokeWidth(thickness);
+ paint_.setStrokeWidth(SkIntToScalar(thickness));
const bool clipped = pieces_.size() > 1;
SkCanvas* sk_canvas = canvas_->sk_canvas();
@@ -720,8 +725,7 @@ VisualCursorDirection RenderText::GetVisualDirectionOfLogicalEnd() {
}
SizeF RenderText::GetStringSizeF() {
- const Size size = GetStringSize();
- return SizeF(size.width(), size.height());
+ return GetStringSize();
}
float RenderText::GetContentWidth() {
@@ -857,7 +861,8 @@ const Vector2d& RenderText::GetUpdatedDisplayOffset() {
}
void RenderText::SetDisplayOffset(int horizontal_offset) {
- const int extra_content = GetContentWidth() - display_rect_.width();
+ const int extra_content =
+ ToFlooredInt(GetContentWidth()) - display_rect_.width();
const int cursor_width = cursor_enabled_ ? 1 : 0;
int min_offset = 0;
@@ -1210,8 +1215,9 @@ void RenderText::UpdateLayoutText() {
static_cast<int>(GetContentWidth()) > display_rect_.width()) {
// This doesn't trim styles so ellipsis may get rendered as a different
// style than the preceding text. See crbug.com/327850.
- layout_text_.assign(
- Elide(layout_text_, display_rect_.width(), elide_behavior_));
+ layout_text_.assign(Elide(layout_text_,
+ static_cast<float>(display_rect_.width()),
+ elide_behavior_));
}
// Replace the newline character with a newline symbol in single line mode.
« no previous file with comments | « ui/gfx/canvas_skia.cc ('k') | ui/gfx/render_text_harfbuzz.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698