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 // This file defines utility functions for eliding and formatting UI text. | 5 // This file defines utility functions for eliding and formatting UI text. |
6 | 6 |
7 #ifndef UI_GFX_TEXT_ELIDER_H_ | 7 #ifndef UI_GFX_TEXT_ELIDER_H_ |
8 #define UI_GFX_TEXT_ELIDER_H_ | 8 #define UI_GFX_TEXT_ELIDER_H_ |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 INSUFFICIENT_SPACE_VERTICAL = 1 << 1, | 137 INSUFFICIENT_SPACE_VERTICAL = 1 << 1, |
138 }; | 138 }; |
139 | 139 |
140 // Reformats |text| into output vector |lines| so that the resulting text fits | 140 // Reformats |text| into output vector |lines| so that the resulting text fits |
141 // into an |available_pixel_width| by |available_pixel_height| rectangle with | 141 // into an |available_pixel_width| by |available_pixel_height| rectangle with |
142 // the specified |font_list|. Input newlines are respected, but lines that are | 142 // the specified |font_list|. Input newlines are respected, but lines that are |
143 // too long are broken into pieces. For words that are too wide to fit on a | 143 // too long are broken into pieces. For words that are too wide to fit on a |
144 // single line, the wrapping behavior can be specified with the |wrap_behavior| | 144 // single line, the wrapping behavior can be specified with the |wrap_behavior| |
145 // param. Returns a combination of |ReformattingResultFlags| that indicate | 145 // param. Returns a combination of |ReformattingResultFlags| that indicate |
146 // whether the given rectangle had insufficient space to accommodate |text|, | 146 // whether the given rectangle had insufficient space to accommodate |text|, |
147 // leading to elision or truncation (and not just reformatting). | 147 // leading to elision or truncation (and not just reformatting). In case |
| 148 // |max_broken_pixel_width| is not NULL it will store maximum width of those |
| 149 // lines which were broken after some words to fit |available_pixel_width|. |
148 GFX_EXPORT int ElideRectangleText(const base::string16& text, | 150 GFX_EXPORT int ElideRectangleText(const base::string16& text, |
149 const gfx::FontList& font_list, | 151 const gfx::FontList& font_list, |
150 float available_pixel_width, | 152 float available_pixel_width, |
151 int available_pixel_height, | 153 int available_pixel_height, |
152 WordWrapBehavior wrap_behavior, | 154 WordWrapBehavior wrap_behavior, |
153 std::vector<base::string16>* lines); | 155 std::vector<base::string16>* lines, |
| 156 float* max_broken_pixel_width); |
154 | 157 |
155 // Truncates |string| to |length| characters. This breaks the string according | 158 // Truncates |string| to |length| characters. This breaks the string according |
156 // to the specified |break_type|, which must be either WORD_BREAK or | 159 // to the specified |break_type|, which must be either WORD_BREAK or |
157 // CHARACTER_BREAK, and adds the horizontal ellipsis character (unicode | 160 // CHARACTER_BREAK, and adds the horizontal ellipsis character (unicode |
158 // character 0x2026) to render "...". The supplied string is returned if the | 161 // character 0x2026) to render "...". The supplied string is returned if the |
159 // string has |length| characters or less. | 162 // string has |length| characters or less. |
160 GFX_EXPORT base::string16 TruncateString(const base::string16& string, | 163 GFX_EXPORT base::string16 TruncateString(const base::string16& string, |
161 size_t length, | 164 size_t length, |
162 BreakType break_type); | 165 BreakType break_type); |
163 | 166 |
164 } // namespace gfx | 167 } // namespace gfx |
165 | 168 |
166 #endif // UI_GFX_TEXT_ELIDER_H_ | 169 #endif // UI_GFX_TEXT_ELIDER_H_ |
OLD | NEW |