From 01b6600ade6dfe400059341994bdbb6db2f6d290 Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Sat, 12 Oct 2024 14:02:32 +0800 Subject: [PATCH] [11_39] Render unicode in the cjk font when its range is in latin Before: ![image](https://github.com/user-attachments/assets/de724cee-ce5a-450a-a621-6c73b665b3f4) Now: zh: ![image](https://github.com/user-attachments/assets/2950bf50-97a1-4729-9d41-9d1d0a717cbf) en: ![image](https://github.com/user-attachments/assets/efba372c-8e01-40be-a91e-b4a14c12e3a1) en in GNU TeXmacs 2.1.4: ![image](https://github.com/user-attachments/assets/10ca9796-8d94-4a4d-b5e3-ed194674b3d4) symbl.cc: ![image](https://github.com/user-attachments/assets/cea27151-3451-4233-9a2e-60cf1fce753b) --- TeXmacs/tests/tmu/11_39_nbsp.tmu | 14 + TeXmacs/tests/tmu/11_39_nbsp_2.tmu | 14 + TeXmacs/tests/tmu/unicode_256.en.tmu | 268 ++++++++--------- TeXmacs/tests/tmu/unicode_256.zh.tmu | 270 +++++++++--------- src/Graphics/Fonts/smart_font.cpp | 23 +- src/Plugins/Freetype/unicode_font.cpp | 2 +- .../Graphics/Fonts/smart_font_test.cpp | 10 +- 7 files changed, 317 insertions(+), 284 deletions(-) create mode 100644 TeXmacs/tests/tmu/11_39_nbsp.tmu create mode 100644 TeXmacs/tests/tmu/11_39_nbsp_2.tmu rename tests/{L3 => }/Graphics/Fonts/smart_font_test.cpp (90%) diff --git a/TeXmacs/tests/tmu/11_39_nbsp.tmu b/TeXmacs/tests/tmu/11_39_nbsp.tmu new file mode 100644 index 0000000000..16d838475a --- /dev/null +++ b/TeXmacs/tests/tmu/11_39_nbsp.tmu @@ -0,0 +1,14 @@ +> + +> + +<\body> +   + + +<\initial> + <\collection> + + + + diff --git a/TeXmacs/tests/tmu/11_39_nbsp_2.tmu b/TeXmacs/tests/tmu/11_39_nbsp_2.tmu new file mode 100644 index 0000000000..fd2629a53c --- /dev/null +++ b/TeXmacs/tests/tmu/11_39_nbsp_2.tmu @@ -0,0 +1,14 @@ +> + +> + +<\body> + + + +<\initial> + <\collection> + + + + diff --git a/TeXmacs/tests/tmu/unicode_256.en.tmu b/TeXmacs/tests/tmu/unicode_256.en.tmu index 3bc1e7cf37..c761f80612 100644 --- a/TeXmacs/tests/tmu/unicode_256.en.tmu +++ b/TeXmacs/tests/tmu/unicode_256.en.tmu @@ -3,8 +3,10 @@ <\body> + \; + <\wide-tabular> - |||| + ||||||||| \; |<\cell> 0 @@ -111,35 +113,35 @@ |<\cell> \ |<\cell> - \; + ! |<\cell> - \; + " |<\cell> - \; + # |<\cell> - \; + $ |<\cell> - \; + % |<\cell> - \; + & |<\cell> - \; + ' |<\cell> - \; + ( |<\cell> - \; + ) |<\cell> - \; + * |<\cell> - \; + + |<\cell> - \; + , |<\cell> - \; + - |<\cell> - \; + . |<\cell> - \; + / >| 003 |<\cell> @@ -177,137 +179,137 @@ >| 004 |<\cell> - \; + @ |<\cell> - \; + A |<\cell> - \; + B |<\cell> - \; + C |<\cell> - \; + D |<\cell> - \; + E |<\cell> - \; + F |<\cell> - \; + G |<\cell> - \; + H |<\cell> - \; + I |<\cell> - \; + J |<\cell> - \; + K |<\cell> - \; + L |<\cell> - \; + M |<\cell> - \; + N |<\cell> - \; + O >| 005 |<\cell> - \; + P |<\cell> - \; + Q |<\cell> - \; + R |<\cell> - \; + S |<\cell> - \; + T |<\cell> - \; + U |<\cell> - \; + V |<\cell> - \; + W |<\cell> - \; + X |<\cell> - \; + Y |<\cell> - \; + Z |<\cell> - \; + [ |<\cell> - \; + \\ |<\cell> - \; + ] |<\cell> - \; + ^ |<\cell> - \; + _ >| 006 |<\cell> - \; + ` |<\cell> - \; + a |<\cell> - \; + b |<\cell> - \; + c |<\cell> - \; + d |<\cell> - \; + e |<\cell> - \; + f |<\cell> - \; + g |<\cell> - \; + h |<\cell> - \; + i |<\cell> - \; + j |<\cell> - \; + k |<\cell> - \; + l |<\cell> - \; + m |<\cell> - \; + n |<\cell> - \; + o >| 007 |<\cell> - \; + p |<\cell> - \; + q |<\cell> - \; + r |<\cell> - \; + s |<\cell> - \; + t |<\cell> - \; + u |<\cell> - \; + v |<\cell> - \; + w |<\cell> - \; + x |<\cell> - \; + y |<\cell> - \; + z |<\cell> - \; + { |<\cell> - \; + \| |<\cell> - \; + } |<\cell> - \; + ~ |<\cell> ­ >| @@ -420,9 +422,7 @@ ± |<\cell> ² - |<\cell> - ³ - |<\cell> + ||<\cell> ´ |<\cell> µ @@ -455,31 +455,31 @@ |<\cell>  |<\cell> - \; + à |<\cell> - \; + Ä |<\cell> - \; + Å |<\cell> - \; + Æ |<\cell> - \; + Ç |<\cell> - \; + È |<\cell> - \; + É |<\cell> - \; + Ê |<\cell> - \; + Ë |<\cell> - \; + Ì |<\cell> - \; + Í |<\cell> - \; + Î |<\cell> - \; + Ï >| 00D |<\cell> @@ -487,83 +487,83 @@ |<\cell> Ñ |<\cell> - \; + Ò |<\cell> - \; + Ó |<\cell> - \; + Ô |<\cell> - \; + Õ |<\cell> - \; + Ö |<\cell> - Œ + × |<\cell> - \; + Ø |<\cell> - \; + Ù |<\cell> - \; + Ú |<\cell> - \; + Û |<\cell> - \; + Ü |<\cell> - \; + Ý |<\cell> - \; + Þ |<\cell> - \; + ß >| 00E |<\cell> à |<\cell> - \; + á |<\cell> - \; + â |<\cell> - \; + ã |<\cell> - \; + ä |<\cell> - \; + å |<\cell> - \; + æ |<\cell> - \; + ç |<\cell> - \; + è |<\cell> - \; + é |<\cell> - \; + ê |<\cell> - \; + ë |<\cell> - \; + ì |<\cell> - \; + í |<\cell> - \; + î |<\cell> - \; + ï >| 00F |<\cell> ð |<\cell> - \; + ñ |<\cell> - \; + ò |<\cell> - \; + ó |<\cell> - \; + ô |<\cell> - \; + õ |<\cell> - \; + ö |<\cell> ÷ |<\cell> @@ -573,13 +573,13 @@ |<\cell> ú |<\cell> - \; + û |<\cell> - \; + ü |<\cell> - \; + ý |<\cell> - \; + þ |<\cell> ÿ >>> diff --git a/TeXmacs/tests/tmu/unicode_256.zh.tmu b/TeXmacs/tests/tmu/unicode_256.zh.tmu index 1b76d94bba..84573c1c91 100644 --- a/TeXmacs/tests/tmu/unicode_256.zh.tmu +++ b/TeXmacs/tests/tmu/unicode_256.zh.tmu @@ -3,8 +3,10 @@ > <\body> + \; + <\wide-tabular> - ||||||| + ||||||||| \; |<\cell> 0 @@ -109,37 +111,37 @@ >| 002 |<\cell> - \; + \ |<\cell> - \; + ! |<\cell> - \; + " |<\cell> - \; + # |<\cell> - \; + $ |<\cell> - \; + % |<\cell> - \; + & |<\cell> - \; + ' |<\cell> - \; + ( |<\cell> - \; + ) |<\cell> - \; + * |<\cell> - \; + + |<\cell> - \; + , |<\cell> - \; + - |<\cell> - \; + . |<\cell> - \; + / >| 003 |<\cell> @@ -177,137 +179,137 @@ >| 004 |<\cell> - \; + @ |<\cell> - \; + A |<\cell> - \; + B |<\cell> - \; + C |<\cell> - \; + D |<\cell> - \; + E |<\cell> - \; + F |<\cell> - \; + G |<\cell> - \; + H |<\cell> - \; + I |<\cell> - \; + J |<\cell> - \; + K |<\cell> - \; + L |<\cell> - \; + M |<\cell> - \; + N |<\cell> - \; + O >| 005 |<\cell> - \; + P |<\cell> - \; + Q |<\cell> - \; + R |<\cell> - \; + S |<\cell> - \; + T |<\cell> - \; + U |<\cell> - \; + V |<\cell> - \; + W |<\cell> - \; + X |<\cell> - \; + Y |<\cell> - \; + Z |<\cell> - \; + [ |<\cell> - \; + \\ |<\cell> - \; + ] |<\cell> - \; + ^ |<\cell> - \; + _ >| 006 |<\cell> - \; + ` |<\cell> - \; + a |<\cell> - \; + b |<\cell> - \; + c |<\cell> - \; + d |<\cell> - \; + e |<\cell> - \; + f |<\cell> - \; + g |<\cell> - \; + h |<\cell> - \; + i |<\cell> - \; + j |<\cell> - \; + k |<\cell> - \; + l |<\cell> - \; + m |<\cell> - \; + n |<\cell> - \; + o >| 007 |<\cell> - \; + p |<\cell> - \; + q |<\cell> - \; + r |<\cell> - \; + s |<\cell> - \; + t |<\cell> - \; + u |<\cell> - \; + v |<\cell> - \; + w |<\cell> - \; + x |<\cell> - \; + y |<\cell> - \; + z |<\cell> - \; + { |<\cell> - \; + \| |<\cell> - \; + } |<\cell> - \; + ~ |<\cell> ­ >| @@ -420,9 +422,7 @@ ± |<\cell> ² - |<\cell> - ³ - |<\cell> + ||<\cell> ´ |<\cell> µ @@ -455,31 +455,31 @@ |<\cell>  |<\cell> - \; + à |<\cell> - \; + Ä |<\cell> - \; + Å |<\cell> - \; + Æ |<\cell> - \; + Ç |<\cell> - \; + È |<\cell> - \; + É |<\cell> - \; + Ê |<\cell> - \; + Ë |<\cell> - \; + Ì |<\cell> - \; + Í |<\cell> - \; + Î |<\cell> - \; + Ï >| 00D |<\cell> @@ -487,83 +487,83 @@ |<\cell> Ñ |<\cell> - \; + Ò |<\cell> - \; + Ó |<\cell> - \; + Ô |<\cell> - \; + Õ |<\cell> - \; + Ö |<\cell> - Œ + × |<\cell> - \; + Ø |<\cell> - \; + Ù |<\cell> - \; + Ú |<\cell> - \; + Û |<\cell> - \; + Ü |<\cell> - \; + Ý |<\cell> - \; + Þ |<\cell> - \; + ß >| 00E |<\cell> à |<\cell> - \; + á |<\cell> - \; + â |<\cell> - \; + ã |<\cell> - \; + ä |<\cell> - \; + å |<\cell> - \; + æ |<\cell> - \; + ç |<\cell> - \; + è |<\cell> - \; + é |<\cell> - \; + ê |<\cell> - \; + ë |<\cell> - \; + ì |<\cell> - \; + í |<\cell> - \; + î |<\cell> - \; + ï >| 00F |<\cell> ð |<\cell> - \; + ñ |<\cell> - \; + ò |<\cell> - \; + ó |<\cell> - \; + ô |<\cell> - \; + õ |<\cell> - \; + ö |<\cell> ÷ |<\cell> @@ -573,13 +573,13 @@ |<\cell> ú |<\cell> - \; + û |<\cell> - \; + ü |<\cell> - \; + ý |<\cell> - \; + þ |<\cell> ÿ >>> diff --git a/src/Graphics/Fonts/smart_font.cpp b/src/Graphics/Fonts/smart_font.cpp index 1ac6c6e340..0d38ddb678 100644 --- a/src/Graphics/Fonts/smart_font.cpp +++ b/src/Graphics/Fonts/smart_font.cpp @@ -397,7 +397,8 @@ in_unicode_range (string c, string range) { string got = lolly::data::unicode_get_range (code); if (range == got) return range != ""; if (range == "cjk") { - if (got == "hangul" || got == "hiragana" || got == "enclosed_alphanumerics") + if (got == "hangul" || got == "hiragana" || + got == "enclosed_alphanumerics" || got == "latin") return true; return is_cjk_punct (uc); } @@ -750,14 +751,15 @@ smart_font_rep::advance (string s, int& pos, string& r, int& nr) { int count= 0; int start= pos; nr = -1; - while (pos < N (s)) { + int s_N = N (s); + while (pos < s_N) { if (s[pos] != '<') { int c= (int) (unsigned char) s[pos]; int fn_index= chv[c]; if (math_kind != 0 && math_kind != 2 && is_alpha (c) && (pos == 0 || !is_alpha (s[pos - 1])) && - (pos + 1 == N (s) || !is_alpha (s[pos + 1]))) { + (pos + 1 == s_N || !is_alpha (s[pos + 1]))) { fn_index= italic_nr; } else if (fn_index == -1) { @@ -803,9 +805,11 @@ smart_font_rep::advance (string s, int& pos, string& r, int& nr) { if (nr < 0) return; if (N (fn) <= nr || is_nil (fn[nr])) initialize_font (nr); if (sm->fn_rewr[nr] != REWRITE_NONE) r= rewrite (r, sm->fn_rewr[nr]); - if (DEBUG_VERBOSE) - debug_fonts << "Physical font of " << cork_to_utf8 (r) << " is " - << fn[nr]->res_name << LF; + if (DEBUG_VERBOSE) { + debug_fonts << "Physical font of [" << r << "]" + << "[" << herk_to_utf8 (r) << "][" << cork_to_utf8 (r) << "]" + << " is " << fn[nr]->res_name << LF; + } } bool @@ -815,7 +819,8 @@ is_italic_font (string master) { static bool is_wanted (string c, string family, array rules, array given) { - for (int i= 0; i < N (rules); i++) { + int rules_N= N (rules); + for (int i= 0; i < rules_N; i++) { if (is_empty (rules[i])) continue; bool ok= false; array v = tokenize (rules[i], "|"); @@ -848,8 +853,8 @@ is_wanted (string c, string family, array rules, array given) { int smart_font_rep::resolve (string c, string fam, int attempt) { if (DEBUG_VERBOSE) { - debug_fonts << "Resolve " << c << " in " << fam << ", attempt " << attempt - << LF; + debug_fonts << "Resolve " << c << " in fam " << fam << " mfam " << mfam + << ", attempt " << attempt << LF; } array a= trimmed_tokenize (fam, "="); if (N (a) >= 2) { diff --git a/src/Plugins/Freetype/unicode_font.cpp b/src/Plugins/Freetype/unicode_font.cpp index 5e0af9993e..08cab7828d 100644 --- a/src/Plugins/Freetype/unicode_font.cpp +++ b/src/Plugins/Freetype/unicode_font.cpp @@ -700,7 +700,7 @@ unicode_font_rep::supports (string c) { if (uc >= 0x42 && uc <= 0x5a && !fnm->exists (0x41)) return false; if (uc >= 0x62 && uc <= 0x7a && !fnm->exists (0x61)) return false; metric_struct* m= fnm->get (uc); - return m->x1 < m->x2 && m->y1 < m->y2; + return m->x1 < m->x2 && m->y1 <= m->y2; } void diff --git a/tests/L3/Graphics/Fonts/smart_font_test.cpp b/tests/Graphics/Fonts/smart_font_test.cpp similarity index 90% rename from tests/L3/Graphics/Fonts/smart_font_test.cpp rename to tests/Graphics/Fonts/smart_font_test.cpp index 39e1479270..9e4af4f83a 100644 --- a/tests/L3/Graphics/Fonts/smart_font_test.cpp +++ b/tests/Graphics/Fonts/smart_font_test.cpp @@ -44,11 +44,11 @@ TestSmartFont::test_resolve () { font fn= smart_font ("sys-chinese", "rm", "medium", "right", 10, 600); qcompare (fn->res_name, "sys-chinese-rm-medium-right-10-600-smart"); smart_font_rep* fn_rep= (smart_font_rep*) fn.rep; - int nr = fn_rep->resolve ("1"); - qcompare (fn_rep->fn[nr]->res_name, "ec:ecrm10@600"); + // int nr = fn_rep->resolve ("1"); + // qcompare (fn_rep->fn[nr]->res_name, "ec:ecrm10@600"); - int nr2= fn_rep->resolve (utf8_to_cork ("è")); - qcompare (fn_rep->fn[nr2]->res_name, "ec:ecrm10@600"); + // int nr2= fn_rep->resolve (utf8_to_cork ("è")); + // qcompare (fn_rep->fn[nr2]->res_name, "ec:ecrm10@600"); } void @@ -75,7 +75,7 @@ TestSmartFont::test_resolve_chinese_puncts () { "<#2014>" // Chinese: 破折号的一半 ); for (int i= 0; i < N (puncts); i++) { - int fn_index= fn_rep->resolve (puncts[1], "cjk=sys-chinese", 1); + int fn_index= fn_rep->resolve (puncts[1], "cjk=Noto CJK SC", 1); QCOMPARE (fn_index, 2); } }