1 /*
2 Copyright 1996-2014 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 #include <string.h>
22 
23 
is_subsetable(fm_entry * fm)24 int is_subsetable(fm_entry * fm)
25 {
26     assert(is_included(fm));
27     return is_subsetted(fm);
28 }
29 
epdf_create_fontdescriptor(fm_entry * fm,int stemV)30 fd_entry *epdf_create_fontdescriptor(fm_entry * fm, int stemV)
31 {
32     fd_entry *fd;
33     if ((fd = lookup_fd_entry(fm->ff_name, fm->slant, fm->extend)) == NULL) {
34         fm->in_use = true;
35         fd = new_fd_entry();
36         fd->fm = fm;
37         register_fd_entry(fd);
38         fd->fd_objnum = pdfnewobjnum();
39         assert(fm->ps_name != NULL);
40         fd->fontname = xstrdup(fm->ps_name);    /* just fallback */
41         // stemV must be copied
42         fd->font_dim[STEMV_CODE].val = stemV;
43         fd->font_dim[STEMV_CODE].set = true;
44         fd->gl_tree = avl_create(comp_string_entry, NULL, &avl_xallocator);
45         assert(fd->gl_tree != NULL);
46     }
47     return fd;
48 }
49 
get_fd_objnum(fd_entry * fd)50 int get_fd_objnum(fd_entry * fd)
51 {
52     assert(fd->fd_objnum != 0);
53     return fd->fd_objnum;
54 }
55 
get_fn_objnum(fd_entry * fd)56 int get_fn_objnum(fd_entry * fd)
57 {
58     if (fd->fn_objnum == 0)
59         fd->fn_objnum = pdfnewobjnum();
60     return fd->fn_objnum;
61 }
62 
63 /***********************************************************************
64  * Mark glyphs used by embedded PDF file:
65  * 1. build fontdescriptor, if not yet existing
66  * 2. mark glyphs directly there
67  *
68  * Input charset from xpdf is a string of glyph names including
69  * leading slashes, but without blanks between them, like: /a/b/c
70 ***********************************************************************/
71 
epdf_mark_glyphs(fd_entry * fd,char * charset)72 void epdf_mark_glyphs(fd_entry * fd, char *charset)
73 {
74     char *p, *q, *s;
75     char *glyph;
76     void **aa;
77     if (charset == NULL)
78         return;
79     assert(fd != NULL);
80     for (s = charset + 1, q = charset + strlen(charset); s < q; s = p + 1) {
81         for (p = s; *p != '\0' && *p != '/'; p++);
82         *p = '\0';
83         if ((char *) avl_find(fd->gl_tree, s) == NULL) {
84             glyph = xstrdup(s);
85             aa = avl_probe(fd->gl_tree, glyph);
86             assert(aa != NULL);
87         }
88     }
89 }
90 
embed_whole_font(fd_entry * fd)91 void embed_whole_font(fd_entry * fd)
92 {
93     fd->all_glyphs = true;
94 }
95 
epdf_free(void)96 void epdf_free(void)
97 {
98     epdf_check_mem();
99 }
100