ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* ligatures/substituation at word boundaries
@ 2017-07-27 18:09 Ulrike Fischer
  2017-07-28 21:21 ` Hans Hagen
  0 siblings, 1 reply; 4+ messages in thread
From: Ulrike Fischer @ 2017-07-27 18:09 UTC (permalink / raw)
  To: ntg-context

Is it possible to refer in fonts.handlers.otf.addfeature to the word
boundary? The luatex manual speaks of a virtual "left_boundary"
char, but I couldn't find a way to use it. 

\startluacode
    fonts.handlers.otf.addfeature {
        name = "ltest",
        type = "ligature",
        data = {
            ['1'] = { "a", "b" },
            ['2'] = { "d", "a" },
        }
    }
\stopluacode

%how to replace only the start a????

\startluacode
    fonts.handlers.otf.addfeature {
        name = "wtest",
        type = "ligature",
        data = {
            ['1'] = { "left_boundary", "a" },
        }
    }
\stopluacode

\definefontfeature[wtest][wtest=yes]
\definefontfeature[ltest][ltest=yes]
\starttext

    \definedfont[file:dejavu-serif.ttf*default]%


    {\addff{ltest} ababa\par}

    {\addff{wtest} ababa\par}


\stoptext





-- 
Ulrike Fischer 
http://www.troubleshooting-tex.de/

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ligatures/substituation at word boundaries
  2017-07-27 18:09 ligatures/substituation at word boundaries Ulrike Fischer
@ 2017-07-28 21:21 ` Hans Hagen
  2017-07-30  9:39   ` Ulrike Fischer
  0 siblings, 1 reply; 4+ messages in thread
From: Hans Hagen @ 2017-07-28 21:21 UTC (permalink / raw)
  To: ntg-context

On 7/27/2017 8:09 PM, Ulrike Fischer wrote:
> Is it possible to refer in fonts.handlers.otf.addfeature to the word
> boundary? The luatex manual speaks of a virtual "left_boundary"
> char, but I couldn't find a way to use it.
> 
> \startluacode
>      fonts.handlers.otf.addfeature {
>          name = "ltest",
>          type = "ligature",
>          data = {
>              ['1'] = { "a", "b" },
>              ['2'] = { "d", "a" },
>          }
>      }
> \stopluacode
> 
> %how to replace only the start a????
> 
> \startluacode
>      fonts.handlers.otf.addfeature {
>          name = "wtest",
>          type = "ligature",
>          data = {
>              ['1'] = { "left_boundary", "a" },
>          }
>      }
> \stopluacode
> 
> \definefontfeature[wtest][wtest=yes]
> \definefontfeature[ltest][ltest=yes]
> \starttext
> 
>      \definedfont[file:dejavu-serif.ttf*default]%
> 
> 
>      {\addff{ltest} ababa\par}
> 
>      {\addff{wtest} ababa\par}
> 
> 
> \stoptext
It is possible to check against spaces in contextual lookups. There 
isn't something like left boundary. I added some test code to the beta 
but keep in mind that this will only work with self-made features. (I 
have to check performance impact because I don't like making contextual 
lookups measurable slower due to some hardly used feature. First test 
show that it behaves ok.) In the test code below 0xFFFC is the boundary 
(this 0xFFFC check is the new thing). I adapted a few more things in the 
loader so best check that out too.

I'll upload a beta.

Hans

\starttext

\startluacode
     fonts.handlers.otf.addfeature {
         name    = "test-a",
         type    = "chainsubstitution",
         lookups = {
             {
                 type = "substitution",
                 data = {
                     ["a"] = "A",
                     ["b"] = "B",
                     ["c"] = "C",
                     ["d"] = "D",
                 },
             },
             {
                 type = "ligature",
                 data = {
                     ['1'] = { "a", "b" },
                     ['2'] = { "c", "d" },
                 },
             },
         },
         data = {
             rules = {
                 {
                     before  = { { " ", 0xFFFC } },
                     current = { { "a" }, { "b" } },
                     lookups = { 2 },
                 },
                 {
                     current = { { "c" }, { "d" } },
                     after   = { { 0xFFFC, " " } },
                     lookups = { 2 },
                 },
                 {
                     current = { { "a" } },
                     after   = { { "b" } },
                     lookups = { 1 },
                 },
                 {
                     current = { { "c" } },
                     after   = { { "d" } },
                     lookups = { 1 },
                 },
             },
         },
     }

     fonts.handlers.otf.addfeature {
         name    = "test-b",
         type    = "chainsubstitution",
         lookups = {
             {
                 type = "ligature",
                 data = {
                     ['1'] = { "a", "b" },
                     ['2'] = { "c", "d" },
                 },
             },
         },
         data = {
             rules = {
                 {
                     -- the space is redundant as 0xFFFC contains it
                     before  = { { " ", 0xFFFC } },
                     current = { { "a" }, { "b" } },
                     lookups = { 1 },
                 },
                 {
                     current = { { "c" }, { "d" } },
                     -- the space is redundant as 0xFFFC contains it
                     after   = { { 0xFFFC, " " } },
                     lookups = { 1 },
                 },
             },
         },
     }

     fonts.handlers.otf.addfeature {
         name    = "test-c",
         type    = "chainsubstitution",
         lookups = {
             {
                 type = "ligature",
                 data = {
                     ['1'] = { "a", "b" },
                     ['2'] = { "c", "d" },
                 },
             },
         },
         data = {
             rules = {
                 {
                     before  = { { " " } },
                     current = { { "a" }, { "b" } },
                     lookups = { 1 },
                 },
                 {
                     current = { { "c" }, { "d" } },
                     after   = { { " " } },
                     lookups = { 1 },
                 },
             },
         },
     }

\stopluacode

\definefontfeature[test-a][test-a=yes]
\definefontfeature[test-b][test-b=yes]
\definefontfeature[test-c][test-c=yes]

\startbuffer
abababcdcd abababcdcd abababcdcd
\stopbuffer

\typebuffer

\definedfont[file:dejavu-serif.ttf*default,test-a] \getbuffer \blank
\definedfont[file:dejavu-serif.ttf*default,test-b] \getbuffer \blank
\definedfont[file:dejavu-serif.ttf*default,test-c] \getbuffer \blank

\stoptext



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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ligatures/substituation at word boundaries
  2017-07-28 21:21 ` Hans Hagen
