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

Side by Side Diff: gfx/canvas_skia_linux.cc

Issue 6121004: Remove wstring from gfx. (Closed) Base URL: svn://chrome-svn/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 std::wstring& text, 165 const string16& 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 std::wstring& text, 194 const string16& 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_, WideToUTF16Hack(text), font, bounds_.width(), 214 SetupPangoLayout(layout_, text, font, bounds_.width(), flags_);
215 flags_);
216 215
217 pango_layout_set_height(layout_, bounds_.height() * PANGO_SCALE); 216 pango_layout_set_height(layout_, bounds_.height() * PANGO_SCALE);
218 217
219 cairo_save(cr_); 218 cairo_save(cr_);
220 219
221 cairo_rectangle(cr_, clip.x(), clip.y(), clip.width(), clip.height()); 220 cairo_rectangle(cr_, clip.x(), clip.y(), clip.width(), clip.height());
222 cairo_clip(cr_); 221 cairo_clip(cr_);
223 222
224 pango_layout_get_pixel_size(layout_, &text_width_, &text_height_); 223 pango_layout_get_pixel_size(layout_, &text_width_, &text_height_);
225 224
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 // asked for. See the loop in pango-layout.c process_item that determines 338 // asked for. See the loop in pango-layout.c process_item that determines
340 // where to wrap. 339 // where to wrap.
341 *width = org_width; 340 *width = org_width;
342 } 341 }
343 342
344 g_object_unref(layout); 343 g_object_unref(layout);
345 cairo_destroy(cr); 344 cairo_destroy(cr);
346 cairo_surface_destroy(surface); 345 cairo_surface_destroy(surface);
347 } 346 }
348 347
349 void CanvasSkia::DrawStringWithHalo(const std::wstring& text, 348 void CanvasSkia::DrawStringWithHalo(const string16& text,
350 const gfx::Font& font, 349 const gfx::Font& font,
351 const SkColor& text_color, 350 const SkColor& text_color,
352 const SkColor& halo_color, 351 const SkColor& halo_color,
353 int x, int y, int w, int h, 352 int x, int y, int w, int h,
354 int flags) { 353 int flags) {
355 if (w <= 0 || h <= 0) 354 if (w <= 0 || h <= 0)
356 return; 355 return;
357 356
358 gfx::Rect bounds(x, y, w, h); 357 gfx::Rect bounds(x, y, w, h);
359 gfx::Rect clip(x - 1, y - 1, w + 2, h + 2); // Bigger clip for halo 358 gfx::Rect clip(x - 1, y - 1, w + 2, h + 2); // Bigger clip for halo
360 DrawStringContext context(this, text, font, bounds, clip,flags); 359 DrawStringContext context(this, text, font, bounds, clip,flags);
361 context.DrawWithHalo(text_color, halo_color); 360 context.DrawWithHalo(text_color, halo_color);
362 } 361 }
363 362
364 void CanvasSkia::DrawStringInt(const std::wstring& text, 363 void CanvasSkia::DrawStringInt(const string16& text,
365 const gfx::Font& font, 364 const gfx::Font& font,
366 const SkColor& color, 365 const SkColor& color,
367 int x, int y, int w, int h, 366 int x, int y, int w, int h,
368 int flags) { 367 int flags) {
369 if (w <= 0 || h <= 0) 368 if (w <= 0 || h <= 0)
370 return; 369 return;
371 370
372 gfx::Rect bounds(x, y, w, h); 371 gfx::Rect bounds(x, y, w, h);
373 DrawStringContext context(this, text, font, bounds, bounds, flags); 372 DrawStringContext context(this, text, font, bounds, bounds, flags);
374 context.Draw(color); 373 context.Draw(color);
375 } 374 }
376 375
377 void CanvasSkia::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) { 376 void CanvasSkia::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) {
378 if (!pixbuf) { 377 if (!pixbuf) {
379 NOTREACHED(); 378 NOTREACHED();
380 return; 379 return;
381 } 380 }
382 381
383 cairo_t* cr = beginPlatformPaint(); 382 cairo_t* cr = beginPlatformPaint();
384 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); 383 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y);
385 cairo_paint(cr); 384 cairo_paint(cr);
386 } 385 }
387 386
388 } // namespace gfx 387 } // 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