76 #include <config_auto.h> 80 #include "allheaders.h" 128 l_int32 w, h, d, i, y, xstart, ystart, extra, spacer, rval, gval, bval;
129 l_int32 nlines, htext, ovf, overflow, offset, index;
135 PROCNAME(
"pixAddSingleTextblock");
137 if (poverflow) *poverflow = 0;
139 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
142 return (
PIX *)ERROR_PTR(
"invalid location", procName, NULL);
144 L_ERROR(
"no bitmap fonts; returning a copy\n", procName);
150 L_WARNING(
"no textstring defined; returning a copy\n", procName);
158 cmap = pixGetColormap(pixs);
159 if (d == 1 && val > 1)
161 else if (d == 2 && val > 3 && !cmap)
163 else if (d == 4 && val > 15 && !cmap)
165 else if (d == 8 && val > 0xff && !cmap)
167 else if (d == 16 && val > 0xffff)
169 else if (d == 32 && val < 256)
172 xstart = (l_int32)(0.1 * w);
175 return (
PIX *)ERROR_PTR(
"line string sa not made", procName, NULL);
181 extra = htext + 2 * spacer;
184 pixCopyResolution(pixd, pixs);
185 pixCopyText(pixd, pixs);
194 cmapd = pixGetColormap(pixd);
202 ystart = offset + spacer;
204 ystart = h - htext - spacer + offset;
206 ystart = h + offset + spacer;
221 for (i = 0, y = ystart; i < nlines; i++) {
224 xstart, y, NULL, &ovf);
234 if (h < htext + 2 * spacer)
237 if (poverflow) *poverflow = overflow;
283 l_int32 i, w, h, d, rval, gval, bval, index;
284 l_int32 wline, wtext, htext, wadd, hadd, spacer, hbaseline, nlines;
290 PROCNAME(
"pixAddTextlines");
293 return (
PIX *)ERROR_PTR(
"pixs not defined", procName, NULL);
296 return (
PIX *)ERROR_PTR(
"invalid location", procName, NULL);
298 L_ERROR(
"no bitmap fonts; returning a copy\n", procName);
304 L_WARNING(
"no textstring defined; returning a copy\n", procName);
313 cmap = pixGetColormap(pixs);
314 if (d == 1 && val > 1)
316 else if (d == 2 && val > 3 && !cmap)
318 else if (d == 4 && val > 15 && !cmap)
320 else if (d == 8 && val > 0xff && !cmap)
322 else if (d == 16 && val > 0xffff)
324 else if (d == 32 && val < 256)
333 for (i = 0; i < nlines; i++) {
340 htext = 1.5 * hbaseline * nlines;
345 hadd = htext + 2 * spacer;
348 pixCopyResolution(pixd, pixs);
349 pixCopyText(pixd, pixs);
356 wadd = wtext + 2 * spacer;
359 pixCopyResolution(pixd, pixs);
360 pixCopyText(pixd, pixs);
370 cmapd = pixGetColormap(pixd);
381 for (i = 0; i < nlines; i++) {
386 (w - wtext) / 2, spacer + hbaseline * (1 + 1.5 * i),
390 (w - wtext) / 2, h + spacer +
391 hbaseline * (1 + 1.5 * i), NULL, NULL);
394 spacer, (h - htext) / 2 + hbaseline * (1 + 1.5 * i),
398 w + spacer, (h - htext) / 2 +
399 hbaseline * (1 + 1.5 * i), NULL, NULL);
450 l_int32 d, h, i, w, x, y, nlines, htext, xwidth, wline, ovf, overflow;
454 PROCNAME(
"pixSetTextblock");
457 return ERROR_INT(
"pixs not defined", procName, 1);
459 return ERROR_INT(
"bmf not defined", procName, 1);
461 return ERROR_INT(
"textstr not defined", procName, 1);
467 cmap = pixGetColormap(pixs);
468 if (d == 1 && val > 1)
470 else if (d == 2 && val > 3 && !cmap)
472 else if (d == 4 && val > 15 && !cmap)
474 else if (d == 8 && val > 0xff && !cmap)
476 else if (d == 16 && val > 0xffff)
478 else if (d == 32 && val < 256)
481 if (w < x0 + wtext) {
482 L_WARNING(
"reducing width of textblock\n", procName);
483 wtext = w - x0 - w / 10;
485 return ERROR_INT(
"wtext too small; no room for text", procName, 1);
490 return ERROR_INT(
"line string sa not made", procName, 1);
496 for (i = 0; i < nlines; i++) {
498 x = x0 + firstindent * xwidth;
511 if (h < y0 - bmf->baselinetab[93] + htext)
514 *poverflow = overflow;
562 l_int32 d, i, x, w, nchar, baseline, index, rval, gval, bval;
567 PROCNAME(
"pixSetTextline");
570 return ERROR_INT(
"pixs not defined", procName, 1);
572 return ERROR_INT(
"bmf not defined", procName, 1);
574 return ERROR_INT(
"teststr not defined", procName, 1);
576 d = pixGetDepth(pixs);
577 cmap = pixGetColormap(pixs);
578 if (d == 1 && val > 1)
580 else if (d == 2 && val > 3 && !cmap)
582 else if (d == 4 && val > 15 && !cmap)
584 else if (d == 8 && val > 0xff && !cmap)
586 else if (d == 16 && val > 0xffff)
588 else if (d == 32 && val < 256)
601 nchar = strlen(textstr);
603 for (i = 0; i < nchar; i++) {
605 if ((l_int32)chr == 10)
continue;
609 w = pixGetWidth(pix);
617 *poverflow = (x > pixGetWidth(pixs) - 1) ? 1 : 0;
660 PROCNAME(
"pixaAddTextNumber");
663 return (
PIXA *)ERROR_PTR(
"pixas not defined", procName, NULL);
665 return (
PIXA *)ERROR_PTR(
"bmf not defined", procName, NULL);
668 return (
PIXA *)ERROR_PTR(
"invalid location", procName, NULL);
672 for (i = 0; i < n; i++) {
678 snprintf(textstr,
sizeof(textstr),
"%d", index);
730 PROCNAME(
"pixaAddTextlines");
733 return (
PIXA *)ERROR_PTR(
"pixas not defined", procName, NULL);
735 return (
PIXA *)ERROR_PTR(
"bmf not defined", procName, NULL);
738 return (
PIXA *)ERROR_PTR(
"invalid location", procName, NULL);
743 if (nstr > 0 && nstr < n)
744 L_WARNING(
"There are %d strings and %d pix\n", procName, nstr, n);
745 for (i = 0; i < n; i++) {
799 PIX *pix1, *pix2, *pix3;
802 PROCNAME(
"pixaAddPixWithText");
805 return ERROR_INT(
"pixa not defined", procName, 1);
807 return ERROR_INT(
"pixs not defined", procName, 1);
810 return ERROR_INT(
"invalid location", procName, 1);
815 L_WARNING(
"no textstring defined; inserting copy", procName);
832 cmap = pixGetColormap(pix1);
833 d = pixGetDepth(pix1);
834 if (!cmap && d != 32)
844 return ERROR_INT(
"pix3 not made", procName, 1);
878 l_int32 i, ifirst, sumw, newsum, w, nwords, nlines, len, xwidth;
882 PROCNAME(
"bmfGetLineStrings");
885 return (
SARRAY *)ERROR_PTR(
"bmf not defined", procName, NULL);
887 return (
SARRAY *)ERROR_PTR(
"teststr not defined", procName, NULL);
890 return (
SARRAY *)ERROR_PTR(
"sawords not made", procName, NULL);
894 return (
SARRAY *)ERROR_PTR(
"na not made", procName, NULL);
900 return (
SARRAY *)ERROR_PTR(
"no words in textstr", procName, NULL);
907 sumw = firstindent * xwidth + w;
908 for (i = 1; i < nwords; i++) {
915 len = strlen(linestr);
917 linestr[len - 1] =
'\0';
952 l_int32 i, nwords, width;
955 PROCNAME(
"bmfGetWordWidths");
958 return (
NUMA *)ERROR_PTR(
"bmf not defined", procName, NULL);
960 return (
NUMA *)ERROR_PTR(
"teststr not defined", procName, NULL);
962 return (
NUMA *)ERROR_PTR(
"sa not defined", procName, NULL);
966 return (
NUMA *)ERROR_PTR(
"na not made", procName, NULL);
968 for (i = 0; i < nwords; i++) {
993 l_int32 i, w, width, nchar;
995 PROCNAME(
"bmfGetStringWidth");
998 return ERROR_INT(
"bmf not defined", procName, 1);
1000 return ERROR_INT(
"teststr not defined", procName, 1);
1002 return ERROR_INT(
"&w not defined", procName, 1);
1004 nchar = strlen(textstr);
1006 for (i = 0; i < nchar; i++) {
1035 char *linestr, *parastring;
1036 l_int32 nlines, i, allwhite, leadwhite;
1037 SARRAY *salines, *satemp, *saout;
1039 PROCNAME(
"splitStringToParagraphs");
1042 return (
SARRAY *)ERROR_PTR(
"textstr not defined", procName, NULL);
1045 return (
SARRAY *)ERROR_PTR(
"salines not made", procName, NULL);
1052 for (i = 1; i < nlines; i++) {
1087 PROCNAME(
"stringAllWhitespace");
1090 return ERROR_INT(
"textstr not defined", procName, 1);
1092 return ERROR_INT(
"&va not defined", procName, 1);
1094 len = strlen(textstr);
1096 for (i = 0; i < len; i++) {
1097 if (textstr[i] !=
' ' && textstr[i] !=
'\t' && textstr[i] !=
'\n') {
1117 PROCNAME(
"stringLeadingWhitespace");
1120 return ERROR_INT(
"textstr not defined", procName, 1);
1122 return ERROR_INT(
"&va not defined", procName, 1);
1125 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()
PIX * pixCopy(PIX *pixd, const PIX *pixs)
pixCopy()
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 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()
l_ok pixCopyColormap(PIX *pixd, const PIX *pixs)
pixCopyColormap()
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()