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

Unified Diff: samplecode/SampleApp.cpp

Issue 17904006: Add an option to have a PdfViewer in SampleApp. Add a parameter --pdfDir to pass the dir with pdfs.… (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: samplecode/SampleApp.cpp
===================================================================
--- samplecode/SampleApp.cpp (revision 9765)
+++ samplecode/SampleApp.cpp (working copy)
@@ -15,6 +15,7 @@
#include "SkPaint.h"
#include "SkPicture.h"
#include "SkStream.h"
+#include "SkTSort.h"
#include "SkTime.h"
#include "SkWindow.h"
@@ -54,6 +55,19 @@
}
};
+#ifdef SAMPLE_PDF_FILE_VIEWER
+extern SampleView* CreateSamplePdfFileViewer(const char filename[]);
+
+class PdfFileViewerFactory : public SkViewFactory {
+ SkString fFilename;
vandebo (ex-Chrome) 2013/06/26 21:58:36 private?
edisonn 2013/07/02 23:20:33 Done.
+public:
+ PdfFileViewerFactory(const SkString& filename) : fFilename(filename) {}
+ virtual SkView* operator() () const SK_OVERRIDE {
+ return CreateSamplePdfFileViewer(fFilename.c_str());
+ }
+};
+#endif // SAMPLE_PDF_FILE_VIEWER
+
#define PIPE_FILEx
#ifdef PIPE_FILE
#define FILE_PATH "/path/to/drawing.data"
@@ -691,6 +705,10 @@
static void usage(const char * argv0) {
SkDebugf("%s [--slide sampleName] [-i resourcePath] [--msaa sampleCount] [--pictureDir dirPath] [--picture path]\n", argv0);
+#ifdef SAMPLE_PDF_FILE_VIEWER
+ SkDebugf(" [--pdfDir pdfPath]\n");
+ SkDebugf(" pdfPath: path to directory pdf files are read from\n");
+#endif // SAMPLE_PDF_FILE_VIEWER
SkDebugf(" sampleName: sample at which to start.\n");
SkDebugf(" resourcePath: directory that stores image resources.\n");
SkDebugf(" msaa: request multisampling with the given sample count.\n");
@@ -698,6 +716,18 @@
SkDebugf(" path: path to skia picture\n");
}
+static SkString getSampleTitle(const SkViewFactory* sampleFactory) {
+ SkView* view = (*sampleFactory)();
+ SkString title;
+ SampleCode::RequestTitle(view, &title);
+ view->unref();
+ return title;
+}
+
+bool compareSampleTitle(const SkViewFactory* first, const SkViewFactory* second) {
+ return strcmp(getSampleTitle(first).c_str(), getSampleTitle(second).c_str()) < 0;
+}
+
SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* devManager)
: INHERITED(hwnd)
, fDevManager(NULL) {
@@ -706,6 +736,9 @@
this->registerPictFileSamples(argv, argc);
this->registerPictFileSample(argv, argc);
+#ifdef SAMPLE_PDF_FILE_VIEWER
+ this->registerPdfFileViewerSamples(argv, argc);
+#endif // SAMPLE_PDF_FILE_VIEWER
SkGMRegistyToSampleRegistry();
{
const SkViewRegister* reg = SkViewRegister::Head();
@@ -715,6 +748,12 @@
}
}
+#ifdef SAMPLE_PDF_FILE_VIEWER
+ // Sort samples, so foo.skp and foo.pdf are consecutive and we can quickly spot where
+ // skp -> pdf -> png fails.
+ SkTQSort(fSamples.begin(), fSamples.end() ? fSamples.end() - 1 : NULL, compareSampleTitle);
+#endif // SAMPLE_PDF_FILE_VIEWER
+
const char* resourcePath = NULL;
fMSAASampleCount = 0;
@@ -969,6 +1008,32 @@
}
}
+#ifdef SAMPLE_PDF_FILE_VIEWER
+void SampleWindow::registerPdfFileViewerSamples(char** argv, int argc) {
+ const char* pdfDir = NULL;
+
+ for (int i = 0; i < argc; ++i) {
+ if (!strcmp(argv[i], "--pdfDir")) {
+ i += 1;
+ if (i < argc) {
+ pdfDir = argv[i];
+ break;
+ }
+ }
+ }
+ if (pdfDir) {
+ SkOSFile::Iter iter(pdfDir, "pdf");
+ SkString filename;
+ while (iter.next(&filename)) {
+ SkString path;
+ make_filepath(&path, pdfDir, filename);
+ *fSamples.append() = new PdfFileViewerFactory(path);
+ }
+ }
+}
+#endif // SAMPLE_PDF_FILE_VIEWER
+
+
int SampleWindow::findByTitle(const char title[]) {
int i, count = fSamples.count();
for (i = 0; i < count; i++) {
@@ -1534,11 +1599,7 @@
}
SkString SampleWindow::getSampleTitle(int i) {
- SkView* view = (*fSamples[i])();
- SkString title;
- SampleCode::RequestTitle(view, &title);
- view->unref();
- return title;
+ return ::getSampleTitle(fSamples[i]);
}
int SampleWindow::sampleCount() {

Powered by Google App Engine
This is Rietveld 408576698