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

Side by Side Diff: src/pdf/SkPDFDevice.cpp

Issue 941023005: PDF : New factory function for SkPDFDevice (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 10 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
OLDNEW
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 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 568
569 SkBaseDevice* SkPDFDevice::onCreateCompatibleDevice(const CreateInfo& cinfo) { 569 SkBaseDevice* SkPDFDevice::onCreateCompatibleDevice(const CreateInfo& cinfo) {
570 // PDF does not support image filters, so render them on CPU. 570 // PDF does not support image filters, so render them on CPU.
571 // Note that this rendering is done at "screen" resolution (100dpi), not 571 // Note that this rendering is done at "screen" resolution (100dpi), not
572 // printer resolution. 572 // printer resolution.
573 // FIXME: It may be possible to express some filters natively using PDF 573 // FIXME: It may be possible to express some filters natively using PDF
574 // to improve quality and file size (http://skbug.com/3043) 574 // to improve quality and file size (http://skbug.com/3043)
575 if (kImageFilter_Usage == cinfo.fUsage) { 575 if (kImageFilter_Usage == cinfo.fUsage) {
576 return SkBitmapDevice::Create(cinfo.fInfo); 576 return SkBitmapDevice::Create(cinfo.fInfo);
577 } 577 }
578
579 SkMatrix initialTransform;
580 initialTransform.reset();
581 SkISize size = SkISize::Make(cinfo.fInfo.width(), cinfo.fInfo.height()); 578 SkISize size = SkISize::Make(cinfo.fInfo.width(), cinfo.fInfo.height());
582 return SkNEW_ARGS(SkPDFDevice, (size, size, initialTransform)); 579 return SkPDFDevice::Create(size, fRasterDpi, fCanon);
583 } 580 }
584 581
585 582
586 struct ContentEntry { 583 struct ContentEntry {
587 GraphicStateEntry fState; 584 GraphicStateEntry fState;
588 SkDynamicMemoryWStream fContent; 585 SkDynamicMemoryWStream fContent;
589 SkAutoTDelete<ContentEntry> fNext; 586 SkAutoTDelete<ContentEntry> fNext;
590 587
591 // If the stack is too deep we could get Stack Overflow. 588 // If the stack is too deep we could get Stack Overflow.
592 // So we manually destruct the object. 589 // So we manually destruct the object.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 paint.getXfermode()->asMode(&fXfermode); 685 paint.getXfermode()->asMode(&fXfermode);
689 } 686 }
690 fContentEntry = fDevice->setUpContentEntry(clipStack, clipRegion, 687 fContentEntry = fDevice->setUpContentEntry(clipStack, clipRegion,
691 matrix, paint, hasText, 688 matrix, paint, hasText,
692 &fDstFormXObject); 689 &fDstFormXObject);
693 } 690 }
694 }; 691 };
695 692
696 //////////////////////////////////////////////////////////////////////////////// 693 ////////////////////////////////////////////////////////////////////////////////
697 694
698 static inline SkImageInfo make_content_info(const SkISize& contentSize, 695 SkPDFDevice::SkPDFDevice(SkISize pageSize,
699 const SkMatrix* initialTransform) { 696 SkScalar rasterDpi,
700 SkImageInfo info; 697 SkPDFCanon* canon,
701 if (initialTransform) { 698 bool flip)
702 // Compute the size of the drawing area.
703 SkVector drawingSize;
704 SkMatrix inverse;
705 drawingSize.set(SkIntToScalar(contentSize.fWidth),
706 SkIntToScalar(contentSize.fHeight));
707 if (!initialTransform->invert(&inverse)) {
708 // This shouldn't happen, initial transform should be invertible.
709 SkASSERT(false);
710 inverse.reset();
711 }
712 inverse.mapVectors(&drawingSize, 1);
713 SkISize size = SkSize::Make(drawingSize.fX, drawingSize.fY).toRound();
714 info = SkImageInfo::MakeUnknown(abs(size.fWidth), abs(size.fHeight));
715 } else {
716 info = SkImageInfo::MakeUnknown(abs(contentSize.fWidth),
717 abs(contentSize.fHeight));
718 }
719 return info;
720 }
721
722 // TODO(vandebo) change pageSize to SkSize.
723 SkPDFDevice::SkPDFDevice(const SkISize& pageSize, const SkISize& contentSize,
724 const SkMatrix& initialTransform)
725 : fPageSize(pageSize) 699 : fPageSize(pageSize)
726 , fContentSize(contentSize) 700 , fContentSize(pageSize)
701 , fExistingClipRegion(SkIRect::MakeSize(pageSize))
702 , fAnnotations(NULL)
703 , fResourceDict(NULL)
727 , fLastContentEntry(NULL) 704 , fLastContentEntry(NULL)
728 , fLastMarginContentEntry(NULL) 705 , fLastMarginContentEntry(NULL)
706 , fDrawingArea(kContent_DrawingArea)
729 , fClipStack(NULL) 707 , fClipStack(NULL)
708 , fFontGlyphUsage(SkNEW(SkPDFGlyphSetMap))
730 , fEncoder(NULL) 709 , fEncoder(NULL)
731 , fRasterDpi(72.0f) 710 , fRasterDpi(rasterDpi)
732 { 711 , fCanon(canon) {
733 const SkImageInfo info = make_content_info(contentSize, &initialTransform); 712 SkASSERT(pageSize.width() > 0);
734 713 SkASSERT(pageSize.height() > 0);
735 // Just report that PDF does not supports perspective in the 714 fLegacyBitmap.setInfo(
736 // initial transform. 715 SkImageInfo::MakeUnknown(pageSize.width(), pageSize.height()));
737 NOT_IMPLEMENTED(initialTransform.hasPerspective(), true); 716 if (flip) {
738 717 // Skia generally uses the top left as the origin but PDF
739 // Skia generally uses the top left as the origin but PDF natively has the 718 // natively has the origin at the bottom left. This matrix
740 // origin at the bottom left. This matrix corrects for that. But that only 719 // corrects for that. But that only needs to be done once, we
741 // needs to be done once, we don't do it when layering. 720 // don't do it when layering.
742 fInitialTransform.setTranslate(0, SkIntToScalar(pageSize.fHeight)); 721 fInitialTransform.setTranslate(0, SkIntToScalar(pageSize.fHeight));
743 fInitialTransform.preScale(SK_Scalar1, -SK_Scalar1); 722 fInitialTransform.preScale(SK_Scalar1, -SK_Scalar1);
744 fInitialTransform.preConcat(initialTransform); 723 } else {
745 fLegacyBitmap.setInfo(info); 724 fInitialTransform.setIdentity();
746 725 }
747 SkIRect existingClip = info.bounds();
748 fExistingClipRegion.setRect(existingClip);
749 this->init();
750 }
751
752 // TODO(vandebo) change layerSize to SkSize.
753 SkPDFDevice::SkPDFDevice(const SkISize& layerSize,
754 const SkClipStack& existingClipStack,
755 const SkRegion& existingClipRegion)
756 : fPageSize(layerSize)
757 , fContentSize(layerSize)
758 , fExistingClipStack(existingClipStack)
759 , fExistingClipRegion(existingClipRegion)
760 , fLastContentEntry(NULL)
761 , fLastMarginContentEntry(NULL)
762 , fClipStack(NULL)
763 , fEncoder(NULL)
764 , fRasterDpi(72.0f)
765 {
766 fInitialTransform.reset();
767 fLegacyBitmap.setInfo(make_content_info(layerSize, NULL));
768
769 this->init();
770 } 726 }
771 727
772 SkPDFDevice::~SkPDFDevice() { 728 SkPDFDevice::~SkPDFDevice() {
773 this->cleanUp(true); 729 this->cleanUp(true);
774 } 730 }
775 731
776 void SkPDFDevice::init() { 732 void SkPDFDevice::init() {
777 fAnnotations = NULL; 733 fAnnotations = NULL;
778 fResourceDict = NULL; 734 fResourceDict = NULL;
779 fContentEntries.free(); 735 fContentEntries.free();
(...skipping 1400 matching lines...) Expand 10 before | Expand all | Expand 10 after
2180 SkAutoTUnref<SkPDFObject> image( 2136 SkAutoTUnref<SkPDFObject> image(
2181 SkPDFCreateImageObject(*bitmap, subset, fEncoder)); 2137 SkPDFCreateImageObject(*bitmap, subset, fEncoder));
2182 if (!image) { 2138 if (!image) {
2183 return; 2139 return;
2184 } 2140 }
2185 2141
2186 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()), 2142 SkPDFUtils::DrawFormXObject(this->addXObjectResource(image.get()),
2187 &content.entry()->fContent); 2143 &content.entry()->fContent);
2188 } 2144 }
2189 2145
OLDNEW
« no previous file with comments | « src/pdf/SkPDFDevice.h ('k') | src/pdf/SkPDFShader.cpp » ('j') | src/pdf/SkPDFShader.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698