]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/framework-ps.scm
Issue 4889/2: Integrate Type1 font embedding procedures
[lilypond.git] / scm / framework-ps.scm
index f6d1700f424355f278fe0d3facdfa1690a030125..9dc8414bbfe608e16d7871c40ee16a07bf611d05 100644 (file)
     (let* ((downcase-file-name (string-downcase file-name)))
       (cond
        ((and file-name (string-endswith downcase-file-name ".pfa"))
-        (embed-document file-name))
+        (ly:type1->pfa file-name))
        ((and file-name (string-endswith downcase-file-name ".pfb"))
-        (ly:pfb->pfa file-name))
+        (ly:type1->pfa file-name))
        ((and file-name (string-endswith downcase-file-name ".ttf"))
         (ly:ttf->pfa file-name))
        ((and file-name (string-endswith downcase-file-name ".ttc"))
-        (ly:ttf->pfa file-name font-index))
+        ;; TODO: distinguish files which have extension `*.ttc'
+        ;; whether TrueType Collection (TTC) fonts
+        ;; or OpenType/CFF Collection (OTC) fonts.
+        (ly:ttf->pfa file-name font-index)) ;; TTC fonts
        ((and file-name (string-endswith downcase-file-name ".otf"))
         (ps-embed-cff (ly:otf->cff file-name) name 0))
+       ((and file-name (string-endswith downcase-file-name ".otc"))
+        ;; The files which have the extension `*.otc' are OTC fonts.
+        (ps-embed-cff (ly:otf->cff file-name font-index) name 0)) ;; OTC fonts
        (else
         (ly:warning (_ "do not know how to embed ~S=~S") name file-name)
         ""))))
            (val (if overrideval overrideval fallbackval)))
       (if val
           (format port "/~a (~a)\n" field (metadata-encode (markup->string val (list header)))))))
-  (display "[ " port)
-  (metadata-lookup-output 'pdfauthor 'author "Author")
-  (format port "/Creator (LilyPond ~a)\n" (lilypond-version))
-  (metadata-lookup-output 'pdftitle 'title "Title")
-  (metadata-lookup-output 'pdfsubject 'subject "Subject")
-  (metadata-lookup-output 'pdfkeywords 'keywords "Keywords")
-  (metadata-lookup-output 'pdfmodDate 'modDate "ModDate")
-  (metadata-lookup-output 'pdfsubtitle 'subtitle "Subtitle")
-  (metadata-lookup-output 'pdfcomposer 'composer "Composer")
-  (metadata-lookup-output 'pdfarranger 'arranger "Arranger")
-  (metadata-lookup-output 'pdfpoet 'poet "Poet")
-  (metadata-lookup-output 'pdfcopyright 'copyright "Copyright")
-  (display "/DOCINFO pdfmark\n\n" port))
 
+  (if (module? header)
+      (begin
+       (display "mark " port)
+       (metadata-lookup-output 'pdfauthor 'author "Author")
+       (format port "/Creator (LilyPond ~a)\n" (lilypond-version))
+       (metadata-lookup-output 'pdftitle 'title "Title")
+       (metadata-lookup-output 'pdfsubject 'subject "Subject")
+       (metadata-lookup-output 'pdfkeywords 'keywords "Keywords")
+       (metadata-lookup-output 'pdfmodDate 'modDate "ModDate")
+       (metadata-lookup-output 'pdfsubtitle 'subtitle "Subtitle")
+       (metadata-lookup-output 'pdfcomposer 'composer "Composer")
+       (metadata-lookup-output 'pdfarranger 'arranger "Arranger")
+       (metadata-lookup-output 'pdfpoet 'poet "Poet")
+       (metadata-lookup-output 'pdfcopyright 'copyright "Copyright")
+       (display "/DOCINFO pdfmark\n\n" port)))
+
+  (if (ly:get-option 'embed-source-code)
+      (let ((source-list (delete-duplicates
+                          (remove (lambda (str)
+                                    (or
+                                     (string-contains str
+                                       (ly:get-option 'datadir))
+                                     (string=? str
+                                       "<included string>")))
+                            (ly:source-files)))))
+         (display "\n/pdfmark where
+{pop} {userdict /pdfmark /cleartomark load put} ifelse" port)
+         (for-each (lambda (fname idx)
+                     (format port "\n
+mark /_objdef {ly~a_stream} /type /stream   /OBJ pdfmark
+mark {ly~a_stream} << /Type /EmbeddedFile>> /PUT pdfmark
+mark {ly~a_stream} (~a) /PUT pdfmark
+mark /Name (LilyPond source file ~a)
+/FS << /Type /Filespec /F (~a) /EF << /F {ly~a_stream} >> >> /EMBED pdfmark
+mark {ly~a_stream} /CLOSE pdfmark
+\n"
+                idx idx idx
+                (ps-quote (ly:gulp-file fname))
+                  idx fname idx idx))
+          source-list (iota (length source-list))))))
 
 (define-public (output-framework basename book scopes fields)
   (let* ((port-tmp (make-tmpfile))
     ;; don't do BeginDefaults PageMedia: A4
     ;; not necessary and wrong
     (write-preamble paper #t port)
-    (if (module? header)
-        (handle-metadata header port))
+    (handle-metadata header port)
     (for-each
      (lambda (page)
        (set! page-number (1+ page-number))
@@ -730,7 +762,7 @@ system-by-system output.  For that, use the EPS backend instead,
 
   lilypond -dbackend=eps FILE
 
-If have cut & pasted a lilypond fragment from a webpage, be sure
+If you have cut & pasted a lilypond fragment from a webpage, be sure
 to only remove anything before
 
   %% ****************************************************************