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. | |
Alexei Svitkine (slow)
2014/07/03 20:12:33
Did we file a bug against pango for this? iirc Beh
msw
2014/07/08 19:07:36
I'm not sure and can't find any relevant open bugs
Evan Stade
2014/07/08 21:07:19
Unfortunately, my memory lasts exactly 5 years, so
| |
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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 int glyph_index) const { | 528 int glyph_index) const { |
520 return LayoutIndexToTextIndex(run->item->offset + | 529 return LayoutIndexToTextIndex(run->item->offset + |
521 run->glyphs->log_clusters[glyph_index]); | 530 run->glyphs->log_clusters[glyph_index]); |
522 } | 531 } |
523 | 532 |
524 RenderText* RenderText::CreateNativeInstance() { | 533 RenderText* RenderText::CreateNativeInstance() { |
525 return new RenderTextPango; | 534 return new RenderTextPango; |
526 } | 535 } |
527 | 536 |
528 } // namespace gfx | 537 } // namespace gfx |
OLD | NEW |