X-Git-Url: http://downloads.foxitsoftware.com/web/?p=pdfium.git;a=blobdiff_plain;f=samples%2Fpdfium_test.cc;h=cb8fef324e55a0376d103a0da549dc8d6d7575ea;hp=0d76b63f26cb866d78372b0e6c05d78b0ee66cf0;hb=388a3b0b8d6f75d47978c08299300f121f04884c;hpb=281d1d293dab54cadd214e5a1c098583fbbe0788 diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc index 0d76b63..cb8fef3 100644 --- a/samples/pdfium_test.cc +++ b/samples/pdfium_test.cc @@ -46,6 +46,7 @@ struct Options { std::string scale_factor_as_string; std::string exe_path; std::string bin_directory; + std::string font_directory; }; // Reads the entire contents of a file into a newly malloc'd buffer. @@ -143,22 +144,20 @@ static void WritePpm(const char* pdf_name, int num, const void* buffer_void, // Source data is B, G, R, unused. // Dest data is R, G, B. char* result = new char[out_len]; - if (result) { - for (int h = 0; h < height; ++h) { - const char* src_line = buffer + (stride * h); - char* dest_line = result + (width * h * 3); - for (int w = 0; w < width; ++w) { - // R - dest_line[w * 3] = src_line[(w * 4) + 2]; - // G - dest_line[(w * 3) + 1] = src_line[(w * 4) + 1]; - // B - dest_line[(w * 3) + 2] = src_line[w * 4]; - } + for (int h = 0; h < height; ++h) { + const char* src_line = buffer + (stride * h); + char* dest_line = result + (width * h * 3); + for (int w = 0; w < width; ++w) { + // R + dest_line[w * 3] = src_line[(w * 4) + 2]; + // G + dest_line[(w * 3) + 1] = src_line[(w * 4) + 1]; + // B + dest_line[(w * 3) + 2] = src_line[w * 4]; } - fwrite(result, out_len, 1, fp); - delete [] result; } + fwrite(result, out_len, 1, fp); + delete[] result; fclose(fp); } @@ -347,7 +346,15 @@ bool ParseCommandLine(const std::vector& args, return false; } options->output_format = OUTPUT_PNG; + } else if (cur_arg.size() > 11 && + cur_arg.compare(0, 11, "--font-dir=") == 0) { + if (!options->font_directory.empty()) { + fprintf(stderr, "Duplicate --font-dir argument\n"); + return false; + } + options->font_directory = cur_arg.substr(11); } + #ifdef _WIN32 else if (cur_arg == "--emf") { if (options->output_format != OUTPUT_NONE) { @@ -560,8 +567,9 @@ void RenderPdf(const std::string& name, const char* pBuf, size_t len, static const char usage_string[] = "Usage: pdfium_test [OPTION] [FILE]...\n" - " --bin-dir= - override path to v8 external data\n" - " --scale= - scale output size by number (e.g. 0.5)\n" + " --bin-dir= - override path to v8 external data\n" + " --font-dir= - override path to external fonts\n" + " --scale= - scale output size by number (e.g. 0.5)\n" #ifdef _WIN32 " --bmp - write page images ..bmp\n" " --emf - write page meta files ..emf\n" @@ -599,7 +607,17 @@ int main(int argc, const char* argv[]) { v8::V8::SetSnapshotDataBlob(&snapshot); #endif // V8_USE_EXTERNAL_STARTUP_DATA - FPDF_InitLibrary(); + if (!options.font_directory.empty()) { + const char* path_array[2]; + path_array[0] = options.font_directory.c_str(); + path_array[1] = nullptr; + FPDF_LIBRARY_CONFIG config; + config.version = 1; + config.m_pUserFontPaths = path_array; + FPDF_InitLibraryWithConfig(&config); + } else { + FPDF_InitLibrary(); + } UNSUPPORT_INFO unsuppored_info; memset(&unsuppored_info, '\0', sizeof(unsuppored_info));