Re: Setting font-features globally?

2023-02-27 Thread Jean Abou Samra



> Le 27 févr. 2023 à 19:53, Valentin Petzel  a écrit :
> 
> Okay, I will create a MR these days. But just gotta point out: You yourself 
> argued back then: \removeFontFeature sounds more like a
> specialized use case though. I'd add just \with-font-feature ...


Mailing list archives are compromising :-)

I guess I don’t have a strong opinion.





Re: Setting font-features globally?

2023-02-27 Thread Valentin Petzel
Okay, I will create a MR these days. But just gotta point out: You yourself 
argued back then: \removeFontFeature sounds more like a
specialized use case though. I'd add just \with-font-feature ...

Note that prefixing a feature to omit with an "-" is not a new syntax. It is 
done e.g. with fontspec in XeTeX and LuaTeX as well as for example LibreOffice. 
So I think this is not too unreasonable a syntax.

Am Montag, 27. Februar 2023, 16:42:55 CET schrieb Jean Abou Samra:
> > Le 27 févr. 2023 à 16:32, Valentin Petzel  a écrit :
> > Would you think it would make sense to provide
> > this (or a similar function) to Lilypond?
> 
> Yes, I do. No need to invent syntax/convenience for less frequently used
> stuff though (the cost of memorizing it outweighs the cost of typing more
> verbose syntax if you use a feature rarely); just provide
> \with-font-feature and \without-font-feature IMHO. Also, beware that
> comparing characters with eq? gives undefined results (use eqv? instead).



signature.asc
Description: This is a digitally signed message part.


Re: Setting font-features globally?

2023-02-27 Thread Valentin Petzel
Hello John,

this property is not documented (yet, but Werner just opened an issue for 
this), so the only real way to understand this behaviour is to look at the 
right places in the source code.

So let’s look in the source code where font-features is actually used: You’ll 
arrive at Text_interface::interpret_string in text-interface.cc. Here we have 
the line

SCM features
= ly_chain_assoc_get (ly_symbol2scm ("font-features"), props, SCM_BOOL_F);

So we pull the value from the props. So where do the props come from? If we 
look where interpret_string is used we find

Text_interface::internal_interpret_markup

which is used in

Text_interface::interpret_markup

which is used in

Text_interface::internal_print

Now internal_print does use

Font_interface::text_font_alist_chain (me);

for props. So we take a look at Font_interface::text_font_alist_chain and find

  SCM defaults
= g->layout ()->lookup_variable (ly_symbol2scm ("text-font-defaults"));

