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 22835002: Supports gfx::FontList in gfx::Canvas and ui::ElideText family. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updates based on review comments. Created 7 years, 4 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 2b0f5046cf0ced0cccf96b9274e1b8965af1e667..db0d6f788a1314c9c30fbe525fba1e02b5e04f8b 100644
--- a/ui/gfx/canvas.cc
+++ b/ui/gfx/canvas.cc
@@ -11,7 +11,7 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "ui/gfx/canvas.h"
-#include "ui/gfx/font.h"
+#include "ui/gfx/font_list.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size_conversions.h"
#include "ui/gfx/skia_util.h"
@@ -87,9 +87,27 @@ void Canvas::RecreateBackingCanvas(const gfx::Size& size,
}
// static
+void Canvas::SizeStringInt(const base::string16& text,
+ const gfx::Font& font,
+ int* width,
+ int* height,
+ int line_height,
+ int flags) {
+ SizeStringInt(text, gfx::FontList(font), width, height, line_height, flags);
+}
+
+// static
+int Canvas::GetStringWidth(const base::string16& text,
+ const gfx::FontList& font_list) {
+ int width = 0, height = 0;
+ SizeStringInt(text, font_list, &width, &height, 0, NO_ELLIPSIS);
+ return width;
+}
+
+// static
int Canvas::GetStringWidth(const base::string16& text, const gfx::Font& font) {
int width = 0, height = 0;
- Canvas::SizeStringInt(text, font, &width, &height, 0, NO_ELLIPSIS);
+ SizeStringInt(text, gfx::FontList(font), &width, &height, 0, NO_ELLIPSIS);
return width;
}
@@ -98,6 +116,19 @@ int Canvas::DefaultCanvasTextAlignment() {
return base::i18n::IsRTL() ? TEXT_ALIGN_RIGHT : TEXT_ALIGN_LEFT;
}
+void Canvas::DrawStringWithHalo(const base::string16& text,
+ const gfx::Font& font,
+ SkColor text_color,
+ SkColor halo_color_in,
+ int x,
+ int y,
+ int w,
+ int h,
+ int flags) {
+ DrawStringWithHalo(text, gfx::FontList(font), text_color, halo_color_in,
+ gfx::Rect(x, y, w, h), flags);
+}
+
gfx::ImageSkiaRep Canvas::ExtractImageRep() const {
const SkBitmap& device_bitmap = canvas_->getDevice()->accessBitmap(false);
@@ -297,7 +328,8 @@ void Canvas::DrawImageInt(const gfx::ImageSkia& image, int x, int y, uint8 a) {
}
void Canvas::DrawImageInt(const gfx::ImageSkia& image,
- int x, int y,
+ int x,
+ int y,
const SkPaint& paint) {
const gfx::ImageSkiaRep& image_rep = GetImageRepToPaint(image);
if (image_rep.is_null())
@@ -316,8 +348,14 @@ void Canvas::DrawImageInt(const gfx::ImageSkia& image,
}
void Canvas::DrawImageInt(const gfx::ImageSkia& image,
- int src_x, int src_y, int src_w, int src_h,
- int dest_x, int dest_y, int dest_w, int dest_h,
+ int src_x,
+ int src_y,
+ int src_w,
+ int src_h,
+ int dest_x,
+ int dest_y,
+ int dest_w,
+ int dest_h,
bool filter) {
SkPaint p;
DrawImageInt(image, src_x, src_y, src_w, src_h, dest_x, dest_y,
@@ -325,8 +363,14 @@ void Canvas::DrawImageInt(const gfx::ImageSkia& image,
}
void Canvas::DrawImageInt(const gfx::ImageSkia& image,
- int src_x, int src_y, int src_w, int src_h,
- int dest_x, int dest_y, int dest_w, int dest_h,
+ int src_x,
+ int src_y,
+ int src_w,
+ int src_h,
+ int dest_x,
+ int dest_y,
+ int dest_w,
+ int dest_h,
bool filter,
const SkPaint& paint) {
DLOG_ASSERT(src_x + src_w < std::numeric_limits<int16_t>::max() &&
@@ -409,10 +453,30 @@ void Canvas::DrawImageInPath(const gfx::ImageSkia& image,
canvas_->drawPath(path, p);
}
+void Canvas::DrawString(const base::string16& text,
+ const gfx::FontList& font_list,
+ SkColor color,
+ const gfx::Rect& display_rect) {
+ DrawStringWithFlags(text, font_list, color, display_rect,
+ DefaultCanvasTextAlignment());
+}
+
+void Canvas::DrawStringWithFlags(const base::string16& text,
+ const gfx::FontList& font_list,
+ SkColor color,
+ const gfx::Rect& display_rect,
+ int flags) {
+ DrawStringWithShadows(text, font_list, color, display_rect, 0, flags,
+ ShadowValues());
+}
+
void Canvas::DrawStringInt(const base::string16& text,
const gfx::Font& font,
SkColor color,
- int x, int y, int w, int h) {
+ int x,
+ int y,
+ int w,
+ int h) {
DrawStringInt(text, font, color, x, y, w, h, DefaultCanvasTextAlignment());
}
@@ -427,32 +491,53 @@ void Canvas::DrawStringInt(const base::string16& text,
void Canvas::DrawStringInt(const base::string16& text,
const gfx::Font& font,
SkColor color,
- int x, int y, int w, int h,
+ int x,
+ int y,
+ int w,
+ int h,
int flags) {
- DrawStringWithShadows(text,
- font,
- color,
- gfx::Rect(x, y, w, h),
- 0,
- flags,
+ DrawStringWithShadows(text, font, color, gfx::Rect(x, y, w, h), 0, flags,
ShadowValues());
}
+void Canvas::DrawStringWithShadows(const base::string16& text,
+ const gfx::Font& font,
+ SkColor color,
+ const gfx::Rect& text_bounds,
+ int line_height,
+ int flags,
+ const ShadowValues& shadows) {
+ DrawStringWithShadows(text, gfx::FontList(font), color, text_bounds,
+ line_height, flags, shadows);
+}
+
void Canvas::TileImageInt(const gfx::ImageSkia& image,
- int x, int y, int w, int h) {
+ int x,
+ int y,
+ int w,
+ int h) {
TileImageInt(image, 0, 0, x, y, w, h);
}
void Canvas::TileImageInt(const gfx::ImageSkia& image,
- int src_x, int src_y,
- int dest_x, int dest_y, int w, int h) {
+ int src_x,
+ int src_y,
+ int dest_x,
+ int dest_y,
+ int w,
+ int h) {
TileImageInt(image, src_x, src_y, 1.0f, 1.0f, dest_x, dest_y, w, h);
}
void Canvas::TileImageInt(const gfx::ImageSkia& image,
- int src_x, int src_y,
- float tile_scale_x, float tile_scale_y,
- int dest_x, int dest_y, int w, int h) {
+ int src_x,
+ int src_y,
+ float tile_scale_x,
+ float tile_scale_y,
+ int dest_x,
+ int dest_y,
+ int w,
+ int h) {
if (!IntersectsClipRectInt(dest_x, dest_y, w, h))
return;
@@ -495,6 +580,18 @@ void Canvas::Transform(const gfx::Transform& transform) {
canvas_->concat(transform.matrix());
}
+void Canvas::DrawFadeTruncatingString(
+ const base::string16& text,
+ TruncateFadeMode truncate_mode,
+ size_t desired_characters_to_truncate_from_head,
+ const gfx::Font& font,
+ SkColor color,
+ const gfx::Rect& display_rect) {
+ DrawFadeTruncatingString(text, truncate_mode,
+ desired_characters_to_truncate_from_head,
+ gfx::FontList(font), color, display_rect);
+}
+
Canvas::Canvas(SkCanvas* canvas, ui::ScaleFactor scale_factor)
: scale_factor_(scale_factor),
owned_canvas_(),
« ui/base/text/text_elider.cc ('K') | « ui/gfx/canvas.h ('k') | ui/gfx/canvas_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698