76 #include "allheaders.h" 123 l_int32 w, h, d, i, y, xstart, ystart, extra, spacer, rval, gval, bval;
124 l_int32 nlines, htext, ovf, overflow, offset, index;
130 PROCNAME(
"pixAddSingleTextblock");
132 if (poverflow) *poverflow = 0;
134 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
137 return (
PIX *)ERROR_PTR(
"invalid location", procName, NULL);
139 L_ERROR(
"no bitmap fonts; returning a copy\n", procName);
145 L_WARNING(
"no textstring defined; returning a copy\n", procName);
153 cmap = pixGetColormap(pixs);
154 if (d == 1 && val > 1)
156 else if (d == 2 && val > 3 && !cmap)
158 else if (d == 4 && val > 15 && !cmap)
160 else if (d == 8 && val > 0xff && !cmap)
162 else if (d == 16 && val > 0xffff)
164 else if (d == 32 && val < 256)
167 xstart = (l_int32)(0.1 * w);
170 return (
PIX *)ERROR_PTR(
"line string sa not made", procName, NULL);
176 extra = htext + 2 * spacer;
179 pixCopyResolution(pixd, pixs);
188 cmapd = pixGetColormap(pixd);
196 ystart = offset + spacer;
198 ystart = h - htext - spacer + offset;
200 ystart = h + offset + spacer;
215 for (i = 0, y = ystart; i < nlines; i++) {
218 xstart, y, NULL, &ovf);
228 if (h < htext + 2 * spacer)
231 if (poverflow) *poverflow = overflow;
277 l_int32 i, w, h, d, rval, gval, bval, index;
278 l_int32 wline, wtext, htext, wadd, hadd, spacer, hbaseline, nlines;
284 PROCNAME(
"pixAddTextlines");
287 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
290 return (
PIX *)ERROR_PTR(
"invalid location", procName, NULL);
292 L_ERROR(
"no bitmap fonts; returning a copy\n", procName);
298 L_WARNING(
"no textstring defined; returning a copy\n", procName);
307 cmap = pixGetColormap(pixs);
308 if (d == 1 && val > 1)
310 else if (d == 2 && val > 3 && !cmap)
312 else if (d == 4 && val > 15 && !cmap)
314 else if (d == 8 && val > 0xff && !cmap)
316 else if (d == 16 && val > 0xffff)
318 else if (d == 32 && val < 256)
327 for (i = 0; i < nlines; i++) {
334 htext = 1.5 * hbaseline * nlines;
339 hadd = htext + 2 * spacer;
342 pixCopyResolution(pixd, pixs);
349 wadd = wtext + 2 * spacer;
352 pixCopyResolution(pixd, pixs);
362 cmapd = pixGetColormap(pixd);
373 for (i = 0; i < nlines; i++) {
378 (w - wtext) / 2, spacer + hbaseline * (1 + 1.5 * i),
382 (w - wtext) / 2, h + spacer +
383 hbaseline * (1 + 1.5 * i), NULL, NULL);
386 spacer, (h - htext) / 2 + hbaseline * (1 + 1.5 * i),
390 w + spacer, (h - htext) / 2 +
391 hbaseline * (1 + 1.5 * i), NULL, NULL);
442 l_int32 d, h, i, w, x, y, nlines, htext, xwidth, wline, ovf, overflow;
446 PROCNAME(
"pixSetTextblock");
449 return ERROR_INT(
"pixs not defined", procName, 1);
451 return ERROR_INT(
"bmf not defined", procName, 1);
453 return ERROR_INT(
"textstr not defined", procName, 1);
459 cmap = pixGetColormap(pixs);
460 if (d == 1 && val > 1)
462 else if (d == 2 && val > 3 && !cmap)
464 else if (d == 4 && val > 15 && !cmap)
466 else if (d == 8 && val > 0xff && !cmap)
468 else if (d == 16 && val > 0xffff)
470 else if (d == 32 && val < 256)
473 if (w < x0 + wtext) {
474 L_WARNING(
"reducing width of textblock\n", procName);
475 wtext = w - x0 - w / 10;
477 return ERROR_INT(
"wtext too small; no room for text", procName, 1);
482 return ERROR_INT(
"line string sa not made", procName, 1);
488 for (i = 0; i < nlines; i++) {
490 x = x0 + firstindent * xwidth;
503 if (h < y0 - bmf->baselinetab[93] + htext)
506 *poverflow = overflow;
554 l_int32 d, i, x, w, nchar, baseline, index, rval, gval, bval;
559 PROCNAME(
"pixSetTextline");
562 return ERROR_INT(
"pixs not defined", procName, 1);
564 return ERROR_INT(
"bmf not defined", procName, 1);
566 return ERROR_INT(
"teststr not defined", procName, 1);
568 d = pixGetDepth(pixs);
569 cmap = pixGetColormap(pixs);
570 if (d == 1 && val > 1)
572 else if (d == 2 && val > 3 && !cmap)
574 else if (d == 4 && val > 15 && !cmap)
576 else if (d == 8 && val > 0xff && !cmap)
578 else if (d == 16 && val > 0xffff)
580 else if (d == 32 && val < 256)
593 nchar = strlen(textstr);
595 for (i = 0; i < nchar; i++) {
597 if ((l_int32)chr == 10)
continue;
601 w = pixGetWidth(pix);
609 *poverflow = (x > pixGetWidth(pixs) - 1) ? 1 : 0;
652 PROCNAME(
"pixaAddTextNumber");
655 return (
PIXA *)ERROR_PTR(
"pixas not defined", procName, NULL);
657 return (
PIXA *)ERROR_PTR(
"bmf not defined", procName, NULL);
660 return (
PIXA *)ERROR_PTR(
"invalid location", procName, NULL);
664 for (i = 0; i < n; i++) {
670 snprintf(textstr,
sizeof(textstr),
"%d", index);
721 PROCNAME(
"pixaAddTextlines");
724 return (
PIXA *)ERROR_PTR(
"pixas not defined", procName, NULL);
726 return (
PIXA *)ERROR_PTR(
"bmf not defined", procName, NULL);
729 return (
PIXA *)ERROR_PTR(
"invalid location", procName, NULL);
734 if (nstr > 0 && nstr < n)
735 L_WARNING(
"There are %d strings and %d pix\n", procName, nstr, n);
736 for (i = 0; i < n; i++) {
790 PIX *pix1, *pix2, *pix3;
793 PROCNAME(
"pixaAddPixWithText");
796 return ERROR_INT(
"pixa not defined", procName, 1);
798 return ERROR_INT(
"pixs not defined", procName, 1);
801 return ERROR_INT(
"invalid location", procName, 1);
806 L_WARNING(
"no textstring defined; inserting copy", procName);
823 cmap = pixGetColormap(pix1);
824 d = pixGetDepth(pix1);
825 if (!cmap && d != 32)
835 return ERROR_INT(
"pix3 not made", procName, 1);
869 l_int32 i, ifirst, sumw, newsum, w, nwords, nlines, len, xwidth;
873 PROCNAME(
"bmfGetLineStrings");
876 return (
SARRAY *)ERROR_PTR(
"bmf not defined", procName, NULL);
878 return (
SARRAY *)ERROR_PTR(
"teststr not defined", procName, NULL);
881 return (
SARRAY *)ERROR_PTR(
"sawords not made", procName, NULL);
885 return (
SARRAY *)ERROR_PTR(
"na not made", procName, NULL);
891 return (
SARRAY *)ERROR_PTR(
"no words in textstr", procName, NULL);
898 sumw = firstindent * xwidth + w;
899 for (i = 1; i < nwords; i++) {
906 len = strlen(linestr);
908 linestr[len - 1] =
'\0';
943 l_int32 i, nwords, width;
946 PROCNAME(
"bmfGetWordWidths");
949 return (
NUMA *)ERROR_PTR(
"bmf not defined", procName, NULL);
951 return (
NUMA *)ERROR_PTR(
"teststr not defined", procName, NULL);
953 return (
NUMA *)ERROR_PTR(
"sa not defined", procName, NULL);
957 return (
NUMA *)ERROR_PTR(
"na not made", procName, NULL);
959 for (i = 0; i < nwords; i++) {
984 l_int32 i, w, width, nchar;
986 PROCNAME(
"bmfGetStringWidth");
989 return ERROR_INT(
"bmf not defined", procName, 1);
991 return ERROR_INT(
"teststr not defined", procName, 1);
993 return ERROR_INT(
"&w not defined", procName, 1);
995 nchar = strlen(textstr);
997 for (i = 0; i < nchar; i++) {
1026 char *linestr, *parastring;
1027 l_int32 nlines, i, allwhite, leadwhite;
1028 SARRAY *salines, *satemp, *saout;
1030 PROCNAME(
"splitStringToParagraphs");
1033 return (
SARRAY *)ERROR_PTR(
"textstr not defined", procName, NULL);
1036 return (
SARRAY *)ERROR_PTR(
"salines not made", procName, NULL);
1043 for (i = 1; i < nlines; i++) {
1078 PROCNAME(
"stringAllWhitespace");
1081 return ERROR_INT(
"textstr not defined", procName, 1);
1083 return ERROR_INT(
"&va not defined", procName, 1);
1085 len = strlen(textstr);
1087 for (i = 0; i < len; i++) {
1088 if (textstr[i] !=
' ' && textstr[i] !=
'\t' && textstr[i] !=
'\n') {
1108 PROCNAME(
"stringLeadingWhitespace");
1111 return ERROR_INT(
"textstr not defined", procName, 1);
1113 return ERROR_INT(
"&va not defined", procName, 1);
1116 if (textstr[0] ==
' ' || textstr[0] ==
'\t')
void bmfDestroy(L_BMF **pbmf)
bmfDestroy()
char * sarrayToString(SARRAY *sa, l_int32 addnlflag)
sarrayToString()
PIX * bmfGetPix(L_BMF *bmf, char chr)
bmfGetPix()
PIX * pixConvertTo32(PIX *pixs)
pixConvertTo32()
l_ok numaAddNumber(NUMA *na, l_float32 val)
numaAddNumber()
PIXA * pixaCreate(l_int32 n)
pixaCreate()
l_ok pixRasterop(PIX *pixd, l_int32 dx, l_int32 dy, l_int32 dw, l_int32 dh, l_int32 op, PIX *pixs, l_int32 sx, l_int32 sy)
pixRasterop()
l_ok pixSetTextblock(PIX *pixs, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 x0, l_int32 y0, l_int32 wtext, l_int32 firstindent, l_int32 *poverflow)
pixSetTextblock()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
SARRAY * sarrayCreate(l_int32 n)
sarrayCreate()
char * sarrayToStringRange(SARRAY *sa, l_int32 first, l_int32 nstrings, l_int32 addnlflag)
sarrayToStringRange()
NUMA * numaCreate(l_int32 n)
numaCreate()
PIXA * pixaAddTextlines(PIXA *pixas, L_BMF *bmf, SARRAY *sa, l_uint32 val, l_int32 location)
pixaAddTextlines()
static l_int32 stringLeadingWhitespace(char *textstr, l_int32 *pval)
stringLeadingWhitespace()
l_ok bmfGetStringWidth(L_BMF *bmf, const char *textstr, l_int32 *pw)
bmfGetStringWidth()
l_ok bmfGetWidth(L_BMF *bmf, char chr, l_int32 *pw)
bmfGetWidth()
l_ok pixPaintThroughMask(PIX *pixd, PIX *pixm, l_int32 x, l_int32 y, l_uint32 val)
pixPaintThroughMask()
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
l_ok pixaAddPix(PIXA *pixa, PIX *pix, l_int32 copyflag)
pixaAddPix()
l_int32 numaGetCount(NUMA *na)
numaGetCount()
l_ok sarrayAddString(SARRAY *sa, const char *string, l_int32 copyflag)
sarrayAddString()
l_ok pixaAddPixWithText(PIXA *pixa, PIX *pixs, l_int32 reduction, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 location)
pixaAddPixWithText()
l_ok pixSetTextline(PIX *pixs, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 x0, l_int32 y0, l_int32 *pwidth, l_int32 *poverflow)
pixSetTextline()
l_ok pixcmapGetColor(PIXCMAP *cmap, l_int32 index, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
pixcmapGetColor()
l_ok pixSetBlackOrWhite(PIX *pixs, l_int32 op)
pixSetBlackOrWhite()
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
PIX * pixClone(PIX *pixs)
pixClone()
void pixDestroy(PIX **ppix)
pixDestroy()
l_ok pixCopyColormap(PIX *pixd, PIX *pixs)
pixCopyColormap()
l_ok pixcmapAddNearestColor(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pindex)
pixcmapAddNearestColor()
SARRAY * splitStringToParagraphs(char *textstr, l_int32 splitflag)
splitStringToParagraphs()
PIX * pixScaleByIntSampling(PIX *pixs, l_int32 factor)
pixScaleByIntSampling()
l_ok bmfGetBaseline(L_BMF *bmf, char chr, l_int32 *pbaseline)
bmfGetBaseline()
SARRAY * sarrayCreateLinesFromString(const char *string, l_int32 blankflag)
sarrayCreateLinesFromString()
void numaDestroy(NUMA **pna)
numaDestroy()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
static l_int32 stringAllWhitespace(char *textstr, l_int32 *pval)
stringAllWhitespace()
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
char * pixGetText(PIX *pix)
pixGetText()
PIX * pixaGetPix(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetPix()
PIX * pixCopy(PIX *pixd, PIX *pixs)
pixCopy()
PIX * pixAddTextlines(PIX *pixs, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 location)
pixAddTextlines()
l_ok composeRGBPixel(l_int32 rval, l_int32 gval, l_int32 bval, l_uint32 *ppixel)
composeRGBPixel()
NUMA * bmfGetWordWidths(L_BMF *bmf, const char *textstr, SARRAY *sa)
bmfGetWordWidths()
SARRAY * bmfGetLineStrings(L_BMF *bmf, const char *textstr, l_int32 maxw, l_int32 firstindent, l_int32 *ph)
bmfGetLineStrings()
PIX * pixAddSingleTextblock(PIX *pixs, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 location, l_int32 *poverflow)
pixAddSingleTextblock()
void extractRGBValues(l_uint32 pixel, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
extractRGBValues()
l_int32 pixaGetCount(PIXA *pixa)
pixaGetCount()
SARRAY * sarrayCreateWordsFromString(const char *string)
sarrayCreateWordsFromString()
PIXA * pixaAddTextNumber(PIXA *pixas, L_BMF *bmf, NUMA *na, l_uint32 val, l_int32 location)
pixaAddTextNumber()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
L_BMF * bmfCreate(const char *dir, l_int32 fontsize)
bmfCreate()