lilypond-devel
[Top][All Lists]
Advanced

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

Fix the encoding of the PDF metadata when using guile-2.0 (issue 3229300


From: thomasmorley65
Subject: Fix the encoding of the PDF metadata when using guile-2.0 (issue 322930043 by address@hidden)
Date: Mon, 01 May 2017 05:44:48 -0700

Reviewers: ,

Message:
This is one of Antonio's set of patches to make LilyPond work with
guile-2.x.
And one (of two) which should be compatible with guile-1.
In case the cc-part will need changes during review I'll be pretty much
at a loss.
So Antonio is cc'ed.

Please review.

Description:
Fix the encoding of the PDF metadata when using guile-2.0

Postscript files are encoded in Latin1, but PDF metadata has to be
encoded in UTF-16BE.

ly:encode-string-for-pdf takes care of that but it was not working
properly with guile-2.0 because the internal representation of strings
in guile-2.0 has changed and the actual destination encoding has to be
specified explicitly, especially when it's different from the current
locale.

Passing the encoded metadata as Latin1 corresponds to pass its raw byte
representation, and this is enough to make things work.

This also gets rid of a misleading warning:
  "`scm_take_str' is deprecated. Use scm_take_locale_stringn instead."

This change is compatible with guile-1.8 so the FIXME comment in
lily/pdf-scheme.cc has been removed. A note was added to
scm/framework-ps.scm to suggest a possible implementation in scheme of
ly_encode_for_pdf(), just in case of a possible future cleanup.

Please review this at https://codereview.appspot.com/322930043/

Affected files (+17, -9 lines):
  M lily/pdf-scheme.cc
  M scm/framework-ps.scm


Index: lily/pdf-scheme.cc
diff --git a/lily/pdf-scheme.cc b/lily/pdf-scheme.cc
index da2ce2cef3c74b8346ef707eda37d1006111e3c1..61cf382e6b45e21955f87d34df57609fc39b48a7 100644
--- a/lily/pdf-scheme.cc
+++ b/lily/pdf-scheme.cc
@@ -84,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;
 }
Index: scm/framework-ps.scm
diff --git a/scm/framework-ps.scm b/scm/framework-ps.scm
index 9498b2ac9dd24bff298a593707e53a9862b57609..6ff034564d7686ccd0b5fbf7b98485bcf290d7a2 100644
--- a/scm/framework-ps.scm
+++ b/scm/framework-ps.scm
@@ -599,8 +599,14 @@
   (define (metadata-encode val)
     ;; First, call ly:encode-string-for-pdf to encode the string (latin1 or
     ;; utf-16be), then escape all parentheses and backslashes
-    ;; FIXME guile-2.0: use (string->utf16 str 'big) instead
-
+    ;;
+ ;; NOTE: with guile-2.0+ ly:encode-string-for-pdf is not really needed and
+    ;; could be replaced with the followng code:
+    ;;
+    ;;    (let* ((utf16be-bom #vu8(#xFE #xFF)))
+    ;;      (string-append (bytevector->string utf16be-bom "ISO-8859-1")
+ ;; (bytevector->string (string->utf16 val 'big) "ISO-8859-1")))
+    ;;
     (ps-quote (ly:encode-string-for-pdf val)))
   (define (metadata-lookup-output overridevar fallbackvar field)
     (let* ((overrideval (ly:modules-lookup (list header) overridevar))





reply via email to

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