(file) Return to afmtest.c CVS log (file) (dir) Up to [RizwankCVS] / testProject / afmlib

  1 rizwank 1.1 /*
  2              * Tester program for the AFM library.
  3              * Copyright (c) 1995-1999 Markku Rossi.
  4              *
  5              * Author: Markku Rossi <mtr@iki.fi>
  6              */
  7             
  8             /*
  9              * This program is free software; you can redistribute it and/or modify
 10              * it under the terms of the GNU General Public License as published by
 11              * the Free Software Foundation; either version 2, or (at your option)
 12              * any later version.
 13              *
 14              * This program is distributed in the hope that it will be useful,
 15              * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16              * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 17              * GNU General Public License for more details.
 18              *
 19              * You should have received a copy of the GNU General Public License
 20              * along with this program; see the file COPYING.  If not, write to
 21              * the Free Software Foundation, 59 Temple Place - Suite 330,
 22 rizwank 1.1  * Boston, MA 02111-1307, USA.
 23              */
 24             
 25             #include <stdio.h>
 26             
 27             #ifdef HAVE_CONFIG_H
 28             #include "config.h"
 29             #endif
 30             
 31             #if STDC_HEADERS
 32             #include <stdlib.h>
 33             #endif
 34             
 35             #if HAVE_STRING_H
 36             #include <string.h>
 37             #endif
 38             
 39             #include "afm.h"
 40             
 41             /*
 42              * Types and definitions.
 43 rizwank 1.1  */
 44             
 45             #define HANDLE_ERROR(msg)				\
 46               if (error != AFM_SUCCESS)				\
 47                 {							\
 48                   char buf[256];					\
 49                   afm_error_to_string (error, buf);			\
 50                   fprintf (stderr, "afmtest: %s: %s\n", msg, buf);	\
 51                   exit (1);						\
 52                 }
 53             
 54             
 55             /*
 56              * Prototypes for static functions.
 57              */
 58             
 59             static void usage ();
 60             
 61             
 62             /*
 63              * Static variables
 64 rizwank 1.1  */
 65             
 66             static char *program;
 67             
 68             
 69             /*
 70              * Global functions.
 71              */
 72             
 73             int
 74             main (int argc, char *argv[])
 75             {
 76               AFMHandle afm;
 77               AFMFont font;
 78               AFMError error;
 79               AFMNumber width, height;
 80               char buf[256];
 81             
 82               program = strrchr (argv[0], '/');
 83               if (program)
 84                 program++;
 85 rizwank 1.1   else
 86                 program = argv[0];
 87             
 88               error = afm_create (NULL, 0, &afm);
 89               HANDLE_ERROR ("couldn't create library");
 90             
 91               if (argc < 2)
 92                 {
 93                   usage ();
 94                   exit (1);
 95                 }
 96             
 97               if (strcmp (argv[1], "dump") == 0 && argc == 3)
 98                 {
 99                   error = afm_open_file (afm, AFM_I_ALL, argv[2], &font);
100                   if (error != AFM_SUCCESS)
101             	{
102             	  fprintf (stderr, "%s: couldn't open font \"%s\", using default\n",
103             		   program, argv[2]);
104             	  error = afm_open_default_font (afm, &font);
105             	  HANDLE_ERROR ("couldn't open default font");
106 rizwank 1.1 	}
107             
108                   afm_font_dump (stdout, font);
109             
110                   error = afm_close_font (font);
111                   HANDLE_ERROR ("couldn't close font");
112                 }
113               else if (strcmp (argv[1], "stringwidth") == 0 && argc == 5)
114                 {
115                   error = afm_open_file (afm, AFM_I_ALL, argv[2], &font);
116                   HANDLE_ERROR ("couldn't open font");
117             
118                   error = afm_font_encoding (font, AFM_ENCODING_ISO_8859_1, 0);
119                   HANDLE_ERROR ("couldn't encode font");
120             
121                   error = afm_font_stringwidth (font, atof (argv[3]), argv[4],
122             				    strlen (argv[4]), &width, &height);
123                   printf ("stringwidth is [%g %g]\n", width, height);
124             
125                   error = afm_close_font (font);
126                   HANDLE_ERROR ("couldn't close font");
127 rizwank 1.1     }
128               else if (strcmp (argv[1], "chardump") == 0 && argc > 2)
129                 {
130                   int i, j;
131             
132                   for (i = 2; i < argc; i++)
133             	{
134             	  error = afm_open_file (afm, AFM_I_COMPOSITES, argv[i], &font);
135             	  if (error != AFM_SUCCESS)
136             	    {
137             	      afm_error_to_string (error, buf);
138             	      fprintf (stderr, "%s: couldn't open AFM file \"%s\": %s\n",
139             		       program, argv[i], buf);
140             	      continue;
141             	    }
142             
143             	  for (j = 0; j < font->num_character_metrics; j++)
144             	    {
145             	      AFMIndividualCharacterMetrics *cm;
146             	      cm = &font->character_metrics[j];
147             
148 rizwank 1.1 	      printf ("/%-30s %3ld glyph %s\n", cm->name, cm->character_code,
149             		      font->global_info.FontName);
150             	    }
151             
152             	  for (j = 0; j < font->num_composites; j++)
153             	    {
154             	      AFMComposite *cc;
155             	      cc = &font->composites[j];
156             
157             	      printf ("/%-30s -1 composite %s\n", cc->name,
158             		      font->global_info.FontName);
159             	    }
160             
161             	  (void) afm_close_font (font);
162             	}
163                 }
164               else
165                 {
166                   usage ();
167                   exit (1);
168                 }
169 rizwank 1.1 
170               return 0;
171             }
172             
173             
174             /*
175              * Static functions.
176              */
177             
178             static void
179             usage ()
180             {
181               fprintf (stderr,
182             	   "Usage: %s dump file\n"
183             	   "       %s stringwidth file ptsize string\n"
184             	   "       %s chardump file [file ...]\n",
185             	   program, program, program);
186             }

Rizwan Kassim
Powered by
ViewCVS 0.9.2