[Top][All Lists]

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

Producing postscript for custom paper size (9x12" manuscript paper)?

From: John Hawkinson
Subject: Producing postscript for custom paper size (9x12" manuscript paper)?
Date: Mon, 3 Apr 2006 13:54:27 -0400 (EDT)


    I'm new to Lilypond.

    I spent a while trying to make LilyPond print to 9x12 inch paper
(a relatively standard size for manuscript staff paper), and I ran
into a bunch of snags and hiccups. Hopefully how I solved them is
helpful, and perhaps someone could advise me on a "better way."  In
particular, I couldn't figure out how to extend the LilyPond scheme
code without actually modifying the .scm files -- it seems like there
ought to be a way without doing so? (see below)

    My work is in a local installation of LilyPond 2.6.3, but it appears
that the relevant code has not changed in LilyPond 2.8.

First off was adding the paper size to paper.scm, which was
straightforward.  I couldn't find a standard name for this manuscript
paper (for instance, the Wikipedia article on paper sizes has lots of good information
on almost all sizes, but does not mention manuscript paper or anything
close to 9"x12"):

--- lilypond/      2006/04/03 02:04:01     1.1
+++ lilypond/      2006/04/03 03:39:00     1.2
@@ -80,3 +80,5 @@
     ("letter" . (cons (* 8.5 in) (* 11.0 in)))
-    ("tabloid" . (cons (* 11.0 in) (* 17.0 in)))))
+    ("tabloid" . (cons (* 11.0 in) (* 17.0 in)))
+    ("manuscript" . (cons (* 9 in) (* 12 in )))
After doing this, and setting 

#(set-default-paper-size "manuscript")

in my .ly file, LilyPond generated the correct postscript, but the printer
(and PDF generator) did not know about the paper size, so still printed
on letter.

I found that adding the following to the top of the postscript output
correctly solved it:

%%BeginFeature: *PageSize Manuscript
<< /ManualFeed true /PageSize [ 648 864 ] /ImagingBBox null >> setpagedevice
%%EndFeature: *PageSize Manuscript

I then slaved a way for a while to try to get LilyPond to output this
for me, and that's where I hit various snags. Ultimately I ended up
with this patch to the (write-preamble) function in framework-ps.scm:

--- lilypond/       2006/04/03 04:16:31     1.1
+++ lilypond/       2006/04/03 04:41:59     1.3
@@ -390,6 +390,31 @@ (define (write-preamble
           (pfas (map font-loader font-names)))
+  ;; XXX: jhawk local patch to add support for manuscript paper. We
+  ;; need to tell the printer (or PDF writer) about the paper size
+  ;; so the right kind of page rotation happens, etc.
+  (if (equal? (ly:output-def-lookup paper 'papersizename) "manuscript")
+      (begin
+       (display "%%BeginFeature: *PageSize Manuscript\n" port)
+       ;; "ManualFeed true" is necessary on the HP8000 series so that
+       ;; it tries to pull custom paper from the manual feed, instead
+       ;; of erroring out. Perhaps this could be better done with
+       ;; the Policies dictionary? That way we could do it all the time,
+       ;; rather than simply for this special size paper, and not have to
+       ;; worry about accidently forcing the printer to manual feed when
+       ;; it is not appropriate.
+       ;;
+       ;; Really, we should get the page dimensions by multiplying
+       ;; the 'vsize and 'hsize values by the output-scale and multiplying
+       ;; that by the /lily-output-units.
+       (display (string-append "<< /ManualFeed true "
+                               "/PageSize [ 648 864 ] /ImagingBBox null >> "
+                               "setpagedevice\n")
+                port)
+       (display "%%EndFeature: *PageSize Manuscript\n" port)
+       ))
   (if load-fonts?
        (lambda (f)

By way of explanation: here /PageSize sets the paper size to
648x864 points (9x12 inches), and whenever you change /PageSize,
you are supposed to reset the /ImagingBBox (the "optional page
bounding box") to null to avoid inheriting a value.

I wasn't very happy forcing /ManualFeed true, but without that, my
printer produced a configuration error because it could not find the
right paper size.  Setting various keys in the /Policies dictionary
seem like they ought to fix this, but I wasn't really able to get it
working right. Looking at the HP8000 series PPD file (I can't seem to
find a postscript reference manual for it...), it looks like an
alternative would be to set /DeferredMediaSelection true, but this
looks like an HP-specific extension (though it seems to work ok...).

Also, the whole thing is conditionalized in the manuscript paper size.
It would be nice to always output the correct /PageSize setting, but
to not force the printer into manual feed for paper sizes that it
already has. I don't know if it is hopelessly naive to believe that
this can be done sufficiently safely and generically (for all or most
PS printers) with a single piece of postscript, rather than oodles of
PPD files and the like.

I guess my question for lilypond-users is:

        Is there some correct way for me to extend (write-preamble)
        without editing framework-ps.scm? Is there some sort of
        hook I can use in GUILE to modify the existing function
        definition to add my extra stuff?

Of course, I'd like to be able to get this all working without
having to modify the lilypond source.

Thanks for any assistance, wisdom, comments, etc.

  John Hawkinson

reply via email to

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