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

Side by Side Diff: ui/gfx/render_text_linux.cc

Issue 8122013: Allow CanvasSkia to bind to an existing SkCanvas. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: 1 more fix Created 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "ui/gfx/render_text_linux.h" 5 #include "ui/gfx/render_text_linux.h"
6 6
7 #include <pango/pangocairo.h> 7 #include <pango/pangocairo.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 int width; 87 int width;
88 pango_layout_get_pixel_size(layout, &width, NULL); 88 pango_layout_get_pixel_size(layout, &width, NULL);
89 return width; 89 return width;
90 } 90 }
91 91
92 void RenderTextLinux::Draw(Canvas* canvas) { 92 void RenderTextLinux::Draw(Canvas* canvas) {
93 PangoLayout* layout = EnsureLayout(); 93 PangoLayout* layout = EnsureLayout();
94 Rect bounds(display_rect()); 94 Rect bounds(display_rect());
95 95
96 // Clip the canvas to the text display area. 96 // Clip the canvas to the text display area.
97 CanvasSkia* canvas_skia = canvas->AsCanvasSkia(); 97 SkCanvas* canvas_skia = canvas->GetSkCanvas();
98 98
99 skia::ScopedPlatformPaint scoped_platform_paint(canvas_skia); 99 skia::ScopedPlatformPaint scoped_platform_paint(canvas_skia);
100 cairo_t* cr = scoped_platform_paint.GetPlatformSurface(); 100 cairo_t* cr = scoped_platform_paint.GetPlatformSurface();
101 cairo_save(cr); 101 cairo_save(cr);
102 cairo_rectangle(cr, bounds.x(), bounds.y(), bounds.width(), bounds.height()); 102 cairo_rectangle(cr, bounds.x(), bounds.y(), bounds.width(), bounds.height());
103 cairo_clip(cr); 103 cairo_clip(cr);
104 104
105 int text_width, text_height; 105 int text_width, text_height;
106 pango_layout_get_pixel_size(layout, &text_width, &text_height); 106 pango_layout_get_pixel_size(layout, &text_width, &text_height);
107 Point offset(ToViewPoint(Point())); 107 Point offset(ToViewPoint(Point()));
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 return right; 491 return right;
492 } 492 }
493 } 493 }
494 494
495 return right_end; 495 return right_end;
496 } 496 }
497 497
498 PangoLayout* RenderTextLinux::EnsureLayout() { 498 PangoLayout* RenderTextLinux::EnsureLayout() {
499 if (layout_ == NULL) { 499 if (layout_ == NULL) {
500 CanvasSkia canvas(display_rect().width(), display_rect().height(), false); 500 CanvasSkia canvas(display_rect().width(), display_rect().height(), false);
501 skia::ScopedPlatformPaint scoped_platform_paint(&canvas); 501 skia::ScopedPlatformPaint scoped_platform_paint(canvas.sk_canvas());
502 cairo_t* cr = scoped_platform_paint.GetPlatformSurface(); 502 cairo_t* cr = scoped_platform_paint.GetPlatformSurface();
503 503
504 layout_ = pango_cairo_create_layout(cr); 504 layout_ = pango_cairo_create_layout(cr);
505 SetupPangoLayout( 505 SetupPangoLayout(
506 layout_, 506 layout_,
507 text(), 507 text(),
508 default_style().font, 508 default_style().font,
509 display_rect().width(), 509 display_rect().width(),
510 base::i18n::GetFirstStrongCharacterDirection(text()), 510 base::i18n::GetFirstStrongCharacterDirection(text()),
511 CanvasSkia::DefaultCanvasTextAlignment()); 511 CanvasSkia::DefaultCanvasTextAlignment());
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 size_t RenderTextLinux::Utf8IndexToUtf16Index(size_t index) const { 672 size_t RenderTextLinux::Utf8IndexToUtf16Index(size_t index) const {
673 int32_t utf16_index = 0; 673 int32_t utf16_index = 0;
674 UErrorCode ec = U_ZERO_ERROR; 674 UErrorCode ec = U_ZERO_ERROR;
675 u_strFromUTF8(NULL, 0, &utf16_index, layout_text_, index, &ec); 675 u_strFromUTF8(NULL, 0, &utf16_index, layout_text_, index, &ec);
676 DCHECK(ec == U_BUFFER_OVERFLOW_ERROR || 676 DCHECK(ec == U_BUFFER_OVERFLOW_ERROR ||
677 ec == U_STRING_NOT_TERMINATED_WARNING); 677 ec == U_STRING_NOT_TERMINATED_WARNING);
678 return utf16_index; 678 return utf16_index;
679 } 679 }
680 680
681 } // namespace gfx 681 } // namespace gfx
OLDNEW
« ui/gfx/canvas.h ('K') | « ui/gfx/render_text.cc ('k') | ui/gfx/render_text_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698