Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lilypond sections can get clipped if they're outside the embedded SVGs bounds #464

Open
edonv opened this issue Nov 22, 2024 · 9 comments
Open

Comments

@edonv
Copy link

edonv commented Nov 22, 2024

Describe the bug

Sometimes, the output SVG from Lilypond isn't perfectly in the bounds of the cropped SVG. This might be due to the possibility of it not knowing the size of the text due to the font changing once embedded in the PDF and uses the PDF's font settings.

The solution might just be to add overflow="visible" to the SVG itself once generated?

Or I also could just set the right font for Lilypond in its settings, but this might be more easily fixable at the start.

Attachments

Screenshot 2024-11-22 at 3 01 07 PM

System information

  • OS: macOS Sonoma 14.5
  • Where did you get ChordPro from? macOS build
  • ChordPro version: 6.060
  • Perl version: 5.30.3

Additional context

In my situation, I have TabNoteHead.font-family = #'roman, which internally defaults to Times New Roman. But in ChordPro's pdf.fontconfig, the serif family is set to Roboto Serif.

@sciurius
Copy link
Collaborator

Can you share a small sample song (+ config) so I can reproduce this?

Adding overflow="visible" won't help since that is not handled by the SVG processor that ChordPro uses. But maybe there are other alternatives.

@edonv
Copy link
Author

edonv commented Nov 26, 2024

Here's a zip containing all the relevant files. Let me know if something is weird. I'm not passing any extra arguments to the command, just specifying the primary "chordpro.json" file I included, the .cho file is the input, and I'm outputting to the same file name but with .pdf.

issue upload.zip

@sciurius
Copy link
Collaborator

I cannot reproduce this. Can you also share crave.pdf?

@edonv
Copy link
Author

edonv commented Nov 27, 2024

Yes, can do. Here you go:
crave.pdf

@sciurius
Copy link
Collaborator

Thanks. As you already assumed the problem is a mismatch of font metrics. LilyPond is formatting with the metrics of Times Bold and ChordPro is rendering the resultant SVG with font RobotoSerif.

If you run ChordPro with --define debug.svg=1 you'll see a couple of messages:

vb -0.0600 -5.1653 90.8544 13.6483 => bb -0.06 -8.48 90.79 5.17
SVG: Font LilyPond Serif (bold) ....
SVG: Font robotobolditalic|normal|normal ....

(The exact names may depend on your system font config)

So when you specify TabNoteHead.font-family = #'roman, LilyPond uses Times-Bold metrics and uses font family LilyPond Serif with style bold in the SVG. In the fontconfig you can map this:

            "lilypond serif": {
                "bold": "Times-Bold",
            }

Now LilyPond and ChordPro use the same font metrics and the image will not be clipped.

@edonv
Copy link
Author

edonv commented Nov 28, 2024

Awesome, thanks!

@edonv
Copy link
Author

edonv commented Nov 28, 2024

I'm actually not having much luck. Should I still be setting TabNoteHead.font-family = #'roman or using #(define fonts (set-global-fonts ...)) too? Between different combinations, I'm either still getting the cut-off, or just getting Times-Bold instead.

@sciurius
Copy link
Collaborator

For me, this works (I have LilyPond 2.25):

In the preamble:

\paper {
    property-defaults.fonts.serif = "Roboto Serif"
   ...
}
\context {
    \TabStaff
    ...
    \override TabNoteHead.font-family = #'serif"
}

In the fontconfig:

	    "Roboto Serif" : {
		"":           "RobotoSerif-Regular.ttf"
		"bold":       "RobotoSerif-Bold.ttf"
	    }

Running ChordPro with --def debug.svg=1 shows:

vb -0.0600 -5.1478 90.8554 13.6352 => bb -0.06 -8.49 90.80 5.15
SVG: Font roboto serif|normal|bold found in font config: /home/jv/.fonts/RobotoSerif-Bold.ttf
SVG: Font robotobolditalic|normal|normal found in font config: /home/jv/.fonts/Roboto-BoldItalic.ttf

The end result uses Roboto Serif for the TabNoteHeads, and there is no clipping.

LilyPond uses fontconfig so you can verify that it does use the right font:

% fc-match "roboto serif :style=bold"
RobotoSerif-Bold.ttf: "Roboto Serif" "Bold"

Does this help?

@edonv
Copy link
Author

edonv commented Nov 29, 2024

Hmmm, I'm still getting the same cut off.

The debug output shows this:

vb -0.0600 -5.1146 87.4812 13.5328 => bb -0.06 -8.42 87.42 5.11
Subroutine Text::Layout::FontConfig::_fallback redefined at /Applications/ChordPro.app/Contents/Resources/script/../lib/ChordPro/Output/PDF.pm line 3054.
SVG: Font serif|normal|bold found in font config: /Users/edon/Library/Fonts/RobotoSerif-Bold.ttf
Subroutine Text::Layout::FontConfig::_fallback redefined at /Applications/ChordPro.app/Contents/Resources/script/../lib/ChordPro/Output/PDF.pm line 3054.
SVG: Font sansbolditalic|normal|normal found in font config: /Users/edon/Library/Fonts/Roboto-BoldItalic.ttf

I have Lilypond 2.24.4, but not sure if that would affect it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants