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/pango_util.h" | 5 #include "ui/gfx/pango_util.h" |
6 | 6 |
7 #include <cairo/cairo.h> | 7 #include <cairo/cairo.h> |
8 #include <fontconfig/fontconfig.h> | 8 #include <fontconfig/fontconfig.h> |
9 #include <pango/pango.h> | 9 #include <pango/pango.h> |
10 #include <pango/pangocairo.h> | 10 #include <pango/pangocairo.h> |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 pango_layout_set_height(layout, bounds.height() * PANGO_SCALE); | 161 pango_layout_set_height(layout, bounds.height() * PANGO_SCALE); |
162 | 162 |
163 cairo_save(cr); | 163 cairo_save(cr); |
164 cairo_rectangle(cr, clip.x(), clip.y(), clip.width(), clip.height()); | 164 cairo_rectangle(cr, clip.x(), clip.y(), clip.width(), clip.height()); |
165 cairo_clip(cr); | 165 cairo_clip(cr); |
166 | 166 |
167 int width = 0, height = 0; | 167 int width = 0, height = 0; |
168 pango_layout_get_pixel_size(layout, &width, &height); | 168 pango_layout_get_pixel_size(layout, &width, &height); |
169 Rect text_rect(bounds.x(), bounds.y(), width, height); | 169 Rect text_rect(bounds.x(), bounds.y(), width, height); |
170 // Vertically center |text_rect| in |bounds|. | 170 // Vertically center |text_rect| in |bounds|. |
171 text_rect.Offset(0, (bounds.height() - text_rect.height()) / 2); | 171 text_rect += gfx::Vector2d(0, (bounds.height() - text_rect.height()) / 2); |
172 | 172 |
173 DrawPangoLayout(cr, layout, font, bounds, text_rect, | 173 DrawPangoLayout(cr, layout, font, bounds, text_rect, |
174 text_color, text_direction, flags); | 174 text_color, text_direction, flags); |
175 | 175 |
176 cairo_restore(cr); | 176 cairo_restore(cr); |
177 g_object_unref(layout); | 177 g_object_unref(layout); |
178 } | 178 } |
179 | 179 |
180 // Pass a width greater than 0 to force wrapping and eliding. | 180 // Pass a width greater than 0 to force wrapping and eliding. |
181 static void SetupPangoLayoutWithoutFont( | 181 static void SetupPangoLayoutWithoutFont( |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 | 407 |
408 if (i == desc_to_metrics->end()) { | 408 if (i == desc_to_metrics->end()) { |
409 PangoFontMetrics* metrics = pango_context_get_metrics(context, desc, NULL); | 409 PangoFontMetrics* metrics = pango_context_get_metrics(context, desc, NULL); |
410 desc_to_metrics->insert(std::make_pair(desc_hash, metrics)); | 410 desc_to_metrics->insert(std::make_pair(desc_hash, metrics)); |
411 return metrics; | 411 return metrics; |
412 } | 412 } |
413 return i->second; | 413 return i->second; |
414 } | 414 } |
415 | 415 |
416 } // namespace gfx | 416 } // namespace gfx |
OLD | NEW |