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 "skia/ext/vector_platform_device.h" | 5 #include "skia/ext/vector_platform_device.h" |
6 | 6 |
7 #include <cairo.h> | 7 #include <cairo.h> |
8 | 8 |
| 9 #include "printing/pdf_ps_metafile_linux.h" |
9 #include "third_party/skia/include/core/SkTypeface.h" | 10 #include "third_party/skia/include/core/SkTypeface.h" |
10 | 11 |
11 namespace skia { | 12 namespace skia { |
12 | 13 |
13 VectorPlatformDevice* VectorPlatformDevice::create(PlatformSurface context, | 14 VectorPlatformDevice* VectorPlatformDevice::create(PlatformSurface context, |
14 int width, int height) { | 15 int width, int height) { |
15 SkASSERT(cairo_status(context) == CAIRO_STATUS_SUCCESS); | 16 SkASSERT(cairo_status(context) == CAIRO_STATUS_SUCCESS); |
16 SkASSERT(width > 0); | 17 SkASSERT(width > 0); |
17 SkASSERT(height > 0); | 18 SkASSERT(height > 0); |
18 | 19 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 SkASSERT(paint.getTextEncoding() == SkPaint::kGlyphID_TextEncoding); | 252 SkASSERT(paint.getTextEncoding() == SkPaint::kGlyphID_TextEncoding); |
252 // Each pos should contain either only x, or (x, y). | 253 // Each pos should contain either only x, or (x, y). |
253 SkASSERT((scalarsPerPos == 1) || (scalarsPerPos == 2)); | 254 SkASSERT((scalarsPerPos == 1) || (scalarsPerPos == 2)); |
254 | 255 |
255 if (!len) | 256 if (!len) |
256 return; | 257 return; |
257 | 258 |
258 // Text color. | 259 // Text color. |
259 ApplyPaintColor(paint); | 260 ApplyPaintColor(paint); |
260 | 261 |
261 const uint16_t* glyphIDs = static_cast<const uint16_t*>(text); | 262 const uint16_t* glyph_ids = static_cast<const uint16_t*>(text); |
262 | 263 |
263 // Draw each glyph by its path. | 264 // The style is either kFill_Style or kStroke_Style. |
264 for (size_t i = 0; i < len / sizeof(uint16_t); ++i) { | 265 if (paint.getStyle() & SkPaint::kStroke_Style) { |
265 uint16_t glyphID = glyphIDs[i]; | 266 ApplyStrokeStyle(paint); |
266 SkPath textPath; | 267 |
267 paint.getTextPath(&glyphID, | 268 // Draw each glyph by its path. |
268 sizeof(uint16_t), | 269 for (size_t i = 0; i < len / sizeof(uint16_t); ++i) { |
269 pos[i * scalarsPerPos], | 270 uint16_t glyph_id = glyph_ids[i]; |
270 (scalarsPerPos == 1) ? | 271 SkPath textPath; |
271 constY : | 272 paint.getTextPath(&glyph_id, |
272 pos[i * scalarsPerPos + 1], | 273 sizeof(uint16_t), |
273 &textPath); | 274 pos[i * scalarsPerPos], |
274 drawPath(draw, textPath, paint); | 275 (scalarsPerPos == 1) ? |
| 276 constY : |
| 277 pos[i * scalarsPerPos + 1], |
| 278 &textPath); |
| 279 drawPath(draw, textPath, paint); |
| 280 } |
| 281 } else { // kFill_Style. |
| 282 // Selects correct font. |
| 283 if (!printing::PdfPsMetafile::SelectFontById( |
| 284 context_, paint.getTypeface()->uniqueID())) { |
| 285 SkASSERT(false); |
| 286 return; |
| 287 } |
| 288 cairo_set_font_size(context_, paint.getTextSize()); |
| 289 |
| 290 // Draw glyphs. |
| 291 for (size_t i = 0; i < len / sizeof(uint16_t); ++i) { |
| 292 uint16_t glyph_id = glyph_ids[i]; |
| 293 |
| 294 cairo_glyph_t glyph; |
| 295 glyph.index = glyph_id; |
| 296 glyph.x = pos[i * scalarsPerPos]; |
| 297 glyph.y = (scalarsPerPos == 1) ? constY : pos[i * scalarsPerPos + 1]; |
| 298 |
| 299 cairo_show_glyphs(context_, &glyph, 1); |
| 300 } |
275 } | 301 } |
276 } | 302 } |
277 | 303 |
278 void VectorPlatformDevice::drawRect(const SkDraw& draw, | 304 void VectorPlatformDevice::drawRect(const SkDraw& draw, |
279 const SkRect& rect, | 305 const SkRect& rect, |
280 const SkPaint& paint) { | 306 const SkPaint& paint) { |
281 if (paint.getPathEffect()) { | 307 if (paint.getPathEffect()) { |
282 // Draw a path instead. | 308 // Draw a path instead. |
283 SkPath path_orginal; | 309 SkPath path_orginal; |
284 path_orginal.addRect(rect); | 310 path_orginal.addRect(rect); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 | 459 |
434 int src_size_x = bitmap.width(); | 460 int src_size_x = bitmap.width(); |
435 int src_size_y = bitmap.height(); | 461 int src_size_y = bitmap.height(); |
436 | 462 |
437 if (!src_size_x || !src_size_y) | 463 if (!src_size_x || !src_size_y) |
438 return; | 464 return; |
439 | 465 |
440 SkAutoLockPixels image_lock(bitmap); | 466 SkAutoLockPixels image_lock(bitmap); |
441 | 467 |
442 cairo_surface_t* bitmap_surface = | 468 cairo_surface_t* bitmap_surface = |
443 cairo_image_surface_create_for_data( | 469 cairo_image_surface_create_for_data( |
444 reinterpret_cast<unsigned char*>(bitmap.getPixels()), | 470 reinterpret_cast<unsigned char*>(bitmap.getPixels()), |
445 CAIRO_FORMAT_ARGB32, src_size_x, src_size_y, bitmap.rowBytes()); | 471 CAIRO_FORMAT_ARGB32, src_size_x, src_size_y, bitmap.rowBytes()); |
446 | 472 |
447 cairo_set_source_surface(context_, bitmap_surface, x, y); | 473 cairo_set_source_surface(context_, bitmap_surface, x, y); |
448 cairo_paint_with_alpha(context_, static_cast<double>(alpha) / 255.); | 474 cairo_paint_with_alpha(context_, static_cast<double>(alpha) / 255.); |
449 | 475 |
450 cairo_surface_destroy(bitmap_surface); | 476 cairo_surface_destroy(bitmap_surface); |
451 } | 477 } |
452 | 478 |
453 void VectorPlatformDevice::LoadClipRegion(const SkRegion& clip) { | 479 void VectorPlatformDevice::LoadClipRegion(const SkRegion& clip) { |
454 cairo_reset_clip(context_); | 480 cairo_reset_clip(context_); |
455 | 481 |
(...skipping 22 matching lines...) Expand all Loading... |
478 m.xy = matrix[SkMatrix::kMSkewX]; | 504 m.xy = matrix[SkMatrix::kMSkewX]; |
479 m.x0 = matrix[SkMatrix::kMTransX]; | 505 m.x0 = matrix[SkMatrix::kMTransX]; |
480 m.yx = matrix[SkMatrix::kMSkewY]; | 506 m.yx = matrix[SkMatrix::kMSkewY]; |
481 m.yy = matrix[SkMatrix::kMScaleY]; | 507 m.yy = matrix[SkMatrix::kMScaleY]; |
482 m.y0 = matrix[SkMatrix::kMTransY]; | 508 m.y0 = matrix[SkMatrix::kMTransY]; |
483 cairo_set_matrix(context_, &m); | 509 cairo_set_matrix(context_, &m); |
484 } | 510 } |
485 | 511 |
486 } // namespace skia | 512 } // namespace skia |
487 | 513 |
OLD | NEW |