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 if (poverflow) *poverflow = 0;
137 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
140 return (
PIX *)ERROR_PTR(
"invalid location", __func__, NULL);
142 L_ERROR(
"no bitmap fonts; returning a copy\n", __func__);
148 L_WARNING(
"no textstring defined; returning a copy\n", __func__);
156 cmap = pixGetColormap(pixs);
157 if (d == 1 && val > 1)
159 else if (d == 2 && val > 3 && !cmap)
161 else if (d == 4 && val > 15 && !cmap)
163 else if (d == 8 && val > 0xff && !cmap)
165 else if (d == 16 && val > 0xffff)
167 else if (d == 32 && val < 256)
170 xstart = (l_int32)(0.1 * w);
173 return (
PIX *)ERROR_PTR(
"line string sa not made", __func__, NULL);
179 extra = htext + 2 * spacer;
182 pixCopyResolution(pixd, pixs);
183 pixCopyText(pixd, pixs);
192 cmapd = pixGetColormap(pixd);
200 ystart = offset + spacer;
202 ystart = h - htext - spacer + offset;
204 ystart = h + offset + spacer;
219 for (i = 0, y = ystart; i < nlines; i++) {
222 xstart, y, NULL, &ovf);
232 if (h < htext + 2 * spacer)
235 if (poverflow) *poverflow = overflow;
281 l_int32 i, w, h, d, rval, gval, bval, index;
282 l_int32 wline, wtext, htext, wadd, hadd, spacer, hbaseline, nlines;
289 return (
PIX *)ERROR_PTR(
"pixs not defined", __func__, NULL);
292 return (
PIX *)ERROR_PTR(
"invalid location", __func__, NULL);
294 L_ERROR(
"no bitmap fonts; returning a copy\n", __func__);
300 L_WARNING(
"no textstring defined; returning a copy\n", __func__);
309 cmap = pixGetColormap(pixs);
310 if (d == 1 && val > 1)
312 else if (d == 2 && val > 3 && !cmap)
314 else if (d == 4 && val > 15 && !cmap)
316 else if (d == 8 && val > 0xff && !cmap)
318 else if (d == 16 && val > 0xffff)
320 else if (d == 32 && val < 256)
329 for (i = 0; i < nlines; i++) {
336 htext = 1.5 * hbaseline * nlines;
341 hadd = htext + 2 * spacer;
344 pixCopyResolution(pixd, pixs);
345 pixCopyText(pixd, pixs);
352 wadd = wtext + 2 * spacer;
355 pixCopyResolution(pixd, pixs);
356 pixCopyText(pixd, pixs);
366 cmapd = pixGetColormap(pixd);
377 for (i = 0; i < nlines; i++) {
382 (w - wtext) / 2, spacer + hbaseline * (1 + 1.5 * i),
386 (w - wtext) / 2, h + spacer +
387 hbaseline * (1 + 1.5 * i), NULL, NULL);
390 spacer, (h - htext) / 2 + hbaseline * (1 + 1.5 * i),
394 w + spacer, (h - htext) / 2 +
395 hbaseline * (1 + 1.5 * i), NULL, NULL);
446 l_int32 d, h, i, w, x, y, nlines, htext, xwidth, wline, ovf, overflow;
451 return ERROR_INT(
"pixs not defined", __func__, 1);
453 return ERROR_INT(
"bmf not defined", __func__, 1);
455 return ERROR_INT(
"textstr not defined", __func__, 1);
461 cmap = pixGetColormap(pixs);
462 if (d == 1 && val > 1)
464 else if (d == 2 && val > 3 && !cmap)
466 else if (d == 4 && val > 15 && !cmap)
468 else if (d == 8 && val > 0xff && !cmap)
470 else if (d == 16 && val > 0xffff)
472 else if (d == 32 && val < 256)
475 if (w < x0 + wtext) {
476 L_WARNING(
"reducing width of textblock\n", __func__);
477 wtext = w - x0 - w / 10;
479 return ERROR_INT(
"wtext too small; no room for text", __func__, 1);
484 return ERROR_INT(
"line string sa not made", __func__, 1);
490 for (i = 0; i < nlines; i++) {
492 x = x0 + firstindent * xwidth;
505 if (h < y0 - bmf->baselinetab[93] + htext)
508 *poverflow = overflow;
556 l_int32 d, i, x, w, nchar, baseline, index, rval, gval, bval;
562 return ERROR_INT(
"pixs not defined", __func__, 1);
564 return ERROR_INT(
"bmf not defined", __func__, 1);
566 return ERROR_INT(
"teststr not defined", __func__, 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;
653 return (
PIXA *)ERROR_PTR(
"pixas not defined", __func__, NULL);
655 return (
PIXA *)ERROR_PTR(
"bmf not defined", __func__, NULL);
658 return (
PIXA *)ERROR_PTR(
"invalid location", __func__, NULL);
662 for (i = 0; i < n; i++) {
668 snprintf(textstr,
sizeof(textstr),
"%d", index);
721 return (
PIXA *)ERROR_PTR(
"pixas not defined", __func__, NULL);
723 return (
PIXA *)ERROR_PTR(
"bmf not defined", __func__, NULL);
726 return (
PIXA *)ERROR_PTR(
"invalid location", __func__, NULL);
731 if (nstr > 0 && nstr < n)
732 L_WARNING(
"There are %d strings and %d pix\n", __func__, nstr, n);
733 for (i = 0; i < n; i++) {
787 PIX *pix1, *pix2, *pix3;
791 return ERROR_INT(
"pixa not defined", __func__, 1);
793 return ERROR_INT(
"pixs not defined", __func__, 1);
796 return ERROR_INT(
"invalid location", __func__, 1);
801 L_WARNING(
"no textstring defined; inserting copy", __func__);
818 cmap = pixGetColormap(pix1);
819 d = pixGetDepth(pix1);
820 if (!cmap && d != 32)
830 return ERROR_INT(
"pix3 not made", __func__, 1);
864 l_int32 i, ifirst, sumw, newsum, w, nwords, nlines, len, xwidth;
869 return (
SARRAY *)ERROR_PTR(
"bmf not defined", __func__, NULL);
871 return (
SARRAY *)ERROR_PTR(
"teststr not defined", __func__, NULL);
874 return (
SARRAY *)ERROR_PTR(
"sawords not made", __func__, NULL);
878 return (
SARRAY *)ERROR_PTR(
"na not made", __func__, NULL);
884 return (
SARRAY *)ERROR_PTR(
"no words in textstr", __func__, NULL);
891 sumw = firstindent * xwidth + w;
892 for (i = 1; i < nwords; i++) {
899 len = strlen(linestr);
901 linestr[len - 1] =
'\0';
936 l_int32 i, nwords, width;
940 return (
NUMA *)ERROR_PTR(
"bmf not defined", __func__, NULL);
942 return (
NUMA *)ERROR_PTR(
"teststr not defined", __func__, NULL);
944 return (
NUMA *)ERROR_PTR(
"sa not defined", __func__, NULL);
948 return (
NUMA *)ERROR_PTR(
"na not made", __func__, NULL);
950 for (i = 0; i < nwords; i++) {
975 l_int32 i, w, width, nchar;
978 return ERROR_INT(
"bmf not defined", __func__, 1);
980 return ERROR_INT(
"teststr not defined", __func__, 1);
982 return ERROR_INT(
"&w not defined", __func__, 1);
984 nchar = strlen(textstr);
986 for (i = 0; i < nchar; i++) {
1015 char *linestr, *parastring;
1016 l_int32 nlines, i, allwhite, leadwhite;
1017 SARRAY *salines, *satemp, *saout;
1020 return (
SARRAY *)ERROR_PTR(
"textstr not defined", __func__, NULL);
1023 return (
SARRAY *)ERROR_PTR(
"salines not made", __func__, NULL);
1030 for (i = 1; i < nlines; i++) {
1066 return ERROR_INT(
"textstr not defined", __func__, 1);
1068 return ERROR_INT(
"&va not defined", __func__, 1);
1070 len = strlen(textstr);
1072 for (i = 0; i < len; i++) {
1073 if (textstr[i] !=
' ' && textstr[i] !=
'\t' && textstr[i] !=
'\n') {
1094 return ERROR_INT(
"textstr not defined", __func__, 1);
1096 return ERROR_INT(
"&va not defined", __func__, 1);
1099 if (textstr[0] ==
' ' || textstr[0] ==
'\t')
void bmfDestroy(L_BMF **pbmf)
bmfDestroy()
PIX * bmfGetPix(L_BMF *bmf, char chr)
bmfGetPix()
L_BMF * bmfCreate(const char *dir, l_int32 fontsize)
bmfCreate()
l_ok bmfGetBaseline(L_BMF *bmf, char chr, l_int32 *pbaseline)
bmfGetBaseline()
l_ok bmfGetWidth(L_BMF *bmf, char chr, l_int32 *pw)
bmfGetWidth()
l_ok pixcmapAddNearestColor(PIXCMAP *cmap, l_int32 rval, l_int32 gval, l_int32 bval, l_int32 *pindex)
pixcmapAddNearestColor()
l_ok pixcmapGetColor(PIXCMAP *cmap, l_int32 index, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
pixcmapGetColor()
l_ok numaAddNumber(NUMA *na, l_float32 val)
numaAddNumber()
NUMA * numaCreate(l_int32 n)
numaCreate()
void numaDestroy(NUMA **pna)
numaDestroy()
l_int32 numaGetCount(NUMA *na)
numaGetCount()
l_ok numaGetIValue(NUMA *na, l_int32 index, l_int32 *pival)
numaGetIValue()
void pixDestroy(PIX **ppix)
pixDestroy()
l_ok pixGetDimensions(const PIX *pix, l_int32 *pw, l_int32 *ph, l_int32 *pd)
pixGetDimensions()
char * pixGetText(PIX *pix)
pixGetText()
PIX * pixCopy(PIX *pixd, const PIX *pixs)
pixCopy()
l_ok pixCopyColormap(PIX *pixd, const PIX *pixs)
pixCopyColormap()
PIX * pixCreate(l_int32 width, l_int32 height, l_int32 depth)
pixCreate()
PIX * pixClone(PIX *pixs)
pixClone()
l_ok composeRGBPixel(l_int32 rval, l_int32 gval, l_int32 bval, l_uint32 *ppixel)
composeRGBPixel()
void extractRGBValues(l_uint32 pixel, l_int32 *prval, l_int32 *pgval, l_int32 *pbval)
extractRGBValues()
l_ok pixSetBlackOrWhite(PIX *pixs, l_int32 op)
pixSetBlackOrWhite()
l_ok pixPaintThroughMask(PIX *pixd, PIX *pixm, l_int32 x, l_int32 y, l_uint32 val)
pixPaintThroughMask()
l_ok pixaAddPix(PIXA *pixa, PIX *pix, l_int32 copyflag)
pixaAddPix()
PIXA * pixaCreate(l_int32 n)
pixaCreate()
l_int32 pixaGetCount(PIXA *pixa)
pixaGetCount()
PIX * pixaGetPix(PIXA *pixa, l_int32 index, l_int32 accesstype)
pixaGetPix()
PIX * pixConvertTo32(PIX *pixs)
pixConvertTo32()
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()
SARRAY * sarrayCreate(l_int32 n)
sarrayCreate()
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
char * sarrayToStringRange(SARRAY *sa, l_int32 first, l_int32 nstrings, l_int32 addnlflag)
sarrayToStringRange()
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
SARRAY * sarrayCreateWordsFromString(const char *string)
sarrayCreateWordsFromString()
SARRAY * sarrayCreateLinesFromString(const char *string, l_int32 blankflag)
sarrayCreateLinesFromString()
l_ok sarrayAddString(SARRAY *sa, const char *string, l_int32 copyflag)
sarrayAddString()
char * sarrayToString(SARRAY *sa, l_int32 addnlflag)
sarrayToString()
PIX * pixScaleByIntSampling(PIX *pixs, l_int32 factor)
pixScaleByIntSampling()
NUMA * bmfGetWordWidths(L_BMF *bmf, const char *textstr, SARRAY *sa)
bmfGetWordWidths()
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()
SARRAY * bmfGetLineStrings(L_BMF *bmf, const char *textstr, l_int32 maxw, l_int32 firstindent, l_int32 *ph)
bmfGetLineStrings()
SARRAY * splitStringToParagraphs(char *textstr, l_int32 splitflag)
splitStringToParagraphs()
PIX * pixAddTextlines(PIX *pixs, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 location)
pixAddTextlines()
PIX * pixAddSingleTextblock(PIX *pixs, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 location, l_int32 *poverflow)
pixAddSingleTextblock()
l_ok bmfGetStringWidth(L_BMF *bmf, const char *textstr, l_int32 *pw)
bmfGetStringWidth()
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 pixaAddPixWithText(PIXA *pixa, PIX *pixs, l_int32 reduction, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 location)
pixaAddPixWithText()
PIXA * pixaAddTextlines(PIXA *pixas, L_BMF *bmf, SARRAY *sa, l_uint32 val, l_int32 location)
pixaAddTextlines()
static l_int32 stringAllWhitespace(char *textstr, l_int32 *pval)
stringAllWhitespace()
PIXA * pixaAddTextNumber(PIXA *pixas, L_BMF *bmf, NUMA *na, l_uint32 val, l_int32 location)
pixaAddTextNumber()
static l_int32 stringLeadingWhitespace(char *textstr, l_int32 *pval)
stringLeadingWhitespace()