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

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

Issue 149409: Keep the cairo clipping region in sync with the Skia one. (Closed)
Patch Set: git try Created 11 years, 5 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 | base/gfx/native_widget_types.h » ('j') | no next file with comments »
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 <pango/pango.h> 8 #include <pango/pango.h>
9 #include <pango/pangocairo.h> 9 #include <pango/pangocairo.h>
10 10
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 88
89 pango_layout_get_size(layout, width, height); 89 pango_layout_get_size(layout, width, height);
90 *width /= PANGO_SCALE; 90 *width /= PANGO_SCALE;
91 *height /= PANGO_SCALE; 91 *height /= PANGO_SCALE;
92 g_object_unref(layout); 92 g_object_unref(layout);
93 pango_font_description_free(desc); 93 pango_font_description_free(desc);
94 cairo_destroy(cr); 94 cairo_destroy(cr);
95 cairo_surface_destroy(surface); 95 cairo_surface_destroy(surface);
96 } 96 }
97 97
98 void Canvas::ApplySkiaMatrixToCairoContext(cairo_t* cr) {
99 const SkMatrix& skia_matrix = getTotalMatrix();
100 cairo_matrix_t cairo_matrix;
101 cairo_matrix_init(&cairo_matrix,
102 SkScalarToFloat(skia_matrix.getScaleX()),
103 SkScalarToFloat(skia_matrix.getSkewY()),
104 SkScalarToFloat(skia_matrix.getSkewX()),
105 SkScalarToFloat(skia_matrix.getScaleY()),
106 SkScalarToFloat(skia_matrix.getTranslateX()),
107 SkScalarToFloat(skia_matrix.getTranslateY()));
108 cairo_set_matrix(cr, &cairo_matrix);
109 }
110
111 void Canvas::DrawStringInt(const std::wstring& text, 98 void Canvas::DrawStringInt(const std::wstring& text,
112 const gfx::Font& font, 99 const gfx::Font& font,
113 const SkColor& color, int x, int y, int w, int h, 100 const SkColor& color, int x, int y, int w, int h,
114 int flags) { 101 int flags) {
115 cairo_surface_t* surface = beginPlatformPaint(); 102 cairo_t* cr = beginPlatformPaint();
116 cairo_t* cr = cairo_create(surface);
117 // We're going to draw onto the surface directly. This circumvents the matrix
118 // installed by Skia. Apply the matrix from skia to cairo so they align and
119 // we draw at the right place.
120 ApplySkiaMatrixToCairoContext(cr);
121 PangoLayout* layout = pango_cairo_create_layout(cr); 103 PangoLayout* layout = pango_cairo_create_layout(cr);
122 104
123 cairo_set_source_rgb(cr, 105 cairo_set_source_rgb(cr,
124 SkColorGetR(color) / 255.0, 106 SkColorGetR(color) / 255.0,
125 SkColorGetG(color) / 255.0, 107 SkColorGetG(color) / 255.0,
126 SkColorGetB(color) / 255.0); 108 SkColorGetB(color) / 255.0);
127 109
128 // TODO(deanm): Implement the rest of the Canvas flags. 110 // TODO(deanm): Implement the rest of the Canvas flags.
129 if (!(flags & Canvas::NO_ELLIPSIS)) 111 if (!(flags & Canvas::NO_ELLIPSIS))
130 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); 112 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 y = y + (h - (height / PANGO_SCALE)); 144 y = y + (h - (height / PANGO_SCALE));
163 } else { 145 } else {
164 // Vertically centered. 146 // Vertically centered.
165 y = y + ((h - (height / PANGO_SCALE)) / 2); 147 y = y + ((h - (height / PANGO_SCALE)) / 2);
166 } 148 }
167 149
168 cairo_move_to(cr, x, y); 150 cairo_move_to(cr, x, y);
169 pango_cairo_show_layout(cr, layout); 151 pango_cairo_show_layout(cr, layout);
170 152
171 g_object_unref(layout); 153 g_object_unref(layout);
172 cairo_destroy(cr);
173 // NOTE: beginPlatformPaint returned its surface, we shouldn't destroy it. 154 // NOTE: beginPlatformPaint returned its surface, we shouldn't destroy it.
174 } 155 }
175 156
176 } // namespace gfx 157 } // namespace gfx
OLDNEW
« no previous file with comments | « no previous file | base/gfx/native_widget_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698