lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Lines to edges of \center-column


From: Thomas Morley
Subject: Re: Lines to edges of \center-column
Date: Sun, 23 Apr 2017 00:56:54 +0200

2017-04-23 0:34 GMT+02:00 David Nalesnik <address@hidden>:
> On Sat, Apr 22, 2017 at 3:22 PM,  <address@hidden> wrote:
>> Is there some way to make a center-column draw lines from slightly outside
>> the text to the edges of the column (see example)?
>>
>> In this specific case, I have both English and Japanese names for stuff, and
>> without those lines, I think it's a bit unclear exactly what part the
>> Japanese refers to.
>>
>> ```
>> subtitle = \markup \bold \large \line {
>>   "from"
>>   \center-column {
>>     "Legend of Heroes"
>>     \smaller \smaller \smaller
>>     "英雄伝説"
>>   }
>>   "VI:"
>>   \center-column {
>>     "Trails in the Sky"
>>     \smaller \smaller \smaller
>>     "空の軌跡"
>>   }
>> }
>> ```
>
> Try this:
>
> \version "2.19.59"
>
> % based on general-column from scm/define-markup-commands.scm
> #(define (general-column align-dir baseline mols)
>    (let* ((aligned-mols
>            (map (lambda (x) (ly:stencil-aligned-to x X align-dir))
>              mols))
>           (max-extent (ly:stencil-extent (car aligned-mols) X))
>           (aligned-mols
>            (cons (car aligned-mols)
>              (map (lambda (x)
>                     (let ((stil-ext (ly:stencil-extent x X)))
>                       (ly:stencil-add
>                        (make-line-stencil 0.1 (car max-extent) 0 (1-
> (car stil-ext)) 0)
>                        (make-line-stencil 0.1 (1+ (cdr stil-ext)) 0
> (cdr max-extent) 0)
>                        (make-line-stencil 0.1 (car max-extent) 0 (car
> max-extent) 1.5)
>                        (make-line-stencil 0.1 (cdr max-extent) 0 (cdr
> max-extent) 1.5)
>                        x)))
>                (cdr aligned-mols))))
>           (stacked-stencil (stack-lines -1 0.0 baseline aligned-mols))
>           (stacked-extent (ly:stencil-extent stacked-stencil X)))
>      (ly:stencil-translate-axis stacked-stencil (- (car stacked-extent)) X)))
>
> #(define-markup-command (center-column layout props args)
>    (markup-list?)
>    #:category align
>    #:properties ((baseline-skip))
>    (general-column CENTER baseline-skip (interpret-markup-list layout
> props args)))
>
> \header {
>   subtitle = \markup \bold \large \line {
>     "from"
>     \center-column {
>       "Legend of Heroes"
>       \smaller \smaller \smaller
>       "英雄伝説"
>       "英雄伝説"
>       \huge
>       "英雄伝説"
>     }
>     "VI:"
>     \center-column {
>       "Trails in the Sky"
>       \smaller \smaller \smaller
>       "空の軌跡"
>     }
>   }
> }
>
> { c }
>
> You might want to adjust some of the hard-coded values
> (line-thickness, length of "protrusions," offset of bracket from
> text), but this should get you started.
>
> -David
>

Here my approach:

#(define-markup-command (single-hbracket-with-text layout props ref arg)
  (markup? markup?)
  #:properties ((thick 0.1)
                (protrusion 1)
                (dir 1)
                (axis X))
"Prints a bracket overlayed by @code{arg}. Both are center-aligned.

Takes the bracket-ext from @var{ref} in direction of the @code{axis}-property.
The angles of the bracket are printed in direction of the @code{dir}-property.
The appearance is tweakable with overrides for @code{thick} and
@code{protrusion}."

  (define (bracket-stencil stil axis thick protrusion dir)
   (let* ((ext (ly:stencil-extent stil axis))
          (lb (ly:bracket axis ext thick protrusion))
          (rb (ly:bracket axis ext thick (- protrusion))))
     (if (= 1 dir) lb rb)))

  (let* ((stil (interpret-markup layout props ref)))
    (ly:stencil-add
      (ly:stencil-aligned-to
        (bracket-stencil stil axis thick protrusion dir) axis CENTER)
      (ly:stencil-aligned-to
        (interpret-markup layout props arg) axis CENTER))))



\markup \bold \large \line {
  "from"
  \override #'(baseline-skip . 1)
  \center-column {
    "Legend of Heroes"
    \single-hbracket-with-text
      "Legend of Heroes"
      \whiteout \vcenter \smaller \smaller \smaller \pad-x #0.3 "英雄伝説"
  }
  "VI:"
  \override #'(baseline-skip . 1)
  \center-column {
    "Trails in the Sky"
    \single-hbracket-with-text
      "Trails in the Sky"
      \whiteout \vcenter \smaller \smaller \smaller \pad-x #0.3 "空の軌跡"
  }
}


It needs a ref-markup for the bracket-extent and the text is overlayed
with control-possibilities for the user.
Didn't want to do too much automatically.


Cheers,
  Harm



reply via email to

[Prev in Thread] Current Thread [Next in Thread]