|
|
#include "document.h" | #include "document.h" |
#include "quotearg.h" | #include "quotearg.h" |
#include "strverscmp.h" | #include "strverscmp.h" |
|
#ifdef USE_LIBJCODE |
|
int use_libjcode = false; |
|
#endif |
| |
/* Suffix of the Encoding Description Files */ | /* Suffix of the Encoding Description Files */ |
#define EDF_SUFFIX ".edf" | #define EDF_SUFFIX ".edf" |
|
|
* Association of suffixes rules, and corresponding style sheet | * Association of suffixes rules, and corresponding style sheet |
* (The hashing is upon `alias') | * (The hashing is upon `alias') |
*/ | */ |
|
struct slantfont_info { |
|
char * name; |
|
char * src; |
|
float raito; |
|
}; |
|
|
struct encoding { | struct encoding { |
char * key; /* e.g. latin1 */ | char * key; /* e.g. latin1 */ |
char * name; /* e.g. ISO Latin 1 */ | char * name; /* e.g. ISO Latin 1 */ |
|
int composite_flag; /* flag for composite font */ |
uchar * documentation; /* Useful pieces of text */ | uchar * documentation; /* Useful pieces of text */ |
| |
char * default_font; /* When a font can't be used | char * default_font; /* When a font can't be used |
define the font to use */ | define the font to use */ |
struct pair_htable * substitutes; /* e.g. in latin2, don't use | struct pair_htable * substitutes; /* e.g. in latin2, don't use |
* Courier, but Courier-Ogonki */ | * Courier, but Courier-Ogonki */ |
|
struct pair_htable * composite; |
|
|
|
struct slantfont_info slantfont[NB_FACES]; |
| |
char * vector[256]; /* Define the char set */ | char * vector[256]; /* Define the char set */ |
struct darray * font_names_used; | struct darray * font_names_used; |
|
|
struct hash_table_s * fonts; /* Contains cells that are | struct hash_table_s * fonts; /* Contains cells that are |
* 1. name of font, 2. int wx[256] */ | * 1. name of font, 2. int wx[256] */ |
unsigned int * faces_wx[NB_FACES]; | unsigned int * faces_wx[NB_FACES]; |
|
|
|
unsigned int composite_wx[NB_FACES]; /* fixed length font width*/ |
|
float composite_raito[NB_FACES]; /* size raito of additonal and orinal font */ |
}; | }; |
| |
/* | /* |
|
|
res->name = NULL; | res->name = NULL; |
res->default_font = NULL; | res->default_font = NULL; |
res->documentation = NULL; | res->documentation = NULL; |
|
res->composite_flag = false; |
| |
/* Vector will be set by setup */ | /* Vector will be set by setup */ |
res->substitutes = pair_table_new (); | res->substitutes = pair_table_new (); |
|
res->composite = pair_table_new (); |
|
res->slantfont[0].name = NULL; |
res->font_names_used = da_new ("List of font names", 10, | res->font_names_used = da_new ("List of font names", 10, |
da_linear, 10, | da_linear, 10, |
(da_print_func_t) da_str_print, | (da_print_func_t) da_str_print, |
|
|
} | } |
| |
/* | /* |
|
* Add a composite font in the current encoding |
|
*/ |
|
static void |
|
encoding_add_composite_font (struct encoding * encoding, |
|
const char * orig, const char * subs, |
|
int wx, float raito) |
|
{ |
|
encoding->composite_flag = true; |
|
pair_add2 (encoding->composite, orig, subs, wx, raito); |
|
} |
|
|
|
/* |
|
* Add a composite font in the current encoding |
|
*/ |
|
static void |
|
encoding_add_slant_font (struct encoding * encoding, |
|
const char * new, const char * src, |
|
float raito) |
|
{ |
|
static num = 0; |
|
encoding->slantfont[num].name = strdup(new); |
|
encoding->slantfont[num].src = strdup(src); |
|
encoding->slantfont[num].raito = raito; |
|
encoding->slantfont[num+1].name = NULL; |
|
num++; |
|
} |
|
|
|
/* |
* When FONT_NAME is used with ENCODING, return the | * When FONT_NAME is used with ENCODING, return the |
* real font name to use (e.g., in latin2, Courier-Ogonki | * real font name to use (e.g., in latin2, Courier-Ogonki |
* should be returned when asked for Courier). | * should be returned when asked for Courier). |
|
|
} | } |
| |
message (msg_enc, | message (msg_enc, |
|
(stderr, "In encoding %s, composite font for %s is resolved as %s\n", |
|
encoding->key, font_name, res)); |
|
return res; |
|
} |
|
|
|
/* |
|
* Get composite font size and raito |
|
*/ |
|
static int |
|
composite_font_info_get_wx(struct a2ps_job * job, |
|
struct encoding * encoding, |
|
const char * font_list) |
|
{ |
|
int wx= -1; |
|
char * font_list_copy; |
|
char * font_name; |
|
astrcpy (font_list_copy, font_list); |
|
font_name = strtok (font_list_copy, ",<>;"); |
|
|
|
wx = pair_get_wx (encoding->composite, font_name); |
|
if (wx<0) |
|
wx = pair_get_wx (encoding->composite, "default_composite__"); |
|
|
|
return wx; |
|
} |
|
|
|
static float |
|
composite_font_info_get_raito(struct a2ps_job * job, |
|
struct encoding * encoding, |
|
const char * font_list) |
|
{ |
|
float raito= -1; |
|
char * font_list_copy; |
|
char * font_name; |
|
|
|
astrcpy (font_list_copy, font_list); |
|
font_name = strtok (font_list_copy, ",<>;"); |
|
|
|
raito = pair_get_raito (encoding->composite, font_name); |
|
if (raito<0) |
|
raito = pair_get_raito (encoding->composite, "default_composite__"); |
|
return raito; |
|
} |
|
|
|
const char * |
|
encoding_resolve_composite_font (struct a2ps_job * job, |
|
struct encoding * encoding, |
|
const char * font_list) |
|
{ |
|
const char * res = NULL; |
|
char * font_list_copy; |
|
char * font_name; |
|
|
|
astrcpy (font_list_copy, font_list); |
|
font_name = strtok (font_list_copy, ",<>;"); |
|
|
|
/* Find if there is a substitute for that font */ |
|
res = pair_get (encoding->composite, font_name); |
|
|
|
/* We've found nothing interesting. Last chance is the default |
|
* font */ |
|
if (!res) |
|
{ |
|
res = pair_get (encoding->composite, "default_composite__"); |
|
|
|
if (!res) |
|
error (1, 0, "Cannot find font %s, nor any composite font", |
|
font_name); |
|
} |
|
|
|
message (msg_enc, |
(stderr, "In encoding %s, font %s is resolved as %s\n", | (stderr, "In encoding %s, font %s is resolved as %s\n", |
encoding->key, font_name, res)); | encoding->key, font_name, res)); |
return res; | return res; |
|
|
{ | { |
token2 = GET_TOKEN (NULL); | token2 = GET_TOKEN (NULL); |
CHECK_TOKEN (); | CHECK_TOKEN (); |
|
#ifdef USE_LIBJCODE |
|
if( strcmp(token2, "EUC-JP")== 0) |
|
use_libjcode = true; |
|
else |
|
use_libjcode = false; |
|
#endif |
encoding->name = xstrdup (token2); | encoding->name = xstrdup (token2); |
} | } |
else if (strequ (token, "Default:")) | else if (strequ (token, "Default:")) |
|
|
subs = token2; | subs = token2; |
encoding_add_font_substitute (encoding, orig, subs); | encoding_add_font_substitute (encoding, orig, subs); |
} | } |
|
else if (strequ (token, "DefaultComposite:")) |
|
{ |
|
char * orig, * subs; |
|
int wx; |
|
float raito; |
|
|
|
token2 = GET_TOKEN (NULL); |
|
CHECK_TOKEN (); |
|
subs = token2; |
|
token2 = GET_TOKEN (NULL); |
|
CHECK_TOKEN (); |
|
wx = (int)atof(token2)*1000; |
|
token2 = GET_TOKEN (NULL); |
|
CHECK_TOKEN (); |
|
raito = atof(token2); |
|
encoding_add_composite_font(encoding, "default_composite__", |
|
subs, wx, raito); |
|
} |
|
else if (strequ (token, "Composite:")) |
|
{ |
|
char * orig, * subs; |
|
int wx; |
|
float raito; |
|
|
|
token2 = GET_TOKEN (NULL); |
|
CHECK_TOKEN (); |
|
orig = token2; |
|
token2 = GET_TOKEN (NULL); |
|
CHECK_TOKEN (); |
|
subs = token2; |
|
token2 = GET_TOKEN (NULL); |
|
CHECK_TOKEN (); |
|
wx = (int)atof(token2)*1000; |
|
token2 = GET_TOKEN (NULL); |
|
CHECK_TOKEN (); |
|
raito = atof(token2); |
|
encoding_add_composite_font(encoding, orig, subs, wx, raito); |
|
} |
|
else if (strequ (token, "SlantFont:")) |
|
{ |
|
char * new, * src; |
|
float raito; |
|
unsigned int num; |
|
|
|
token2 = GET_TOKEN (NULL); |
|
CHECK_TOKEN (); |
|
new = token2; |
|
token2 = GET_TOKEN (NULL); |
|
CHECK_TOKEN (); |
|
src = token2; |
|
token2 = GET_TOKEN (NULL); |
|
CHECK_TOKEN (); |
|
raito = atof(token2); |
|
for (num = 0 ; encoding->slantfont[num].name ; num ++ ); |
|
if (num > sizeof encoding->slantfont - 1){ |
|
error_at_line (1, 0, fname, firstline, |
|
_("too many slant font: `%s'"), new); |
|
} |
|
encoding_add_slant_font(encoding, new, src, raito); |
|
} |
else | else |
error_at_line (1, 0, fname, firstline, | error_at_line (1, 0, fname, firstline, |
_("invalid option `%s'"), quotearg (token)); | _("invalid option `%s'"), quotearg (token)); |
|
|
} | } |
| |
/* | /* |
|
* Return the flag of composite flag |
|
*/ |
|
int |
|
encoding_get_composite_flag (struct encoding * enc) |
|
{ |
|
return enc->composite_flag; |
|
} |
|
|
|
/* |
* Prepare the environment (a dictionary) for the support | * Prepare the environment (a dictionary) for the support |
* of ENCODING, dump it into STREAM. | * of ENCODING, dump it into STREAM. |
* | * |
|
|
struct encoding * encoding) | struct encoding * encoding) |
{ | { |
size_t i, nb; | size_t i, nb; |
|
size_t ns; |
const char * real_font_name; /* After subsitution */ | const char * real_font_name; /* After subsitution */ |
char ** font_names = (char **) encoding->font_names_used->content; | char ** font_names = (char **) encoding->font_names_used->content; |
| |
|
|
/* How many fonts are there? */ | /* How many fonts are there? */ |
da_qsort (encoding->font_names_used); | da_qsort (encoding->font_names_used); |
da_unique (encoding->font_names_used, (da_map_func_t) free); | da_unique (encoding->font_names_used, (da_map_func_t) free); |
|
|
* in the current ENCODING */ | * in the current ENCODING */ |
nb = encoding->font_names_used->len; | nb = encoding->font_names_used->len; |
| |
|
/* The number of slant fonts */ |
|
for (i= 0, ns=0 ; encoding->slantfont[i].name ; i++ ) |
|
ns++; |
|
|
/* Create the dictionary and fill it */ | /* Create the dictionary and fill it */ |
fprintf (stream, "%% Dictionary for %s support\n", | fprintf (stream, "%% Dictionary for %s support\n", |
encoding->name); | encoding->name); |
fprintf (stream, "/%sdict %d dict begin\n", encoding->key, nb); |
fprintf (stream, "/%sdict %d dict begin\n", encoding->key, |
|
(encoding->composite_flag == true)? nb+nb+ns:nb+ns); |
for (i = 0 ; i < nb ; i++) | for (i = 0 ; i < nb ; i++) |
fprintf (stream, " /f%s %sEncoding /%s reencode_font\n", | fprintf (stream, " /f%s %sEncoding /%s reencode_font\n", |
font_names [i], | font_names [i], |
encoding->name, | encoding->name, |
encoding_resolve_font_substitute (job, encoding, font_names [i])); | encoding_resolve_font_substitute (job, encoding, font_names [i])); |
|
|
|
/* Slant font setting */ |
|
for (i = 0 ; encoding->slantfont[i].name ; i++ ) |
|
fprintf (stream, " /%s /%s %f slantfont definefont pop\n", |
|
encoding->slantfont[i].name, |
|
encoding->slantfont[i].src, |
|
encoding->slantfont[i].raito); |
|
|
|
/* |
|
* Composite font setting. |
|
* If kanji font size is larger than alphabet character, |
|
* set base font size to kanji charactor size. |
|
*/ |
|
if (encoding->composite_flag == true) { |
|
for (i = 0 ; i < nb ; i++) |
|
fprintf (stream, " /f%s /f%s /%s %f %f false compositefont " |
|
"%f scalefont def\n", |
|
font_names [i], |
|
font_names [i], |
|
encoding_resolve_composite_font (job, encoding, font_names [i]), |
|
encoding->composite_raito[i], |
|
(encoding->composite_raito[i] > 1.0)? |
|
0: (1-encoding->composite_raito[i])/2.0, |
|
(encoding->composite_raito[i] > 1.0)? |
|
1.0/encoding->composite_raito[i]: 1.0 ); |
|
} |
fputs ("currentdict end def\n", stream); | fputs ("currentdict end def\n", stream); |
} | } |
| |
|
|
true_font_name, | true_font_name, |
encoding->vector, | encoding->vector, |
encoding->faces_wx [face]); | encoding->faces_wx [face]); |
|
|
|
if (encoding->composite_flag) |
|
{ |
|
encoding->composite_raito[i] = |
|
composite_font_info_get_raito(job, encoding, |
|
job->face_eo_font [face]); |
|
|
|
encoding->composite_wx[i] = |
|
composite_font_info_get_wx(job, encoding, |
|
job->face_eo_font [face]); |
|
|
|
/* If kanji font size is larger than alphabet character, |
|
fit kanji charactor size to base font size */ |
|
if (encoding->composite_raito[i] < 1.0) |
|
encoding->composite_wx[i] *= encoding->composite_raito[i]; |
|
} |
} | } |
} | } |
| |
|
|
return 0; /* For -Wall */ | return 0; /* For -Wall */ |
} | } |
| |
|
unsigned int |
|
char_composite_WX (a2ps_job * job, uchar c) |
|
{ |
|
return (job->encoding->composite_wx[job->status->face]/ |
|
job->encoding->composite_raito[job->status->face]); |
|
} |
|
|
/* | /* |
* Returns the WX of a string (including M- and ^) | * Returns the WX of a string (including M- and ^) |
*/ | */ |