Lines 37-42
Link Here
|
37 |
#include "document.h" |
37 |
#include "document.h" |
38 |
#include "quotearg.h" |
38 |
#include "quotearg.h" |
39 |
#include "strverscmp.h" |
39 |
#include "strverscmp.h" |
|
|
40 |
#ifdef USE_LIBJCODE |
41 |
int use_libjcode = false; |
42 |
#endif |
40 |
|
43 |
|
41 |
/* Suffix of the Encoding Description Files */ |
44 |
/* Suffix of the Encoding Description Files */ |
42 |
#define EDF_SUFFIX ".edf" |
45 |
#define EDF_SUFFIX ".edf" |
Lines 389-403
Link Here
|
389 |
* Association of suffixes rules, and corresponding style sheet |
392 |
* Association of suffixes rules, and corresponding style sheet |
390 |
* (The hashing is upon `alias') |
393 |
* (The hashing is upon `alias') |
391 |
*/ |
394 |
*/ |
|
|
395 |
struct slantfont_info { |
396 |
char * name; |
397 |
char * src; |
398 |
float raito; |
399 |
}; |
400 |
|
392 |
struct encoding { |
401 |
struct encoding { |
393 |
char * key; /* e.g. latin1 */ |
402 |
char * key; /* e.g. latin1 */ |
394 |
char * name; /* e.g. ISO Latin 1 */ |
403 |
char * name; /* e.g. ISO Latin 1 */ |
|
|
404 |
int composite_flag; /* flag for composite font */ |
395 |
uchar * documentation; /* Useful pieces of text */ |
405 |
uchar * documentation; /* Useful pieces of text */ |
396 |
|
406 |
|
397 |
char * default_font; /* When a font can't be used |
407 |
char * default_font; /* When a font can't be used |
398 |
define the font to use */ |
408 |
define the font to use */ |
399 |
struct pair_htable * substitutes; /* e.g. in latin2, don't use |
409 |
struct pair_htable * substitutes; /* e.g. in latin2, don't use |
400 |
* Courier, but Courier-Ogonki */ |
410 |
* Courier, but Courier-Ogonki */ |
|
|
411 |
struct pair_htable * composite; |
412 |
|
413 |
struct slantfont_info slantfont[NB_FACES]; |
401 |
|
414 |
|
402 |
char * vector[256]; /* Define the char set */ |
415 |
char * vector[256]; /* Define the char set */ |
403 |
struct darray * font_names_used; |
416 |
struct darray * font_names_used; |
Lines 407-412
Link Here
|
407 |
struct hash_table_s * fonts; /* Contains cells that are |
420 |
struct hash_table_s * fonts; /* Contains cells that are |
408 |
* 1. name of font, 2. int wx[256] */ |
421 |
* 1. name of font, 2. int wx[256] */ |
409 |
unsigned int * faces_wx[NB_FACES]; |
422 |
unsigned int * faces_wx[NB_FACES]; |
|
|
423 |
|
424 |
unsigned int composite_wx[NB_FACES]; /* fixed length font width*/ |
425 |
float composite_raito[NB_FACES]; /* size raito of additonal and orinal font */ |
410 |
}; |
426 |
}; |
411 |
|
427 |
|
412 |
/* |
428 |
/* |
Lines 423-431
Link Here
|
423 |
res->name = NULL; |
439 |
res->name = NULL; |
424 |
res->default_font = NULL; |
440 |
res->default_font = NULL; |
425 |
res->documentation = NULL; |
441 |
res->documentation = NULL; |
|
|
442 |
res->composite_flag = false; |
426 |
|
443 |
|
427 |
/* Vector will be set by setup */ |
444 |
/* Vector will be set by setup */ |
428 |
res->substitutes = pair_table_new (); |
445 |
res->substitutes = pair_table_new (); |
|
|
446 |
res->composite = pair_table_new (); |
447 |
res->slantfont[0].name = NULL; |
429 |
res->font_names_used = da_new ("List of font names", 10, |
448 |
res->font_names_used = da_new ("List of font names", 10, |
430 |
da_linear, 10, |
449 |
da_linear, 10, |
431 |
(da_print_func_t) da_str_print, |
450 |
(da_print_func_t) da_str_print, |
Lines 471-476
Link Here
|
471 |
} |
490 |
} |
472 |
|
491 |
|
473 |
/* |
492 |
/* |
|
|
493 |
* Add a composite font in the current encoding |
494 |
*/ |
495 |
static void |
496 |
encoding_add_composite_font (struct encoding * encoding, |
497 |
const char * orig, const char * subs, |
498 |
int wx, float raito) |
499 |
{ |
500 |
encoding->composite_flag = true; |
501 |
pair_add2 (encoding->composite, orig, subs, wx, raito); |
502 |
} |
503 |
|
504 |
/* |
505 |
* Add a composite font in the current encoding |
506 |
*/ |
507 |
static void |
508 |
encoding_add_slant_font (struct encoding * encoding, |
509 |
const char * new, const char * src, |
510 |
float raito) |
511 |
{ |
512 |
static num = 0; |
513 |
encoding->slantfont[num].name = strdup(new); |
514 |
encoding->slantfont[num].src = strdup(src); |
515 |
encoding->slantfont[num].raito = raito; |
516 |
encoding->slantfont[num+1].name = NULL; |
517 |
num++; |
518 |
} |
519 |
|
520 |
/* |
474 |
* When FONT_NAME is used with ENCODING, return the |
521 |
* When FONT_NAME is used with ENCODING, return the |
475 |
* real font name to use (e.g., in latin2, Courier-Ogonki |
522 |
* real font name to use (e.g., in latin2, Courier-Ogonki |
476 |
* should be returned when asked for Courier). |
523 |
* should be returned when asked for Courier). |
Lines 514-519
Link Here
|
514 |
} |
561 |
} |
515 |
|
562 |
|
516 |
message (msg_enc, |
563 |
message (msg_enc, |
|
|
564 |
(stderr, "In encoding %s, composite font for %s is resolved as %s\n", |
565 |
encoding->key, font_name, res)); |
566 |
return res; |
567 |
} |
568 |
|
569 |
/* |
570 |
* Get composite font size and raito |
571 |
*/ |
572 |
static int |
573 |
composite_font_info_get_wx(struct a2ps_job * job, |
574 |
struct encoding * encoding, |
575 |
const char * font_list) |
576 |
{ |
577 |
int wx= -1; |
578 |
char * font_list_copy; |
579 |
char * font_name; |
580 |
astrcpy (font_list_copy, font_list); |
581 |
font_name = strtok (font_list_copy, ",<>;"); |
582 |
|
583 |
wx = pair_get_wx (encoding->composite, font_name); |
584 |
if (wx<0) |
585 |
wx = pair_get_wx (encoding->composite, "default_composite__"); |
586 |
|
587 |
return wx; |
588 |
} |
589 |
|
590 |
static float |
591 |
composite_font_info_get_raito(struct a2ps_job * job, |
592 |
struct encoding * encoding, |
593 |
const char * font_list) |
594 |
{ |
595 |
float raito= -1; |
596 |
char * font_list_copy; |
597 |
char * font_name; |
598 |
|
599 |
astrcpy (font_list_copy, font_list); |
600 |
font_name = strtok (font_list_copy, ",<>;"); |
601 |
|
602 |
raito = pair_get_raito (encoding->composite, font_name); |
603 |
if (raito<0) |
604 |
raito = pair_get_raito (encoding->composite, "default_composite__"); |
605 |
return raito; |
606 |
} |
607 |
|
608 |
const char * |
609 |
encoding_resolve_composite_font (struct a2ps_job * job, |
610 |
struct encoding * encoding, |
611 |
const char * font_list) |
612 |
{ |
613 |
const char * res = NULL; |
614 |
char * font_list_copy; |
615 |
char * font_name; |
616 |
|
617 |
astrcpy (font_list_copy, font_list); |
618 |
font_name = strtok (font_list_copy, ",<>;"); |
619 |
|
620 |
/* Find if there is a substitute for that font */ |
621 |
res = pair_get (encoding->composite, font_name); |
622 |
|
623 |
/* We've found nothing interesting. Last chance is the default |
624 |
* font */ |
625 |
if (!res) |
626 |
{ |
627 |
res = pair_get (encoding->composite, "default_composite__"); |
628 |
|
629 |
if (!res) |
630 |
error (1, 0, "Cannot find font %s, nor any composite font", |
631 |
font_name); |
632 |
} |
633 |
|
634 |
message (msg_enc, |
517 |
(stderr, "In encoding %s, font %s is resolved as %s\n", |
635 |
(stderr, "In encoding %s, font %s is resolved as %s\n", |
518 |
encoding->key, font_name, res)); |
636 |
encoding->key, font_name, res)); |
519 |
return res; |
637 |
return res; |
Lines 585-590
Link Here
|
585 |
{ |
703 |
{ |
586 |
token2 = GET_TOKEN (NULL); |
704 |
token2 = GET_TOKEN (NULL); |
587 |
CHECK_TOKEN (); |
705 |
CHECK_TOKEN (); |
|
|
706 |
#ifdef USE_LIBJCODE |
707 |
if( strcmp(token2, "EUC-JP")== 0) |
708 |
use_libjcode = true; |
709 |
else |
710 |
use_libjcode = false; |
711 |
#endif |
588 |
encoding->name = xstrdup (token2); |
712 |
encoding->name = xstrdup (token2); |
589 |
} |
713 |
} |
590 |
else if (strequ (token, "Default:")) |
714 |
else if (strequ (token, "Default:")) |
Lines 633-638
Link Here
|
633 |
subs = token2; |
757 |
subs = token2; |
634 |
encoding_add_font_substitute (encoding, orig, subs); |
758 |
encoding_add_font_substitute (encoding, orig, subs); |
635 |
} |
759 |
} |
|
|
760 |
else if (strequ (token, "DefaultComposite:")) |
761 |
{ |
762 |
char * orig, * subs; |
763 |
int wx; |
764 |
float raito; |
765 |
|
766 |
token2 = GET_TOKEN (NULL); |
767 |
CHECK_TOKEN (); |
768 |
subs = token2; |
769 |
token2 = GET_TOKEN (NULL); |
770 |
CHECK_TOKEN (); |
771 |
wx = (int)atof(token2)*1000; |
772 |
token2 = GET_TOKEN (NULL); |
773 |
CHECK_TOKEN (); |
774 |
raito = atof(token2); |
775 |
encoding_add_composite_font(encoding, "default_composite__", |
776 |
subs, wx, raito); |
777 |
} |
778 |
else if (strequ (token, "Composite:")) |
779 |
{ |
780 |
char * orig, * subs; |
781 |
int wx; |
782 |
float raito; |
783 |
|
784 |
token2 = GET_TOKEN (NULL); |
785 |
CHECK_TOKEN (); |
786 |
orig = token2; |
787 |
token2 = GET_TOKEN (NULL); |
788 |
CHECK_TOKEN (); |
789 |
subs = token2; |
790 |
token2 = GET_TOKEN (NULL); |
791 |
CHECK_TOKEN (); |
792 |
wx = (int)atof(token2)*1000; |
793 |
token2 = GET_TOKEN (NULL); |
794 |
CHECK_TOKEN (); |
795 |
raito = atof(token2); |
796 |
encoding_add_composite_font(encoding, orig, subs, wx, raito); |
797 |
} |
798 |
else if (strequ (token, "SlantFont:")) |
799 |
{ |
800 |
char * new, * src; |
801 |
float raito; |
802 |
unsigned int num; |
803 |
|
804 |
token2 = GET_TOKEN (NULL); |
805 |
CHECK_TOKEN (); |
806 |
new = token2; |
807 |
token2 = GET_TOKEN (NULL); |
808 |
CHECK_TOKEN (); |
809 |
src = token2; |
810 |
token2 = GET_TOKEN (NULL); |
811 |
CHECK_TOKEN (); |
812 |
raito = atof(token2); |
813 |
for (num = 0 ; encoding->slantfont[num].name ; num ++ ); |
814 |
if (num > sizeof encoding->slantfont - 1){ |
815 |
error_at_line (1, 0, fname, firstline, |
816 |
_("too many slant font: `%s'"), new); |
817 |
} |
818 |
encoding_add_slant_font(encoding, new, src, raito); |
819 |
} |
636 |
else |
820 |
else |
637 |
error_at_line (1, 0, fname, firstline, |
821 |
error_at_line (1, 0, fname, firstline, |
638 |
_("invalid option `%s'"), quotearg (token)); |
822 |
_("invalid option `%s'"), quotearg (token)); |
Lines 754-759
Link Here
|
754 |
} |
938 |
} |
755 |
|
939 |
|
756 |
/* |
940 |
/* |
|
|
941 |
* Return the flag of composite flag |
942 |
*/ |
943 |
int |
944 |
encoding_get_composite_flag (struct encoding * enc) |
945 |
{ |
946 |
return enc->composite_flag; |
947 |
} |
948 |
|
949 |
/* |
757 |
* Prepare the environment (a dictionary) for the support |
950 |
* Prepare the environment (a dictionary) for the support |
758 |
* of ENCODING, dump it into STREAM. |
951 |
* of ENCODING, dump it into STREAM. |
759 |
* |
952 |
* |
Lines 766-774
Link Here
|
766 |
struct encoding * encoding) |
959 |
struct encoding * encoding) |
767 |
{ |
960 |
{ |
768 |
size_t i, nb; |
961 |
size_t i, nb; |
|
|
962 |
size_t ns; |
769 |
const char * real_font_name; /* After subsitution */ |
963 |
const char * real_font_name; /* After subsitution */ |
770 |
char ** font_names = (char **) encoding->font_names_used->content; |
964 |
char ** font_names = (char **) encoding->font_names_used->content; |
771 |
|
965 |
|
|
|
966 |
|
772 |
/* How many fonts are there? */ |
967 |
/* How many fonts are there? */ |
773 |
da_qsort (encoding->font_names_used); |
968 |
da_qsort (encoding->font_names_used); |
774 |
da_unique (encoding->font_names_used, (da_map_func_t) free); |
969 |
da_unique (encoding->font_names_used, (da_map_func_t) free); |
Lines 787-801
Link Here
|
787 |
* in the current ENCODING */ |
982 |
* in the current ENCODING */ |
788 |
nb = encoding->font_names_used->len; |
983 |
nb = encoding->font_names_used->len; |
789 |
|
984 |
|
|
|
985 |
/* The number of slant fonts */ |
986 |
for (i= 0, ns=0 ; encoding->slantfont[i].name ; i++ ) |
987 |
ns++; |
988 |
|
790 |
/* Create the dictionary and fill it */ |
989 |
/* Create the dictionary and fill it */ |
791 |
fprintf (stream, "%% Dictionary for %s support\n", |
990 |
fprintf (stream, "%% Dictionary for %s support\n", |
792 |
encoding->name); |
991 |
encoding->name); |
793 |
fprintf (stream, "/%sdict %d dict begin\n", encoding->key, nb); |
992 |
fprintf (stream, "/%sdict %d dict begin\n", encoding->key, |
|
|
993 |
(encoding->composite_flag == true)? nb+nb+ns:nb+ns); |
794 |
for (i = 0 ; i < nb ; i++) |
994 |
for (i = 0 ; i < nb ; i++) |
795 |
fprintf (stream, " /f%s %sEncoding /%s reencode_font\n", |
995 |
fprintf (stream, " /f%s %sEncoding /%s reencode_font\n", |
796 |
font_names [i], |
996 |
font_names [i], |
797 |
encoding->name, |
997 |
encoding->name, |
798 |
encoding_resolve_font_substitute (job, encoding, font_names [i])); |
998 |
encoding_resolve_font_substitute (job, encoding, font_names [i])); |
|
|
999 |
|
1000 |
/* Slant font setting */ |
1001 |
for (i = 0 ; encoding->slantfont[i].name ; i++ ) |
1002 |
fprintf (stream, " /%s /%s %f slantfont definefont pop\n", |
1003 |
encoding->slantfont[i].name, |
1004 |
encoding->slantfont[i].src, |
1005 |
encoding->slantfont[i].raito); |
1006 |
|
1007 |
/* |
1008 |
* Composite font setting. |
1009 |
* If kanji font size is larger than alphabet character, |
1010 |
* set base font size to kanji charactor size. |
1011 |
*/ |
1012 |
if (encoding->composite_flag == true) { |
1013 |
for (i = 0 ; i < nb ; i++) |
1014 |
fprintf (stream, " /f%s /f%s /%s %f %f false compositefont " |
1015 |
"%f scalefont def\n", |
1016 |
font_names [i], |
1017 |
font_names [i], |
1018 |
encoding_resolve_composite_font (job, encoding, font_names [i]), |
1019 |
encoding->composite_raito[i], |
1020 |
(encoding->composite_raito[i] > 1.0)? |
1021 |
0: (1-encoding->composite_raito[i])/2.0, |
1022 |
(encoding->composite_raito[i] > 1.0)? |
1023 |
1.0/encoding->composite_raito[i]: 1.0 ); |
1024 |
} |
799 |
fputs ("currentdict end def\n", stream); |
1025 |
fputs ("currentdict end def\n", stream); |
800 |
} |
1026 |
} |
801 |
|
1027 |
|
Lines 939-944
Link Here
|
939 |
true_font_name, |
1165 |
true_font_name, |
940 |
encoding->vector, |
1166 |
encoding->vector, |
941 |
encoding->faces_wx [face]); |
1167 |
encoding->faces_wx [face]); |
|
|
1168 |
|
1169 |
if (encoding->composite_flag) |
1170 |
{ |
1171 |
encoding->composite_raito[i] = |
1172 |
composite_font_info_get_raito(job, encoding, |
1173 |
job->face_eo_font [face]); |
1174 |
|
1175 |
encoding->composite_wx[i] = |
1176 |
composite_font_info_get_wx(job, encoding, |
1177 |
job->face_eo_font [face]); |
1178 |
|
1179 |
/* If kanji font size is larger than alphabet character, |
1180 |
fit kanji charactor size to base font size */ |
1181 |
if (encoding->composite_raito[i] < 1.0) |
1182 |
encoding->composite_wx[i] *= encoding->composite_raito[i]; |
1183 |
} |
942 |
} |
1184 |
} |
943 |
} |
1185 |
} |
944 |
|
1186 |
|
Lines 1073-1078
Link Here
|
1073 |
return 0; /* For -Wall */ |
1315 |
return 0; /* For -Wall */ |
1074 |
} |
1316 |
} |
1075 |
|
1317 |
|
|
|
1318 |
unsigned int |
1319 |
char_composite_WX (a2ps_job * job, uchar c) |
1320 |
{ |
1321 |
return (job->encoding->composite_wx[job->status->face]/ |
1322 |
job->encoding->composite_raito[job->status->face]); |
1323 |
} |
1324 |
|
1076 |
/* |
1325 |
/* |
1077 |
* Returns the WX of a string (including M- and ^) |
1326 |
* Returns the WX of a string (including M- and ^) |
1078 |
*/ |
1327 |
*/ |