summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/mpdir/writefont.c
blob: 528e1577bd1b1e459f9734d841785202f931f072 (plain)
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*
Copyright (c) 1996-2006 Han The Thanh, <thanh@pdftex.org>

This file is part of pdfTeX.

pdfTeX 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 2 of the License, or
(at your option) any later version.

pdfTeX 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 pdfTeX; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

$Id: writefont.c,v 1.3 2005/12/27 19:04:42 hahe Exp $
*/

#include "mplib.h"

static const char perforce_id[] =
    "$Id: writefont.c,v 1.3 2005/12/27 19:04:42 hahe Exp $";

boolean fontfile_found;
boolean is_otf_font;
char fontname_buf[FONTNAME_BUF_SIZE];

boolean fontisreencoded (fontnumber f) {
  fm_entry *fm;
  if (fontsizes[f]!=0 && hasfmentry (f)) { 
    fm = (fm_entry *) mpfontmap[f];
    if (fm != NULL 
	&& (fm->ps_name != NULL)
	&& is_reencoded (fm))
      return 1;
  }
  return 0;
}

boolean fontisincluded (fontnumber f) {
  fm_entry *fm;
  if (fontsizes[f]!=0 && hasfmentry (f)) { 
    fm = (fm_entry *) mpfontmap[f];
    if (fm != NULL 
	&& (fm->ps_name != NULL && fm->ff_name != NULL) 
	&& is_included (fm))
      return 1;
  }
  return 0;
}

boolean fontissubsetted (fontnumber f) {
  fm_entry *fm;
  if (fontsizes[f]!=0 && hasfmentry (f)) { 
    fm = (fm_entry *) mpfontmap[f];
    if (fm != NULL 
	&& (fm->ps_name != NULL && fm->ff_name != NULL) 
	&& is_included (fm) && is_subsetted (fm))
      return 1;
  }
  return 0;
}


strnumber fmencodingname (fontnumber f) {
  enc_entry *e;
  fm_entry *fm;
  if (hasfmentry (f)) { 
    fm = (fm_entry *) mpfontmap[f];
    if (fm != NULL && (fm->ps_name != NULL)) {
      if (is_reencoded (fm)) {
	e = fm->encoding;
	if (e->encname!=NULL) {
	  return maketexstring(e->encname);
	} 
      } else {
	return 0;
      }
    }
  }
  pdftex_fail ("fontmap encoding problems for font %s",makecstring (fontname[f]));
  return 0;
}

strnumber fmfontname (fontnumber f) {
  fm_entry *fm;
  if (hasfmentry (f)) { 
    fm = (fm_entry *) mpfontmap[f];
    if (fm != NULL && (fm->ps_name != NULL)) {
	  if (fontisincluded(f) && !fontpsnamefixed[f]) {
		/* find the real fontname, and update ps_name and subset_tag if needed */
	    if(t1_updatefm(f,fm)) {
	      fontpsnamefixed[f] = true;
	    } else {
	      pdftex_fail ("font loading problems for font %s",makecstring (fontname[f]));
	    }
	  }
	  return maketexstring(fm->ps_name);
    }
  }
  pdftex_fail ("fontmap name problems for font %s",makecstring (fontname[f]));
  return 0;
}

strnumber fmfontsubsetname (fontnumber f) {
  fm_entry *fm;
  char *s;
  if (hasfmentry (f)) { 
    fm = (fm_entry *) mpfontmap[f];
    if (fm != NULL && (fm->ps_name != NULL)) {
      if (is_subsetted(fm)) {
		s = xmalloc(strlen(fm->ps_name)+8);
		snprintf(s,strlen(fm->ps_name)+8,"%s-%s",fm->subset_tag,fm->ps_name);
		return maketexstring(s);
      } else {
		return maketexstring(fm->ps_name);
	  }
    }
  }
  pdftex_fail ("fontmap name problems for font %s",makecstring (fontname[f]));
  return 0;
}



integer fmfontslant (fontnumber f) {
  fm_entry *fm;
  if (hasfmentry (f)) { 
    fm = (fm_entry *) mpfontmap[f];
    if (fm != NULL && (fm->ps_name != NULL)) {
      return fm->slant;
    }
  }
  return 0;
}

integer fmfontextend (fontnumber f) {
  fm_entry *fm;
  if (hasfmentry (f)) { 
    fm = (fm_entry *) mpfontmap[f];
    if (fm != NULL && (fm->ps_name != NULL)) {
      return fm->extend;
    }
  }
  return 0;
}



void mploadencodings (int lastfnum) {
  int nullfont;
  int f;
  enc_entry *e;
  fm_entry *fm_cur;
  nullfont = getnullfont();
  for (f=nullfont+1;f<=lastfnum;f++) {
    if (fontsizes[f]!=0 && hasfmentry (f)) { 
      fm_cur = (fm_entry *) mpfontmap[f];
      if (fm_cur != NULL && 
	  fm_cur->ps_name != NULL &&
	  is_reencoded (fm_cur)) {
		e = fm_cur->encoding;
		read_enc (e);
      }
    }
  }
}

void mpfontencodings (int lastfnum, int encodings_only) {
  int nullfont;
  int f;
  enc_entry *e;
  fm_entry *fm;
  nullfont = getnullfont();
  for (f=nullfont+1;f<=lastfnum;f++) {
    if (fontsizes[f]!=0 && hasfmentry (f)) { 
      fm = (fm_entry *) mpfontmap[f];
      if (fm != NULL && (fm->ps_name != NULL)) {
	if (is_reencoded (fm)) {
	  if (encodings_only || (!is_subsetted (fm))) {
	    e = fm->encoding;
	    write_enc (NULL, e, 0);
            /* clear for next run */
            e->objnum = 0;
	  }
	}
      }
    }
  }
}

boolean dopsfont (fontnumber f)
{
  fm_entry *fm_cur;
    if (mpfontmap[f] == NULL)
        pdftex_fail ("pdffontmap not initialized for font %s",
                     makecstring (fontname[f]));
    if (hasfmentry (f))
        fm_cur = (fm_entry *) mpfontmap[f];
    else
        fm_cur = NULL;
    if (fm_cur == NULL)
      return 1;
    if (is_truetype(fm_cur) ||
	(fm_cur->ps_name == NULL && fm_cur->ff_name == NULL)) {
        return 0;
    }
    
    if (is_included(fm_cur)) {
      printnl(maketexstring("%%BeginResource: font "));
      flushstr (last_tex_string);
      if (is_subsetted(fm_cur)) {
	    print(maketexstring(fm_cur->subset_tag));
        flushstr (last_tex_string);
     	print(maketexstring("-"));
        flushstr (last_tex_string);
      }
      print(maketexstring(fm_cur->ps_name));
      flushstr (last_tex_string);
      println();
      writet1 (f,fm_cur);
      printnl(maketexstring("%%EndResource"));
      flushstr (last_tex_string);
      println();
    }
    return 1;
}