so we look up the value of "text-font-defaults" in the layout of the grob. The 
dafault value of this is defined in the most global layout, which is the top 
level paper block. This is done in ly/paper-defaults-init.ly:

  #(define text-font-defaults
 `((font-encoding . latin1)
   (baseline-skip . 3)
   (replacement-alist . ())
   (string-transformers . (,ly:perform-text-replacements))
   (word-space . 0.6)))

Cheers,
Valentin

Am Montag, 27. Februar 2023, 19:14:15 CET schrieb John Zaitseff:
> Hi, everyone (especially Jean),
> 
> Thanks for all your replies -- most helpful.
> 
> > > In short, is there a way to set "ss03" globally?
> > 
> > This should do:
> > 
> > ```
> > \paper {
> > 
> >   text-font-defaults.font-features = #'("ss03")
> > 
> > }
> > ```
> 
> This was exactly what I was looking for -- I've tested it and it
> works.
> 
> FYI, before writing to this list I did do multiple Google searches,
> as well as a search of the LilyPond source code, and I couldn't find
> any references to this, at least in regard to font-features.
> 
> So, thanks: you've all saved me a lot of tearing of the hair! :-)
> 
> Yours truly,
> 
> John Zaitseff



signature.asc
Description: This is a digitally signed message part.


Re: Setting font-features globally?

2023-02-27 Thread John Zaitseff
Hi, everyone (especially Jean),

Thanks for all your replies -- most helpful.

> > In short, is there a way to set "ss03" globally?
>
> This should do:
>
> ```
> \paper {
>   text-font-defaults.font-features = #'("ss03")
> }
> ```

This was exactly what I was looking for -- I've tested it and it
works.

FYI, before writing to this list I did do multiple Google searches,
as well as a search of the LilyPond source code, and I couldn't find
any references to this, at least in regard to font-features.

So, thanks: you've all saved me a lot of tearing of the hair! :-)

Yours truly,

John Zaitseff

-- 
John Zaitseff   ╭───╮   Email: j.zaits...@zap.org.au
The ZAP Group   │ Z │   GnuPG: 0x0D254111C4EE569B
Australia Inc.  ╰───╯   https://www.zap.org.au/~john/



Re: Setting font-features globally?

2023-02-27 Thread Jean Abou Samra



> Le 27 févr. 2023 à 16:32, Valentin Petzel  a écrit :
> Would you think it would make sense to provide 
> this (or a similar function) to Lilypond?


Yes, I do. No need to invent syntax/convenience for less frequently used stuff 
though (the cost of memorizing it outweighs the cost of typing more verbose 
syntax if you use a feature rarely); just provide \with-font-feature and 
\without-font-feature IMHO. Also, beware that comparing characters with eq? 
gives undefined results (use eqv? instead).





Re: Setting font-features globally?

2023-02-27 Thread Valentin Petzel
Hello Jean,

yes, did not think about that. Doing is your way is better anyway ...

Regarding the \with-font-feature-Part: I think I had some discussion on the 
list wrt this a long time ago. Would you think it would make sense to provide 
this (or a similar function) to Lilypond? Usually people actually using 
Opentype features use this in a sort of toggle-like manner, so I think this 
would be useful.

Cheers,
Valentin

Am Montag, 27. Februar 2023, 14:11:56 CET schrieb Jean Abou Samra:
> Le lundi 27 février 2023 à 13:53 +0100, Valentin Petzel a écrit :
> > Hello John,
> > 
> > you can do this by setting this in the default props:
> > 
> > \paper {
> > #(define fonts
> > (set-global-fonts
> > #:roman  "Linux Libertine"
> > #:factor (/ staff-height pt 20)
> > ))
> > text-font-defaults = #(assoc-set! text-font-defaults 'font-features
> > '("smcp"))
> 
> `assoc-set!` here is a bad idea imho because it will mutate the original.
> You can see this in
> 
> ```
> \version "2.24.1"
> 
> \paper {
> text-font-defaults = #(assoc-set! text-font-defaults 'font-features
> '("smcp")) #(define fonts
> (set-global-fonts
> #:roman  "Linux Libertine"
> #:factor (/ staff-height pt 20)
> ))
> }
> 
> \bookpart {
>   \markup "abc" % no small caps because of bleedover from next \bookpart
> }
> 
> \bookpart {
>   \paper {
> text-font-defaults = #(assoc-set! text-font-defaults 'font-features #f)
>  }
>   \markup "abc"
> }
> ```
> 
> You could use `(assoc-set! (alist-copy text-font-defaults) ...)`, but
> LilyPond's nested assignment syntax `text-font-defaults.font-features =
> ...` is just as convenient (as in my first reply shortly before yours).



signature.asc
Description: This is a digitally signed message part.


Re: Setting font-features globally?

2023-02-27 Thread Werner LEMBERG
>> In short, is there a way to set "ss03" globally?
> 
> This should do:
> 
> ```
> \paper {
>   text-font-defaults.font-features = #'("ss03")
> }
> ```

I think it would be very beneficial to add documentation for
`text-font-defaults` to the NR.

  https://gitlab.com/lilypond/lilypond/-/issues/6542


Werner



Re: Setting font-features globally?

2023-02-27 Thread Jean Abou Samra
Le lundi 27 février 2023 à 16:52 +1100, John Zaitseff a écrit :
> Hello,
> 
> I have a fairly large collection of LilyPond music scores that I  
> have entered over the years.  Now that I have access to the rather  
> nice Adobe Minion 3 set of fonts, I would like to use them for my  
> scores.  I have successfully included the following in my  
> stylesheet:
> 
>   \paper {  
>   #(define fonts  
>   (set-global-fonts  
>   #:roman  "Minion 3,"  
>   #:sans   "Myriad Pro,"  
>   #:typewriter "Hack,"  
>   #:factor (/ staff-height pt 20)  
>   ))  
>   }
> 
> However, I'd like to use the SS03 font feature of Minion 3  
> (trapezoid variants of Cyrillic DE and EL [1]) everywhere that text  
> appears.  Is this possible?  If so, how?  I don't mind writing  
> Scheme to do it!
> 
> [1] [https://minion.typekit.com/usage/](https://minion.typekit.com/usage/)
> 
> I know I can do something like:
> 
>   \layout {  
>   \context { \Lyrics \override LyricText.font-features = #'("ss03") }  
>   # ... every other context / text variation here  
>   }
> 
> but this misses headings, page headers and footers and verse text  
> typeset after a score.
> 
> In short, is there a way to set "ss03" globally?


This should do:

```
\paper {
  text-font-defaults.font-features = #'("ss03")
}
```


HTH


signature.asc
Description: This is a digitally signed message part


Re: Setting font-features globally?

2023-02-27 Thread Jean Abou Samra
Le lundi 27 février 2023 à 13:53 +0100, Valentin Petzel a écrit :
> Hello John,
> 
> you can do this by setting this in the default props:
> 
> \paper {  
>     #(define fonts  
>     (set-global-fonts  
>     #:roman  "Linux Libertine"  
>     #:factor (/ staff-height pt 20)  
>     ))  
>     text-font-defaults = #(assoc-set! text-font-defaults 'font-features  
> '("smcp"))  


`assoc-set!` here is a bad idea imho because it will mutate the original. You 
can see this in

```
\version "2.24.1"

\paper {
text-font-defaults = #(assoc-set! text-font-defaults 'font-features 
'("smcp"))
#(define fonts
(set-global-fonts
#:roman  "Linux Libertine"
#:factor (/ staff-height pt 20)
))
}

