| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkPDFDevice.h" | 8 #include "SkPDFDevice.h" |
| 9 | 9 |
| 10 #include "SkAnnotation.h" | 10 #include "SkAnnotation.h" |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 enum_must_match_value); | 559 enum_must_match_value); |
| 560 SK_COMPILE_ASSERT(SkPaint::kStrokeAndFill_Style == 2, | 560 SK_COMPILE_ASSERT(SkPaint::kStrokeAndFill_Style == 2, |
| 561 enum_must_match_value); | 561 enum_must_match_value); |
| 562 fContentStream->writeDecAsText(state.fTextFill); | 562 fContentStream->writeDecAsText(state.fTextFill); |
| 563 fContentStream->writeText(" Tr\n"); | 563 fContentStream->writeText(" Tr\n"); |
| 564 currentEntry()->fTextFill = state.fTextFill; | 564 currentEntry()->fTextFill = state.fTextFill; |
| 565 } | 565 } |
| 566 } | 566 } |
| 567 } | 567 } |
| 568 | 568 |
| 569 SkDevice* SkPDFDevice::onCreateCompatibleDevice(SkBitmap::Config config, | 569 SkBaseDevice* SkPDFDevice::onCreateCompatibleDevice(SkBitmap::Config config, |
| 570 int width, int height, | 570 int width, int height, |
| 571 bool isOpaque, | 571 bool isOpaque, |
| 572 Usage usage) { | 572 Usage usage) { |
| 573 SkMatrix initialTransform; | 573 SkMatrix initialTransform; |
| 574 initialTransform.reset(); | 574 initialTransform.reset(); |
| 575 SkISize size = SkISize::Make(width, height); | 575 SkISize size = SkISize::Make(width, height); |
| 576 return SkNEW_ARGS(SkPDFDevice, (size, size, initialTransform)); | 576 return SkNEW_ARGS(SkPDFDevice, (size, size, initialTransform)); |
| 577 } | 577 } |
| 578 | 578 |
| 579 | 579 |
| 580 struct ContentEntry { | 580 struct ContentEntry { |
| 581 GraphicStateEntry fState; | 581 GraphicStateEntry fState; |
| 582 SkDynamicMemoryWStream fContent; | 582 SkDynamicMemoryWStream fContent; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 bitmap.setConfig(SkBitmap::kNo_Config, abs(contentSize.fWidth), | 665 bitmap.setConfig(SkBitmap::kNo_Config, abs(contentSize.fWidth), |
| 666 abs(contentSize.fHeight)); | 666 abs(contentSize.fHeight)); |
| 667 } | 667 } |
| 668 | 668 |
| 669 return bitmap; | 669 return bitmap; |
| 670 } | 670 } |
| 671 | 671 |
| 672 // TODO(vandebo) change pageSize to SkSize. | 672 // TODO(vandebo) change pageSize to SkSize. |
| 673 SkPDFDevice::SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize, | 673 SkPDFDevice::SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize, |
| 674 const SkMatrix& initialTransform) | 674 const SkMatrix& initialTransform) |
| 675 : SkDevice(makeContentBitmap(contentSize, &initialTransform)), | 675 : SkBitmapDevice(makeContentBitmap(contentSize, &initialTransform)), |
| 676 fPageSize(pageSize), | 676 fPageSize(pageSize), |
| 677 fContentSize(contentSize), | 677 fContentSize(contentSize), |
| 678 fLastContentEntry(NULL), | 678 fLastContentEntry(NULL), |
| 679 fLastMarginContentEntry(NULL), | 679 fLastMarginContentEntry(NULL), |
| 680 fClipStack(NULL), | 680 fClipStack(NULL), |
| 681 fEncoder(NULL) { | 681 fEncoder(NULL) { |
| 682 // Skia generally uses the top left as the origin but PDF natively has the | 682 // Skia generally uses the top left as the origin but PDF natively has the |
| 683 // origin at the bottom left. This matrix corrects for that. But that only | 683 // origin at the bottom left. This matrix corrects for that. But that only |
| 684 // needs to be done once, we don't do it when layering. | 684 // needs to be done once, we don't do it when layering. |
| 685 fInitialTransform.setTranslate(0, SkIntToScalar(pageSize.fHeight)); | 685 fInitialTransform.setTranslate(0, SkIntToScalar(pageSize.fHeight)); |
| 686 fInitialTransform.preScale(SK_Scalar1, -SK_Scalar1); | 686 fInitialTransform.preScale(SK_Scalar1, -SK_Scalar1); |
| 687 fInitialTransform.preConcat(initialTransform); | 687 fInitialTransform.preConcat(initialTransform); |
| 688 | 688 |
| 689 SkIRect existingClip = SkIRect::MakeWH(this->width(), this->height()); | 689 SkIRect existingClip = SkIRect::MakeWH(this->width(), this->height()); |
| 690 fExistingClipRegion.setRect(existingClip); | 690 fExistingClipRegion.setRect(existingClip); |
| 691 | 691 |
| 692 this->init(); | 692 this->init(); |
| 693 } | 693 } |
| 694 | 694 |
| 695 // TODO(vandebo) change layerSize to SkSize. | 695 // TODO(vandebo) change layerSize to SkSize. |
| 696 SkPDFDevice::SkPDFDevice(const SkISize& layerSize, | 696 SkPDFDevice::SkPDFDevice(const SkISize& layerSize, |
| 697 const SkClipStack& existingClipStack, | 697 const SkClipStack& existingClipStack, |
| 698 const SkRegion& existingClipRegion) | 698 const SkRegion& existingClipRegion) |
| 699 : SkDevice(makeContentBitmap(layerSize, NULL)), | 699 : SkBitmapDevice(makeContentBitmap(layerSize, NULL)), |
| 700 fPageSize(layerSize), | 700 fPageSize(layerSize), |
| 701 fContentSize(layerSize), | 701 fContentSize(layerSize), |
| 702 fExistingClipStack(existingClipStack), | 702 fExistingClipStack(existingClipStack), |
| 703 fExistingClipRegion(existingClipRegion), | 703 fExistingClipRegion(existingClipRegion), |
| 704 fLastContentEntry(NULL), | 704 fLastContentEntry(NULL), |
| 705 fLastMarginContentEntry(NULL), | 705 fLastMarginContentEntry(NULL), |
| 706 fClipStack(NULL) { | 706 fClipStack(NULL) { |
| 707 fInitialTransform.reset(); | 707 fInitialTransform.reset(); |
| 708 this->init(); | 708 this->init(); |
| 709 } | 709 } |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1146 int vertexCount, const SkPoint verts[], | 1146 int vertexCount, const SkPoint verts[], |
| 1147 const SkPoint texs[], const SkColor colors[], | 1147 const SkPoint texs[], const SkColor colors[], |
| 1148 SkXfermode* xmode, const uint16_t indices[], | 1148 SkXfermode* xmode, const uint16_t indices[], |
| 1149 int indexCount, const SkPaint& paint) { | 1149 int indexCount, const SkPaint& paint) { |
| 1150 if (d.fClip->isEmpty()) { | 1150 if (d.fClip->isEmpty()) { |
| 1151 return; | 1151 return; |
| 1152 } | 1152 } |
| 1153 NOT_IMPLEMENTED("drawVerticies", true); | 1153 NOT_IMPLEMENTED("drawVerticies", true); |
| 1154 } | 1154 } |
| 1155 | 1155 |
| 1156 void SkPDFDevice::drawDevice(const SkDraw& d, SkDevice* device, int x, int y, | 1156 void SkPDFDevice::drawDevice(const SkDraw& d, SkBaseDevice* device, int x, int y
, |
| 1157 const SkPaint& paint) { | 1157 const SkPaint& paint) { |
| 1158 if ((device->getDeviceCapabilities() & kVector_Capability) == 0) { | 1158 if ((device->getDeviceCapabilities() & kVector_Capability) == 0) { |
| 1159 // If we somehow get a raster device, do what our parent would do. | 1159 // If we somehow get a raster device, do what our parent would do. |
| 1160 SkDevice::drawDevice(d, device, x, y, paint); | 1160 INHERITED::drawDevice(d, device, x, y, paint); |
| 1161 return; | 1161 return; |
| 1162 } | 1162 } |
| 1163 | 1163 |
| 1164 // Assume that a vector capable device means that it's a PDF Device. | 1164 // Assume that a vector capable device means that it's a PDF Device. |
| 1165 SkPDFDevice* pdfDevice = static_cast<SkPDFDevice*>(device); | 1165 SkPDFDevice* pdfDevice = static_cast<SkPDFDevice*>(device); |
| 1166 if (pdfDevice->isContentEmpty()) { | 1166 if (pdfDevice->isContentEmpty()) { |
| 1167 return; | 1167 return; |
| 1168 } | 1168 } |
| 1169 | 1169 |
| 1170 SkMatrix matrix; | 1170 SkMatrix matrix; |
| (...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1922 } | 1922 } |
| 1923 | 1923 |
| 1924 bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y, | 1924 bool SkPDFDevice::onReadPixels(const SkBitmap& bitmap, int x, int y, |
| 1925 SkCanvas::Config8888) { | 1925 SkCanvas::Config8888) { |
| 1926 return false; | 1926 return false; |
| 1927 } | 1927 } |
| 1928 | 1928 |
| 1929 bool SkPDFDevice::allowImageFilter(SkImageFilter*) { | 1929 bool SkPDFDevice::allowImageFilter(SkImageFilter*) { |
| 1930 return false; | 1930 return false; |
| 1931 } | 1931 } |
| OLD | NEW |