summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c
diff options
context:
space:
mode:
authorLuigi Scarso <luigi.scarso@gmail.com>2017-03-24 00:38:37 +0000
committerLuigi Scarso <luigi.scarso@gmail.com>2017-03-24 00:38:37 +0000
commit5d062cf98a24ed23b0df14465fec4c081f99d7a4 (patch)
treebbad41c50125226ca6867e84a9006403a827e303 /Build/source/texk/web2c
parent61e0a756c8bd5b2b5c5501bffd7a65486f8b1249 (diff)
sync with latest luatex from new svn repo.
git-svn-id: svn://tug.org/texlive/trunk@43592 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c')
-rw-r--r--Build/source/texk/web2c/luatexdir/font/luafont.w3
-rw-r--r--Build/source/texk/web2c/luatexdir/font/luatexfont.h3
-rw-r--r--Build/source/texk/web2c/luatexdir/font/texfont.h5
-rw-r--r--Build/source/texk/web2c/luatexdir/font/texfont.w2
-rw-r--r--Build/source/texk/web2c/luatexdir/font/tt_glyf.h4
-rw-r--r--Build/source/texk/web2c/luatexdir/font/tt_glyf.w60
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writecff.h7
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writecff.w1013
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writefont.w320
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writettf.w9
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writetype0.w9
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writetype2.w2
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c1
-rw-r--r--Build/source/texk/web2c/luatexdir/lua/luatex-api.h3
-rw-r--r--Build/source/texk/web2c/luatexdir/luatexcallbackids.h1
-rw-r--r--Build/source/texk/web2c/luatexdir/tex/dumpdata.w2
16 files changed, 759 insertions, 685 deletions
diff --git a/Build/source/texk/web2c/luatexdir/font/luafont.w b/Build/source/texk/web2c/luatexdir/font/luafont.w
index 9c7354a3f8f..8013883c454 100644
--- a/Build/source/texk/web2c/luatexdir/font/luafont.w
+++ b/Build/source/texk/web2c/luatexdir/font/luafont.w
@@ -438,6 +438,7 @@ int font_to_lua(lua_State * L, int f)
dump_stringfield(L,writingmode,font_writingmode_strings[font_writingmode(f)]);
dump_stringfield(L,identity,font_identity_strings[font_identity(f)]);
dump_stringfield(L,embedding,font_embedding_strings[font_embedding(f)]);
+ dump_intfield(L,streamprovider,font_streamprovider(f));
dump_intfield(L,units_per_em,font_units_per_em(f));
dump_intfield(L,size,font_size(f));
@@ -1383,6 +1384,8 @@ int font_from_lua(lua_State * L, int f)
set_font_natural_dir(f, i);
i = lua_numeric_field_by_index(L,lua_key_index(encodingbytes), 0);
set_font_encodingbytes(f, (char) i);
+ i = lua_numeric_field_by_index(L,lua_key_index(streamprovider), 0);
+ set_font_streamprovider(f, (char) i);
i = n_boolean_field(L,lua_key_index(oldmath), 0);
set_font_oldmath(f, i);
i = lua_numeric_field_by_index(L,lua_key_index(tounicode), 0);
diff --git a/Build/source/texk/web2c/luatexdir/font/luatexfont.h b/Build/source/texk/web2c/luatexdir/font/luatexfont.h
index bd84a61672c..9ef5110db24 100644
--- a/Build/source/texk/web2c/luatexdir/font/luatexfont.h
+++ b/Build/source/texk/web2c/luatexdir/font/luatexfont.h
@@ -102,6 +102,7 @@ typedef struct fd_entry_ {
fm_entry *fm; /* pointer to font map structure */
struct avl_table *tx_tree; /* tree of non-reencoded TeX characters marked as used */
struct avl_table *gl_tree; /* tree of all marked glyphs */
+ internal_font_number tex_font; /* needed for variable */
} fd_entry;
typedef struct fo_entry_ {
@@ -162,7 +163,7 @@ void writetype0(PDF pdf, fd_entry * fd);
/* writefont.c */
void do_pdf_font(PDF, internal_font_number);
fd_entry *lookup_fd_entry(char *);
-fd_entry *new_fd_entry(void);
+fd_entry *new_fd_entry(internal_font_number);
void write_fontstuff(PDF);
void register_fd_entry(fd_entry * fd);
diff --git a/Build/source/texk/web2c/luatexdir/font/texfont.h b/Build/source/texk/web2c/luatexdir/font/texfont.h
index ff15cc791b4..98557992f97 100644
--- a/Build/source/texk/web2c/luatexdir/font/texfont.h
+++ b/Build/source/texk/web2c/luatexdir/font/texfont.h
@@ -153,6 +153,7 @@ typedef struct texfont {
int _font_writingmode;
int _font_identity;
int _font_embedding;
+ int _font_streamprovider;
int _font_bc;
int _hyphen_char;
int _skew_char;
@@ -316,6 +317,10 @@ boolean cmp_font_area(int, str_number);
# define font_encodingbytes(a) font_tables[a]->_font_encodingbytes
# define set_font_encodingbytes(a,b) font_encodingbytes(a) = b
+# define font_streamprovider(a) font_tables[a]->_font_streamprovider
+# define set_font_streamprovider(a,b) font_streamprovider(a) = b
+
+
# define font_oldmath(a) font_tables[a]->_font_oldmath
# define set_font_oldmath(a,b) font_oldmath(a) = b
diff --git a/Build/source/texk/web2c/luatexdir/font/texfont.w b/Build/source/texk/web2c/luatexdir/font/texfont.w
index ab72a52f592..0c64045752e 100644
--- a/Build/source/texk/web2c/luatexdir/font/texfont.w
+++ b/Build/source/texk/web2c/luatexdir/font/texfont.w
@@ -1542,6 +1542,7 @@ static void dump_font_entry(texfont * f)
dump_int(f->_font_writingmode);
dump_int(f->_font_identity);
dump_int(f->_font_embedding);
+ dump_int(f->_font_streamprovider);
dump_int(f->_font_bc);
dump_int(f->_hyphen_char);
dump_int(f->_skew_char);
@@ -1721,6 +1722,7 @@ static void undump_font_entry(texfont * f)
undump_int(x); f->_font_writingmode = x;
undump_int(x); f->_font_identity = x;
undump_int(x); f->_font_embedding = x;
+ undump_int(x); f->_font_streamprovider = x;
undump_int(x); f->_font_bc = x;
undump_int(x); f->_hyphen_char = x;
undump_int(x); f->_skew_char = x;
diff --git a/Build/source/texk/web2c/luatexdir/font/tt_glyf.h b/Build/source/texk/web2c/luatexdir/font/tt_glyf.h
index a16cfbc9f05..780b77793dc 100644
--- a/Build/source/texk/web2c/luatexdir/font/tt_glyf.h
+++ b/Build/source/texk/web2c/luatexdir/font/tt_glyf.h
@@ -1,5 +1,5 @@
/* tt_glyf.h
-
+
Copyright 2002 by Jin-Hwan Cho and Shunsaku Hirata,
the dvipdfmx project team <dvipdfmx@project.ktug.or.kr>
Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
@@ -52,7 +52,7 @@ extern USHORT tt_add_glyph(struct tt_glyphs *g, USHORT gid, USHORT new_gid);
extern USHORT tt_get_index(struct tt_glyphs *g, USHORT gid);
extern USHORT tt_find_glyph(struct tt_glyphs *g, USHORT gid);
-extern int tt_build_tables(sfnt * sfont, struct tt_glyphs *g);
+extern int tt_build_tables(sfnt * sfont, struct tt_glyphs *g, fd_entry * fd);
extern int tt_get_metrics(sfnt * sfont, struct tt_glyphs *g);
#endif /* _TT_GLYF_H_ */
diff --git a/Build/source/texk/web2c/luatexdir/font/tt_glyf.w b/Build/source/texk/web2c/luatexdir/font/tt_glyf.w
index 167d8df2038..c0f17e5ab59 100644
--- a/Build/source/texk/web2c/luatexdir/font/tt_glyf.w
+++ b/Build/source/texk/web2c/luatexdir/font/tt_glyf.w
@@ -174,11 +174,11 @@ static int glyf_cmp(const void *v1, const void *v2)
}
@ @c
-int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
+int tt_build_tables(sfnt * sfont, struct tt_glyphs *g, fd_entry * fd)
{
char *hmtx_table_data = NULL, *loca_table_data = NULL;
char *glyf_table_data = NULL;
- ULONG hmtx_table_size, loca_table_size, glyf_table_size;
+ ULONG hmtx_table_size, loca_table_size, glyf_table_size, glyf_table_used;
/* some information available from other TrueType table */
struct tt_head_table *head = NULL;
struct tt_hhea_table *hhea = NULL;
@@ -190,6 +190,14 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
long i;
USHORT *w_stat; /* Estimate most frequently appeared width */
+ int tex_font = fd->tex_font;
+ int streamprovider = 0;
+ int callback_id = 0 ;
+ if ((tex_font > 0) && (font_streamprovider(tex_font) == 2)) {
+ streamprovider = font_streamprovider(tex_font);
+ callback_id = callback_defined(glyph_stream_provider_callback);
+ }
+
ASSERT(g);
if (sfont->type != SFNT_TYPE_TRUETYPE && sfont->type != SFNT_TYPE_TTC)
@@ -307,6 +315,7 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
formatted_error("ttf","invalid glyph data (gid %u)", gid);
}
+/* todo: no need for this */
g->gd[i].data = p = NEW(len, BYTE);
endptr = p + len;
@@ -432,6 +441,7 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
hmtx_table_data = p = NEW(hmtx_table_size, char);
loca_table_data = q = NEW(loca_table_size, char);
glyf_table_data = NEW(glyf_table_size, char);
+ glyf_table_used = 0;
offset = 0UL;
prev = 0;
@@ -451,8 +461,6 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
q += sfnt_put_ulong(q, (LONG) offset);
}
}
- padlen =
- (int) ((g->gd[i].length % 4) ? (4 - (g->gd[i].length % 4)) : 0);
if (g->gd[i].gid < hhea->numberOfHMetrics) {
p += sfnt_put_ushort(p, g->gd[i].advw);
}
@@ -462,13 +470,35 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
} else {
q += sfnt_put_ulong(q, (LONG) offset);
}
- memset(glyf_table_data + offset, 0,
- (size_t) (g->gd[i].length + (ULONG) padlen));
- memcpy(glyf_table_data + offset, g->gd[i].data, g->gd[i].length);
- offset += (g->gd[i].length + (ULONG) padlen);
+
+ if (callback_id > 0) {
+
+ lstring * result;
+ long size = 0;
+ run_callback(callback_id, "ddd->L", tex_font, g->gd[i].gid, streamprovider, &result); /* this call can be sped up */
+ padlen = (int) ((result->l % 4) ? (4 - (result->l % 4)) : 0);
+ size = (size_t) result->l + (ULONG) padlen;
+ if (glyf_table_used + size >= glyf_table_size) {
+ glyf_table_size = glyf_table_size + 20 * size; /* just a guess */
+ glyf_table_data = xrealloc(glyf_table_data, (unsigned)((unsigned)glyf_table_size*sizeof(char)));
+ }
+ glyf_table_used += size;
+ memset(glyf_table_data + offset, 0, (size_t) size);
+ memcpy(glyf_table_data + offset, (const char *) result->s, (size_t) result->l);
+ offset += size;
+ xfree(result);
+
+ } else {
+
+ padlen = (int) ((g->gd[i].length % 4) ? (4 - (g->gd[i].length % 4)) : 0);
+ memset(glyf_table_data + offset, 0, (size_t) (g->gd[i].length + (ULONG) padlen));
+ memcpy(glyf_table_data + offset, g->gd[i].data, g->gd[i].length);
+ offset += (g->gd[i].length + (ULONG) padlen);
+
+ }
prev = g->gd[i].gid;
- /* free data here since it consume much memory */
RELEASE(g->gd[i].data);
+ /* free data here since it consume much memory */
g->gd[i].length = 0;
g->gd[i].data = NULL;
}
@@ -478,12 +508,12 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g)
q += sfnt_put_ulong(q, (LONG) offset);
}
- sfnt_set_table(sfont, "hmtx", (char *) hmtx_table_data,
- hmtx_table_size);
- sfnt_set_table(sfont, "loca", (char *) loca_table_data,
- loca_table_size);
- sfnt_set_table(sfont, "glyf", (char *) glyf_table_data,
- glyf_table_size);
+ sfnt_set_table(sfont, "hmtx", (char *) hmtx_table_data, hmtx_table_size);
+ sfnt_set_table(sfont, "loca", (char *) loca_table_data, loca_table_size);
+ if (callback_id > 0) {
+ glyf_table_size = glyf_table_used;
+ }
+ sfnt_set_table(sfont, "glyf", (char *) glyf_table_data, glyf_table_size);
}
head->checkSumAdjustment = 0;
diff --git a/Build/source/texk/web2c/luatexdir/font/writecff.h b/Build/source/texk/web2c/luatexdir/font/writecff.h
index 3063eadb0c5..1a24df483b4 100644
--- a/Build/source/texk/web2c/luatexdir/font/writecff.h
+++ b/Build/source/texk/web2c/luatexdir/font/writecff.h
@@ -1,5 +1,5 @@
/* writecff.h
-
+
Copyright 2002 by Jin-Hwan Cho and Shunsaku Hirata,
the dvipdfmx project team <dvipdfmx@project.ktug.or.kr>
Copyright 2006-2008 Taco Hoekwater <taco@luatex.org>
@@ -327,11 +327,6 @@ typedef struct {
} seac; /* unused in Type 2 charstring */
} cs_ginfo;
-extern long cs_copy_charstring(card8 * dest, long destlen,
- card8 * src, long srclen,
- cff_index * gsubr, cff_index * subr,
- double default_width, double nominal_width,
- cs_ginfo * ginfo);
#endif /* _CS_TYPE2_H_ */
#define cff_is_cidfont(a) (a->flag & FONTTYPE_CIDFONT)
diff --git a/Build/source/texk/web2c/luatexdir/font/writecff.w b/Build/source/texk/web2c/luatexdir/font/writecff.w
index 2c95ac88e41..9707c751e25 100644
--- a/Build/source/texk/web2c/luatexdir/font/writecff.w
+++ b/Build/source/texk/web2c/luatexdir/font/writecff.w
@@ -19,7 +19,6 @@
@ @c
-
#include "ptexlib.h"
#include "lua/luatex-api.h"
#include "font/writecff.h"
@@ -30,6 +29,7 @@ extern int cidset;
#define get_offset(s,n) get_unsigned(s, (n))
#define get_card8(a) (card8)(a->stream[a->offset++])
#define get_card16(a) (card16)(get_unsigned(a,2))
+#define get_card32(a) (get_unsigned(a,4))
#undef b0
#undef b1
@@ -146,75 +146,61 @@ const char *const cff_stdstr[CFF_STDSTR_MAX] = {
"Black", "Bold", "Book", "Light", "Medium", "Regular", "Roman", "Semibold"
};
-
@ Only read header part but not body
@c
cff_index *cff_get_index_header(cff_font * cff)
{
cff_index *idx;
card16 i, count;
-
idx = xcalloc(1, sizeof(cff_index));
-
- idx->count = count = get_card16(cff);
+ if (cff->header_major == 2) {
+ idx->count = count = get_card32(cff);
+ } else {
+ idx->count = count = get_card16(cff);
+ }
if (count > 0) {
idx->offsize = get_card8(cff);
if (idx->offsize < 1 || idx->offsize > 4)
- normal_error("cff","invalid offsize data");
-
- idx->offset =
- xmalloc((unsigned) (((unsigned) count + 1) * sizeof(l_offset)));
+ normal_error("cff","invalid offsize data (1)");
+ idx->offset = xmalloc((unsigned) (((unsigned) count + 1) * sizeof(l_offset)));
for (i = 0; i <count + 1 ; i++) {
(idx->offset)[i] = get_offset(cff, idx->offsize);
if (i == USHRT_MAX)
break;
}
-
if (idx->offset[0] != 1)
normal_error("cff","invalid index data");
-
idx->data = NULL;
} else {
idx->offsize = 0;
idx->offset = NULL;
idx->data = NULL;
}
-
return idx;
}
-
-
@ @c
cff_index *cff_get_index(cff_font * cff)
{
cff_index *idx;
card16 i, count;
size_t length;
-
idx = xcalloc(1, sizeof(cff_index));
-
idx->count = count = get_card16(cff);
if (count > 0) {
idx->offsize = get_card8(cff);
if (idx->offsize < 1 || idx->offsize > 4)
- normal_error("cff","invalid offsize data");
-
- idx->offset =
- xmalloc((unsigned) (((unsigned) count + 1) * sizeof(l_offset)));
+ normal_error("cff","invalid offsize data (2)");
+ idx->offset = xmalloc((unsigned) (((unsigned) count + 1) * sizeof(l_offset)));
for (i = 0; i < count + 1; i++) {
idx->offset[i] = get_offset(cff, idx->offsize);
}
-
if (idx->offset[0] != 1)
normal_error("cff","invalid index offset data");
-
length = (size_t) (idx->offset[count] - idx->offset[0]);
-
idx->data = xmalloc((unsigned) length * sizeof(card8));
memcpy(idx->data, &cff->stream[cff->offset], length);
cff->offset += length;
-
} else {
idx->offsize = 0;
idx->offset = NULL;
@@ -223,6 +209,40 @@ cff_index *cff_get_index(cff_font * cff)
return idx;
}
+static cff_index *cff_empty_index(cff_font * cff)
+{
+ cff_index *idx;
+ idx = xcalloc(1, sizeof(cff_index));
+ idx->count = 0;
+ idx->offsize = 0;
+ idx->offset = NULL;
+ idx->data = NULL;
+ return idx;
+}
+
+static cff_index *cff_get_index2(cff_font * cff)
+{
+ /* we fake a dict array */
+
+ cff_index *idx;
+ size_t length;
+
+ idx = xcalloc(1, sizeof(cff_index));
+
+ length = (size_t) cff->header_offsize;
+
+ idx->offsize = 2;
+ idx->count = 1;
+ idx->offset = xmalloc((unsigned) (((unsigned) 2) * sizeof(l_offset)));
+ idx->offset[0] = 1; // get_offset(cff, idx->offsize);
+ idx->offset[1] = length + 1; // idx->offset[0] + length;
+
+ idx->data = xmalloc((unsigned) length * sizeof(card8));
+ memcpy(idx->data, &cff->stream[cff->offset], length );
+ cff->offset += length ;
+
+ return idx;
+}
@ @c
long cff_pack_index(cff_index * idx, card8 * dest, long destlen)
@@ -230,23 +250,18 @@ long cff_pack_index(cff_index * idx, card8 * dest, long destlen)
long len = 0;
unsigned long datalen;
card16 i;
-
if (idx->count < 1) {
if (destlen < 2)
normal_error("cff","not enough space available");
memset(dest, 0, 2);
return 2;
}
-
len = cff_index_size(idx);
datalen = idx->offset[idx->count] - 1;
-
if (destlen < len)
normal_error("cff","not enough space available");
-
*(dest++) = (card8) ((idx->count >> 8) & 0xff);
*(dest++) = (card8) (idx->count & 0xff);
-
if (datalen < 0xffUL) {
idx->offsize = 1;
*(dest++) = 1;
@@ -278,9 +293,7 @@ long cff_pack_index(cff_index * idx, card8 * dest, long destlen)
*(dest++) = (card8) (idx->offset[i] & 0xff);
}
}
-
memmove(dest, idx->data, idx->offset[idx->count] - 1);
-
return len;
}
@@ -289,7 +302,6 @@ long cff_index_size(cff_index * idx)
{
if (idx->count > 0) {
l_offset datalen;
-
datalen = idx->offset[idx->count] - 1;
if (datalen < 0xffUL) {
idx->offsize = 1;
@@ -310,11 +322,9 @@ long cff_index_size(cff_index * idx)
cff_index *cff_new_index(card16 count)
{
cff_index *idx;
-
idx = xcalloc(1, sizeof(cff_index));
idx->count = count;
idx->offsize = 0;
-
if (count > 0) {
idx->offset = xcalloc((unsigned) (count + 1), sizeof(l_offset));
(idx->offset)[0] = 1;
@@ -322,11 +332,9 @@ cff_index *cff_new_index(card16 count)
idx->offset = NULL;
}
idx->data = NULL;
-
return idx;
}
-
@ @c
void cff_release_index(cff_index * idx)
{
@@ -352,7 +360,6 @@ void cff_release_dict(cff_dict * dict)
}
}
-
@ @c
void cff_release_encoding(cff_encoding * encoding)
{
@@ -407,12 +414,10 @@ void cff_release_fdselect(cff_fdselect * fdselect)
}
}
-
@ @c
void cff_close(cff_font * cff)
{
card16 i;
-
if (cff) {
xfree(cff->fontname);
if (cff->name)
@@ -456,7 +461,6 @@ void cff_close(cff_font * cff)
cff_release_index(cff->_string);
xfree(cff);
}
-
return;
}
@@ -466,28 +470,22 @@ char *cff_get_name(cff_font * cff)
char *fontname;
l_offset len;
cff_index *idx;
-
idx = cff->name;
len = idx->offset[cff->index + 1] - idx->offset[cff->index];
fontname = xmalloc((unsigned) (len + 1) * sizeof(char));
memcpy(fontname, idx->data + idx->offset[cff->index] - 1, len);
fontname[len] = '\0';
-
return fontname;
}
-
@ @c
long cff_set_name(cff_font * cff, char *name)
{
cff_index *idx;
-
if (strlen(name) > 127)
normal_error("cff","FontName string length too large");
-
if (cff->name)
cff_release_index(cff->name);
-
cff->name = idx = xcalloc(1, sizeof(cff_index));
idx->count = 1;
idx->offsize = 1;
@@ -495,8 +493,7 @@ long cff_set_name(cff_font * cff, char *name)
(idx->offset)[0] = 1;
(idx->offset)[1] = strlen(name) + 1;
idx->data = xmalloc((unsigned) strlen(name) * sizeof(card8));
- memmove(idx->data, name, strlen(name)); /* no trailing |'\0'| */
-
+ memmove(idx->data, name, strlen(name)); /* no trailing |'\0'| */
return (long) (5 + strlen(name));
}
@@ -505,15 +502,16 @@ long cff_put_header(cff_font * cff, card8 * dest, long destlen)
if (destlen < 4)
normal_error("cff","not enough space available");
- *(dest++) = cff->header_major;
+ *(dest++) = 1; /* cff->header_major; */
*(dest++) = cff->header_minor;
- *(dest++) = 4; /* Additional data in between header and
- * Name INDEX ignored.
- */
- /* We will set all offset (0) to four-byte integer. */
*(dest++) = 4;
- cff->header_offsize = 4;
+ /*
+ Additional data in between header and Name INDEX is ignored.
+ We will set all offset (0) to a four-byte integer.
+ */
+ *(dest++) = 4;
+ cff->header_offsize = 4;
return 4;
}
@@ -529,7 +527,6 @@ long cff_put_header(cff_font * cff, card8 * dest, long destlen)
cff_dict *cff_new_dict(void)
{
cff_dict *dict;
-
dict = xcalloc(1, sizeof(cff_dict));
dict->max = DICT_ENTRY_MAX;
dict->count = 0;
@@ -537,30 +534,22 @@ cff_dict *cff_new_dict(void)
return dict;
}
-@
-
-Operand stack:
- only numbers are stored (as double)
+@ Operand stack: only numbers are stored (as double). Operand types are:
-Operand types:
-
-number : double (integer or real)
-boolean: stored as a number
-SID : stored as a number
-array : array of numbers
-delta : array of numbers
+\item number: double (integer or real)
+\item boolean: stored as a number
+\item SID: stored as a number
+\item array: array of numbers
+\item delta: array of numbers
@c
#define CFF_DICT_STACK_LIMIT 64
static int stack_top = 0;
static double arg_stack[CFF_DICT_STACK_LIMIT];
-@
-CFF DICT encoding:
-TODO: default values
-
+@ CFF DICT encoding.
@c
-#define CFF_LAST_DICT_OP1 22
+#define CFF_LAST_DICT_OP1 26 /* 22 */
#define CFF_LAST_DICT_OP2 39
#define CFF_LAST_DICT_OP (CFF_LAST_DICT_OP1 + CFF_LAST_DICT_OP2)
@@ -568,78 +557,73 @@ static struct {
const char *opname;
int argtype;
} dict_operator[CFF_LAST_DICT_OP] = {
- {
- "version", CFF_TYPE_SID}, {
- "Notice", CFF_TYPE_SID}, {
- "FullName", CFF_TYPE_SID}, {
- "FamilyName", CFF_TYPE_SID}, {
- "Weight", CFF_TYPE_SID}, {
- "FontBBox", CFF_TYPE_ARRAY}, {
- "BlueValues", CFF_TYPE_DELTA}, {
- "OtherBlues", CFF_TYPE_DELTA}, {
- "FamilyBlues", CFF_TYPE_DELTA}, {
- "FamilyOtherBlues", CFF_TYPE_DELTA}, {
- "StdHW", CFF_TYPE_NUMBER}, {
- "StdVW", CFF_TYPE_NUMBER}, {
- NULL, -1}, /* first byte of two-byte operator */
- /* Top */
- {
- "UniqueID", CFF_TYPE_NUMBER}, {
- "XUID", CFF_TYPE_ARRAY}, {
- "charset", CFF_TYPE_OFFSET}, {
- "Encoding", CFF_TYPE_OFFSET}, {
- "CharStrings", CFF_TYPE_OFFSET}, {
- "Private", CFF_TYPE_SZOFF}, /* two numbers (size and offset) */
- /* Private */
- {
- "Subrs", CFF_TYPE_OFFSET}, {
- "defaultWidthX", CFF_TYPE_NUMBER}, {
- "nominalWidthX", CFF_TYPE_NUMBER},
- /* Operator 2 */
- {
- "Copyright", CFF_TYPE_SID}, {
- "IsFixedPitch", CFF_TYPE_BOOLEAN}, {
- "ItalicAngle", CFF_TYPE_NUMBER}, {
- "UnderlinePosition", CFF_TYPE_NUMBER}, {
- "UnderlineThickness", CFF_TYPE_NUMBER}, {
- "PaintType", CFF_TYPE_NUMBER}, {
- "CharstringType", CFF_TYPE_NUMBER}, {
- "FontMatrix", CFF_TYPE_ARRAY}, {
- "StrokeWidth", CFF_TYPE_NUMBER}, {
- "BlueScale", CFF_TYPE_NUMBER}, {
- "BlueShift", CFF_TYPE_NUMBER}, {
- "BlueFuzz", CFF_TYPE_NUMBER}, {
- "StemSnapH", CFF_TYPE_DELTA}, {
- "StemSnapV", CFF_TYPE_DELTA}, {
- "ForceBold", CFF_TYPE_BOOLEAN}, {
- NULL, -1}, {
- NULL, -1}, {
- "LanguageGroup", CFF_TYPE_NUMBER}, {
- "ExpansionFactor", CFF_TYPE_NUMBER}, {
- "InitialRandomSeed", CFF_TYPE_NUMBER}, {
- "SyntheticBase", CFF_TYPE_NUMBER}, {
- "PostScript", CFF_TYPE_SID}, {
- "BaseFontName", CFF_TYPE_SID}, {
- "BaseFontBlend", CFF_TYPE_DELTA}, /* MMaster ? */
- {
- NULL, -1}, {
- NULL, -1}, {
- NULL, -1}, {
- NULL, -1}, {
- NULL, -1}, {
- NULL, -1},
- /* CID-Keyed font */
- {
- "ROS", CFF_TYPE_ROS}, /* SID SID number */
- {
- "CIDFontVersion", CFF_TYPE_NUMBER}, {
- "CIDFontRevision", CFF_TYPE_NUMBER}, {
- "CIDFontType", CFF_TYPE_NUMBER}, {
- "CIDCount", CFF_TYPE_NUMBER}, {
- "UIDBase", CFF_TYPE_NUMBER}, {
- "FDArray", CFF_TYPE_OFFSET}, {
- "FDSelect", CFF_TYPE_OFFSET}, {
-"FontName", CFF_TYPE_SID},};
+ { "version", CFF_TYPE_SID },
+ { "Notice", CFF_TYPE_SID },
+ { "FullName", CFF_TYPE_SID },
+ { "FamilyName", CFF_TYPE_SID },
+ { "Weight", CFF_TYPE_SID },
+ { "FontBBox", CFF_TYPE_ARRAY },
+ { "BlueValues", CFF_TYPE_DELTA },
+ { "OtherBlues", CFF_TYPE_DELTA },
+ { "FamilyBlues", CFF_TYPE_DELTA },
+ { "FamilyOtherBlues", CFF_TYPE_DELTA },
+ { "StdHW", CFF_TYPE_NUMBER },
+ { "StdVW", CFF_TYPE_NUMBER },
+ { NULL, -1 }, /* first byte of two-byte operator 12 */
+ { "UniqueID", CFF_TYPE_NUMBER },
+ { "XUID", CFF_TYPE_ARRAY },
+ { "charset", CFF_TYPE_OFFSET },
+ { "Encoding", CFF_TYPE_OFFSET },
+ { "CharStrings", CFF_TYPE_OFFSET },
+ { "Private", CFF_TYPE_SZOFF }, /* two numbers (size and offset) */
+ { "Subrs", CFF_TYPE_OFFSET },
+ { "defaultWidthX", CFF_TYPE_NUMBER },
+ { "nominalWidthX", CFF_TYPE_NUMBER },
+ { NULL, -1 },
+ { NULL, -1 },
+ { "vstore", CFF_TYPE_OFFSET }, /* cff2 */
+ { "maxstack", CFF_TYPE_NUMBER }, /* cff2 */
+ /* Here we start with operator 2 of 12 */
+ { "Copyright", CFF_TYPE_SID },
+ { "IsFixedPitch", CFF_TYPE_BOOLEAN },
+ { "ItalicAngle", CFF_TYPE_NUMBER },
+ { "UnderlinePosition", CFF_TYPE_NUMBER },
+ { "UnderlineThickness", CFF_TYPE_NUMBER },
+ { "PaintType", CFF_TYPE_NUMBER },
+ { "CharstringType", CFF_TYPE_NUMBER },
+ { "FontMatrix", CFF_TYPE_ARRAY },
+ { "StrokeWidth", CFF_TYPE_NUMBER },
+ { "BlueScale", CFF_TYPE_NUMBER },
+ { "BlueShift", CFF_TYPE_NUMBER },
+ { "BlueFuzz", CFF_TYPE_NUMBER },
+ { "StemSnapH", CFF_TYPE_DELTA },
+ { "StemSnapV", CFF_TYPE_DELTA },
+ { "ForceBold", CFF_TYPE_BOOLEAN },
+ { NULL, -1 },
+ { NULL, -1 },
+ { "LanguageGroup", CFF_TYPE_NUMBER },
+ { "ExpansionFactor", CFF_TYPE_NUMBER },
+ { "InitialRandomSeed", CFF_TYPE_NUMBER },
+ { "SyntheticBase", CFF_TYPE_NUMBER },
+ { "PostScript", CFF_TYPE_SID },
+ { "BaseFontName", CFF_TYPE_SID },
+ { "BaseFontBlend", CFF_TYPE_DELTA },
+ { NULL, -1 },
+ { NULL, -1 },
+ { NULL, -1 },
+ { NULL, -1 },
+ { NULL, -1 },
+ { NULL, -1 },
+ { "ROS", CFF_TYPE_ROS },
+ { "CIDFontVersion", CFF_TYPE_NUMBER },
+ { "CIDFontRevision", CFF_TYPE_NUMBER },
+ { "CIDFontType", CFF_TYPE_NUMBER },
+ { "CIDCount", CFF_TYPE_NUMBER },
+ { "UIDBase", CFF_TYPE_NUMBER },
+ { "FDArray", CFF_TYPE_OFFSET },
+ { "FDSelect", CFF_TYPE_OFFSET },
+ { "FontName", CFF_TYPE_SID }
+};
@ Parse DICT data
@c
@@ -833,12 +817,10 @@ cff_dict *cff_dict_unpack(card8 * data, card8 * endptr)
{
cff_dict *dict;
int status = CFF_PARSE_OK;
-
stack_top = 0;
-
dict = cff_new_dict();
while (data < endptr && status == CFF_PARSE_OK) {
- if (*data < 22) { /* operator */
+ if (*data < CFF_LAST_DICT_OP1) { /* operator */
add_dict(dict, &data, endptr, &status);
} else if (*data == 30) { /* real - First byte of a sequence (variable) */
if (stack_top < CFF_DICT_STACK_LIMIT) {
@@ -847,7 +829,7 @@ cff_dict *cff_dict_unpack(card8 * data, card8 * endptr)
} else {
status = CFF_CFF_ERROR_STACK_OVERFLOW;
}
- } else if (*data == 255 || (*data >= 22 && *data <= 27)) { /* reserved */
+ } else if (*data == 255 || (*data >= CFF_LAST_DICT_OP1 && *data <= 27)) { /* reserved */
data++;
} else { /* everything else are integer */
if (stack_top < CFF_DICT_STACK_LIMIT) {
@@ -858,14 +840,12 @@ cff_dict *cff_dict_unpack(card8 * data, card8 * endptr)
}
}
}
-
if (status != CFF_PARSE_OK) {
formatted_error("cff","parsing DICT failed (error=%d)", status);
} else if (stack_top != 0) {
normal_warning("cff","garbage in DICT data");
stack_top = 0;
}
-
return dict;
}
@@ -873,13 +853,11 @@ cff_dict *cff_dict_unpack(card8 * data, card8 * endptr)
int cff_dict_known(cff_dict * dict, const char *key)
{
int i;
-
for (i = 0; i < dict->count; i++) {
if (key && strcmp(key, (dict->entries)[i].key) == 0
&& (dict->entries)[i].count > 0)
return 1;
}
-
return 0;
}
@@ -888,9 +866,7 @@ double cff_dict_get(cff_dict * dict, const char *key, int idx)
{
double value = 0.0;
int i;
-
assert(key && dict);
-
for (i = 0; i < dict->count; i++) {
if (strcmp(key, (dict->entries)[i].key) == 0) {
if ((dict->entries)[i].count > idx)
@@ -900,10 +876,8 @@ double cff_dict_get(cff_dict * dict, const char *key, int idx)
break;
}
}
-
if (i == dict->count)
formatted_error("cff","DICT entry '%s' not found", key);
-
return value;
}
@@ -957,7 +931,6 @@ long cff_read_subrs(cff_font * cff)
long offset;
int i;
-
if ((cff->flag & FONTTYPE_CIDFONT) && cff->fdselect == NULL) {
cff_read_fdselect(cff);
}
@@ -988,23 +961,19 @@ long cff_read_subrs(cff_font * cff)
len += cff_index_size((cff->subrs)[i]);
}
}
+ } else if (cff->private[0] == NULL || !cff_dict_known(cff->private[0], "Subrs")) {
+ (cff->subrs)[0] = NULL;
} else {
- if (cff->private[0] == NULL ||
- !cff_dict_known(cff->private[0], "Subrs")) {
- (cff->subrs)[0] = NULL;
- } else {
- offset = (long) cff_dict_get(cff->topdict, "Private", 1);
- offset += (long) cff_dict_get(cff->private[0], "Subrs", 0);
- cff->offset = (l_offset) offset;
- (cff->subrs)[0] = cff_get_index(cff);
- len += cff_index_size((cff->subrs)[0]);
- }
+ offset = (long) cff_dict_get(cff->topdict, "Private", 1);
+ offset += (long) cff_dict_get(cff->private[0], "Subrs", 0);
+ cff->offset = (l_offset) offset;
+ (cff->subrs)[0] = cff_get_index(cff);
+ len += cff_index_size((cff->subrs)[0]);
}
return len;
}
-
@ @c
long cff_read_fdarray(cff_font * cff)
{
@@ -1057,9 +1026,8 @@ long cff_read_private(cff_font * cff)
cff->private = xmalloc((unsigned) (cff->num_fds * sizeof(cff_dict *)));
for (i = 0; i < cff->num_fds; i++) {
if (cff->fdarray[i] != NULL &&
- cff_dict_known(cff->fdarray[i], "Private") &&
- (size = (long) cff_dict_get(cff->fdarray[i], "Private", 0))
- > 0) {
+ cff_dict_known(cff->fdarray[i], "Private") &&
+ (size = (long) cff_dict_get(cff->fdarray[i], "Private", 0)) > 0) {
offset = (long) cff_dict_get(cff->fdarray[i], "Private", 1);
cff->offset = (l_offset) offset;
data = xmalloc((unsigned) size * sizeof(card8));
@@ -1076,7 +1044,7 @@ long cff_read_private(cff_font * cff)
cff->num_fds = 1;
cff->private = xmalloc(sizeof(cff_dict *));
if (cff_dict_known(cff->topdict, "Private") &&
- (size = (long) cff_dict_get(cff->topdict, "Private", 0)) > 0) {
+ (size = (long) cff_dict_get(cff->topdict, "Private", 0)) > 0) {
offset = (long) cff_dict_get(cff->topdict, "Private", 1);
cff->offset = (l_offset) offset;
data = xmalloc((unsigned) size * sizeof(card8));
@@ -1102,7 +1070,6 @@ cff_font *read_cff(unsigned char *buf, long buflength, int n)
cff_index *idx;
long offset;
-
cff = xcalloc(1, sizeof(cff_font));
cff->stream = buf;
@@ -1112,13 +1079,18 @@ cff_font *read_cff(unsigned char *buf, long buflength, int n)
cff->header_major = get_card8(cff);
cff->header_minor = get_card8(cff);
cff->header_hdr_size = get_card8(cff);
- cff->header_offsize = get_card8(cff);
- if (cff->header_offsize < 1 || cff->header_offsize > 4) {
- normal_warning("cff","invalid offsize data");
- cff_close(cff);
- return NULL;
+ if (cff->header_major == 2) {
+ /* we have only one top dictionary */
+ cff->header_offsize = get_card16(cff);
+ } else {
+ cff->header_offsize = get_card8(cff);
+ if (cff->header_offsize < 1 || cff->header_offsize > 4) {
+ normal_warning("cff","invalid offsize data (4)");
+ cff_close(cff);
+ return NULL;
+ }
}
- if (cff->header_major > 1) {
+ if (cff->header_major > 2) {
formatted_warning("cff","major version %u not supported", cff->header_major);
cff_close(cff);
return NULL;
@@ -1126,19 +1098,27 @@ cff_font *read_cff(unsigned char *buf, long buflength, int n)
cff->offset = cff->header_hdr_size;
/* Name INDEX */
- idx = cff_get_index(cff);
- if (n > idx->count - 1) {
- normal_warning("cff","invalid fontset index number");
- cff_close(cff);
- return NULL;
+ if (cff->header_major == 2) {
+ cff->name = cff_empty_index(cff);
+ } else {
+ idx = cff_get_index(cff);
+ if (n > idx->count - 1) {
+ normal_warning("cff","invalid fontset index number");
+ cff_close(cff);
+ return NULL;
+ }
+ cff->name = idx;
+ cff->fontname = cff_get_name(cff);
}
- cff->name = idx;
-
- cff->fontname = cff_get_name(cff);
-
/* Top DICT INDEX */
- idx = cff_get_index(cff);
+ if (cff->header_major == 2) {
+ /* we fake an index (just one entry) */
+ idx = cff_get_index2(cff);
+ } else {
+ idx = cff_get_index(cff);
+ }
+
if (n > idx->count - 1) {
normal_warning("cff","top DICT not exist");
cff_close(cff);
@@ -1167,7 +1147,11 @@ cff_font *read_cff(unsigned char *buf, long buflength, int n)
}
/* String INDEX */
- cff->string = cff_get_index(cff);
+ if (cff->header_major == 2) {
+ // cff->string = cff_empty_index(cff);
+ } else {
+ cff->string = cff_get_index(cff);
+ }
/* offset to GSubr */
cff->gsubr_offset = cff->offset;
@@ -1211,33 +1195,33 @@ static long pack_integer(card8 * dest, long destlen, long value)
if (value >= -107 && value <= 107) {
if (destlen < 1)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (1)");
dest[0] = (card8) ((value + 139) & 0xff);
len = 1;
} else if (value >= 108 && value <= 1131) {
if (destlen < 2)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (2)");
value = (long) 0xf700u + value - 108;
dest[0] = (card8) ((value >> 8) & 0xff);
dest[1] = (card8) (value & 0xff);
len = 2;
} else if (value >= -1131 && value <= -108) {
if (destlen < 2)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (3)");
value = (long) 0xfb00u - value - 108;
dest[0] = (card8) ((value >> 8) & 0xff);
dest[1] = (card8) (value & 0xff);
len = 2;
} else if (value >= -32768 && value <= 32767) { /* shortint */
if (destlen < 3)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (4)");
dest[0] = 28;
dest[1] = (card8) ((value >> 8) & 0xff);
dest[2] = (card8) (value & 0xff);
len = 3;
} else { /* longint */
if (destlen < 5)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (5)");
dest[0] = 29;
dest[1] = (card8) ((value >> 24) & 0xff);
dest[2] = (card8) ((value >> 16) & 0xff);
@@ -1257,7 +1241,7 @@ static long pack_real(card8 * dest, long destlen, double value)
#define CFF_REAL_MAX_LEN 17
if (destlen < 2)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (6)");
dest[0] = 30;
@@ -1305,7 +1289,7 @@ static long pack_real(card8 * dest, long destlen, double value)
}
if (destlen < pos / 2 + 1)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (7)");
if (pos % 2) {
dest[pos / 2] = (card8) (dest[pos / 2] + ch);
@@ -1320,7 +1304,7 @@ static long pack_real(card8 * dest, long destlen, double value)
dest[pos / 2] = (card8) (dest[pos / 2] + 0x0b);
} else {
if (destlen < pos / 2 + 1)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (8)");
dest[pos / 2] = (card8) (0xb0);
}
pos++;
@@ -1329,7 +1313,7 @@ static long pack_real(card8 * dest, long destlen, double value)
dest[pos / 2] = (card8) (dest[pos / 2] + 0x0c);
} else {
if (destlen < pos / 2 + 1)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (9)");
dest[pos / 2] = (card8) (0xc0);
}
e *= -1;
@@ -1351,7 +1335,7 @@ static long pack_real(card8 * dest, long destlen, double value)
}
if (destlen < pos / 2 + 1)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (10)");
if (pos % 2) {
dest[pos / 2] = (card8) (dest[pos / 2] + ch);
@@ -1367,7 +1351,7 @@ static long pack_real(card8 * dest, long destlen, double value)
pos++;
} else {
if (destlen < pos / 2 + 1)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (11)");
dest[pos / 2] = (card8) (0xff);
pos += 2;
}
@@ -1386,10 +1370,9 @@ static long cff_dict_put_number(double value,
/* set offset to longint */
if (type == CFF_TYPE_OFFSET) {
long lvalue;
-
lvalue = (long) value;
if (destlen < 5)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (12)");
dest[0] = 29;
dest[1] = (card8) ((lvalue >> 24) & 0xff);
dest[2] = (card8) ((lvalue >> 16) & 0xff);
@@ -1420,16 +1403,15 @@ static long put_dict_entry(cff_dict_entry * de, card8 * dest, long destlen)
type = CFF_TYPE_NUMBER;
}
for (i = 0; i < de->count; i++) {
- len += cff_dict_put_number(de->values[i],
- dest + len, destlen - len, type);
+ len += cff_dict_put_number(de->values[i], dest + len, destlen - len, type);
}
if (id >= 0 && id < CFF_LAST_DICT_OP1) {
if (len + 1 > destlen)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (13)");
dest[len++] = (card8) id;
} else if (id >= 0 && id < CFF_LAST_DICT_OP) {
if (len + 2 > destlen)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (14)");
dest[len++] = 12;
dest[len++] = (card8) (id - CFF_LAST_DICT_OP1);
} else {
@@ -1461,7 +1443,6 @@ long cff_dict_pack(cff_dict * dict, card8 * dest, long destlen)
return len;
}
-
@ @c
void cff_dict_add(cff_dict * dict, const char *key, int count)
{
@@ -1506,7 +1487,6 @@ void cff_dict_add(cff_dict * dict, const char *key, int count)
return;
}
-
@ @c
void cff_dict_remove(cff_dict * dict, const char *key)
{
@@ -1593,90 +1573,81 @@ long cff_get_sid(cff_font * cff, const char *str)
return -1;
}
-
@ @c
void cff_update_string(cff_font * cff)
{
if (cff == NULL)
normal_error("cff","CFF font not opened");
-
if (cff->string)
cff_release_index(cff->string);
cff->string = cff->_string;
cff->_string = NULL;
}
-
@ @c
s_SID cff_add_string(cff_font * cff, const char *str)
{
card16 idx;
cff_index *strings;
l_offset offset, size;
-
- if (cff == NULL)
+ if (cff == NULL) {
normal_error("cff","CFF font not opened");
-
- if (cff->_string == NULL)
+ }
+ if (cff->_string == NULL) {
cff->_string = cff_new_index(0);
+ }
strings = cff->_string;
-
for (idx = 0; idx < strings->count; idx++) {
size = strings->offset[idx + 1] - strings->offset[idx];
offset = strings->offset[idx];
- if (size == strlen(str) &&
- !memcmp(strings->data + offset - 1, str, strlen(str)))
+ if (size == strlen(str) && !memcmp(strings->data + offset - 1, str, strlen(str))) {
return (s_SID) (idx + CFF_STDSTR_MAX);
+ }
}
-
for (idx = 0; idx < CFF_STDSTR_MAX; idx++) {
- if (cff_stdstr[idx] && !strcmp(cff_stdstr[idx], str))
+ if (cff_stdstr[idx] && !strcmp(cff_stdstr[idx], str)) {
return idx;
+ }
}
offset = (strings->count > 0) ? strings->offset[strings->count] : 1;
- strings->offset =
- xrealloc(strings->offset,
- (unsigned) (((unsigned) strings->count +
- 2) * sizeof(l_offset)));
+ strings->offset = xrealloc(strings->offset, (unsigned) (((unsigned) strings->count + 2) * sizeof(l_offset)));
if (strings->count == 0)
strings->offset[0] = 1;
idx = strings->count;
strings->count = (card16) (strings->count + 1);
strings->offset[strings->count] = offset + strlen(str);
- strings->data =
- xrealloc(strings->data,
- (unsigned) ((offset + strlen(str) - 1) * sizeof(card8)));
+ strings->data = xrealloc(strings->data, (unsigned) ((offset + strlen(str) - 1) * sizeof(card8)));
memcpy(strings->data + offset - 1, str, strlen(str));
-
return (s_SID) (idx + CFF_STDSTR_MAX);
}
-
@ @c
void cff_dict_update(cff_dict * dict, cff_font * cff)
{
int i;
-
for (i = 0; i < dict->count; i++) {
if ((dict->entries)[i].count > 0) {
char *str;
int id;
-
id = (dict->entries)[i].id;
-
if (dict_operator[id].argtype == CFF_TYPE_SID) {
str = cff_get_string(cff, (s_SID) (dict->entries)[i].values[0]);
- (dict->entries)[i].values[0] = cff_add_string(cff, str);
- xfree(str);
+ if (str != NULL) {
+ (dict->entries)[i].values[0] = cff_add_string(cff, str);
+ xfree(str);
+ }
} else if (dict_operator[id].argtype == CFF_TYPE_ROS) {
str = cff_get_string(cff, (s_SID) (dict->entries)[i].values[0]);
- (dict->entries)[i].values[0] = cff_add_string(cff, str);
- xfree(str);
+ if (str != NULL) {
+ (dict->entries)[i].values[0] = cff_add_string(cff, str);
+ xfree(str);
+ }
str = cff_get_string(cff, (s_SID) (dict->entries)[i].values[1]);
- (dict->entries)[i].values[1] = cff_add_string(cff, str);
- xfree(str);
+ if (str != NULL) {
+ (dict->entries)[i].values[1] = cff_add_string(cff, str);
+ xfree(str);
+ }
}
-
}
}
}
@@ -1775,7 +1746,6 @@ long cff_read_charsets(cff_font * cff)
}
if (count > 0) {
- /* fprintf(stdout, "count=%d\n", count); */
normal_warning("cff","charset data possibly broken (too many glyphs)");
}
@@ -1793,7 +1763,7 @@ long cff_pack_charsets(cff_font * cff, card8 * dest, long destlen)
return 0;
if (destlen < 1)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (15)");
charset = cff->charsets;
@@ -1801,7 +1771,7 @@ long cff_pack_charsets(cff_font * cff, card8 * dest, long destlen)
switch (charset->format) {
case 0:
if (destlen < len + (charset->num_entries) * 2)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (16)");
for (i = 0; i < (charset->num_entries); i++) {
s_SID sid = (charset->data).glyphs[i]; /* or CID */
dest[len++] = (card8) ((sid >> 8) & 0xff);
@@ -1811,10 +1781,9 @@ long cff_pack_charsets(cff_font * cff, card8 * dest, long destlen)
case 1:
{
if (destlen < len + (charset->num_entries) * 3)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (17)");
for (i = 0; i < (charset->num_entries); i++) {
- dest[len++] =
- (card8) (((charset->data).range1[i].first >> 8) & 0xff);
+ dest[len++] = (card8) (((charset->data).range1[i].first >> 8) & 0xff);
dest[len++] = (card8) ((charset->data).range1[i].first & 0xff);
dest[len++] = (card8) ((charset->data).range1[i].n_left);
}
@@ -1823,13 +1792,11 @@ long cff_pack_charsets(cff_font * cff, card8 * dest, long destlen)
case 2:
{
if (destlen < len + (charset->num_entries) * 4)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (18)");
for (i = 0; i < (charset->num_entries); i++) {
- dest[len++] =
- (card8) (((charset->data).range2[i].first >> 8) & 0xff);
+ dest[len++] = (card8) (((charset->data).range2[i].first >> 8) & 0xff);
dest[len++] = (card8) ((charset->data).range2[i].first & 0xff);
- dest[len++] =
- (card8) (((charset->data).range2[i].n_left >> 8) & 0xff);
+ dest[len++] = (card8) (((charset->data).range2[i].n_left >> 8) & 0xff);
dest[len++] = (card8) ((charset->data).range2[i].n_left & 0xff);
}
}
@@ -1869,7 +1836,6 @@ number in the range (0, 1] and push them into argument stack.
How pseudo-random sequences are generated is not documented in the Type 2
charstring spec..
-
@c
#define CS_TYPE2_DEBUG_STR "Type2 Charstring Parser"
#define CS_TYPE2_DEBUG 5
@@ -1900,10 +1866,9 @@ static int cs2_nest = 0;
static int have_width = 0;
static double width = 0.0;
-@
- Standard Encoding Accented Characters:
- Optional four arguments for endchar. See, CFF spec., p.35.
- This is obsolete feature and is no longer supported.
+@ Standard Encoding Accented Characters: Optional four arguments for
+endchar. See, CFF spec., p.35. This is obsolete feature and is no longer
+supported.
@c
#if 0
/* adx ady bchar achar endchar */
@@ -1920,7 +1885,7 @@ static double trn_array[CS_TRANS_ARRAY_MAX];
@c
/*
- 1-byte CharString operaotrs:
+ 1-byte CharString operators:
|cs_escape| is first byte of two-byte operator
*/
@@ -1939,8 +1904,8 @@ static double trn_array[CS_TRANS_ARRAY_MAX];
#define cs_escape 12
/* |cs_hsbw| 13 : TYPE1 */
#define cs_endchar 14
-/* RESERVED 15 */
-/* RESERVED 16 */
+#define cs_setvsindex 15
+#define cs_blend 16
/* RESERVED 17 */
#define cs_hstemhm 18
#define cs_hintmask 19
@@ -2001,8 +1966,7 @@ static double trn_array[CS_TRANS_ARRAY_MAX];
#define cs_hflex1 36
#define cs_flex1 37
-@
-|clear_stack()| put all operands sotred in operand stack to dest.
+@ |clear_stack()| put all operands sotred in operand stack to dest.
@c
static void clear_stack(card8 ** dest, card8 * limit)
{
@@ -2016,18 +1980,18 @@ static void clear_stack(card8 ** dest, card8 * limit)
ivalue = (long) floor(value + 0.5);
if (value >= 0x8000L || value <= (-0x8000L - 1)) {
/*
- This number cannot be represented as a single operand.
- We must use `a b mul ...' or `a c div' to represent large values.
- */
+ This number cannot be represented as a single operand. We must
+ use `a b mul ...' or `a c div' to represent large values.
+ */
normal_error("cff","argument value too large (this is bug)");
} else if (fabs(value - (double) ivalue) > 3.0e-5) {
/* 16.16-bit signed fixed value */
DST_NEED(limit, *dest + 5);
*(*dest)++ = 255;
- ivalue = (long) floor(value); /* mantissa */
+ ivalue = (long) floor(value); /* mantissa */
*(*dest)++ = (card8) ((ivalue >> 8) & 0xff);
*(*dest)++ = (card8) (ivalue & 0xff);
- ivalue = (long) ((value - (double) ivalue) * 0x10000l); /* fraction */
+ ivalue = (long) ((value - (double) ivalue) * 0x10000l); /* fraction */
*(*dest)++ = (card8) ((ivalue >> 8) & 0xff);
*(*dest)++ = (card8) (ivalue & 0xff);
/* Everything else are integers. */
@@ -2044,7 +2008,8 @@ static void clear_stack(card8 ** dest, card8 * limit)
ivalue = (long) 0xfb00u - ivalue - 108;
*(*dest)++ = (card8) ((ivalue >> 8) & 0xff);
*(*dest)++ = (card8) (ivalue & 0xff);
- } else if (ivalue >= -32768 && ivalue <= 32767) { /* shortint */
+ } else if (ivalue >= -32768 && ivalue <= 32767) {
+ /* shortint */
DST_NEED(limit, *dest + 3);
*(*dest)++ = 28;
*(*dest)++ = (card8) ((ivalue >> 8) & 0xff);
@@ -2053,24 +2018,25 @@ static void clear_stack(card8 ** dest, card8 * limit)
normal_error("cff","unexpected error");
}
}
-
- cs2_stack_top = 0; /* clear stack */
-
+ cs2_stack_top = 0; /* clear stack */
return;
}
-@
- Single byte operators:
- Path construction, Operator for finishing a path, Hint operators.
+@ Single byte operators: Path construction, Operator for finishing a
+path, Hint operators. Phases:
- phase:
- \item 0: inital state
- \item 1: hint declaration, first stack-clearing operator appeared
- \item 2: in path construction
+\item 0: inital state
+\item 1: hint declaration, first stack-clearing operator appeared
+\item 2: in path construction
@c
-static void
-do_operator1(card8 ** dest, card8 * limit, card8 ** data, card8 * endptr)
+/*
+static int vsindex = 0;
+static int blends = 0;
+static int regions = 5;
+*/
+
+static void do_operator1(card8 ** dest, card8 * limit, card8 ** data, card8 * endptr)
{
card8 op = **data;
@@ -2151,7 +2117,24 @@ do_operator1(card8 ** dest, card8 * limit, card8 ** data, card8 * endptr)
*(*dest)++ = op;
status = CS_CHAR_END;
break;
- /* above oprators are candidate for first stack-clearing operator */
+ /* above operators are candidate for first stack-clearing operator */
+ case cs_setvsindex:
+ /*
+ vsindex = cs2_arg_stack[cs2_stack_top-1];
+ cs2_stack_top -= 1;
+ */
+ normal_warning("cff2","unsupported setvindex operator");
+ status = CS_PARSE_CFF_ERROR;
+ break;
+ case cs_blend:
+ /*
+ blends = cs2_arg_stack[cs2_stack_top-1];
+ cs2_stack_top -= 1;
+ cs2_stack_top -= blends * regions ;
+ */
+ normal_warning("cff2","unsupported blend operator");
+ status = CS_PARSE_CFF_ERROR;
+ break;
case cs_rlineto:
case cs_hlineto:
case cs_vlineto:
@@ -2184,20 +2167,14 @@ do_operator1(card8 ** dest, card8 * limit, card8 ** data, card8 * endptr)
status = CS_PARSE_CFF_ERROR;
break;
}
-
return;
}
-@
- Double byte operators:
- Flex, arithmetic, conditional, and storage operators.
-
- Following operators are not supported:
- random: How random ?
+@ Double byte operators: Flex, arithmetic, conditional, and storage operators.
+The following operators are not supported: random: How random ?
@c
-static void
-do_operator2(card8 ** dest, card8 * limit, card8 ** data, card8 * endptr)
+static void do_operator2(card8 ** dest, card8 * limit, card8 ** data, card8 * endptr)
{
card8 op;
@@ -2398,13 +2375,10 @@ do_operator2(card8 ** dest, card8 * limit, card8 ** data, card8 * endptr)
status = CS_PARSE_CFF_ERROR;
break;
}
-
return;
}
-@
- integer:
- exactly the same as the DICT encoding (except 29)
+@ integer: exactly the same as the DICT encoding (except 29)
@c
static void cs2_get_integer(card8 ** data, card8 * endptr)
{
@@ -2437,15 +2411,12 @@ static void cs2_get_integer(card8 ** data, card8 * endptr)
status = CS_PARSE_CFF_ERROR;
return;
}
-
NEED(CS_ARG_STACK_MAX, cs2_stack_top + 1);
cs2_arg_stack[cs2_stack_top++] = (double) result;
-
return;
}
-@
-Signed 16.16-bits fixed number for Type 2 charstring encoding
+@ Signed 16.16-bits fixed number for Type 2 charstring encoding
@c
static void get_fixed(card8 ** data, card8 * endptr)
{
@@ -2468,14 +2439,13 @@ static void get_fixed(card8 ** data, card8 * endptr)
return;
}
-@
- Subroutines:
- The bias for subroutine number is introduced in type 2 charstrings.
+@ Subroutines: the bias for subroutine number is introduced in type 2
+charstrings.
- subr: set to a pointer to the subroutine charstring.
- len: set to the length of subroutine charstring.
- |subr_idx|: CFF INDEX data that contains subroutines.
- id: biased subroutine number.
+\item subr: set to a pointer to the subroutine charstring.
+\item len: set to the length of subroutine charstring.
+\item |subr_idx|: CFF INDEX data that contains subroutines.
+\item id: biased subroutine number.
@c
static void get_subr(card8 ** subr, long *len, cff_index * subr_idx, long id)
@@ -2505,17 +2475,14 @@ static void get_subr(card8 ** subr, long *len, cff_index * subr_idx, long id)
return;
}
-
-@ NOTE:
- The Type 2 interpretation of a number encoded in five-bytes (those with
- an initial byte value of 255) differs from how it is interpreted in the
- Type 1 format.
+@ The Type 2 interpretation of a number encoded in five-bytes (those with
+an initial byte value of 255) differs from how it is interpreted in the
+Type 1 format.
@c
-static void
-do_charstring(card8 ** dest, card8 * limit,
- card8 ** data, card8 * endptr,
- cff_index * gsubr_idx, cff_index * subr_idx)
+static void do_charstring(card8 ** dest, card8 * limit,
+ card8 ** data, card8 * endptr,
+ cff_index * gsubr_idx, cff_index * subr_idx, int cff2)
{
card8 b0 = 0, *subr;
long len;
@@ -2539,8 +2506,8 @@ do_charstring(card8 ** dest, card8 * limit,
get_subr(&subr, &len, gsubr_idx,
(long) cs2_arg_stack[cs2_stack_top]);
if (*dest + len > limit)
- formatted_error("cff","%s: possible buffer overflow", CS_TYPE2_DEBUG_STR);
- do_charstring(dest, limit, &subr, subr + len, gsubr_idx, subr_idx);
+ formatted_error("cff","%s: possible buffer overflow (1)", CS_TYPE2_DEBUG_STR);
+ do_charstring(dest, limit, &subr, subr + len, gsubr_idx, subr_idx, cff2);
*data += 1;
}
} else if (b0 == cs_callsubr) {
@@ -2551,8 +2518,8 @@ do_charstring(card8 ** dest, card8 * limit,
get_subr(&subr, &len, subr_idx,
(long) cs2_arg_stack[cs2_stack_top]);
if (limit < *dest + len)
- formatted_error("cff","%s: possible buffer overflow", CS_TYPE2_DEBUG_STR);
- do_charstring(dest, limit, &subr, subr + len, gsubr_idx, subr_idx);
+ formatted_error("cff","%s: possible buffer overflow (2)", CS_TYPE2_DEBUG_STR);
+ do_charstring(dest, limit, &subr, subr + len, gsubr_idx, subr_idx, cff2);
*data += 1;
}
} else if (b0 == cs_escape) {
@@ -2566,7 +2533,12 @@ do_charstring(card8 ** dest, card8 * limit,
}
}
- if (status == CS_SUBR_RETURN) {
+ if (cff2) {
+ DST_NEED(limit, *dest + 1);
+ ++endptr;
+ *(*dest)++ = cs_endchar;
+ /* no return and endchar */
+ } else if (status == CS_SUBR_RETURN) {
status = CS_PARSE_OK;
} else if (status == CS_CHAR_END && *data < endptr) {
formatted_warning("cff","%s: garbage after endchar", CS_TYPE2_DEBUG_STR);
@@ -2589,14 +2561,11 @@ static void cs_parse_init(void)
cs2_stack_top = 0;
}
-
@ Not just copying...
@c
-long
-cs_copy_charstring(card8 * dst, long dstlen,
- card8 * src, long srclen,
- cff_index * gsubr, cff_index * subr,
- double default_width, double nominal_width, cs_ginfo * ginfo)
+static long cs_copy_charstring(card8 * dst, long dstlen, card8 * src, long srclen,
+ cff_index * gsubr, cff_index * subr, double default_width,
+ double nominal_width, cs_ginfo * ginfo, int cff2)
{
card8 *save = dst;
@@ -2606,7 +2575,7 @@ cs_copy_charstring(card8 * dst, long dstlen,
have_width = 0;
/* expand call(g)subrs */
- do_charstring(&dst, dst + dstlen, &src, src + srclen, gsubr, subr);
+ do_charstring(&dst, dst + dstlen, &src, src + srclen, gsubr, subr, cff2);
if (ginfo) {
ginfo->flags = 0; /* not used */
@@ -2622,9 +2591,7 @@ cs_copy_charstring(card8 * dst, long dstlen,
@* encodings.
-@ Encoding and Charset
-
-Encoding and Charset arrays always begin with GID = 1.
+@ Encoding and Charset arrays always begin with GID = 1.
@c
long cff_read_encoding(cff_font * cff)
@@ -2686,7 +2653,6 @@ long cff_read_encoding(cff_font * cff)
normal_error("cff","unknown encoding format");
break;
}
-
/* Supplementary data */
if ((encoding->format) & 0x80) {
cff_map *map;
@@ -2716,7 +2682,7 @@ long cff_pack_encoding(cff_font * cff, card8 * dest, long destlen)
return 0;
if (destlen < 2)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (19)");
encoding = cff->encoding;
@@ -2725,7 +2691,7 @@ long cff_pack_encoding(cff_font * cff, card8 * dest, long destlen)
switch (encoding->format & (~0x80)) {
case 0:
if (destlen < len + encoding->num_entries)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (20)");
for (i = 0; i < (encoding->num_entries); i++) {
dest[len++] = (encoding->data).codes[i];
}
@@ -2733,7 +2699,7 @@ long cff_pack_encoding(cff_font * cff, card8 * dest, long destlen)
case 1:
{
if (destlen < len + (encoding->num_entries) * 2)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (21)");
for (i = 0; i < (encoding->num_entries); i++) {
dest[len++] = (card8) ((encoding->data).range1[i].first & 0xff);
dest[len++] = (card8) ((encoding->data).range1[i].n_left);
@@ -2747,7 +2713,7 @@ long cff_pack_encoding(cff_font * cff, card8 * dest, long destlen)
if ((encoding->format) & 0x80) {
if (destlen < len + (encoding->num_supps) * 3 + 1)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (22)");
dest[len++] = encoding->num_supps;
for (i = 0; i < (encoding->num_supps); i++) {
dest[len++] = (card8) ((encoding->supp)[i].code);
@@ -2815,7 +2781,6 @@ long cff_read_fdselect(cff_font * cff)
return length;
}
-
@ @c
long cff_pack_fdselect(cff_font * cff, card8 * dest, long destlen)
{
@@ -2827,7 +2792,7 @@ long cff_pack_fdselect(cff_font * cff, card8 * dest, long destlen)
return 0;
if (destlen < 1)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (23)");
fdsel = cff->fdselect;
@@ -2837,7 +2802,7 @@ long cff_pack_fdselect(cff_font * cff, card8 * dest, long destlen)
if (fdsel->num_entries != cff->num_glyphs)
normal_error("cff","invalid data");
if (destlen < len + fdsel->num_entries)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (24)");
for (i = 0; i < fdsel->num_entries; i++) {
dest[len++] = (fdsel->data).fds[i];
}
@@ -2845,18 +2810,18 @@ long cff_pack_fdselect(cff_font * cff, card8 * dest, long destlen)
case 3:
{
if (destlen < len + 2)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (25)");
len += 2;
for (i = 0; i < (fdsel->num_entries); i++) {
if (destlen < len + 3)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (26)");
dest[len++] =
(card8) (((fdsel->data).ranges[i].first >> 8) & 0xff);
dest[len++] = (card8) ((fdsel->data).ranges[i].first & 0xff);
dest[len++] = (card8) ((fdsel->data).ranges[i].fd);
}
if (destlen < len + 2)
- normal_error("cff","buffer overflow");
+ normal_error("cff","buffer overflow (27)");
dest[len++] = (card8) ((cff->num_glyphs >> 8) & 0xff);
dest[len++] = (card8) (cff->num_glyphs & 0xff);
dest[1] = (card8) (((len / 3 - 1) >> 8) & 0xff);
@@ -2871,8 +2836,6 @@ long cff_pack_fdselect(cff_font * cff, card8 * dest, long destlen)
return len;
}
-
-
@ Create an instance of embeddable font.
@c
@@ -2892,26 +2855,23 @@ static void write_fontfile(PDF pdf, cff_font * cffont, char *fullname)
cff_dict_remove(cffont->topdict, "XUID");
cff_dict_remove(cffont->topdict, "Private"); /* some bad font may have */
cff_dict_remove(cffont->topdict, "Encoding"); /* some bad font may have */
+ cff_dict_remove(cffont->topdict, "vstore"); /* cff2 */
+ cff_dict_remove(cffont->topdict, "maxstack"); /* cff2 */
- topdict->offset[1] = (l_offset) cff_dict_pack(cffont->topdict,
- (card8 *) work_buffer,
- WORK_BUFFER_SIZE) + 1;
+ topdict->offset[1] = (l_offset) cff_dict_pack(cffont->topdict, (card8 *) work_buffer, WORK_BUFFER_SIZE) + 1;
for (i = 0; i < cffont->num_fds; i++) {
size = 0;
if (cffont->private && cffont->private[i]) {
- size = cff_dict_pack(cffont->private[i],
- (card8 *) work_buffer, WORK_BUFFER_SIZE);
- if (size < 1) { /* Private had contained only Subr */
+ size = cff_dict_pack(cffont->private[i], (card8 *) work_buffer, WORK_BUFFER_SIZE);
+ if (size < 1) {
+ /* Private had contained only Subr. */
cff_dict_remove(cffont->fdarray[i], "Private");
}
}
- (private->offset)[i + 1] =
- (unsigned long) ((private->offset)[i] + (unsigned) size);
- (fdarray->offset)[i + 1] =
- (unsigned long) ((fdarray->offset)[i] + (unsigned)
- cff_dict_pack(cffont->fdarray[i],
- (card8 *) work_buffer,
- WORK_BUFFER_SIZE));
+ (private->offset)[i + 1] = (unsigned long) ((private->offset)[i]
+ + (unsigned) size);
+ (fdarray->offset)[i + 1] = (unsigned long) ((fdarray->offset)[i]
+ + (unsigned) cff_dict_pack(cffont->fdarray[i], (card8 *) work_buffer, WORK_BUFFER_SIZE));
}
destlen = 4; /* header size */
@@ -2924,7 +2884,6 @@ static void write_fontfile(PDF pdf, cff_font * cffont, char *fullname)
destlen += cff_index_size(cffont->cstrings);
destlen += cff_index_size(fdarray);
destlen = (long) (destlen + (long) private->offset[private->count] - 1); /* Private is not INDEX */
-
dest = xcalloc((unsigned) destlen, sizeof(card8));
offset = 0;
@@ -2939,30 +2898,23 @@ static void write_fontfile(PDF pdf, cff_font * cffont, char *fullname)
offset += cff_pack_index(cffont->string, dest + offset, destlen - offset);
/* Global Subrs */
offset += cff_pack_index(cffont->gsubr, dest + offset, destlen - offset);
-
/* charset */
cff_dict_set(cffont->topdict, "charset", 0, (double) offset);
offset += cff_pack_charsets(cffont, dest + offset, destlen - offset);
-
/* FDSelect */
cff_dict_set(cffont->topdict, "FDSelect", 0, (double) offset);
offset += cff_pack_fdselect(cffont, dest + offset, destlen - offset);
-
/* CharStrings */
cff_dict_set(cffont->topdict, "CharStrings", 0, (double) offset);
- offset += cff_pack_index(cffont->cstrings,
- dest + offset, cff_index_size(cffont->cstrings));
+ offset += cff_pack_index(cffont->cstrings, dest + offset, cff_index_size(cffont->cstrings));
cff_release_index(cffont->cstrings);
cffont->cstrings = NULL; /* Charstrings cosumes huge memory */
-
/* FDArray and Private */
cff_dict_set(cffont->topdict, "FDArray", 0, (double) offset);
fdarray_offset = offset;
offset += cff_index_size(fdarray);
- fdarray->data =
- xcalloc((unsigned) (fdarray->offset[fdarray->count] - 1),
- sizeof(card8));
+ fdarray->data = xcalloc((unsigned) (fdarray->offset[fdarray->count] - 1), sizeof(card8));
for (i = 0; i < cffont->num_fds; i++) {
size = (long) (private->offset[i + 1] - private->offset[i]);
if (cffont->private[i] && size > 0) {
@@ -2970,56 +2922,27 @@ static void write_fontfile(PDF pdf, cff_font * cffont, char *fullname)
cff_dict_set(cffont->fdarray[i], "Private", 0, (double) size);
cff_dict_set(cffont->fdarray[i], "Private", 1, (double) offset);
}
- cff_dict_pack(cffont->fdarray[i],
- fdarray->data + (fdarray->offset)[i] - 1,
- (long) (fdarray->offset[fdarray->count] - 1));
+ cff_dict_pack(cffont->fdarray[i], fdarray->data + (fdarray->offset)[i] - 1, (long) (fdarray->offset[fdarray->count] - 1));
offset += size;
}
-
cff_pack_index(fdarray, dest + fdarray_offset, cff_index_size(fdarray));
cff_release_index(fdarray);
cff_release_index(private);
/* Finally Top DICT */
- topdict->data =
- xcalloc((unsigned) (topdict->offset[topdict->count] - 1),
- sizeof(card8));
- cff_dict_pack(cffont->topdict, topdict->data,
- (long) (topdict->offset[topdict->count] - 1));
+ topdict->data = xcalloc((unsigned) (topdict->offset[topdict->count] - 1), sizeof(card8));
+ cff_dict_pack(cffont->topdict, topdict->data, (long) (topdict->offset[topdict->count] - 1));
cff_pack_index(topdict, dest + topdict_offset, cff_index_size(topdict));
cff_release_index(topdict);
- for (i = 0; i < offset; i++)
+ for (i = 0; i < offset; i++) {
+// printf("%i\n",(unsigned char)dest[i]);
strbuf_putchar(pdf->fb, dest[i]);
-
+ }
xfree(dest);
return;
}
-
-@ this block is used a few times
-@c
-#define DO_COPY_CHARSTRING() \
- if ((avl_find(fd->gl_tree,glyph) != NULL)) { \
- size = (long)(cs_idx->offset[code+1] - cs_idx->offset[code]); \
- if (size > CS_STR_LEN_MAX) { \
- formatted_error("cff","charstring too long: gid=%u, %ld bytes", code, size); \
- } \
- if (charstring_len + CS_STR_LEN_MAX >= max_len) { \
- max_len = (long)(charstring_len + 2 * CS_STR_LEN_MAX); \
- charstrings->data = xrealloc(charstrings->data, (unsigned)((unsigned)max_len*sizeof(card8))); \
- } \
- (charstrings->offset)[gid] = (unsigned)(charstring_len + 1); \
- cffont->offset= (l_offset)((unsigned)offset + (cs_idx->offset)[code] - 1); \
- memcpy(data,&cffont->stream[cffont->offset],(size_t)size); \
- charstring_len += cs_copy_charstring(charstrings->data + charstring_len, \
- max_len - charstring_len, \
- data, size, \
- cffont->gsubr, (cffont->subrs)[0], \
- default_width, nominal_width, NULL); \
- gid++; \
- }
-
@ @c
void write_cff(PDF pdf, cff_font * cffont, fd_entry * fd)
{
@@ -3033,11 +2956,17 @@ void write_cff(PDF pdf, cff_font * cffont, fd_entry * fd)
double nominal_width, default_width;
+ char *fontname;
char *fullname;
glw_entry *glyph, *found;
struct avl_traverser t;
+cffont->_string = NULL;
+
+ fontname = xcalloc((unsigned) (1 + strlen(fd->fontname)), 1);
+ sprintf(fontname, "%s", fd->fontname);
+
fullname = xcalloc((unsigned) (8 + strlen(fd->fontname)), 1);
sprintf(fullname, "%s+%s", fd->subset_tag, fd->fontname);
@@ -3045,20 +2974,14 @@ void write_cff(PDF pdf, cff_font * cffont, fd_entry * fd)
cff_read_private(cffont);
cff_read_subrs(cffont);
- /*
- Widths
- */
- if (cffont->private[0] &&
- cff_dict_known(cffont->private[0], "defaultWidthX")) {
- default_width =
- (double) cff_dict_get(cffont->private[0], "defaultWidthX", 0);
+ /* Widths */
+ if (cffont->private[0] && cff_dict_known(cffont->private[0], "defaultWidthX")) {
+ default_width = (double) cff_dict_get(cffont->private[0], "defaultWidthX", 0);
} else {
default_width = CFF_DEFAULTWIDTHX_DEFAULT;
}
- if (cffont->private[0] &&
- cff_dict_known(cffont->private[0], "nominalWidthX")) {
- nominal_width =
- (double) cff_dict_get(cffont->private[0], "nominalWidthX", 0);
+ if (cffont->private[0] && cff_dict_known(cffont->private[0], "nominalWidthX")) {
+ nominal_width = (double) cff_dict_get(cffont->private[0], "nominalWidthX", 0);
} else {
nominal_width = CFF_NOMINALWIDTHX_DEFAULT;
}
@@ -3113,15 +3036,31 @@ void write_cff(PDF pdf, cff_font * cffont, fd_entry * fd)
}
}
cffont->charsets = charset;
- }
+ if (cffont->header_major == 2) {
+ cff_dict_add(cffont->topdict, "charset", 1);
+ }
+ }
cff_dict_add(cffont->topdict, "CIDCount", 1);
cff_dict_set(cffont->topdict, "CIDCount", 0, last_cid + 1);
+ if (cffont->header_major == 2) {
+
+ cff_dict_add(cffont->topdict, "FullName", 1);
+ cff_dict_set(cffont->topdict, "FullName", 0, (double) cff_add_string(cffont, fontname));
+
+ cff_dict_add(cffont->topdict, "FontBBox", 4);
+ cff_dict_set(cffont->topdict, "FontBBox", 0, fd->font_dim[FONTBBOX1_CODE].val);
+ cff_dict_set(cffont->topdict, "FontBBox", 1, fd->font_dim[FONTBBOX2_CODE].val);
+ cff_dict_set(cffont->topdict, "FontBBox", 2, fd->font_dim[FONTBBOX3_CODE].val);
+ cff_dict_set(cffont->topdict, "FontBBox", 3, fd->font_dim[FONTBBOX4_CODE].val);
+ }
+
cffont->fdarray = xcalloc(1, sizeof(cff_dict *));
cffont->fdarray[0] = cff_new_dict();
cff_dict_add(cffont->fdarray[0], "FontName", 1);
- cff_dict_set(cffont->fdarray[0], "FontName", 0, (double) cff_add_string(cffont, fullname)); /* FIXME: Skip XXXXXX+ */
+ /* FIXME: Skip XXXXXX+ */
+ cff_dict_set(cffont->fdarray[0], "FontName", 0, (double) cff_add_string(cffont, fullname));
cff_dict_add(cffont->fdarray[0], "Private", 2);
cff_dict_set(cffont->fdarray[0], "Private", 0, 0.0);
cff_dict_set(cffont->fdarray[0], "Private", 0, 0.0);
@@ -3157,40 +3096,89 @@ void write_cff(PDF pdf, cff_font * cffont, fd_entry * fd)
{
int i;
+ int tex_font = fd->tex_font;
+ int streamprovider = 0;
+ int callback_id = 0 ;
+ if ((tex_font > 0) && (font_streamprovider(tex_font) == 1)) {
+ streamprovider = font_streamprovider(tex_font);
+ callback_id = callback_defined(glyph_stream_provider_callback);
+ }
for (i = 0; i < cs_count1; i++) {
code = (card16) i;
glyph->id = code;
- DO_COPY_CHARSTRING();
+ if ((avl_find(fd->gl_tree,glyph) != NULL)) {
+ /* this code is the same as below, apart from small details */
+ if (callback_id > 0) {
+ lstring * result;
+ run_callback(callback_id, "ddd->L", tex_font, i, streamprovider, &result); /* this call can be sped up */
+ size = (size_t) result->l ;
+ if (size > 0) {
+ if (charstring_len + CS_STR_LEN_MAX >= max_len) {
+ max_len = (long)(charstring_len + 2 * CS_STR_LEN_MAX);
+ charstrings->data = xrealloc(charstrings->data, (unsigned)((unsigned)max_len*sizeof(card8)));
+ }
+ (charstrings->offset)[gid] = (unsigned)(charstring_len + 1);
+ cffont->offset = (l_offset)((unsigned)offset + (cs_idx->offset)[code] - 1);
+ memcpy(charstrings->data+charstring_len,(const char *) result->s,(size_t) size);
+ charstring_len += size;
+ xfree(result);
+ }
+ } else {
+ size = (long)(cs_idx->offset[code+1] - cs_idx->offset[code]);
+ if (size > CS_STR_LEN_MAX) {
+ formatted_error("cff","charstring too long: gid=%u, %ld bytes", code, size);
+ }
+ if (charstring_len + CS_STR_LEN_MAX >= max_len) {
+ max_len = (long)(charstring_len + 2 * CS_STR_LEN_MAX);
+ charstrings->data = xrealloc(charstrings->data, (unsigned)((unsigned)max_len*sizeof(card8)));
+ }
+ (charstrings->offset)[gid] = (unsigned)(charstring_len + 1);
+ cffont->offset = (l_offset)((unsigned)offset + (cs_idx->offset)[code] - 1);
+ memcpy(data,&cffont->stream[cffont->offset],(size_t)size);
+ charstring_len += cs_copy_charstring(
+ charstrings->data + charstring_len,
+ max_len - charstring_len,
+ data, size,
+ cffont->gsubr, (cffont->subrs)[0],
+ default_width, nominal_width, NULL,
+ cffont->header_major == 2
+ );
+ }
+ gid++;
+ }
}
}
-
- /* CIDSet: a table of bits indexed by cid, bytes with high order bit first,
- each (set) bit is a (present) CID. */
+ /*
+ CIDSet: a table of bits indexed by cid, bytes with high order bit first,
+ each (set) bit is a (present) CID.
+ */
if (1) {
- int cid;
- cidset = pdf_create_obj(pdf, obj_type_others, 0);
- if (cidset != 0) {
- size_t l = (last_cid/8)+1;
- char *stream = xmalloc(l);
- memset(stream, 0, l);
- for (cid = 1; cid <= (long) last_cid; cid++) {
- glyph->id = cid;
- if (avl_find(fd->gl_tree,glyph) != NULL) {
- stream[(cid / 8)] |= (1 << (7 - (cid % 8)));
- }
- }
- pdf_begin_obj(pdf, cidset, OBJSTM_NEVER);
- pdf_begin_dict(pdf);
- pdf_dict_add_streaminfo(pdf);
- pdf_end_dict(pdf);
- pdf_begin_stream(pdf);
- pdf_out_block(pdf, stream, l);
- pdf_end_stream(pdf);
- pdf_end_obj(pdf);
- }
- }
-
- /* this happens if the internal metrics do not agree with the actual disk font */
+ int cid;
+ cidset = pdf_create_obj(pdf, obj_type_others, 0);
+ if (cidset != 0) {
+ size_t l = (last_cid/8)+1;
+ char *stream = xmalloc(l);
+ memset(stream, 0, l);
+ for (cid = 1; cid <= (long) last_cid; cid++) {
+ glyph->id = cid;
+ if (avl_find(fd->gl_tree,glyph) != NULL) {
+ stream[(cid / 8)] |= (1 << (7 - (cid % 8)));
+ }
+ }
+ pdf_begin_obj(pdf, cidset, OBJSTM_NEVER);
+ pdf_begin_dict(pdf);
+ pdf_dict_add_streaminfo(pdf);
+ pdf_end_dict(pdf);
+ pdf_begin_stream(pdf);
+ pdf_out_block(pdf, stream, l);
+ pdf_end_stream(pdf);
+ pdf_end_obj(pdf);
+ }
+ }
+ /*
+ This happens if the internal metrics do not agree with the actual
+ disk font.
+ */
if (gid < num_glyphs) {
formatted_warning("cff","embedded subset is smaller than expected: %d instead of %d glyphs", gid, num_glyphs);
num_glyphs = gid;
@@ -3203,10 +3191,9 @@ void write_cff(PDF pdf, cff_font * cffont, fd_entry * fd)
charstrings->count = num_glyphs;
cffont->num_glyphs = num_glyphs;
cffont->cstrings = charstrings;
-
/*
- We don't use subroutines at all.
- */
+ We don't use subroutines at all.
+ */
if (cffont->gsubr)
cff_release_index(cffont->gsubr);
cffont->gsubr = cff_new_index(0);
@@ -3219,33 +3206,34 @@ void write_cff(PDF pdf, cff_font * cffont, fd_entry * fd)
cff_dict_remove((cffont->private)[0], "Subrs"); /* no Subrs */
}
+ cff_dict_update(cffont->topdict, cffont);
+
cff_add_string(cffont, "Adobe");
cff_add_string(cffont, "Identity");
-
- cff_dict_update(cffont->topdict, cffont);
- cff_dict_update(cffont->private[0], cffont);
+ if (cffont->header_major == 2) {
+ /* crash */
+ } else {
+ cff_dict_update(cffont->private[0], cffont);
+ }
cff_update_string(cffont);
- /* CFF code need to be rewrote... */
+ /* CFF code need to be rewritten */
cff_dict_add(cffont->topdict, "ROS", 3);
- cff_dict_set(cffont->topdict, "ROS", 0,
- (double) cff_get_sid(cffont, "Adobe"));
- cff_dict_set(cffont->topdict, "ROS", 1,
- (double) cff_get_sid(cffont, "Identity"));
+ cff_dict_set(cffont->topdict, "ROS", 0, (double) cff_get_sid(cffont, "Adobe"));
+ cff_dict_set(cffont->topdict, "ROS", 1, (double) cff_get_sid(cffont, "Identity"));
cff_dict_set(cffont->topdict, "ROS", 2, 0.0);
write_fontfile(pdf, cffont, fullname);
+ xfree(fontname);
xfree(fullname);
cff_close(cffont);
-
}
@ @c
-#undef ERROR /* for mingw */
+#undef ERROR /* for mingw */
#define ERROR(a) { perror(a); return 0; }
-@ Input : SID or CID (16-bit unsigned int)
- Output: glyph index
+@ Input : SID or CID (16-bit unsigned int) Output: glyph index
@c
card16 cff_charsets_lookup(cff_font * cff, card16 cid)
@@ -3279,9 +3267,7 @@ card16 cff_charsets_lookup(cff_font * cff, card16 cid)
case 1:
for (i = 0; i < charset->num_entries; i++) {
if (cid >= charset->data.range1[i].first &&
- cid <=
- charset->data.range1[i].first +
- charset->data.range1[i].n_left) {
+ cid <= charset->data.range1[i].first + charset->data.range1[i].n_left) {
gid = (card16) (gid + cid - charset->data.range1[i].first + 1);
return gid;
}
@@ -3291,9 +3277,7 @@ card16 cff_charsets_lookup(cff_font * cff, card16 cid)
case 2:
for (i = 0; i < charset->num_entries; i++) {
if (cid >= charset->data.range2[i].first &&
- cid <=
- charset->data.range2[i].first +
- charset->data.range2[i].n_left) {
+ cid <= charset->data.range2[i].first + charset->data.range2[i].n_left) {
gid = (card16) (gid + cid - charset->data.range2[i].first + 1);
return gid;
}
@@ -3307,22 +3291,24 @@ card16 cff_charsets_lookup(cff_font * cff, card16 cid)
return 0; /* not found */
}
-
@ @c
#define is_cidfont(a) ((a)->flag & FONTTYPE_CIDFONT)
#define CID_MAX 65535
+
void write_cid_cff(PDF pdf, cff_font * cffont, fd_entry * fd)
{
cff_index *charstrings, *cs_idx;
long charstring_len, max_len;
long size, offset = 0;
+ int tex_font = fd->tex_font;
+ int streamprovider = 0;
+ int callback_id = 0 ;
card8 *data;
card16 num_glyphs, cs_count1, gid, last_cid;
-
- int fdsel, prev_fd, cid_count, cid;
+ int fdsel, prev_fd, cid_count, cid ;
char *fullname;
glw_entry *glyph;
@@ -3332,12 +3318,16 @@ void write_cid_cff(PDF pdf, cff_font * cffont, fd_entry * fd)
cff_fdselect *fdselect = NULL;
cff_charsets *charset = NULL;
-
if (!is_cidfont(cffont)) {
perror("Not a CIDfont.");
return;
}
+ if ((tex_font > 0) && (font_streamprovider(tex_font) == 1)) {
+ streamprovider = font_streamprovider(tex_font);
+ callback_id = callback_defined(glyph_stream_provider_callback);
+ }
+
fullname = xcalloc((unsigned) (8 + strlen(fd->fontname)), 1);
sprintf(fullname, "%s+%s", fd->subset_tag, fd->fontname);
@@ -3348,9 +3338,12 @@ void write_cid_cff(PDF pdf, cff_font * cffont, fd_entry * fd)
} else {
cid_count = CFF_CIDCOUNT_DEFAULT;
}
- cff_read_charsets(cffont);
- CIDToGIDMap = xmalloc((unsigned)
- ((2 * (unsigned) cid_count) * sizeof(unsigned char)));
+ if (cffont->header_major == 2) {
+ /* hm */
+ } else {
+ cff_read_charsets(cffont);
+ }
+ CIDToGIDMap = xmalloc((unsigned) ((2 * (unsigned) cid_count) * sizeof(unsigned char)));
memset(CIDToGIDMap, 0, (size_t) (2 * cid_count));
glyph = xtalloc(1, glw_entry);
@@ -3376,12 +3369,15 @@ void write_cid_cff(PDF pdf, cff_font * cffont, fd_entry * fd)
num_glyphs++;
}
}
- if (last_cid >= cffont->num_glyphs) {
+ if (cffont->header_major == 2) {
+ /* hm */
+ } else if (last_cid >= cffont->num_glyphs) {
formatted_error("cff font","bad glyph index %i",last_cid);
}
-
- /* CIDSet: a table of bits indexed by cid, bytes with high order bit first,
- each (set) bit is a (present) CID. */
+ /*
+ CIDSet: a table of bits indexed by cid, bytes with high order bit
+ first, each (set) bit is a (present) CID.
+ */
if (1) {
cidset = pdf_create_obj(pdf, obj_type_others, 0);
if (cidset != 0) {
@@ -3397,7 +3393,7 @@ void write_cid_cff(PDF pdf, cff_font * cffont, fd_entry * fd)
pdf_begin_dict(pdf);
pdf_dict_add_streaminfo(pdf);
pdf_end_dict(pdf);
- pdf_begin_stream(pdf);
+ pdf_begin_stream(pdf);
pdf_out_block(pdf, stream, l);
pdf_end_stream(pdf);
pdf_end_obj(pdf);
@@ -3405,14 +3401,12 @@ void write_cid_cff(PDF pdf, cff_font * cffont, fd_entry * fd)
}
}
-
cff_read_fdselect(cffont);
cff_read_fdarray(cffont);
cff_read_private(cffont);
cff_read_subrs(cffont);
-
cffont->offset = (l_offset) cff_dict_get(cffont->topdict, "CharStrings", 0);
cs_idx = cff_get_index_header(cffont);
@@ -3447,31 +3441,46 @@ void write_cid_cff(PDF pdf, cff_font * cffont, fd_entry * fd)
if (avl_find(fd->gl_tree, glyph) == NULL)
continue;
- gid_org =
- (short unsigned) ((CIDToGIDMap[2 * cid] << 8) |
- (CIDToGIDMap[2 * cid + 1]));
- size = (long) (cs_idx->offset[gid_org + 1] - cs_idx->offset[gid_org]);
- if (size > CS_STR_LEN_MAX) {
- formatted_error("cff","charstring too long: gid=%u, %ld bytes", cid, size);
- }
- if (charstring_len + CS_STR_LEN_MAX >= max_len) {
- max_len = charstring_len + 2 * CS_STR_LEN_MAX;
- charstrings->data =
- xrealloc(charstrings->data,
- (unsigned) ((unsigned) max_len * sizeof(card8)));
- }
- (charstrings->offset)[gid] = (l_offset) (charstring_len + 1);
- cffont->offset =
- (l_offset) ((unsigned) offset + (cs_idx->offset)[gid_org] - 1);
- memcpy(data, &cffont->stream[cffont->offset], (size_t) size);
+ gid_org = (short unsigned) ((CIDToGIDMap[2 * cid] << 8) | (CIDToGIDMap[2 * cid + 1]));
fdsel = cff_fdselect_lookup(cffont, gid_org);
- charstring_len += cs_copy_charstring(charstrings->data + charstring_len,
- max_len - charstring_len,
- data, size,
- cffont->gsubr,
- (cffont->subrs)[fdsel], 0, 0,
- NULL);
+ if (callback_id > 0) {
+ /* the next blob is not yet tested ... i need a font */
+ lstring * result;
+ run_callback(callback_id, "ddd->L", tex_font, gid_org, streamprovider, &result); /* this call can be sped up */
+ size = (size_t) result->l ;
+ if (size > 0) {
+ if (charstring_len + CS_STR_LEN_MAX >= max_len) {
+ max_len = (long)(charstring_len + 2 * CS_STR_LEN_MAX);
+ charstrings->data = xrealloc(charstrings->data, (unsigned)((unsigned)max_len*sizeof(card8)));
+ }
+ (charstrings->offset)[gid] = (unsigned)(charstring_len + 1);
+ cffont->offset = (l_offset)((unsigned)offset + (cs_idx->offset)[gid_org] - 1);
+ memcpy(charstrings->data+charstring_len,(const char *) result->s,(size_t)size);
+ charstring_len += size;
+ xfree(result);
+ }
+ } else {
+ size = (long) (cs_idx->offset[gid_org + 1] - cs_idx->offset[gid_org]);
+ if (size > CS_STR_LEN_MAX) {
+ formatted_error("cff","charstring too long: gid=%u, %ld bytes", cid, size);
+ }
+ if (charstring_len + CS_STR_LEN_MAX >= max_len) {
+ max_len = charstring_len + 2 * CS_STR_LEN_MAX;
+ charstrings->data = xrealloc(charstrings->data, (unsigned) ((unsigned) max_len * sizeof(card8)));
+ }
+ (charstrings->offset)[gid] = (l_offset) (charstring_len + 1);
+ cffont->offset = (l_offset) ((unsigned) offset + (cs_idx->offset)[gid_org] - 1);
+ memcpy(data, &cffont->stream[cffont->offset], (size_t) size);
+ charstring_len += cs_copy_charstring(
+ charstrings->data + charstring_len,
+ max_len - charstring_len,
+ data, size,
+ cffont->gsubr, (cffont->subrs)[fdsel],
+ 0, 0, NULL,
+ cffont->header_major == 2
+ );
+ }
if (cid > 0 && gid_org > 0) {
charset->data.glyphs[charset->num_entries] = (s_SID) cid;
charset->num_entries++;
@@ -3496,15 +3505,13 @@ void write_cid_cff(PDF pdf, cff_font * cffont, fd_entry * fd)
charstrings->count = num_glyphs;
cffont->num_glyphs = num_glyphs;
cffont->cstrings = charstrings;
-
cff_release_charsets(cffont->charsets);
cffont->charsets = charset;
cff_release_fdselect(cffont->fdselect);
cffont->fdselect = fdselect;
-
/*
- * We don't use subroutines at all.
- */
+ We don't use subroutines at all.
+ */
if (cffont->gsubr)
cff_release_index(cffont->gsubr);
cffont->gsubr = cff_new_index(0);
@@ -3518,14 +3525,12 @@ void write_cid_cff(PDF pdf, cff_font * cffont, fd_entry * fd)
cff_dict_remove((cffont->private)[fdsel], "Subrs"); /* no Subrs */
}
}
-
write_fontfile(pdf, cffont, fullname);
xfree(fullname);
cff_close(cffont);
-
}
-@ here is a sneaky trick: fontforge knows how to convert Type1 to CFF, so
+@ Here is a sneaky trick: fontforge knows how to convert Type1 to CFF, so
I have defined a utility function in luafflib.c that does exactly that.
If it works out ok, I will clean up this code.
diff --git a/Build/source/texk/web2c/luatexdir/font/writefont.w b/Build/source/texk/web2c/luatexdir/font/writefont.w
index 66c26fa7c16..76d88b68bc4 100644
--- a/Build/source/texk/web2c/luatexdir/font/writefont.w
+++ b/Build/source/texk/web2c/luatexdir/font/writefont.w
@@ -28,23 +28,23 @@ void write_cid_fontdictionary(PDF pdf, fo_entry * fo, internal_font_number f);
static void create_cid_fontdictionary(PDF pdf, internal_font_number f);
const key_entry font_key[FONT_KEYS_NUM] = {
- {"Ascent", "Ascender", 1}
- , {"CapHeight", "CapHeight", 1}
- , {"Descent", "Descender", 1}
- , {"ItalicAngle", "ItalicAngle", 1}
- , {"StemV", "StdVW", 1}
- , {"XHeight", "XHeight", 1}
- , {"FontBBox", "FontBBox", 1}
- , {"", "", 0}
- , {"", "", 0}
- , {"", "", 0}
- , {"FontName", "FontName", 1}
+ { "Ascent", "Ascender", 1 },
+ { "CapHeight", "CapHeight", 1 },
+ { "Descent", "Descender", 1 },
+ { "ItalicAngle", "ItalicAngle", 1 },
+ { "StemV", "StdVW", 1 },
+ { "XHeight", "XHeight", 1 },
+ { "FontBBox", "FontBBox", 1 },
+ { "", "", 0 },
+ { "", "", 0 },
+ { "", "", 0 },
+ { "FontName", "FontName", 1 }
};
@
@c
-struct avl_table *fo_tree = NULL; /* tree of font dictionaries */
-struct avl_table *fd_tree = NULL; /* tree of font descriptor objects */
+struct avl_table *fo_tree = NULL; /* tree of font dictionaries */
+struct avl_table *fd_tree = NULL; /* tree of font descriptor objects */
static int comp_fo_entry(const void *pa, const void *pb, void *p)
{
@@ -83,7 +83,7 @@ static fo_entry *new_fo_entry(void)
@ initialize data structure for /Type /FontDescriptor
@c
-fd_entry *new_fd_entry(void)
+fd_entry *new_fd_entry(internal_font_number f)
{
fd_entry *fd;
int i;
@@ -104,6 +104,7 @@ fd_entry *new_fd_entry(void)
fd->fm = NULL;
fd->tx_tree = NULL;
fd->gl_tree = NULL;
+ fd->tex_font = f;
return fd;
}
@@ -249,7 +250,8 @@ void register_fd_entry(fd_entry * fd)
assert(fd_tree != NULL);
}
assert(fd != NULL && fd->fm != NULL && is_fontfile(fd->fm));
- assert(lookup_fd_entry(fd->fm->ff_name) == NULL); /* font descriptor not yet registered */
+ /* font descriptor not yet registered: */
+ assert(lookup_fd_entry(fd->fm->ff_name) == NULL);
aa = avl_probe(fd_tree, fd);
assert(aa != NULL);
}
@@ -259,11 +261,13 @@ static void create_fontdescriptor(fo_entry * fo, internal_font_number f)
assert(fo != NULL);
assert(fo->fm != NULL);
assert(fo->fd == NULL);
- fo->fd = new_fd_entry();
+ fo->fd = new_fd_entry(f);
preset_fontname(fo, f);
preset_fontmetrics(fo->fd, f);
- fo->fd->fe = fo->fe; /* encoding needed by TrueType writing */
- fo->fd->fm = fo->fm; /* map entry needed by TrueType writing */
+ /* encoding needed by TrueType writing: */
+ fo->fd->fe = fo->fe;
+ /* map entry needed by TrueType writing: */
+ fo->fd->fm = fo->fm;
fo->fd->gl_tree = avl_create(comp_string_entry, NULL, &avl_xallocator);
assert(fo->fd->gl_tree != NULL);
}
@@ -285,7 +289,8 @@ static void mark_reenc_glyphs(fo_entry * fo, internal_font_number f)
/* mark glyphs from TeX (externally reencoded characters) */
g = fo->fe->glyph_names;
for (i = fo->first_char; i <= fo->last_char; i++) {
- if (pdf_char_marked(f, i) && g[i] != notdef
+ if (pdf_char_marked(f, i)
+ && g[i] != notdef
&& (char *) avl_find(fo->fd->gl_tree, g[i]) == NULL) {
aa = avl_probe(fo->fd->gl_tree, xstrdup(g[i]));
assert(aa != NULL);
@@ -301,7 +306,7 @@ Function |mark_chars| has 2 uses:
@c
static struct avl_table *mark_chars(fo_entry * fo, struct avl_table *tx_tree,
- internal_font_number f)
+ internal_font_number f)
{
int i, *j;
void **aa;
@@ -326,7 +331,8 @@ static void get_char_range(fo_entry * fo, internal_font_number f)
{
int i;
assert(fo != NULL);
- for (i = font_bc(f); i <= font_ec(f); i++) /* search for |first_char| and |last_char| */
+ /* search for |first_char| and |last_char| */
+ for (i = font_bc(f); i <= font_ec(f); i++)
if (pdf_char_marked(f, i))
break;
fo->first_char = i;
@@ -334,8 +340,8 @@ static void get_char_range(fo_entry * fo, internal_font_number f)
if (pdf_char_marked(f, i))
break;
fo->last_char = i;
- if ((fo->first_char > fo->last_char)
- || !pdf_char_marked(f, fo->first_char)) { /* no character used from this font */
+ if ((fo->first_char > fo->last_char) || !pdf_char_marked(f, fo->first_char)) {
+ /* no character used from this font */
fo->last_char = 0;
fo->first_char = fo->last_char + 1;
}
@@ -344,7 +350,8 @@ static void get_char_range(fo_entry * fo, internal_font_number f)
static int font_has_subset(internal_font_number f)
{
int i, s;
- for (i = font_bc(f); i <= font_ec(f); i++) /* search for |first_char| and |last_char| */
+ /* search for |first_char| and |last_char| */
+ for (i = font_bc(f); i <= font_ec(f); i++)
if (pdf_char_marked(f, i))
break;
s = i;
@@ -359,8 +366,7 @@ static int font_has_subset(internal_font_number f)
@
@c
-static void write_charwidth_array(PDF pdf, fo_entry * fo,
- internal_font_number f)
+static void write_charwidth_array(PDF pdf, fo_entry * fo, internal_font_number f)
{
int i, j, *ip, *fip;
struct avl_traverser t;
@@ -420,13 +426,13 @@ static void register_fo_entry(fo_entry * fo)
}
@
+In principle we could replace the pdftex derived ttf.otf inclusion part
+by using the regular code for this and assigning indices and tounicodes
+to the character blobs, but for the moment we keep the current approach.
@c
static void write_fontfile(PDF pdf, fd_entry * fd)
{
assert(is_included(fd->fm));
- /* In principle we could replace the pdftex derived ttf.otf inclusion part */
- /* by using the regular code for this and assigning indices and tounicodes */
- /* to the character blobs, but for the moment we keep the current approach */
if (is_cidkeyed(fd->fm)) {
if (is_opentype(fd->fm)) {
writetype0(pdf, fd);
@@ -453,7 +459,7 @@ static void write_fontfile(PDF pdf, fd_entry * fd)
return;
assert(fd->ff_objnum == 0);
fd->ff_objnum = pdf_create_obj(pdf, obj_type_others, 0);
- pdf_begin_obj(pdf, fd->ff_objnum, OBJSTM_NEVER); /* font file stream */
+ pdf_begin_obj(pdf, fd->ff_objnum, OBJSTM_NEVER); /* font file stream */
pdf_begin_dict(pdf);
if (is_cidkeyed(fd->fm)) {
/* No subtype is used for TrueType-based OpenType fonts */
@@ -463,17 +469,16 @@ static void write_fontfile(PDF pdf, fd_entry * fd)
else
pdf_dict_add_name(pdf, "Subtype", "OpenType");
#endif
+ } else if (is_type1(fd->fm)) {
+ pdf_dict_add_int(pdf, "Length1", (int) t1_length1);
+ pdf_dict_add_int(pdf, "Length2", (int) t1_length2);
+ pdf_dict_add_int(pdf, "Length3", (int) t1_length3);
+ } else if (is_truetype(fd->fm)) {
+ pdf_dict_add_int(pdf, "Length1", (int) ttf_length);
+ } else if (is_opentype(fd->fm)) {
+ pdf_dict_add_name(pdf, "Subtype", "Type1C");
} else {
- if (is_type1(fd->fm)) {
- pdf_dict_add_int(pdf, "Length1", (int) t1_length1);
- pdf_dict_add_int(pdf, "Length2", (int) t1_length2);
- pdf_dict_add_int(pdf, "Length3", (int) t1_length3);
- } else if (is_truetype(fd->fm))
- pdf_dict_add_int(pdf, "Length1", (int) ttf_length);
- else if (is_opentype(fd->fm))
- pdf_dict_add_name(pdf, "Subtype", "Type1C");
- else
- assert(0);
+ assert(0); /* todo: error messages */
}
pdf_dict_add_streaminfo(pdf);
pdf_end_dict(pdf);
@@ -489,32 +494,36 @@ int cidset = 0;
static void write_fontdescriptor(PDF pdf, fd_entry * fd)
{
static const int std_flags[] = {
- /* indices for << start with 0, but bits start with 1, so the numbers
- * for << are 1 lower than the bits in table 5.20 */
+ /*
+ The indices for << start with 0, but bits start with 1, so the
+ numbers for << are 1 lower than the bits in table 5.20.
+ */
/* *INDENT-OFF* */
- 1 + 2 + (1 << 5), /* Courier */
- 1 + 2 + (1 << 5) + (1 << 18),/* Courier-Bold */
- 1 + 2 + (1 << 5) + (1 << 6), /* Courier-Oblique */
- 1 + 2 + (1 << 5) + (1 << 6) + (1 << 18),/* Courier-BoldOblique */
- (1 << 5), /* Helvetica */
- (1 << 5) + (1 << 18),/* Helvetica-Bold */
- (1 << 5) + (1 << 6), /* Helvetica-Oblique */
- (1 << 5) + (1 << 6) + (1 << 18),/* Helvetica-BoldOblique */
- 4, /* Symbol */
- 2 + (1 << 5), /* Times-Roman */
- 2 + (1 << 5) + (1 << 18),/* Times-Bold */
- 2 + (1 << 5) + (1 << 6), /* Times-Italic */
- 2 + (1 << 5) + (1 << 6) + (1 << 18),/* Times-BoldItalic */
- 4 /* ZapfDingbats */
+ 1 + 2 + (1 << 5), /* Courier */
+ 1 + 2 + (1 << 5) + (1 << 18), /* Courier-Bold */
+ 1 + 2 + (1 << 5) + (1 << 6), /* Courier-Oblique */
+ 1 + 2 + (1 << 5) + (1 << 6) + (1 << 18), /* Courier-BoldOblique */
+ (1 << 5), /* Helvetica */
+ (1 << 5) + (1 << 18), /* Helvetica-Bold */
+ (1 << 5) + (1 << 6), /* Helvetica-Oblique */
+ (1 << 5) + (1 << 6) + (1 << 18), /* Helvetica-BoldOblique */
+ 4, /* Symbol */
+ 2 + (1 << 5), /* Times-Roman */
+ 2 + (1 << 5) + (1 << 18), /* Times-Bold */
+ 2 + (1 << 5) + (1 << 6), /* Times-Italic */
+ 2 + (1 << 5) + (1 << 6) + (1 << 18), /* Times-BoldItalic */
+ 4 /* ZapfDingbats */
/* *INDENT-ON* */
};
char *glyph;
struct avl_traverser t;
int fd_flags;
assert(fd != NULL && fd->fm != NULL);
- cidset = 0; /* possibly updated by |write_fontfile| */
- if (is_fontfile(fd->fm) && is_included(fd->fm))
- write_fontfile(pdf, fd); /* this will set |fd->ff_found| if font file is found */
+ cidset = 0; /* possibly updated by |write_fontfile| */
+ if (is_fontfile(fd->fm) && is_included(fd->fm)) {
+ /* this will set |fd->ff_found| if font file is found */
+ write_fontfile(pdf, fd);
+ }
if (fd->fd_objnum == 0)
fd->fd_objnum = pdf_create_obj(pdf, obj_type_others, 0);
pdf_begin_obj(pdf, fd->fd_objnum, OBJSTM_ALWAYS);
@@ -572,10 +581,11 @@ static void write_fontdescriptor(PDF pdf, fd_entry * fd)
if ((! pdf->omit_cidset) && (cidset != 0)) {
pdf_dict_add_ref(pdf, "CIDSet", cidset);
}
- /* TODO: Other optional keys for CID fonts.
- The most interesting one is
- \.{/Style << /Panose <12-byte string>>>}
- */
+ /*
+ Currently we don't export the optional keys for CID fonts like
+ \.{/Style << /Panose <12-byte string> >>} and we probably never
+ will.
+ */
pdf_end_dict(pdf);
pdf_end_obj(pdf);
}
@@ -587,8 +597,7 @@ static void write_fontdescriptors(PDF pdf)
if (fd_tree == NULL)
return;
avl_t_init(&t, fd_tree);
- for (fd = (fd_entry *) avl_t_first(&t, fd_tree); fd != NULL;
- fd = (fd_entry *) avl_t_next(&t))
+ for (fd = (fd_entry *) avl_t_first(&t, fd_tree); fd != NULL; fd = (fd_entry *) avl_t_next(&t))
write_fontdescriptor(pdf, fd);
}
@@ -598,18 +607,16 @@ static void write_fontdictionary(PDF pdf, fo_entry * fo)
{
assert(fo != NULL);
assert(fo->fm != NULL);
- assert(fo->fo_objnum != 0); /* reserved as |pdf_font_num(f)| elsewhere */
+ /* reserved as |pdf_font_num(f)| elsewhere: */
+ assert(fo->fo_objnum != 0);
/* write ToUnicode entry if needed */
if (pdf->gen_tounicode > 0 && fo->fd != NULL) {
if (fo->fe != NULL) {
- fo->tounicode_objnum =
- write_tounicode(pdf, fo->fe->glyph_names, fo->fe->name);
+ fo->tounicode_objnum = write_tounicode(pdf, fo->fe->glyph_names, fo->fe->name);
} else if (is_type1(fo->fm)) {
assert(fo->fd->builtin_glyph_names != NULL);
- fo->tounicode_objnum =
- write_tounicode(pdf, fo->fd->builtin_glyph_names,
- fo->fm->tfm_name);
+ fo->tounicode_objnum = write_tounicode(pdf, fo->fd->builtin_glyph_names, fo->fm->tfm_name);
}
}
pdf_begin_obj(pdf, fo->fo_objnum, OBJSTM_ALWAYS);
@@ -630,13 +637,11 @@ static void write_fontdictionary(PDF pdf, fo_entry * fo)
pdf_dict_add_int(pdf, "FirstChar", (int) fo->first_char);
pdf_dict_add_int(pdf, "LastChar", (int) fo->last_char);
pdf_dict_add_ref(pdf, "Widths", (int) fo->cw_objnum);
- if ((is_type1(fo->fm) || is_opentype(fo->fm)) && fo->fe != NULL
- && fo->fe->fe_objnum != 0)
+ if ((is_type1(fo->fm) || is_opentype(fo->fm)) && fo->fe != NULL && fo->fe->fe_objnum != 0)
pdf_dict_add_ref(pdf, "Encoding", (int) fo->fe->fe_objnum);
if (fo->tounicode_objnum != 0)
pdf_dict_add_ref(pdf, "ToUnicode", (int) fo->tounicode_objnum);
- if (pdf_font_attr(fo->tex_font) != get_nullstr() &&
- pdf_font_attr(fo->tex_font) != 0) {
+ if (pdf_font_attr(fo->tex_font) != get_nullstr() && pdf_font_attr(fo->tex_font) != 0) {
pdf_print(pdf, pdf_font_attr(fo->tex_font));
pdf_out(pdf, '\n');
}
@@ -651,14 +656,12 @@ static void write_fontdictionaries(PDF pdf)
if (fo_tree == NULL)
return;
avl_t_init(&t, fo_tree);
- for (fo = (fo_entry *) avl_t_first(&t, fo_tree); fo != NULL;
- fo = (fo_entry *) avl_t_next(&t))
+ for (fo = (fo_entry *) avl_t_first(&t, fo_tree); fo != NULL; fo = (fo_entry *) avl_t_next(&t))
write_fontdictionary(pdf, fo);
}
-@ Final flush of all font related stuff by call from
- \.{Output fonts definitions} elsewhere
-
+@ Final flush of all font related stuff by call from \.{Output fonts
+definitions} elsewhere
@c
void write_fontstuff(PDF pdf)
{
@@ -673,23 +676,30 @@ static void create_fontdictionary(PDF pdf, internal_font_number f)
{
fo_entry *fo = new_fo_entry();
fm_entry *fm = font_map(f);
- get_char_range(fo, f); /* set |fo->first_char| and |fo->last_char| from |f| */
+ /* set |fo->first_char| and |fo->last_char| from |f| */
+ get_char_range(fo, f);
if (fo->last_char > 255)
- fo->last_char = 255; /* added 9-4-2008, mantis \#25 */
+ fo->last_char = 255;
assert(fo->last_char >= fo->first_char);
fo->fm = fm;
fo->fo_objnum = pdf_font_num(f);
fo->tex_font = f;
- if (is_reencoded(fo->fm)) { /* at least the map entry tells so */
- fo->fe = get_fe_entry(fo->fm->encname); /* returns |NULL| if .enc file couldn't be opened */
- if (fo->fe != NULL && (is_type1(fo->fm) || is_opentype(fo->fm))) { /* not entered for truetype */
+ if (is_reencoded(fo->fm)) {
+ /*
+ At least the map entry tells so but it returns |NULL| if the .enc
+ file couldn't be opened.
+ */
+ fo->fe = get_fe_entry(fo->fm->encname);
+ if (fo->fe != NULL && (is_type1(fo->fm) || is_opentype(fo->fm))) {
+ /* We don't end up here for truetype fonts. */
if (fo->fe->fe_objnum == 0)
fo->fe->fe_objnum = pdf_create_obj(pdf, obj_type_others, 0); /* then it will be written out */
- /* mark encoding pairs used by TeX to optimize encoding vector */
+ /* Mark encoding pairs used by TeX to optimize encoding vector. */
fo->fe->tx_tree = mark_chars(fo, fo->fe->tx_tree, f);
}
}
- fo->tx_tree = mark_chars(fo, fo->tx_tree, f); /* for |write_charwidth_array| */
+ /* for |write_charwidth_array|: */
+ fo->tx_tree = mark_chars(fo, fo->tx_tree, f);
write_charwidth_array(pdf, fo, f);
if (!is_builtin(fo->fm)) {
if (is_type1(fo->fm)) {
@@ -697,36 +707,42 @@ static void create_fontdictionary(PDF pdf, internal_font_number f)
create_fontdescriptor(fo, f);
register_fd_entry(fo->fd);
}
- } else
+ } else {
create_fontdescriptor(fo, f);
+ }
if (fo->fe != NULL) {
mark_reenc_glyphs(fo, f);
if (!is_type1(fo->fm)) {
/* mark reencoded characters as chars on TeX level */
assert(fo->fd->tx_tree == NULL);
fo->fd->tx_tree = mark_chars(fo, fo->fd->tx_tree, f);
- if (is_truetype(fo->fm))
+ if (is_truetype(fo->fm)) {
fo->fd->write_ttf_glyph_names = true;
+ }
}
- } else
+ } else {
/* mark non-reencoded characters as chars on TeX level */
fo->fd->tx_tree = mark_chars(fo, fo->fd->tx_tree, f);
- if (!is_type1(fo->fm))
+ }
+ if (!is_type1(fo->fm)) {
write_fontdescriptor(pdf, fo->fd);
+ }
} else {
- /* builtin fonts still need the /Widths array and /FontDescriptor
- * (to avoid error 'font FOO contains bad /BBox')
- */
+ /*
+ Builtin fonts still need the /Widths array and /FontDescriptor
+ (to avoid error 'font FOO contains bad /BBox').
+ */
create_fontdescriptor(fo, f);
write_fontdescriptor(pdf, fo->fd);
- if (!is_std_t1font(fo->fm))
- formatted_warning("map file", "font '%s' is not a standard font; I suppose it is available to your PDF viewer then",
- fo->fm->ps_name);
+ if (!is_std_t1font(fo->fm)) {
+ formatted_warning("map file", "font '%s' is not a standard font; I suppose it is available to your PDF viewer then", fo->fm->ps_name);
+ }
}
- if (is_type1(fo->fm))
+ if (is_type1(fo->fm)) {
register_fo_entry(fo);
- else
+ } else {
write_fontdictionary(pdf, fo);
+ }
}
@
@@ -751,32 +767,37 @@ void do_pdf_font(PDF pdf, internal_font_number f)
{
int del_file = 0;
fm_entry *fm;
- /* TODO This is not 100\% true: CID is actually needed whenever (and
- only) there are more than 256 separate glyphs used. But for
- now, just assume the user knows what he is doing;
- */
+ /*
+ This is not 100\% true: CID is actually needed whenever (and
+ only) there are more than 256 separate glyphs used. But for
+ now, we just assume the user knows what he is doing. In practice
+ this seems to be the case.
+ */
if (!font_has_subset(f))
return;
if (font_encodingbytes(f) == 2) {
- /* Create a virtual font map entry, as this is needed by the
- rest of the font inclusion mechanism.
- */
+ /*
+ Create a virtual font map entry, as this is needed by the
+ rest of the font inclusion mechanism.
+ */
fm = font_map(f) = new_fm_entry();
fm->tfm_name = font_name(f); /* or whatever, not a real tfm */
fm->ff_name = font_filename(f); /* the actual file */
if (font_psname(f) != NULL)
- fm->ps_name = font_psname(f); /* the true name */
+ fm->ps_name = font_psname(f); /* the true name */
else
- fm->ps_name = font_fullname(f); /* the true name */
+ fm->ps_name = font_fullname(f); /* the true name */
if (fm->ff_name
&& strlen(fm->ff_name) >= 6
- && strstr(fm->ff_name,
- ".dfont") == (fm->ff_name + strlen(fm->ff_name) - 6)) {
- /* In case of a .dfont, we will extract the correct ttf here,
- and adjust |fm->ff_name| to point to the temporary file.
- This file will be deleted later. Todo: keep a nicer name
- somewhere for the terminal message.
+ && strstr(fm->ff_name,".dfont") == (fm->ff_name + strlen(fm->ff_name) - 6)) {
+ /*
+ In case of a .dfont, we will extract the correct ttf here,
+ and adjust |fm->ff_name| to point to the temporary file.
+ This file will be deleted later. Todo: keep a nicer name
+ somewhere for the terminal message.
+
+ Support for dfonts will be removed at some point anyhow.
*/
char *s = FindResourceTtfFont(fm->ff_name, fm->ps_name);
if (s != NULL) {
@@ -786,12 +807,14 @@ void do_pdf_font(PDF pdf, internal_font_number f)
formatted_error("font","file '%s' does not contain font '%s'",fm->ff_name, fm->ps_name);
}
}
- fm->encname = font_encodingname(f); /* for the CIDSystemInfo */
- fm->slant = font_slant(f); /* slant factor */
+ /* Needed for the CIDSystemInfo: */
+ fm->encname = font_encodingname(f);
+ fm->slant = font_slant(f);
set_slantset(fm);
- fm->extend = font_extend(f); /* extension factor */
+ fm->extend = font_extend(f);
set_extendset(fm);
- fm->fd_flags = 4; /* can perhaps be done better */
+ /* Flags can perhaps be done better. */
+ fm->fd_flags = 4;
set_inuse(fm);
switch (font_format(f)) {
@@ -826,7 +849,10 @@ void do_pdf_font(PDF pdf, internal_font_number f)
unlink(fm->ff_name);
} else {
- /* by now |font_map(f)|, if any, should have been set via |pdf_init_font()| */
+ /*
+ By now |font_map(f)|, if any, should have been set via
+ |pdf_init_font()|.
+ */
if ((fm = font_map(f)) == NULL
|| (fm->ps_name == NULL && fm->ff_name == NULL))
writet3(pdf, f);
@@ -836,12 +862,12 @@ void do_pdf_font(PDF pdf, internal_font_number f)
}
@ The glyph width is included in |glw_entry|, because that width
- depends on the value it has in the font where it is actually
- typeset from, not the font that is the 'owner' of the fd entry.
+depends on the value it has in the font where it is actually
+typeset from, not the font that is the 'owner' of the fd entry.
- TODO: It is possible that the user messes with the metric width,
- but handling that properly would require access to the 'hmtx' table
- at this point in the program.
+TODO: It is possible that the user messes with the metric width,
+but handling that properly would require access to the 'hmtx' table
+at this point in the program.
@c
static int comp_glw_entry(const void *pa, const void *pb, void *p
@@ -860,19 +886,19 @@ static void create_cid_fontdescriptor(fo_entry * fo, internal_font_number f)
assert(fo != NULL);
assert(fo->fm != NULL);
assert(fo->fd == NULL);
- fo->fd = new_fd_entry();
+ fo->fd = new_fd_entry(f);
preset_fontname(fo, f);
preset_fontmetrics(fo->fd, f);
- fo->fd->fe = fo->fe; /* encoding needed by TrueType writing */
- fo->fd->fm = fo->fm; /* map entry needed by TrueType writing */
+ fo->fd->fe = fo->fe; /* encoding needed by TrueType writing */
+ fo->fd->fm = fo->fm; /* map entry needed by TrueType writing */
fo->fd->gl_tree = avl_create(comp_glw_entry, NULL, &avl_xallocator);
assert(fo->fd->gl_tree != NULL);
}
-@ The values |font_bc()| and |font_ec()| are potentially large
- character ids, but the strings that are written out use CID
- indexes, and those are limited to 16-bit values.
+@ The values |font_bc()| and |font_ec()| are potentially large character
+ids, but the strings that are written out use CID indexes, and those are
+limited to 16-bit values.
@c
static void mark_cid_subset_glyphs(fo_entry * fo, internal_font_number f)
@@ -900,17 +926,16 @@ static void mark_cid_subset_glyphs(fo_entry * fo, internal_font_number f)
}
}
+@ It is possible to compress the widths array even better, by using the
+alternate 'range' syntax and possibly even using /DW to set a default
+value.
-@ It is possible to compress the widths array even better, by using the
- alternate 'range' syntax and possibly even using /DW to set
- a default value.
+There is a some optimization here already: glyphs that are not used do
+not appear in the widths array at all.
- There is a some optimization here already: glyphs that are
- not used do not appear in the widths array at all.
-
- We have to make sure that we do not output an (incorrect!)
- width for a character that exists in the font, but is not used
- in typesetting. An enormous negative width is used as sentinel value
+We have to make sure that we do not output an (incorrect!) width for a
+character that exists in the font, but is not used in typesetting. An
+enormous negative width is used as sentinel value
@c
static void write_cid_charwidth_array(PDF pdf, fo_entry * fo)
@@ -977,10 +1002,10 @@ static void create_cid_fontdictionary(PDF pdf, internal_font_number f)
mark_cid_subset_glyphs(fo, f);
if (is_subsetted(fo->fm)) {
/*
- this is a bit sneaky. |make_subset_tag()| actually expects the glyph tree
- to contain strings instead of |glw_entry| items. However, all calculations
- are done using explicit typecasts, so it works out ok.
- */
+ This is a bit sneaky. |make_subset_tag()| actually expects the glyph
+ tree to contain strings instead of |glw_entry| items. However, all
+ calculations are done using explicit typecasts, so it works out ok.
+ */
make_subset_tag(fo->fd);
}
write_cid_charwidth_array(pdf, fo);
@@ -1038,15 +1063,13 @@ void write_cid_fontdictionary(PDF pdf, fo_entry * fo, internal_font_number f)
pdf_dict_add_ref(pdf, "W", (int) fo->cw_objnum);
pdf_add_name(pdf, "CIDSystemInfo");
pdf_begin_dict(pdf);
- pdf_dict_add_string(pdf, "Registry",
- (font_cidregistry(f) ? font_cidregistry(f) : "Adobe"));
- pdf_dict_add_string(pdf, "Ordering",
- (font_cidordering(f) ? font_cidordering(f) :
- "Identity"));
+ pdf_dict_add_string(pdf, "Registry", (font_cidregistry(f) ? font_cidregistry(f) : "Adobe"));
+ pdf_dict_add_string(pdf, "Ordering", (font_cidordering(f) ? font_cidordering(f) : "Identity"));
pdf_dict_add_int(pdf, "Supplement", (int) font_cidsupplement(f));
pdf_end_dict(pdf);
/* I doubt there is anything useful that could be written here */
+
#if 0
if (pdf_font_attr(fo->tex_font) != get_nullstr()) {
pdf_out(pdf, '\n');
@@ -1054,6 +1077,7 @@ void write_cid_fontdictionary(PDF pdf, fo_entry * fo, internal_font_number f)
pdf_out(pdf, '\n');
}
#endif
+
pdf_end_dict(pdf);
pdf_end_obj(pdf);
}
diff --git a/Build/source/texk/web2c/luatexdir/font/writettf.w b/Build/source/texk/web2c/luatexdir/font/writettf.w
index e1edea5e2ab..ff968eef9e2 100644
--- a/Build/source/texk/web2c/luatexdir/font/writettf.w
+++ b/Build/source/texk/web2c/luatexdir/font/writettf.w
@@ -1751,7 +1751,6 @@ void writettf(PDF pdf, fd_entry * fd)
pdf_save_offset(pdf);
pdf_flush(pdf);
-
if (is_subsetted(fd_cur->fm)) {
ttf_copy_encoding();
ttf_subset_font(pdf);
@@ -1795,9 +1794,13 @@ static void do_writeotf(PDF pdf, fd_entry * fd)
if (ttf_name_lookup("post", false) != NULL)
ttf_read_post();
/* copy font file */
- tab = ttf_seek_tab("CFF ", 0);
- for (i = (long) tab->length; i > 0; i--)
+ if (ttf_name_lookup("CFF2", false) != NULL) /* HH */
+ tab = ttf_seek_tab("CFF2", 0); /* HH */
+ else /* HH */
+ tab = ttf_seek_tab("CFF ", 0);
+ for (i = (long) tab->length; i > 0; i--) {
copy_char();
+ }
xfree(dir_tab);
if (tracefilenames)
tex_printf(">>");
diff --git a/Build/source/texk/web2c/luatexdir/font/writetype0.w b/Build/source/texk/web2c/luatexdir/font/writetype0.w
index 3053103c524..ebf4be66723 100644
--- a/Build/source/texk/web2c/luatexdir/font/writetype0.w
+++ b/Build/source/texk/web2c/luatexdir/font/writetype0.w
@@ -19,13 +19,13 @@
@ @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;
@@ -76,14 +76,12 @@ void writetype0(PDF pdf, fd_entry * fd)
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);
@@ -99,7 +97,10 @@ void writetype0(PDF pdf, fd_entry * fd)
ttf_read_post();
/* copy font file */
- tab = ttf_seek_tab("CFF ", 0);
+ 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);
diff --git a/Build/source/texk/web2c/luatexdir/font/writetype2.w b/Build/source/texk/web2c/luatexdir/font/writetype2.w
index 950af999879..dc1821c5e5f 100644
--- a/Build/source/texk/web2c/luatexdir/font/writetype2.w
+++ b/Build/source/texk/web2c/luatexdir/font/writetype2.w
@@ -344,7 +344,7 @@ boolean make_tt_subset(PDF pdf, fd_entry * fd, unsigned char *buff, int buflen)
normal_error("type 2","there are no glyphs in the subset");
}
- if (tt_build_tables(sfont, glyphs) < 0) {
+ if (tt_build_tables(sfont, glyphs, fd) < 0) {
normal_error("type 2","the TTF buffer can't be parsed");
}
diff --git a/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c b/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c
index 988d1e40c51..7944fdfd8a5 100644
--- a/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c
+++ b/Build/source/texk/web2c/luatexdir/lua/lcallbacklib.c
@@ -74,6 +74,7 @@ static const char *const callbacknames[] = {
"contribute_filter",
"call_edit",
"build_page_insert",
+ "glyph_stream_provider",
NULL
};
diff --git a/Build/source/texk/web2c/luatexdir/lua/luatex-api.h b/Build/source/texk/web2c/luatexdir/lua/luatex-api.h
index 7d34607b9e0..2ec38e6b686 100644
--- a/Build/source/texk/web2c/luatexdir/lua/luatex-api.h
+++ b/Build/source/texk/web2c/luatexdir/lua/luatex-api.h
@@ -782,6 +782,7 @@ make_lua_key(start);\
make_lua_key(step);\
make_lua_key(stream);\
make_lua_key(streamfile);\
+make_lua_key(streamprovider);\
make_lua_key(stretch);\
make_lua_key(stretch_order);\
make_lua_key(string);\
@@ -1143,6 +1144,7 @@ init_lua_key(start);\
init_lua_key(step);\
init_lua_key(stream);\
init_lua_key(streamfile);\
+init_lua_key(streamprovider);\
init_lua_key(stretch);\
init_lua_key(stretch_order);\
init_lua_key(string);\
@@ -1571,6 +1573,7 @@ use_lua_key(start);
use_lua_key(step);
use_lua_key(stream);
use_lua_key(streamfile);
+use_lua_key(streamprovider);
use_lua_key(stretch);
use_lua_key(stretch_order);
use_lua_key(string);
diff --git a/Build/source/texk/web2c/luatexdir/luatexcallbackids.h b/Build/source/texk/web2c/luatexdir/luatexcallbackids.h
index 6ca9da7087e..927c4f1b2f1 100644
--- a/Build/source/texk/web2c/luatexdir/luatexcallbackids.h
+++ b/Build/source/texk/web2c/luatexdir/luatexcallbackids.h
@@ -68,6 +68,7 @@ typedef enum {
contribute_filter_callback,
call_edit_callback,
build_page_insert_callback,
+ glyph_stream_provider_callback,
total_callbacks
} callback_callback_types;
diff --git a/Build/source/texk/web2c/luatexdir/tex/dumpdata.w b/Build/source/texk/web2c/luatexdir/tex/dumpdata.w
index 0c4e51a7593..aa0d1655d6d 100644
--- a/Build/source/texk/web2c/luatexdir/tex/dumpdata.w
+++ b/Build/source/texk/web2c/luatexdir/tex/dumpdata.w
@@ -23,7 +23,7 @@
/* we start with 907: the sum of the values of the bytes of "don knuth" */
-#define FORMAT_ID (907+27)
+#define FORMAT_ID (907+28)
#if ((FORMAT_ID>=0) && (FORMAT_ID<=256))
#error Wrong value for FORMAT_ID.
#endif