| 1 |
/* |
| 2 |
|
| 3 |
Copyright 2006-2008 Taco Hoekwater <[email protected]> |
| 4 |
|
| 5 |
This file is part of LuaTeX. |
| 6 |
|
| 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. |
| 11 |
|
| 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. |
| 16 |
|
| 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/>. |
| 19 |
|
| 20 |
*/ |
| 21 |
|
| 22 |
#include "ptexlib.h" |
| 23 |
#include "font/writettf.h" |
| 24 |
#include "font/writecff.h" |
| 25 |
|
| 26 |
/*tex |
| 27 |
|
| 28 |
Here we also support the newer CFF2 specification, |
| 29 |
|
| 30 |
*/ |
| 31 |
|
| 32 |
extern unsigned char *ttf_buffer; |
| 33 |
|
| 34 |
void writetype0(PDF pdf, fd_entry * fd) |
| 35 |
{ |
| 36 |
int callback_id; |
| 37 |
int file_opened = 0; |
| 38 |
long i = 0; |
| 39 |
dirtab_entry *tab; |
| 40 |
cff_font *cff; |
| 41 |
sfnt *sfont; |
| 42 |
dir_tab = NULL; |
| 43 |
glyph_tab = NULL; |
| 44 |
/*tex |fd_cur| is global inside |writettf.c| */ |
| 45 |
fd_cur = fd; |
| 46 |
assert(fd_cur->fm != NULL); |
| 47 |
assert(is_opentype(fd_cur->fm) || is_truetype(fd_cur->fm)); |
| 48 |
assert(is_included(fd_cur->fm)); |
| 49 |
ttf_curbyte = 0; |
| 50 |
ttf_size = 0; |
| 51 |
cur_file_name = luatex_find_file(fd_cur->fm->ff_name, find_opentype_file_callback); |
| 52 |
if (cur_file_name == NULL) { |
| 53 |
cur_file_name = |
| 54 |
luatex_find_file(fd_cur->fm->ff_name, find_truetype_file_callback); |
| 55 |
if (cur_file_name == NULL) { |
| 56 |
formatted_error("type 0","cannot find file '%s'", fd_cur->fm->ff_name); |
| 57 |
} |
| 58 |
} |
| 59 |
callback_id = callback_defined(read_opentype_file_callback); |
| 60 |
if (callback_id > 0) { |
| 61 |
if (run_callback(callback_id, "S->bSd", cur_file_name, |
| 62 |
&file_opened, &ttf_buffer, &ttf_size) && |
| 63 |
file_opened && ttf_size > 0) { |
| 64 |
} else { |
| 65 |
formatted_error("type 0","cannot find file '%s'", cur_file_name); |
| 66 |
} |
| 67 |
} else { |
| 68 |
if (!otf_open(cur_file_name)) { |
| 69 |
formatted_error("type 0","cannot find file '%s'", cur_file_name); |
| 70 |
} |
| 71 |
ttf_read_file(); |
| 72 |
ttf_close(); |
| 73 |
} |
| 74 |
fd_cur->ff_found = true; |
| 75 |
sfont = sfnt_open(ttf_buffer, ttf_size); |
| 76 |
if (sfont->type == SFNT_TYPE_TTC) |
| 77 |
i = fd->fm->subfont > 0 ? (fd->fm->subfont - 1): ff_get_ttc_index(fd->fm->ff_name, fd->fm->ps_name); |
| 78 |
if (is_subsetted(fd_cur->fm)) { |
| 79 |
report_start_file(filetype_subset, cur_file_name); |
| 80 |
} else { |
| 81 |
report_start_file(filetype_font, cur_file_name); |
| 82 |
} |
| 83 |
if (sfont->type == SFNT_TYPE_TTC) otc_read_tabdir(i); |
| 84 |
else ttf_read_tabdir(); |
| 85 |
sfnt_close(sfont); |
| 86 |
/*tex Read font parameters: */ |
| 87 |
if (ttf_name_lookup("head", false) != NULL) |
| 88 |
ttf_read_head(); |
| 89 |
if (ttf_name_lookup("hhea", false) != NULL) |
| 90 |
ttf_read_hhea(); |
| 91 |
if (ttf_name_lookup("PCLT", false) != NULL) |
| 92 |
ttf_read_pclt(); |
| 93 |
if (ttf_name_lookup("post", false) != NULL) |
| 94 |
ttf_read_post(); |
| 95 |
/*tex Copy font file, including the newer variant: */ |
| 96 |
if (ttf_name_lookup("CFF2", false) != NULL) |
| 97 |
tab = ttf_seek_tab("CFF2", 0); |
| 98 |
else |
| 99 |
tab = ttf_seek_tab("CFF ", 0); |
| 100 |
cff = read_cff(ttf_buffer + ttf_curbyte, (long) tab->length, 0); |
| 101 |
if (!is_subsetted(fd_cur->fm)) { |
| 102 |
/*tex not subsetted, copy: */ |
| 103 |
for (i = (long) tab->length; i > 0; i--) |
| 104 |
strbuf_putchar(pdf->fb, (unsigned char) ttf_getnum(1)); |
| 105 |
} else { |
| 106 |
if (cff != NULL) { |
| 107 |
if (cff_is_cidfont(cff)) { |
| 108 |
write_cid_cff(pdf, cff, fd_cur); |
| 109 |
} else { |
| 110 |
write_cff(pdf, cff, fd_cur); |
| 111 |
} |
| 112 |
} else { |
| 113 |
/*tex Just copy: */ |
| 114 |
for (i = (long) tab->length; i > 0; i--) |
| 115 |
strbuf_putchar(pdf->fb, (unsigned char) ttf_getnum(1)); |
| 116 |
} |
| 117 |
} |
| 118 |
xfree(dir_tab); |
| 119 |
xfree(ttf_buffer); |
| 120 |
if (is_subsetted(fd_cur->fm)) { |
| 121 |
report_stop_file(filetype_subset); |
| 122 |
} else { |
| 123 |
report_stop_file(filetype_font); |
| 124 |
} |
| 125 |
cur_file_name = NULL; |
| 126 |
} |