| 851 | } |
| 852 | |
| 853 | bool TessPDFRenderer::AddImageHandler(TessBaseAPI* api) { |
| 854 | size_t n; |
| 855 | char buf[kBasicBufSize]; |
| 856 | char buf2[kBasicBufSize]; |
| 857 | Pix *pix = api->GetInputImage(); |
| 858 | char *filename = (char *)api->GetInputName(); |
| 859 | int ppi = api->GetSourceYResolution(); |
| 860 | if (!pix || ppi <= 0) |
| 861 | return false; |
| 862 | double width = pixGetWidth(pix) * 72.0 / ppi; |
| 863 | double height = pixGetHeight(pix) * 72.0 / ppi; |
| 864 | |
| 865 | snprintf(buf2, sizeof(buf2), "/XObject << /Im1 %ld 0 R >>\n", obj_ + 2); |
| 866 | const char *xobject = (textonly_) ? "" : buf2; |
| 867 | |
| 868 | // PAGE |
| 869 | n = snprintf(buf, sizeof(buf), |
| 870 | "%ld 0 obj\n" |
| 871 | "<<\n" |
| 872 | " /Type /Page\n" |
| 873 | " /Parent %ld 0 R\n" |
| 874 | " /MediaBox [0 0 %.2f %.2f]\n" |
| 875 | " /Contents %ld 0 R\n" |
| 876 | " /Resources\n" |
| 877 | " <<\n" |
| 878 | " %s" |
| 879 | " /ProcSet [ /PDF /Text /ImageB /ImageI /ImageC ]\n" |
| 880 | " /Font << /f-0-0 %ld 0 R >>\n" |
| 881 | " >>\n" |
| 882 | ">>\n" |
| 883 | "endobj\n", |
| 884 | obj_, |
| 885 | 2L, // Pages object |
| 886 | width, height, |
| 887 | obj_ + 1, // Contents object |
| 888 | xobject, // Image object |
| 889 | 3L); // Type0 Font |
| 890 | if (n >= sizeof(buf)) return false; |
| 891 | pages_.push_back(obj_); |
| 892 | AppendPDFObject(buf); |
| 893 | |
| 894 | // CONTENTS |
| 895 | char* pdftext = GetPDFTextObjects(api, width, height); |
| 896 | long pdftext_len = strlen(pdftext); |
| 897 | unsigned char *pdftext_casted = reinterpret_cast<unsigned char *>(pdftext); |
| 898 | size_t len; |
| 899 | unsigned char *comp_pdftext = |
| 900 | zlibCompress(pdftext_casted, pdftext_len, &len); |
| 901 | long comp_pdftext_len = len; |
| 902 | n = snprintf(buf, sizeof(buf), |
| 903 | "%ld 0 obj\n" |
| 904 | "<<\n" |
| 905 | " /Length %ld /Filter /FlateDecode\n" |
| 906 | ">>\n" |
| 907 | "stream\n", obj_, comp_pdftext_len); |
| 908 | if (n >= sizeof(buf)) { |
| 909 | delete[] pdftext; |
| 910 | lept_free(comp_pdftext); |
nothing calls this directly
no test coverage detected