Hi Simon,
Am 06.01.25 um 21:46 schrieb Simon Albrecht:
On 06.01.25 15:33, Lukas-Fabian Moser wrote:
This is possible, but
The issue of “de-whiting” everything that’s supposed to be white
outside of whiteout immediately popped up when applying this to my
example file for LSR…
Let’s keep in touch with regards to creating issues and such.
Yes, I expected as much. See below nevertheless for a slightly cleaner
version of that attempt. (It's still not ideal in that for non-'color
stencil expressions, all sorts of objects get tested whether they happen
to be 'color. But in order to avoid this, it would be necessary to cater
for all the possible stencil expression commands and their respective
syntax, I think.)
Basically, there is an unsolvable problem here, namely finding out
whether an explicit "white" in any layout is meant as "emphatically
white" or "the colour of the background". In many situations, de-whiting
all explicitly white stencils may very well be the "the right thing".
And behind all of this is an even more fundamental issue: LilyPond by
default uses white for white-out without making sure the paper is white.
I routinely have a non-white paper background in my Frescobaldi view
(this is more comfortable for my eyes), and so I see every white-out as
a bright-white spot. This exposes the "cheat nature" of LilyPond's
whiteout feature, I'm afraid.
Nevertheless: Thanks to Werner's additions, current LilyPond development
versions have a configurable whiteout option. Currently, the default
fallback value is white (hardcoded), and this probably should be changed
to use an explicit background-color variable from \paper { }. Probably
another paper variable then should specify whether LilyPond should paint
the paper white (as in Harm's post-processing code).
And while we're at it, as a separate matter, it would probably be
reasonable to be able to also specify a default foreground color, so we
can sidestep the ex-post re-coloring that Harm's code does.
Lukas
\version "2.25.21"
#(use-modules (ice-9 match))
#(define (stencil-color-replace stil from to)
(let*
((from-color (normalize-color from))
(to-color (normalize-color to)))
(define (stencil-expr-color-replace expr)
(if (pair? expr)
(match expr
(('color explicit-color sub-expr)
`(color
,(if (equal? explicit-color from-color)
to-color
explicit-color)
,(stencil-expr-color-replace sub-expr)))
((head . tail)
(cons (stencil-expr-color-replace head)
(stencil-expr-color-replace tail))))
expr))
(ly:make-stencil
(stencil-expr-color-replace (ly:stencil-expr stil))
(ly:stencil-extent stil X)
(ly:stencil-extent stil Y))))
\paper {
background-color = #(x11-color "gray20")
print-color = "ivory"
#(define (page-post-process layout pages)
(let ((print-color (ly:output-def-lookup $defaultpaper
'print-color #f))
(background-color
(ly:output-def-lookup $defaultpaper 'background-color #f)))
(for-each
(lambda (page)
(let ((page-stencil (ly:prob-property page 'stencil)))
(set! (ly:prob-property page 'stencil)
(if (not background-color)
(stencil-with-color page-stencil print-color)
(ly:stencil-add
(stencil-with-color (make-filled-box-stencil
(ly:stencil-extent
page-stencil X)
(ly:stencil-extent
page-stencil Y))
background-color)
(stencil-with-color
(stencil-color-replace page-stencil white
background-color)
print-color))))))
pages)))
}
\markup { Here’s an example of \override #'(color . "green") \whiteout
\line { whiteout in markup. } }
{ \override Staff.TimeSignature.whiteout = 5 1 } \addlyrics { test }
\markup { \with-color #green This should be green. }
\markup { \with-color #white This is explicit white and remains invisible. }