lilypond-user
[Top][All Lists]
Advanced

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

Re: Crop only top and bottom


From: Urs Liska
Subject: Re: Crop only top and bottom
Date: Tue, 16 Jan 2018 15:24:48 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2



Am 16.01.2018 um 13:26 schrieb Urs Liska:


Am 16.01.2018 um 12:49 schrieb Werner LEMBERG:
I have looked for ways to crop the EPS to only two borders of the
bounding box but didn't find anything useful so far.
While I can't help with the lilypond issue, I suggest to have a look
at the `pdfcrop' program that comes with TeXLive: It supports a
`--margins' option.

Unfortunately that doesn't help, as this only allows to *add* margins.
I think it is only a wrapper using Ghostscript anyway, so there should be a direct solution. It's possible to specify the box to be cropped using Ghostscript, and it is possible to crop to the content, which is what LilyPond does (-dEPSCrop).

For the function I need it would be necessary to retrieve the document width and the content box of the original file and then crop it ignoring the left and right part of the bounding box.
However, so far I'm poking in the fog and haven't found the proper way to do it.
I need a way to compile a score with LilyPond so these informations are present in the resulting file (PDF or EPS) so I can read it either directly from the file or using some tools like pdfinfo or similar.

Any suggestions?


OK, I think I have found something. But still I would be glad if LilyPond could do that on its own.

I have a two-system score:

%%%%%

\paper{
    left-margin = 50\pt % see below why I use \pt here
    line-width = 17\cm
    indent = 0
}

\new PianoStaff \with {
  instrumentName = "Vl."
} <<
  \new Staff {
    \tempo Allegro
    c''2 ( c'''-. )
    \break
    c'1
  }
  \new Staff {
    \clef bass
    c2 c,\sustainOn
    c1
  }
>>
%%%%%

I compile it using the EPS backend, producing the series of cropped systems:

    lilypond --pdf -dbackend=eps my-file.ly

This gives me (among others) the files my-file.eps. From this I can extract the dimensions of the two systems:

    %%BoundingBox: 27 -200 539 0

(is the third line of the file)
(Parameters are bottom left (X/Y) and top right (X/Y), in points. There are also .eps files for each system, but they differ only by the second parameter, which refers to the height.

What this tells me is that 27 points have been cropped from the left, that is: the 50 point margin defined in the \paper block has been reduced by 27 points. That means the "protrusion" of brace plus instrument name is 50 - 27 = 23 points.

And voilà: when I do

   \hspace*{-23bp}\includegraphics{my-file-1.pdf}

The alignment is correct. (bp (big points) is LaTeX's unit for "points").

Interestingly that left cropping is the same for all systems, obviously referring to the widest system.

To achieve my goal I have to - for every score, but not for every system -
  • define an appropriately large left-margin
  • define the line-width
  • (set indent to 0)
  • compile with --pdf -dbackend=eps
  • retrieve the first value from the BoundingBox line from the main .eps
  • calculate left-margin - left-crop
  • use that for each system include in LaTeX

So in the end I don't have to post-process the output but can actually retrieve the necessary information from the EPS.

Urs



     Werner


_______________________________________________
lilypond-user mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/lilypond-user


reply via email to

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