18
18
You should have received a copy of the GNU General Public License along
19
19
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
21
static const char _svn_version[] =
22
"$Id: mapfile.c 3282 2009-12-21 21:55:47Z hhenkel $ "
23
"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.50.0/source/texk/web2c/luatexdir/font/mapfile.c $";
22
26
#include "ptexlib.h"
23
27
#include <kpathsea/c-auto.h>
24
28
#include <kpathsea/c-memstr.h>
25
29
#include <string.h>
26
#include "luatex-api.h"
28
static const char _svn_version[] =
29
"$Id: mapfile.c 2331 2009-04-18 16:39:50Z hhenkel $ "
30
"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.40.6/source/texk/web2c/luatexdir/font/mapfile.c $";
32
31
#define FM_BUF_SIZE 1024
34
33
static FILE *fm_file;
36
35
static unsigned char *fm_buffer = NULL;
37
static integer fm_size = 0;
38
static integer fm_curbyte = 0;
36
static int fm_size = 0;
37
static int fm_curbyte = 0;
41
(fm_file = fopen((char *) nameoffile + 1, FOPEN_RBIN_MODE))
40
(fm_file = fopen((char *)(a), FOPEN_RBIN_MODE))
42
41
#define fm_read_file() \
43
42
readbinfile(fm_file,&fm_buffer,&fm_size)
44
43
#define fm_close() xfclose(fm_file, cur_file_name)
143
142
((const fm_entry *) pb)->tfm_name);
146
/* AVL sort fm_entry into ps_tree by ps_name, slant, and extend */
148
static int comp_fm_entry_ps(const void *pa, const void *pb, void *p)
151
const fm_entry *p1 = (const fm_entry *) pa, *p2 = (const fm_entry *) pb;
153
assert(p1->ps_name != NULL && p2->ps_name != NULL);
154
if ((i = strcmp(p1->ps_name, p2->ps_name)))
156
cmp_return(p1->slant, p2->slant);
157
cmp_return(p1->extend, p2->extend);
161
145
/* AVL sort ff_entry into ff_tree by ff_name */
163
147
static int comp_ff_entry(const void *pa, const void *pb, void *p)
183
164
assert(encname_tree != NULL);
187
The function avl_do_entry() is not completely symmetrical with regards
188
to tfm_name and ps_name handling, e. g. a duplicate tfm_name gives a
189
"goto exit", and no ps_name link is tried. This is to keep it compatible
190
with the original version.
193
167
int avl_do_entry(fm_entry * fm, int mode)
199
/* handle tfm_name link */
201
172
if (strcmp(fm->tfm_name, nontfm)) {
202
173
p = (fm_entry *) avl_find(tfm_tree, fm);
323
/* SlantFont and ExtendFont can be used only with Type1 fonts */
324
if ((fm->slant != 0 || fm->extend != 0)
325
&& !(is_t1fontfile(fm) && is_included(fm))) {
328
("invalid entry for `%s': SlantFont/ExtendFont can be used only with embedded Type1 fonts",
333
263
/* the value of SlantFont and ExtendFont must be reasonable */
334
if (abs(fm->slant) > 1000) {
264
if (fm->slant < FONT_SLANT_MIN || fm->slant > FONT_SLANT_MAX) {
337
267
("invalid entry for `%s': too big value of SlantFont (%g)",
338
268
fm->tfm_name, fm->slant / 1000.0);
341
if (abs(fm->extend) > 2000) {
271
if (fm->extend < FONT_EXTEND_MIN || fm->extend > FONT_EXTEND_MAX) {
344
274
("invalid entry for `%s': too big value of ExtendFont (%g)",
477
407
s--; /* e. g. 0.5ExtendFont: %f = 0.5E */
478
408
if (str_prefix(s, "SlantFont")) {
479
409
d *= 1000.0; /* correct rounding also for neg. numbers */
480
fm->slant = (integer) (d > 0 ? d + 0.5 : d - 0.5);
410
fm->slant = (int) (d > 0 ? d + 0.5 : d - 0.5);
481
412
r = s + strlen("SlantFont");
482
413
} else if (str_prefix(s, "ExtendFont")) {
484
fm->extend = (integer) (d > 0 ? d + 0.5 : d - 0.5);
485
if (fm->extend == 1000)
415
fm->extend = (int) (d > 0 ? d + 0.5 : d - 0.5);
487
417
r = s + strlen("ExtendFont");
488
418
} else { /* unknown name */
489
419
for (r = s; *r != ' ' && *r != '"' && *r != '\0'; r++); /* jump over name */
587
519
mitem->lineno = 1;
588
520
switch (mitem->type) {
590
set_cur_file_name(mitem->line);
591
522
if (fm_buffer != NULL) {
592
523
xfree(fm_buffer);
593
524
fm_buffer = NULL;
597
callback_id = callback_defined(find_map_file_callback);
598
if (callback_id > 0) {
600
(callback_id, "S->S", (char *) (nameoffile + 1), &ftemp)) {
601
if (ftemp != NULL && strlen(ftemp)) {
603
namelength = strlen(ftemp);
604
nameoffile = xmalloc(namelength + 2);
605
strcpy((char *) (nameoffile + 1), ftemp);
611
kpse_find_file((char *) (nameoffile + 1), kpse_fontmap_format,
615
namelength = strlen(ftemp);
616
nameoffile = xmalloc(namelength + 2);
617
strcpy((char *) (nameoffile + 1), ftemp);
621
callback_id = callback_defined(read_map_file_callback);
622
if (callback_id > 0) {
623
if (run_callback(callback_id, "S->bSd", (char *) (nameoffile + 1),
624
&file_opened, &fm_buffer, &fm_size)) {
627
cur_file_name = (char *) nameoffile + 1;
629
tex_printf("{%s", cur_file_name);
528
cur_file_name = luatex_find_file(mitem->line, find_map_file_callback);
530
callback_id = callback_defined(read_map_file_callback);
531
if (callback_id > 0) {
532
if (run_callback(callback_id, "S->bSd", cur_file_name,
533
&file_opened, &fm_buffer, &fm_size)) {
537
tex_printf("{%s", cur_file_name);
639
pdftex_warn("cannot open font map file");
642
pdftex_warn("cannot open font map file");
646
pdftex_warn("cannot open font map file");
649
cur_file_name = (char *) nameoffile + 1;
650
tex_printf("{%s", cur_file_name);
547
pdftex_warn("cannot open font map file");
550
pdftex_warn("cannot open font map file");
553
if (!fm_open(cur_file_name)) {
554
pdftex_warn("cannot open font map file");
557
tex_printf("{%s", cur_file_name);
567
cur_file_name = NULL;
697
608
if (font_map(f) == NULL)
698
609
set_font_map(f, (fm_entry_ptr) fmlookup(f));
699
610
assert(font_map(f) != NULL);
611
/* TODO: this still overrides already set font_slant(f) */
612
if (is_slantset((fm_entry *) font_map(f)))
613
font_slant(f) = ((fm_entry *) font_map(f))->slant;
614
if (is_extendset((fm_entry *) font_map(f)))
615
font_extend(f) = ((fm_entry *) font_map(f))->extend;
700
616
return font_map(f) != (fm_entry_ptr) dummy_fm_entry();
703
/* check whether a map entry is valid for font replacement */
705
static boolean fm_valid_for_font_replacement(fm_entry * fm)
710
assert(is_fontfile(fm)); /* ps_tree should contain only entries with font file */
711
assert(is_type1(fm)); /* ps_tree should contain only Type1 entries */
713
ff = check_ff_exist(fm->ff_name, false);
715
if (ff->ff_path == NULL) /* ...there is no font file available */
717
return true; /* all tests passed */
720
/**********************************************************************/
722
* lookup fontmap by ps_name;
723
* used for Type1 font replacement when embedding of PDF files
726
fm_entry *lookup_fontmap(char *ps_name)
728
fm_entry *fm, *fm2, tmp;
729
char *a, *b, *c, *d, *e, *s;
731
struct avl_traverser t, t2;
732
if (tfm_tree == NULL)
733
fm_read_info(); /* only to read default map file */
734
assert(ps_name != NULL);
736
if (strlen(ps_name) > 7) { /* check for subsetted name tag */
737
for (i = 0; i < 6; i++, s++)
738
if (*s < 'A' || *s > 'Z')
740
if (i == 6 && *s == '+')
741
s++; /* if name tag found, skip behind it */
747
* Scan -Slant_<slant> and -Extend_<extend> font name extensions;
748
* three valid formats:
749
* <fontname>-Slant_<slant>
750
* <fontname>-Slant_<slant>-Extend_<extend>
751
* <fontname>-Extend_<extend>
752
* Slant entry must come _before_ Extend entry
757
if ((a = strstr(s, "-Slant_")) != NULL) {
758
b = a + strlen("-Slant_");
759
sl = (int) strtol(b, &e, 10);
760
if ((e != b) && (e == strend(b))) {
762
*a = '\0'; /* ps_name string ends before "-Slant_" */
764
if (e != b) { /* only if <slant> is valid number */
765
if ((c = strstr(e, "-Extend_")) != NULL) {
766
d = c + strlen("-Extend_");
767
ex = (int) strtol(d, &e, 10);
768
if ((e != d) && (e == strend(d))) {
771
*a = '\0'; /* ps_name string ends before "-Slant_" */
777
if ((a = strstr(s, "-Extend_")) != NULL) {
778
b = a + strlen("-Extend_");
779
ex = (int) strtol(b, &e, 10);
780
if ((e != b) && (e == strend(b))) {
782
*a = '\0'; /* ps_name string ends before "-Extend_" */
788
fm = (fm_entry *) avl_t_find(&t, ps_tree, &tmp);
790
return NULL; /* no entry found */
792
/* at this point we know there is at least one fm_entry with given ps_name;
793
* we test all such entries and return the first one that is valid for font
797
fm2 = (fm_entry *) avl_t_prev(&t2);
801
if (fm_valid_for_font_replacement(fm))
803
fm = (fm_entry *) avl_t_next(&t);
804
} while (fm != NULL && comp_fm_entry_ps(fm, &tmp, NULL) == 0);
806
/* search backward */
807
while (fm2 != NULL && comp_fm_entry_ps(fm2, &tmp, NULL) == 0) {
808
if (fm_valid_for_font_replacement(fm2))
810
fm2 = (fm_entry *) avl_t_prev(&t2);
816
619
/**********************************************************************/
818
621
* Process map file given by its name or map line contents. Items not
871
void pdfmapfile(integer t)
674
void pdfmapfile(int t)
873
process_map_item(makecstring(tokens_to_string(t)), MAPFILE);
874
flush_str(last_tokens_string);
676
char *s = tokenlist_to_cstring(t, true, NULL);
677
process_map_item(s, MAPFILE);
877
void pdfmapline(integer t)
681
void pdfmapline(int t)
879
process_map_item(makecstring(tokens_to_string(t)), MAPLINE);
880
flush_str(last_tokens_string);
683
char *s = tokenlist_to_cstring(t, true, NULL);
684
process_map_item(s, MAPLINE);
883
688
void pdf_init_map_file(string map_name)