Leptonica 1.68
C Image Processing Library

genfonts.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  * genfonts.c
00018  *
00019  *    This program can be used to generate characters for a
00020  *    font and save them in .pixa format.
00021  *
00022  *    The tiff images of bitmaps fonts, which are used as input
00023  *    to this generator, are supplied in Leptonica in the prog/fonts
00024  *    directory.  The tiff images were generated from the PostScript files
00025  *    in that directory, using the shell script prog/ps2tiff.  If you
00026  *    want to generate other fonts, modify the PostScript files
00027  *    and use ps2tiff.  ps2tiff uses GhostScript.
00028  */
00029 
00030 #include "allheaders.h"
00031 
00032 #define   NFONTS        9
00033 #define   TEST_DIR      "/tmp/fonts"
00034 #define   INSTALL_DIR   "fonts"
00035 
00036 const char  *outputfonts[] = {"chars-4.pixa", "chars-6.pixa",
00037                               "chars-8.pixa", "chars-10.pixa",
00038                               "chars-12.pixa", "chars-14.pixa",
00039                               "chars-16.pixa", "chars-18.pixa",
00040                               "chars-20.pixa"};
00041 
00042 const l_int32 sizes[] = { 4, 6, 8, 10, 12, 14, 16, 18, 20 };
00043 
00044 #define  DEBUG            1
00045 
00046 
00047 main(int    argc,
00048      char **argv)
00049 {
00050 char         buf[512];
00051 char        *pathname;
00052 l_int32      i, bl1, bl2, bl3;
00053 PIX         *pixd;
00054 PIXA        *pixa;
00055 static char  mainName[] = "genfonts";
00056 
00057     if (argc != 1)
00058         exit(ERROR_INT(" Syntax:  genfonts", mainName, 1));
00059 
00060     /* ------------  Generate all the pixa char bitmap files ----------- */
00061 #if 1
00062     for (i = 0; i < 9; i++) { 
00063         pixaSaveFont(INSTALL_DIR, TEST_DIR, sizes[i]);
00064 
00065 #if DEBUG
00066         pathname = genPathname(INSTALL_DIR, outputfonts[i]);
00067         pixa = pixaRead(pathname);
00068         fprintf(stderr, "Found %d chars in font size %d\n",
00069                 pixaGetCount(pixa), sizes[i]);
00070         pixd = pixaDisplayTiled(pixa, 1500, 0, 15);
00071         pixDisplay(pixd, 100 * i, 200);
00072         pixDestroy(&pixd);
00073         pixaDestroy(&pixa);
00074         lept_free(pathname);
00075 #endif  /* DEBUG */
00076 
00077     }
00078 #endif
00079 
00080 
00081     /* -----  Use pixaGetFont() and write the result out  -----*/
00082 #if 1
00083     for (i = 0; i < 9; i++) { 
00084         pixa = pixaGetFont(INSTALL_DIR, sizes[i], &bl1, &bl2, &bl3);
00085         fprintf(stderr, "Baselines are at: %d, %d, %d\n", bl1, bl2, bl3);
00086         snprintf(buf, sizeof(buf), "/tmp/junkchars.%d.pixa", sizes[i]);
00087         pixaWrite(buf, pixa);
00088 
00089 #if DEBUG
00090         pixd = pixaDisplayTiled(pixa, 1500, 0, 15);
00091         pixDisplay(pixd, 100 * i, 700);
00092         pixDestroy(&pixd);
00093 #endif  /* DEBUG */
00094 
00095         pixaDestroy(&pixa);
00096     }
00097 #endif
00098 
00099 
00100     /* ------------  Get timing for font generation ----------- */
00101 #if 0
00102     startTimer();
00103     i = 8;
00104     pixa = pixaGenerateFont(DIRECTORY, sizes[i], &bl1, &bl2, &bl3);
00105     pixaDestroy(&pixa);
00106     fprintf(stderr, "Time for font gen = %7.3f sec\n", stopTimer());
00107 #endif
00108 
00109 
00110     return 0;
00111 }
00112 
00113 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines