Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: app/gfx/canvas_linux.cc

Issue 338001: Get the About panel to align its links correctly, (Closed)
Patch Set: Found some leftover cruft in files. Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | app/gfx/font_skia.cc » ('j') | chrome/browser/chromeos/status_area_view.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 cairo_surface_t* surface = 147 cairo_surface_t* surface =
148 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0); 148 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0);
149 cairo_t* cr = cairo_create(surface); 149 cairo_t* cr = cairo_create(surface);
150 PangoLayout* layout = pango_cairo_create_layout(cr); 150 PangoLayout* layout = pango_cairo_create_layout(cr);
151 151
152 SetupPangoLayout(layout, font, *width, flags); 152 SetupPangoLayout(layout, font, *width, flags);
153 153
154 std::string utf8 = WideToUTF8(text); 154 std::string utf8 = WideToUTF8(text);
155 pango_layout_set_text(layout, utf8.data(), utf8.size()); 155 pango_layout_set_text(layout, utf8.data(), utf8.size());
156 156
157 int chars_height; 157 pango_layout_get_pixel_size(layout, width, height);
158 pango_layout_get_size(layout, width, &chars_height);
159 *width /= PANGO_SCALE;
160 // Pango returns the height of the characters, not the height of the font.
161 *height = font.height();
162 158
163 g_object_unref(layout); 159 g_object_unref(layout);
164 cairo_destroy(cr); 160 cairo_destroy(cr);
165 cairo_surface_destroy(surface); 161 cairo_surface_destroy(surface);
166 } 162 }
167 163
168 void Canvas::DrawStringInt(const std::wstring& text, 164 void Canvas::DrawStringInt(const std::wstring& text,
169 const gfx::Font& font, 165 const gfx::Font& font,
170 const SkColor& color, 166 const SkColor& color,
171 int x, int y, int w, int h, 167 int x, int y, int w, int h,
172 int flags) { 168 int flags) {
173 cairo_t* cr = beginPlatformPaint(); 169 cairo_t* cr = beginPlatformPaint();
174 PangoLayout* layout = pango_cairo_create_layout(cr); 170 PangoLayout* layout = pango_cairo_create_layout(cr);
175 171
176 SetupPangoLayout(layout, font, w, flags); 172 SetupPangoLayout(layout, font, w, flags);
177 173
178 pango_layout_set_height(layout, h * PANGO_SCALE); 174 pango_layout_set_height(layout, h * PANGO_SCALE);
179 175
180 cairo_save(cr); 176 cairo_save(cr);
181 cairo_set_source_rgb(cr, 177 cairo_set_source_rgb(cr,
182 SkColorGetR(color) / 255.0, 178 SkColorGetR(color) / 255.0,
183 SkColorGetG(color) / 255.0, 179 SkColorGetG(color) / 255.0,
184 SkColorGetB(color) / 255.0); 180 SkColorGetB(color) / 255.0);
185 181
186 std::string utf8 = WideToUTF8(text); 182 std::string utf8 = WideToUTF8(text);
187 pango_layout_set_text(layout, utf8.data(), utf8.size()); 183 pango_layout_set_text(layout, utf8.data(), utf8.size());
188 184
189 int width, height; 185 int width, height;
190 pango_layout_get_size(layout, &width, &height); 186 pango_layout_get_pixel_size(layout, &width, &height);
191 width /= PANGO_SCALE;
192 height /= PANGO_SCALE;
193 187
194 if (flags & Canvas::TEXT_VALIGN_TOP) { 188 if (flags & Canvas::TEXT_VALIGN_TOP) {
195 // Cairo should draw from the top left corner already. 189 // Cairo should draw from the top left corner already.
196 } else if (flags & Canvas::TEXT_VALIGN_BOTTOM) { 190 } else if (flags & Canvas::TEXT_VALIGN_BOTTOM) {
197 y += (h - height); 191 y += (h - height);
198 } else { 192 } else {
199 // Vertically centered. 193 // Vertically centered.
200 y += ((h - height) / 2); 194 y += ((h - height) / 2);
201 } 195 }
202 196
(...skipping 13 matching lines...) Expand all
216 NOTREACHED(); 210 NOTREACHED();
217 return; 211 return;
218 } 212 }
219 213
220 cairo_t* cr = beginPlatformPaint(); 214 cairo_t* cr = beginPlatformPaint();
221 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); 215 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y);
222 cairo_paint(cr); 216 cairo_paint(cr);
223 } 217 }
224 218
225 } // namespace gfx 219 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | app/gfx/font_skia.cc » ('j') | chrome/browser/chromeos/status_area_view.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698