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)  

type1.c
Go to the documentation of this file.
1 /* $Header$
2 
3  This is dvipdfm, a DVI to PDF translator.
4  Copyright (C) 1998, 1999 by Mark A. Wicks
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20  The author may be contacted via the e-mail address
21 
22  mwicks@kettering.edu
23 */
24 
25 /* This is tailored for PDF */
26 
27 #include <string.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <math.h>
31 #include <time.h>
32 #include <ctype.h>
33 #include "system.h"
34 #include "mem.h"
35 #include "error.h"
36 #include "mfileio.h"
37 #include "pdfobj.h"
38 #include "numbers.h"
39 #include "type1.h"
40 #include "tfm.h"
41 #include "pdfparse.h"
42 #include "pdflimits.h"
43 #include "t1crypt.h"
44 #include "twiddle.h"
45 #include "encodings.h"
46 
47 static unsigned char verbose = 0;
48 
50 {
51  if (verbose < 255) {
52  verbose += 1;
53  }
54 }
55 
56 
57 static unsigned long get_low_endian_quad (FILE *file)
58 {
59  unsigned long result;
60  static unsigned bytes[4];
61  int ch, i;
62  for (i=0; i<4; i++) {
63  if ((ch = fgetc (file)) < 0) {
64  ERROR ("get_low_endian_quad: Error reading file");
65  }
66  bytes[i] = ch;
67  }
68  result = bytes[3];
69  for (i=2; i>=0; i--) {
70  result = result*256u + bytes[i];
71  }
72  return result;
73 }
74 
75 /* PFB section */
76 
77 static char partial_enabled = 1;
78 
80 {
81  partial_enabled = 0;
82 }
83 
84 static unsigned num_pfbs = 0;
85 static unsigned max_pfbs = 0;
86 struct a_pfb
87 {
88  char *pfb_name;
89  char *fontname;
91  char **used_glyphs;
92  char **int_encoding;
93  char *used_def_enc_chars; /* The positions used from the default
94  encoding. When a default encoding
95  is used, the glyph names will not
96  be known until the font is actually
97  read. Since the glyph names are
98  unknown, only the positions of the
99  used chars are stored when the
100  default encoding is used */
102 } *pfbs = NULL;
103 
104 static void init_a_pfb (struct a_pfb *pfb)
105 {
106  int i;
107  pfb -> n_used_glyphs = 0;
108  pfb -> max_used_glyphs = 0;
109  pfb -> used_glyphs = NULL;
110  pfb->pfb_name = NULL;
111  pfb->fontname = NULL;
112  pfb->direct = NULL;
113  pfb->indirect = NULL;
114  pfb->descriptor = NULL;
115  pfb -> used_def_enc_chars = NULL;
116  if (partial_enabled) {
117  pfb -> int_encoding = NEW (256, char *);
118  for (i=0; i<256; i++) {
119  (pfb -> int_encoding)[i] = NULL;
120  }
121  } else {
122  pfb -> int_encoding = NULL;
123  }
124 }
125 
126 #include "standardenc.h"
127 
128 static void do_a_standard_enc(char **glyphs, char **encoding)
129 {
130  int i;
131  for (i=0; i<256; i++) {
132  RELEASE (glyphs[i]);
133  glyphs[i] = NEW (strlen(encoding[i])+1, char);
134  strcpy (glyphs[i], encoding[i]);
135  }
136 }
137 #define FIXED_WIDTH 1
138 #define SERIF 2
139 #define STANDARD 32
140 #define ITALIC 64
141 #define SYMBOLIC 4 /* Fonts that don't have Adobe encodings (e.g.,
142  cmr, should be set to be symbolic */
143 #define STEMV 80
144 
145 
146 int CDECL glyph_cmp (const void *v1, const void *v2)
147 {
148  char *s1, *s2;
149  s1 = *((char **) v1);
150  s2 = *((char **) v2);
151  return (strcmp (s1, s2));
152 }
153 
154 int CDECL glyph_match (const void *key, const void *v)
155 {
156  char *s;
157  s = *((char **) v);
158  return (strcmp (key, s));
159 }
160 
161 static unsigned long parse_header (unsigned char *filtered, unsigned char *buffer,
162  unsigned long length, int pfb_id)
163 {
164  /* If the encoding has been overridden, this routine should eliminate any
165  built-in encoding (other than things like StandardEncoding) in
166  the header to save space */
167 
168  /* On second thought, that's the way it _should_ work, but the
169  reader doesn't seem to agree. The reader is happy if you don't
170  specify an encoding as long as you actually change the locations
171  in the overriding encoding. The reader is unhappy if you don't
172  specify an encoding and don't change the location of the
173  characters in the overriding encoding. Ghostscript doesn't
174  have a problem with it. */
175 
176  unsigned char *filtered_pointer;
177  int state = 0;
178  char *start, *end, *lead;
179  int copy = 1;
180  int last_number = 0;
181  char *glyph = NULL;
182 #ifdef MEM_DEBUG
183  MEM_START
184 #endif
185  /* This routine uses a state machine parser rather than trying to
186  interpret Postcript the way mpost.c does. There are only
187  a few key parameters it is trying to find */
188 
189  /* State definitions
190  state 0: Initial state
191  state 1: Saw /FontName
192  state 2: Saw /Encoding
193  state 3: Saw "dup" in state 2
194  state 4: Saw a number in state 3
195  state 5: Saw /glyphname in state 4
196  state 6: Saw /FontBBox in state 0
197  state 7: Saw a '{' or a '[' in state 6
198  state 8: Saw /ItalicAngle in state 0 */
199  /* As the parser operates, start always points to the next point in
200  the buffer */
201  start = (char *) buffer;
202  end = start+length;
203  filtered_pointer = filtered;
204  /* When the parser decides to keep text, the text
205  between lead and start is copied to the output buffer. To
206  keep a block of text from being copied, the parser simply
207  sets copy = 0 */
208  lead = start;
209  skip_white (&start, end);
210  if (filtered && lead != start) {
211  memcpy (filtered_pointer, lead, start-lead);
212  filtered_pointer += start-lead;
213  lead = start;
214  }
215  while (start < end) {
216  char *ident;
217  pdf_obj *pdfobj;
218  copy = 1; /* By default, we copy most things */
219  switch (state) {
220  /* First three states are very similar. In most cases we just
221  ignore other postscript junk and don't change state */
222  case 0:
223  case 1:
224  case 2:
225  switch (*start) {
226  /* Ignore arrays and procedures */
227  case '[':
228  case ']':
229  case '{':
230  case '}':
231  start += 1;
232  if (state >= 2)
233  state = 2;
234  break;
235  case '(':
236  pdfobj = parse_pdf_string (&start, end);
237  if (pdfobj == NULL) {
238  ERROR ("parse_header: Error parsing a string in pfb header");
239  }
240  pdf_release_obj (pdfobj);
241  if (state == 1) {
242  if (filtered)
243  filtered_pointer += sprintf ((char *)filtered_pointer, "/%s ",
244  pfbs[pfb_id].fontname);
245  copy = 0; /* Don't copy old string to output */
246  lead = start; /* Forget what we've seen */
247  state = 0;
248  }
249  if (state >= 2)
250  state = 2;
251  break;
252  case '/':
253  start += 1;
254  ident = parse_ident (&start, end);
255  if (state == 0 && !strcmp (ident, "FontName")) {
256  state = 1;
257  } else if (state == 0 && !strcmp (ident, "Encoding")) {
258  state = 2;
259  if (filtered && !pfbs[pfb_id].used_def_enc_chars) {
260  filtered_pointer += sprintf ((char *)filtered_pointer,
261  "/Encoding StandardEncoding readonly ");
262  }
263  } else if (state == 0 && !strcmp (ident, "FontBBox")) {
264  state = 6;
265  } else if (state == 0 && !strcmp (ident, "ItalicAngle")) {
266  state = 8;
267  } else if (state == 1) {
268  if (filtered)
269  filtered_pointer += sprintf ((char *)filtered_pointer, "/%s ",
270  pfbs[pfb_id].fontname);
271  copy = 0; /* Don't copy old string to putput */
272  lead = start; /* Forget the name we've seen */
273  state = 0;
274  }
275  RELEASE (ident);
276  break;
277  default:
278  ident = parse_ident (&start, end);
279  if (state == 2 && !strcmp (ident, "def")) {
280  /* Assume this is the end of the encoding */
281  state = 0;
282  } else if (state == 2 &&
283  !strcmp (ident, "dup")) {
284  copy = 0; /* Don't copy this to output buffer until we
285  know if we want to keep it */
286  state = 3;
287  } else if (state == 2 &&
288  !strcmp (ident, "StandardEncoding") &&
289  pfbs[pfb_id].int_encoding) {
290  do_a_standard_enc(pfbs[pfb_id].int_encoding, standardencoding);
291  } else if (state == 2 &&
292  !strcmp (ident, "ISOLatin1Encoding") &&
293  pfbs[pfb_id].int_encoding) {
294  do_a_standard_enc(pfbs[pfb_id].int_encoding, isoencoding);
295  }
296  RELEASE (ident);
297  break;
298  }
299  break;
300  case 3:
301  ident = parse_ident (&start, end);
302  if (is_an_int (ident)) {
303  last_number = (int) atof (ident);
304  copy = 0; /* We still don't know if we want to keep it */
305  state = 4;
306  } else {
307  state = 2; /* Contents back to "lead" will be flushed */
308  }
309  RELEASE (ident);
310  break;
311  case 4:
312  if (*start == '/') {
313  start += 1;
314  glyph = parse_ident (&start, end);
315  copy = 0; /* We still don't know if we want to keep it.
316  Wait for a complete sequence before making
317  that decision */
318  state = 5;
319  } else {
320  state = 2;
321  }
322  break;
323  case 5:
324  ident = parse_ident (&start, end);
325  /* Here we either decide to keep or remove the encoding entry */
326  if (ident != NULL && !strcmp (ident, "put") &&
327  (int) last_number < 256 && (int) last_number >= 0) {
328  skip_white(&start, end); /* Remove white space */
329  lead = start; /* Remove this entry (it may or may not be
330  replaced with a rewritten entry) */
331  copy = 0;
332  if (filtered &&
333  pfbs[pfb_id].used_def_enc_chars &&
334  (pfbs[pfb_id].used_def_enc_chars)[last_number]) {
335  filtered_pointer +=
336  sprintf((char *) filtered_pointer, "dup %d /%s put\n",
337  last_number,
338  glyph);
339  }
340  /* Add this glyph to the internal encoding table for the pfb
341  */
342  if (pfbs[pfb_id].int_encoding &&
343  (!(pfbs[pfb_id].int_encoding)[last_number])) {
344  if ((pfbs[pfb_id].int_encoding)[last_number]) {
345  RELEASE ((pfbs[pfb_id].int_encoding)[last_number]);
346  }
347  (pfbs[pfb_id].int_encoding)[last_number] = glyph;
348  glyph = NULL; /* Prevent glyph from being released */
349  }
350  }
351  if (glyph)
352  RELEASE (glyph);
353  if (ident != NULL)
354  RELEASE (ident);
355  state = 2;
356  break;
357  case 6:
358  switch (*start) {
359  case '[':
360  case '{':
361  start += 1 ;
362  state = 7;
363  break;
364  default:
365  state = 0; /* Something's probably wrong */
366  fprintf (stderr, "\nUnexpected token after FontBBox. Struggling along\n");
367  dump (start, end);
368  }
369  break;
370  case 7:
371  switch (*start) {
372  case ']':
373  case '}':
374  start += 1 ;
375  state = 0;
376  break;
377  case '{':
378  case '[':
379  case '(':
380  case '/':
381  state = 0; /* Something's probably wrong */
382  fprintf (stderr, "\nUnexpected token in FontBBox array. Struggling along\n");
383  dump (start, end);
384  break;
385  default:
386  ident = parse_ident (&start, end);
387  if ((ident) && is_a_number (ident)) {
388  pdf_obj *tmp = pdf_lookup_dict (pfbs[pfb_id].descriptor,
389  "FontBBox");
391  }
392  if (ident)
393  RELEASE (ident);
394  }
395  break;
396  case 8:
397  switch (*start) {
398  case '{': case '}': case '[': case ']': case '/':
399  state = 0;
400  break;
401  default:
402  ident = parse_ident (&start, end);
403  if ((ident) && is_a_number (ident)) {
404  double italic = atof(ident);
405  if (italic != 0.0) {
407  "Flags"));
408  pdf_add_dict (pfbs[pfb_id].descriptor,
409  pdf_new_name ("ItalicAngle"),
411  pdf_add_dict (pfbs[pfb_id].descriptor,
412  pdf_new_name ("Flags"),
414  }
415  }
416  if (ident)
417  RELEASE (ident);
418  state = 0;
419  }
420  }
421  skip_white (&start, end);
422  if (state >=2 && state <= 5 && !pfbs[pfb_id].used_def_enc_chars) {
423  lead = start;
424  }
425  if (copy && start != lead) { /* Flush everything back to "lead" */
426  if (filtered) {
427  memcpy (filtered_pointer, lead, start-lead);
428  filtered_pointer += start-lead;
429  }
430  lead = start;
431  }
432  }
433 #ifdef MEM_DEBUG
434  MEM_END
435 #endif /* MEM_DEBUG */
436  return filtered? filtered_pointer-filtered: length;
437 }
438 
439 static void dump_glyphs( char **glyphs, int n, int show_index)
440 {
441  int i;
442  for (i=0; i<n; i++) {
443  if (show_index)
444  fprintf (stderr, "(%d", i);
445  if (glyphs[i])
446  fprintf (stderr, "/%s", glyphs[i]);
447  else
448  fprintf (stderr, "(null)");
449  if (show_index)
450  fprintf (stderr, ")");
451  }
452  return;
453 }
454 static void dump_used( char *used_chars)
455 {
456  int i;
457  for (i=0; i<256; i++)
458  fprintf (stderr, "(%d/%d)", i, used_chars[i]);
459  return;
460 }
461 
462 
463 #define ASCII 1
464 #define BINARY 2
465 
466 static int is_a_pfb (FILE *file)
467 {
468  int result, ch;
469  if ((ch = fgetc (file)) == 128 &&
470  ((ch = fgetc (file)) == ASCII ||
471  (ch == BINARY))) {
472  result = 1;
473  } else
474  result = 0;
475  rewind (file);
476  return result;
477 }
478 
479 static unsigned char *get_pfb_segment (unsigned long *length,
480  FILE *file, int expected_type)
481 {
482  unsigned char *buffer = NULL;
483  unsigned long nread;
484  unsigned long new_length;
485  int stream_type, ch;
486 
487  *length = 0;
488  /* Unfortunately, there can be several segments that need to be
489  concatenated, so we loop through all of them */
490  for (;;) {
491  if ((ch = fgetc (file)) < 0) /* Some files don't terminate
492  properly */
493  break;
494  if (ch != 128){
495  sprintf (work_buffer, "get_pfb_segment: Not a pfb file.\n");
496  sprintf (work_buffer, "get_pfb_segment: pfb header has %d, expecting 128\n", ch);
497  ERROR (work_buffer);
498  }
499  if ((stream_type = fgetc (file)) < 0 || stream_type != expected_type) {
500  seek_relative (file, -2); /* Backup up two (yuck!) */
501  break;
502  }
503  new_length = get_low_endian_quad (file);
504  if (verbose > 4) {
505  fprintf (stderr, "Length of next PFB segment: %ld\n",
506  new_length);
507  }
508  buffer = RENEW (buffer, (*length)+new_length, unsigned char);
509  if ((nread = fread(buffer+(*length), sizeof(unsigned char), new_length, file)) !=
510  new_length) {
511  fprintf (stderr, "Found only %ld/%ld bytes\n", nread, new_length);
512  ERROR ("type1_do_pfb_segment: Are you sure this is a pfb?");
513  }
514  *length += new_length;
515  }
516  if (*length == 0) {
517  ERROR ("type1_get_pfb_segment: Segment length is zero");
518  }
519  if (expected_type == ASCII) {
520  int i;
521  for (i=0; i<(*length); i++) {
522  if (buffer[i] == '\r')
523  buffer[i] = '\n'; /* Show my Unix prejudice */
524  }
525  }
526  return buffer;
527 }
528 
529 static unsigned int glyph_length (char **glyphs)
530 {
531  int i;
532  unsigned result = 0;
533  for (i=0; i<256; i++) {
534  result += strlen (glyphs[i]);
535  }
536  return result;
537 }
538 
539 static char *pfb_find_name (FILE *pfb_file)
540 {
541  unsigned char *buffer;
542  unsigned long length = 0;
543  char *start, *end, *fontname;
544  int state = 0;
545 #ifdef MEM_DEBUG
546  MEM_START
547 #endif
548  rewind (pfb_file);
549  buffer = get_pfb_segment (&length, pfb_file, ASCII);
550  /* State definitions
551  state 0: Initial state
552  state 1: Saw /FontName */
553  start = (char *) buffer;
554  end = start+length;
555  skip_white (&start, end);
556  fontname = NULL;
557  while (start < end && fontname == NULL) {
558  char *ident;
559  pdf_obj *pdfobj;
560  switch (*start) {
561  /* Ignore arrays and procedures */
562  case '[':
563  case ']':
564  case '{':
565  case '}':
566  start += 1;
567  if (state == 1) {
568  ERROR ("Garbage following /FontName");
569  }
570  break;
571  case '(':
572  pdfobj = parse_pdf_string (&start, end);
573  if (pdfobj == NULL) {
574  ERROR ("parse_header: Error parsing a string in pfb header");
575  }
576  if (state == 1) { /* This string must be the font name */
577  char *tmp = pdf_string_value (pdfobj);
578  fontname = NEW (strlen(tmp)+1, char);
579  memcpy (fontname, tmp, strlen(tmp)+1);
580  }
581  pdf_release_obj (pdfobj);
582  break;
583  case '/':
584  start += 1;
585  ident = parse_ident (&start, end);
586  if (state == 0 && !strcmp (ident, "FontName")) {
587  state = 1;
588  } else if (state == 1) {
589  fontname = NEW (strlen(ident)+1, char);
591  }
592  RELEASE (ident);
593  break;
594  default:
595  ident = parse_ident (&start, end);
596  RELEASE (ident);
597  break;
598  }
599  skip_white (&start, end);
600  }
601  RELEASE (buffer);
602 #ifdef MEM_DEBUG
603  MEM_END
604 #endif /* MEM_DEBUG */
605  return fontname;
606 }
607 
608 static void pfb_add_to_used_glyphs (int pfb_id, char *glyph)
609 {
610  if (pfb_id >= 0 && pfb_id < num_pfbs && glyph) {
611  if (pfbs[pfb_id].n_used_glyphs == 0 ||
612  !bsearch (glyph, pfbs[pfb_id].used_glyphs,
613  pfbs[pfb_id].n_used_glyphs,
614  sizeof (char *), glyph_match)) {
615  if (pfbs[pfb_id].n_used_glyphs+1 >=
616  pfbs[pfb_id].max_used_glyphs) {
617  pfbs[pfb_id].max_used_glyphs += 16;
618  pfbs[pfb_id].used_glyphs = RENEW (pfbs[pfb_id].used_glyphs,
619  pfbs[pfb_id].max_used_glyphs,
620  char *);
621  }
622  (pfbs[pfb_id].used_glyphs)[pfbs[pfb_id].n_used_glyphs] =
623  NEW (strlen(glyph)+1, char);
624  strcpy((pfbs[pfb_id].used_glyphs)[pfbs[pfb_id].n_used_glyphs],
625  glyph);
626  pfbs[pfb_id].n_used_glyphs += 1;
627  qsort (pfbs[pfb_id].used_glyphs, pfbs[pfb_id].n_used_glyphs,
628  sizeof (char *), glyph_cmp);
629  }
630  }
631 }
632 
633 static char *new_used_chars (void)
634 {
635  char *result;
636  int i;
637  result = NEW (256, char);
638  for (i=0; i<256; i++) {
639  result[i] = 0;
640  }
641  return result;
642 }
643 
644 /* Mark the character at position "code" as used in the pfb font
645  corresponding to "pfb_id" */
646 static void pfb_add_to_used_chars (int pfb_id, unsigned code)
647 {
648  if (pfb_id >= 0 && pfb_id < num_pfbs && code < 256) {
649  if (!pfbs[pfb_id].used_def_enc_chars) {
651  }
652  (pfbs[pfb_id].used_def_enc_chars)[code] = 1;
653  }
654  if (code >= 256)
655  ERROR ("pfb_add_to_used_chars(): code >= 256");
656  return;
657 }
658 
659 static unsigned long do_pfb_header (FILE *file, int pfb_id)
660 {
661  unsigned char *buffer, *filtered = NULL;
662  unsigned long length = 0;
663 #ifdef MEM_DEBUG
664 MEM_START
665 #endif
667  if (partial_enabled) {
668  filtered = NEW (length+strlen(pfbs[pfb_id].fontname)+1+1024, unsigned
669  char);
670  }
671  /* We must parse the header even if not doing font subsetting so
672  that we can determine the parameters for the font descriptor.
673  parse_head() won't write to a null pointer */
674  length = parse_header (filtered, buffer, length, pfb_id);
675  if (filtered) {
676  pdf_add_stream (pfbs[pfb_id].direct, (char *) filtered, length);
677  RELEASE (filtered);
678  } else {
679  pdf_add_stream (pfbs[pfb_id].direct, (char *) buffer, length);
680  }
681  RELEASE (buffer);
682 #ifdef MEM_DEBUG
683 MEM_END
684 #endif
685  return length;
686 }
687 
688 
689 static unsigned long parse_body (unsigned char *filtered, unsigned char
690  *unfiltered, unsigned long length,
691  char **used_glyphs, unsigned *n_used,
693 {
694  char *start, *end, *tail, *ident;
695  unsigned char *filtered_pointer;
696  double last_number = 0.0;
697  int state = 0;
698  if (verbose > 2) {
699  fprintf (stderr, "\nSearching for following glyphs in font:\n");
700  dump_glyphs (used_glyphs, *n_used, 0);
701  }
702  start = (char *) unfiltered, end = (char *) unfiltered+length;
703  /* Skip first four bytes */
704  tail = start; filtered_pointer = filtered;
705  start += 4;
706  /* Skip everything up to the charstrings section */
707  while (start < end) {
708  pdf_obj *pdfobj;
709  skip_white (&start, end);
710  /* Very simple state machine
711  state = 0: nothing special
712  state = 1: Saw StdVW, but waiting for number after it */
713  switch (*start) {
714  case '[':
715  case ']':
716  case '{':
717  case '}':
718  start += 1;
719  continue;
720  case '(':
721  pdfobj = parse_pdf_string (&start, end);
722  if (pdfobj == NULL) {
723  ERROR ("Error processing a string in a PFB file.");
724  }
725  pdf_release_obj (pdfobj);
726  continue;
727  case '/':
728  start += 1;
729  if ((ident = parse_ident (&start, end)) &&
730  !strcmp ((char *) ident, "CharStrings")) {
731  RELEASE (ident);
732  break;
733  } else if (ident && !strcmp ((char *) ident, "StdVW")) {
734  state = 1; /* Saw StdVW */
735  }
736  if (ident) {
737  RELEASE (ident);
738  } else {
739  fprintf (stderr, "\nError processing identifier in PFB file.\n");
740  dump (start, end);
741  }
742  continue;
743  default:
744  ident = parse_ident (&start, end);
745  if (ident == NULL)
746  ERROR ("Error processing a symbol in the PFB file.");
747  if (is_an_int(ident))
748  if (state == 1) {
751  state = 0; /* Return to normal processing */
752  } else
753  last_number = atof (ident); /* Might be start of RD */
754  else {
755  if (!strcmp (ident, "RD") ||
756  !strcmp (ident, "-|")) {
757  start += ((unsigned long) last_number) + 1;
758  }
759  }
760  RELEASE (ident);
761  continue;
762  }
763  break;
764  }
765  if (start >= end)
766  ERROR ("Unexpected end of binary portion of PFB file");
767  /* Copy what we have so far over to the new buffer */
768  if (filtered) {
769  memcpy (filtered_pointer, tail, start-tail);
770  /* Advance pointer into new buffer */
771  filtered_pointer += (start-tail);
772  }
773  /* At this point, start is positioned just before the beginning of the glyphs, just after
774  the word /CharStrings. The earlier portion of the input buffer has
775  been copied to the output. The remainder of the routine need not
776  be executed if not doing font subsetting */
777  if (filtered) {
778  char **this_glyph;
779  filtered_pointer += sprintf ((char *) filtered_pointer, " %d",
780  *n_used);
781  skip_white(&start, end);
782  /* The following ident *should* be the number of glyphs in this
783  file */
784  ident = parse_ident (&start, end);
785  if (verbose>1) {
786  fprintf (stderr, "\n Embedding %d of %s glyphs\n", *n_used, ident);
787  }
788  if (ident == NULL || !is_an_int (ident) || *n_used > atof (ident))
789  ERROR ("More glyphs needed than present in file");
790  RELEASE (ident);
791  tail = start;
792  while (start < end && *start != '/') start++;
793  if (filtered) {
794  memcpy (filtered_pointer, tail, start-tail);
795  filtered_pointer += (start-tail);
796  }
797  /* Now we are exactly at the beginning of the glyphs */
798  while (start < end && *start == '/') {
799  char *glyph;
800  tail = start;
801  start += 1;
802  glyph = parse_ident (&start, end);
803  /* Get the number that should follow the glyph name */
804  skip_white(&start, end);
805  ident = parse_ident (&start, end);
806  if (!is_an_int (ident))
807  ERROR ("Expecting an integer after glyph name");
808  last_number = atof (ident);
809  RELEASE (ident);
810  /* The next identifier should be a "RD" or a "-|". We don't
811  really care what it is */
812  skip_white(&start, end);
813  ident = parse_ident (&start, end);
814  RELEASE (ident);
815  /* Skip a blank */
816  start += 1;
817  /* Skip the binary stream */
818  start += (unsigned long) last_number;
819  /* Skip the "ND" or "|-" terminator */
820  skip_white(&start, end);
821  ident = parse_ident (&start, end);
822  RELEASE (ident);
823  skip_white (&start, end);
824  if (*n_used != 0 && (this_glyph = bsearch (glyph, used_glyphs, *n_used, sizeof (char *),
825  glyph_match))) {
826  memcpy (filtered_pointer, tail, start-tail);
827  filtered_pointer += start-tail;
828  (*n_used)--;
829  /* Remove glyph and rearrange used_glyphs array */
830  {
831  RELEASE (*this_glyph);
832  (*this_glyph) = used_glyphs[*n_used];
833  qsort (used_glyphs, *n_used, sizeof (char *), glyph_cmp);
834  }
835  }
836  RELEASE (glyph);
837  }
838  if (*n_used != 0) {
839  fprintf (stderr, "Didn't find following required glyphs in the font:\n");
840  dump_glyphs (used_glyphs, *n_used, 0);
841  ERROR ("Possibly the encoding is incorrect.");
842  }
843  /* Include the rest of the file verbatim */
844  if (start < end){
845  memcpy (filtered_pointer, start, end-start);
846  filtered_pointer += end-start;
847  }
848  if (verbose>1) {
849  fprintf (stderr, " (subsetting eliminated %ld bytes)", length-(filtered_pointer-filtered));
850  }
851  }
852  return (filtered? filtered_pointer-filtered: length);
853 }
854 
855 static unsigned long do_pfb_body (FILE *file, int pfb_id)
856 {
857  int i;
858  unsigned char *buffer=NULL, *filtered=NULL;
859  unsigned long length=0;
860 #ifdef MEM_DEBUG
861  MEM_START
862 #endif
864  /* We need to decrypt the binary
865  portion of the pfb */
867  for (i=0; i<length; i++) {
868  buffer[i] = t1_decrypt(buffer[i]);
869  }
870  if (partial_enabled) {
871  filtered = NEW (length, unsigned char);
872  }
873  length = parse_body (filtered, buffer, length,
874  pfbs[pfb_id].used_glyphs,
875  &pfbs[pfb_id].n_used_glyphs,
876  pfbs[pfb_id].descriptor);
877  /* And reencrypt the whole thing */
879  for (i=0; i<length; i++) {
880  buffer[i] = t1_encrypt(partial_enabled? filtered[i]: buffer[i]);
881  }
882  if (filtered)
883  RELEASE (filtered);
884  pdf_add_stream (pfbs[pfb_id].direct, (char *) buffer, length);
885  RELEASE (buffer);
886 #ifdef MEM_DEBUG
887  MEM_START
888 #endif
889  return length;
890 }
891 
892 static unsigned long do_pfb_trailer (FILE *file, pdf_obj *stream)
893 {
894  unsigned char *buffer;
895  unsigned long length;
897  pdf_add_stream (stream, (char *) buffer, length);
898  RELEASE (buffer);
899  return length;
900 }
901 
902 
903 static pdf_obj *type1_fontfile (int pfb_id)
904 {
905  if (pfb_id >= 0 && pfb_id < num_pfbs)
906  return pdf_link_obj(pfbs[pfb_id].indirect);
907  else
908  return NULL;
909 }
910 
911 static char *type1_fontname (int pfb_id)
912 {
913  if (pfb_id >= 0 && pfb_id < num_pfbs)
914  return pfbs[pfb_id].fontname;
915  else
916  return NULL;
917 }
918 
919 /* Mangle_fontname mangles the name in place. fontname
920  must be big enough to add seven characters */
921 
922 static void mangle_fontname(char *fontname)
923 {
924  int i;
925  char ch;
926  static char first = 1;
928  /* The following procedure isn't very random, but it
929  doesn't need to be for this application. */
930  if (first) {
931  srand (time(NULL));
932  first = 0;
933  }
934  for (i=0; i<6; i++) {
935  ch = rand() % 26;
936  fontname[i] = ch+'A';
937  }
938  fontname[6] = '+';
939 }
940 
941 
942 /* This routine builds a default font descriptor with dummy values
943  filled in for the required keys. As the pfb file is parsed,
944  any values that are found are rewritten. By doing this,
945  all the required fields are found in the font descriptor
946  even if the pfb is somewhat defective. This approach is
947  conservative, with the cost of keeping the names around in memory
948  for a while.
949 */
950 
951 static void type1_start_font_descriptor (int pfb_id)
952 {
953  pdf_obj *tmp1;
954  pfbs[pfb_id].descriptor = pdf_new_dict ();
955  pdf_add_dict (pfbs[pfb_id].descriptor,
956  pdf_new_name ("Type"),
957  pdf_new_name ("FontDescriptor"));
958  /* For now, insert dummy values */
959  pdf_add_dict (pfbs[pfb_id].descriptor,
960  pdf_new_name ("CapHeight"),
961  pdf_new_number (850.0)); /* This number is arbitrary */
962  pdf_add_dict (pfbs[pfb_id].descriptor,
963  pdf_new_name ("Ascent"),
964  pdf_new_number (850.0)); /* This number is arbitrary */
965  pdf_add_dict (pfbs[pfb_id].descriptor,
966  pdf_new_name ("Descent"),
967  pdf_new_number (-200.0));
968  tmp1 = pdf_new_array ();
969  pdf_add_dict (pfbs[pfb_id].descriptor, pdf_new_name ("FontBBox"), tmp1);
970  pdf_add_dict (pfbs[pfb_id].descriptor,
971  pdf_new_name ("FontName"),
972  pdf_new_name (type1_fontname(pfb_id)));
973 
974  pdf_add_dict (pfbs[pfb_id].descriptor,
975  pdf_new_name ("ItalicAngle"),
976  pdf_new_number(0.0));
977  pdf_add_dict (pfbs[pfb_id].descriptor,
978  pdf_new_name ("StemV"), /* StemV is required, StemH
979  is not */
980  pdf_new_number (STEMV)); /* Use a default value */
981  /* You don't need a fontfile for the standard fonts */
982  if (pfb_id >= 0)
983  pdf_add_dict (pfbs[pfb_id].descriptor,
984  pdf_new_name ("FontFile"),
985  type1_fontfile (pfb_id));
986 
987  pdf_add_dict (pfbs[pfb_id].descriptor,
988  pdf_new_name ("Flags"),
989  pdf_new_number (SYMBOLIC)); /* Treat all fonts as symbolic */
990  return;
991 }
992 
993 static int pfb_get_id (const char *pfb_name)
994 {
995  int i;
996  char *pp;
997  char t1name[128];
998 
999  strcpy(t1name, pfb_name);
1000  pp = strrchr(t1name, '.');
1001  if(!pp || stricmp(pp, ".pfb")) strcat(t1name, ".pfb");
1002  for (i=0; i<num_pfbs; i++) {
1003  if (pfbs[i].pfb_name && !stricmp (pfbs[i].pfb_name, pfb_name))
1004  break;
1005  }
1006  if (i == num_pfbs) { /* This font not previously called for */
1007  FILE *pfb_file = NULL;
1008  char *full_pfb_name, *short_fontname;
1009  if (!(full_pfb_name = kpse_find_file (t1name, kpse_type1_format,
1010  1)) ||
1011  !(pfb_file = MFOPEN (full_pfb_name, FOPEN_RBIN_MODE)) ||
1012  !(is_a_pfb (pfb_file))) {
1013  if (pfb_file)
1014  MFCLOSE (pfb_file);
1015  i = -1;
1016  } else {
1017  short_fontname = pfb_find_name (pfb_file);
1018  MFCLOSE (pfb_file);
1019  if (num_pfbs >= max_pfbs) {
1020  max_pfbs += MAX_FONTS;
1021  pfbs = RENEW (pfbs, max_pfbs, struct a_pfb);
1022  }
1023  num_pfbs += 1;
1024  init_a_pfb (pfbs+i);
1025  pfbs[i].pfb_name = NEW (strlen(pfb_name)+1, char);
1026  strcpy (pfbs[i].pfb_name, pfb_name);
1029  if (partial_enabled) {
1030  pfbs[i].fontname = NEW (strlen(short_fontname)+8, char);
1031  strcpy (pfbs[i].fontname, short_fontname);
1033  }
1034  else {
1035  pfbs[i].fontname = NEW (strlen(short_fontname)+1, char);
1036  strcpy (pfbs[i].fontname, short_fontname);
1037  }
1039  if (short_fontname)
1040  RELEASE (short_fontname);
1041  }
1042  }
1043  return i;
1044 }
1045 
1046 static void pfb_release (int id)
1047 {
1048  if (id >= 0 && id < num_pfbs) {
1049  pdf_release_obj (pfbs[id].direct);
1050  RELEASE (pfbs[id].pfb_name);
1051  pdf_release_obj (pfbs[id].indirect);
1052  RELEASE (pfbs[id].fontname);
1053  if (pfbs[id].used_def_enc_chars)
1054  RELEASE (pfbs[id].used_def_enc_chars);
1055  if (pfbs[id].int_encoding){
1056  int i;
1057  for (i=0; i<256; i++) {
1058  if ((pfbs[id].int_encoding)[i])
1059  RELEASE ((pfbs[id].int_encoding)[i]);
1060  }
1061  RELEASE (pfbs[id].int_encoding);
1062  }
1063  if (pfbs[id].used_glyphs) {
1064  unsigned i;
1065  for (i=0; i<pfbs[id].n_used_glyphs; i++) {
1066  RELEASE ((pfbs[id].used_glyphs)[i]);
1067  }
1068  RELEASE (pfbs[id].used_glyphs);
1069  }
1070  }
1071 }
1072 
1073 static void release_glyphs (char **glyphs)
1074 {
1075  int i;
1076  for (i=0; i<256; i++) {
1077  RELEASE (glyphs[i]);
1078  }
1079 }
1080 
1081 static void do_pfb (int pfb_id)
1082 {
1083  char *full_pfb_name;
1084  FILE *type1_binary_file;
1085  pdf_obj *stream_dict;
1086  unsigned long length1, length2, length3;
1087  int ch;
1088  char *pp;
1089  char t1name[128];
1090 
1091  strcpy(t1name, pfbs[pfb_id].pfb_name);
1092  pp = strrchr(t1name, '.');
1093  if(!pp || stricmp(pp, ".pfb")) strcat(t1name, ".pfb");
1094  full_pfb_name = kpse_find_file (t1name, kpse_type1_format, 1);
1095  if (verbose == 1)
1096  fprintf (stderr, "(PFB:%s", pfbs[pfb_id].pfb_name);
1097  if (verbose > 1)
1098  fprintf (stderr, "(PFB:%s", full_pfb_name);
1099  if (full_pfb_name == NULL ||
1100  (type1_binary_file = MFOPEN (full_pfb_name, FOPEN_RBIN_MODE)) == NULL) {
1101  fprintf (stderr, "type1_fontfile: Unable to find or open binary font file (%s)",
1102  pfbs[pfb_id].pfb_name);
1103  ERROR ("This existed when I checked it earlier!");
1104  return;
1105  }
1106  /* Following section doesn't hide PDF stream structure very well */
1107  length1 = do_pfb_header (type1_binary_file, pfb_id);
1108  /* The following section seems determines which, if any,
1109  glyphs were used via the internal encoding, which hasn't
1110  been known until now.*/
1111  if (partial_enabled) {
1112  int j;
1113  if (verbose > 2) {
1114  fprintf (stderr, "Default encoding:\n");
1115  dump_glyphs (pfbs[pfb_id].int_encoding, 256, 1);
1116  }
1117  if (pfbs[pfb_id].used_def_enc_chars) {
1118  if (verbose > 2)
1119  fprintf (stderr, "\nRetaining portion of default encoding:\n");
1120  for (j=0; j<256; j++) {
1121  if ((pfbs[pfb_id].used_def_enc_chars)[j]) {
1122  if (verbose > 2)
1123  fprintf (stderr, "(%d/%s)", j, (pfbs[pfb_id].int_encoding)[j]);
1124  pfb_add_to_used_glyphs (pfb_id, (pfbs[pfb_id].int_encoding)[j]);
1125  }
1126  }
1127  }
1128  }
1129  length2 = do_pfb_body (type1_binary_file, pfb_id);
1130  length3 = do_pfb_trailer (type1_binary_file, pfbs[pfb_id].direct);
1131  if ((ch = fgetc (type1_binary_file)) != 128 ||
1132  (ch = fgetc (type1_binary_file)) != 3) {
1133  fprintf (stderr, "\n\nWarning: PFB file may be improperly terminated\n");
1134  }
1135  /* Got entire file! */
1136  if (verbose > 1)
1137  fprintf (stderr, "\n Embedded size: %ld bytes\n", length1+length2+length3);
1138  if (verbose) {
1139  fprintf (stderr, ")");
1140  }
1141  MFCLOSE (type1_binary_file);
1142  stream_dict = pdf_stream_dict (pfbs[pfb_id].direct);
1143  pdf_add_dict (stream_dict, pdf_new_name("Length1"),
1144  pdf_new_number (length1));
1145  pdf_add_dict (stream_dict, pdf_new_name("Length2"),
1146  pdf_new_number (length2));
1147  pdf_add_dict (stream_dict, pdf_new_name("Length3"),
1148  pdf_new_number (length3));
1149  /* Finally, flush the descriptor */
1150  pdf_release_obj (pfbs[pfb_id].descriptor);
1151  return;
1152 }
1153 
1154 void pfb_flush_all (void)
1155 {
1156  int i;
1157  for (i=0; i<num_pfbs; i++) {
1158  do_pfb(i);
1159  pfb_release (i);
1160  }
1161  if (pfbs)
1162  RELEASE (pfbs);
1163 }
1164 
1166 {
1168  long pfb_id;
1170  char *used_chars;
1173 
1174 
1175 static void init_a_type1_font (struct a_type1_font *this_type1_font)
1176 {
1177  if (partial_enabled) {
1178  this_type1_font -> used_chars = new_used_chars ();
1179  } else {
1180  this_type1_font -> used_chars = NULL;
1181  }
1182 }
1183 
1185 {
1186  if (type1_id>=0 && type1_id<max_type1_fonts)
1187  return pdf_link_obj(type1_fonts[type1_id].indirect);
1188  else {
1189  ERROR ("Invalid font id in type1_font_resource");
1190  return NULL;
1191  }
1192 }
1193 
1194 char *type1_font_used (int type1_id)
1195 {
1196  char *result;
1197  if (type1_id>=0 && type1_id<max_type1_fonts) {
1198  result = type1_fonts[type1_id].used_chars;
1199  } else {
1200  fprintf (stderr, "type1_font_used: type1_id=%d\n", type1_id);
1201  ERROR ("Invalid font id in type1_font_used");
1202  }
1203  return result;
1204 }
1205 
1206 
1207 static int is_a_base_font (const char *name)
1208 {
1209  static char *basefonts[] = {
1210  "Courier", "Courier-Bold", "Courier-Oblique",
1211  "Courier-BoldOblique", "Helvetica", "Helvetica-Bold",
1212  "Helvetica-Oblique", "Helvetica-BoldOblique", "Symbol",
1213  "Times-Roman", "Times-Bold", "Times-Italic",
1214  "Times-BoldItalic", "ZapfDingbats"
1215  };
1216  int i;
1217  for (i=0; i<14; i++) {
1218  if (!strcmp (name, basefonts[i]))
1219  return 1;
1220  }
1221  return 0;
1222 }
1223 
1224 int type1_font (const char *map_name, int tfm_font_id, char
1225  *resource_name, int encoding_id, int remap)
1226 {
1227  int i, result = -1;
1228  int tfm_firstchar, tfm_lastchar;
1229  int pdf_firstchar, pdf_lastchar;
1230  int pfb_id = -1;
1231  pdf_obj *font_resource, *tmp1, *font_encoding_ref;
1232 
1236  a_type1_font);
1237  }
1238 
1239  if ((map_name && is_a_base_font(map_name)) ||
1240  (pfb_id = pfb_get_id(map_name)) >= 0) {
1241  /* Looks like we have a physical font (either a reader font or a
1242  Type 1 font binary file). */
1245  type1_fonts[num_type1_fonts].encoding_id = encoding_id;
1246  /* Allocate a dictionary for the physical font */
1247  font_resource = pdf_new_dict ();
1248  if (type1_fonts[num_type1_fonts].encoding_id >= 0) {
1249  font_encoding_ref = encoding_ref (encoding_id);
1250  pdf_add_dict (font_resource,
1251  pdf_new_name ("Encoding"),
1252  font_encoding_ref);
1253  }
1254  pdf_add_dict (font_resource,
1255  pdf_new_name ("Type"),
1256  pdf_new_name ("Font"));
1257  pdf_add_dict (font_resource,
1258  pdf_new_name ("Subtype"),
1259  pdf_new_name ("Type1"));
1260  pdf_add_dict (font_resource,
1261  pdf_new_name ("Name"),
1262  pdf_new_name (resource_name));
1263  if (type1_fonts[num_type1_fonts].pfb_id >= 0) {
1264  pdf_add_dict (font_resource,
1265  pdf_new_name ("FontDescriptor"),
1267  }
1268  /* If we are embedding this font, it may have been used by another virtual
1269  font and we need to use the same mangled name. Mangled
1270  names are known only to the pfb module, so we call it to get
1271  the name */
1272  if (type1_fonts[num_type1_fonts].pfb_id >= 0) {
1273  pdf_add_dict (font_resource,
1274  pdf_new_name ("BaseFont"),
1275  pdf_new_name
1277  /* Otherwise we use the base name */
1278  } else {
1279  pdf_add_dict (font_resource,
1280  pdf_new_name ("BaseFont"),
1281  pdf_new_name (map_name));
1282  }
1283  if (!(map_name && is_a_base_font (map_name))) {
1284  tfm_firstchar = tfm_get_firstchar(tfm_font_id);
1285  tfm_lastchar = tfm_get_lastchar(tfm_font_id);
1286  if (remap) {
1287  unsigned char t;
1288  pdf_firstchar=255; pdf_lastchar=0;
1289  for (i=tfm_firstchar; i<=tfm_lastchar; i++) {
1290  if ((t=twiddle(i)) < pdf_firstchar)
1291  pdf_firstchar = t;
1292  if (t > pdf_lastchar)
1293  pdf_lastchar = t;
1294  }
1295  } else {
1296  pdf_firstchar = tfm_firstchar;
1297  pdf_lastchar = tfm_lastchar;
1298  }
1299  pdf_add_dict (font_resource,
1300  pdf_new_name ("FirstChar"),
1301  pdf_new_number (pdf_firstchar));
1302  pdf_add_dict (font_resource,
1303  pdf_new_name ("LastChar"),
1304  pdf_new_number (pdf_lastchar));
1305  tmp1 = pdf_new_array ();
1306  for (i=pdf_firstchar; i<=pdf_lastchar; i++) {
1307  if (remap) {
1308  int t;
1309  if ((t=untwiddle(i)) <= tfm_lastchar && t>=tfm_firstchar)
1312  (tfm_font_id,t)*1000.0,0.1)));
1313  else
1315  pdf_new_number(0.0));
1316  } else
1319  (tfm_font_id, i)*1000.0,0.1)));
1320  }
1321  pdf_add_dict (font_resource,
1322  pdf_new_name ("Widths"),
1323  tmp1);
1324  }
1325  type1_fonts[num_type1_fonts].indirect = pdf_ref_obj(font_resource);
1326  pdf_release_obj (font_resource);
1328  num_type1_fonts += 1;
1329  } else { /* Don't have a physical font */
1330  result = -1;
1331  }
1332  return result;
1333 }
1334 
1335 
1336 void type1_close_all (void)
1337 {
1338  int i, j;
1339  /* Three arrays are created by this module and need to be released */
1340  /* First, each TeX font name that ends up as a postscript font gets
1341  added to type1_fonts (yes, even Times-Roman, etc.) */
1342  /* The first thing to do is to resolve all character references to
1343  actual glyph references. If an external encoding is specified,
1344  we simply look up the glyph name in the encoding. If the internal
1345  encoding is being used, we add it to the used_chars array of
1346  the internal encoding */
1347  for (i=0; i<num_type1_fonts; i++) {
1348  /* If font subsetting is enabled, each used character needs
1349  to be added to the used_glyphs array in the corresponding pfb
1350  */
1351  if (partial_enabled) {
1352  /* We always consider .notdef to be used */
1353  pfb_add_to_used_glyphs (type1_fonts[i].pfb_id, ".notdef");
1354  for (j=0; j<256; j++) {
1355  char *glyph;
1356  if (type1_fonts[i].pfb_id >= 0 &&
1357  type1_fonts[i].encoding_id >= 0 &&
1358  (type1_fonts[i].used_chars)[j]) {
1359  glyph = encoding_glyph (type1_fonts[i].encoding_id,
1360  j);
1362  }
1363  if (type1_fonts[i].pfb_id >= 0 &&
1364  type1_fonts[i].encoding_id < 0 &&
1365  (type1_fonts[i].used_chars)[j])
1366  pfb_add_to_used_chars (type1_fonts[i].pfb_id, j);
1367  }
1368  }
1369  if (type1_fonts[i].used_chars)
1370  RELEASE (type1_fonts[i].used_chars);
1371  pdf_release_obj (type1_fonts[i].indirect);
1372  }
1373  RELEASE (type1_fonts);
1374  /* Second every distinct pfb name ends up in pfbs. It is possible
1375  that two distinct tex names map to the same pfb name. That's why
1376  there is a separate array for pfbs */
1377 
1378  /* Read any necessary font files and flush them */
1379  pfb_flush_all();
1380 
1381 }
1382 
void *__cdecl bsearch(void const *_Key, void const *_Base, size_t _NumOfElements, size_t _SizeOfElements, _CoreCrtNonSecureSearchSortCompareFunction _CompareFunction)
const char * fontname
Definition: afm2pl.c:186
long * italic
Definition: afm2tfm.c:1034
#define name
#define tail
Definition: aptex-macros.h:514
#define n
Definition: t4ht.c:1290
#define strrchr
Definition: detex.c:67
void glyphs(int opcode)
Definition: disdvi.c:775
static int id
Definition: bifont.c:66
int v
Definition: dviconv.c:10
#define fread
Definition: xxstdio.h:25
#define fgetc
Definition: xxstdio.h:26
#define FOPEN_RBIN_MODE
Definition: dvips.h:86
int strcmp()
Definition: coll.cpp:143
char * strcpy()
char * encoding_glyph(int encoding_id, unsigned code)
Definition: encodings.c:210
pdf_obj * encoding_ref(int encoding_id)
Definition: encodings.c:186
static void copy(GlyphCachePtr *root)
Definition: gcache.c:378
mpz_t pp
Definition: gen-psqr.c:108
#define v1
#define v2
#define s
Definition: afcover.h:80
#define t
Definition: afcover.h:96
#define memmove(d, s, n)
Definition: gsftopk.c:65
#define memcpy(d, s, n)
Definition: gsftopk.c:64
#define MAX(a, b)
Definition: jpegint.h:267
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific i
Definition: afcover.h:80
t1_decrypt(FT_Byte *buffer, FT_Offset length, FT_UShort seed)
Definition: psobjs.c:2574
#define NEW
Definition: gdkanji.c:77
#define CDECL
Definition: config.h:100
double atof(const char *)
const char * descriptor
Definition: cid_basefont.h:48
static void skip_white(const char **pp, const char *endptr)
Definition: dpxutil.c:74
#define RENEW(p, n, type)
Definition: mem.h:38
#define srand(x)
Definition: mem.h:48
#define RELEASE(p)
Definition: mem.h:39
#define rand()
Definition: mem.h:49
void seek_relative(FILE *file, int32_t pos)
Definition: mfileio.c:85
char work_buffer[1024]
Definition: mfileio.c:171
#define MFOPEN(name, mode)
Definition: mfileio.h:42
#define MFCLOSE(file)
Definition: mfileio.h:44
pdf_obj * pdf_new_array(void)
Definition: pdfobj.c:1421
pdf_obj * pdf_new_name(const char *name)
Definition: pdfobj.c:1330
pdf_obj * pdf_new_number(double value)
Definition: pdfobj.c:1076
pdf_obj * pdf_ref_obj(pdf_obj *object)
Definition: pdfobj.c:960
pdf_obj * pdf_new_stream(int flags)
Definition: pdfobj.c:1863
double pdf_number_value(pdf_obj *object)
Definition: pdfobj.c:1119
void pdf_release_obj(pdf_obj *object)
Definition: pdfobj.c:3217
pdf_obj * pdf_lookup_dict(pdf_obj *dict, const char *name)
Definition: pdfobj.c:1800
pdf_obj * pdf_stream_dict(pdf_obj *stream)
Definition: pdfobj.c:2374
void pdf_add_stream(pdf_obj *stream, const void *stream_data, int length)
Definition: pdfobj.c:2424
pdf_obj * pdf_link_obj(pdf_obj *object)
Definition: pdfobj.c:948
void * pdf_string_value(pdf_obj *object)
Definition: pdfobj.c:1155
void pdf_add_array(pdf_obj *array, pdf_obj *object)
Definition: pdfobj.c:1511
pdf_obj * pdf_new_dict(void)
Definition: pdfobj.c:1645
int pdf_add_dict(pdf_obj *dict, pdf_obj *key, pdf_obj *value)
Definition: pdfobj.c:1680
#define STREAM_COMPRESS
Definition: pdfobj.h:45
void dump(const char *start, const char *end)
Definition: pdfparse.c:74
char * parse_ident(const char **start, const char *end)
Definition: pdfparse.c:195
pdf_obj * parse_pdf_string(const char **pp, const char *endptr)
Definition: pdfparse.c:622
double tfm_get_width(int font_id, int32_t ch)
Definition: tfm.c:1074
#define MAX_FONTS
Definition: tfm.c:314
#define ERROR(string)
Definition: error.h:36
#define MEM_END
Definition: mem.h:45
#define MEM_START
Definition: mem.h:44
static pdf_obj * tmp1
Definition: pdfdoc.c:76
int is_a_number(const char *s)
Definition: pdfparse.c:101
int is_an_int(const char *s)
Definition: pdfparse.c:89
UNSIGNED_PAIR tfm_get_firstchar(int font_id)
Definition: tfm.c:719
UNSIGNED_PAIR tfm_get_lastchar(int font_id)
Definition: tfm.c:724
static void do_a_standard_enc(char **glyphs, char **encoding)
Definition: type1.c:128
char * type1_font_used(int type1_id)
Definition: type1.c:1194
static void pfb_add_to_used_glyphs(int pfb_id, char *glyph)
Definition: type1.c:608
void pfb_flush_all(void)
Definition: type1.c:1154
static void mangle_fontname(char *fontname)
Definition: type1.c:922
static void type1_start_font_descriptor(int pfb_id)
Definition: type1.c:951
static int pfb_get_id(const char *pfb_name)
Definition: type1.c:993
static char * new_used_chars(void)
Definition: type1.c:633
static unsigned num_pfbs
Definition: type1.c:84
static unsigned long do_pfb_header(FILE *file, int pfb_id)
Definition: type1.c:659
static void pfb_release(int id)
Definition: type1.c:1046
static unsigned int glyph_length(char **glyphs)
Definition: type1.c:529
static unsigned char * get_pfb_segment(unsigned long *length, FILE *file, int expected_type)
Definition: type1.c:479
int max_type1_fonts
Definition: type1.c:1172
static unsigned long get_low_endian_quad(FILE *file)
Definition: type1.c:57
static char * type1_fontname(int pfb_id)
Definition: type1.c:911
static unsigned long parse_body(unsigned char *filtered, unsigned char *unfiltered, unsigned long length, char **used_glyphs, unsigned *n_used, pdf_obj *descriptor)
Definition: type1.c:689
#define ASCII
Definition: type1.c:463
static int is_a_pfb(FILE *file)
Definition: type1.c:466
static void dump_used(char *used_chars)
Definition: type1.c:454
static void do_pfb(int pfb_id)
Definition: type1.c:1081
static void dump_glyphs(char **glyphs, int n, int show_index)
Definition: type1.c:439
static void release_glyphs(char **glyphs)
Definition: type1.c:1073
int glyph_cmp(const void *v1, const void *v2)
Definition: type1.c:146
int num_type1_fonts
Definition: type1.c:1172
pdf_obj * type1_font_resource(int type1_id)
Definition: type1.c:1184
struct a_type1_font * type1_fonts
static int is_a_base_font(const char *name)
Definition: type1.c:1207
void type1_set_verbose(void)
Definition: type1.c:49
static unsigned long do_pfb_trailer(FILE *file, pdf_obj *stream)
Definition: type1.c:892
void type1_close_all(void)
Definition: type1.c:1336
static unsigned char verbose
Definition: type1.c:47
void type1_disable_partial(void)
Definition: type1.c:79
static unsigned max_pfbs
Definition: type1.c:85
struct a_pfb * pfbs
static void pfb_add_to_used_chars(int pfb_id, unsigned code)
Definition: type1.c:646
static unsigned long parse_header(unsigned char *filtered, unsigned char *buffer, unsigned long length, int pfb_id)
Definition: type1.c:161
static pdf_obj * type1_fontfile(int pfb_id)
Definition: type1.c:903
int glyph_match(const void *key, const void *v)
Definition: type1.c:154
static void init_a_pfb(struct a_pfb *pfb)
Definition: type1.c:104
#define BINARY
Definition: type1.c:464
#define SYMBOLIC
Definition: type1.c:141
int type1_font(const char *map_name, int tfm_font_id, char *resource_name, int encoding_id, int remap)
Definition: type1.c:1224
static void init_a_type1_font(struct a_type1_font *this_type1_font)
Definition: type1.c:1175
static unsigned long do_pfb_body(FILE *file, int pfb_id)
Definition: type1.c:855
#define ITALIC
Definition: type1.c:140
static char * pfb_find_name(FILE *pfb_file)
Definition: type1.c:539
static char partial_enabled
Definition: type1.c:77
#define STEMV
Definition: type1.c:143
@ kpse_type1_format
Definition: types.h:135
#define stricmp
Definition: win32lib.h:93
#define fprintf
Definition: mendex.h:64
#define ROUND(x)
Definition: type1.c:118
#define length(c)
Definition: ctangleboot.c:65
#define sprintf
Definition: snprintf.c:44
#define qsort
Definition: includes.h:72
static int32_t first
Definition: ppagelist.c:29
static long bytes
Definition: psutil.c:35
time_t time()
struct stream_s stream
Definition: pts_fax.h:93
#define flags
static char * isoencoding[256]
Definition: standardenc.h:56
static char * standardencoding[256]
Definition: standardenc.h:1
Definition: type1.c:87
unsigned max_used_glyphs
Definition: type1.c:101
pdf_obj * direct
Definition: type1.c:90
char * pfb_name
Definition: type1.c:88
pdf_obj * indirect
Definition: type1.c:90
char * fontname
Definition: type1.c:89
pdf_obj * descriptor
Definition: type1.c:90
char * used_def_enc_chars
Definition: type1.c:93
char ** used_glyphs
Definition: type1.c:91
char ** int_encoding
Definition: type1.c:92
unsigned n_used_glyphs
Definition: type1.c:101
char * used_chars
Definition: type1.c:1170
pdf_obj * encoding
Definition: type1.c:1167
pdf_obj * indirect
Definition: type1.c:1167
int encoding_id
Definition: type1.c:1169
long pfb_id
Definition: type1.c:1168
Definition: utils.c:300
Definition: inftrees.h:24
Definition: vmsdir.h:32
Definition: filedef.h:30
Definition: pbmfont.h:4
Definition: pdfobj.c:63
Definition: dvips.h:235
unsigned char t1_encrypt(unsigned char plain)
Definition: t1crypt.c:7
void t1_crypt_init(unsigned short int key)
Definition: t1crypt.c:15
#define EEKEY
Definition: t1crypt.h:4
#define FILE
Definition: t1stdio.h:34
ch
Definition: t4ht.c:1443
int j
Definition: t4ht.c:1589
s1
Definition: t4ht.c:1059
char * s2
Definition: t4ht.c:1062
*job_name strlen((char *) job_name) - 4)
#define key
Definition: tex2xindy.c:753
return() int(((double) *(font_tbl[cur_fnt].wtbl+(int)(*(font_tbl[cur_fnt].char_wi+(int)(ch - font_tbl[cur_fnt].char_f)% 256)))/(double)(1L<< 20)) *(double) font_tbl[cur_fnt].scale)
TT_Glyph glyph
Definition: ttf2pfb.c:162
char ident[]
Definition: ttf2pk.c:40
#define twiddle(n)
Definition: twiddle.h:2
#define untwiddle(n)
Definition: twiddle.h:7
static int pfb
Definition: type1asm.c:60
@ start
Definition: preamble.c:52
#define buffer
Definition: xmlparse.c:611
#define end(cp)
Definition: zic.c:71