| 1 |
/* g2ntotex.c |
| 2 |
* Usage: g2ntotex fontname (converts fontname.g2n to fontname.tex) |
| 3 |
* |
| 4 |
* Copyright 2012 Bob Tennent |
| 5 |
* School of Computing, Queen's University |
| 6 |
* This program is free software, licensed under the GNU GPL, >=2.0. |
| 7 |
* This software comes with absolutely NO WARRANTY. |
| 8 |
* */ |
| 9 |
# include <stdlib.h> |
| 10 |
# include <stdio.h> |
| 11 |
# include <string.h> |
| 12 |
# define FILE_LEN 36 |
| 13 |
# define LINE_LEN 72 |
| 14 |
|
| 15 |
FILE *g2n_file, *tex_file; |
| 16 |
char g2n_filename[FILE_LEN+5]; |
| 17 |
char tex_filename[FILE_LEN+5]; |
| 18 |
|
| 19 |
void error (char msg[]) /* abort with stderr message msg */ |
| 20 |
{ fprintf (stderr, "Error: %s\n", msg); |
| 21 |
exit (EXIT_FAILURE); |
| 22 |
} |
| 23 |
|
| 24 |
int main (int argc, char *argv[]) { |
| 25 |
int ch; |
| 26 |
int gid; |
| 27 |
char codepoint[5]; |
| 28 |
char glyphname [LINE_LEN+1]; |
| 29 |
g2n_filename[0] = '\0'; |
| 30 |
strncat (g2n_filename, argv[1], FILE_LEN); |
| 31 |
strcat (g2n_filename, ".g2n"); |
| 32 |
g2n_file = fopen (g2n_filename, "r+"); |
| 33 |
if (g2n_file == NULL) error("Can't open g2n file."); |
| 34 |
tex_filename[0] = '\0'; |
| 35 |
strncat (tex_filename, argv[1], FILE_LEN); |
| 36 |
strcat (tex_filename, ".tex"); |
| 37 |
tex_file = fopen (tex_filename, "w+"); |
| 38 |
if (tex_file == NULL) error("Can't open tex file."); |
| 39 |
/* skip first line: */ |
| 40 |
ch = getc (g2n_file); while (ch != '\n') { ch = getc (g2n_file);} |
| 41 |
while (fscanf (g2n_file, |
| 42 |
"GLYPHID%i PSNAME %s UNICODE %s\n", |
| 43 |
&gid, &glyphname, &codepoint) |
| 44 |
== 3 ) |
| 45 |
{ int glyphindex; |
| 46 |
sscanf ( codepoint, "%x", &glyphindex); /* convert hex codepoint to integer index */ |
| 47 |
if (glyphname[0] != 'u' || glyphname[1] != 'n' || glyphname[2] != 'i' ) { |
| 48 |
fprintf (tex_file, "\\DeclareTextGlyphY{%s}{%s}{%i}\n", argv[1], glyphname, glyphindex); |
| 49 |
} |
| 50 |
fprintf (tex_file, "\\DeclareTextGlyphY{%s}{uni%s}{%i}\n", argv[1], codepoint, glyphindex); |
| 51 |
} |
| 52 |
return 0; |
| 53 |
} |