Exemplo n.º 1
0
/** 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;
}
Exemplo n.º 2
0
/** Write the output of pdf renderer to a file.
 * @param outputDir Output dir.
 * @param inputFilename The skp file that was read.
 * @param renderer The object responsible to write the pdf file.
 */
static bool write_output(const SkString& outputDir,
                         const SkString& inputFilename,
                         const sk_tools::PdfRenderer& renderer) {
    if (outputDir.isEmpty()) {
        SkDynamicMemoryWStream stream;
        renderer.write(&stream);
        return true;
    }

    SkString outputPath;
    if (!make_output_filepath(&outputPath, outputDir, inputFilename)) {
        return false;
    }

    SkFILEWStream stream(outputPath.c_str());
    if (!stream.isValid()) {
        SkDebugf("Could not write to file %s\n", outputPath.c_str());
        return false;
    }
    renderer.write(&stream);

    return true;
}
Exemplo n.º 3
0
/** 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;
}