97#include <config_auto.h>
101#include "allheaders.h"
108static l_int32 var_PS_WRITE_BOUNDING_BOX = 1;
111static const l_int32 DefaultInputRes = 300;
112static const l_int32 MinRes = 5;
113static const l_int32 MaxRes = 3000;
116static const l_int32 LetterWidth = 612;
117static const l_int32 LetterHeight = 792;
118static const l_int32 A4Width = 595;
119static const l_int32 A4Height = 842;
120static const l_float32 DefaultFillFraction = 0.95f;
140 l_int32 res, l_float32 scale,
141 l_float32 *pxpt, l_float32 *pypt,
142 l_float32 *pwpt, l_float32 *phpt);
145 l_int32 *pnbytes, l_int32 x, l_int32 y,
146 l_int32 res, l_float32 scale,
147 l_int32 pageno, l_int32 endpage);
149 l_float32 xpt, l_float32 ypt, l_float32 wpt,
150 l_float32 hpt, l_int32 pageno, l_int32 endpage);
152 l_int32 *pnbytes, l_int32 x, l_int32 y,
153 l_int32 res, l_float32 scale, l_int32 pageno,
154 l_int32 maskflag, l_int32 endpage);
156 l_float32 ypt, l_float32 wpt, l_float32 hpt,
157 l_int32 maskflag, l_int32 pageno, l_int32 endpage);
159 l_int32 *pnbytes, l_int32 x, l_int32 y,
160 l_int32 res, l_float32 scale,
161 l_int32 pageno, l_int32 endpage);
163 l_float32 xpt, l_float32 ypt, l_float32 wpt,
164 l_float32 hpt, l_int32 pageno, l_int32 endpage);
197 return ERROR_INT(
"filein not defined", __func__, 1);
199 return ERROR_INT(
"fileout not defined", __func__, 1);
201 if ((pix = pixRead(filein)) == NULL)
202 return ERROR_INT(
"image not read from file", __func__, 1);
203 w = pixGetWidth(pix);
204 h = pixGetHeight(pix);
205 if (w * 11.0 > h * 8.5)
206 scale = 8.5f * 300.f / (l_float32)w;
208 scale = 11.0f * 300.f / (l_float32)h;
210 if ((fp = fopenWriteStream(fileout,
"wb")) == NULL)
211 return ERROR_INT_1(
"file not opened for write", fileout, __func__, 1);
250 return (l_int32)ERROR_INT(
"stream not open", __func__, 1);
252 return (l_int32)ERROR_INT(
"pix not defined", __func__, 1);
254 if ((pixc = pixConvertForPSWrap(pix)) == NULL)
255 return (l_int32)ERROR_INT(
"pixc not made", __func__, 1);
259 return (l_int32)ERROR_INT(
"outstr not made", __func__, 1);
261 length = strlen(outstr);
262 fwrite(outstr, 1, length, fp);
343char *hexdata, *outstr;
345l_int32 i, j, k, w, h, d;
346l_float32 wpt, hpt, xpt, ypt;
347l_int32 wpl, psbpl, hexbytes, boxflag, bps;
348l_uint32 *line, *data;
352 return (
char *)ERROR_PTR(
"pixs not defined", __func__, NULL);
354 if ((pix = pixConvertForPSWrap(pixs)) == NULL)
355 return (
char *)ERROR_PTR(
"pix not made", __func__, NULL);
356 pixGetDimensions(pix, &w, &h, &d);
375 wpl = pixGetWpl(pix);
376 if (d == 1 || d == 8)
377 psbpl = (w * d + 7) / 8;
380 data = pixGetData(pix);
381 hexbytes = 2 * psbpl * h;
382 if ((hexdata = (
char *)LEPT_CALLOC(hexbytes + 1,
sizeof(
char))) == NULL)
383 return (
char *)ERROR_PTR(
"hexdata not made", __func__, NULL);
384 if (d == 1 || d == 8) {
385 for (i = 0, k = 0; i < h; i++) {
386 line = data + i * wpl;
387 for (j = 0; j < psbpl; j++) {
395 for (i = 0, k = 0; i < h; i++) {
396 line = data + i * wpl;
397 for (j = 0; j < w; j++) {
416 xpt, ypt, wpt, hpt, boxflag);
419 return (
char *)ERROR_PTR(
"outstr not made", __func__, NULL);
462 return (
char *)ERROR_PTR(
"hexdata not defined", __func__, NULL);
464 sa = sarrayCreate(0);
465 sarrayAddString(sa,
"%!Adobe-PS",
L_COPY);
467 snprintf(bigbuf,
sizeof(bigbuf),
468 "%%%%BoundingBox: %7.2f %7.2f %7.2f %7.2f",
469 xpt, ypt, xpt + wpt, ypt + hpt);
470 sarrayAddString(sa, bigbuf,
L_COPY);
472 sarrayAddString(sa,
"gsave",
L_COPY);
477 "{1 exch sub} settransfer %invert binary",
L_COPY);
479 snprintf(bigbuf,
sizeof(bigbuf),
480 "/bpl %d string def %%bpl as a string", psbpl);
481 sarrayAddString(sa, bigbuf,
L_COPY);
482 snprintf(bigbuf,
sizeof(bigbuf),
483 "%7.2f %7.2f translate %%set image origin in pts", xpt, ypt);
484 sarrayAddString(sa, bigbuf,
L_COPY);
485 snprintf(bigbuf,
sizeof(bigbuf),
486 "%7.2f %7.2f scale %%set image size in pts", wpt, hpt);
487 sarrayAddString(sa, bigbuf,
L_COPY);
488 snprintf(bigbuf,
sizeof(bigbuf),
489 "%d %d %d %%image dimensions in pixels", w, h, bps);
490 sarrayAddString(sa, bigbuf,
L_COPY);
491 snprintf(bigbuf,
sizeof(bigbuf),
492 "[%d %d %d %d %d %d] %%mapping matrix: [w 0 0 -h 0 h]",
494 sarrayAddString(sa, bigbuf,
L_COPY);
497 if (d == 1 || d == 8)
499 "{currentfile bpl readhexstring pop} image",
L_COPY);
502 "{currentfile bpl readhexstring pop} false 3 colorimage",
505 if (d == 1 || d == 8)
507 "{currentfile bpl readhexstring pop} bind image",
L_COPY);
510 "{currentfile bpl readhexstring pop} bind false 3 colorimage",
514 sarrayAddString(sa, hexdata,
L_INSERT);
517 sarrayAddString(sa,
"\nshowpage",
L_COPY);
519 sarrayAddString(sa,
"\ngrestore",
L_COPY);
521 outstr = sarrayToString(sa, 1);
523 if (!outstr) L_ERROR(
"outstr not made\n", __func__);
560l_int32 bx, by, bw, bh;
561l_float32 winch, hinch, xinch, yinch, fres;
564 res = DefaultInputRes;
565 fres = (l_float32)res;
571 fres = (l_float32)res / scale;
576 if (res < MinRes || res > MaxRes) {
577 L_WARNING(
"res %d out of bounds; using default res; no scaling\n",
579 res = DefaultInputRes;
580 fres = (l_float32)res;
584 winch = (l_float32)wpix / fres;
585 hinch = (l_float32)hpix / fres;
586 xinch = (8.5f - winch) / 2.f;
587 yinch = (11.0f - hinch) / 2.f;
589 boxGetGeometry(box, &bx, &by, &bw, &bh);
591 winch = (l_float32)wpix / fres;
593 winch = (l_float32)bw / 1000.f;
595 hinch = (l_float32)hpix / fres;
597 hinch = (l_float32)bh / 1000.f;
598 xinch = (l_float32)bx / 1000.f;
599 yinch = (l_float32)by / 1000.f;
603 L_WARNING(
"left edge < 0.0 inch\n", __func__);
604 if (xinch + winch > 8.5)
605 L_WARNING(
"right edge > 8.5 inch\n", __func__);
607 L_WARNING(
"bottom edge < 0.0 inch\n", __func__);
608 if (yinch + hinch > 11.0)
609 L_WARNING(
"top edge > 11.0 inch\n", __func__);
611 *pwpt = 72.f * winch;
612 *phpt = 72.f * hinch;
613 *pxpt = 72.f * xinch;
614 *pypt = 72.f * yinch;
637 *pnib1 =
'a' + (nib - 10);
642 *pnib2 =
'a' + (nib - 10);
672l_int32 w, h, nbytes, ret;
673l_float32 xpt, ypt, wpt, hpt;
677 return ERROR_INT(
"filein not defined", __func__, 1);
679 return ERROR_INT(
"fileout not defined", __func__, 1);
682 if ((cid = l_generateJpegData(filein, 1)) == NULL)
683 return ERROR_INT(
"jpeg data not made", __func__, 1);
691 if (w * 11.0 > h * 8.5) {
693 hpt = wpt * (l_float32)h / (l_float32)w;
696 wpt = hpt * (l_float32)w / (l_float32)h;
702 l_CIDataDestroy(&cid);
704 return ERROR_INT(
"outstr not made", __func__, 1);
705 nbytes = strlen(outstr);
707 ret = l_binaryWrite(fileout,
"w", outstr, nbytes);
709 if (ret) L_ERROR(
"ps string not written to file\n", __func__);
784 const char *operation,
796 return ERROR_INT(
"filein not defined", __func__, 1);
798 return ERROR_INT(
"fileout not defined", __func__, 1);
799 if (strcmp(operation,
"w") && strcmp(operation,
"a"))
800 return ERROR_INT(
"operation must be \"w\" or \"a\"", __func__, 1);
804 return ERROR_INT(
"ps string not made", __func__, 1);
806 if (l_binaryWrite(fileout, operation, outstr, nbytes)) {
808 return ERROR_INT(
"ps string not written to file", __func__, 1);
853l_float32 xpt, ypt, wpt, hpt;
857 return ERROR_INT(
"&outstr not defined", __func__, 1);
859 return ERROR_INT(
"&nbytes not defined", __func__, 1);
863 return ERROR_INT(
"filein not defined", __func__, 1);
866 if ((cid = l_generateJpegData(filein, 1)) == NULL)
867 return ERROR_INT(
"jpeg data not made", __func__, 1);
878 res = DefaultInputRes;
884 xpt = scale * x * 72.f / res;
885 ypt = scale * y * 72.f / res;
886 wpt = scale * cid->
w * 72.f / res;
887 hpt = scale * cid->
h * 72.f / res;
893 lept_stderr(
"w = %d, h = %d, bps = %d, spp = %d\n",
894 cid->
w, cid->
h, cid->
bps, cid->
spp);
895 lept_stderr(
"comp bytes = %ld, nbytes85 = %ld, ratio = %5.3f\n",
898 lept_stderr(
"xpt = %7.2f, ypt = %7.2f, wpt = %7.2f, hpt = %7.2f\n",
903 outstr =
generateJpegPS(NULL, cid, xpt, ypt, wpt, hpt, pageno, endpage);
904 l_CIDataDestroy(&cid);
906 return ERROR_INT(
"outstr not made", __func__, 1);
908 *pnbytes = strlen(outstr);
943l_int32 w, h, bps, spp;
949 return (
char *)ERROR_PTR(
"jpeg data not defined", __func__, NULL);
955 sa = sarrayCreate(50);
956 sarrayAddString(sa,
"%!PS-Adobe-3.0",
L_COPY);
957 sarrayAddString(sa,
"%%Creator: leptonica",
L_COPY);
959 snprintf(bigbuf,
sizeof(bigbuf),
"%%%%Title: %s", filein);
961 snprintf(bigbuf,
sizeof(bigbuf),
"%%%%Title: Jpeg compressed PS");
962 sarrayAddString(sa, bigbuf,
L_COPY);
963 sarrayAddString(sa,
"%%DocumentData: Clean7Bit",
L_COPY);
965 if (var_PS_WRITE_BOUNDING_BOX == 1) {
966 snprintf(bigbuf,
sizeof(bigbuf),
967 "%%%%BoundingBox: %7.2f %7.2f %7.2f %7.2f",
968 xpt, ypt, xpt + wpt, ypt + hpt);
969 sarrayAddString(sa, bigbuf,
L_COPY);
972 sarrayAddString(sa,
"%%LanguageLevel: 2",
L_COPY);
973 sarrayAddString(sa,
"%%EndComments",
L_COPY);
974 snprintf(bigbuf,
sizeof(bigbuf),
"%%%%Page: %d %d", pageno, pageno);
975 sarrayAddString(sa, bigbuf,
L_COPY);
977 sarrayAddString(sa,
"save",
L_COPY);
979 "/RawData currentfile /ASCII85Decode filter def",
L_COPY);
980 sarrayAddString(sa,
"/Data RawData << >> /DCTDecode filter def",
L_COPY);
982 snprintf(bigbuf,
sizeof(bigbuf),
983 "%7.2f %7.2f translate %%set image origin in pts", xpt, ypt);
984 sarrayAddString(sa, bigbuf,
L_COPY);
986 snprintf(bigbuf,
sizeof(bigbuf),
987 "%7.2f %7.2f scale %%set image size in pts", wpt, hpt);
988 sarrayAddString(sa, bigbuf,
L_COPY);
991 sarrayAddString(sa,
"/DeviceGray setcolorspace",
L_COPY);
993 sarrayAddString(sa,
"/DeviceRGB setcolorspace",
L_COPY);
995 sarrayAddString(sa,
"/DeviceCMYK setcolorspace",
L_COPY);
997 sarrayAddString(sa,
"{ << /ImageType 1",
L_COPY);
998 snprintf(bigbuf,
sizeof(bigbuf),
" /Width %d", w);
999 sarrayAddString(sa, bigbuf,
L_COPY);
1000 snprintf(bigbuf,
sizeof(bigbuf),
" /Height %d", h);
1001 sarrayAddString(sa, bigbuf,
L_COPY);
1002 snprintf(bigbuf,
sizeof(bigbuf),
1003 " /ImageMatrix [ %d 0 0 %d 0 %d ]", w, -h, h);
1004 sarrayAddString(sa, bigbuf,
L_COPY);
1005 sarrayAddString(sa,
" /DataSource Data",
L_COPY);
1006 snprintf(bigbuf,
sizeof(bigbuf),
" /BitsPerComponent %d", bps);
1007 sarrayAddString(sa, bigbuf,
L_COPY);
1010 sarrayAddString(sa,
" /Decode [0 1]",
L_COPY);
1012 sarrayAddString(sa,
" /Decode [0 1 0 1 0 1]",
L_COPY);
1014 sarrayAddString(sa,
" /Decode [0 1 0 1 0 1 0 1]",
L_COPY);
1016 sarrayAddString(sa,
" >> image",
L_COPY);
1017 sarrayAddString(sa,
" Data closefile",
L_COPY);
1018 sarrayAddString(sa,
" RawData flushfile",
L_COPY);
1019 if (endpage == TRUE)
1020 sarrayAddString(sa,
" showpage",
L_COPY);
1021 sarrayAddString(sa,
" restore",
L_COPY);
1022 sarrayAddString(sa,
"} exec",
L_COPY);
1029 outstr = sarrayToString(sa, 1);
1059 const char *fileout)
1062l_int32 w, h, nbytes, ret;
1063l_float32 xpt, ypt, wpt, hpt;
1067 return ERROR_INT(
"filein not defined", __func__, 1);
1069 return ERROR_INT(
"fileout not defined", __func__, 1);
1071 if ((cid = l_generateG4Data(filein, 1)) == NULL)
1072 return ERROR_INT(
"g4 data not made", __func__, 1);
1080 if (w * 11.0 > h * 8.5) {
1082 hpt = wpt * (l_float32)h / (l_float32)w;
1085 wpt = hpt * (l_float32)w / (l_float32)h;
1090 outstr =
generateG4PS(NULL, cid, xpt, ypt, wpt, hpt, 1, 1, 1);
1091 l_CIDataDestroy(&cid);
1093 return ERROR_INT(
"outstr not made", __func__, 1);
1094 nbytes = strlen(outstr);
1096 ret = l_binaryWrite(fileout,
"w", outstr, nbytes);
1098 if (ret) L_ERROR(
"ps string not written to file\n", __func__);
1163 const char *fileout,
1164 const char *operation,
1177 return ERROR_INT(
"filein not defined", __func__, 1);
1179 return ERROR_INT(
"fileout not defined", __func__, 1);
1180 if (strcmp(operation,
"w") && strcmp(operation,
"a"))
1181 return ERROR_INT(
"operation must be \"w\" or \"a\"", __func__, 1);
1184 pageno, maskflag, endpage))
1185 return ERROR_INT(
"ps string not made", __func__, 1);
1187 ret = l_binaryWrite(fileout, operation, outstr, nbytes);
1190 return ERROR_INT(
"ps string not written to file", __func__, 1);
1235l_float32 xpt, ypt, wpt, hpt;
1239 return ERROR_INT(
"&outstr not defined", __func__, 1);
1241 return ERROR_INT(
"&nbytes not defined", __func__, 1);
1245 return ERROR_INT(
"filein not defined", __func__, 1);
1247 if ((cid = l_generateG4Data(filein, 1)) == NULL)
1248 return ERROR_INT(
"g4 data not made", __func__, 1);
1265 xpt = scale * x * 72.f / res;
1266 ypt = scale * y * 72.f / res;
1267 wpt = scale * cid->
w * 72.f / res;
1268 hpt = scale * cid->
h * 72.f / res;
1274 lept_stderr(
"w = %d, h = %d, minisblack = %d\n",
1276 lept_stderr(
"comp bytes = %ld, nbytes85 = %ld\n",
1278 lept_stderr(
"xpt = %7.2f, ypt = %7.2f, wpt = %7.2f, hpt = %7.2f\n",
1279 xpt, ypt, wpt, hpt);
1284 maskflag, pageno, endpage);
1285 l_CIDataDestroy(&cid);
1287 return ERROR_INT(
"outstr not made", __func__, 1);
1289 *pnbytes = strlen(outstr);
1329char bigbuf[Bufsize];
1333 return (
char *)ERROR_PTR(
"g4 data not defined", __func__, NULL);
1337 sa = sarrayCreate(50);
1338 sarrayAddString(sa,
"%!PS-Adobe-3.0",
L_COPY);
1339 sarrayAddString(sa,
"%%Creator: leptonica",
L_COPY);
1341 snprintf(bigbuf,
sizeof(bigbuf),
"%%%%Title: %s", filein);
1343 snprintf(bigbuf,
sizeof(bigbuf),
"%%%%Title: G4 compressed PS");
1344 sarrayAddString(sa, bigbuf,
L_COPY);
1345 sarrayAddString(sa,
"%%DocumentData: Clean7Bit",
L_COPY);
1347 if (var_PS_WRITE_BOUNDING_BOX == 1) {
1348 snprintf(bigbuf,
sizeof(bigbuf),
1349 "%%%%BoundingBox: %7.2f %7.2f %7.2f %7.2f",
1350 xpt, ypt, xpt + wpt, ypt + hpt);
1351 sarrayAddString(sa, bigbuf,
L_COPY);
1354 sarrayAddString(sa,
"%%LanguageLevel: 2",
L_COPY);
1355 sarrayAddString(sa,
"%%EndComments",
L_COPY);
1356 snprintf(bigbuf,
sizeof(bigbuf),
"%%%%Page: %d %d", pageno, pageno);
1357 sarrayAddString(sa, bigbuf,
L_COPY);
1359 sarrayAddString(sa,
"save",
L_COPY);
1360 sarrayAddString(sa,
"100 dict begin",
L_COPY);
1362 snprintf(bigbuf,
sizeof(bigbuf),
1363 "%7.2f %7.2f translate %%set image origin in pts", xpt, ypt);
1364 sarrayAddString(sa, bigbuf,
L_COPY);
1366 snprintf(bigbuf,
sizeof(bigbuf),
1367 "%7.2f %7.2f scale %%set image size in pts", wpt, hpt);
1368 sarrayAddString(sa, bigbuf,
L_COPY);
1370 sarrayAddString(sa,
"/DeviceGray setcolorspace",
L_COPY);
1372 sarrayAddString(sa,
"{",
L_COPY);
1374 " /RawData currentfile /ASCII85Decode filter def",
L_COPY);
1375 sarrayAddString(sa,
" << ",
L_COPY);
1376 sarrayAddString(sa,
" /ImageType 1",
L_COPY);
1377 snprintf(bigbuf,
sizeof(bigbuf),
" /Width %d", w);
1378 sarrayAddString(sa, bigbuf,
L_COPY);
1379 snprintf(bigbuf,
sizeof(bigbuf),
" /Height %d", h);
1380 sarrayAddString(sa, bigbuf,
L_COPY);
1381 snprintf(bigbuf,
sizeof(bigbuf),
1382 " /ImageMatrix [ %d 0 0 %d 0 %d ]", w, -h, h);
1383 sarrayAddString(sa, bigbuf,
L_COPY);
1384 sarrayAddString(sa,
" /BitsPerComponent 1",
L_COPY);
1385 sarrayAddString(sa,
" /Interpolate true",
L_COPY);
1387 sarrayAddString(sa,
" /Decode [1 0]",
L_COPY);
1389 sarrayAddString(sa,
" /Decode [0 1]",
L_COPY);
1390 sarrayAddString(sa,
" /DataSource RawData",
L_COPY);
1391 sarrayAddString(sa,
" <<",
L_COPY);
1392 sarrayAddString(sa,
" /K -1",
L_COPY);
1393 snprintf(bigbuf,
sizeof(bigbuf),
" /Columns %d", w);
1394 sarrayAddString(sa, bigbuf,
L_COPY);
1395 snprintf(bigbuf,
sizeof(bigbuf),
" /Rows %d", h);
1396 sarrayAddString(sa, bigbuf,
L_COPY);
1397 sarrayAddString(sa,
" >> /CCITTFaxDecode filter",
L_COPY);
1398 if (maskflag == TRUE)
1399 sarrayAddString(sa,
" >> imagemask",
L_COPY);
1401 sarrayAddString(sa,
" >> image",
L_COPY);
1402 sarrayAddString(sa,
" RawData flushfile",
L_COPY);
1403 if (endpage == TRUE)
1404 sarrayAddString(sa,
" showpage",
L_COPY);
1405 sarrayAddString(sa,
"}",
L_COPY);
1407 sarrayAddString(sa,
"%%BeginData:",
L_COPY);
1408 sarrayAddString(sa,
"exec",
L_COPY);
1414 sarrayAddString(sa,
"%%EndData",
L_COPY);
1415 sarrayAddString(sa,
"end",
L_COPY);
1416 sarrayAddString(sa,
"restore",
L_COPY);
1418 outstr = sarrayToString(sa, 1);
1448 const char *fileout,
1449 l_float32 fillfract)
1452l_int32 i, npages, w, h, istiff;
1458 return ERROR_INT(
"filein not defined", __func__, 1);
1460 return ERROR_INT(
"fileout not defined", __func__, 1);
1462 if ((fp = fopenReadStream(filein)) == NULL)
1463 return ERROR_INT_1(
"file not found", filein, __func__, 1);
1464 istiff = fileFormatIsTiff(fp);
1467 return ERROR_INT_1(
"file not tiff format", filein, __func__, 1);
1469 tiffGetCount(fp, &npages);
1472 if (fillfract == 0.0)
1473 fillfract = DefaultFillFraction;
1475 for (i = 0; i < npages; i++) {
1476 if ((pix = pixReadTiff(filein, i)) == NULL)
1477 return ERROR_INT_1(
"pix not made", filein, __func__, 1);
1479 pixGetDimensions(pix, &w, &h, NULL);
1480 if (w == 1728 && h < w)
1481 pixs = pixScale(pix, 1.0, 2.0);
1483 pixs = pixClone(pix);
1485 tempfile = l_makeTempFilename();
1486 pixWrite(tempfile, pixs, IFF_TIFF_G4);
1487 scale = L_MIN(fillfract * 2550 / w, fillfract * 3300 / h);
1490 i + 1, FALSE, TRUE);
1493 i + 1, FALSE, TRUE);
1494 lept_rmfile(tempfile);
1495 LEPT_FREE(tempfile);
1526 const char *fileout)
1529l_int32 w, h, nbytes, ret;
1530l_float32 xpt, ypt, wpt, hpt;
1534 return ERROR_INT(
"filein not defined", __func__, 1);
1536 return ERROR_INT(
"fileout not defined", __func__, 1);
1538 if ((cid = l_generateFlateData(filein, 1)) == NULL)
1539 return ERROR_INT(
"flate data not made", __func__, 1);
1547 if (w * 11.0 > h * 8.5) {
1549 hpt = wpt * (l_float32)h / (l_float32)w;
1552 wpt = hpt * (l_float32)w / (l_float32)h;
1558 l_CIDataDestroy(&cid);
1560 return ERROR_INT(
"outstr not made", __func__, 1);
1561 nbytes = strlen(outstr);
1563 ret = l_binaryWrite(fileout,
"w", outstr, nbytes);
1565 if (ret) L_ERROR(
"ps string not written to file\n", __func__);
1638 const char *fileout,
1639 const char *operation,
1651 return ERROR_INT(
"filein not defined", __func__, 1);
1653 return ERROR_INT(
"fileout not defined", __func__, 1);
1654 if (strcmp(operation,
"w") && strcmp(operation,
"a"))
1655 return ERROR_INT(
"operation must be \"w\" or \"a\"", __func__, 1);
1659 return ERROR_INT(
"ps string not made", __func__, 1);
1661 ret = l_binaryWrite(fileout, operation, outstr, nbytes);
1663 if (ret) L_ERROR(
"ps string not written to file\n", __func__);
1713l_float32 xpt, ypt, wpt, hpt;
1717 return ERROR_INT(
"&outstr not defined", __func__, 1);
1719 return ERROR_INT(
"&nbytes not defined", __func__, 1);
1723 return ERROR_INT(
"filein not defined", __func__, 1);
1725 if ((cid = l_generateFlateData(filein, 1)) == NULL)
1726 return ERROR_INT(
"flate data not made", __func__, 1);
1737 res = DefaultInputRes;
1739 xpt = scale * x * 72.f / res;
1740 ypt = scale * y * 72.f / res;
1741 wpt = scale * cid->
w * 72.f / res;
1742 hpt = scale * cid->
h * 72.f / res;
1748 lept_stderr(
"w = %d, h = %d, bps = %d, spp = %d\n",
1749 cid->
w, cid->
h, cid->
bps, cid->
spp);
1750 lept_stderr(
"uncomp bytes = %ld, comp bytes = %ld, nbytes85 = %ld\n",
1753 lept_stderr(
"xpt = %7.2f, ypt = %7.2f, wpt = %7.2f, hpt = %7.2f\n",
1754 xpt, ypt, wpt, hpt);
1758 outstr =
generateFlatePS(NULL, cid, xpt, ypt, wpt, hpt, pageno, endpage);
1759 l_CIDataDestroy(&cid);
1761 return ERROR_INT(
"outstr not made", __func__, 1);
1763 *pnbytes = strlen(outstr);
1793l_int32 w, h, bps, spp;
1795char bigbuf[Bufsize];
1799 return (
char *)ERROR_PTR(
"flate data not defined", __func__, NULL);
1805 sa = sarrayCreate(50);
1806 sarrayAddString(sa,
"%!PS-Adobe-3.0 EPSF-3.0",
L_COPY);
1807 sarrayAddString(sa,
"%%Creator: leptonica",
L_COPY);
1809 snprintf(bigbuf,
sizeof(bigbuf),
"%%%%Title: %s", filein);
1811 snprintf(bigbuf,
sizeof(bigbuf),
"%%%%Title: Flate compressed PS");
1812 sarrayAddString(sa, bigbuf,
L_COPY);
1813 sarrayAddString(sa,
"%%DocumentData: Clean7Bit",
L_COPY);
1815 if (var_PS_WRITE_BOUNDING_BOX == 1) {
1816 snprintf(bigbuf,
sizeof(bigbuf),
1817 "%%%%BoundingBox: %7.2f %7.2f %7.2f %7.2f",
1818 xpt, ypt, xpt + wpt, ypt + hpt);
1819 sarrayAddString(sa, bigbuf,
L_COPY);
1822 sarrayAddString(sa,
"%%LanguageLevel: 3",
L_COPY);
1823 sarrayAddString(sa,
"%%EndComments",
L_COPY);
1824 snprintf(bigbuf,
sizeof(bigbuf),
"%%%%Page: %d %d", pageno, pageno);
1825 sarrayAddString(sa, bigbuf,
L_COPY);
1827 sarrayAddString(sa,
"save",
L_COPY);
1828 snprintf(bigbuf,
sizeof(bigbuf),
1829 "%7.2f %7.2f translate %%set image origin in pts", xpt, ypt);
1830 sarrayAddString(sa, bigbuf,
L_COPY);
1832 snprintf(bigbuf,
sizeof(bigbuf),
1833 "%7.2f %7.2f scale %%set image size in pts", wpt, hpt);
1834 sarrayAddString(sa, bigbuf,
L_COPY);
1838 snprintf(bigbuf,
sizeof(bigbuf),
1839 "[ /Indexed /DeviceRGB %d %%set colormap type/size",
1841 sarrayAddString(sa, bigbuf,
L_COPY);
1842 sarrayAddString(sa,
" <~",
L_COPY);
1844 sarrayAddString(sa,
" ] setcolorspace",
L_COPY);
1845 }
else if (spp == 1) {
1846 sarrayAddString(sa,
"/DeviceGray setcolorspace",
L_COPY);
1848 sarrayAddString(sa,
"/DeviceRGB setcolorspace",
L_COPY);
1852 "/RawData currentfile /ASCII85Decode filter def",
L_COPY);
1854 "/Data RawData << >> /FlateDecode filter def",
L_COPY);
1856 sarrayAddString(sa,
"{ << /ImageType 1",
L_COPY);
1857 snprintf(bigbuf,
sizeof(bigbuf),
" /Width %d", w);
1858 sarrayAddString(sa, bigbuf,
L_COPY);
1859 snprintf(bigbuf,
sizeof(bigbuf),
" /Height %d", h);
1860 sarrayAddString(sa, bigbuf,
L_COPY);
1861 snprintf(bigbuf,
sizeof(bigbuf),
" /BitsPerComponent %d", bps);
1862 sarrayAddString(sa, bigbuf,
L_COPY);
1863 snprintf(bigbuf,
sizeof(bigbuf),
1864 " /ImageMatrix [ %d 0 0 %d 0 %d ]", w, -h, h);
1865 sarrayAddString(sa, bigbuf,
L_COPY);
1868 sarrayAddString(sa,
" /Decode [0 255]",
L_COPY);
1869 }
else if (spp == 1) {
1871 sarrayAddString(sa,
" /Decode [1 0]",
L_COPY);
1873 sarrayAddString(sa,
" /Decode [0 1]",
L_COPY);
1875 sarrayAddString(sa,
" /Decode [0 1 0 1 0 1]",
L_COPY);
1878 sarrayAddString(sa,
" /DataSource Data",
L_COPY);
1879 sarrayAddString(sa,
" >> image",
L_COPY);
1880 sarrayAddString(sa,
" Data closefile",
L_COPY);
1881 sarrayAddString(sa,
" RawData flushfile",
L_COPY);
1882 if (endpage == TRUE)
1883 sarrayAddString(sa,
" showpage",
L_COPY);
1884 sarrayAddString(sa,
" restore",
L_COPY);
1885 sarrayAddString(sa,
"} exec",
L_COPY);
1891 outstr = sarrayToString(sa, 1);
1929 return ERROR_INT(
"&data not defined", __func__, 1 );
1931 return ERROR_INT(
"&size not defined", __func__, 1 );
1933 return ERROR_INT(
"&pix not defined", __func__, 1 );
1936 *psize = strlen((
char *)(*pdata));
1956 l_float32 fillfract)
1958l_int32 resw, resh, res;
1960 if (fillfract == 0.0)
1961 fillfract = DefaultFillFraction;
1962 resw = (l_int32)((w * 72.) / (LetterWidth * fillfract));
1963 resh = (l_int32)((h * 72.) / (LetterHeight * fillfract));
1964 res = L_MAX(resw, resh);
1981 l_float32 fillfract)
1983l_int32 resw, resh, res;
1985 if (fillfract == 0.0)
1986 fillfract = DefaultFillFraction;
1987 resw = (l_int32)((w * 72.) / (A4Width * fillfract));
1988 resh = (l_int32)((h * 72.) / (A4Height * fillfract));
1989 res = L_MAX(resw, resh);
1998l_psWriteBoundingBox(l_int32 flag)
2000 var_PS_WRITE_BOUNDING_BOX = flag;
#define GET_DATA_BYTE(pdata, n)
static char * generateFlatePS(const char *filein, L_COMP_DATA *cid, l_float32 xpt, l_float32 ypt, l_float32 wpt, l_float32 hpt, l_int32 pageno, l_int32 endpage)
generateFlatePS()
static l_ok convertG4ToPSString(const char *filein, char **poutstr, l_int32 *pnbytes, l_int32 x, l_int32 y, l_int32 res, l_float32 scale, l_int32 pageno, l_int32 maskflag, l_int32 endpage)
convertG4ToPSString()
l_ok convertFlateToPS(const char *filein, const char *fileout, const char *operation, l_int32 x, l_int32 y, l_int32 res, l_float32 scale, l_int32 pageno, l_int32 endpage)
convertFlateToPS()
static void getScaledParametersPS(BOX *box, l_int32 wpix, l_int32 hpix, l_int32 res, l_float32 scale, l_float32 *pxpt, l_float32 *pypt, l_float32 *pwpt, l_float32 *phpt)
getScaledParametersPS()
static l_ok convertFlateToPSString(const char *filein, char **poutstr, l_int32 *pnbytes, l_int32 x, l_int32 y, l_int32 res, l_float32 scale, l_int32 pageno, l_int32 endpage)
convertFlateToPSString()
l_ok pixWriteStreamPS(FILE *fp, PIX *pix, BOX *box, l_int32 res, l_float32 scale)
pixWriteStreamPS()
l_ok convertJpegToPS(const char *filein, const char *fileout, const char *operation, l_int32 x, l_int32 y, l_int32 res, l_float32 scale, l_int32 pageno, l_int32 endpage)
convertJpegToPS()
l_int32 getResA4Page(l_int32 w, l_int32 h, l_float32 fillfract)
getResA4Page()
l_ok pixWritePSEmbed(const char *filein, const char *fileout)
pixWritePSEmbed()
char * pixWriteStringPS(PIX *pixs, BOX *box, l_int32 res, l_float32 scale)
pixWriteStringPS()
static l_ok convertJpegToPSString(const char *filein, char **poutstr, l_int32 *pnbytes, l_int32 x, l_int32 y, l_int32 res, l_float32 scale, l_int32 pageno, l_int32 endpage)
convertJpegToPSString()
l_ok convertTiffMultipageToPS(const char *filein, const char *fileout, l_float32 fillfract)
convertTiffMultipageToPS()
static void convertByteToHexAscii(l_uint8 byteval, char *pnib1, char *pnib2)
convertByteToHexAscii()
l_ok convertFlateToPSEmbed(const char *filein, const char *fileout)
convertFlateToPSEmbed()
l_ok convertG4ToPSEmbed(const char *filein, const char *fileout)
convertG4ToPSEmbed()
l_ok pixWriteMemPS(l_uint8 **pdata, size_t *psize, PIX *pix, BOX *box, l_int32 res, l_float32 scale)
pixWriteMemPS()
l_ok convertJpegToPSEmbed(const char *filein, const char *fileout)
convertJpegToPSEmbed()
char * generateUncompressedPS(char *hexdata, l_int32 w, l_int32 h, l_int32 d, l_int32 psbpl, l_int32 bps, l_float32 xpt, l_float32 ypt, l_float32 wpt, l_float32 hpt, l_int32 boxflag)
generateUncompressedPS()
l_ok convertG4ToPS(const char *filein, const char *fileout, const char *operation, l_int32 x, l_int32 y, l_int32 res, l_float32 scale, l_int32 pageno, l_int32 maskflag, l_int32 endpage)
convertG4ToPS()
static char * generateJpegPS(const char *filein, L_COMP_DATA *cid, l_float32 xpt, l_float32 ypt, l_float32 wpt, l_float32 hpt, l_int32 pageno, l_int32 endpage)
generateJpegPS()
l_int32 getResLetterPage(l_int32 w, l_int32 h, l_float32 fillfract)
getResLetterPage()
static char * generateG4PS(const char *filein, L_COMP_DATA *cid, l_float32 xpt, l_float32 ypt, l_float32 wpt, l_float32 hpt, l_int32 maskflag, l_int32 pageno, l_int32 endpage)
generateG4PS()