| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |