OLD | NEW |
1 /* | 1 /* |
2 This file is part of LilyPond, the GNU music typesetter. | 2 This file is part of LilyPond, the GNU music typesetter. |
3 | 3 |
4 Copyright (C) 1998--2020 Han-Wen Nienhuys <hanwen@xs4all.nl> | 4 Copyright (C) 1998--2020 Han-Wen Nienhuys <hanwen@xs4all.nl> |
5 Jan Nieuwenhuizen <janneke@gnu.org> | 5 Jan Nieuwenhuizen <janneke@gnu.org> |
6 | 6 |
7 LilyPond is free software: you can redistribute it and/or modify | 7 LilyPond is free software: you can redistribute it and/or modify |
8 it under the terms of the GNU General Public License as published by | 8 it under the terms of the GNU General Public License as published by |
9 the Free Software Foundation, either version 3 of the License, or | 9 the Free Software Foundation, either version 3 of the License, or |
10 (at your option) any later version. | 10 (at your option) any later version. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 { | 49 { |
50 max_length = std::max (max_length, scm_to_int | 50 max_length = std::max (max_length, scm_to_int |
51 (scm_string_length (scm_caar (s)))); | 51 (scm_string_length (scm_caar (s)))); |
52 } | 52 } |
53 | 53 |
54 for (vsize i = 0; i < str.size (); i++) | 54 for (vsize i = 0; i < str.size (); i++) |
55 { | 55 { |
56 /* Don't match in mid-UTF-8 */ | 56 /* Don't match in mid-UTF-8 */ |
57 if ((str[i] & 0xc0) == 0x80) | 57 if ((str[i] & 0xc0) == 0x80) |
58 continue; | 58 continue; |
59 for (vsize j = max_length + 1; j--;) | 59 for (vsize j = max_length; j > 0; j--) |
60 { | 60 { |
61 if (j > str.size () - i) | 61 if (j > str.size () - i) |
62 continue; | 62 continue; |
63 string dummy = str.substr (i, j); | 63 // TODO: It could make sense to skip if not at the end of a UTF-8 |
64 SCM ligature = ly_assoc_get (ly_string2scm (dummy), | 64 // glyph. However that requires finding the start of the last glyph |
65 replacement_alist, SCM_BOOL_F); | 65 // (not necessarily at str[i] - the longest replacement could match |
| 66 // multiple glyphs) to get the glyph's length which is not trivial. |
| 67 // So for now just continue checking all substrings that could be |
| 68 // valid UTF-8 (see check for str[i] not in mid-UTF-8 above). |
| 69 SCM substr = scm_from_latin1_stringn (str.c_str() + i, j); |
| 70 SCM ligature = ly_assoc_get (substr, replacement_alist, SCM_BOOL_F); |
66 if (scm_is_true (ligature)) | 71 if (scm_is_true (ligature)) |
67 str.replace (i, j, robust_scm2string (ligature, "")); | 72 str.replace (i, j, robust_scm2string (ligature, "")); |
68 } | 73 } |
69 } | 74 } |
70 } | 75 } |
71 | 76 |
72 MAKE_SCHEME_CALLBACK (Text_interface, interpret_string, 3); | 77 MAKE_SCHEME_CALLBACK (Text_interface, interpret_string, 3); |
73 SCM | 78 SCM |
74 Text_interface::interpret_string (SCM layout_smob, | 79 Text_interface::interpret_string (SCM layout_smob, |
75 SCM props, | 80 SCM props, |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 237 |
233 /* properties */ | 238 /* properties */ |
234 "baseline-skip " | 239 "baseline-skip " |
235 "replacement-alist " | 240 "replacement-alist " |
236 "text " | 241 "text " |
237 "word-space " | 242 "word-space " |
238 "text-direction " | 243 "text-direction " |
239 "flag-style " | 244 "flag-style " |
240 ); | 245 ); |
241 | 246 |
OLD | NEW |