lilypond-user
[Top][All Lists]
Advanced

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

Re: How to get text width in Scheme?


From: Reinhold Kainhofer
Subject: Re: How to get text width in Scheme?
Date: Mon, 22 Sep 2008 11:40:43 +0200
User-agent: KMail/1.9.10

-----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 <address@hidden> 
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: address@hidden, 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-----

Attachment: text-width.ly
Description: Text Data


reply via email to

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