void CReporter::Print( CommonDataType::ReportType rType ) { if ( !GetAdboeExePath( strAdobeExe ) ) { return; } KillAdobeProcess( strAdobeExe ); printer.setPageSize( QPrinter::A4 ); printer.setOutputFormat( QPrinter::PdfFormat ); QString strFile; CCommonFunction::GetPath( strFile, CommonDataType::PathSnapshot ); strFile += "reporter.pdf"; if ( QFile::exists( strFile ) ) { QFile::remove( strFile ); Sleep( 1000 ); } printer.setOutputFileName( strFile ); pReportView->print( &printer ); //Call Adobe Reader print pdf PrintPdf( strFile ); }
int main(int argc, const char* argv[]) { int N = 100000000; int pdf_type = 2; int pdf_param = 5; int max_symbol = MAX_SYMBOLS; int print_pdf = 0; int log_tab_size = LOG_TAB_SIZE; FSCCodingMethod method = CODING_METHOD_DEFAULT; const char* in_file = NULL; const char* pdf_file = NULL; int c; for (c = 1; c < argc; ++c) { if (!strcmp(argv[c], "-t") && c + 1 < argc) { pdf_type = atoi(argv[++c]); if (pdf_type < 0) pdf_type = 0; else if (pdf_type > 5) pdf_type = 5; } else if (!strcmp(argv[c], "-p") && c + 1 < argc) { pdf_param = atoi(argv[++c]); if (pdf_type < 0) pdf_param = 0; } else if (!strcmp(argv[c], "-s") && c + 1 < argc) { max_symbol = atoi(argv[++c]); if (max_symbol < 2) max_symbol = 2; else if (max_symbol > 256) max_symbol = 256; } else if (!strcmp(argv[c], "-l") && c + 1 < argc) { log_tab_size = atoi(argv[++c]); if (log_tab_size > LOG_TAB_SIZE) log_tab_size = LOG_TAB_SIZE; } else if (!strcmp(argv[c], "-f") && c + 1 < argc) { in_file = argv[++c]; } else if (FSCParseCodingMethodOpt(argv[c], &method)) { continue; } else if (!strcmp(argv[c], "-m") && c + 1 < argc) { method = (FSCCodingMethod)atoi(argv[++c]); } else if (!strcmp(argv[c], "-save") && c + 1 < argc) { pdf_file = argv[++c]; } else if (!strcmp(argv[c], "-d")) { print_pdf = 1; } else if (!strcmp(argv[c], "-h")) { Help(); } else { N = atoi(argv[c]); if (N <= 2) N = 2; } } uint8_t* base; FILE* file = NULL; if (in_file != NULL) { file = fopen(in_file, "rb"); if (file == NULL) { fprintf(stderr, "Error opening file %s!\n", in_file); exit(-1); } fseek(file, 0L, SEEK_END); N = ftell(file); fseek(file, 0L, SEEK_SET); printf("Read File [%s] (%d bytes)\n", in_file, N); } base = (uint8_t*)malloc(N * sizeof(*base)); if (base == NULL) { fprintf(stderr, "Malloc(%d) failed!\n", N); exit(-1); } if (file != NULL) { N = fread(base, 1, N, file); fclose(file); } else { uint32_t pdf[256] = { 0 }; int i; FSCRandom r; FSCInitRandom(&r); const int total = GeneratePdf(pdf_type, pdf_param, pdf, &r, max_symbol); const int nb_bits = 1 + log2(total - 1); uint64_t cumul[256 + 1]; cumul[0] = 0; for (i = 1; i <= max_symbol; ++i) { cumul[i] = cumul[i - 1] + pdf[i - 1]; } for (i = 0; i < N; ++i) { base[i] = DrawSymbol(cumul, max_symbol, total, nb_bits, &r); } } printf("PDF generated OK (max symbol:%d).\n", max_symbol); if (print_pdf) { PrintPdf(base, N); printf("[Params: type=%d param=%d max_symbol=%d size=%d]\n", pdf_type, pdf_param, max_symbol, N); } if (pdf_file != NULL) { SavePdfToFile(base, N, pdf_file); } const double entropy = GetEntropy(base, N); int nb_errors = 0; uint8_t* out = NULL; size_t out_size = 0; // Encode uint8_t* bits = NULL; size_t bits_size = 0; MyClock start, tmp; GetElapsed(&start, NULL); int ok = FSCEncode(base, N, &bits, &bits_size, log_tab_size, method); double elapsed = GetElapsed(&tmp, &start); const double MS = 1.e-6 * N; // 8.e-6 * bits_size; const double reduction = 1. * bits_size / N; printf("Enc time: %.3f sec [%.2lf MS/s] (%ld bytes out, %d in).\n", elapsed, MS / elapsed, bits_size, N); printf("Entropy: %.4lf vs expected %.4lf " "(off by %.5lf bit/symbol [%.3lf%%])\n", reduction, entropy, reduction - entropy, 100. * (reduction - entropy) / entropy); if (!ok) { fprintf(stderr, "ERROR while encoding!\n"); nb_errors = 1; } else { // Decode GetElapsed(&start, NULL); ok = FSCDecode(bits, bits_size, &out, &out_size); elapsed = GetElapsed(&tmp, &start); printf("Dec time: %.3f sec [%.2lf MS/s].\n", elapsed, MS / elapsed); ok &= (out_size == N); if (!ok) { fprintf(stderr, "Decoding error!\n"); nb_errors = 1; } else { int i; for (i = 0; i < N; ++i) { nb_errors += (out[i] != base[i]); } printf("#%d errors\n", nb_errors); if (nb_errors) fprintf(stderr, "*** PROBLEM!! ***\n"); } } End: free(base); free(out); free(bits); return (nb_errors != 0); }