128l_int32 w, h, d, i, y, xstart, ystart, extra, spacer, rval, gval, bval;
129l_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__);
143 return pixCopy(NULL, pixs);
146 textstr = pixGetText(pixs);
148 L_WARNING(
"no textstring defined; returning a copy\n", __func__);
149 return pixCopy(NULL, pixs);
155 pixGetDimensions(pixs, &w, &h, &d);
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);
174 nlines = sarrayGetCount(salines);
179 extra = htext + 2 * spacer;
180 pixd = pixCreate(w, h + extra, d);
181 pixCopyColormap(pixd, pixs);
182 pixCopyResolution(pixd, pixs);
183 pixCopyText(pixd, pixs);
186 pixRasterop(pixd, 0, extra, w, h,
PIX_SRC, pixs, 0, 0);
188 pixRasterop(pixd, 0, 0, w, h,
PIX_SRC, pixs, 0, 0);
190 pixd = pixCopy(NULL, pixs);
192 cmapd = pixGetColormap(pixd);
200 ystart = offset + spacer;
202 ystart = h - htext - spacer + offset;
204 ystart = h + offset + spacer;
209 extractRGBValues(val, &rval, &gval, &bval);
210 pixcmapAddNearestColor(cmapd, rval, gval, bval, &index);
211 pixcmapGetColor(cmapd, index, &rval, &gval, &bval);
212 composeRGBPixel(rval, gval, bval, &textcolor);
219 for (i = 0, y = ystart; i < nlines; i++) {
220 linestr = sarrayGetString(salines, i,
L_NOCOPY);
222 xstart, y, NULL, &ovf);
232 if (h < htext + 2 * spacer)
235 if (poverflow) *poverflow = overflow;
237 sarrayDestroy(&salines);
281l_int32 i, w, h, d, rval, gval, bval, index;
282l_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__);
295 return pixCopy(NULL, pixs);
298 textstr = pixGetText(pixs);
300 L_WARNING(
"no textstring defined; returning a copy\n", __func__);
301 return pixCopy(NULL, pixs);
308 pixGetDimensions(pixs, &w, &h, &d);
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)
324 sa = sarrayCreateLinesFromString(textstr, 0);
325 nlines = sarrayGetCount(sa);
329 for (i = 0; i < nlines; i++) {
330 str = sarrayGetString(sa, i,
L_NOCOPY);
336 htext = 1.5 * hbaseline * nlines;
341 hadd = htext + 2 * spacer;
342 pixd = pixCreate(w, h + hadd, d);
343 pixCopyColormap(pixd, pixs);
344 pixCopyResolution(pixd, pixs);
345 pixCopyText(pixd, pixs);
348 pixRasterop(pixd, 0, hadd, w, h,
PIX_SRC, pixs, 0, 0);
350 pixRasterop(pixd, 0, 0, w, h,
PIX_SRC, pixs, 0, 0);
352 wadd = wtext + 2 * spacer;
353 pixd = pixCreate(w + wadd, h, d);
354 pixCopyColormap(pixd, pixs);
355 pixCopyResolution(pixd, pixs);
356 pixCopyText(pixd, pixs);
359 pixRasterop(pixd, wadd, 0, w, h,
PIX_SRC, pixs, 0, 0);
361 pixRasterop(pixd, 0, 0, w, h,
PIX_SRC, pixs, 0, 0);
366 cmapd = pixGetColormap(pixd);
368 extractRGBValues(val, &rval, &gval, &bval);
369 pixcmapAddNearestColor(cmapd, rval, gval, bval, &index);
370 pixcmapGetColor(cmapd, index, &rval, &gval, &bval);
371 composeRGBPixel(rval, gval, bval, &textcolor);
377 for (i = 0; i < nlines; i++) {
378 str = sarrayGetString(sa, i,
L_NOCOPY);
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);
446l_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);
460 pixGetDimensions(pixs, &w, &h, &d);
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);
485 nlines = sarrayGetCount(salines);
486 bmfGetWidth(bmf,
'x', &xwidth);
490 for (i = 0; i < nlines; i++) {
492 x = x0 + firstindent * xwidth;
495 linestr = sarrayGetString(salines, i,
L_NOCOPY);
505 if (h < y0 - bmf->baselinetab[93] + htext)
508 *poverflow = overflow;
510 sarrayDestroy(&salines);
556l_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)
586 extractRGBValues(val, &rval, &gval, &bval);
587 pixcmapAddNearestColor(cmap, rval, gval, bval, &index);
588 pixcmapGetColor(cmap, index, &rval, &gval, &bval);
589 composeRGBPixel(rval, gval, bval, &textcolor);
593 nchar = strlen(textstr);
595 for (i = 0; i < nchar; i++) {
597 if ((l_int32)chr == 10)
continue;
598 pix = bmfGetPix(bmf, chr);
599 bmfGetBaseline(bmf, chr, &baseline);
600 pixPaintThroughMask(pixs, pix, x, y0 - baseline, textcolor);
601 w = pixGetWidth(pix);
609 *poverflow = (x > pixGetWidth(pixs) - 1) ? 1 : 0;
864l_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);
873 if ((sawords = sarrayCreateWordsFromString(textstr)) == NULL)
874 return (
SARRAY *)ERROR_PTR(
"sawords not made", __func__, NULL);
877 sarrayDestroy(&sawords);
878 return (
SARRAY *)ERROR_PTR(
"na not made", __func__, NULL);
880 nwords = numaGetCount(na);
882 sarrayDestroy(&sawords);
884 return (
SARRAY *)ERROR_PTR(
"no words in textstr", __func__, NULL);
886 bmfGetWidth(bmf,
'x', &xwidth);
888 sa = sarrayCreate(0);
890 numaGetIValue(na, 0, &w);
891 sumw = firstindent * xwidth + w;
892 for (i = 1; i < nwords; i++) {
893 numaGetIValue(na, i, &w);
896 linestr = sarrayToStringRange(sawords, ifirst, i - ifirst, 2);
899 len = strlen(linestr);
901 linestr[len - 1] =
'\0';
902 sarrayAddString(sa, linestr,
L_INSERT);
909 linestr = sarrayToStringRange(sawords, ifirst, nwords - ifirst, 2);
911 sarrayAddString(sa, linestr,
L_INSERT);
912 nlines = sarrayGetCount(sa);
915 sarrayDestroy(&sawords);
1015char *linestr, *parastring;
1016l_int32 nlines, i, allwhite, leadwhite;
1017SARRAY *salines, *satemp, *saout;
1020 return (
SARRAY *)ERROR_PTR(
"textstr not defined", __func__, NULL);
1022 if ((salines = sarrayCreateLinesFromString(textstr, 1)) == NULL)
1023 return (
SARRAY *)ERROR_PTR(
"salines not made", __func__, NULL);
1024 nlines = sarrayGetCount(salines);
1025 saout = sarrayCreate(0);
1026 satemp = sarrayCreate(0);
1028 linestr = sarrayGetString(salines, 0,
L_NOCOPY);
1029 sarrayAddString(satemp, linestr,
L_COPY);
1030 for (i = 1; i < nlines; i++) {
1031 linestr = sarrayGetString(salines, i,
L_NOCOPY);
1037 parastring = sarrayToString(satemp, 1);
1038 sarrayAddString(saout, parastring,
L_INSERT);
1039 sarrayDestroy(&satemp);
1040 satemp = sarrayCreate(0);
1042 sarrayAddString(satemp, linestr,
L_COPY);
1044 parastring = sarrayToString(satemp, 1);
1045 sarrayAddString(saout, parastring,
L_INSERT);
1046 sarrayDestroy(&satemp);
1047 sarrayDestroy(&salines);
PIXA * pixaAddTextNumber(PIXA *pixas, L_BMF *bmf, NUMA *na, l_uint32 val, l_int32 location)
pixaAddTextNumber()
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 * pixAddTextlines(PIX *pixs, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 location)
pixAddTextlines()
SARRAY * splitStringToParagraphs(char *textstr, l_int32 splitflag)
splitStringToParagraphs()
l_ok bmfGetStringWidth(L_BMF *bmf, const char *textstr, l_int32 *pw)
bmfGetStringWidth()
PIX * pixAddSingleTextblock(PIX *pixs, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 location, l_int32 *poverflow)
pixAddSingleTextblock()
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()
NUMA * bmfGetWordWidths(L_BMF *bmf, const char *textstr, SARRAY *sa)
bmfGetWordWidths()
l_ok pixaAddPixWithText(PIXA *pixa, PIX *pixs, l_int32 reduction, L_BMF *bmf, const char *textstr, l_uint32 val, l_int32 location)
pixaAddPixWithText()
static l_int32 stringAllWhitespace(char *textstr, l_int32 *pval)
stringAllWhitespace()
SARRAY * bmfGetLineStrings(L_BMF *bmf, const char *textstr, l_int32 maxw, l_int32 firstindent, l_int32 *ph)
bmfGetLineStrings()
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()