diff --git a/TeXmacs/tests/tmu/69_9_punct.tmu b/TeXmacs/tests/tmu/69_9_punct.tmu new file mode 100644 index 0000000000..903dc3f01f --- /dev/null +++ b/TeXmacs/tests/tmu/69_9_punct.tmu @@ -0,0 +1,80 @@ +> + +> + +<\body> + 达\芬奇 + + 半角逗号 + + 标点符号,标点符号 + + 逗号 + + 标点符号,标点符号 + + 标点符号中标点符号 + + 句号 + + 标点符号。标点符号 + + 标点符号中标点符号 + + 问好 + + 标点符号?标点符号 + + 标点符号中标点符号 + + 冒号 + + 标点符号:标点符号 + + 标点符号中标点符号 + + 破折号 + + 标点标点符号 + + 标点—–符号 + + 标点—符号 + + 标点中中符号 + + 引号 + + 他是一个“有趣”的人 + + 他是一个左有趣右的人 + + 他是一个‘有趣’的人 + + 他是一个左有趣右的人 + + 他是一个「有趣」的人 + + 他是一个左有趣右的人 + + 他是一个『有趣』的人 + + 书名号 + + 书名《三鲤》如何? + + 书名左三鲤右如何? + + \; + + \; + + \; + + +<\initial> + <\collection> + + + + diff --git a/src/Typeset/Line/lazy_paragraph.cpp b/src/Typeset/Line/lazy_paragraph.cpp index 28097f80b7..c716ba7d30 100644 --- a/src/Typeset/Line/lazy_paragraph.cpp +++ b/src/Typeset/Line/lazy_paragraph.cpp @@ -15,6 +15,8 @@ #include "Format/format.hpp" #include "Line/lazy_vstream.hpp" #include "analyze.hpp" +#include "array.hpp" +#include "converter.hpp" #include @@ -124,6 +126,21 @@ lazy_paragraph_rep::lazy_paragraph_rep (edit_env env2, path ip) tree dec= env->read (ATOM_DECORATIONS); if (N (dec) > 0) decs << tuple ("0", dec); + + array puncts= array (); + puncts << string ("。") << string (",") << string (":") << string (";") + << string ("!") << string ("?") << string ("、") << string ("~") + << string ("』") << string ("」") << string (")") << string ("】") + << string ("》") << string ("〉"); + puncts << string ("『") << string ("「") << string ("(") << string ("【") + << string ("《") << string ("〈"); + for (string punct : puncts) { + cjk_puncts->insert (utf8_to_cork (punct)); + } + cjk_puncts->insert ("<#201D>"); // 双引号 + cjk_puncts->insert ("<#201C>"); + cjk_puncts->insert ("<#2019>"); // 单引号 + cjk_puncts->insert ("<#2018>"); } lazy_paragraph_rep::~lazy_paragraph_rep () { tm_delete (sss); } @@ -273,9 +290,10 @@ lazy_paragraph_rep::protrude (bool lf, bool rf) { void lazy_paragraph_rep::cjk_auto_spacing () { - int prev= -1; - int now = -1; - for (int i= cur_start; i < N (items); i++) { + int prev = -1; + int now = -1; + int items_N= N (items); + for (int i= cur_start; i < items_N; i++) { if (items_box[i]) { prev= now; now = i; @@ -289,7 +307,7 @@ lazy_paragraph_rep::cjk_auto_spacing () { prev = -1; now = -1; array tmp= array (); - for (int i= N (items) - 1; i >= cur_start; i--) { + for (int i= items_N - 1; i >= cur_start; i--) { if (items_box[i]) { prev= now; now = i; @@ -299,7 +317,7 @@ lazy_paragraph_rep::cjk_auto_spacing () { tmp << -1; } } - for (int i= N (tmp) - 1; i >= 0; i--) { + for (int i= items_N - 1; i >= 0; i--) { items_right << tmp[i]; } @@ -308,7 +326,7 @@ lazy_paragraph_rep::cjk_auto_spacing () { "length of items must match") bool no_cjk_flag= true; - for (int i= cur_start; i < N (items); i++) { + for (int i= cur_start; i < items_N; i++) { if (items_cjk_text[i]) { no_cjk_flag= false; break; @@ -319,13 +337,14 @@ lazy_paragraph_rep::cjk_auto_spacing () { int first, last; find_first_last_text (first, last); - for (int i= cur_start; i + 1 < N (items); i++) { + for (int i= cur_start; i + 1 < items_N; i++) { if (i != last && items_cjk_text[i] // test if the current item is a cjk text box && items_right[i] != -1 // test if the right item is not empty && is_text (a[items_right[i]]) // test if the right item is a text box - && !items_cjk_text[items_right[i]]) { // test if the right item is not a - // cjk text box + && !items_cjk_text[items_right[i]] // test if the right item is not a + // cjk text box + && !cjk_puncts->contains (a[items_right[i]]->b->get_leaf_string ())) { box b = items[i]; SI auto_space_size= b->get_leaf_font ()->spc->def * 0.2; box nb = b->right_auto_spacing (auto_space_size); @@ -334,13 +353,14 @@ lazy_paragraph_rep::cjk_auto_spacing () { } } - for (int i= cur_start + 1; i < N (items); i++) { + for (int i= cur_start + 1; i < items_N; i++) { if (i != first && items_cjk_text[i] // test if the current item is a cjk text box && items_left[i] != -1 // test if the left item is not empty - && is_text (a[items_left[i]]) // test if the left item is a text box - && !items_cjk_text[items_left[i]]) { // test if the left item is not a - // cjk text box + && is_text (a[items_left[i]]) // test if the left item is a text box + && !items_cjk_text[items_left[i]] // test if the left item is not a cjk + // text box + && !cjk_puncts->contains (a[items_left[i]]->b->get_leaf_string ())) { box b = items[i]; SI auto_space_size= b->get_leaf_font ()->spc->def * 0.2; box nb = b->left_auto_spacing (auto_space_size); diff --git a/src/Typeset/Line/lazy_paragraph.hpp b/src/Typeset/Line/lazy_paragraph.hpp index 9734adc868..6126596cd0 100644 --- a/src/Typeset/Line/lazy_paragraph.hpp +++ b/src/Typeset/Line/lazy_paragraph.hpp @@ -29,20 +29,21 @@ struct lazy_paragraph_rep : public lazy_rep { stacker_rep* sss; // the typesetted paragraph protected: - array items; // the boxes on the line in order - array items_sp; // the final spaces between boxes in lines - array items_left; // the index of the previous non-empty text box item - array items_right; // the index of the next non-empty text box item - array items_box; // is non-empty text box item: true / false - array items_cjk_text; // is non-empty text box item: true / false - array spcs; // the spacing between the boxes of items - array fl; // floating insertions - array notes; // line notes - array tabs; // tabulations - array decs; // decorations of the boxes on lines - SI cur_r; // the current right offset of the last line unit - space cur_w; // the current width of the line unit - int cur_start; // index of the start of the line unit + array items; // the boxes on the line in order + array items_sp; // the final spaces between boxes in lines + array items_left; // the index of the previous non-empty text box item + array items_right; // the index of the next non-empty text box item + array items_box; // is non-empty text box item: true / false + array items_cjk_text; // is non-empty text box item: true / false + hashset cjk_puncts; + array spcs; // the spacing between the boxes of items + array fl; // floating insertions + array notes; // line notes + array tabs; // tabulations + array decs; // decorations of the boxes on lines + SI cur_r; // the current right offset of the last line unit + space cur_w; // the current width of the line unit + int cur_start; // index of the start of the line unit string mode; // justified, left, center or right double flexibility; // threshold for switching to ragged mode