]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/pdf-scheme.cc
Release: bump Welcome versions.
[lilypond.git] / lily / pdf-scheme.cc
index 13e8389ecec7b42a1831c4001090b25ff54e9474..61cf382e6b45e21955f87d34df57609fc39b48a7 100644 (file)
@@ -1,7 +1,7 @@
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 2011 Reinhold Kainhofer <reinhold@kainhofer.com>
+  Copyright (C) 2011--2015 Reinhold Kainhofer <reinhold@kainhofer.com>
 
   LilyPond is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -36,10 +36,25 @@ LY_DEFINE (ly_encode_string_for_pdf, "ly:encode-string-for-pdf",
   char const *charset = "UTF-8"; // Input is ALWAYS UTF-8!
   gsize bytes_written = 0;
 
+#if 0
+
   /* First, try to convert to ISO-8859-1 (no encodings required). This will
    * fail, if the string contains accented characters, so we do not check
    * for errors. */
   g = g_convert (p, -1, "ISO-8859-1", charset, 0, &bytes_written, 0);
+
+#else
+
+  /* In contrast to the above comment, we do _not_ try full ISO-8859-1
+   * since a number of Ghostscript versions fail to properly convert
+   * this into PDF.  UTF-16BE, in contrast, works better with recent
+   * versions of Ghostscript.
+   */
+
+  g = g_convert (p, -1, "ASCII", charset, 0, &bytes_written, 0);
+
+#endif
+
   /* If that fails, we have to resolve to full UTF-16BE */
   if (!g)
     {
@@ -58,7 +73,7 @@ LY_DEFINE (ly_encode_string_for_pdf, "ly:encode-string-for-pdf",
        * though), we have to prepend it manually. */
       if (g_without_BOM) // conversion to UTF-16be might have failed (shouldn't!)
         {
-          g = (char*)malloc ( sizeof(char) * (bytes_written + 3));
+          g = (char *)malloc ( sizeof (char) * (bytes_written + 3));
           char const *BOM = "\xFE\xFF";
           strcpy (g, BOM);
           memcpy (&g[2], g_without_BOM, bytes_written + 1); // Copy string + \0
@@ -69,14 +84,16 @@ LY_DEFINE (ly_encode_string_for_pdf, "ly:encode-string-for-pdf",
   free (p);
 
   /* Convert back to SCM object and return it */
-  /* FIXME guile-2.0: With guile 2.0 the internal representation of a string
-   *                  has changed (char vector rather than binary bytes in
-   *                  UTF-8). However, with guile 2.0, ly:encode-string-for-pdf
-   *                  is no longer needed and can be replaced by the new
-   *                  (string->utf16 str 'big)
-   */
   if (g)
-    return scm_take_str (g, bytes_written); // scm_take_str eventually frees g!
+    {
+      /*
+       * Return the raw byte representation of the UTF-16BE encoded string,
+       * in a locale independent way.
+       */
+      SCM string = scm_from_latin1_stringn (g, bytes_written);
+      free(g);
+      return string;
+    }
   else
     return str;
 }