[Dev-luatex] Improvements for glyph_stream_provider with TTF fonts

Marcel Fabian Krüger tex at 2krueger.de
Sat Aug 7 14:26:08 CEST 2021


On Sat, Aug 07, 2021 at 10:43:35AM +0200, luigi scarso wrote:
> On Sat, Aug 7, 2021 at 2:30 AM Marcel Fabian Krüger <tex at 2krueger.de> wrote:
> 
> >
> > An example implementation is attached.
> >
> 
> 
> $> dos2unix streamprovider3.patch
> 
> $> patch  <streamprovider3.patch
> patching file tt_glyf.c
> Hunk #2 succeeded at 230 with fuzz 1.
> 
> hm, different source files ?

No, just an odd diff. I applied it locally with patch and got the same
fuzz. The result is correct though. I'll attach a fixed patch file anyway.
(It's probably caused by attempts to make the patch more
readable by moving lines around. Not quite sure what exactly caused it.
I had only checked patch with `git apply` before which seems to be more
tolerant.)

Best,

  Marcel
-------------- next part --------------
diff --git a/source/texk/web2c/luatexdir/font/tt_glyf.c b/source/texk/web2c/luatexdir/font/tt_glyf.c
index 750e126aa..17a72c8e4 100644
--- a/source/texk/web2c/luatexdir/font/tt_glyf.c
+++ b/source/texk/web2c/luatexdir/font/tt_glyf.c
@@ -163,7 +163,7 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g, fd_entry * fd)
     int tex_font = fd->tex_font;
     int streamprovider = 0;
     int callback_id = 0 ;
-    if ((tex_font > 0) && (font_streamprovider(tex_font) == 2)) {
+    if ((tex_font > 0) && (font_streamprovider(tex_font) == 2 || font_streamprovider(tex_font) == 3)) {
         streamprovider = font_streamprovider(tex_font);
         callback_id = callback_defined(glyph_stream_provider_callback);
     }
@@ -230,14 +230,23 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g, fd_entry * fd)
             formatted_error("ttf","invalid glyph index (gid %u)", gid);
         loc = location[gid];
         len = location[gid + 1] - loc;
-        g->gd[i].advw = hmtx[gid].advance;
-        g->gd[i].lsb = hmtx[gid].sideBearing;
-        if (vmtx) {
-            g->gd[i].advh = vmtx[gid].advance;
-            g->gd[i].tsb = vmtx[gid].sideBearing;
+        if (callback_id > 0 && streamprovider == 3) {
+            int advw, lsb, advh, tsb;
+            run_callback(callback_id, "dddd->dddd", tex_font, g->gd[i].gid, 3, gid, &advw, &lsb, &advh, &tsb);
+            g->gd[i].advw = advw;
+            g->gd[i].lsb = lsb;
+            g->gd[i].advh = advh;
+            g->gd[i].tsb = tsb;
         } else {
-            g->gd[i].advh = g->default_advh;
-            g->gd[i].tsb = g->default_tsb;
+            g->gd[i].advw = hmtx[gid].advance;
+            g->gd[i].lsb = hmtx[gid].sideBearing;
+            if (vmtx) {
+                g->gd[i].advh = vmtx[gid].advance;
+                g->gd[i].tsb = vmtx[gid].sideBearing;
+            } else {
+                g->gd[i].advh = g->default_advh;
+                g->gd[i].tsb = g->default_tsb;
+            }
         }
         g->gd[i].length = len;
         g->gd[i].data = NULL;
@@ -402,7 +411,7 @@ int tt_build_tables(sfnt * sfont, struct tt_glyphs *g, fd_entry * fd)
             if (callback_id > 0) {
                 lstring * result;
                 long size = 0;
-                run_callback(callback_id, "ddd->L", tex_font, g->gd[i].gid, streamprovider, &result);
+                run_callback(callback_id, "ddd->L", tex_font, g->gd[i].gid, 2, &result);
                 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) {


More information about the dev-luatex mailing list