GNU lilypondで日本語を使いたい

ケーニヒスクローネ

僕は楽譜を書くのにGNU lilypondを使っています。lilypond-2.6からはUTF-8で書けば日本語が使えるはずなのですが、僕の環境では使えません。調べたらどうやら日本語フォントを文字列に直しているところで、guileで扱える最大サイズを越えてしまっているようです。仕方がないからクイックハック。実装がひどすぎですが、クイックハックなんで勘弁してください。
ファイル: lilypond-2.6.5_utf8-fix.patch

--- lilypond-2.6.5/lily/ttf.cc.orig	2006-02-05 11:48:27.000000000 +0900
+++ lilypond-2.6.5/lily/ttf.cc	2006-02-05 10:56:55.000000000 +0900
@@ -9,6 +9,7 @@
 
 #include "freetype.hh"
 
+#include <libgen.h>
 #include <freetype/tttables.h>
 
 #include "lily-proto.hh"
@@ -175,10 +176,23 @@
     progress_indication ("[" + file_name);
   
   Memory_out_stream stream;
-
   create_type42_font (&stream, file_name);
-  SCM asscm = scm_from_locale_stringn (stream.get_string (),
+
+  SCM asscm;
+  if (stream.get_length () < (1 << 24) - 1) {
+	  asscm = scm_from_locale_stringn (stream.get_string (),
 				       stream.get_length ());
+  } else {
+	  String s(basename (file_name.get_str0 ()));
+	  s += ".dat";
+	  FILE *fd = fopen (s.get_str0 (), "wb");
+	  fprintf (fd, "%s", stream.get_string ());
+	  fclose (fd);
+	  Memory_out_stream stream2;
+	  lily_cookie_fprintf (&stream2, "XXX replace:%s", s.get_str0 ());
+	  asscm = scm_from_locale_stringn (stream2.get_string (),
+				       stream2.get_length ());
+  }
 
   if (be_verbose_global)
     progress_indication ("]");
--- lilypond-2.6.5/scripts/replace-ly.rb.orig	2006-02-05 11:51:58.000000000 +0900
+++ lilypond-2.6.5/scripts/replace-ly.rb	2006-02-05 11:51:19.000000000 +0900
@@ -0,0 +1,18 @@
+#!/usr/bin/env ruby
+# -*- ruby -*-
+
+filename = ARGV[0]
+File.rename(filename, filename + '.orig')
+open(filename, 'w') do |dst|
+  open(filename + '.orig', 'r') do |src|
+    while line = src.gets
+      if line =~ /XXX replace:(.*)/
+        open($1, 'r') do |file|
+          dst.print file.read
+        end
+      else
+        dst.print line
+      end
+    end
+  end
+end
--- lilypond-2.6.5/scm/backend-library.scm.orig	2006-02-05 11:50:23.000000000 +0900
+++ lilypond-2.6.5/scm/backend-library.scm	2006-02-06 23:27:14.000000000 +0900
@@ -48,7 +48,7 @@
 (define-public (postscript->pdf papersizename name)
   (let* ((pdf-name (string-append (basename name ".ps") ".pdf"))
 	 (cmd (format #f
-		      "~a\
+		      "replace-ly ~S && ~a\
  ~a\
  ~a\
  -dCompatibilityLevel=1.4 \
@@ -61,6 +61,7 @@
  -c .setpdfwrite\
  -f ~S\
 "
+		      name
 		      (search-gs)
 		      (if (ly:get-option 'verbose) "" "-q")
 		      (if (ly:get-option 'gs-font-load)

このpatchを使う人はいないと思いますが、 一応インストール方法もメモしておきます。

$ tar zxvf lilypond-2.6.5.tar.gz
$ cd lilypond-2.6.5
$ patch -p1 < /path/to/lilypond-2.6.5_utf8-fix.patch
$ ./configure
$ gmake
$ gmake install
$ sudo install -m 755  scripts/replace-ly.rb /usr/local/bin/replace-ly

僕にとって、GNU lilypondは複雑怪奇なシステム(C++ & Python & Guileを使って、独自書式のファイルからPS・PDFを出力するシステム。ちょっと前はTeXも絡んでました)なんでできれば手を出したくないんですよね。