Hallo,
anbei zuerst das in einer anderen Diskussion versprochene Postscript-Markup für Kalendermonatsblätter.
--> Siehe Anhang »Postscript-2.ly«
Es zeigt schon ein allgemeines Postscript-Problem auf: lokale Variablen.
Um die Initialisierung nicht jedesmal beim Interpretieren des Postscript durchlaufen zu müssen, habe ich ein lokales, persönliches »Dictionary« gesucht, und es eventuell (beim ersten Mal) neu angelegt. Dennoch, ich habe nicht überprüft, ob der Codeteil wirklich wie gewünscht übersprungen wird.
Nun zu meinem zweiten Beispiel für heute, meine FineCaesura in einer neuen Variante:
%{
Postscript
%}
\version "2.12.3"
%PREPROCESS: C:\Programme_privat_32\Spezial\close_acrobat -c ${BASENAME} ${BASENAME}-print
FootLeft = #(string-append "Music engraving by LILYPOND, Version " (lilypond-version))
FootRight = #(string-append "compiled at " (strftime "%Y-%m-%d %H:%M:%S" (localtime (current-time))))
FootCenter = #(let*
((cmdl (object->string (command-line)))
(laloc (+ (string-rindex cmdl #\space) 2))
(cmdlen (- (string-length cmdl) 2))
(filen (substring cmdl laloc cmdlen))
(workdir (getcwd))
(basename (let ((ppos (string-rindex filen #\. )))
(if (number? ppos) (substring filen 0 ppos) filen)))
(lastdir (let*
((dpos (string-rindex workdir (string->char-set "\\/")))
(laenge (string-length workdir)))
(if (< (+ dpos 1) laenge) (string-append (substring workdir (+ dpos 1)) "/") "/"))))
(string-append lastdir basename))
#(set-global-staff-size 11.0)
\pointAndClickOff
\paper {
oddFooterMarkup = \markup \fill-line {
\abs-fontsize #6.5 { \FootLeft }
\abs-fontsize #9.0 { \bold { \FootCenter } }
\abs-fontsize #6.5 { \FootRight }
}
left-margin = 12 \mm
line-width = 188 \mm
indent = 3 \mm
ragged-right = ##f
between-system-space = 1 \mm
between-system-padding = 0.6 \mm
}
\header {
title = "»Postscript« Beispiele - Nr. 3"
}
#(define (scaled-ps-markup scale x-min x-max y-min y-max ps-string)
(markup #:line (#:with-dimensions
(cons (* x-min scale) (* x-max scale))
(cons (* y-min scale) (* y-max scale))
(#:postscript (string-concatenate
(list " " (number->string scale) " dup scale \n"
ps-string))))))
#(define (scale-postscript my-grob x-min x-max y-min y-max ps-string)
(let*
((sz (ly:grob-property my-grob 'font-size 0.0))
(mult (magstep sz)))
(scaled-ps-markup mult x-min x-max y-min y-max ps-string)))
#(define (fine-caesur-ps notehead-grob)
(scale-postscript notehead-grob -1.0625 4.6375 -3.5 2.25 "
newpath 0 setlinewidth 1 setlinejoin 1 setlinecap
-0.1875 0.25 moveto
-0.9375 0.25 lineto
-1.0625 -0.25 lineto
-0.3125 -0.25 lineto
-1.0625 -3.25 lineto
-0.625 -3.5 lineto
0.1875 -0.25 lineto
3.4375 -0.25 lineto
3.8125 0.25 lineto
0.3125 0.25 lineto
0.5 1.0 1.0875 1.75 1.9375 1.75 curveto
2.7875 1.75 3.2375 1.55 3.65 1.0 curveto
4.0625 1.25 lineto
3.6125 1.85 3.0625 2.25 2.0625 2.25 curveto
1.0125 2.25 0.1125 1.45 -0.1875 0.25 curveto closepath fill
0.0625 -2.75 moveto
0.5625 -2.75 lineto
1.0625 -0.75 lineto
0.5625 -0.75 lineto
0.0625 -2.75 lineto closepath fill
1.0625 -2.75 moveto
1.5625 -2.75 lineto
1.8625 -1.55 lineto
2.4875 -1.05 lineto
2.0625 -2.75 lineto
2.5625 -2.75 lineto
3.0625 -0.75 lineto
2.5625 -0.75 lineto
1.9375 -1.25 lineto
2.0625 -0.75 lineto
1.5625 -0.75 lineto
1.0625 -2.75 lineto closepath fill
1.75 1.0 0.5 0 360 arc closepath fill
3.1375 -2.25 moveto
3.625 -2.9 lineto
4.1875 -2.45 lineto
4.2125 -2.35 lineto
3.8375 -2.65 lineto
3.6125 -2.35 lineto
3.7 -2.0 lineto
4.6375 -1.25 lineto
4.15 -0.6 lineto
3.4 -1.2 lineto
3.1375 -2.25 lineto
3.9 -1.2 moveto
4.2125 -0.95 lineto
4.5125 -1.35 lineto
4.4 -1.2 lineto
3.775 -1.7 lineto
3.9 -1.2 lineto closepath fill
"))
FineCaesura = {
\once \override BreathingSign #'text = #fine-caesur-ps \breathe
}
{ \repeat unfold 600 { c' \FineCaesura } \bar "|." }
Es zeigt ein weiteres Problem: Wiederholungen
Kommt dieses Zeichen sehr häufig im Quelltext vor, so stehen im PDF auch für jedes Vorkommen alle einzelnen Geometrieelemente drin. Das bläht natürlich (außer der PS-Datei) auch die PDF unnötigerweise auf.
Im dritten Beispiel habe ich nun einmal einen Postscriptfont definiert und nur noch diesen einen Buchstaben daraus jeweils zur Anzeige aufgerufen. Durch die Font-Machinery reduziert sich dann die PDF-Dateigröße erheblich.
%{
Postscript
%}
\version "2.12.3"
%PREPROCESS: C:\Programme_privat_32\Spezial\close_acrobat -c ${BASENAME} ${BASENAME}-print
FootLeft = #(string-append "Music engraving by LILYPOND, Version " (lilypond-version))
FootRight = #(string-append "compiled at " (strftime "%Y-%m-%d %H:%M:%S" (localtime (current-time))))
FootCenter = #(let*
((cmdl (object->string (command-line)))
(laloc (+ (string-rindex cmdl #\space) 2))
(cmdlen (- (string-length cmdl) 2))
(filen (substring cmdl laloc cmdlen))
(workdir (getcwd))
(basename (let ((ppos (string-rindex filen #\. )))
(if (number? ppos) (substring filen 0 ppos) filen)))
(lastdir (let*
((dpos (string-rindex workdir (string->char-set "\\/")))
(laenge (string-length workdir)))
(if (< (+ dpos 1) laenge) (string-append (substring workdir (+ dpos 1)) "/") "/"))))
(string-append lastdir basename))
#(set-global-staff-size 11.0)
\pointAndClickOff
\paper {
oddFooterMarkup = \markup \fill-line {
\abs-fontsize #6.5 { \FootLeft }
\abs-fontsize #9.0 { \bold { \FootCenter } }
\abs-fontsize #6.5 { \FootRight }
}
left-margin = 12 \mm
line-width = 188 \mm
indent = 3 \mm
ragged-right = ##f
between-system-space = 1 \mm
between-system-padding = 0.6 \mm
}
\header {
title = "»Postscript« Beispiele - Nr. 4"
}
#(define (scaled-ps-markup scale x-min x-max y-min y-max ps-string)
(markup #:line (#:with-dimensions
(cons (* x-min scale) (* x-max scale))
(cons (* y-min scale) (* y-max scale))
(#:postscript (string-concatenate
(list " " (number->string scale) " dup scale \n"
ps-string))))))
#(define (scale-postscript my-grob x-min x-max y-min y-max ps-string)
(let*
((sz (ly:grob-property my-grob 'font-size 0.0))
(mult (magstep sz)))
(scaled-ps-markup mult x-min x-max y-min y-max ps-string)))
#(define (fine-caesur-ps notehead-grob)
(scale-postscript notehead-grob -1.0625 4.6375 -3.5 2.25 "
%%BeginResource: font FineScriptFont
/FineScriptFontIsDefined where { pop } {
%%BeginFont: FineScriptFont
/newFont 13 dict def
newFont begin
/FontType 3 def
/FontMatrix [1 0 0 1 0 0] def
/FontBBox [-1.0625 -3.5 4.6375 2.25] def
/Encoding 256 array def
0 1 255 { Encoding exch /.notdef put } for
Encoding 97 /fineScriptGlyph put % a
/CharProcs 19 dict def
CharProcs begin
/.notdef {} def
/fineScriptGlyph {
newpath 0 setlinewidth 1 setlinejoin 1 setlinecap
-0.1875 0.25 moveto
-0.9375 0.25 lineto
-1.0625 -0.25 lineto
-0.3125 -0.25 lineto
-1.0625 -3.25 lineto
-0.625 -3.5 lineto
0.1875 -0.25 lineto
3.4375 -0.25 lineto
3.8125 0.25 lineto
0.3125 0.25 lineto
0.5 1.0 1.0875 1.75 1.9375 1.75 curveto
2.7875 1.75 3.2375 1.55 3.65 1.0 curveto
4.0625 1.25 lineto
3.6125 1.85 3.0625 2.25 2.0625 2.25 curveto
1.0125 2.25 0.1125 1.45 -0.1875 0.25 curveto closepath fill
0.0625 -2.75 moveto
0.5625 -2.75 lineto
1.0625 -0.75 lineto
0.5625 -0.75 lineto
0.0625 -2.75 lineto closepath fill
1.0625 -2.75 moveto
1.5625 -2.75 lineto
1.8625 -1.55 lineto
2.4875 -1.05 lineto
2.0625 -2.75 lineto
2.5625 -2.75 lineto
3.0625 -0.75 lineto
2.5625 -0.75 lineto
1.9375 -1.25 lineto
2.0625 -0.75 lineto
1.5625 -0.75 lineto
1.0625 -2.75 lineto closepath fill
1.75 1.0 0.5 0 360 arc closepath fill
3.1375 -2.25 moveto
3.625 -2.9 lineto
4.1875 -2.45 lineto
4.2125 -2.35 lineto
3.8375 -2.65 lineto
3.6125 -2.35 lineto
3.7 -2.0 lineto
4.6375 -1.25 lineto
4.15 -0.6 lineto
3.4 -1.2 lineto
3.1375 -2.25 lineto
3.9 -1.2 moveto
4.2125 -0.95 lineto
4.5125 -1.35 lineto
4.4 -1.2 lineto
3.775 -1.7 lineto
3.9 -1.2 lineto closepath fill
} def
end
/Metrics 2 dict def
Metrics begin
/.notdef 1 def
/fineScriptGlyph 5.7 def
end
/BBX 2 dict def
BBX begin
/.notdef [ 0 0 1 1 ] def
/fineScriptGlyph [-1.0625 -3.5 4.6375 2.25] def
end
/FontInfo 1 dict def
FontInfo begin
/isFixedPitch false def
end
/BuildChar % Fontdict charindex
{
exch begin % charindex
Encoding exch get % GlyphName
dup % GlyphName GlyphName
CharProcs exch get % GlyphName GlyphProcedure
exch % GlyphProcedure GlyphName
dup % GlyphProcedure GlyphName GlyphName
Metrics exch get % GlyphProcedure GlyphName GlyphDict
exch 0 exch % GlyphProcedure GlyphDict 0 GlyphName
BBX exch get % GlyphProcedure GlyphDict 0 BBX-Array
end
aload pop % GlyphProcedure GlyphDict 0 BBX_xl BBX_yu bBX_xr BBX_yo
setcachedevice % GlpyhProcedure
exec
} def
end
/FineScriptFont newFont definefont pop
/FineScriptFontIsDefined true def
%%EndFont
} ifelse
%%EndResource
/FineScriptFont findfont 1 scalefont setfont (a) show
"))
FineCaesura = {
\once \override BreathingSign #'text = #fine-caesur-ps \breathe
}
{ \repeat unfold 600 { c' \FineCaesura } \bar "|." }
Mein PDF hat sich gegenüber dem vorigen Beispiel von 227.228 Byte auf 44.268 Byte reduziert (- 80 %),
demgegenüber hat sich aber die PS-Datei von 1.223.666 Byte auf 2.437.462 Byte vergrößert (+ 99 %) - dies ist dem Overhead der Font-Definition geschuldet, die ich bei jedem Vorkommen in die Postscriptdatei aufnehmen muß, und nur über Bedingungsabfragen bei der Umwandlung vom PS ins PDF wird die Ausführung übersprungen.
So komme ich zum Wunsch wohl einiger Anwender, die intensiv mit Postscript arbeiten:Ein »
Include additional Postscript Header File«.
Vielleicht muß man erst »\include "postscript-utils.ly"« angeben, um dann mit so etwas wie »\includePS "xyz-procedure-setup.ps"« die gewünschte Postscript-Routinen-Erweiterung zu registrieren.
Diese Postscript-Datei(en), die wie die LY-Dateien irgendwo im Lilypond-Suchpfad liegt (liegen), wird (werden) dann beim Erzeugen der PS-Datei im Anschluß an die ProcSets »music-drawing-routines.ps« und »lilyponddefs.ps« in die PS-Datei übertragen.
Diese beiden eben genannten System-PS-Dateien werden in der Version 2.12.3 in der Datei framework-ps.scm ziemlich am Schluß der Routine »write-preamble« ausgegeben.
- Kann man diese »write-preable«-Routine eigentlich »überladen« mit einer neuen, welche erst die Originalroutine ausführt, und dann noch den persönlichen Postscript-Anhang ausgibt?
- Oder muß bei einem Lily-Book die Ausgabe noch höher aufgehängt werden?
- Reicht für diese Erweiterung das Hinzufügen von Code via \include, oder muß eine Routine aus der Standardinstallation verändert werden?
Immerhin, wäre die Fontdefinition des dritten Beispiels nur einmal in der PS-Datei vorhanden, so habe ich eine Einsparung von 1,98 MB geschätzt - dann wäre also die PS-Datei statt 99 % größer um 60 % kleiner als beim zweiten Beispiel.
Arnold