w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

subfont.c
Go to the documentation of this file.
1 /*
2  * subfont.c
3  *
4  * This file is part of the ttf2pk package.
5  *
6  * Copyright 1997-1999, 2000, 2002 by
7  * Frederic Loyer <loyer@ensta.fr>
8  * Werner Lemberg <wl@gnu.org>
9  */
10 
11 #ifdef HAVE_CONFIG_H
12 #include <config.h>
13 #endif
14 
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <stddef.h> /* for size_t */
18 #include <ctype.h>
19 #include <string.h>
20 
21 #include "filesrch.h"
22 #include "subfont.h"
23 #include "newobj.h"
24 #include "errormsg.h"
25 
26 
27 struct _realsubfont;
28 typedef struct _realsubfont realsubfont;
29 
31 {
33  char *name;
35 };
36 
38 
39 static realsubfont *
41 static Boolean
43 static void
44 really_close_sfd(realsubfont *real_name);
45 
46 
47 /*
48  * Initialize subfont functionality. The argument is the subfont
49  * definition file name. If `fatal' is `True', the routine exits
50  * with an error. If `fatal' is `False', a warning message is emitted
51  * and `False' returned if an error occurs; in case of success `True'
52  * will be returned.
53  */
54 
55 Boolean
57 {
59  if (fnt->ligname)
61 
62  return (real_sfd_name ? True : False);
63 }
64 
65 
66 static realsubfont *
68 {
69  char *sf;
70  char *buf, *p, *q;
71  realsubfont *rsf, *temp, *real_name = NULL;
72 
73 
74  buf = newstring(name);
75  p = buf;
76 
77  while (1)
78  {
79  if (*p == '\0')
80  {
81  if (real_name)
82  break;
83  else
84  {
85  if (fatal)
86  oops("No subfont definition file.");
87  else
88  {
89  warning("No subfont definition file.");
90  return NULL;
91  }
92  }
93  }
94 
95  q = p;
96  while (*q && *q != ',') /* search end of subfont name */
97  q++;
98  if (*q)
99  *(q++) = '\0';
100 
101  sf = newstring(p);
102 
103  p = q;
104 
105  rsf = (realsubfont *)mymalloc(sizeof (realsubfont));
106  rsf->name = TeX_search_sfd_file(&sf);
107  if (!rsf->name)
108  {
109  if (fatal)
110  oops("Cannot find subfont definition file `%s'.", sf);
111  else
112  {
113  warning("Cannot find subfont definition file `%s'.", sf);
114  return NULL;
115  }
116  }
117 
118  rsf->file = fopen(rsf->name, "rt");
119  if (rsf->file == NULL)
120  {
121  if (fatal)
122  oops("Cannot open subfont definition file `%s'.", rsf->name);
123  else
124  {
125  warning("Cannot open subfont definition file `%s'.", rsf->name);
126  return NULL;
127  }
128  }
129 
130  rsf->next = real_name;
131  real_name = rsf;
132 
133  free(sf);
134  }
135 
136  free(buf);
137 
138  /* reverse list */
139 
140  rsf = NULL;
141  while (real_name)
142  {
143  temp = real_name;
144  real_name = real_name->next;
145  temp->next = rsf;
146  rsf = temp;
147  }
148  real_name = rsf;
149 
150  return real_name;
151 }
152 
153 
154 /*
155  * This function fills the font structure sequentially with subfont
156  * entries; it returns `False' if no more subfont entries are available,
157  * `True' otherwise.
158  *
159  * If `next' is `True', check `rsf' whether it contains entries for the
160  * current subfont name, overwriting subfont code points.
161  *
162  * fnt->subfont_name must be set to NULL before the first call.
163  *
164  * The subset parser was inspired by ttf2bdf.c .
165  */
166 
168 {
169  if (is_sfd)
171  else
173 }
174 
175 
176 static Boolean
178 {
179  long i, offset;
180  long begin, end = -1;
181  char *buffer, *oldbuffer, *bufp, *bufp2, *bufp3;
182 
183 
184  if (next)
185  rewind(rsf->file);
186  else
187  for (i = 0; i < 256; i++)
188  fnt->sf_code[i] = -1;
189 
190 again:
191 
192  buffer = get_line(rsf->file);
193  if (!buffer)
194  oops("Error reading subfont definition file `%s'.", rsf->name);
195  if (!*buffer)
196  return False;
197 
198  oldbuffer = newstring(buffer);
199  bufp = buffer;
200  offset = 0;
201 
202  while (*bufp) /* remove comment */
203  {
204  if (*bufp == '#')
205  {
206  bufp++;
207  break;
208  }
209  bufp++;
210  }
211  *(--bufp) = '\0'; /* remove final newline character */
212 
213  bufp = buffer;
214 
215  while (isspace((unsigned char)*bufp))
216  bufp++;
217 
218  if (*bufp == '\0') /* empty line? */
219  {
220  free(buffer);
221  free(oldbuffer);
222  goto again;
223  }
224 
225  while (*bufp && !isspace((unsigned char)*bufp)) /* subfont name */
226  bufp++;
227  if (*bufp)
228  *(bufp++) = '\0';
229 
230  while (isspace((unsigned char)*bufp))
231  bufp++;
232 
233  if (*bufp == '\0')
234  oops("Invalid subfont entry in `%s'.", rsf->name);
235 
236  if (next || !new_sfd)
237  {
238  if (strcmp(fnt->subfont_name, buffer))
239  goto again;
240  }
241  else
242  {
243  if (fnt->subfont_name)
244  free(fnt->subfont_name);
245  fnt->subfont_name = newstring(buffer);
246  }
247 
248  while (1)
249  {
250  bufp3 = bufp;
251 
252  begin = strtol(bufp, &bufp2, 0);
253 
254  if (bufp == bufp2 || begin < 0 || begin > 0x16FFFF)
255  boops(oldbuffer, bufp - buffer,
256  "Invalid subfont range or offset entry.");
257 
258  if (*bufp2 == ':') /* offset */
259  {
260  offset = begin;
261  if (offset > 0xFF)
262  boops(oldbuffer, bufp - buffer, "Invalid subfont offset.");
263 
264  bufp = bufp2 + 1;
265 
266  while (isspace((unsigned char)*bufp))
267  bufp++;
268 
269  continue;
270  }
271  else if (*bufp2 == '_') /* range */
272  {
273  bufp = bufp2 + 1;
274  if (!isdigit((unsigned char)*bufp))
275  boops(oldbuffer, bufp - buffer, "Invalid subfont range entry.");
276 
277  end = strtol(bufp, &bufp2, 0);
278 
279  if (bufp == bufp2 || end < 0 || end > 0x16FFFFL)
280  boops(oldbuffer, bufp - buffer, "Invalid subfont range entry.");
281  if (*bufp2 && !isspace((unsigned char)*bufp2))
282  boops(oldbuffer, bufp2 - buffer, "Invalid subfont range entry.");
283  if (end < begin)
284  boops(oldbuffer, bufp - buffer, "End of subfont range too small.");
285  if (offset + (end - begin) > 255)
286  boops(oldbuffer, bufp3 - buffer,
287  "Subfont range too large for current offset (%i).", offset);
288  }
289  else if (isspace((unsigned char)*bufp2) || !*bufp2) /* single value */
290  end = begin;
291  else
292  boops(oldbuffer, bufp2 - buffer, "Invalid subfont range entry.");
293 
294  for (i = begin; i <= end; i++)
295  {
296  if (!next && fnt->sf_code[offset] != -1)
297  boops(oldbuffer, bufp3 - buffer, "Overlapping subfont ranges.");
298 
299  fnt->sf_code[offset++] = i;
300  }
301 
302  bufp = bufp2;
303 
304  while (isspace((unsigned char)*bufp))
305  bufp++;
306 
307  if (!*bufp)
308  break;
309  }
310 
311  free(buffer);
312  free(oldbuffer);
313 
314  if (!next)
315  while ((rsf = rsf->next))
316  (void)really_get_sfd(fnt, True, rsf, new_sfd);
317 
318  return True;
319 }
320 
321 
322 void
324 {
327 }
328 
329 
330 static void
332 {
333  realsubfont *rsf;
334 
335 
336  while (real_name)
337  {
338  if (real_name->file)
339  fclose(real_name->file);
340  if (real_name->name)
341  free(real_name->name);
342 
343  rsf = real_name;
344  real_name = real_name->next;
345  free(rsf);
346  }
347 }
348 
349 
350 /*
351  * We extract the subfont definition file name. The name must
352  * be embedded between two `@' characters. If there is no sfd file,
353  * `sfd_begin' is set to -1.
354  *
355  * The `@' characters will be replaced with null characters.
356  */
357 
358 void
359 handle_sfd(char *s, int *sfd_begin, int *postfix_begin)
360 {
361  int i;
362  Boolean have_atsign;
363 
364 
365  have_atsign = False;
366  *sfd_begin = -1;
367  *postfix_begin = -1;
368 
369  for (i = 0; s[i]; i++)
370  {
371  if (s[i] == '@')
372  {
373  if (have_atsign)
374  {
375  *postfix_begin = i + 1;
376 
377  s[i] = '\0';
378  break;
379  }
380  have_atsign = True;
381  *sfd_begin = i + 1;
382 
383  s[i] = '\0';
384  }
385  }
386 
387  if (*sfd_begin != -1 &&
388  (*postfix_begin == -1 || *postfix_begin < *sfd_begin + 2))
389  oops("Invalid subfont definition file name.");
390 
391  if (*postfix_begin > -1)
392  for (i = *postfix_begin; s[i]; i++)
393  if (s[i] == '/' || s[i] == ':' || s[i] == '\\' || s[i] == '@')
394  oops("`/', `:', `\\', and `@' not allowed after second `@'.");
395 }
396 
397 
398 /* end */
long __cdecl strtol(char const *_String, char **_EndPtr, int _Radix)
q
Definition: afm2pl.c:2287
static char * newstring(const char *s)
Definition: afm2pl.c:282
#define name
#define next(a)
Definition: aptex-macros.h:924
Definition: Font.hpp:55
#define free(a)
Definition: decNumber.cpp:310
op_table fnt
Definition: dt2dv.c:217
#define fopen
Definition: xxstdio.h:21
int strcmp()
Definition: coll.cpp:143
char * temp
Definition: dvidvi.c:137
void boops(const char *buffer, size_t offset, const char *message,...)
Definition: errormsg.c:53
char * TeX_search_sfd_file(char **name)
Definition: filesrch.c:459
static void
Definition: fpif.c:118
#define s
Definition: afcover.h:80
static FIELD_PTR begin
Definition: genind.c:37
static bool get_line(char *buf, int len, FILE *f)
Definition: hbf.c:859
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p
Definition: afcover.h:72
small capitals from c petite p scientific i
Definition: afcover.h:80
void warning(char msg[])
Definition: utils.c:72
#define buf
#define fclose
Definition: debug.h:100
void handle_sfd(char *s, int *sfd_begin, int *postfix_begin)
Definition: subfont.c:359
static Boolean really_get_sfd(Font *fnt, Boolean next, realsubfont *rsf, Boolean new_sfd)
Definition: subfont.c:177
static realsubfont * real_sfd_name
Definition: subfont.c:37
static void really_close_sfd(realsubfont *real_name)
Definition: subfont.c:331
static realsubfont * real_lig_name
Definition: subfont.c:37
Boolean init_sfd(Font *fnt, Boolean fatal)
Definition: subfont.c:56
Boolean get_sfd(Font *fnt, Boolean is_sfd)
Definition: subfont.c:167
void close_sfd(void)
Definition: subfont.c:323
static realsubfont * really_init_sfd(char *name, Boolean fatal)
Definition: subfont.c:67
#define fatal
Definition: tie.c:14
#define isdigit(c)
Definition: snprintf.c:177
int Boolean
Definition: pgmcrater.c:64
static int offset
Definition: ppmtogif.c:642
#define mymalloc
Definition: pscolor.c:28
#define isspace(ch)
Definition: utype.h:87
void oops(const char *message,...)
Definition: stackenv.c:90
realsubfont * next
Definition: subfont.c:32
char * name
Definition: subfont.c:33
FILE * file
Definition: subfont.c:34
Definition: utils.c:300
Definition: tfmaux.c:31
#define FILE
Definition: t1stdio.h:34
@ True
Definition: ttf2tfm.h:20
@ False
Definition: ttf2tfm.h:19
#define buffer
Definition: xmlparse.c:611
#define end(cp)
Definition: zic.c:71