Leptonica 1.68
C Image Processing Library

renderfonts.c

Go to the documentation of this file.
00001 /*====================================================================*
00002  -  Copyright (C) 2001 Leptonica.  All rights reserved.
00003  -  This software is distributed in the hope that it will be
00004  -  useful, but with NO WARRANTY OF ANY KIND.
00005  -  No author or distributor accepts responsibility to anyone for the
00006  -  consequences of using this software, or for whether it serves any
00007  -  particular purpose or works at all, unless he or she says so in
00008  -  writing.  Everyone is granted permission to copy, modify and
00009  -  redistribute this source code, for commercial or non-commercial
00010  -  purposes, with the following restrictions: (1) the origin of this
00011  -  source code must not be misrepresented; (2) modified versions must
00012  -  be plainly marked as such; and (3) this notice may not be removed
00013  -  or altered from any source or modified source distribution.
00014  *====================================================================*/
00015 
00016 /*
00017  * renderfonts.c
00018  *
00019  *     This tests the font rendering functions
00020  */
00021 
00022 #include "allheaders.h"
00023 
00024 #define   NFONTS   9
00025 #define   DIRECTORY    "./fonts"
00026 
00027 const l_int32 sizes[] = { 4, 6, 8, 10, 12, 14, 16, 18, 20 };
00028 
00029 #define  DEBUG            0
00030 
00031 
00032 main(int    argc,
00033      char **argv)
00034 {
00035 char        *filein, *fileout, *textstr;
00036 l_int32      i, d, size, width, wtext, overflow;
00037 l_uint32     val;
00038 L_BMF       *bmf;
00039 PIX         *pixs, *pix;
00040 static char  mainName[] = "renderfonts";
00041 
00042     if (argc != 4)
00043         exit(ERROR_INT("Syntax: renderfonts filein size fileout", mainName, 1));
00044 
00045     filein = argv[1];
00046     size = atoi(argv[2]);
00047     fileout = argv[3];
00048 
00049     if ((pixs = pixRead(filein)) == NULL)
00050         exit(ERROR_INT("pixs not made", mainName, 1));
00051     d = pixGetDepth(pixs);
00052     if (d == 8)
00053         val = 128;
00054     else if (d == 16)
00055         val = 0x8000;
00056     else if (d == 32)
00057         composeRGBPixel(128, 0, 255, &val);
00058     else
00059         exit(ERROR_INT("pixs not 8, 16 or 32 bpp", mainName, 1));
00060 
00061     bmf = bmfCreate(DIRECTORY, size);
00062 
00063 #if 0  /* render a character of text */
00064     pix = pixaGetPix(bmf->pixa, 45, L_CLONE);
00065     startTimer();
00066     for (i = 0; i < 10000; i++)
00067         pixSetMaskedGeneral(pixs, pix, val, 150, 150);
00068     fprintf(stderr, "time: %7.3f sec\n", stopTimer());
00069     pixWrite(fileout, pixs, IFF_JFIF_JPEG);
00070     pixDestroy(&pix);
00071 #endif
00072 
00073 #if 0  /* render a line of text; use marge.jpg with size 14 */
00074     bmfGetStringWidth(bmf, "This is a funny cat!", &width);
00075     fprintf(stderr, "String width: %d pixels\n", width);
00076 
00077     pixSetTextline(pixs, bmf, "This is a funny cat!", 0x8000ff00, 50, 250,
00078                    &width, &overflow);
00079     pixWrite(fileout, pixs, IFF_JFIF_JPEG);
00080     fprintf(stderr, "Text width = %d\n", width);
00081     if (overflow)
00082         fprintf(stderr, "Text overflow beyond image boundary\n");
00083 #endif
00084 
00085 #if 1  /* render a block of text; use marge.jpg with size 14 */
00086     textstr = stringNew("This is a cat! This is a funny cat! This is a funny funny cat! This is a funny funny funny cat!");
00087 
00088     wtext = pixGetWidth(pixs) - 70;
00089     pixSetTextblock(pixs, bmf, textstr, 0x4040ff00, 50, 50, wtext,
00090                     1, &overflow);
00091     pixWrite(fileout, pixs, IFF_JFIF_JPEG);
00092     if (overflow)
00093         fprintf(stderr, "Text overflow beyond image boundary\n");
00094     lept_free(textstr);
00095 #endif
00096 
00097     pixDestroy(&pixs);
00098     bmfDestroy(&bmf);
00099     return 0;
00100 }
00101 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines