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)  

type1c.c
Go to the documentation of this file.
1 /* This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks.
2 
3  Copyright (C) 2002-2020 by Jin-Hwan Cho, Matthias Franz, and Shunsaku Hirata,
4  the dvipdfmx project team.
5 
6  Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu>
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 */
22 
23 /*
24  * CFF/OpenType Font support:
25  *
26  * Adobe Technical Note #5176, "The Compact Font Format Specfication"
27  *
28  * NOTE:
29  *
30  * Many CFF/OpenType does not have meaningful/correct CFF encoding.
31  * Encoding should be expilicitly supplied in the fontmap.
32  *
33  */
34 
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
38 
39 #include <string.h>
40 
41 #include "system.h"
42 #include "mem.h"
43 #include "error.h"
44 #include "dpxconf.h"
45 #include "dpxfile.h"
46 
47 #include "pdfobj.h"
48 #include "pdffont.h"
49 
50 #include "pdfencoding.h"
51 #include "unicode.h"
52 
53 /* Font info. from OpenType tables */
54 #include "sfnt.h"
55 #include "tt_aux.h"
56 
57 #include "cff_types.h"
58 #include "cff_limits.h"
59 #include "cff.h"
60 #include "cff_dict.h"
61 #include "cs_type2.h"
62 
63 #include "type1c.h"
64 
65 int
66 pdf_font_open_type1c (pdf_font *font, const char *ident, int index, int encoding_id, int embedding)
67 {
68  char *fontname;
69  FILE *fp = NULL;
70  sfnt *sfont;
71  cff_font *cffont;
72  pdf_obj *descriptor, *tmp;
73  ULONG offset = 0;
74 
75  ASSERT(font);
76  ASSERT(ident);
77 
79  if (!fp)
81  if (!fp)
82  return -1;
83 
84  sfont = sfnt_open(fp);
85  if (!sfont) {
86  if (fp)
87  DPXFCLOSE(fp);
88  return -1;
89  }
90 
91  if (sfont->type == SFNT_TYPE_TTC) {
92  offset = ttc_read_offset(sfont, index);
93  }
94 
95  if ((sfont->type != SFNT_TYPE_TTC && sfont->type != SFNT_TYPE_POSTSCRIPT) ||
96  sfnt_read_table_directory(sfont, offset) < 0 ||
97  (offset = sfnt_find_table_pos(sfont, "CFF ")) == 0) {
98  sfnt_close(sfont);
99  if (fp)
100  DPXFCLOSE(fp);
101  return -1;
102  }
103 
104  cffont = cff_open(sfont->stream, offset, 0);
105  if (!cffont) {
106  WARN("Could not read CFF font data: %s", ident);
107  sfnt_close(sfont);
108  if (fp)
109  DPXFCLOSE(fp);
110  return -1;
111  }
112 
113  if (cffont->flag & FONTTYPE_CIDFONT) {
114  cff_close (cffont);
115  sfnt_close(sfont);
116  if (fp)
117  DPXFCLOSE(fp);
118  return -1;
119  }
120 
121  fontname = cff_get_name(cffont);
122  if (!fontname) {
123  WARN("No valid FontName found in CFF/OpenType font: %s", ident);
124  cff_close (cffont);
125  sfnt_close(sfont);
126  if (fp)
127  DPXFCLOSE(fp);
128  return -1;
129  }
131 
132  cff_close(cffont);
133 
134  if (!embedding) {
135  WARN("Ignoring no-embed option for Type1C font: %s", ident);
136  embedding = 1;
137  font->flags &= ~~PDF_FONT_FLAG_NOEMBED;
138  }
139  /*
140  * Font like AdobePiStd does not have meaningful built-in encoding.
141  * Some software generate CFF/OpenType font with incorrect encoding.
142  */
143  if (encoding_id < 0) {
144  WARN("Built-in encoding used for CFF/OpenType font.");
145  WARN("CFF font in OpenType font sometimes have strange built-in encoding.");
146  WARN("If you find text is not encoded properly in the generated PDF file,");
147  WARN("please specify appropriate \".enc\" file in your fontmap.");
148  }
149  font->subtype = PDF_FONT_FONTTYPE_TYPE1C;
150 
152  /*
153  * Create font descriptor from OpenType tables.
154  * We can also use CFF TOP DICT/Private DICT for this.
155  */
156  tmp = tt_get_fontdesc(sfont, &embedding, -1, 1, fontname);
157  if (!tmp) {
158  ERROR("Could not obtain neccesary font info from OpenType table.");
159  return -1;
160  }
161  pdf_merge_dict (descriptor, tmp); /* copy */
162  pdf_release_obj(tmp);
163  if (!embedding) { /* tt_get_fontdesc may have changed this */
164  WARN("Font embedding disallowed for \"%s\"", ident);
165  sfnt_close(sfont);
166  if (fp)
167  DPXFCLOSE(fp);
168  return -1;
169  }
170 
171  sfnt_close(sfont);
172  if (fp)
173  DPXFCLOSE(fp);
174 
175  return 0;
176 }
177 
178 static void
179 add_SimpleMetrics (pdf_font *font, cff_font *cffont, double *widths, card16 num_glyphs)
180 {
181  pdf_obj *fontdict;
182  int code, firstchar, lastchar;
183  char *usedchars;
184  pdf_obj *array;
185  double scaling = 1.0;
186 
188  usedchars = font->usedchars;
189 
190  /* The widhts array in the font dictionary must be given relative
191  * to the default scaling of 1000:1, not relative to the scaling
192  * given by the font matrix.
193  */
194  if (cff_dict_known(cffont->topdict, "FontMatrix")) {
195  scaling = 1000.0 * cff_dict_get(cffont->topdict, "FontMatrix", 0);
196  } else {
197  scaling = 1.0;
198  }
199 
200  array = pdf_new_array();
201  if (num_glyphs <= 1) {
202  /* This should be error. */
203  firstchar = lastchar = 0;
205  } else {
206  firstchar = 255; lastchar = 0;
207  for (code = 0; code < 256; code++) {
208  if (usedchars[code]) {
209  if (code < firstchar) firstchar = code;
210  if (code > lastchar) lastchar = code;
211  widths[code] *= scaling;
212  }
213  }
214  if (firstchar > lastchar) {
215  ERROR("No glyphs used at all!");
216  return;
217  }
218  pdf_check_tfm_widths(font->ident, widths, firstchar, lastchar, usedchars);
219 
220  for (code = firstchar; code <= lastchar; code++) {
221  if (usedchars[code]) {
222  pdf_add_array(array, pdf_new_number(ROUND(widths[code], 0.1)));
223  } else {
225  }
226  }
227  }
228 
229  if (pdf_array_length(array) > 0) {
231  }
233 
234  pdf_add_dict(fontdict, pdf_new_name("FirstChar"), pdf_new_number(firstchar));
236 
237  return;
238 }
239 
240 int
242 {
244  pdf_obj *pdfcharset; /* Actually string object */
245  char *usedchars;
246  char *fontname, *uniqueTag, *ident, *fullname;
247  FILE *fp = NULL;
248  int encoding_id;
249  pdf_obj *fontfile, *stream_dict;
250  char **enc_vec;
251  sfnt *sfont;
252  cff_font *cffont;
253  cff_index *charstrings, *topdict, *cs_idx;
256  int topdict_offset, private_size;
257  int charstring_len, max_len;
258  int size, offset = 0;
259  int stream_data_len = 0;
260  card8 *stream_data_ptr, *data;
261  card16 num_glyphs, cs_count, code;
262  cs_ginfo ginfo;
263  double nominal_width, default_width, notdef_width;
264  double widths[256];
265 
266  ASSERT(font);
267 
268  if (!font->reference)
269  return 0;
270 
272  ERROR("Only embedded font supported for CFF/OpenType font.");
273  }
274 
275  usedchars = font->usedchars;
277  ident = font->filename;
278  uniqueTag = pdf_font_get_uniqueTag (font);
279 
280  ASSERT(usedchars);
281  ASSERT(fontname);
282  ASSERT(ident);
283 
286  encoding_id = font->encoding_id;
287 
289  if (!fp) {
290  ERROR("Could not open OpenType font: %s", ident);
291  }
292 
293  sfont = sfnt_open(fp);
294  if (!sfont) {
295  ERROR("Could not open OpenType font: %s", ident);
296  }
297  if (sfnt_read_table_directory(sfont, 0) < 0) {
298  ERROR("Could not read OpenType table directory: %s", ident);
299  }
300  if (sfont->type != SFNT_TYPE_POSTSCRIPT ||
301  (offset = sfnt_find_table_pos(sfont, "CFF ")) == 0) {
302  ERROR("Not a CFF/OpenType font (or variable font?) (11)?");
303  }
304 
305  cffont = cff_open(fp, offset, 0);
306  if (!cffont) {
307  ERROR("Could not open CFF font.");
308  }
309  if (cffont->flag & FONTTYPE_CIDFONT) {
310  ERROR("This is CIDFont...");
311  }
312 
313  fullname = NEW(strlen(fontname) + 8, char);
314  sprintf(fullname, "%6s+%s", uniqueTag, fontname);
315 
316  /* Offsets from DICTs */
317  cff_read_charsets(cffont);
318  if (encoding_id < 0)
319  cff_read_encoding(cffont);
320  cff_read_private(cffont);
321  cff_read_subrs (cffont);
322 
323  /* FIXME */
324  cffont->_string = cff_new_index(0);
325 
326  /* New Charsets data */
327  charset = NEW(1, cff_charsets);
328  charset->format = 0;
329  charset->num_entries = 0;
330  charset->data.glyphs = NEW(256, s_SID);
331 
332  /*
333  * Encoding related things.
334  */
335  enc_vec = NULL;
336  if (encoding_id >= 0) {
337  enc_vec = pdf_encoding_get_encoding(encoding_id);
338  } else {
340 
341  /*
342  * Create enc_vec and ToUnicode CMap for built-in encoding.
343  */
344  enc_vec = NEW(256, char *);
345  for (code = 0; code < 256; code++) {
346  if (usedchars[code]) {
347  card16 gid;
348 
349  gid = cff_encoding_lookup(cffont, code);
350  enc_vec[code] = cff_get_string(cffont, cff_charsets_lookup_inverse(cffont, gid));
351  } else {
352  enc_vec[code] = NULL;
353  }
354  }
355  if (!pdf_lookup_dict(fontdict, "ToUnicode")) {
356  tounicode = pdf_create_ToUnicode_CMap(fullname, enc_vec, usedchars);
357  if (tounicode) {
359  pdf_new_name("ToUnicode"),
362  }
363  }
364  }
365 
366  /*
367  * New Encoding data:
368  *
369  * We should not use format 0 here.
370  * The number of encoded glyphs (num_entries) is limited to 255 in format 0,
371  * and hence it causes problem for encodings that uses full 256 code-points.
372  * As we always sort glyphs by encoding, we can avoid this problem simply
373  * by using format 1; Using full range result in a single range, 0 255.
374  *
375  * Creating actual encoding date is delayed to eliminate character codes to
376  * be mapped to .notdef and to handle multiply-encoded glyphs.
377  */
378  encoding = NEW(1, cff_encoding);
379  encoding->format = 1;
380  encoding->num_entries = 0;
381  encoding->data.range1 = NEW(255, cff_range1);
382  encoding->num_supps = 0;
383  encoding->supp = NEW(255, cff_map);
384 
385  /*
386  * Charastrings.
387  */
388  offset = cff_dict_get(cffont->topdict, "CharStrings", 0);
389  cff_seek_set(cffont, offset);
390  cs_idx = cff_get_index_header(cffont);
391 
392  /* Offset is now absolute offset ... fixme */
393  offset = cff_tell(cffont);
394  cs_count = cs_idx->count;
395  if (cs_count < 2) {
396  ERROR("No valid charstring data found.");
397  }
398 
399  /* New CharStrings INDEX */
400  charstrings = cff_new_index(257); /* 256 + 1 for ".notdef" glyph */
401  max_len = 2 * CS_STR_LEN_MAX;
402  charstrings->data = NEW(max_len, card8);
403  charstring_len = 0;
404 
405  /*
406  * Information from OpenType table is rough estimate. Replace with accurate value.
407  */
408  if (cffont->private[0] &&
409  cff_dict_known(cffont->private[0], "StdVW")) {
410  double stemv;
411 
412  stemv = cff_dict_get(cffont->private[0], "StdVW", 0);
414  }
415 
416  /*
417  * Widths
418  */
419  if (cffont->private[0] &&
420  cff_dict_known(cffont->private[0], "defaultWidthX")) {
421  default_width = (double) cff_dict_get(cffont->private[0], "defaultWidthX", 0);
422  } else {
423  default_width = CFF_DEFAULTWIDTHX_DEFAULT;
424  }
425  if (cffont->private[0] &&
426  cff_dict_known(cffont->private[0], "nominalWidthX")) {
427  nominal_width = (double) cff_dict_get(cffont->private[0], "nominalWidthX", 0);
428  } else {
429  nominal_width = CFF_NOMINALWIDTHX_DEFAULT;
430  }
431 
433 
434  /* First we add .notdef glyph.
435  * All Type 1 font requires .notdef glyph to be present.
436  */
437  if (dpx_conf.verbose_level > 2) {
438  MESG("[glyphs:/.notdef");
439  }
440  size = cs_idx->offset[1] - cs_idx->offset[0];
441  if (size > CS_STR_LEN_MAX) {
442  ERROR("Charstring too long: gid=%u, %ld bytes", 0, size);
443  }
444  charstrings->offset[0] = charstring_len + 1;
445  cff_seek(cffont, offset + cs_idx->offset[0] - 1);
446  cff_read_data(data, size, cffont);
447  charstring_len += cs_copy_charstring(charstrings->data + charstring_len,
448  max_len - charstring_len,
449  data, size,
450  cffont->gsubr, cffont->subrs[0],
451  default_width, nominal_width, &ginfo);
452  notdef_width = ginfo.wx;
453 
454  /*
455  * Subset font
456  */
457  num_glyphs = 1;
458  pdfcharset = pdf_new_stream(0);
459  for (code = 0; code < 256; code++) {
460  card16 gid, j;
461  s_SID sid_orig, sid;
462 
463  widths[code] = notdef_width;
464 
465  if (!usedchars[code] || !enc_vec[code] ||
466  !strcmp(enc_vec[code], ".notdef"))
467  continue;
468 
469  /*
470  * FIXME:
471  * cff_get_sid() obtain SID from original String INDEX.
472  * It should be cff_string_get_sid(string, ...).
473  * cff_add_string(cff, ...) -> cff_string_add(string, ...).
474  */
475  sid_orig = cff_get_sid (cffont, enc_vec[code]);
476  sid = sid_orig < CFF_STDSTR_MAX ?
477  sid_orig : cff_add_string(cffont, enc_vec[code], 0);
478  /*
479  * We use "unique = 0" because duplicate strings are impossible
480  * at this stage unless the original font already had duplicates.
481  */
482 
483  /*
484  * Check if multiply-encoded glyph.
485  */
486  for (j = 0; j < charset->num_entries; j++) {
487  if (sid == charset->data.glyphs[j]) {
488  /* Already have this glyph. */
489  encoding->supp[encoding->num_supps].code = code;
490  encoding->supp[encoding->num_supps].glyph = sid;
491  usedchars[code] = 0; /* Used but multiply-encoded. */
492  encoding->num_supps += 1;
493  break;
494  }
495  }
496  if (j < charset->num_entries) {
497  continue; /* Prevent duplication. */
498  }
499 
500  /* This is new encoding entry. */
501  gid = cff_charsets_lookup(cffont, sid_orig); /* FIXME */
502  if (gid == 0) {
503  WARN("Glyph \"%s\" missing in font \"%s\".", enc_vec[code], fontname);
504  WARN("Maybe incorrect encoding specified.");
505  usedchars[code] = 0; /* Set unused for writing correct encoding */
506  continue;
507  }
508  pdf_add_stream(pdfcharset, "/", 1);
509  pdf_add_stream(pdfcharset, enc_vec[code], strlen(enc_vec[code]));
510 
511  if (dpx_conf.verbose_level > 2) {
512  MESG("/%s", enc_vec[code]);
513  }
514 
515  size = cs_idx->offset[gid+1] - cs_idx->offset[gid];
516  if (size > CS_STR_LEN_MAX) {
517  ERROR("Charstring too long: gid=%u, %ld bytes", gid, size);
518  }
519 
520  if (charstring_len + CS_STR_LEN_MAX >= max_len) {
521  max_len = charstring_len + 2 * CS_STR_LEN_MAX;
522  charstrings->data = RENEW(charstrings->data, max_len, card8);
523  }
524  charstrings->offset[num_glyphs] = charstring_len + 1;
525  cff_seek(cffont, offset + cs_idx->offset[gid] - 1);
526  cff_read_data(data, size, cffont);
527  charstring_len += cs_copy_charstring(charstrings->data + charstring_len,
528  max_len - charstring_len,
529  data, size,
530  cffont->gsubr, cffont->subrs[0],
531  default_width, nominal_width, &ginfo);
532  widths[code] = ginfo.wx;
533  charset->data.glyphs[charset->num_entries] = sid;
534  charset->num_entries += 1;
535  num_glyphs++;
536  }
537  if (dpx_conf.verbose_level > 2) {
538  MESG("]");
539  }
540  RELEASE(data);
541 
542  /*
543  * Now we create encoding data.
544  */
545  if (encoding->num_supps > 0)
546  encoding->format |= 0x80; /* Have supplemantary data. */
547  else {
548  RELEASE(encoding->supp); /* FIXME */
549  }
550  for (code = 0; code < 256; code++) {
551  if (!usedchars[code] ||
552  !enc_vec[code] || !strcmp(enc_vec[code], ".notdef"))
553  continue;
554  encoding->data.range1[encoding->num_entries].first = code;
555  encoding->data.range1[encoding->num_entries].n_left = 0;
556  code++;
557  while (code < 256 && usedchars[code] &&
558  enc_vec[code] && strcmp(enc_vec[code], ".notdef")) {
559  encoding->data.range1[encoding->num_entries].n_left += 1;
560  code++;
561  }
562  encoding->num_entries += 1;
563  /* The above while() loop stopped at unused char or code == 256. */
564  }
565 
566  /* cleanup */
567  if (encoding_id < 0 && enc_vec) {
568  for (code = 0; code < 256; code++) {
569  if (enc_vec[code]) {
570  RELEASE(enc_vec[code]);
571  }
572  }
573  RELEASE(enc_vec);
574  }
575 
576  cff_release_index(cs_idx);
577 
578  charstrings->offset[num_glyphs] = charstring_len + 1;
579  charstrings->count = num_glyphs;
580  charstring_len = cff_index_size(charstrings);
581  cffont->num_glyphs = num_glyphs;
582 
583  /*
584  * Discard old one, set new data.
585  */
586  if (cffont->charsets)
588  cffont->charsets = charset;
589  if (cffont->encoding)
591  cffont->encoding = encoding;
592  /*
593  * We don't use subroutines at all.
594  */
595  if (cffont->gsubr)
596  cff_release_index(cffont->gsubr);
597  cffont->gsubr = cff_new_index(0);
598  if (cffont->subrs[0])
599  cff_release_index(cffont->subrs[0]);
600  cffont->subrs[0] = NULL;
601 
602  /*
603  * Flag must be reset since cff_pack_encoding(charset) does not write
604  * encoding(charset) if HAVE_STANDARD_ENCODING(CHARSET) is set. We are
605  * re-encoding font.
606  */
607  cffont->flag = FONTTYPE_FONT;
608 
609  /*
610  * FIXME:
611  * Update String INDEX to delete unused strings.
612  */
613  cff_dict_update(cffont->topdict, cffont);
614  if (cffont->private[0])
615  cff_dict_update(cffont->private[0], cffont);
616  cff_update_string(cffont);
617 
618  /*
619  * Calculate sizes of Top DICT and Private DICT.
620  * All offset values in DICT are set to long (32-bit) integer
621  * in cff_dict_pack(), those values are updated later.
622  */
623  topdict = cff_new_index(1);
624 
625  cff_dict_remove(cffont->topdict, "UniqueID");
626  cff_dict_remove(cffont->topdict, "XUID");
627 
628  /*
629  * Force existence of Encoding.
630  */
631  if (!cff_dict_known(cffont->topdict, "Encoding"))
632  cff_dict_add(cffont->topdict, "Encoding", 1);
633  topdict->offset[1] = cff_dict_pack(cffont->topdict,
634  (card8 *) work_buffer,
635  WORK_BUFFER_SIZE) + 1;
636  private_size = 0;
637  if (cffont->private[0]) {
638  cff_dict_remove(cffont->private[0], "Subrs"); /* no Subrs */
639  private_size = cff_dict_pack(cffont->private[0],
641  }
642 
643  /*
644  * Estimate total size of fontfile.
645  */
646  stream_data_len = 4; /* header size */
647 
648  stream_data_len += cff_set_name(cffont, fullname);
649  RELEASE(fullname);
650 
651  stream_data_len += cff_index_size(topdict);
652  stream_data_len += cff_index_size(cffont->string);
653  stream_data_len += cff_index_size(cffont->gsubr);
654 
655  /* We are using format 1 for Encoding and format 0 for charset.
656  * TODO: Should implement cff_xxx_size().
657  */
658  stream_data_len += 2 + (encoding->num_entries)*2 + 1 + (encoding->num_supps)*3;
659  stream_data_len += 1 + (charset->num_entries)*2;
660  stream_data_len += charstring_len;
661  stream_data_len += private_size;
662 
663  /*
664  * Now we create FontFile data.
665  */
666  stream_data_ptr = NEW(stream_data_len, card8);
667 
668  /*
669  * Data Layout order as described in CFF spec., sec 2 "Data Layout".
670  */
671  offset = 0;
672  /* Header */
673  offset += cff_put_header(cffont, stream_data_ptr + offset, stream_data_len - offset);
674  /* Name */
675  offset += cff_pack_index(cffont->name, stream_data_ptr + offset, stream_data_len - offset);
676  /* Top DICT */
677  topdict_offset = offset;
678  offset += cff_index_size(topdict);
679  /* Strings */
680  offset += cff_pack_index(cffont->string,
681  stream_data_ptr + offset, stream_data_len - offset);
682  /* Global Subrs */
683  offset += cff_pack_index(cffont->gsubr,
684  stream_data_ptr + offset, stream_data_len - offset);
685  /* Encoding */
686  cff_dict_set(cffont->topdict, "Encoding", 0, offset);
687  offset += cff_pack_encoding(cffont,
688  stream_data_ptr + offset, stream_data_len - offset);
689  /* charset */
690  cff_dict_set(cffont->topdict, "charset", 0, offset);
691  offset += cff_pack_charsets(cffont,
692  stream_data_ptr + offset, stream_data_len - offset);
693  /* CharStrings */
694  cff_dict_set(cffont->topdict, "CharStrings", 0, offset);
695  offset += cff_pack_index(charstrings,
696  stream_data_ptr + offset, charstring_len);
697  cff_release_index(charstrings);
698  /* Private */
699  cff_dict_set(cffont->topdict, "Private", 1, offset);
700  if (cffont->private[0] && private_size > 0)
701  private_size = cff_dict_pack(cffont->private[0],
702  stream_data_ptr + offset, private_size);
703  cff_dict_set(cffont->topdict, "Private", 0, private_size);
704  offset += private_size;
705 
706  /* Finally Top DICT */
707  topdict->data = NEW(topdict->offset[1] - 1, card8);
708  cff_dict_pack (cffont->topdict, topdict->data, topdict->offset[1] - 1);
709  cff_pack_index(topdict,
710  stream_data_ptr + topdict_offset, cff_index_size(topdict));
711  cff_release_index(topdict);
712 
713  /* Copyright and Trademark Notice ommited. */
714 
715  /* Handle Widths in fontdict. */
716  add_SimpleMetrics(font, cffont, widths, num_glyphs);
717 
718  /* Close font */
719  cff_close (cffont);
720  sfnt_close(sfont);
721 
722  if (fp)
723  DPXFCLOSE(fp);
724 
725  if (dpx_conf.verbose_level > 1) {
726  MESG("[%u/%u glyphs][%ld bytes]", num_glyphs, cs_count, offset);
727  }
728 
729  /*
730  * CharSet
731  */
732  if (pdf_check_version(2, 0) < 0) {
734  pdf_new_name("CharSet"),
736  pdf_stream_length(pdfcharset)));
737  }
738  pdf_release_obj(pdfcharset);
739  /*
740  * Write PDF FontFile data.
741  */
743  stream_dict = pdf_stream_dict(fontfile);
745  pdf_new_name("FontFile3"), pdf_ref_obj (fontfile));
746  pdf_add_dict(stream_dict,
747  pdf_new_name("Subtype"), pdf_new_name("Type1C"));
748  pdf_add_stream (fontfile, (void *) stream_data_ptr, offset);
750 
751  RELEASE(stream_data_ptr);
752 
753  return 0;
754 }
const char * fontname
Definition: afm2pl.c:186
int code
Definition: aftopl.c:52
int strcmp()
Definition: coll.cpp:143
struct rect data
Definition: dvipdfm.c:64
#define NULL
Definition: ftobjs.h:61
FT_UInt sid
Definition: cffcmap.c:138
#define NEW
Definition: gdkanji.c:77
static int cs_count
Definition: writet1.c:215
void cff_release_encoding(cff_encoding *encoding)
Definition: cff.c:814
int cff_pack_charsets(cff_font *cff, card8 *dest, int destlen)
Definition: cff.c:927
card16 cff_charsets_lookup_inverse(cff_font *cff, card16 gid)
Definition: cff.c:1115
int cff_index_size(cff_index *idx)
Definition: cff.c:429
char * cff_get_string(cff_font *cff, s_SID id)
Definition: cff.c:484
int cff_read_encoding(cff_font *cff)
Definition: cff.c:625
int cff_read_subrs(cff_font *cff)
Definition: cff.c:1356
void cff_release_charsets(cff_charsets *charset)
Definition: cff.c:1172
int cff_set_name(cff_font *cff, char *name)
Definition: cff.c:250
int cff_pack_encoding(cff_font *cff, card8 *dest, int destlen)
Definition: cff.c:703
int cff_get_sid(cff_font *cff, const char *str)
Definition: cff.c:508
cff_font * cff_open(FILE *stream, int offset, int n)
Definition: cff.c:58
cff_index * cff_get_index_header(cff_font *cff)
Definition: cff.c:292
card16 cff_encoding_lookup(cff_font *cff, card8 code)
Definition: cff.c:757
int cff_put_header(cff_font *cff, card8 *dest, int destlen)
Definition: cff.c:273
void cff_release_index(cff_index *idx)
Definition: cff.c:470
int cff_pack_index(cff_index *idx, card8 *dest, int destlen)
Definition: cff.c:369
void cff_update_string(cff_font *cff)
Definition: cff.c:567
s_SID cff_add_string(cff_font *cff, const char *str, int unique)
Definition: cff.c:578
int cff_read_charsets(cff_font *cff)
Definition: cff.c:837
void cff_close(cff_font *cff)
Definition: cff.c:192
card16 cff_charsets_lookup(cff_font *cff, card16 cid)
Definition: cff.c:1055
char * cff_get_name(cff_font *cff)
Definition: cff.c:234
int cff_read_private(cff_font *cff)
Definition: cff.c:1438
cff_index * cff_new_index(card16 count)
Definition: cff.c:451
#define cff_read_data(d, l, c)
Definition: cff.h:85
#define cff_seek_set(c, p)
Definition: cff.h:84
#define cff_seek(c, p)
Definition: cff.h:87
#define cff_tell(c)
Definition: cff.h:86
#define FONTTYPE_CIDFONT
Definition: cff.h:28
#define FONTTYPE_FONT
Definition: cff.h:29
void cff_dict_set(cff_dict *dict, const char *key, int idx, double value)
Definition: cff_dict.c:680
void cff_dict_update(cff_dict *dict, cff_font *cff)
Definition: cff_dict.c:700
double cff_dict_get(cff_dict *dict, const char *key, int idx)
Definition: cff_dict.c:657
int cff_dict_pack(cff_dict *dict, card8 *dest, int destlen)
Definition: cff_dict.c:570
int cff_dict_known(cff_dict *dict, const char *key)
Definition: cff_dict.c:644
void cff_dict_remove(cff_dict *dict, const char *key)
Definition: cff_dict.c:631
void cff_dict_add(cff_dict *dict, const char *key, int count)
Definition: cff_dict.c:590
#define CFF_NOMINALWIDTHX_DEFAULT
Definition: cff_dict.h:27
#define CFF_DEFAULTWIDTHX_DEFAULT
Definition: cff_dict.h:28
#define CS_STR_LEN_MAX
Definition: cff_limits.h:38
#define CFF_STDSTR_MAX
Definition: cff_limits.h:34
unsigned char card8
Definition: cff_types.h:42
unsigned short s_SID
Definition: cff_types.h:47
unsigned short card16
Definition: cff_types.h:43
const char * fontdict
Definition: cid_basefont.h:47
const char * descriptor
Definition: cid_basefont.h:48
int cs_copy_charstring(card8 *dst, int dstlen, card8 *src, int srclen, cff_index *gsubr, cff_index *subr, double default_width, double nominal_width, cs_ginfo *ginfo)
Definition: cs_type2.c:783
struct _dpx_conf dpx_conf
Definition: dpxconf.c:33
#define DPXFCLOSE(f)
Definition: dpxfile.h:57
#define DPXFOPEN(n, t)
Definition: dpxfile.h:56
@ DPX_RES_TYPE_OTFONT
Definition: dpxfile.h:33
@ DPX_RES_TYPE_TTFONT
Definition: dpxfile.h:32
void WARN(const char *fmt,...)
Definition: error.c:62
void MESG(const char *fmt,...)
Definition: error.c:49
#define ASSERT(e)
Definition: error.h:48
#define RENEW(p, n, type)
Definition: mem.h:38
#define RELEASE(p)
Definition: mem.h:39
char work_buffer[1024]
Definition: mfileio.c:171
#define WORK_BUFFER_SIZE
Definition: mfileio.h:68
pdf_obj * pdf_create_ToUnicode_CMap(const char *enc_name, char **enc_vec, const char *is_used)
Definition: pdfencoding.c:641
char ** pdf_encoding_get_encoding(int enc_id)
Definition: pdfencoding.c:526
int pdf_check_tfm_widths(const char *ident, double *widths, int firstchar, int lastchar, const char *usedchars)
Definition: pdffont.c:1058
pdf_obj * pdf_font_get_descriptor(pdf_font *font)
Definition: pdffont.c:1019
char * pdf_font_get_uniqueTag(pdf_font *font)
Definition: pdffont.c:1034
pdf_obj * pdf_font_get_resource(pdf_font *font)
Definition: pdffont.c:992
#define PDF_FONT_FLAG_NOEMBED
Definition: pdffont.h:41
#define PDF_FONT_FONTTYPE_TYPE1C
Definition: pdffont.h:31
pdf_obj * pdf_new_array(void)
Definition: pdfobj.c:1421
pdf_obj * pdf_new_name(const char *name)
Definition: pdfobj.c:1330
int pdf_check_version(int major, int minor)
Definition: pdfobj.c:416
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
void pdf_release_obj(pdf_obj *object)
Definition: pdfobj.c:3217
void pdf_merge_dict(pdf_obj *dict1, pdf_obj *dict2)
Definition: pdfobj.c:1763
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_new_string(const void *str, unsigned length)
Definition: pdfobj.c:1131
int pdf_stream_length(pdf_obj *stream)
Definition: pdfobj.c:2398
void pdf_add_array(pdf_obj *array, pdf_obj *object)
Definition: pdfobj.c:1511
unsigned pdf_array_length(pdf_obj *array)
Definition: pdfobj.c:1479
const void * pdf_stream_dataptr(pdf_obj *stream)
Definition: pdfobj.c:2386
int pdf_add_dict(pdf_obj *dict, pdf_obj *key, pdf_obj *value)
Definition: pdfobj.c:1680
#define STREAM_COMPRESS
Definition: pdfobj.h:45
int sfnt_read_table_directory(sfnt *sfont, SFNT_ULONG offset)
Definition: sfnt.c:356
void sfnt_close(sfnt *sfont)
Definition: sfnt.c:164
SFNT_ULONG sfnt_find_table_pos(sfnt *sfont, const char *tag)
Definition: sfnt.c:320
sfnt * sfnt_open(FILE *fp)
Definition: sfnt.c:52
#define SFNT_TYPE_POSTSCRIPT
Definition: sfnt.h:71
#define SFNT_TYPE_TTC
Definition: sfnt.h:72
SFNT_ULONG ttc_read_offset(sfnt *sfont, SFNT_ULONG ttc_idx)
Definition: tt_aux.c:38
pdf_obj * tt_get_fontdesc(sfnt *sfont, int *embed, int stemv, int type, const char *fontname)
Definition: tt_aux.c:130
int pdf_font_load_type1c(pdf_font *font)
Definition: type1c.c:241
int pdf_font_open_type1c(pdf_font *font, const char *ident, int index, int encoding_id, int embedding)
Definition: type1c.c:66
#define ERROR(string)
Definition: error.h:36
#define sprintf
Definition: snprintf.c:44
unsigned long ULONG
Definition: pdfgen.h:158
#define fp
logical lastchar
Definition: pmxab.c:132
#define ROUND(x)
Definition: pnmnlfilt.c:322
static int size
Definition: ppmlabel.c:24
static int offset
Definition: ppmtogif.c:642
charset
Definition: charset.h:51
static void add_SimpleMetrics(pdf_font *font, cff_font *cffont, double *widths, card16 num_glyphs)
Definition: type1c.c:179
int verbose_level
Definition: dpxconf.h:35
Definition: cff.h:46
card16 num_glyphs
Definition: cff.h:66
cff_index * _string
Definition: cff.h:72
cff_charsets * charsets
Definition: cff.h:56
cff_dict ** private
Definition: cff.h:60
cff_dict * topdict
Definition: cff.h:52
cff_index * gsubr
Definition: cff.h:54
cff_index ** subrs
Definition: cff.h:61
cff_index * string
Definition: cff.h:53
cff_encoding * encoding
Definition: cff.h:55
cff_index * name
Definition: cff.h:51
int flag
Definition: cff.h:79
card16 count
Definition: cff_types.h:50
l_offset * offset
Definition: cff_types.h:52
card8 * data
Definition: cff_types.h:53
Definition: inftrees.h:24
Definition: pbmfont.h:11
char * filename
Definition: gf2pbm.c:114
char * fontname
Definition: gf2pbm.c:110
ubyte flags
Definition: gf2pbm.c:117
Definition: mendex.h:20
Definition: pdfobj.c:63
Definition: sfnt.h:76
int type
Definition: sfnt.h:77
FILE * stream
Definition: sfnt.h:79
#define FILE
Definition: t1stdio.h:34
int j
Definition: t4ht.c:1589
*job_name strlen((char *) job_name) - 4)
FILE * fontfile
Definition: ttf2afm.c:100
char ident[]
Definition: ttf2pk.c:40
#define encoding
Definition: xmlparse.c:588