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

Unified Diff: ui/gfx/canvas.cc

Issue 24883002: Uses and returns the fractional width in text eliding (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix per feedbacks Created 7 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
Index: ui/gfx/canvas.cc
diff --git a/ui/gfx/canvas.cc b/ui/gfx/canvas.cc
index eb0834ba8d9ac7ed0bd166d4d6a1d420f0074b07..1a316e9db7e447546f26e90a36ca9f082ab718c1 100644
--- a/ui/gfx/canvas.cc
+++ b/ui/gfx/canvas.cc
@@ -4,6 +4,7 @@
#include "ui/gfx/canvas.h"
+#include <cmath>
#include <limits>
#include "base/i18n/rtl.h"
@@ -84,6 +85,20 @@ void Canvas::RecreateBackingCanvas(const Size& size,
// static
void Canvas::SizeStringInt(const base::string16& text,
+ const FontList& font_list,
+ int* width,
+ int* height,
+ int line_height,
+ int flags) {
+ float fractional_width = *width, factional_height = *height;
Alexei Svitkine (slow) 2013/10/07 23:33:28 Nit: Separate lines.
jianli 2013/10/08 00:01:18 Done.
+ SizeStringFloat(text, font_list, &fractional_width,
+ &factional_height, line_height, flags);
+ *width = std::ceil(fractional_width);
+ *height = std::ceil(factional_height);
+}
+
+// static
+void Canvas::SizeStringInt(const base::string16& text,
const Font& font,
int* width,
int* height,
@@ -101,6 +116,14 @@ int Canvas::GetStringWidth(const base::string16& text,
}
// static
+float Canvas::GetStringWidthF(const base::string16& text,
+ const FontList& font_list) {
+ float width = 0, height = 0;
+ SizeStringFloat(text, font_list, &width, &height, 0, NO_ELLIPSIS);
+ return width;
+}
+
+// static
int Canvas::GetStringWidth(const base::string16& text, const Font& font) {
int width = 0, height = 0;
SizeStringInt(text, FontList(font), &width, &height, 0, NO_ELLIPSIS);

Powered by Google App Engine
This is Rietveld 408576698