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)  

writefont.c
Go to the documentation of this file.
1 /* writefont.c: font descriptors and writing Type 1 fonts.
2 Copyright 1996-2021 Han The Thanh, <thanh@pdftex.org>
3 
4 This file is part of pdfTeX.
5 
6 pdfTeX 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 pdfTeX 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 along
17 with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "ptexlib.h"
21 
22 /**********************************************************************/
23 
24 struct avl_table *fo_tree = NULL; /* tree of font dictionaries */
25 struct avl_table *fd_tree = NULL; /* tree of font descriptor objects */
26 
27 static int comp_fo_entry(const void *pa, const void *pb, void *p)
28 {
29  return strcmp(((const fo_entry *) pa)->fm->tfm_name,
30  ((const fo_entry *) pb)->fm->tfm_name);
31 }
32 
33 static int comp_fd_entry(const void *pa, const void *pb, void *p)
34 {
35  int i;
36  const fd_entry *p1 = (const fd_entry *) pa, *p2 = (const fd_entry *) pb;
37  assert(p1->fm != NULL && is_fontfile(p1->fm) &&
38  p2->fm != NULL && is_fontfile(p2->fm));
39  if ((i = strcmp(p1->fm->ff_name, p2->fm->ff_name)) != 0)
40  return i;
41  cmp_return(p1->fm->slant, p2->fm->slant);
42  cmp_return(p1->fm->extend, p2->fm->extend);
43  return 0;
44 }
45 
46 /**********************************************************************/
47 /* initialize data structure for /Type /Font */
48 
49 static fo_entry *new_fo_entry(void)
50 {
51  fo_entry *fo;
52  fo = xtalloc(1, fo_entry);
53  fo->fo_objnum = 0;
54  fo->tex_font = 0;
55  fo->fm = NULL;
56  fo->fd = NULL;
57  fo->fe = NULL;
58  fo->cw = NULL;
59  fo->first_char = 1;
60  fo->last_char = 0;
61  fo->tounicode_objnum = 0;
62  return fo;
63 }
64 
65 /* initialize data structure for /Type /FontDescriptor */
66 
68 {
69  fd_entry *fd;
70  int i;
71  fd = xtalloc(1, fd_entry);
72  fd->fd_objnum = 0;
73  fd->fontname = NULL;
74  fd->subset_tag = NULL;
75  fd->ff_found = false;
76  fd->ff_objnum = 0;
77  fd->fn_objnum = 0;
78  fd->all_glyphs = false;
79  fd->write_ttf_glyph_names = false;
80  for (i = 0; i < FONT_KEYS_NUM; i++) {
81  fd->font_dim[i].val = 0;
82  fd->font_dim[i].set = false;
83  }
84  fd->fe = NULL;
86  fd->fm = NULL;
87  fd->tx_tree = NULL;
88  fd->gl_tree = NULL;
89  return fd;
90 }
91 
92 /* initialize data structure for /Widths array object */
93 
94 static cw_entry *new_cw_entry(void)
95 {
96  cw_entry *cw;
97  cw = xtalloc(1, cw_entry);
98  cw->cw_objnum = 0;
99  cw->width = NULL;
100  return cw;
101 }
102 
103 /**********************************************************************/
104 /*
105  * Only fallback values of font metrics are taken from the TFM info
106  * of f by preset_fontmetrics(). During reading of the font file,
107  * these values are replaced by metrics from the font, if available.
108  */
109 
110 static void preset_fontmetrics(fd_entry * fd, internalfontnumber f)
111 {
112  int i;
114  dividescaled(-atan(getslant(f) / 65536.0) * (180 / M_PI),
115  pdffontsize[f], 3);
116  fd->font_dim[ASCENT_CODE].val =
117  dividescaled(getcharheight(f, 'h'), pdffontsize[f], 3);
119  dividescaled(getcharheight(f, 'H'), pdffontsize[f], 3);
120  i = -dividescaled(getchardepth(f, 'y'), pdffontsize[f], 3);
121  fd->font_dim[DESCENT_CODE].val = i < 0 ? i : 0;
122  fd->font_dim[STEMV_CODE].val =
123  dividescaled(getcharwidth(f, '.') / 3, pdffontsize[f], 3);
124  fd->font_dim[XHEIGHT_CODE].val =
125  dividescaled(getxheight(f), pdffontsize[f], 3);
126  fd->font_dim[FONTBBOX1_CODE].val = 0;
129  dividescaled(getquad(f), pdffontsize[f], 3);
133  for (i = 0; i < INT_KEYS_NUM; i++)
134  fd->font_dim[i].set = true;
135 }
136 
137 static void fix_fontmetrics(fd_entry * fd)
138 {
139  intparm *p = (intparm *) fd->font_dim;
140  if (!p[FONTBBOX1_CODE].set || !p[FONTBBOX2_CODE].set ||
141  !p[FONTBBOX3_CODE].set || !p[FONTBBOX4_CODE].set) {
142  pdftex_warn("font `%s' doesn't have a BoundingBox", fd->fm->ff_name);
143  return;
144  }
145  if (!p[ASCENT_CODE].set) {
146  p[ASCENT_CODE].val = p[FONTBBOX4_CODE].val;
147  p[ASCENT_CODE].set = true;
148  }
149  if (!p[DESCENT_CODE].set) {
150  p[DESCENT_CODE].val = p[FONTBBOX2_CODE].val;
151  p[DESCENT_CODE].set = true;
152  }
153  if (!p[CAPHEIGHT_CODE].set) {
154  p[CAPHEIGHT_CODE].val = p[FONTBBOX4_CODE].val;
155  p[CAPHEIGHT_CODE].set = true;
156  }
157 }
158 
159 static void write_fontmetrics(fd_entry * fd)
160 {
161  int i;
162  fix_fontmetrics(fd);
165  pdf_printf("/%s [%i %i %i %i]\n", font_key[FONTBBOX1_CODE].pdfname,
166  (int) fd->font_dim[FONTBBOX1_CODE].val,
167  (int) fd->font_dim[FONTBBOX2_CODE].val,
168  (int) fd->font_dim[FONTBBOX3_CODE].val,
169  (int) fd->font_dim[FONTBBOX4_CODE].val);
170  for (i = 0; i < GEN_KEY_NUM; i++)
171  if (fd->font_dim[i].set)
172  pdf_printf("/%s %i\n", font_key[i].pdfname, fd->font_dim[i].val);
173 }
174 
175 /**********************************************************************/
176 
177 static void preset_fontname(fo_entry * fo)
178 {
179  if (fo->fm->ps_name != NULL)
180  fo->fd->fontname = xstrdup(fo->fm->ps_name); /* just fallback */
181  else
182  fo->fd->fontname = xstrdup(fo->fm->tfm_name);
183 }
184 
185 static void write_fontname(fd_entry * fd, const char *key)
186 {
187  assert(fd->fontname != NULL);
188  pdf_puts("/");
189  if (key != NULL)
190  pdf_printf("%s /", key);
191  if (fd->subset_tag != NULL)
192  pdf_printf("%s+", fd->subset_tag);
193  pdf_printf("%s\n", fd->fontname);
194 }
195 
197 {
198  assert(fd->fn_objnum != 0);
199  pdfbeginobj(fd->fn_objnum, 1);
200  write_fontname(fd, NULL);
201  pdfendobj();
202 }
203 
204 /**********************************************************************/
205 
207 {
208  fd_entry fd;
209  fm_entry fm;
210  assert(s != NULL);
211  fm.ff_name = s;
212  fm.slant = slant;
213  fm.extend = extend;
214  fd.fm = &fm;
215  if (fd_tree == NULL) {
217  assert(fd_tree != NULL);
218  }
219  return (fd_entry *) avl_find(fd_tree, &fd);
220 }
221 
223 {
224  assert(fo != NULL);
225  assert(fo->fm != NULL);
226  assert(is_fontfile(fo->fm));
227  return lookup_fd_entry(fo->fm->ff_name, fo->fm->slant, fo->fm->extend);
228 }
229 
231 {
232  void **aa;
233  if (fd_tree == NULL) {
235  assert(fd_tree != NULL);
236  }
237  assert(fd != NULL && fd->fm != NULL && is_fontfile(fd->fm));
238  assert(lookup_fd_entry(fd->fm->ff_name, fd->fm->slant, fd->fm->extend) == NULL); /* font descriptor not yet registered */
239  aa = avl_probe(fd_tree, fd);
240  assert(aa != NULL);
241 }
242 
243 static void create_fontdescriptor(fo_entry * fo, internalfontnumber f)
244 {
245  assert(fo != NULL);
246  assert(fo->fm != NULL);
247  assert(fo->fd == NULL);
248  fo->fd = new_fd_entry();
249  preset_fontname(fo);
250  preset_fontmetrics(fo->fd, f);
251  fo->fd->fe = fo->fe; /* encoding needed by TrueType writing */
252  fo->fd->fm = fo->fm; /* map entry needed by TrueType writing */
254  assert(fo->fd->gl_tree != NULL);
255 }
256 
257 /**********************************************************************/
258 /*
259  * For all used characters of TeX font f, get corresponding glyph names
260  * from external reencoding (.enc) file and collect these in the glyph
261  * tree gl_tree of font descriptor fd referenced by font dictionary fo.
262  */
263 
264 static void mark_reenc_glyphs(fo_entry * fo, internalfontnumber f)
265 {
266  int i;
267  char **g;
268  void **aa;
269  assert(fo->fe != NULL);
270  if (is_subsetted(fo->fm)) {
271  assert(is_included(fo->fm));
272  /* mark glyphs from TeX (externally reencoded characters) */
273  g = fo->fe->glyph_names;
274  for (i = fo->first_char; i <= fo->last_char; i++) {
275  if (pdfcharmarked(f, i) && g[i] != notdef
276  && (char *) avl_find(fo->fd->gl_tree, g[i]) == NULL) {
277  aa = avl_probe(fo->fd->gl_tree, xstrdup(g[i]));
278  assert(aa != NULL);
279  }
280  }
281  }
282 }
283 
284 /*
285  * Function mark_chars() has 2 uses:
286  * 1. Mark characters as chars on TeX level.
287  * 2. Mark encoding pairs used by TeX to optimize encoding vector.
288  */
289 
290 static struct avl_table *mark_chars(fo_entry * fo, struct avl_table *tx_tree,
291  internalfontnumber f)
292 {
293  int i, *j;
294  void **aa;
295  if (tx_tree == NULL) {
297  assert(tx_tree != NULL);
298  }
299  for (i = fo->first_char; i <= fo->last_char; i++) {
300  if (pdfcharmarked(f, i) && (int *) avl_find(tx_tree, &i) == NULL) {
301  j = xtalloc(1, int);
302  *j = i;
303  aa = avl_probe(tx_tree, j);
304  assert(aa != NULL);
305  }
306  }
307  return tx_tree;
308 }
309 
310 /**********************************************************************/
311 
312 static void get_char_range(fo_entry * fo, internalfontnumber f)
313 {
314  int i;
315  assert(fo != NULL);
316  for (i = fontbc[f]; i <= fontec[f]; i++) /* search for first_char and last_char */
317  if (pdfcharmarked(f, i))
318  break;
319  fo->first_char = i;
320  for (i = fontec[f]; i >= fontbc[f]; i--)
321  if (pdfcharmarked(f, i))
322  break;
323  fo->last_char = i;
324  if ((fo->first_char > fo->last_char)
325  || !pdfcharmarked(f, fo->first_char)) { /* no character used from this font */
326  fo->last_char = 0;
327  fo->first_char = fo->last_char + 1;
328  }
329 }
330 
331 static void create_charwidth_array(fo_entry * fo, internalfontnumber f)
332 {
333  int i;
334  assert(fo != NULL);
335  assert(fo->cw == NULL);
336  fo->cw = new_cw_entry();
337  fo->cw->width = xtalloc(256, integer);
338  for (i = 0; i < fo->first_char; i++)
339  fo->cw->width[i] = 0;
340  for (i = fo->first_char; i <= fo->last_char; i++)
341  fo->cw->width[i] = dividescaled(getcharwidth(f, i), pdffontsize[f], 4);
342  for (i = fo->last_char + 1; i < 256; i++)
343  fo->cw->width[i] = 0;
344 }
345 
347 {
348  int i, j;
349  assert(fo->cw != NULL);
350  assert(fo->cw->cw_objnum == 0);
351  fo->cw->cw_objnum = pdfnewobjnum();
352  pdfbeginobj(fo->cw->cw_objnum, 1);
353  pdf_puts("[");
354  for (i = fo->first_char; i <= fo->last_char; i++) {
355  pdf_printf("%i", (int) fo->cw->width[i] / 10); /* see adv_char_width() in pdftex.web */
356  if ((j = fo->cw->width[i] % 10) != 0)
357  pdf_printf(".%i", j);
358  if (i != fo->last_char)
359  pdf_puts(" ");
360  }
361  pdf_puts("]\n");
362  pdfendobj();
363 }
364 
365 /**********************************************************************/
366 /*
367  * Remark: Font objects from embedded PDF files are never registered
368  * into fo_tree; they are individually written out.
369  */
370 
371 static fo_entry *lookup_fo_entry(char *s)
372 {
373  fo_entry fo;
374  fm_entry fm;
375  assert(s != NULL);
376  fm.tfm_name = s;
377  fo.fm = &fm;
378  if (fo_tree == NULL) {
380  assert(fo_tree != NULL);
381  }
382  return (fo_entry *) avl_find(fo_tree, &fo);
383 }
384 
385 static void register_fo_entry(fo_entry * fo)
386 {
387  void **aa;
388  if (fo_tree == NULL) {
390  assert(fo_tree != NULL);
391  }
392  assert(fo != NULL);
393  assert(fo->fm != NULL);
394  assert(fo->fm->tfm_name != NULL);
396  aa = avl_probe(fo_tree, fo);
397  assert(aa != NULL);
398 }
399 
400 /**********************************************************************/
401 
402 static void write_fontfile(fd_entry * fd)
403 {
404  assert(is_included(fd->fm));
405  if (is_type1(fd->fm))
406  writet1(fd);
407  else if (is_truetype(fd->fm))
408  writettf(fd);
409  else if (is_opentype(fd->fm))
410  writeotf(fd);
411  else
412  assert(0);
413  if (!fd->ff_found)
414  return;
415  assert(fd->ff_objnum == 0);
416  fd->ff_objnum = pdfnewobjnum();
417  pdfbegindict(fd->ff_objnum, 0); /* font file stream */
418  if (is_type1(fd->fm))
419  pdf_printf("/Length1 %i\n/Length2 %i\n/Length3 %i\n",
420  (int) t1_length1, (int) t1_length2, (int) t1_length3);
421  else if (is_truetype(fd->fm))
422  pdf_printf("/Length1 %i\n", (int) ttf_length);
423  else if (is_opentype(fd->fm))
424  pdf_puts("/Subtype /Type1C\n");
425  else
426  assert(0);
427  pdfbeginstream();
428  fb_flush();
429  pdfendstream();
430 }
431 
432 /**********************************************************************/
433 
435 {
436  static const int std_flags[] = {
437  /* indices for << start with 0, but bits start with 1, so the numbers
438  * for << are 1 lower than the bits in table 5.20 */
439  /* *INDENT-OFF* */
440  1 + 2 + (1 << 5), /* Courier */
441  1 + 2 + (1 << 5) + (1 << 18),/* Courier-Bold */
442  1 + 2 + (1 << 5) + (1 << 6), /* Courier-Oblique */
443  1 + 2 + (1 << 5) + (1 << 6) + (1 << 18),/* Courier-BoldOblique */
444  (1 << 5), /* Helvetica */
445  (1 << 5) + (1 << 18),/* Helvetica-Bold */
446  (1 << 5) + (1 << 6), /* Helvetica-Oblique */
447  (1 << 5) + (1 << 6) + (1 << 18),/* Helvetica-BoldOblique */
448  4, /* Symbol */
449  2 + (1 << 5), /* Times-Roman */
450  2 + (1 << 5) + (1 << 18),/* Times-Bold */
451  2 + (1 << 5) + (1 << 6), /* Times-Italic */
452  2 + (1 << 5) + (1 << 6) + (1 << 18),/* Times-BoldItalic */
453  4 /* ZapfDingbats */
454  /* *INDENT-ON* */
455  };
456  char *glyph;
457  struct avl_traverser t;
458  int fd_flags;
459  assert(fd != NULL && fd->fm != NULL);
460 
461  if (is_fontfile(fd->fm))
462  write_fontfile(fd); /* this will set fd->ff_found if font file is found */
463  if (fd->fn_objnum != 0)
465  if (fd->fd_objnum == 0)
466  fd->fd_objnum = pdfnewobjnum();
467  pdfbegindict(fd->fd_objnum, 1);
468  pdf_puts("/Type /FontDescriptor\n");
469  write_fontname(fd, "FontName");
471  fd_flags = (int) fd->fm->fd_flags;
472  else if (fd->ff_found)
473  fd_flags = FD_FLAGS_DEFAULT_EMBED;
474  else {
475  fd_flags = is_std_t1font(fd->fm)
476  ? std_flags[check_std_t1font(fd->fm->ps_name)]
479  ("No flags specified for non-embedded font `%s' (%s) (I'm using %i): "
480  "fix your map entry.",
481  fd->fm->ps_name != NULL ? fd->fm->ps_name : "No name given",
482  fd->fm->tfm_name, fd_flags);
483  }
484  pdf_printf("/Flags %i\n", fd_flags);
485  write_fontmetrics(fd);
486  if (fd->ff_found) {
487  if (getpdfomitcharset() == 0 && is_subsetted(fd->fm) && is_type1(fd->fm)) {
488  /* We don't get CharSet right. For some PDF standards,
489  CharSet is optional, but if it appears, it must be
490  correct. Unfortunately, there seems to be no practical
491  way we can guarantee correctness with precomposed accent
492  characters in our usual fonts (EC, TX, etc.):
493  https://mailman.ntg.nl/pipermail/ntg-pdftex/2018-June/004251.html
494 
495  But for PDF/A-1, apparently it is required, regardless:
496  https://mailman.ntg.nl/pipermail/ntg-pdftex/2019-January/004264.html
497 
498  Whereas for PDF/A-2 and PDF/A-3, it can be omitted:
499  https://github.com/veraPDF/veraPDF-validation-profiles/wiki/PDFA-Parts-2-and-3-rules#rule-62114-3
500 
501  Therefore, whether it is output can be controlled by the
502  user at runtime via \pdfincludecharset. */
503  assert(fd->gl_tree != NULL);
504  avl_t_init(&t, fd->gl_tree);
505  /* Names may appear in any order. */
506  pdf_puts("/CharSet (");
507  for (glyph = (char *) avl_t_first(&t, fd->gl_tree); glyph != NULL;
508  glyph = (char *) avl_t_next(&t))
509  pdf_printf("/%s", glyph);
510  pdf_puts(")\n");
511  }
512 
513  if (is_type1(fd->fm))
514  pdf_printf("/FontFile %i 0 R\n", (int) fd->ff_objnum);
515  else if (is_truetype(fd->fm))
516  pdf_printf("/FontFile2 %i 0 R\n", (int) fd->ff_objnum);
517  else if (is_opentype(fd->fm))
518  pdf_printf("/FontFile3 %i 0 R\n", (int) fd->ff_objnum);
519  else
520  assert(0);
521  }
522  pdfenddict();
523 }
524 
525 static void write_fontdescriptors(void)
526 {
527  fd_entry *fd;
528  struct avl_traverser t;
529  if (fd_tree == NULL)
530  return;
531  avl_t_init(&t, fd_tree);
532  for (fd = (fd_entry *) avl_t_first(&t, fd_tree); fd != NULL;
533  fd = (fd_entry *) avl_t_next(&t))
535 }
536 
537 /**********************************************************************/
538 
540 {
541  assert(fo != NULL);
542  assert(fo->fm != NULL);
543  assert(fo->fo_objnum != 0); /* reserved as pdf_font_num[f] in pdftex.web */
544  assert(fo->tex_font != 0);
545 
546  /* write ToUnicode entry if needed */
547  if ((fixedgentounicode > 0 && fo->fd != NULL
548  && !pdffontnobuiltintounicode[fo->tex_font])
549  || (fo->fd != NULL && fo->fm->tfm_name != NULL
550  && strcmp(fo->fm->tfm_name, "dummy-space")) == 0) {
551  if (fo->fe != NULL) {
552  fo->tounicode_objnum =
553  write_tounicode(fo->fe->glyph_names, fo->fm->tfm_name, fo->fe->name);
554  } else if (is_type1(fo->fm)) {
555  if (fo->fd->builtin_glyph_names==NULL) {
556  pdftex_fail("builtin glyph names is empty");
557  }
558  fo->tounicode_objnum =
560  }
561  }
562 
563  pdfbegindict(fo->fo_objnum, 1);
564  pdf_puts("/Type /Font\n");
565  pdf_puts("/Subtype /");
566  if (is_type1(fo->fm))
567  pdf_printf("%s\n", "Type1");
568  else if (is_truetype(fo->fm))
569  pdf_printf("%s\n", "TrueType");
570  else if (is_opentype(fo->fm))
571  pdf_printf("%s\n", "Type1");
572  else
573  assert(0);
574  assert(fo->fd != NULL && fo->fd->fd_objnum != 0);
575  write_fontname(fo->fd, "BaseFont");
576  pdf_printf("/FontDescriptor %i 0 R\n", (int) fo->fd->fd_objnum);
577  assert(fo->cw != NULL);
578  pdf_printf("/FirstChar %i\n/LastChar %i\n/Widths %i 0 R\n",
579  (int) fo->first_char, (int) fo->last_char,
580  (int) fo->cw->cw_objnum);
581  if ((is_type1(fo->fm) || is_opentype(fo->fm)) && fo->fe != NULL
582  && fo->fe->fe_objnum != 0)
583  pdf_printf("/Encoding %i 0 R\n", (int) fo->fe->fe_objnum);
584  if (fo->tounicode_objnum != 0)
585  pdf_printf("/ToUnicode %i 0 R\n", (int) fo->tounicode_objnum);
586  if (pdffontattr[fo->tex_font] != getnullstr()) {
587  pdfprint(pdffontattr[fo->tex_font]);
588  pdf_puts("\n");
589  }
590  pdfenddict();
591 }
592 
593 static void write_fontdictionaries(void)
594 {
595  fo_entry *fo;
596  struct avl_traverser t;
597  if (fo_tree == NULL)
598  return;
599  avl_t_init(&t, fo_tree);
600  for (fo = (fo_entry *) avl_t_first(&t, fo_tree); fo != NULL;
601  fo = (fo_entry *) avl_t_next(&t))
603 }
604 
605 /**********************************************************************/
606 /*
607  * Final flush of all font related stuff by call from
608  * @<Output fonts definition@>= in pdftex.web.
609  */
610 
611 void writefontstuff(void)
612 {
614  write_fontencodings(); /* see writeenc.c */
616 }
617 
618 /**********************************************************************/
619 
620 static void create_fontdictionary(fm_entry * fm, integer font_objnum,
621  internalfontnumber f)
622 {
623  fo_entry *fo = new_fo_entry();
624  get_char_range(fo, f); /* set fo->first_char and fo->last_char from f */
625  assert(fo->last_char >= fo->first_char);
626  fo->fm = fm;
627  fo->fo_objnum = font_objnum;
628  fo->tex_font = f;
629  if (is_reencoded(fo->fm)) { /* at least the map entry tells so */
630  fo->fe = get_fe_entry(fo->fm->encname); /* returns NULL if .enc file couldn't be opened */
631  if (fo->fe != NULL && (is_type1(fo->fm) || is_opentype(fo->fm))) {
632  if (fo->fe->fe_objnum == 0)
633  fo->fe->fe_objnum = pdfnewobjnum(); /* then it will be written out */
634  /* mark encoding pairs used by TeX to optimize encoding vector */
635  fo->fe->tx_tree = mark_chars(fo, fo->fe->tx_tree, f);
636  }
637  }
638  if (!is_builtin(fo->fm)) {
639  if (is_type1(fo->fm)) {
640  if ((fo->fd = lookup_fontdescriptor(fo)) == NULL) {
642  register_fd_entry(fo->fd);
643  }
644  } else
648  if (fo->fe != NULL) {
649  mark_reenc_glyphs(fo, f);
650  if (!is_type1(fo->fm)) {
651  /* mark reencoded characters as chars on TeX level */
652  assert(fo->fd->tx_tree == NULL);
653  fo->fd->tx_tree = mark_chars(fo, fo->fd->tx_tree, f);
654  if (is_truetype(fo->fm))
655  fo->fd->write_ttf_glyph_names = true;
656  }
657  } else
658  /* mark non-reencoded characters as chars on TeX level */
659  fo->fd->tx_tree = mark_chars(fo, fo->fd->tx_tree, f);
660  if (!is_type1(fo->fm))
662  } else {
663  /* builtin fonts still need the /Widths array and /FontDescriptor
664  * (to avoid error 'font FOO contains bad /BBox')
665  */
670  if (!is_std_t1font(fo->fm))
671  pdftex_warn("font `%s' is not a standard font; "
672  "I suppose it is available to your PDF viewer then",
673  fo->fm->ps_name);
674  }
675  if (is_type1(fo->fm))
676  register_fo_entry(fo);
677  else
679 }
680 
681 
682 ␌
683 /* This is called font_has_subset in luatex, but it returns 1 if any
684  characters from the font are used, and 0 if not (using fontbc and
685  fontec as the endpoints to check), i.e., whether any characters are
686  actually used from the font. */
687 
688 static int
689 font_is_used(internalfontnumber f)
690 {
691  int i, s;
692  /* search for |first_char| and |last_char| */
693  for (i = fontbc[f]; i <= fontec[f]; i++)
694  if (pdfcharmarked(f, i))
695  break;
696  s = i;
697  for (i = fontec[f]; i >= fontbc[f]; i--)
698  if (pdfcharmarked(f, i))
699  break;
700  if (s > i)
701  return 0;
702  else
703  return 1;
704 }
705 
706 void
707 dopdffont(integer font_objnum, internalfontnumber f)
708 {
709  fm_entry *fm;
710  if (!font_is_used(f))
711  return; /* avoid failed assertion in create_fontdictionary,
712  mailman.ntg.nl/pipermail/ntg-pdftex/2018-January/004209.html */
713 
714 
715  fm = hasfmentry(f) ? (fm_entry *) pdffontmap[f] : NULL;
716  if (fm == NULL || is_pk(fm))
717  writet3(fm, font_objnum, f);
718  else
719  create_fontdictionary(fm, font_objnum, f);
720 }
721 
722 // vim: ts=4
double __cdecl atan(double _X)
#define slant(f)
char * p2
Definition: bmpfont.h:62
char * p1
Definition: bmpfont.h:62
#define FONTBBOX1_CODE
Definition: ptexmac.h:97
#define XHEIGHT_CODE
Definition: ptexmac.h:96
#define ITALIC_ANGLE_CODE
Definition: ptexmac.h:94
#define STEMV_CODE
Definition: ptexmac.h:95
#define is_reencoded(fm)
Definition: ptexmac.h:135
#define FONTBBOX2_CODE
Definition: ptexmac.h:98
#define CAPHEIGHT_CODE
Definition: ptexmac.h:91
#define is_subsetted(fm)
Definition: ptexmac.h:126
#define FONT_KEYS_NUM
Definition: ptexmac.h:102
#define xtalloc
Definition: ptexmac.h:87
#define ASCENT_CODE
Definition: ptexmac.h:90
#define FONTBBOX3_CODE
Definition: ptexmac.h:99
#define is_included(fm)
Definition: ptexmac.h:125
#define is_truetype(fm)
Definition: ptexmac.h:127
#define FONTBBOX4_CODE
Definition: ptexmac.h:100
#define DESCENT_CODE
Definition: ptexmac.h:92
int strcmp()
Definition: coll.cpp:143
#define is_fontfile(fm)
Definition: ptexmac.h:172
mpz_t * f
Definition: gen-fib.c:34
#define s
Definition: afcover.h:80
int last_char
Definition: hbf2gf.c:340
assert(pcxLoadImage24((char *)((void *) 0), fp, pinfo, hdr))
#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
for(n=0;n< outline->n_points;n++)
Definition: ftbbox.c:494
#define M_PI
Definition: gd.h:236
#define xstrdup(s)
Definition: writet1.c:34
static char notdef[]
Definition: writet1.c:88
void writet1(void)
Definition: writet1.c:1582
static void pdftex_warn()
void * avl_t_next(struct avl_traverser *trav)
Definition: avl.c:524
void * avl_t_first(struct avl_traverser *trav, struct avl_table *tree)
Definition: avl.c:393
void ** avl_probe(struct avl_table *tree, void *item)
Definition: avl.c:85
void avl_t_init(struct avl_traverser *trav, struct avl_table *tree)
Definition: avl.c:382
int comp_string_entry(const void *pa, const void *pb, void *p)
Definition: avlstuff.c:55
struct libavl_allocator avl_xallocator
Definition: avlstuff.c:41
int comp_int_entry(const void *pa, const void *pb, void *p)
Definition: avlstuff.c:49
int check_std_t1font(char *s)
Definition: mapfile.c:377
boolean hasfmentry(internalfontnumber f)
Definition: mapfile.c:649
void fb_flush(void)
Definition: utils.c:88
integer t1_length1
Definition: writet1.c:109
void writettf(fd_entry *)
Definition: writettf.c:1334
integer ttf_length
Definition: writettf.c:103
void writet3(fm_entry *, int, internalfontnumber)
Definition: writet3.c:284
void writeotf(fd_entry *)
Definition: writettf.c:1402
integer t1_length3
Definition: ptexlib.h:167
void write_fontencodings(void)
Definition: writeenc.c:143
#define FD_FLAGS_DEFAULT_NON_EMBED
Definition: ptexlib.h:87
#define FD_FLAGS_NOT_SET_IN_MAPLINE
Definition: ptexlib.h:85
integer t1_length2
Definition: ptexlib.h:167
integer write_tounicode(char **, const char *, const char *)
Definition: tounicode.c:319
fe_entry * get_fe_entry(char *)
Definition: writeenc.c:71
#define FD_FLAGS_DEFAULT_EMBED
Definition: ptexlib.h:86
static struct avl_table * mark_chars(fo_entry *fo, struct avl_table *tx_tree, internalfontnumber f)
Definition: writefont.c:290
struct avl_table * fo_tree
Definition: writefont.c:24
static void write_fontdictionaries(void)
Definition: writefont.c:593
static cw_entry * new_cw_entry(void)
Definition: writefont.c:94
static void write_fontname(fd_entry *fd, const char *key)
Definition: writefont.c:185
static int comp_fo_entry(const void *pa, const void *pb, void *p)
Definition: writefont.c:27
static int font_is_used(internalfontnumber f)
Definition: writefont.c:689
static void fix_fontmetrics(fd_entry *fd)
Definition: writefont.c:137
static void create_fontdescriptor(fo_entry *fo, internalfontnumber f)
Definition: writefont.c:243
void writefontstuff(void)
Definition: writefont.c:611
static void write_fontmetrics(fd_entry *fd)
Definition: writefont.c:159
static void write_fontfile(fd_entry *fd)
Definition: writefont.c:402
static void mark_reenc_glyphs(fo_entry *fo, internalfontnumber f)
Definition: writefont.c:264
static void write_charwidth_array(fo_entry *fo)
Definition: writefont.c:346
fd_entry * new_fd_entry(void)
Definition: writefont.c:67
static void get_char_range(fo_entry *fo, internalfontnumber f)
Definition: writefont.c:312
fd_entry * lookup_fd_entry(char *s, integer slant, integer extend)
Definition: writefont.c:206
static void write_fontdictionary(fo_entry *fo)
Definition: writefont.c:539
void dopdffont(integer font_objnum, internalfontnumber f)
Definition: writefont.c:707
static void write_fontname_object(fd_entry *fd)
Definition: writefont.c:196
static void create_fontdictionary(fm_entry *fm, integer font_objnum, internalfontnumber f)
Definition: writefont.c:620
static void register_fo_entry(fo_entry *fo)
Definition: writefont.c:385
static fo_entry * lookup_fo_entry(char *s)
Definition: writefont.c:371
static fd_entry * lookup_fontdescriptor(fo_entry *fo)
Definition: writefont.c:222
static void write_fontdescriptors(void)
Definition: writefont.c:525
static void create_charwidth_array(fo_entry *fo, internalfontnumber f)
Definition: writefont.c:331
void register_fd_entry(fd_entry *fd)
Definition: writefont.c:230
static void preset_fontmetrics(fd_entry *fd, internalfontnumber f)
Definition: writefont.c:110
static void write_fontdescriptor(fd_entry *fd)
Definition: writefont.c:434
static fo_entry * new_fo_entry(void)
Definition: writefont.c:49
static void preset_fontname(fo_entry *fo)
Definition: writefont.c:177
struct avl_table * fd_tree
Definition: writefont.c:25
static int comp_fd_entry(const void *pa, const void *pb, void *p)
Definition: writefont.c:33
static int getpdfomitcharset(lua_State *L)
Definition: lpdflib.c:811
static double extend
Definition: otftotfm.cc:277
int integer
Definition: pbmtopk.c:38
void pdfbeginstream(void)
void pdfendobj(void)
void pdf_printf(const char *,...)
void pdfendstream(void)
integer pdfnewobjnum(void)
#define pdfbeginobj(i, pdfoslevel)
Definition: pdftex-common.h:60
#define pdfcharmarked(f, c)
Definition: pdftex.h:26
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
int g
Definition: ppmqvga.c:68
#define avl_find
Definition: avl.h:18
#define avl_create
Definition: avl.h:19
const key_entry font_key[(10+1)]
Definition: writefont.c:32
#define pdf_puts(pdf, s)
Definition: epdf.h:108
Definition: avl.h:61
Definition: ptexlib.h:133
integer * width
Definition: ptexlib.h:135
integer cw_objnum
Definition: ptexlib.h:134
Definition: ptexlib.h:116
char * fontname
Definition: ptexlib.h:118
integer fd_objnum
Definition: ptexlib.h:117
struct avl_table * gl_tree
Definition: ptexlib.h:130
struct avl_table * tx_tree
Definition: ptexlib.h:129
fm_entry * fm
Definition: ptexlib.h:128
integer ff_objnum
Definition: ptexlib.h:121
integer fn_objnum
Definition: ptexlib.h:122
intparm font_dim[(10+1)]
Definition: ptexlib.h:125
boolean write_ttf_glyph_names
Definition: ptexlib.h:124
boolean all_glyphs
Definition: ptexlib.h:123
char * subset_tag
Definition: ptexlib.h:119
boolean ff_found
Definition: ptexlib.h:120
fe_entry * fe
Definition: ptexlib.h:126
char ** builtin_glyph_names
Definition: ptexlib.h:127
struct avl_table * tx_tree
Definition: ptexlib.h:75
integer fe_objnum
Definition: ptexlib.h:72
char * name
Definition: ptexlib.h:73
char ** glyph_names
Definition: ptexlib.h:74
Definition: ptexlib.h:90
integer slant
Definition: ptexlib.h:96
char * tfm_name
Definition: ptexlib.h:92
integer extend
Definition: ptexlib.h:97
char * ff_name
Definition: ptexlib.h:99
char * encname
Definition: ptexlib.h:98
integer fd_flags
Definition: ptexlib.h:95
char * ps_name
Definition: ptexlib.h:94
Definition: ptexlib.h:138
internalfontnumber tex_font
Definition: ptexlib.h:140
fm_entry * fm
Definition: ptexlib.h:141
cw_entry * cw
Definition: ptexlib.h:144
integer tounicode_objnum
Definition: ptexlib.h:147
integer last_char
Definition: ptexlib.h:146
integer fo_objnum
Definition: ptexlib.h:139
fd_entry * fd
Definition: ptexlib.h:142
fe_entry * fe
Definition: ptexlib.h:143
integer first_char
Definition: ptexlib.h:145
Definition: pbmfont.h:4
boolean set
Definition: ptexlib.h:113
int val
Definition: ptexlib.h:112
Definition: dvips.h:235
int j
Definition: t4ht.c:1589
#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)
#define pdftex_fail
Definition: ttf2afm.c:48
TT_Glyph glyph
Definition: ttf2pfb.c:162
#define is_pk(fm)
Definition: ptexmac.h:185
#define GEN_KEY_NUM
Definition: ptexmac.h:146
#define cmp_return(a, b)
Definition: ptexmac.h:210
#define is_opentype(fm)
Definition: ptexmac.h:184
#define is_std_t1font(fm)
Definition: ptexmac.h:180
#define is_type1(fm)
Definition: ptexmac.h:182
#define is_builtin(fm)
Definition: ptexmac.h:194
#define INT_KEYS_NUM
Definition: ptexmac.h:148