@ 2017-07-30  9:39   ` Ulrike Fischer
  2017-07-30 14:52     ` Hans Hagen
  0 siblings, 1 reply; 4+ messages in thread
From: Ulrike Fischer @ 2017-07-30  9:39 UTC (permalink / raw)
  To: ntg-context

Am Fri, 28 Jul 2017 23:21:18 +0200 schrieb Hans Hagen:

>> Is it possible to refer in fonts.handlers.otf.addfeature to the word
>> boundary? The luatex manual speaks of a virtual "left_boundary"
>> char, but I couldn't find a way to use it.

> It is possible to check against spaces in contextual lookups. There 
> isn't something like left boundary. I added some test code to the beta 
> but keep in mind that this will only work with self-made features. 

Thanks. It seems to work quite good and after some playing around I
also got the knack of the syntax.

A few questions: 

1. "lookups = { 1 }," refers to the first lookup. Is it possible to
name the lookups and to refer to this name?.

2. 0xFFFC refers more or less to the begin and end of line, right?
Why doesn't it interfere with hyphenations? I tried to get 
      ab-
ab 

and the second wasn't replaced (as wanted) and I wondered how it
worked. 

3. Why is in the following example "abcd" not replaced by "12"? 


\startluacode
     fonts.handlers.otf.addfeature {
         name    = "test-a",
         type    = "chainsubstitution",
         lookups = {
             {
                 type = "ligature",
                 data = {
                     ['1'] = { "a", "b" },
                     ['2'] = { "c", "d" },
                 },
             },
         },
         data = {
             rules = {
                 {
                     before  = { { " ", 0xFFFC } },
                     current = { { "a" }, { "b" } },
                     lookups = { 1 },
                 },
                 {
                     current = { { "c" }, { "d" } },
                     after   = { { 0xFFFC, " " } },
                     lookups = { 1 },
                 },
             },
         },
     }


