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

Side by Side Diff: gm/gmmain.cpp

Issue 839603002: Revert "Remove SkPDFDocument and SkPDFDevice from the public headers." (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | gyp/pdf.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /* 8 /*
9 * Code for the "gm" (Golden Master) rendering comparison tool. 9 * Code for the "gm" (Golden Master) rendering comparison tool.
10 * 10 *
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 #else 67 #else
68 class GrContextFactory; 68 class GrContextFactory;
69 class GrContext; 69 class GrContext;
70 class GrSurface; 70 class GrSurface;
71 typedef int GLContextType; 71 typedef int GLContextType;
72 typedef int GrGLStandard; 72 typedef int GrGLStandard;
73 #endif 73 #endif
74 74
75 #define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message") 75 #define DEBUGFAIL_SEE_STDERR SkDEBUGFAIL("see stderr for message")
76 76
77 DECLARE_bool(useDocumentInsteadOfDevice);
78
79 #ifdef SK_SUPPORT_PDF
80 #include "SkPDFDevice.h"
81 #include "SkPDFDocument.h"
82 #endif
83
77 // Until we resolve http://code.google.com/p/skia/issues/detail?id=455 , 84 // Until we resolve http://code.google.com/p/skia/issues/detail?id=455 ,
78 // stop writing out XPS-format image baselines in gm. 85 // stop writing out XPS-format image baselines in gm.
79 #undef SK_SUPPORT_XPS 86 #undef SK_SUPPORT_XPS
80 #ifdef SK_SUPPORT_XPS 87 #ifdef SK_SUPPORT_XPS
81 #include "SkXPSDevice.h" 88 #include "SkXPSDevice.h"
82 #endif 89 #endif
83 90
84 #ifdef SK_BUILD_FOR_MAC 91 #ifdef SK_BUILD_FOR_MAC
85 #include "SkCGUtils.h" 92 #include "SkCGUtils.h"
86 #endif 93 #endif
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 668
662 setup_bitmap(config, size, bitmap); 669 setup_bitmap(config, size, bitmap);
663 670
664 surf->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes() , 0, 0); 671 surf->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes() , 0, 0);
665 672
666 complete_bitmap(bitmap); 673 complete_bitmap(bitmap);
667 } 674 }
668 675
669 static bool generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) { 676 static bool generate_pdf(GM* gm, SkDynamicMemoryWStream& pdf) {
670 #ifdef SK_SUPPORT_PDF 677 #ifdef SK_SUPPORT_PDF
671 SkAutoTUnref<SkDocument> pdfDoc( 678 SkMatrix initialTransform = gm->getInitialTransform();
672 SkDocument::CreatePDF(&pdf, NULL, encode_to_dct_data, 679 if (FLAGS_useDocumentInsteadOfDevice) {
673 SkIntToScalar(FLAGS_pdfRasterDpi))); 680 SkISize pageISize = gm->getISize();
674 if (!pdfDoc) { 681 SkAutoTUnref<SkDocument> pdfDoc(
675 return false; 682 SkDocument::CreatePDF(&pdf, NULL,
683 encode_to_dct_data,
684 SkIntToScalar(FLAGS_pdfRasterDpi)));
685
686 if (!pdfDoc.get()) {
687 return false;
688 }
689
690 SkCanvas* canvas = NULL;
691 canvas = pdfDoc->beginPage(SkIntToScalar(pageISize.width()),
692 SkIntToScalar(pageISize.height()));
693 canvas->concat(initialTransform);
694
695 invokeGM(gm, canvas, true, false);
696
697 return pdfDoc->close();
698 } else {
699 SkISize pageSize = gm->getISize();
700 SkPDFDevice* dev = NULL;
701 if (initialTransform.isIdentity()) {
702 dev = new SkPDFDevice(pageSize, pageSize, initialTransform);
703 } else {
704 SkRect content = SkRect::MakeWH(SkIntToScalar(pageSize.width()),
705 SkIntToScalar(pageSize.height()) );
706 initialTransform.mapRect(&content);
707 content.intersect(0, 0, SkIntToScalar(pageSize.width()),
708 SkIntToScalar(pageSize.height()));
709 SkISize contentSize =
710 SkISize::Make(SkScalarRoundToInt(content.width()),
711 SkScalarRoundToInt(content.height()));
712 dev = new SkPDFDevice(pageSize, contentSize, initialTransform);
713 }
714 dev->setDCTEncoder(encode_to_dct_data);
715 dev->setRasterDpi(SkIntToScalar(FLAGS_pdfRasterDpi));
716 SkAutoUnref aur(dev);
717 SkCanvas c(dev);
718 invokeGM(gm, &c, true, false);
719 SkPDFDocument doc;
720 doc.appendPage(dev);
721 doc.emitPDF(&pdf);
676 } 722 }
677
678 SkCanvas* canvas = NULL;
679 canvas = pdfDoc->beginPage(gm->width(), gm->height());
680 canvas->concat(gm->getInitialTransform());
681
682 invokeGM(gm, canvas, true, false);
683
684 return pdfDoc->close();
685
686 #else // SK_SUPPORT_PDF
687 return true; // Do not report failure if pdf is not supported.
688 #endif // SK_SUPPORT_PDF 723 #endif // SK_SUPPORT_PDF
724 return true; // Do not report failure if pdf is not supported.
689 } 725 }
690 726
691 static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) { 727 static void generate_xps(GM* gm, SkDynamicMemoryWStream& xps) {
692 #ifdef SK_SUPPORT_XPS 728 #ifdef SK_SUPPORT_XPS
693 SkISize size = gm->getISize(); 729 SkISize size = gm->getISize();
694 730
695 SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()), 731 SkSize trimSize = SkSize::Make(SkIntToScalar(size.width()),
696 SkIntToScalar(size.height())); 732 SkIntToScalar(size.height()));
697 static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254); 733 static const SkScalar inchesPerMeter = SkScalarDiv(10000, 254);
698 static const SkScalar upm = 72 * inchesPerMeter; 734 static const SkScalar upm = 72 * inchesPerMeter;
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, " 1571 DEFINE_int32(pdfJpegQuality, -1, "Encodes images in JPEG at quality level N, "
1536 "which can be in range 0-100). N = -1 will disable JPEG compression . " 1572 "which can be in range 0-100). N = -1 will disable JPEG compression . "
1537 "Default is N = 100, maximum quality."); 1573 "Default is N = 100, maximum quality.");
1538 // TODO(edisonn): pass a matrix instead of forcePerspectiveMatrix 1574 // TODO(edisonn): pass a matrix instead of forcePerspectiveMatrix
1539 // Either the 9 numbers defining the matrix 1575 // Either the 9 numbers defining the matrix
1540 // or probably more readable would be to replace it with a set of a few predicat es 1576 // or probably more readable would be to replace it with a set of a few predicat es
1541 // Like --prerotate 100 200 10 --posttranslate 10, 10 1577 // Like --prerotate 100 200 10 --posttranslate 10, 10
1542 // Probably define spacial names like centerx, centery, top, bottom, left, right 1578 // Probably define spacial names like centerx, centery, top, bottom, left, right
1543 // then we can write something reabable like --rotate centerx centery 90 1579 // then we can write something reabable like --rotate centerx centery 90
1544 DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix."); 1580 DEFINE_bool(forcePerspectiveMatrix, false, "Force a perspective matrix.");
1581 DEFINE_bool(useDocumentInsteadOfDevice, false, "Use SkDocument::CreateFoo instea d of SkFooDevice.");
1545 DEFINE_int32(pdfRasterDpi, 72, "Scale at which at which the non suported " 1582 DEFINE_int32(pdfRasterDpi, 72, "Scale at which at which the non suported "
1546 "features in PDF are rasterized. Must be be in range 0-10000. " 1583 "features in PDF are rasterized. Must be be in range 0-10000. "
1547 "Default is 72. N = 0 will disable rasterizing features like " 1584 "Default is 72. N = 0 will disable rasterizing features like "
1548 "text shadows or perspective bitmaps."); 1585 "text shadows or perspective bitmaps.");
1549 static SkData* encode_to_dct_data(size_t*, const SkBitmap& bitmap) { 1586 static SkData* encode_to_dct_data(size_t*, const SkBitmap& bitmap) {
1550 // Filter output of warnings that JPEG is not available for the image. 1587 // Filter output of warnings that JPEG is not available for the image.
1551 if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return NULL; 1588 if (bitmap.width() >= 65500 || bitmap.height() >= 65500) return NULL;
1552 if (FLAGS_pdfJpegQuality == -1) return NULL; 1589 if (FLAGS_pdfJpegQuality == -1) return NULL;
1553 1590
1554 SkBitmap bm = bitmap; 1591 SkBitmap bm = bitmap;
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after
2543 if (FLAGS_forceBWtext) { 2580 if (FLAGS_forceBWtext) {
2544 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); 2581 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref();
2545 } 2582 }
2546 } 2583 }
2547 2584
2548 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) 2585 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
2549 int main(int argc, char * const argv[]) { 2586 int main(int argc, char * const argv[]) {
2550 return tool_main(argc, (char**) argv); 2587 return tool_main(argc, (char**) argv);
2551 } 2588 }
2552 #endif 2589 #endif
OLDNEW
« no previous file with comments | « no previous file | gyp/pdf.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698