/** * Test that for Jpeg files that use the JFIF colorspace, they are * directly embedded into the PDF (without re-encoding) when that * makes sense. */ DEF_TEST(PDFJpegEmbedTest, r) { const char test[] = "PDFJpegEmbedTest"; SkAutoTUnref<SkData> mandrillData( load_resource(r, test, "mandrill_512_q075.jpg")); SkAutoTUnref<SkData> cmykData(load_resource(r, test, "CMYK.jpg")); if (!mandrillData || !cmykData) { return; } SkDynamicMemoryWStream pdf; SkAutoTUnref<SkDocument> document(SkDocument::CreatePDF(&pdf)); SkCanvas* canvas = document->beginPage(642, 1028); canvas->clear(SK_ColorLTGRAY); SkBitmap bm1(bitmap_from_data(mandrillData)); canvas->drawBitmap(bm1, 65.0, 0.0, NULL); SkBitmap bm2(bitmap_from_data(cmykData)); canvas->drawBitmap(bm2, 0.0, 512.0, NULL); canvas->flush(); document->endPage(); document->close(); SkAutoTUnref<SkData> pdfData(pdf.copyToData()); SkASSERT(pdfData); pdf.reset(); REPORTER_ASSERT(r, is_subset_of(mandrillData, pdfData)); // This JPEG uses a nonstandard colorspace - it can not be // embedded into the PDF directly. REPORTER_ASSERT(r, !is_subset_of(cmykData, pdfData)); }
static BaseEngine *ps2pdf(const WCHAR *fileName) { // TODO: read from gswin32c's stdout instead of using a TEMP file ScopedMem<WCHAR> shortPath(path::ShortPath(fileName)); ScopedMem<WCHAR> tmpFile(path::GetTempPath(L"PsE")); ScopedFile tmpFileScope(tmpFile); ScopedMem<WCHAR> gswin32c(GetGhostscriptPath()); if (!shortPath || !tmpFile || !gswin32c) return NULL; // try to help Ghostscript determine the intended page size ScopedMem<WCHAR> psSetup; RectI page = ExtractDSCPageSize(fileName); if (!page.IsEmpty()) psSetup.Set(str::Format(L" << /PageSize [%i %i] >> setpagedevice", page.dx, page.dy)); ScopedMem<WCHAR> cmdLine(str::Format( L"\"%s\" -q -dSAFER -dNOPAUSE -dBATCH -dEPSCrop -sOutputFile=\"%s\" -sDEVICE=pdfwrite -c \".setpdfwrite%s\" -f \"%s\"", gswin32c, tmpFile, psSetup ? psSetup : L"", shortPath)); fprintf(stderr, "- %s:%d: using '%ls' for creating '%%TEMP%%\\%ls'\n", path::GetBaseName(__FILE__), __LINE__, gswin32c.Get(), path::GetBaseName(tmpFile)); // TODO: the PS-to-PDF conversion can hang the UI for several seconds HANDLE process = LaunchProcess(cmdLine, NULL, CREATE_NO_WINDOW); if (!process) return NULL; DWORD timeout = 10000; #ifdef DEBUG // allow to disable the timeout for debugging purposes if (GetEnvironmentVariable(L"SUMATRAPDF_NO_GHOSTSCRIPT_TIMEOUT", NULL, 0)) timeout = INFINITE; #endif DWORD exitCode = EXIT_FAILURE; WaitForSingleObject(process, timeout); GetExitCodeProcess(process, &exitCode); TerminateProcess(process, 1); CloseHandle(process); if (exitCode != EXIT_SUCCESS) return NULL; size_t len; ScopedMem<char> pdfData(file::ReadAll(tmpFile, &len)); if (!pdfData) return NULL; ScopedComPtr<IStream> stream(CreateStreamFromData(pdfData, len)); if (!stream) return NULL; return PdfEngine::CreateFromStream(stream); }
/** * Test that for Jpeg files that use the JFIF colorspace, they are * directly embedded into the PDF (without re-encoding) when that * makes sense. */ DEF_TEST(PDFJpegEmbedTest, r) { const char test[] = "PDFJpegEmbedTest"; SkAutoTUnref<SkData> mandrillData( load_resource(r, test, "mandrill_512_q075.jpg")); SkAutoTUnref<SkData> cmykData(load_resource(r, test, "CMYK.jpg")); if (!mandrillData || !cmykData) { return; } SkDynamicMemoryWStream pdf; SkAutoTUnref<SkDocument> document(SkDocument::CreatePDF(&pdf)); SkCanvas* canvas = document->beginPage(642, 1028); canvas->clear(SK_ColorLTGRAY); SkBitmap bm1(bitmap_from_data(mandrillData)); canvas->drawBitmap(bm1, 65.0, 0.0, NULL); SkBitmap bm2(bitmap_from_data(cmykData)); canvas->drawBitmap(bm2, 0.0, 512.0, NULL); canvas->flush(); document->endPage(); document->close(); SkAutoTUnref<SkData> pdfData(pdf.copyToData()); SkASSERT(pdfData); pdf.reset(); // Test disabled, waiting on resolution to http://skbug.com/3180 // REPORTER_ASSERT(r, is_subset_of(mandrillData, pdfData)); // This JPEG uses a nonstandard colorspace - it can not be // embedded into the PDF directly. REPORTER_ASSERT(r, !is_subset_of(cmykData, pdfData)); // The following is for debugging purposes only. const char* outputPath = getenv("SKIA_TESTS_PDF_JPEG_EMBED_OUTPUT_PATH"); if (outputPath) { SkFILEWStream output(outputPath); if (output.isValid()) { output.write(pdfData->data(), pdfData->size()); } } }
static PdfEngine *ps2pdf(const WCHAR *fileName) { // TODO: read from gswin32c's stdout instead of using a TEMP file ScopedMem<WCHAR> shortPath(path::ShortPath(fileName)); ScopedMem<WCHAR> tmpFile(path::GetTempPath(L"PsE")); ScopedFile tmpFileScope(tmpFile); ScopedMem<WCHAR> gswin32c(GetGhostscriptPath()); if (!shortPath || !tmpFile || !gswin32c) return NULL; ScopedMem<WCHAR> cmdLine(str::Format(L"\"%s\" -q -dSAFER -dNOPAUSE -dBATCH -dEPSCrop -sOutputFile=\"%s\" -sDEVICE=pdfwrite -c .setpdfwrite -f \"%s\"", gswin32c, tmpFile, shortPath)); if (GetEnvironmentVariable(L"MULOG", NULL, 0)) { wprintf(L"ps2pdf: using Ghostscript from '%s'\n", gswin32c.Get()); wprintf(L"ps2pdf: for creating '%s'\n", tmpFile.Get()); } // TODO: the PS-to-PDF conversion can hang the UI for several seconds HANDLE process = LaunchProcess(cmdLine, NULL, CREATE_NO_WINDOW); if (!process) return NULL; DWORD exitCode = EXIT_FAILURE; WaitForSingleObject(process, 10000); GetExitCodeProcess(process, &exitCode); TerminateProcess(process, 1); CloseHandle(process); if (exitCode != EXIT_SUCCESS) return NULL; size_t len; ScopedMem<char> pdfData(file::ReadAll(tmpFile, &len)); if (!pdfData) return NULL; ScopedComPtr<IStream> stream(CreateStreamFromData(pdfData, len)); if (!stream) return NULL; if (GetEnvironmentVariable(L"MULOG", NULL, 0)) printf("ps2pdf: PDF conversion successful\n"); return PdfEngine::CreateFromStream(stream); }