\bookpart {
  \markup "abc" % no small caps because of bleedover from next \bookpart
}

\bookpart {
  \paper {
text-font-defaults = #(assoc-set! text-font-defaults 'font-features #f)
 }
  \markup "abc"
}
```

You could use `(assoc-set! (alist-copy text-font-defaults) ...)`, but 
LilyPond's nested assignment syntax `text-font-defaults.font-features = ...` is 
just as convenient (as in my first reply shortly before yours).


signature.asc
Description: This is a digitally signed message part


Re: Setting font-features globally?

2023-02-27 Thread Valentin Petzel
Hello John,

you can do this by setting this in the default props:

\paper {
#(define fonts
(set-global-fonts
#:roman  "Linux Libertine"
#:factor (/ staff-height pt 20)
))
text-font-defaults = #(assoc-set! text-font-defaults 'font-features 
'("smcp"))
}

\markup "abc"

But keep in mind that \override '((font-feature . (...))) needs to specify all 
font features, which is a bit of a hassle, as this requires you to add this 
feature to all places where you change features.

Alternatively you might want to use a markup command like this instead:

\paper {
#(define fonts
(set-global-fonts
#:roman  "Linux Libertine"
#:factor (/ staff-height pt 20)
))
text-font-defaults = #(assoc-set! text-font-defaults 'font-features 
'("smcp"))
}

#(define-markup-command (with-font-features layout props feats markup)
   ((lambda (x) (or (string? x) (list? x))) markup?)
   #:properties ((font-features '()))
   (if (not (list? feats)) (set! feats (list feats)))
   (let* ((add-feats (filter (lambda (x) (not (eq? (string-ref x 0) #\-))) 
feats))
  (rm-feats (filter (lambda (x) (eq? (string-ref x 0) #\-)) feats))
  (rm-feats (map (lambda (x) (substring x 1)) rm-feats))
  (font-features (if font-features font-features '()))
  (font-features (lset-difference equal? font-features rm-feats))
  (font-features (lset-union equal? font-features add-feats))
  (font-features (if (null? font-features) #f font-features)))
 (interpret-markup layout
   (prepend-alist-chain
'font-features font-features
props)
   markup)))

\markup "abc"
\markup \with-font-features "lnum" "A12a"
\markup \with-font-features "onum" "A12a"
\markup \with-font-features "-smcp" "abc"

Cheers,
Valentin

Am Montag, 27. Februar 2023, 06:52:25 CET schrieb John Zaitseff:
> Hello,
> 
> I have a fairly large collection of LilyPond music scores that I
> have entered over the years.  Now that I have access to the rather
> nice Adobe Minion 3 set of fonts, I would like to use them for my
> scores.  I have successfully included the following in my
> stylesheet:
> 
>   \paper {
>   #(define fonts
>   (set-global-fonts
>   #:roman  "Minion 3,"
>   #:sans   "Myriad Pro,"
>   #:typewriter "Hack,"
>   #:factor (/ staff-height pt 20)
>   ))
>   }
> 
> However, I'd like to use the SS03 font feature of Minion 3
> (trapezoid variants of Cyrillic DE and EL [1]) everywhere that text
> appears.  Is this possible?  If so, how?  I don't mind writing
> Scheme to do it!
> 
> [1] https://minion.typekit.com/usage/
> 
> I know I can do something like:
> 
>   \layout {
>   \context { \Lyrics \override LyricText.font-features = #'("ss03") }
>   # ... every other context / text variation here
>   }
> 
> but this misses headings, page headers and footers and verse text
> typeset after a score.
> 
> In short, is there a way to set "ss03" globally?
> 
> Yours truly,
> 
> John Zaitseff



signature.asc
Description: This is a digitally signed message part.


Setting font-features globally?

2023-02-27 Thread John Zaitseff
Hello,

I have a fairly large collection of LilyPond music scores that I
have entered over the years.  Now that I have access to the rather
nice Adobe Minion 3 set of fonts, I would like to use them for my
scores.  I have successfully included the following in my
stylesheet:

  \paper {
  #(define fonts
  (set-global-fonts
  #:roman  "Minion 3,"
  #:sans   "Myriad Pro,"
  #:typewriter "Hack,"
  #:factor (/ staff-height pt 20)
  ))
  }

However, I'd like to use the SS03 font feature of Minion 3
(trapezoid variants of Cyrillic DE and EL [1]) everywhere that text
appears.  Is this possible?  If so, how?  I don't mind writing
Scheme to do it!

[1] https://minion.typekit.com/usage/

I know I can do something like:

  \layout {
  \context { \Lyrics \override LyricText.font-features = #'("ss03") }
  # ... every other context / text variation here
  }

but this misses headings, page headers and footers and verse text
typeset after a score.

In short, is there a way to set "ss03" globally?

Yours truly,

John Zaitseff

-- 
John Zaitseff   ╭───╮   Email: j.zaits...@zap.org.au
The ZAP Group   │ Z │   GnuPG: 0x0D254111C4EE569B
Australia Inc.  ╰───╯   https://www.zap.org.au/~john/