src/textops.c
l_int32
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)
{
char     *linestr;
l_int32   d, h, i, w, x, y, nlines, htext, xwidth, wline, ovf, overflow;
SARRAY   *salines;
PIXCMAP  *cmap;

    PROCNAME("pixSetTextblock");

    if (!pixs)
        return ERROR_INT("pixs not defined", procName, 1);
    if (!bmf)
        return ERROR_INT("bmf not defined", procName, 1);
    if (!textstr)
        return ERROR_INT("textstr not defined", procName, 1);
    if (val < 0)
        return ERROR_INT("val must be >= 0", procName, 1);

        /* Make sure the "color" value for the text will work
         * for the pix.  If the pix is not colormapped and the
         * value is out of range, set it to mid-range. */
    pixGetDimensions(pixs, &w, &h, &d);
    cmap = pixGetColormap(pixs);
    if (d == 1 && val > 1)
        val = 1;
    else if (d == 2 && val > 3 && !cmap)
        val = 2;
    else if (d == 4 && val > 15 && !cmap)
        val = 8;
    else if (d == 8 && val > 0xff && !cmap)
        val = 128;
    else if (d == 16 && val > 0xffff)
        val = 0x8000;
    else if (d == 32 && val < 256)
        val = 0x80808000;

    if (w < x0 + wtext) {
        L_WARNING("reducing width of textblock", procName);
        wtext = w - x0 - w / 10;
        if (wtext <= 0)
            return ERROR_INT("wtext too small; no room for text", procName, 1);
    }

    salines = bmfGetLineStrings(bmf, textstr, wtext, firstindent, &htext);
    if (!salines)
        return ERROR_INT("line string sa not made", procName, 1);
    nlines = sarrayGetCount(salines);
    bmfGetWidth(bmf, 'x', &xwidth);

    y = y0;
    overflow = 0;
    for (i = 0; i < nlines; i++) {
        if (i == 0)
            x = x0 + firstindent * xwidth;
        else
            x = x0;
        linestr = sarrayGetString(salines, i, 0);
        pixSetTextline(pixs, bmf, linestr, val, x, y, &wline, &ovf);
        y += bmf->lineheight + bmf->vertlinesep;
        if (ovf)
            overflow = 1;
    }

       /* (y0 - baseline) is the top of the printed text.  Character
        * 93 was chosen at random, as all the baselines are essentially
        * equal for each character in a font. */
    if (h < y0 - bmf->baselinetab[93] + htext)
        overflow = 1;
    if (poverflow)
        *poverflow = overflow;

    sarrayDestroy(&salines);
    return 0;
}
/*!
 *  pixSetTextblock()
 *
 *      Input:  pixs (input image)
 *              bmf (bitmap font data)
 *              textstr (block text string to be set)
 *              val (color to set the text)
 *              x0 (left edge for each line of text)
 *              y0 (baseline location for the first text line)
 *              wtext (max width of each line of generated text)
 *              firstindent (indentation of first line, in x-widths)
 *              &overflow (<optional return> 0 if text is contained in
 *                         input pix; 1 if it is clipped)
 *      Return: 0 if OK, 1 on error
 *
 *  Notes:
 *      (1) This function paints a set of lines of text over an image.
 *      (2) @val is the pixel value to be painted through the font mask.
 *          It should be chosen to agree with the depth of pixs.
 *          If it is out of bounds, an intermediate value is chosen.
 *          For RGB, use hex notation: 0xRRGGBB00, where RR is the
 *          hex representation of the red intensity, etc.
 *          The last two hex digits are 00 (byte value 0), assigned to
 *          the A component.  Note that, as usual, RGBA proceeds from 
 *          left to right in the order from MSB to LSB (see pix.h
 *          for details).
 *      (3) If there is a colormap, this does the best it can to use
 *          the requested color, or something similar to it.
 */


