/** Reads an skp file, renders it to pdf and writes the output to a pdf file * @param inputPath The skp file to be read. * @param outputDir Output dir. * @param renderer The object responsible to render the skp object into pdf. */ static bool render_pdf(const SkString& inputPath, const SkString& outputDir, sk_tools::PdfRenderer& renderer) { SkString inputFilename; sk_tools::get_basename(&inputFilename, inputPath); SkFILEStream inputStream; inputStream.setPath(inputPath.c_str()); if (!inputStream.isValid()) { SkDebugf("Could not open file %s\n", inputPath.c_str()); return false; } bool success = false; SkAutoTUnref<SkPicture> picture(SkNEW_ARGS(SkPicture, (&inputStream, &success))); if (!success) { SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str()); return false; } SkDebugf("exporting... [%i %i] %s\n", picture->width(), picture->height(), inputPath.c_str()); renderer.init(picture); renderer.render(); success = write_output(outputDir, inputFilename, renderer); renderer.end(); return success; }
/** Reads an skp file, renders it to pdf and writes the output to a pdf file * @param inputPath The skp file to be read. * @param outputDir Output dir. * @param renderer The object responsible to render the skp object into pdf. */ static bool render_pdf(const SkString& inputPath, const SkString& outputDir, sk_tools::PdfRenderer& renderer) { SkString inputFilename; sk_tools::get_basename(&inputFilename, inputPath); SkFILEStream inputStream; inputStream.setPath(inputPath.c_str()); if (!inputStream.isValid()) { SkDebugf("Could not open file %s\n", inputPath.c_str()); return false; } SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream)); if (NULL == picture.get()) { SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str()); return false; } SkDebugf("exporting... [%i %i] %s\n", picture->width(), picture->height(), inputPath.c_str()); SkWStream* stream(open_stream(outputDir, inputFilename)); if (!stream) { return false; } renderer.init(picture, stream); bool success = renderer.render(); SkDELETE(stream); renderer.end(); return success; }