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