File: writetype0.w

package info (click to toggle)
texlive-bin 2018.20181218.49446-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 186,920 kB
  • sloc: ansic: 873,264; cpp: 311,278; perl: 82,918; sh: 23,243; makefile: 8,590; lex: 4,939; python: 4,462; pascal: 3,813; java: 3,569; yacc: 2,901; tcl: 2,379; exp: 2,031; xml: 844; ruby: 678; lisp: 398; sed: 331; asm: 140; csh: 46; awk: 30
file content (136 lines) | stat: -rw-r--r-- 4,356 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
% writetype0.w
%
% Copyright 2006-2008 Taco Hoekwater <taco@@luatex.org>
%
% This file is part of LuaTeX.
%
% LuaTeX is free software; you can redistribute it and/or modify it under
% the terms of the GNU General Public License as published by the Free
% Software Foundation; either version 2 of the License, or (at your
% option) any later version.
%
% LuaTeX is distributed in the hope that it will be useful, but WITHOUT
% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
% FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
% License for more details.
%
% You should have received a copy of the GNU General Public License along
% with LuaTeX; if not, see <http://www.gnu.org/licenses/>.

@ @c

#include "ptexlib.h"
#include "font/writettf.h"
#include "font/writecff.h"

@ @c
extern unsigned char *ttf_buffer;

void writetype0(PDF pdf, fd_entry * fd)
{
    int callback_id;
    int file_opened = 0;
    long i = 0;
    dirtab_entry *tab;
    cff_font *cff;
    sfnt *sfont;

    dir_tab = NULL;
    glyph_tab = NULL;

    fd_cur = fd;                /* |fd_cur| is global inside \.{writettf.w} */
    assert(fd_cur->fm != NULL);
    assert(is_opentype(fd_cur->fm) || is_truetype(fd_cur->fm));
    assert(is_included(fd_cur->fm));

    ttf_curbyte = 0;
    ttf_size = 0;
    cur_file_name =
        luatex_find_file(fd_cur->fm->ff_name, find_opentype_file_callback);
    if (cur_file_name == NULL) {
        cur_file_name =
            luatex_find_file(fd_cur->fm->ff_name, find_truetype_file_callback);
        if (cur_file_name == NULL) {
            formatted_error("type 0","cannot find file '%s'", fd_cur->fm->ff_name);
        }
    }
    callback_id = callback_defined(read_opentype_file_callback);
    if (callback_id > 0) {
        if (run_callback(callback_id, "S->bSd", cur_file_name,
                         &file_opened, &ttf_buffer, &ttf_size) &&
            file_opened && ttf_size > 0) {
        } else {
            formatted_error("type 0","cannot find file '%s'", cur_file_name);
        }
    } else {
        if (!otf_open(cur_file_name)) {
            formatted_error("type 0","cannot find file '%s'", cur_file_name);
        }
        ttf_read_file();
        ttf_close();
    }

    fd_cur->ff_found = true;

    sfont = sfnt_open(ttf_buffer, ttf_size);
    if (sfont->type == SFNT_TYPE_TTC)
        i = ff_get_ttc_index(fd->fm->ff_name, fd->fm->ps_name);

    if (is_subsetted(fd_cur->fm)) {
        report_start_file(filetype_subset, cur_file_name);
    } else {
        report_start_file(filetype_font, cur_file_name);
    }

    if (sfont->type == SFNT_TYPE_TTC) otc_read_tabdir(i);
    else ttf_read_tabdir();
    sfnt_close(sfont);

    /* read font parameters */
    if (ttf_name_lookup("head", false) != NULL)
        ttf_read_head();
    if (ttf_name_lookup("hhea", false) != NULL)
        ttf_read_hhea();
    if (ttf_name_lookup("PCLT", false) != NULL)
        ttf_read_pclt();
    if (ttf_name_lookup("post", false) != NULL)
        ttf_read_post();

    /* copy font file */
    if (ttf_name_lookup("CFF2", false) != NULL)      /* HH */
        tab = ttf_seek_tab("CFF2", 0);               /* HH */
    else                                             /* HH */
        tab = ttf_seek_tab("CFF ", 0);

    /* TODO the next 0 is a subfont index */
    cff = read_cff(ttf_buffer + ttf_curbyte, (long) tab->length, 0);
    if (!is_subsetted(fd_cur->fm)) {
        /* not subsetted, just do a copy */
        for (i = (long) tab->length; i > 0; i--)
            strbuf_putchar(pdf->fb, (unsigned char) ttf_getnum(1));
    } else {
        if (cff != NULL) {
            if (cff_is_cidfont(cff)) {
                write_cid_cff(pdf, cff, fd_cur);
#if 0
                for (i = tab->length; i > 0; i--)
                    strbuf_putchar(pdf->fb, (unsigned char) ttf_getnum(1));
#endif
            } else {
                write_cff(pdf, cff, fd_cur);
            }
        } else {
            /* not understood, just do a copy */
            for (i = (long) tab->length; i > 0; i--)
                strbuf_putchar(pdf->fb, (unsigned char) ttf_getnum(1));
        }
    }
    xfree(dir_tab);
    xfree(ttf_buffer);
    if (is_subsetted(fd_cur->fm)) {
        report_stop_file(filetype_subset);
    } else {
        report_stop_file(filetype_font);
    }
    cur_file_name = NULL;
}