summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/luatexdir/font
diff options
context:
space:
mode:
authorLuigi Scarso <luigi.scarso@gmail.com>2020-10-04 19:39:39 +0000
committerLuigi Scarso <luigi.scarso@gmail.com>2020-10-04 19:39:39 +0000
commit897efa4b7afe155a5913e31e318891bba54dd1bb (patch)
treec696b26e7512932f476d9fde7536194a585457cf /Build/source/texk/web2c/luatexdir/font
parentb485704ecdb46ae6bc0997142320038f924469d1 (diff)
sync with upstream luatex; Lua 5.3.6
git-svn-id: svn://tug.org/texlive/trunk@56535 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/font')
-rw-r--r--Build/source/texk/web2c/luatexdir/font/luatexfont.h11
-rw-r--r--Build/source/texk/web2c/luatexdir/font/tounicode.c60
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writefont.c18
-rw-r--r--Build/source/texk/web2c/luatexdir/font/writet3.c182
4 files changed, 213 insertions, 58 deletions
diff --git a/Build/source/texk/web2c/luatexdir/font/luatexfont.h b/Build/source/texk/web2c/luatexdir/font/luatexfont.h
index 5eb6a5bd94e..c60fc4a91f9 100644
--- a/Build/source/texk/web2c/luatexdir/font/luatexfont.h
+++ b/Build/source/texk/web2c/luatexdir/font/luatexfont.h
@@ -119,9 +119,10 @@ typedef struct {
/* tounicode.c */
int write_cid_tounicode(PDF, fo_entry *, internal_font_number);
-void glyph_unicode_free(void);
-void def_tounicode(str_number, str_number);
int write_tounicode(PDF, char **, char *);
+int write_raw_tounicode(PDF, internal_font_number, char *);
+void def_tounicode(str_number, str_number);
+void glyph_unicode_free(void);
/* vfpacket.c */
@@ -143,6 +144,7 @@ void writetype0(PDF pdf, fd_entry * fd);
/* writefont.c */
void do_pdf_font(PDF, internal_font_number);
+int do_pdf_preroll_font(PDF, internal_font_number);
fd_entry *lookup_fd_entry(char *);
fd_entry *new_fd_entry(internal_font_number);
void write_fontstuff(PDF);
@@ -194,7 +196,10 @@ internal_font_number copy_font_info(internal_font_number f);
/* writet3.c */
extern FILE *t3_file;
-void writet3(PDF, internal_font_number);
+
+void writet3pk(PDF, internal_font_number);
+void prerollt3user(PDF, internal_font_number);
+void writet3user(PDF, internal_font_number);
extern unsigned char *t3_buffer;
extern int t3_size;
diff --git a/Build/source/texk/web2c/luatexdir/font/tounicode.c b/Build/source/texk/web2c/luatexdir/font/tounicode.c
index 32210600c21..b1e08e7cebd 100644
--- a/Build/source/texk/web2c/luatexdir/font/tounicode.c
+++ b/Build/source/texk/web2c/luatexdir/font/tounicode.c
@@ -305,22 +305,30 @@ static void set_cid_glyph_unicode(long index, glyph_unicode_entry * gp, internal
}
*/
-int write_tounicode(PDF pdf, char **glyph_names, char *name)
+static int do_write_tounicode(PDF pdf, char **glyph_names, char *name, internal_font_number f)
{
- char buf[SMALL_BUF_SIZE], *p;
+ char buf[SMALL_BUF_SIZE], *p, *s;
static char builtin_suffix[] = "-builtin";
short range_size[257];
glyph_unicode_entry gtab[257];
int objnum;
int i, j;
int bfchar_count, bfrange_count, subrange_count;
- assert(strlen(name) + strlen(builtin_suffix) < SMALL_BUF_SIZE);
if (glyph_unicode_tree == NULL) {
pdf->gen_tounicode = 0;
return 0;
}
- strcpy(buf, name);
- if ((p = strrchr(buf, '.')) != NULL && strcmp(p, ".enc") == 0) {
+ if (name == NULL) {
+ strcpy(buf, "no-name");
+ } else {
+ strcpy(buf, name);
+ }
+ if (f) {
+ /*tex
+ Always.
+ */
+ strcat(buf, builtin_suffix);
+ } else if ((p = strrchr(buf, '.')) != NULL && strcmp(p, ".enc") == 0) {
/*tex
Strip |.enc| from encoding name.
*/
@@ -332,6 +340,29 @@ int write_tounicode(PDF pdf, char **glyph_names, char *name)
*/
strcat(buf, builtin_suffix);
}
+ /*tex Set gtab: */
+ if (f) {
+ int done = 0 ;
+ for (i = 0; i < 256; ++i) {
+ if ((s = get_charinfo_tounicode(char_info(f,(int)i))) != NULL) {
+ gtab[i].code = UNI_EXTRA_STRING;
+ gtab[i].unicode_seq = xstrdup(s);
+ done = 1 ;
+ } else {
+ gtab[i].code = UNI_UNDEF;
+ }
+ }
+ if (! done) {
+ return 0;
+ }
+ } else {
+ for (i = 0; i < 256; ++i) {
+ gtab[i].code = UNI_UNDEF;
+ set_glyph_unicode(glyph_names[i], &gtab[i]);
+ }
+ }
+ gtab[256].code = UNI_UNDEF;
+ /* */
objnum = pdf_create_obj(pdf, obj_type_others, 0);
pdf_begin_obj(pdf, objnum, OBJSTM_NEVER);
pdf_begin_dict(pdf);
@@ -359,12 +390,6 @@ int write_tounicode(PDF pdf, char **glyph_names, char *name)
"1 begincodespacerange\n"
"<00> <FF>\n" "endcodespacerange\n",
buf, buf, buf, buf, buf);
- /*tex Set gtab: */
- for (i = 0; i < 256; ++i) {
- gtab[i].code = UNI_UNDEF;
- set_glyph_unicode(glyph_names[i], &gtab[i]);
- }
- gtab[256].code = UNI_UNDEF;
/*tex Set |range_size|: */
for (i = 0; i < 256;) {
if (gtab[i].code == UNI_STRING || gtab[i].code == UNI_EXTRA_STRING) {
@@ -414,8 +439,7 @@ int write_tounicode(PDF pdf, char **glyph_names, char *name)
while (range_size[i] <= 1 && i < 256)
i++;
assert(i < 256);
- pdf_printf(pdf, "<%02X> <%02X> <%s>\n", i, i + range_size[i] - 1,
- utf16be_str(gtab[i].code));
+ pdf_printf(pdf, "<%02X> <%02X> <%s>\n", i, i + range_size[i] - 1, utf16be_str(gtab[i].code));
i += range_size[i];
}
pdf_printf(pdf, "endbfrange\n");
@@ -467,6 +491,16 @@ int write_tounicode(PDF pdf, char **glyph_names, char *name)
return objnum;
}
+int write_tounicode(PDF pdf, char **glyph_names, char *name)
+{
+ return do_write_tounicode(pdf, glyph_names, name, 0);
+}
+
+int write_raw_tounicode(PDF pdf, internal_font_number f, char *name)
+{
+ return do_write_tounicode(pdf, NULL, name, f);
+}
+
int write_cid_tounicode(PDF pdf, fo_entry * fo, internal_font_number f)
{
static int range_size[65537];
diff --git a/Build/source/texk/web2c/luatexdir/font/writefont.c b/Build/source/texk/web2c/luatexdir/font/writefont.c
index b367fa2bf85..13fa8b7543d 100644
--- a/Build/source/texk/web2c/luatexdir/font/writefont.c
+++ b/Build/source/texk/web2c/luatexdir/font/writefont.c
@@ -851,13 +851,27 @@ void do_pdf_font(PDF pdf, internal_font_number f)
create_cid_fontdictionary(pdf, f);
} else {
/*tex 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);
+ if (font_psname(f) != NULL && strstr(font_psname(f),"none"))
+ writet3user(pdf, f);
+ else if ((fm = font_map(f)) == NULL || (fm->ps_name == NULL && fm->ff_name == NULL))
+ writet3pk(pdf, f);
else
create_fontdictionary(pdf, f);
}
}
+int do_pdf_preroll_font(PDF pdf, internal_font_number f)
+{
+ if (!font_has_subset(f)) {
+ return 0;
+ } else if (font_encodingbytes(f) != 2 && font_psname(f) != NULL && strstr(font_psname(f),"none")) {
+ prerollt3user(pdf, f);
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
/*tex
The glyph width is included in |glw_entry|, because that width depends on the
diff --git a/Build/source/texk/web2c/luatexdir/font/writet3.c b/Build/source/texk/web2c/luatexdir/font/writet3.c
index 6121c24a1f0..693bb0c6ef9 100644
--- a/Build/source/texk/web2c/luatexdir/font/writet3.c
+++ b/Build/source/texk/web2c/luatexdir/font/writet3.c
@@ -31,14 +31,12 @@ typedef char t3_line_entry;
define_array(t3_line);
FILE *t3_file;
-static boolean t3_image_used;
static int t3_char_procs[256];
-static float t3_char_widths[256];
+static double t3_char_widths[256];
static int t3_glyph_num;
-static float t3_font_scale;
+static double t3_font_scale;
static int t3_b0, t3_b1, t3_b2, t3_b3;
-static boolean is_pk_font;
/*tex Not static because used elsewhere. */
@@ -135,8 +133,6 @@ static boolean writepk(PDF pdf, internal_font_number f)
t3_read_file();
t3_close();
}
- t3_image_used = true;
- is_pk_font = true;
report_start_file(filetype_font,(char *) name);
cd.rastersize = 256;
cd.raster = xtalloc((unsigned long) cd.rastersize, halfword);
@@ -150,7 +146,7 @@ static boolean writepk(PDF pdf, internal_font_number f)
check_preamble = false;
if (!pdf_char_marked(f, cd.charcode))
continue;
- t3_char_widths[cd.charcode] = (float) pk_char_width(pdf, f, get_charwidth(f, cd.charcode), pdf->pk_scale_factor);
+ t3_char_widths[cd.charcode] = (double) pk_char_width(pdf, f, get_charwidth(f, cd.charcode), pdf->pk_scale_factor);
if (cd.cwidth < 1 || cd.cheight < 1) {
cd.xescape = cd.cwidth = round(t3_char_widths[cd.charcode] / 100.0);
cd.cheight = 1;
@@ -206,35 +202,86 @@ static boolean writepk(PDF pdf, internal_font_number f)
return true;
}
-void writet3(PDF pdf, internal_font_number f)
+/*tex
+
+ Mode |0| is traditional pk with map file lookup, while mode |1| listens to
+ the callback. The callback gets a font id and character number and returns an
+ object number of a stream object plus the width that ends up in the widths
+ array. The stream can of course refer to another xform but it has to start
+ with the right sequence for being a character. As there are different
+ situations this is more flexible that hardcoding all kind of variants that
+ will never suit all possible purposes.
+
+ The next ones are a bit strange. We could as well have had one callback that
+ just generates the whole type 3 but I think that the assumption is that
+ \LUATEX\ should do the work. So, instead we have one callback that is invoked
+ with several intentions as indicated by the first argument.
+
+*/
+
+static void writet3(PDF pdf, internal_font_number f, int callback_id)
{
int i;
char s[32];
int wptr, eptr, cptr;
int first_char, last_char;
int pk_font_scale;
+ int tounicode_objnum = 0;
pdffloat pf;
boolean is_notdef;
t3_glyph_num = 0;
- t3_image_used = false;
for (i = 0; i < 256; i++) {
t3_char_procs[i] = 0;
t3_char_widths[i] = 0;
}
- is_pk_font = false;
xfree(t3_buffer);
t3_curbyte = 0;
t3_size = 0;
- if (!writepk(pdf, f))
- return;
- for (i = font_bc(f); i <= font_ec(f); i++)
- if (pdf_char_marked(f, i))
+ for (i = font_bc(f); i <= font_ec(f); i++) {
+ if (pdf_char_marked(f, i)) {
break;
+ }
+ }
first_char = i;
- for (i = font_ec(f); i > first_char; i--)
- if (pdf_char_marked(f, i))
+ for (i = font_ec(f); i > first_char; i--) {
+ if (pdf_char_marked(f, i)) {
break;
+ }
+ }
last_char = i;
+ if (callback_id > 0) {
+ /*tex We assume a user font. */
+ for (i = first_char; i <= last_char; i++) {
+ if (pdf_char_marked(f, i)) {
+ int r = 0;
+ double w = 0;
+ /*tex
+ We pass |2|, the font id, the character index, and we expect
+ back a width in basepoints, an object number of a stream, and
+ an objectnumber of an xobject used where zero means nothing is
+ used.
+ */
+ run_callback(callback_id, "ddd->df", 2, f, i, &r, &w);
+ if (r > 0) {
+ t3_char_procs[i] = r;
+ t3_char_widths[i] = w;
+ }
+ }
+ }
+ t3_font_scale = 0.001;
+ t3_b0 = 0;
+ t3_b1 = 0;
+ t3_b2 = 0;
+ t3_b3 = 0;
+ } else if (writepk(pdf, f)) {
+ /*tex We assume a pk font. */
+ } else {
+ /*tex We just quit. */
+ return;
+ }
+ if (pdf->gen_tounicode > 0) {
+ tounicode_objnum = write_raw_tounicode(pdf, f, font_fullname(f));
+ }
/*tex We create a |Type3| font dictionary: */
pdf_begin_obj(pdf, pdf_font_num(f), OBJSTM_ALWAYS);
pdf_begin_dict(pdf);
@@ -247,22 +294,6 @@ void writet3(PDF pdf, internal_font_number f)
pdf_print(pdf, pdf_font_attr(f));
pdf_out(pdf, '\n');
}
- if (is_pk_font) {
- pk_font_scale = get_pk_font_scale(pdf,f,pdf->pk_scale_factor);
- pdf_add_name(pdf, "FontMatrix");
- pdf_begin_array(pdf);
- setpdffloat(pf, (int64_t) pk_font_scale, 5);
- print_pdffloat(pdf, pf);
- pdf_puts(pdf, " 0 0 ");
- print_pdffloat(pdf, pf);
- pdf_puts(pdf, " 0 0");
- pdf_end_array(pdf);
- } else {
- pdf_add_name(pdf, "FontMatrix");
- pdf_begin_array(pdf);
- pdf_printf(pdf, "%g 0 0 %g 0 0", (double) t3_font_scale, (double) t3_font_scale);
- pdf_end_array(pdf);
- }
pdf_add_name(pdf, font_key[FONTBBOX1_CODE].pdfname);
pdf_begin_array(pdf);
pdf_add_int(pdf, (int) t3_b0);
@@ -271,15 +302,56 @@ void writet3(PDF pdf, internal_font_number f)
pdf_add_int(pdf, (int) t3_b3);
pdf_end_array(pdf);
pdf_add_name(pdf, "Resources");
+ /*tex
+ This is not mandate but we just set them all. They are ignored anyway. In
+ PDF version 2 they are even obsolete but then, unknown entries are again
+ ignored.
+ */
pdf_begin_dict(pdf);
pdf_add_name(pdf, "ProcSet");
pdf_begin_array(pdf);
pdf_add_name(pdf, "PDF");
- if (t3_image_used) {
- pdf_add_name(pdf, "ImageB");
+ pdf_add_name(pdf, "ImageB");
+ if (callback_id) {
+ pdf_add_name(pdf, "ImageC");
+ pdf_add_name(pdf, "ImageI");
+ pdf_add_name(pdf, "Text");
}
pdf_end_array(pdf);
- pdf_end_dict(pdf);
+ /*tex
+ A previous version had two calls that dealt with adding font resources and
+ xform references and a separate one for the font matrix but we now delegate
+ some stupid work to the caller and have all in one: we expect a matrix and
+ a resource string.
+ */
+ if (callback_id > 0) {
+ char *str = NULL;
+ double s = t3_font_scale;
+ run_callback(callback_id, "dd->fR", 3, f, &s, &str);
+ t3_font_scale = s;
+ if (str != NULL) {
+ pdf_out(pdf, ' ');
+ pdf_puts(pdf, str);
+ free(str);
+ }
+ pdf_end_dict(pdf); /*tex The resources. */
+ pdf_add_name(pdf, "FontMatrix");
+ pdf_begin_array(pdf);
+ pdf_printf(pdf, "%g 0 0 %g 0 0", t3_font_scale, t3_font_scale);
+ pdf_end_array(pdf);
+ } else {
+ pdf_end_dict(pdf); /*tex The resources. */
+ pk_font_scale = get_pk_font_scale(pdf,f,pdf->pk_scale_factor);
+ pdf_add_name(pdf, "FontMatrix");
+ pdf_begin_array(pdf);
+ setpdffloat(pf, (int64_t) pk_font_scale, 5);
+ print_pdffloat(pdf, pf);
+ pdf_puts(pdf, " 0 0 ");
+ print_pdffloat(pdf, pf);
+ pdf_puts(pdf, " 0 0");
+ pdf_end_array(pdf);
+ }
+ /*tex Some preparations. */
pdf_dict_add_int(pdf, "FirstChar", first_char);
pdf_dict_add_int(pdf, "LastChar", last_char);
wptr = pdf_create_obj(pdf, obj_type_others, 0);
@@ -288,20 +360,23 @@ void writet3(PDF pdf, internal_font_number f)
pdf_dict_add_ref(pdf, "Widths", (int) wptr);
pdf_dict_add_ref(pdf, "Encoding", (int) eptr);
pdf_dict_add_ref(pdf, "CharProcs", (int) cptr);
+ if (tounicode_objnum) {
+ pdf_dict_add_ref(pdf, "ToUnicode", tounicode_objnum);
+ }
pdf_end_dict(pdf);
pdf_end_obj(pdf);
/*tex The |Widths| array: */
pdf_begin_obj(pdf, wptr, OBJSTM_ALWAYS);
pdf_begin_array(pdf);
- if (is_pk_font) {
+ if (callback_id) {
for (i = first_char; i <= last_char; i++) {
- setpdffloat(pf, (int64_t) t3_char_widths[i], 2);
- print_pdffloat(pdf, pf);
- pdf_out(pdf, ' ');
+ pdf_printf(pdf, " %g", t3_char_widths[i]);
}
} else {
for (i = first_char; i <= last_char; i++) {
- pdf_add_int(pdf, (int) t3_char_widths[i]);
+ setpdffloat(pf, (int64_t) t3_char_widths[i], 2);
+ print_pdffloat(pdf, pf);
+ pdf_out(pdf, ' ');
}
}
pdf_end_array(pdf);
@@ -354,3 +429,30 @@ void writet3(PDF pdf, internal_font_number f)
report_stop_file(filetype_font);
cur_file_name = NULL;
}
+
+void writet3pk(PDF pdf, internal_font_number f)
+{
+ writet3(pdf, f, 0);
+}
+
+void prerollt3user(PDF pdf, internal_font_number f)
+{
+ int callback_id = callback_defined(provide_charproc_data_callback);
+ if (callback_id > 0) {
+ int i;
+ for (i = font_bc(f); i <= font_ec(f); i++) {
+ if (pdf_char_marked(f, i)) {
+ /*tex We pass |true|, the font id and the character index. */
+ run_callback(callback_id, "ddd->", 1, f, i);
+ }
+ }
+ }
+}
+
+void writet3user(PDF pdf, internal_font_number f)
+{
+ int callback_id = callback_defined(provide_charproc_data_callback);
+ if (callback_id) {
+ writet3(pdf, f, callback_id);
+ }
+}