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

Side by Side Diff: gfx/canvas_skia_linux.cc

Issue 6134010: Revert 71167 - Remove wstring from gfx.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « gfx/canvas_skia.cc ('k') | gfx/canvas_skia_mac.mm » ('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 "gfx/canvas_skia.h" 5 #include "gfx/canvas_skia.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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 pango_layout_set_text(layout, utf8.data(), utf8.size()); 155 pango_layout_set_text(layout, utf8.data(), utf8.size());
156 } else { 156 } else {
157 pango_layout_set_text(layout, utf8.data(), utf8.size()); 157 pango_layout_set_text(layout, utf8.data(), utf8.size());
158 } 158 }
159 } 159 }
160 160
161 // A class to encapsulate string drawing params and operations. 161 // A class to encapsulate string drawing params and operations.
162 class DrawStringContext { 162 class DrawStringContext {
163 public: 163 public:
164 DrawStringContext(gfx::CanvasSkia* canvas, 164 DrawStringContext(gfx::CanvasSkia* canvas,
165 const string16& text, 165 const std::wstring& text,
166 const gfx::Font& font, 166 const gfx::Font& font,
167 const gfx::Rect& bounds, 167 const gfx::Rect& bounds,
168 const gfx::Rect& clip, 168 const gfx::Rect& clip,
169 int flags); 169 int flags);
170 ~DrawStringContext(); 170 ~DrawStringContext();
171 171
172 void Draw(const SkColor& text_color); 172 void Draw(const SkColor& text_color);
173 void DrawWithHalo(const SkColor& text_color, 173 void DrawWithHalo(const SkColor& text_color,
174 const SkColor& halo_color); 174 const SkColor& halo_color);
175 175
176 private: 176 private:
177 const gfx::Rect& bounds_; 177 const gfx::Rect& bounds_;
178 int flags_; 178 int flags_;
179 const gfx::Font& font_; 179 const gfx::Font& font_;
180 180
181 gfx::CanvasSkia* canvas_; 181 gfx::CanvasSkia* canvas_;
182 cairo_t* cr_; 182 cairo_t* cr_;
183 PangoLayout* layout_; 183 PangoLayout* layout_;
184 184
185 int text_x_; 185 int text_x_;
186 int text_y_; 186 int text_y_;
187 int text_width_; 187 int text_width_;
188 int text_height_; 188 int text_height_;
189 189
190 DISALLOW_COPY_AND_ASSIGN(DrawStringContext); 190 DISALLOW_COPY_AND_ASSIGN(DrawStringContext);
191 }; 191 };
192 192
193 DrawStringContext::DrawStringContext(gfx::CanvasSkia* canvas, 193 DrawStringContext::DrawStringContext(gfx::CanvasSkia* canvas,
194 const string16& text, 194 const std::wstring& text,
195 const gfx::Font& font, 195 const gfx::Font& font,
196 const gfx::Rect& bounds, 196 const gfx::Rect& bounds,
197 const gfx::Rect& clip, 197 const gfx::Rect& clip,
198 int flags) 198 int flags)
199 : bounds_(bounds), 199 : bounds_(bounds),
200 flags_(flags), 200 flags_(flags),
201 font_(font), 201 font_(font),
202 canvas_(canvas), 202 canvas_(canvas),
203 cr_(NULL), 203 cr_(NULL),
204 layout_(NULL), 204 layout_(NULL),
205 text_x_(bounds.x()), 205 text_x_(bounds.x()),
206 text_y_(bounds.y()), 206 text_y_(bounds.y()),
207 text_width_(0), 207 text_width_(0),
208 text_height_(0) { 208 text_height_(0) {
209 DCHECK(!bounds_.IsEmpty()); 209 DCHECK(!bounds_.IsEmpty());
210 210
211 cr_ = canvas_->beginPlatformPaint(); 211 cr_ = canvas_->beginPlatformPaint();
212 layout_ = pango_cairo_create_layout(cr_); 212 layout_ = pango_cairo_create_layout(cr_);
213 213
214 SetupPangoLayout(layout_, text, font, bounds_.width(), flags_); 214 SetupPangoLayout(layout_, WideToUTF16Hack(text), font, bounds_.width(),
215 flags_);
215 216
216 pango_layout_set_height(layout_, bounds_.height() * PANGO_SCALE); 217 pango_layout_set_height(layout_, bounds_.height() * PANGO_SCALE);
217 218
218 cairo_save(cr_); 219 cairo_save(cr_);
219 220
220 cairo_rectangle(cr_, clip.x(), clip.y(), clip.width(), clip.height()); 221 cairo_rectangle(cr_, clip.x(), clip.y(), clip.width(), clip.height());
221 cairo_clip(cr_); 222 cairo_clip(cr_);
222 223
223 pango_layout_get_pixel_size(layout_, &text_width_, &text_height_); 224 pango_layout_get_pixel_size(layout_, &text_width_, &text_height_);
224 225
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 // asked for. See the loop in pango-layout.c process_item that determines 339 // asked for. See the loop in pango-layout.c process_item that determines
339 // where to wrap. 340 // where to wrap.
340 *width = org_width; 341 *width = org_width;
341 } 342 }
342 343
343 g_object_unref(layout); 344 g_object_unref(layout);
344 cairo_destroy(cr); 345 cairo_destroy(cr);
345 cairo_surface_destroy(surface); 346 cairo_surface_destroy(surface);
346 } 347 }
347 348
348 void CanvasSkia::DrawStringWithHalo(const string16& text, 349 void CanvasSkia::DrawStringWithHalo(const std::wstring& text,
349 const gfx::Font& font, 350 const gfx::Font& font,
350 const SkColor& text_color, 351 const SkColor& text_color,
351 const SkColor& halo_color, 352 const SkColor& halo_color,
352 int x, int y, int w, int h, 353 int x, int y, int w, int h,
353 int flags) { 354 int flags) {
354 if (w <= 0 || h <= 0) 355 if (w <= 0 || h <= 0)
355 return; 356 return;
356 357
357 gfx::Rect bounds(x, y, w, h); 358 gfx::Rect bounds(x, y, w, h);
358 gfx::Rect clip(x - 1, y - 1, w + 2, h + 2); // Bigger clip for halo 359 gfx::Rect clip(x - 1, y - 1, w + 2, h + 2); // Bigger clip for halo
359 DrawStringContext context(this, text, font, bounds, clip,flags); 360 DrawStringContext context(this, text, font, bounds, clip,flags);
360 context.DrawWithHalo(text_color, halo_color); 361 context.DrawWithHalo(text_color, halo_color);
361 } 362 }
362 363
363 void CanvasSkia::DrawStringInt(const string16& text, 364 void CanvasSkia::DrawStringInt(const std::wstring& text,
364 const gfx::Font& font, 365 const gfx::Font& font,
365 const SkColor& color, 366 const SkColor& color,
366 int x, int y, int w, int h, 367 int x, int y, int w, int h,
367 int flags) { 368 int flags) {
368 if (w <= 0 || h <= 0) 369 if (w <= 0 || h <= 0)
369 return; 370 return;
370 371
371 gfx::Rect bounds(x, y, w, h); 372 gfx::Rect bounds(x, y, w, h);
372 DrawStringContext context(this, text, font, bounds, bounds, flags); 373 DrawStringContext context(this, text, font, bounds, bounds, flags);
373 context.Draw(color); 374 context.Draw(color);
374 } 375 }
375 376
376 void CanvasSkia::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) { 377 void CanvasSkia::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) {
377 if (!pixbuf) { 378 if (!pixbuf) {
378 NOTREACHED(); 379 NOTREACHED();
379 return; 380 return;
380 } 381 }
381 382
382 cairo_t* cr = beginPlatformPaint(); 383 cairo_t* cr = beginPlatformPaint();
383 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); 384 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y);
384 cairo_paint(cr); 385 cairo_paint(cr);
385 } 386 }
386 387
387 } // namespace gfx 388 } // namespace gfx
OLDNEW
« no previous file with comments | « gfx/canvas_skia.cc ('k') | gfx/canvas_skia_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698