[Dev-luatex] Improvements for glyph_stream_provider with TTF fonts

Marcel Fabian Kr├╝ger tex at 2krueger.de
Sun Aug 8 13:27:06 CEST 2021


Hi,

On Sun, Aug 08, 2021 at 12:19:36PM +0200, luigi scarso wrote:
> Patch is now ok, but I am perplexed by this line
> 
> -                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);
> 
> It's not clear why now we use 2.

Basically this call is always compatible with the call made if the
streamprovider were 2, so 2 is passed to differentiate it from the
second call which actually provides behavior specific to streamprovider 3
and therefore uses streamprovider 3.

We could also do this differently, e.g. by letting the Lua code determine
it automatically by looking at the number of arguments passed to the
callback or using different callback names, but since I would assume
that most implementations would want to treat the callback from
streamprovider 2 and the streamprovider 2 compatible call from
streamprovider 3 identically anyway I considered this nicer.

> Perhaps it's better to introduce another variable, i.e.
> int actual_streamprovider ;
> if actual_streamprovider>2 {
>   actual_streamprovider=2;
> }
> run_callback(callback_id, "ddd->L", tex_font, g->gd[i].gid,
> actual_streamprovider, &result);
> 
> Or add a comment  before , something like
> /* The streamprovider here is always 2 because... */

Suggested comment:

  /*
      The streamprovider here is always 2, even when we actually have streamprovider == 3,
      to differentiate this call which behaves exactly like the call in the
      streamprovider == 2 case from the streamprovider == 3 specific call earlier.
  */

Best regards,
Marcel

> 
> -- 
> luigi

> _______________________________________________
> dev-luatex mailing list
> dev-luatex at ntg.nl
> https://mailman.ntg.nl/mailman/listinfo/dev-luatex

-------------- next part --------------
diff --git a/source/texk/web2c/luatexdir/font/tt_glyf.c b/source/texk/web2c/luatexdir/font/tt_glyf.c
index 750e126aa..010a25a7f 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,24 @@ 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,
+                streamprovider, 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 +412,12 @@ 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);
+                /*
+                    The streamprovider here is always 2, even when we actually have streamprovider == 3,
+                    to differentiate this call which behaves exactly like the call in the
+                    streamprovider == 2 case from the streamprovider == 3 specific call earlier.
+                */
+                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