| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/gfx/canvas.h" | 5 #include "app/gfx/canvas.h" |
| 6 | 6 |
| 7 #include <cairo/cairo.h> | 7 #include <cairo/cairo.h> |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 #include <pango/pango.h> | 9 #include <pango/pango.h> |
| 10 #include <pango/pangocairo.h> | 10 #include <pango/pangocairo.h> |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 160 |
| 161 PangoFontDescription* desc = gfx::Font::PangoFontFromGfxFont(font); | 161 PangoFontDescription* desc = gfx::Font::PangoFontFromGfxFont(font); |
| 162 pango_layout_set_font_description(layout, desc); | 162 pango_layout_set_font_description(layout, desc); |
| 163 pango_font_description_free(desc); | 163 pango_font_description_free(desc); |
| 164 } | 164 } |
| 165 | 165 |
| 166 // static | 166 // static |
| 167 void Canvas::SizeStringInt(const std::wstring& text, | 167 void Canvas::SizeStringInt(const std::wstring& text, |
| 168 const gfx::Font& font, | 168 const gfx::Font& font, |
| 169 int* width, int* height, int flags) { | 169 int* width, int* height, int flags) { |
| 170 int org_width = *width; |
| 170 cairo_surface_t* surface = | 171 cairo_surface_t* surface = |
| 171 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0); | 172 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0); |
| 172 cairo_t* cr = cairo_create(surface); | 173 cairo_t* cr = cairo_create(surface); |
| 173 PangoLayout* layout = pango_cairo_create_layout(cr); | 174 PangoLayout* layout = pango_cairo_create_layout(cr); |
| 174 | 175 |
| 175 SetupPangoLayout(layout, font, *width, flags); | 176 SetupPangoLayout(layout, font, *width, flags); |
| 176 | 177 |
| 177 std::string utf8 = WideToUTF8(text); | 178 std::string utf8 = WideToUTF8(text); |
| 178 pango_layout_set_text(layout, utf8.data(), utf8.size()); | 179 pango_layout_set_text(layout, utf8.data(), utf8.size()); |
| 179 | 180 |
| 180 pango_layout_get_pixel_size(layout, width, height); | 181 pango_layout_get_pixel_size(layout, width, height); |
| 181 | 182 |
| 183 if (org_width > 0 && flags & Canvas::MULTI_LINE && |
| 184 pango_layout_is_wrapped(layout)) { |
| 185 // The text wrapped. There seems to be a bug in Pango when this happens |
| 186 // such that the width returned from pango_layout_get_pixel_size is too |
| 187 // small. Using the width from pango_layout_get_pixel_size in this case |
| 188 // results in wrapping across more lines, which requires a bigger height. |
| 189 // As a workaround we use the original width, which is not necessarily |
| 190 // exactly correct, but isn't wrong by much. |
| 191 *width = org_width; |
| 192 } |
| 193 |
| 182 g_object_unref(layout); | 194 g_object_unref(layout); |
| 183 cairo_destroy(cr); | 195 cairo_destroy(cr); |
| 184 cairo_surface_destroy(surface); | 196 cairo_surface_destroy(surface); |
| 185 } | 197 } |
| 186 | 198 |
| 187 void Canvas::DrawStringInt(const std::wstring& text, | 199 void Canvas::DrawStringInt(const std::wstring& text, |
| 188 const gfx::Font& font, | 200 const gfx::Font& font, |
| 189 const SkColor& color, | 201 const SkColor& color, |
| 190 int x, int y, int w, int h, | 202 int x, int y, int w, int h, |
| 191 int flags) { | 203 int flags) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 NOTREACHED(); | 253 NOTREACHED(); |
| 242 return; | 254 return; |
| 243 } | 255 } |
| 244 | 256 |
| 245 cairo_t* cr = beginPlatformPaint(); | 257 cairo_t* cr = beginPlatformPaint(); |
| 246 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); | 258 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); |
| 247 cairo_paint(cr); | 259 cairo_paint(cr); |
| 248 } | 260 } |
| 249 | 261 |
| 250 } // namespace gfx | 262 } // namespace gfx |
| OLD | NEW |