\stopluacode

\definefontfeature[test-a][test-a=yes]

\startbuffer
xxx abcd abxcd xxx
\stopbuffer

\starttext

\typebuffer

\definedfont[file:dejavu-serif.ttf*default] \getbuffer \blank
\definedfont[file:dejavu-serif.ttf*default,test-a] \getbuffer \blank

\stoptext





-- 
Ulrike Fischer 
http://www.troubleshooting-tex.de/

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ligatures/substituation at word boundaries
  2017-07-30  9:39   ` Ulrike Fischer
@ 2017-07-30 14:52     ` Hans Hagen
  0 siblings, 0 replies; 4+ messages in thread
From: Hans Hagen @ 2017-07-30 14:52 UTC (permalink / raw)
  To: ntg-context

On 7/30/2017 11:39 AM, Ulrike Fischer wrote:
> Am Fri, 28 Jul 2017 23:21:18 +0200 schrieb Hans Hagen:
> 
>>> Is it possible to refer in fonts.handlers.otf.addfeature to the word
>>> boundary? The luatex manual speaks of a virtual "left_boundary"
>>> char, but I couldn't find a way to use it.
> 
>> It is possible to check against spaces in contextual lookups. There
>> isn't something like left boundary. I added some test code to the beta
>> but keep in mind that this will only work with self-made features.
> 
> Thanks. It seems to work quite good and after some playing around I
> also got the knack of the syntax.
> 
> A few questions:
> 
> 1. "lookups = { 1 }," refers to the first lookup. Is it possible to
> name the lookups and to refer to this name?.

no, because order matters

> 2. 0xFFFC refers more or less to the begin and end of line, right?
> Why doesn't it interfere with hyphenations? I tried to get
>        ab-
> ab
> 
> and the second wasn't replaced (as wanted) and I wondered how it
> worked.

0xFFFC is just the same as "anything other than glyph or discretionary"

> 3. Why is in the following example "abcd" not replaced by "12"?

i'll have a look at this (advancing in somewhat messy defined)

> \startluacode
>       fonts.handlers.otf.addfeature {
>           name    = "test-a",
>           type    = "chainsubstitution",
>           lookups = {
>               {
>                   type = "ligature",
>                   data = {
>                       ['1'] = { "a", "b" },
>                       ['2'] = { "c", "d" },
>                   },
>               },
>           },
>           data = {
>               rules = {
>                   {
>                       before  = { { " ", 0xFFFC } },
>                       current = { { "a" }, { "b" } },
>                       lookups = { 1 },
>                   },
>                   {
>                       current = { { "c" }, { "d" } },
>                       after   = { { 0xFFFC, " " } },
>                       lookups = { 1 },
>                   },
>               },
>           },
>       }
> 
> 
> \stopluacode
> 
> \definefontfeature[test-a][test-a=yes]
> 
> \startbuffer
> xxx abcd abxcd xxx
> \stopbuffer
> 
> \starttext
> 
> \typebuffer
> 
> \definedfont[file:dejavu-serif.ttf*default] \getbuffer \blank
> \definedfont[file:dejavu-serif.ttf*default,test-a] \getbuffer \blank
> 
> \stoptext


-- 

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-07-30 14:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-27 18:09 ligatures/substituation at word boundaries Ulrike Fischer
2017-07-28 21:21 ` Hans Hagen
2017-07-30  9:39   ` Ulrike Fischer
2017-07-30 14:52     ` Hans Hagen

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).