Reviewers: dak, Message: I think this may have lacked sf.net issue. Please review.
Description: Introduce ly_scm2utf8_string, and use it for printing text Before, Text_interface::interpret_string used ly_scm2string, which runs scm_to_locale_stringn to get at the string. The default locale is "C", so all Unicode chars are then converted to "?". Please review this at https://codereview.appspot.com/577440043/ Affected files (+20, -1 lines): M lily/include/lily-guile.hh M lily/lily-guile.cc M lily/text-interface.cc Index: lily/include/lily-guile.hh diff --git a/lily/include/lily-guile.hh b/lily/include/lily-guile.hh index ab14e8541e4f6a39bd9d87a0bc262c0b86805af1..ccbebcadf976bd2da40a14e2e0d88edc715ac0a4 100644 --- a/lily/include/lily-guile.hh +++ b/lily/include/lily-guile.hh @@ -57,6 +57,7 @@ std::string gulp_file_to_string (const std::string &fn, bool must_exist, int siz SCM ly_string2scm (std::string const &s); std::string ly_scm2string (SCM s); +std::string ly_scm2utf8_string (SCM); std::string ly_symbol2string (SCM); std::string robust_symbol2string (SCM, const std::string&); Rational ly_scm2rational (SCM); Index: lily/lily-guile.cc diff --git a/lily/lily-guile.cc b/lily/lily-guile.cc index 7f084806e928aebf1a1add8e0dbe9f41a95fcf82..84e2e69672f2590acdbf3938fa739edcacecda7b 100644 --- a/lily/lily-guile.cc +++ b/lily/lily-guile.cc @@ -119,6 +119,24 @@ extern "C" { /* STRINGS */ +string +ly_scm2utf8_string (SCM str) +{ +#if GUILEV2 + assert (scm_is_string (str)); + size_t len = 0; + char *bytes = scm_to_utf8_stringn (str, &len); + + // It would be nice to stick 'bytes' directly into string. + string result(bytes, len); + + free(bytes); + return result; +#else + return ly_scm2string(str); +#endif +} + string ly_scm2string (SCM str) { Index: lily/text-interface.cc diff --git a/lily/text-interface.cc b/lily/text-interface.cc index 1f62e9b287290439d45375e717b03196656ac763..9d8de13778966b169771c7762a186adc6cb61e00 100644 --- a/lily/text-interface.cc +++ b/lily/text-interface.cc @@ -78,7 +78,7 @@ Text_interface::interpret_string (SCM layout_smob, LY_ASSERT_SMOB (Output_def, layout_smob, 1); LY_ASSERT_TYPE (scm_is_string, markup, 3); - string str = ly_scm2string (markup); + string str = ly_scm2utf8_string (markup); Output_def *layout = unsmob<Output_def> (layout_smob); Font_metric *fm = select_encoded_font (layout, props);