-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Am Sonntag, 21. September 2008 schrieb Han-Wen Nienhuys:
> On Fri, Sep 19, 2008 at 9:29 AM, Risto Vääräniemi <[EMAIL PROTECTED]>
wrote:
> > Hi all,
> >
> > Can someone tell me how I can get the text width inside scheme?
> >
> > There's a method called ly:text-dimension that takes font metric and
> > the text as parameters and gives the dimensions. Alright - I should
> > get the font metric somehow. I tried (let ((fontMetr (ly:grob-property
> > BarNumber 'font))) (...)) but the fontMetr is not a font metric
> > (ly:font-metric? returns false) although the description in
> > font-interface made me think so.
>
> This is sort-of a bug. The 'font is only set in C++, from
>
> Font_interface::get_default_font (Grob *me)
>
> we should change this so it uses the standard property calculation
> scheme.
There is also the ly:grob-default-font Scheme function, which is just a
wrapper around Font_interface::get_default_font for Scheme. It really returns
the font (it is a ly:font-metric?). Here's my code with some debug
statements:
#(define (bis-bar-number BarNumber)
"Append bis to the bar number."
(let* (
(fontMetr (ly:grob-default-font BarNumber))
(barNumber (ly:grob-property BarNumber 'text))
(bisBarNumber (string-append barNumber " bis"))
(width (ly:text-dimension fontMetr bisBarNumber)))
(ly:grob-set-property! BarNumber 'text bisBarNumber)
(ly:warning "Font is metric: ~a" (ly:font-metric? fontMetr))
(ly:warning "text-width for bar number ~a is ~a with font ~a"
bisBarNumber width fontMetr)
(ly:text-interface::print BarNumber)))
Unfortunately, it seems that the font used is not a Modified_font_metric, so
lilypond is not able to obtain a text stencil from this font, and thus can
also not get the width of the text stencil. text-dimension works only for
modified font metrics, but the font is <Font_metric ("emmentaler-16" .
0.569198924458776)>
In particular, I get the output / warning messages:
Vorverarbeitung der grafischen Elemente...
Programmierfehler: Cannot get a text stencil from this font
Fortsetzung, die Daumen drücken
Warnung: Font is metric: #t
Warnung: text-width for bar number 5 bis is ((+inf.0 . -inf.0)
+inf.0 . -inf.0) with font #<Font_metric ("emmentaler-16" .
0.569198924458776)>
Programmierfehler: Cannot get a text stencil from this font
Fortsetzung, die Daumen drücken
Warnung: Font is metric: #t
Warnung: text-width for bar number 5 bis is ((+inf.0 . -inf.0)
+inf.0 . -inf.0) with font #<Font_metric ("emmentaler-16" .
0.569198924458776)>
Programmierfehler: Cannot get a text stencil from this font
Fortsetzung, die Daumen drücken
Cheers,
Reinhold
- --
- ------------------------------------------------------------------
Reinhold Kainhofer, Vienna University of Technology, Austria
email: [EMAIL PROTECTED], http://reinhold.kainhofer.com/
* Financial and Actuarial Mathematics, TU Wien, http://www.fam.tuwien.ac.at/
* K Desktop Environment, http://www.kde.org, KOrganizer maintainer
* Chorvereinigung "Jung-Wien", http://www.jung-wien.at/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFI12gdTqjEwhXvPN0RAkA7AJ4hnH1gRS6RW+HD3r4UEb9mRiuNhwCgqxfD
PdFuTy9rl7a9ruBIyMPP3aY=
=+fIR
-----END PGP SIGNATURE-----
\version "2.11.60"
#(define (bis-bar-number BarNumber)
"Append bis to the bar number."
(let* (
(fontMetr (ly:grob-default-font BarNumber))
; Set barNumber to the current value
(barNumber (ly:grob-property BarNumber 'text))
; Append " bis" to it
(bisBarNumber (string-append barNumber " bis"))
(width (ly:text-dimension fontMetr bisBarNumber))
)
; Store the new value back
(ly:grob-set-property! BarNumber 'text bisBarNumber)
; and print it
(ly:warning "Font is metric: ~a" (ly:font-metric? fontMetr))
(ly:warning "text-width for bar number ~a is ~a with font ~a" bisBarNumber width fontMetr)
(ly:text-interface::print BarNumber)))
music = \relative
{
\override Score.BarNumber #'self-alignment-X = #center
\override Score.BarNumber #'break-visibility = #all-visible
\repeat unfold 4 { a1 }
\override Score.BarNumber #'stencil = #bis-bar-number
\repeat unfold 4 { a1 }
\revert Score.BarNumber #'stencil
\repeat unfold 4 { a1 }
}
\score { \music }
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-user