OLD | NEW |
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 #include "ui/gfx/render_text_pango.h" | 5 #include "ui/gfx/render_text_pango.h" |
6 | 6 |
7 #include <pango/pangocairo.h> | 7 #include <pango/pangocairo.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } | 75 } |
76 | 76 |
77 RenderTextPango::~RenderTextPango() { | 77 RenderTextPango::~RenderTextPango() { |
78 ResetLayout(); | 78 ResetLayout(); |
79 } | 79 } |
80 | 80 |
81 Size RenderTextPango::GetStringSize() { | 81 Size RenderTextPango::GetStringSize() { |
82 EnsureLayout(); | 82 EnsureLayout(); |
83 int width = 0, height = 0; | 83 int width = 0, height = 0; |
84 pango_layout_get_pixel_size(layout_, &width, &height); | 84 pango_layout_get_pixel_size(layout_, &width, &height); |
| 85 |
| 86 // Pango returns 0 widths for very long strings (of 0x40000 chars or more). |
| 87 // This is caused by an int overflow in pango_glyph_string_extents_range. |
| 88 // Absurdly long strings may even report non-zero garbage values for width; |
| 89 // while detecting that isn't worthwhile, this handles the 0 width cases. |
| 90 const long kAbsurdLength = 100000; |
| 91 if (width == 0 && g_utf8_strlen(layout_text_, -1) > kAbsurdLength) |
| 92 width = font_list().GetExpectedTextWidth(g_utf8_strlen(layout_text_, -1)); |
| 93 |
85 // Keep a consistent height between this particular string's PangoLayout and | 94 // Keep a consistent height between this particular string's PangoLayout and |
86 // potentially larger text supported by the FontList. | 95 // potentially larger text supported by the FontList. |
87 // For example, if a text field contains a Japanese character, which is | 96 // For example, if a text field contains a Japanese character, which is |
88 // smaller than Latin ones, and then later a Latin one is inserted, this | 97 // smaller than Latin ones, and then later a Latin one is inserted, this |
89 // ensures that the text baseline does not shift. | 98 // ensures that the text baseline does not shift. |
90 return Size(width, std::max(height, font_list().GetHeight())); | 99 return Size(width, std::max(height, font_list().GetHeight())); |
91 } | 100 } |
92 | 101 |
93 SelectionModel RenderTextPango::FindCursorPosition(const Point& point) { | 102 SelectionModel RenderTextPango::FindCursorPosition(const Point& point) { |
94 EnsureLayout(); | 103 EnsureLayout(); |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 int glyph_index) const { | 518 int glyph_index) const { |
510 return LayoutIndexToTextIndex(run->item->offset + | 519 return LayoutIndexToTextIndex(run->item->offset + |
511 run->glyphs->log_clusters[glyph_index]); | 520 run->glyphs->log_clusters[glyph_index]); |
512 } | 521 } |
513 | 522 |
514 RenderText* RenderText::CreateNativeInstance() { | 523 RenderText* RenderText::CreateNativeInstance() { |
515 return new RenderTextPango; | 524 return new RenderTextPango; |
516 } | 525 } |
517 | 526 |
518 } // namespace gfx | 527 } // namespace gfx |
OLD | NEW |