Skip to content

Commit

Permalink
[69_9] Fix: CJK auto spacing should not apply for CJK puncts
Browse files Browse the repository at this point in the history
<!-- Thank you for your contribution! -->
## What
as title

## How to test your changes?
see 69_9_puncts.tmu
  • Loading branch information
da-liii authored Sep 29, 2024
1 parent e1dd9a8 commit 1f01499
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 27 deletions.
80 changes: 80 additions & 0 deletions TeXmacs/tests/tmu/69_9_punct.tmu
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<TMU|<tuple|1.0.3|1.2.9.3-rc1>>

<style|<tuple|generic|chinese>>

<\body>
达\<centerdot\>芬奇

半角逗号

标点符号,标点符号

逗号

标点符号,标点符号

标点符号中标点符号

句号

标点符号。标点符号

标点符号中标点符号

问好

标点符号?标点符号

标点符号中标点符号

冒号

标点符号:标点符号

标点符号中标点符号

破折号

标点标点符号

标点—–符号

标点—符号

标点中中符号

引号

他是一个“有趣”的人

他是一个左有趣右的人

他是一个‘有趣’的人

他是一个左有趣右的人

他是一个「有趣」的人

他是一个左有趣右的人

他是一个『有趣』的人

书名号

书名《三鲤》如何?

书名左三鲤右如何?

\;

\;

\;
</body>

<\initial>
<\collection>
<associate|page-medium|paper>
<associate|page-screen-margin|false>
</collection>
</initial>
46 changes: 33 additions & 13 deletions src/Typeset/Line/lazy_paragraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "Format/format.hpp"
#include "Line/lazy_vstream.hpp"
#include "analyze.hpp"
#include "array.hpp"
#include "converter.hpp"

#include <lolly/data/unicode.hpp>

Expand Down Expand Up @@ -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<string> puncts= array<string> ();
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); }
Expand Down Expand Up @@ -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;
Expand All @@ -289,7 +307,7 @@ lazy_paragraph_rep::cjk_auto_spacing () {
prev = -1;
now = -1;
array<int> tmp= array<int> ();
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;
Expand All @@ -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];
}

Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down
29 changes: 15 additions & 14 deletions src/Typeset/Line/lazy_paragraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@ struct lazy_paragraph_rep : public lazy_rep {
stacker_rep* sss; // the typesetted paragraph

protected:
array<box> items; // the boxes on the line in order
array<SI> items_sp; // the final spaces between boxes in lines
array<int> items_left; // the index of the previous non-empty text box item
array<int> items_right; // the index of the next non-empty text box item
array<bool> items_box; // is non-empty text box item: true / false
array<bool> items_cjk_text; // is non-empty text box item: true / false
array<space> spcs; // the spacing between the boxes of items
array<lazy> fl; // floating insertions
array<line_item> notes; // line notes
array<tab> tabs; // tabulations
array<tree> 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<box> items; // the boxes on the line in order
array<SI> items_sp; // the final spaces between boxes in lines
array<int> items_left; // the index of the previous non-empty text box item
array<int> items_right; // the index of the next non-empty text box item
array<bool> items_box; // is non-empty text box item: true / false
array<bool> items_cjk_text; // is non-empty text box item: true / false
hashset<string> cjk_puncts;
array<space> spcs; // the spacing between the boxes of items
array<lazy> fl; // floating insertions
array<line_item> notes; // line notes
array<tab> tabs; // tabulations
array<tree> 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
Expand Down

0 comments on commit 1f01499

Please sign in to comment.