beta-0.89.2
[luatex.git] / source / texk / web2c / luatexdir / font / writetype0.w
blob3053103c52465ad1198eb746531c8dbf4fbfee3c
1 % writetype0.w
3 % Copyright 2006-2008 Taco Hoekwater <taco@@luatex.org>
5 % This file is part of LuaTeX.
7 % LuaTeX is free software; you can redistribute it and/or modify it under
8 % the terms of the GNU General Public License as published by the Free
9 % Software Foundation; either version 2 of the License, or (at your
10 % option) any later version.
12 % LuaTeX is distributed in the hope that it will be useful, but WITHOUT
13 % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 % FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 % License for more details.
17 % You should have received a copy of the GNU General Public License along
18 % with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
20 @ @c
23 #include "ptexlib.h"
24 #include "font/writettf.h"
25 #include "font/writecff.h"
27 @ @c
28 extern unsigned char *ttf_buffer;
29 void writetype0(PDF pdf, fd_entry * fd)
31 int callback_id;
32 int file_opened = 0;
33 long i = 0;
34 dirtab_entry *tab;
35 cff_font *cff;
36 sfnt *sfont;
38 dir_tab = NULL;
39 glyph_tab = NULL;
41 fd_cur = fd; /* |fd_cur| is global inside \.{writettf.w} */
42 assert(fd_cur->fm != NULL);
43 assert(is_opentype(fd_cur->fm) || is_truetype(fd_cur->fm));
44 assert(is_included(fd_cur->fm));
46 ttf_curbyte = 0;
47 ttf_size = 0;
48 cur_file_name =
49 luatex_find_file(fd_cur->fm->ff_name, find_opentype_file_callback);
50 if (cur_file_name == NULL) {
51 cur_file_name =
52 luatex_find_file(fd_cur->fm->ff_name, find_truetype_file_callback);
53 if (cur_file_name == NULL) {
54 formatted_error("type 0","cannot find file '%s'", fd_cur->fm->ff_name);
57 callback_id = callback_defined(read_opentype_file_callback);
58 if (callback_id > 0) {
59 if (run_callback(callback_id, "S->bSd", cur_file_name,
60 &file_opened, &ttf_buffer, &ttf_size) &&
61 file_opened && ttf_size > 0) {
62 } else {
63 formatted_error("type 0","cannot find file '%s'", cur_file_name);
65 } else {
66 if (!otf_open(cur_file_name)) {
67 formatted_error("type 0","cannot find file '%s'", cur_file_name);
69 ttf_read_file();
70 ttf_close();
73 fd_cur->ff_found = true;
75 sfont = sfnt_open(ttf_buffer, ttf_size);
76 if (sfont->type == SFNT_TYPE_TTC)
77 i = ff_get_ttc_index(fd->fm->ff_name, fd->fm->ps_name);
80 if (is_subsetted(fd_cur->fm)) {
81 report_start_file(filetype_subset, cur_file_name);
82 } else {
83 report_start_file(filetype_font, cur_file_name);
87 if (sfont->type == SFNT_TYPE_TTC) otc_read_tabdir(i);
88 else ttf_read_tabdir();
89 sfnt_close(sfont);
91 /* read font parameters */
92 if (ttf_name_lookup("head", false) != NULL)
93 ttf_read_head();
94 if (ttf_name_lookup("hhea", false) != NULL)
95 ttf_read_hhea();
96 if (ttf_name_lookup("PCLT", false) != NULL)
97 ttf_read_pclt();
98 if (ttf_name_lookup("post", false) != NULL)
99 ttf_read_post();
101 /* copy font file */
102 tab = ttf_seek_tab("CFF ", 0);
104 /* TODO the next 0 is a subfont index */
105 cff = read_cff(ttf_buffer + ttf_curbyte, (long) tab->length, 0);
106 if (!is_subsetted(fd_cur->fm)) {
107 /* not subsetted, just do a copy */
108 for (i = (long) tab->length; i > 0; i--)
109 strbuf_putchar(pdf->fb, (unsigned char) ttf_getnum(1));
110 } else {
111 if (cff != NULL) {
112 if (cff_is_cidfont(cff)) {
113 write_cid_cff(pdf, cff, fd_cur);
114 #if 0
115 for (i = tab->length; i > 0; i--)
116 strbuf_putchar(pdf->fb, (unsigned char) ttf_getnum(1));
117 #endif
118 } else {
119 write_cff(pdf, cff, fd_cur);
121 } else {
122 /* not understood, just do a copy */
123 for (i = (long) tab->length; i > 0; i--)
124 strbuf_putchar(pdf->fb, (unsigned char) ttf_getnum(1));
127 xfree(dir_tab);
128 xfree(ttf_buffer);
129 if (is_subsetted(fd_cur->fm)) {
130 report_stop_file(filetype_subset);
131 } else {
132 report_stop_file(filetype_font);
134 cur_file_name = NULL;