ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Hans Hagen via ntg-context <ntg-context@ntg.nl>
To: "Thomas A. Schmitz via ntg-context" <ntg-context@ntg.nl>
Cc: Hans Hagen <j.hagen@xs4all.nl>
Subject: Re: font features
Date: Thu, 3 Nov 2022 19:24:46 +0100	[thread overview]
Message-ID: <8874383b-3f05-76f7-0198-f18f0ce0260a@xs4all.nl> (raw)
In-Reply-To: <e39c312d-3eb4-71ca-f42c-72ba2134288c@uni-bonn.de>

On 11/3/2022 2:03 PM, Thomas A. Schmitz via ntg-context wrote:
> On 11/3/22 13:27, Henning Hraban Ramm via ntg-context wrote:
>> If it works for you, then it’s a problem of my installation, otherwise 
>> a regression in current LMTX...
> 
> No, I get the same error message, this looks promising but doesn't work.
> 
> And at the risk of sounding grumpy, but all of this is too much manual 
> intervention; I would like to have a completely automated script. So 
> I'll show what I have and add a few comments:
> 
> local Feature_Table = { }
> local Parsed_Features = { }
> 
> local My_Font = environment.arguments["font"]
> 
> local Font_Features = os.resultof("otfinfo -f " .. My_Font)
> 
> for Feature_Sigla, Feature_Name in
>    string.gmatch(Font_Features, "(%S-)\t(.-)\n") do
>    Feature_Table[Feature_Sigla] = Feature_Name
> end
> 
> COMMENTS
> 
> Expectation: this should return a list of all features and their 
> descriptions as a lua table. If you run the file as
> 
> context test.cld --font="/path/to/font"
> 
> this works, and you get a table
> 
> Feature_Table={
>   ["aalt"]="Access All Alternates",
>   ["c2sc"]="Small Capitals From Capitals"} etc.
> 
> CODE
> 
> for name, _ in pairs(Feature_Table) do
>    Context_Name = "f:" .. name
>    Parsed_Features[name] = Context_Name
>    context.definefontfeature( { Context_Name }, { name="yes" } )
> end
> 
> COMMENTS
> 
> This should produce a lua table with ConTeXt fontfeatures and define 
> those features. The table appears to be correct:
> 
> Parsed_Features={
>   ["aalt"]="f:aalt",
>   ["c2sc"]="f:c2sc"} etc.
> 
> So I expected that this should be equivalent to
> 
> \definefontfeature [f:aalt] [aalt=yes]
> 
> and return a list of defined features.
> 
> CODE
> 
> local Test_String = [[
> ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz 1234567890 1/4 2/8 
> 3/9 ffi ft fi fl ffl
> ]]
> 
> local Font_Name =  os.resultof("otfinfo -a " .. My_Font)
> 
> context.definefontfamily( { "Test" }, { "serif" }, { Font_Name }, {} )
> 
> context.setupbodyfont{ "Test, 12pt" }
> 
> COMMENTS
> 
> Again, this works; the font is set as bodyfont.
> 
> CODE
> 
> context.starttext()
> 
> for name, feature in pairs(Feature_Table) do
>    context.start ()
>    context.addfeature { Parsed_Features[name] }
>    context.midaligned (feature)
>    context.bold (Parsed_Features[name])
>    context.par ()
>    context.blank{ "medium" }
>    context(Test_String)
>    context.par ()
>    context.stop ()
> end
> 
> context.stoptext()
> 
> COMMENTS
> 
> And this doesn't work: the names are picked up, but the font features 
> are not defined; the sample text does not reflect any features. So this 
> is what I've got... maybe one of the wizards can help.
You're going way too complex. Access to features and info has alwaye 
been part of mkic (and therefore lmtx). You can peek into the s-font* 
styles for all kind of ways to get overviews. Anyway, the following 
helper operates on the current font:

\starttext

\startluacode
     function document.ShowFeatures(script)
         local test = [[
             ABCDEFGHIJKLMNOPQRSTUVWXYZ
             abcdefghijklmnopqrstuvwxyz
             1234567890
             1/4 2/8 3/9
             ffi ft fi fl ffl
         ]]

         local font     = fonts.hashes.identifiers[true]
         local features = font.resources.features
      -- inspect(features)
         for name, detail in table.sortedhash(features.gsub) do
             if #name == 4 then
                 context.type(name)
                 context.quad()
                 if script then
                     context.type(script)
                     context.quad()
                 end
                 -- this should be doen once in order to save memory
                 -- not too hard to do ..
                 context.definefontfeature(
                   { "f:"..name },
                   { [name] = "yes", script = script }
                 )
                 context.start()
                 context.addff("f:"..name)
                 context(test)
                 context.stop()
                 context.blank()
             end
         end
     end
\stopluacode

\definedfont[LibertinusSerif-Regular.otf*always]

\ctxlua{document.ShowFeatures()}
% \ctxlua{document.ShowFeatures("latn")}
% \ctxlua{document.ShowFeatures("grek")}

\stoptext

But, be aware that (1) features can combine in weird ways, (2) some 
features are only meant to be applied to a sunset of characters, (3) 
some are driven by script and/or language. Also, (4) you need to load 
the font without any features except the ones that enable node mode.

So, now you need to wikify ...

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://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : https://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : https://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2022-11-03 18:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-03 11:37 Thomas A. Schmitz via ntg-context
2022-11-03 11:52 ` Herbert Voss via ntg-context
2022-11-03 12:19   ` Thomas A. Schmitz via ntg-context
2022-11-03 17:57   ` Hans Hagen via ntg-context
2022-11-03 12:20 ` Henning Hraban Ramm via ntg-context
2022-11-03 12:27   ` Henning Hraban Ramm via ntg-context
2022-11-03 13:03     ` Thomas A. Schmitz via ntg-context
2022-11-03 18:24       ` Hans Hagen via ntg-context [this message]
2022-11-03 19:38         ` Thomas A. Schmitz via ntg-context
  -- strict thread matches above, loose matches on Subject: below --
2010-11-17 19:15 Herbert Voss
2010-11-17 20:55 ` Hans Hagen
2009-05-15  2:06 Font features Vyatcheslav Yatskovsky
2009-05-15  6:21 ` Wolfgang Schuster
2009-05-15 12:23   ` Idris Samawi Hamid ادريس سماوي حامد
2009-05-15 12:41     ` Alex Lubberts
2009-05-15 14:22       ` Hans Hagen

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=8874383b-3f05-76f7-0198-f18f0ce0260a@xs4all.nl \
    --to=ntg-context@ntg.nl \
    --cc=j.hagen@xs4all.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).