[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
Fix the encoding of the PDF metadata when using guile-2.0 (issue 322930043 by address@hidden)
Mon, 01 May 2017 05:44:48 -0700
This is one of Antonio's set of patches to make LilyPond work with
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.
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
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):
diff --git a/lily/pdf-scheme.cc b/lily/pdf-scheme.cc
@@ -84,14 +84,16 @@ LY_DEFINE
/* Convert back to SCM object and return it */
- /* FIXME guile-2.0: With guile 2.0 the internal representation of a
- * has changed (char vector rather than binary bytes in
- * UTF-8). However, with guile 2.0,
- * is no longer needed and can be replaced by the new
- * (string->utf16 str 'big)
- return scm_take_str (g, bytes_written); // scm_take_str eventually
+ * 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);
+ return string;
diff --git 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
+ ;; 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))
- Fix the encoding of the PDF metadata when using guile-2.0 (issue 322930043 by address@hidden),