(1) This function paints a set of lines of text over an image.
(2) @val is the pixel value to be painted through the font mask.
It should be chosen to agree with the depth of pixs.
If it is out of bounds, an intermediate value is chosen.
For RGB, use hex notation: 0xRRGGBB00, where RR is the
hex representation of the red intensity, etc.
The last two hex digits are 00 (byte value 0), assigned to
the A component.  Note that, as usual, RGBA proceeds from
left to right in the order from MSB to LSB (see pix.h
for details).
(3) If there is a colormap, this does the best it can to use
the requested color, or something similar to it.
( 1 ) This function paints a set of lines of text over an image . ( 2 ) @val is the pixel value to be painted through the font mask . It should be chosen to agree with the depth of pixs . If it is out of bounds an intermediate value is chosen . For RGB use hex notation : 0xRRGGBB00 where RR is the hex representation of the red intensity etc . The last two hex digits are 00 ( byte value 0 ) assigned to the A component . Note that as usual RGBA proceeds from left to right in the order from MSB to LSB ( see pix . h for details ) . ( 3 ) If there is a colormap this does the best it can to use the requested color or something similar to it .
l_int32
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)
{
char     *linestr;
l_int32   d, h, i, w, x, y, nlines, htext, xwidth, wline, ovf, overflow;
SARRAY   *salines;
PIXCMAP  *cmap;
    PROCNAME("pixSetTextblock");
    if (!pixs)
        return ERROR_INT("pixs not defined", procName, 1);
    if (!bmf)
        return ERROR_INT("bmf not defined", procName, 1);
    if (!textstr)
        return ERROR_INT("textstr not defined", procName, 1);
    if (val < 0)
        return ERROR_INT("val must be >= 0", procName, 1);
    pixGetDimensions(pixs, &w, &h, &d);
    cmap = pixGetColormap(pixs);
    if (d == 1 && val > 1)
        val = 1;
    else if (d == 2 && val > 3 && !cmap)
        val = 2;
    else if (d == 4 && val > 15 && !cmap)
        val = 8;
    else if (d == 8 && val > 0xff && !cmap)
        val = 128;
    else if (d == 16 && val > 0xffff)
        val = 0x8000;
    else if (d == 32 && val < 256)
        val = 0x80808000;
    if (w < x0 + wtext) {
        L_WARNING("reducing width of textblock", procName);
        wtext = w - x0 - w / 10;
        if (wtext <= 0)
            return ERROR_INT("wtext too small; no room for text", procName, 1);
    }
    salines = bmfGetLineStrings(bmf, textstr, wtext, firstindent, &htext);
    if (!salines)
        return ERROR_INT("line string sa not made", procName, 1);
    nlines = sarrayGetCount(salines);
    bmfGetWidth(bmf, 'x', &xwidth);
    y = y0;
    overflow = 0;
    for (i = 0; i < nlines; i++) {
        if (i == 0)
            x = x0 + firstindent * xwidth;
        else
            x = x0;
        linestr = sarrayGetString(salines, i, 0);
        pixSetTextline(pixs, bmf, linestr, val, x, y, &wline, &ovf);
        y += bmf->lineheight + bmf->vertlinesep;
        if (ovf)
            overflow = 1;
    }
    if (h < y0 - bmf->baselinetab[93] + htext)
        overflow = 1;
    if (poverflow)
        *poverflow = overflow;
    sarrayDestroy(&salines);
    return 0;
}
l_int32 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 ) { char * linestr ; l_int32 d , h , i , w , x , y , nlines , htext , xwidth , wline , ovf , overflow ; SARRAY * salines ; PIXCMAP * cmap ; PROCNAME ( " " ) ; if ( ! pixs ) return ERROR_INT ( " " , procName , 1 ) ; if ( ! bmf ) return ERROR_INT ( " " , procName , 1 ) ; if ( ! textstr ) return ERROR_INT ( " " , procName , 1 ) ; if ( val < 0 ) return ERROR_INT ( " " , procName , 1 ) ; pixGetDimensions ( pixs , & w , & h , & d ) ; cmap = pixGetColormap ( pixs ) ; if ( d == 1 && val > 1 ) val = 1 ; else if ( d == 2 && val > 3 && ! cmap ) val = 2 ; else if ( d == 4 && val > 15 && ! cmap ) val = 8 ; else if ( d == 8 && val > 0xff && ! cmap ) val = 128 ; else if ( d == 16 && val > 0xffff ) val = 0x8000 ; else if ( d == 32 && val < 256 ) val = 0x80808000 ; if ( w < x0 + wtext ) { L_WARNING ( " " , procName ) ; wtext = w - x0 - w / 10 ; if ( wtext <= 0 ) return ERROR_INT ( " " , procName , 1 ) ; } salines = bmfGetLineStrings ( bmf , textstr , wtext , firstindent , & htext ) ; if ( ! salines ) return ERROR_INT ( " " , procName , 1 ) ; nlines = sarrayGetCount ( salines ) ; bmfGetWidth ( bmf , ' ' , & xwidth ) ; y = y0 ; overflow = 0 ; for ( i = 0 ; i < nlines ; i ++ ) { if ( i == 0 ) x = x0 + firstindent * xwidth ; else x = x0 ; linestr = sarrayGetString ( salines , i , 0 ) ; pixSetTextline ( pixs , bmf , linestr , val , x , y , & wline , & ovf ) ; y += bmf -> lineheight + bmf -> vertlinesep ; if ( ovf ) overflow = 1 ; } if ( h < y0 - bmf -> baselinetab [ 93 ] + htext ) overflow = 1 ; if ( poverflow ) * poverflow = overflow ; sarrayDestroy ( & salines ) ; return 0 ; }
pixSetTextblock()
      Input:  pixs (input image)
              bmf (bitmap font data)
              textstr (block text string to be set)
              val (color to set the text)
              x0 (left edge for each line of text)
              y0 (baseline location for the first text line)
              wtext (max width of each line of generated text)
              firstindent (indentation of first line, in x-widths)
              &overflow (<optional return> 0 if text is contained in
                         input pix; 1 if it is clipped)
      Return: 0 if OK, 1 on error
pixSetTextblock () Input : pixs ( input image ) bmf ( bitmap font data ) textstr ( block text string to be set ) val ( color to set the text ) x0 ( left edge for each line of text ) y0 ( baseline location for the first text line ) wtext ( max width of each line of generated text ) firstindent ( indentation of first line in x - widths ) &overflow ( <optional return > 0 if text is contained in input pix ; 1 if it is clipped ) Return : 0 if OK 1 on error
/* Make sure the "color" value for the text will work
         * for the pix.  If the pix is not colormapped and the
         * value is out of range, set it to mid-range. */ /* (y0 - baseline) is the top of the printed text.  Character
        * 93 was chosen at random, as all the baselines are essentially
        * equal for each character in a font. */