ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen via ntg-context <ntg-context@ntg.nl>
To: ntg-context@ntg.nl
Cc: Hans Hagen <j.hagen@freedom.nl>
Subject: [NTG-context] Re: fixing kerning and substitutions
Date: Wed, 9 Oct 2024 17:01:54 +0200	[thread overview]
Message-ID: <a9cf97c2-1fea-45c9-a6db-11fe6b74ca16@freedom.nl> (raw)
In-Reply-To: <C7F8CA3E-6A9C-44C1-81E0-36EC268E7914@gmail.com>

On 10/9/2024 12:22 PM, Florian Grammel wrote:
> I am trying to reuse code of a project from 2017 with TL23 context. (Other questions probably coming up...)
> 
> Back then I used font handlers to fix some smaller problems in the font, i.e. a wrongly placed small capital and missing kerning for the small caps.
> 
> The following code works with context 2017.04.27 01:00 MKIV beta but has stopped having any effect using recent context (2023.05.05 18:36 LMTX).
> There are no error messages.
> 
> Has the syntax changed? Or is the functionality dropped completely?
> 
> I was also wondering why it has never been working to adjust the kerning for the regular letters, e.g. "A" and "V" in the example, neither in 2017 nor today.
> 
> Thanks a lot in advance!
> Florian.
> 
> 
> 
> 
> 
> 
> 
> 
> \definefontfamily     [mainface] [serif] [Palatino Linotype] [oldstyle]
> 
> \setupbodyfont [mainface]
> 
> 
> 
> %\feature[+][oldstyle]
> %\feature[+][kernup]
> 
> 
> 
> %works with Context beta from 2017, doesn't work with TL 2023
> \directlua{
> fonts.handlers.otf.addfeature
> 	{
>      name = "smcp",
>      type = "alternate",
>      data =
>      	{
>              ['eth'] = 'Eth.ordn' ,
> %            ['k.smcp'] = 'Ķ' ,
>          },
> 	}
> }
> 
> %works for the smcp with Context beta from 2017, doesn't work for the regular capital letters
> %doesn't work at all with Context TL 2023
> \directlua
> {
>   fonts.handlers.otf.addfeature
>    {
>      name = "kern",
>      type = "kern",
>      data =
>          {
>              ["A"] = { ["V"] =  1500 },
>              ["P"] = { ["Æ"] =  1500 },
>              ["a.smcp"] = { ["s.smcp"] =  1500 },
>           },
>    }
>   }
>   
> 
> 
> 
> \startdocument
> 
> 
> AVAPÆV
> 
> þýðask
> 
> {\sc þýðask}
> 
> 123

Nothing has changed (in fact, the font handler hasn't been touched that 
much at all, apart from some fixes for border cases that you're unlikely 
to run into).

There are several issues with your approach, one being that you add a 
feature *after* defining the font, so it is not applied. You also use 
names and that fonts doesn't have names like that.

Something like this can work:


\startluacode
local getsubstitution = fonts.handlers.otf.getsubstitution

fonts.handlers.otf.addfeature {
     name = "smcp",
     type = "alternate",
     data = {
         ["ð"] = char_e,
     },
     data = function(data,specification,list,i)
         -- maybe intercept this cheat in a next version
         data = { shared = { rawdata = { resources = data.resources } } }
         --
         local char_e = 
getsubstitution(data,utf.byte("ð"),"ordn",1,"latn","dflt")
         return {
             ["ð"] = char_e,
         }
     end,
}

fonts.handlers.otf.addfeature {
     name = "kern",
     type = "kern",
     data = function(data,specification,list,i)
         -- maybe intercept this cheat in a next version
         data = { shared = { rawdata = { resources = data.resources } } }
         --
         local char_a = 
getsubstitution(data,utf.byte("a"),"smcp",1,"latn","dflt")
         local char_s = 
getsubstitution(data,utf.byte("s"),"smcp",1,"latn","dflt")
         return {
             ["A"]    = { ["V"]    = 1500 },
             ["P"]    = { ["Æ"]    = 1500 },
             [char_a] = { [char_s] = 1500 },
         }
     end,
}
\stopluacode

\definefontfamily [mainface] [serif]  [Palatino Linotype]
\definefontfamily [mainface] [math]   [TeX Gyre Pagella]

\setupbodyfont [mainface]

\starttext
     AVAPÆV
     þýðask
     {\smallcaps þýðask}
     123
\stoptext

But it is a kind of ugly solution, mostly demonstrating that the nature 
of tex is that one can always find a solution for any weird problem.

Hans

-----------------------------------------------------------------
                                           Hans Hagen | PRAGMA ADE
               Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
        tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

      reply	other threads:[~2024-10-09 15:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-09 10:22 [NTG-context] " Florian Grammel
2024-10-09 15:01 ` Hans Hagen via ntg-context [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a9cf97c2-1fea-45c9-a6db-11fe6b74ca16@freedom.nl \
    --to=ntg-context@ntg.nl \
    --cc=j.hagen@freedom.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).