| 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 // TODO(myhuang): We have to decide or allow the user the choose the type | 7 // TODO(myhuang): We have to decide or allow the user the choose the type |
| 8 // of the surface in the future. | 8 // of the surface in the future. |
| 9 #include <cairo-pdf.h> | 9 #include <cairo-pdf.h> |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 } | 26 } |
| 27 | 27 |
| 28 VectorPlatformDevice::VectorPlatformDevice(const SkBitmap& bitmap) | 28 VectorPlatformDevice::VectorPlatformDevice(const SkBitmap& bitmap) |
| 29 : PlatformDevice(bitmap) { | 29 : PlatformDevice(bitmap) { |
| 30 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); | 30 SkASSERT(bitmap.getConfig() == SkBitmap::kARGB_8888_Config); |
| 31 | 31 |
| 32 // FIXME(myhuang): At this moment, we write the PDF file to the disk | 32 // FIXME(myhuang): At this moment, we write the PDF file to the disk |
| 33 // for testing when we run chromium without sanboxing. | 33 // for testing when we run chromium without sanboxing. |
| 34 surface_ = cairo_pdf_surface_create("chrome_printing_test.pdf", | 34 surface_ = cairo_pdf_surface_create("chrome_printing_test.pdf", |
| 35 width(), height()); | 35 width(), height()); |
| 36 SkASSERT(surface); | 36 SkASSERT(surface_); |
| 37 context_ = cairo_create(surface_); | 37 context_ = cairo_create(surface_); |
| 38 SkASSERT(context_); | 38 SkASSERT(context_); |
| 39 | 39 |
| 40 transform_.reset(); | 40 transform_.reset(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 VectorPlatformDevice::~VectorPlatformDevice() { | 43 VectorPlatformDevice::~VectorPlatformDevice() { |
| 44 SkASSERT(surface); | 44 SkASSERT(surface_); |
| 45 SkASSERT(context_); | 45 SkASSERT(context_); |
| 46 | 46 |
| 47 cairo_destroy(context_); | 47 cairo_destroy(context_); |
| 48 cairo_surface_destroy(surface_); | 48 cairo_surface_destroy(surface_); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void VectorPlatformDevice::drawBitmap(const SkDraw& draw, | 51 void VectorPlatformDevice::drawBitmap(const SkDraw& draw, |
| 52 const SkBitmap& bitmap, | 52 const SkBitmap& bitmap, |
| 53 const SkMatrix& matrix, | 53 const SkMatrix& matrix, |
| 54 const SkPaint& paint) { | 54 const SkPaint& paint) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 65 // Restore the original matrix. | 65 // Restore the original matrix. |
| 66 LoadTransformToContext(transform_); | 66 LoadTransformToContext(transform_); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void VectorPlatformDevice::drawDevice(const SkDraw& draw, | 69 void VectorPlatformDevice::drawDevice(const SkDraw& draw, |
| 70 SkDevice* device, | 70 SkDevice* device, |
| 71 int x, | 71 int x, |
| 72 int y, | 72 int y, |
| 73 const SkPaint& paint) { | 73 const SkPaint& paint) { |
| 74 SkASSERT(device); | 74 SkASSERT(device); |
| 75 SkASSERT(device->accessBitmap(false)); | |
| 76 | 75 |
| 77 // TODO(myhuang): We may also have to consider http://b/1183870 . | 76 // TODO(myhuang): We may also have to consider http://b/1183870 . |
| 78 drawSprite(draw, device->accessBitmap(false), x, y, paint); | 77 drawSprite(draw, device->accessBitmap(false), x, y, paint); |
| 79 } | 78 } |
| 80 | 79 |
| 81 void VectorPlatformDevice::drawPaint(const SkDraw& draw, | 80 void VectorPlatformDevice::drawPaint(const SkDraw& draw, |
| 82 const SkPaint& paint) { | 81 const SkPaint& paint) { |
| 83 // Bypass the current transformation matrix. | 82 // Bypass the current transformation matrix. |
| 84 LoadIdentityTransformToContext(); | 83 LoadIdentityTransformToContext(); |
| 85 | 84 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 // TODO(myhuang): Support Stroke/Fill better. | 240 // TODO(myhuang): Support Stroke/Fill better. |
| 242 void VectorPlatformDevice::drawPosText(const SkDraw& draw, | 241 void VectorPlatformDevice::drawPosText(const SkDraw& draw, |
| 243 const void* text, | 242 const void* text, |
| 244 size_t len, | 243 size_t len, |
| 245 const SkScalar pos[], | 244 const SkScalar pos[], |
| 246 SkScalar constY, | 245 SkScalar constY, |
| 247 int scalarsPerPos, | 246 int scalarsPerPos, |
| 248 const SkPaint& paint) { | 247 const SkPaint& paint) { |
| 249 SkASSERT(text); | 248 SkASSERT(text); |
| 250 SkASSERT(pos); | 249 SkASSERT(pos); |
| 251 SkASSERT(paint.gettextEncoding() == SkPaint::kGlyphID_TextEncoding); | 250 SkASSERT(paint.getTextEncoding() == SkPaint::kGlyphID_TextEncoding); |
| 252 SkASSERT(scalarsPerPos == 2); // Each pos contains x and y. | 251 SkASSERT(scalarsPerPos == 2); // Each pos contains x and y. |
| 253 | 252 |
| 254 if (!len) | 253 if (!len) |
| 255 return; | 254 return; |
| 256 | 255 |
| 257 // Text color. | 256 // Text color. |
| 258 ApplyPaintColor(paint); | 257 ApplyPaintColor(paint); |
| 259 | 258 |
| 260 cairo_set_font_size(context_, paint.getTextSize()); | 259 cairo_set_font_size(context_, paint.getTextSize()); |
| 261 | 260 |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 m.xy = matrix[SkMatrix::kMSkewX]; | 488 m.xy = matrix[SkMatrix::kMSkewX]; |
| 490 m.x0 = matrix[SkMatrix::kMTransX]; | 489 m.x0 = matrix[SkMatrix::kMTransX]; |
| 491 m.yx = matrix[SkMatrix::kMSkewY]; | 490 m.yx = matrix[SkMatrix::kMSkewY]; |
| 492 m.yy = matrix[SkMatrix::kMScaleY]; | 491 m.yy = matrix[SkMatrix::kMScaleY]; |
| 493 m.y0 = matrix[SkMatrix::kMTransY]; | 492 m.y0 = matrix[SkMatrix::kMTransY]; |
| 494 cairo_set_matrix(context_, &m); | 493 cairo_set_matrix(context_, &m); |
| 495 } | 494 } |
| 496 | 495 |
| 497 } // namespace skia | 496 } // namespace skia |
| 498 | 497 |
| OLD | NEW |