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

Side by Side Diff: ui/gfx/canvas.h

Issue 22835002: Supports gfx::FontList in gfx::Canvas and ui::ElideText family. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_GFX_CANVAS_H_ 5 #ifndef UI_GFX_CANVAS_H_
6 #define UI_GFX_CANVAS_H_ 6 #define UI_GFX_CANVAS_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "skia/ext/platform_canvas.h" 13 #include "skia/ext/platform_canvas.h"
14 #include "skia/ext/refptr.h" 14 #include "skia/ext/refptr.h"
15 #include "ui/gfx/image/image_skia.h" 15 #include "ui/gfx/image/image_skia.h"
16 #include "ui/gfx/native_widget_types.h" 16 #include "ui/gfx/native_widget_types.h"
17 #include "ui/gfx/shadow_value.h" 17 #include "ui/gfx/shadow_value.h"
18 18
19 namespace gfx { 19 namespace gfx {
20 20
21 class Rect; 21 class Rect;
22 class Font; 22 class Font;
23 class FontList;
23 class Point; 24 class Point;
24 class Size; 25 class Size;
25 class Transform; 26 class Transform;
26 27
27 // Canvas is a SkCanvas wrapper that provides a number of methods for 28 // Canvas is a SkCanvas wrapper that provides a number of methods for
28 // common operations used throughout an application built using ui/gfx. 29 // common operations used throughout an application built using ui/gfx.
29 // 30 //
30 // All methods that take integer arguments (as is used throughout views) 31 // All methods that take integer arguments (as is used throughout views)
31 // end with Int. If you need to use methods provided by SkCanvas, you'll 32 // end with Int. If you need to use methods provided by SkCanvas, you'll
32 // need to do a conversion. In particular you'll need to use |SkIntToScalar()|, 33 // need to do a conversion. In particular you'll need to use |SkIntToScalar()|,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // Recreates the backing platform canvas with DIP |size| and |scale_factor|. 115 // Recreates the backing platform canvas with DIP |size| and |scale_factor|.
115 // If the canvas is not opaque, it is explicitly cleared. 116 // If the canvas is not opaque, it is explicitly cleared.
116 // This method is public so that canvas_skia_paint can recreate the platform 117 // This method is public so that canvas_skia_paint can recreate the platform
117 // canvas after having initialized the canvas. 118 // canvas after having initialized the canvas.
118 // TODO(pkotwicz): Push the scale factor into skia::PlatformCanvas such that 119 // TODO(pkotwicz): Push the scale factor into skia::PlatformCanvas such that
119 // this method can be private. 120 // this method can be private.
120 void RecreateBackingCanvas(const gfx::Size& size, 121 void RecreateBackingCanvas(const gfx::Size& size,
121 ui::ScaleFactor scale_factor, 122 ui::ScaleFactor scale_factor,
122 bool is_opaque); 123 bool is_opaque);
123 124
124 // Compute the size required to draw some text with the provided font. 125 // Compute the size required to draw some text with the provided fonts.
125 // Attempts to fit the text with the provided width and height. Increases 126 // Attempts to fit the text with the provided width and height. Increases
126 // height and then width as needed to make the text fit. This method 127 // height and then width as needed to make the text fit. This method
127 // supports multiple lines. On Skia only a line_height can be specified and 128 // supports multiple lines. On Skia only a line_height can be specified and
128 // specifying a 0 value for it will cause the default height to be used. 129 // specifying a 0 value for it will cause the default height to be used.
129 static void SizeStringInt(const base::string16& text, 130 static void SizeStringInt(const base::string16& text,
131 const gfx::FontList& font_list,
132 int* width, int* height,
Alexei Svitkine (slow) 2013/08/12 18:16:21 Nit: can you fix this to be 1 param per line, per
Yuki 2013/08/13 09:32:13 Done.
133 int line_height,
134 int flags);
135 // Obsolete version. Use the above version which takes gfx::FontList.
136 static void SizeStringInt(const base::string16& text,
130 const gfx::Font& font, 137 const gfx::Font& font,
131 int* width, int* height, 138 int* width, int* height,
132 int line_height, 139 int line_height,
133 int flags); 140 int flags);
134 141
135 // Returns the number of horizontal pixels needed to display the specified 142 // Returns the number of horizontal pixels needed to display the specified
136 // |text| with |font|. 143 // |text| with |font_list|.
144 static int GetStringWidth(const base::string16& text,
145 const gfx::FontList& font_list);
146 // Obsolete version. Use the above version which takes gfx::FontList.
137 static int GetStringWidth(const base::string16& text, const gfx::Font& font); 147 static int GetStringWidth(const base::string16& text, const gfx::Font& font);
138 148
139 // Returns the default text alignment to be used when drawing text on a 149 // Returns the default text alignment to be used when drawing text on a
140 // gfx::Canvas based on the directionality of the system locale language. 150 // gfx::Canvas based on the directionality of the system locale language.
141 // This function is used by gfx::Canvas::DrawStringInt when the text alignment 151 // This function is used by gfx::Canvas::DrawStringInt when the text alignment
142 // is not specified. 152 // is not specified.
143 // 153 //
144 // This function returns either gfx::Canvas::TEXT_ALIGN_LEFT or 154 // This function returns either gfx::Canvas::TEXT_ALIGN_LEFT or
145 // gfx::Canvas::TEXT_ALIGN_RIGHT. 155 // gfx::Canvas::TEXT_ALIGN_RIGHT.
146 static int DefaultCanvasTextAlignment(); 156 static int DefaultCanvasTextAlignment();
147 157
148 // Draws text with a 1-pixel halo around it of the given color. 158 // Draws text with a 1-pixel halo around it of the given color.
149 // On Windows, it allows ClearType to be drawn to an otherwise transparenct 159 // On Windows, it allows ClearType to be drawn to an otherwise transparent
150 // bitmap for drag images. Drag images have only 1-bit of transparency, so 160 // bitmap for drag images. Drag images have only 1-bit of transparency, so
151 // we don't do any fancy blurring. 161 // we don't do any fancy blurring.
152 // On Linux, text with halo is created by stroking it with 2px |halo_color| 162 // On Linux, text with halo is created by stroking it with 2px |halo_color|
153 // then filling it with |text_color|. 163 // then filling it with |text_color|.
154 // On Mac, NOTIMPLEMENTED. 164 // On Mac, NOTIMPLEMENTED.
155 // TODO(dhollowa): Skia-native implementation is underway. Cut over to 165 // TODO(dhollowa): Skia-native implementation is underway. Cut over to
156 // that when ready. http::/crbug.com/109946 166 // that when ready. http::/crbug.com/109946
157 void DrawStringWithHalo(const base::string16& text, 167 void DrawStringWithHalo(const base::string16& text,
168 const gfx::FontList& font_list,
169 SkColor text_color,
170 SkColor halo_color,
171 const Rect& display_rect,
172 int flags);
173 // Obsolete version. Use the above version which takes gfx::FontList.
174 void DrawStringWithHalo(const base::string16& text,
158 const gfx::Font& font, 175 const gfx::Font& font,
159 SkColor text_color, 176 SkColor text_color,
160 SkColor halo_color, 177 SkColor halo_color,
161 int x, int y, int w, int h, 178 int x, int y, int w, int h,
162 int flags); 179 int flags);
163 180
164 // Extracts an ImageSkiaRep from the contents of this canvas. 181 // Extracts an ImageSkiaRep from the contents of this canvas.
165 gfx::ImageSkiaRep ExtractImageRep() const; 182 gfx::ImageSkiaRep ExtractImageRep() const;
166 183
167 // Draws a dashed rectangle of the specified color. 184 // Draws a dashed rectangle of the specified color.
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // Draws an |image| with the top left corner at |x| and |y|, clipped to 312 // Draws an |image| with the top left corner at |x| and |y|, clipped to
296 // |path|. 313 // |path|.
297 // Parameters are specified relative to current canvas scale not in pixels. 314 // Parameters are specified relative to current canvas scale not in pixels.
298 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1. 315 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1.
299 void DrawImageInPath(const gfx::ImageSkia& image, 316 void DrawImageInPath(const gfx::ImageSkia& image,
300 int x, 317 int x,
301 int y, 318 int y,
302 const SkPath& path, 319 const SkPath& path,
303 const SkPaint& paint); 320 const SkPaint& paint);
304 321
305 // Draws text with the specified color, font and location. The text is 322 // Draws text with the specified color, fonts and location. The text is
306 // aligned to the left, vertically centered, clipped to the region. If the 323 // aligned to the left, vertically centered, clipped to the region. If the
307 // text is too big, it is truncated and '...' is added to the end. 324 // text is too big, it is truncated and '...' is added to the end.
325 void DrawString(const base::string16& text,
326 const gfx::FontList& font_list,
327 SkColor color,
328 const gfx::Rect& display_rect);
329 // Obsolete versions. Use the above versions which take gfx::FontList.
308 void DrawStringInt(const base::string16& text, 330 void DrawStringInt(const base::string16& text,
309 const gfx::Font& font, 331 const gfx::Font& font,
310 SkColor color, 332 SkColor color,
311 int x, int y, int w, int h); 333 int x, int y, int w, int h);
312 void DrawStringInt(const base::string16& text, 334 void DrawStringInt(const base::string16& text,
313 const gfx::Font& font, 335 const gfx::Font& font,
314 SkColor color, 336 SkColor color,
315 const gfx::Rect& display_rect); 337 const gfx::Rect& display_rect);
316 338
317 // Draws text with the specified color, font and location. The last argument 339 // Draws text with the specified color, fonts and location. The last argument
318 // specifies flags for how the text should be rendered. It can be one of 340 // specifies flags for how the text should be rendered. It can be one of
319 // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT. 341 // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT.
342 void DrawStringWithAligned(const base::string16& text,
Alexei Svitkine (slow) 2013/08/12 18:16:21 Flags can specify more than just alignment. How ab
Yuki 2013/08/13 09:32:13 Done.
343 const gfx::FontList& font_list,
344 SkColor color,
345 const gfx::Rect& display_rect,
346 int flags);
347 // Obsolete version. Use the above version which takes gfx::FontList.
320 void DrawStringInt(const base::string16& text, 348 void DrawStringInt(const base::string16& text,
321 const gfx::Font& font, 349 const gfx::Font& font,
322 SkColor color, 350 SkColor color,
323 int x, int y, int w, int h, 351 int x, int y, int w, int h,
324 int flags); 352 int flags);
325 353
326 // Similar to above DrawStringInt method but with text shadows support. 354 // Similar to above DrawStringInt method but with text shadows support.
327 // Currently it's only implemented for canvas skia. Specifying a 0 line_height 355 // Currently it's only implemented for canvas skia. Specifying a 0 line_height
328 // will cause the default height to be used. 356 // will cause the default height to be used.
329 void DrawStringWithShadows(const base::string16& text, 357 void DrawStringWithShadows(const base::string16& text,
358 const gfx::FontList& font_list,
359 SkColor color,
360 const gfx::Rect& text_bounds,
361 int line_height,
362 int flags,
363 const ShadowValues& shadows);
364 // Obsolete version. Use the above version which takes gfx::FontList.
365 void DrawStringWithShadows(const base::string16& text,
330 const gfx::Font& font, 366 const gfx::Font& font,
331 SkColor color, 367 SkColor color,
332 const gfx::Rect& text_bounds, 368 const gfx::Rect& text_bounds,
333 int line_height, 369 int line_height,
334 int flags, 370 int flags,
335 const ShadowValues& shadows); 371 const ShadowValues& shadows);
336 372
337 // Draws a dotted gray rectangle used for focus purposes. 373 // Draws a dotted gray rectangle used for focus purposes.
338 void DrawFocusRect(const gfx::Rect& rect); 374 void DrawFocusRect(const gfx::Rect& rect);
339 375
(...skipping 22 matching lines...) Expand all
362 void Transform(const gfx::Transform& transform); 398 void Transform(const gfx::Transform& transform);
363 399
364 // Draws the given string with the beginning and/or the end using a fade 400 // Draws the given string with the beginning and/or the end using a fade
365 // gradient. When truncating the head 401 // gradient. When truncating the head
366 // |desired_characters_to_truncate_from_head| specifies the maximum number of 402 // |desired_characters_to_truncate_from_head| specifies the maximum number of
367 // characters that can be truncated. 403 // characters that can be truncated.
368 void DrawFadeTruncatingString( 404 void DrawFadeTruncatingString(
369 const base::string16& text, 405 const base::string16& text,
370 TruncateFadeMode truncate_mode, 406 TruncateFadeMode truncate_mode,
371 size_t desired_characters_to_truncate_from_head, 407 size_t desired_characters_to_truncate_from_head,
408 const gfx::FontList& font_list,
409 SkColor color,
410 const gfx::Rect& display_rect);
411 // Obsolete version. Use the above version which takes gfx::FontList.
412 void DrawFadeTruncatingString(
413 const base::string16& text,
414 TruncateFadeMode truncate_mode,
415 size_t desired_characters_to_truncate_from_head,
372 const gfx::Font& font, 416 const gfx::Font& font,
373 SkColor color, 417 SkColor color,
374 const gfx::Rect& display_rect); 418 const gfx::Rect& display_rect);
375 419
376 skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); } 420 skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); }
377 SkCanvas* sk_canvas() const { return canvas_; } 421 SkCanvas* sk_canvas() const { return canvas_; }
378 ui::ScaleFactor scale_factor() const { return scale_factor_; } 422 ui::ScaleFactor scale_factor() const { return scale_factor_; }
379 423
380 private: 424 private:
381 Canvas(SkCanvas* canvas, ui::ScaleFactor scale_factor); 425 Canvas(SkCanvas* canvas, ui::ScaleFactor scale_factor);
(...skipping 21 matching lines...) Expand all
403 447
404 skia::RefPtr<skia::PlatformCanvas> owned_canvas_; 448 skia::RefPtr<skia::PlatformCanvas> owned_canvas_;
405 SkCanvas* canvas_; 449 SkCanvas* canvas_;
406 450
407 DISALLOW_COPY_AND_ASSIGN(Canvas); 451 DISALLOW_COPY_AND_ASSIGN(Canvas);
408 }; 452 };
409 453
410 } // namespace gfx 454 } // namespace gfx
411 455
412 #endif // UI_GFX_CANVAS_H_ 456 #endif // UI_GFX_CANVAS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698