Skip to content

Commit 8c5420d

Browse files
authored
[0103] 修复文档级 par-first 导致页眉页脚缩进 (#3314)
1 parent 2c9b33e commit 8c5420d

3 files changed

Lines changed: 66 additions & 6 deletions

File tree

TeXmacs/tests/tmu/0103.tmu

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<TMU|<tuple|1.1.0|2026.2.4>>
2+
3+
<style|<tuple|generic|chinese|table-captions-above|number-europe|preview-ref>>
4+
5+
<\body>
6+
这是一个段落。这是一个段落。这是一个段落。这是一个段落。这是一个段落。这是一个段落。这是一个段落。这是一个有缩进的段落。
7+
8+
<\with|par-first|0fn>
9+
1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890
10+
</with>
11+
12+
本文档是全局缩进两个字符,第二个段落是通过格式\<rightarrow\>段落取消了缩进的,可以通过第二个段落来观察页眉是否缩进。
13+
</body>
14+
15+
<\initial>
16+
<\collection>
17+
<associate|page-even-footer|<tformat|<cwith|1|-1|1|-1|cell-halign|c>|<tformat|<twith|table-width|1par>|<twith|table-hmode|exact>|<cwith|1|1|1|1|cell-width|0.3par>|<cwith|1|1|1|1|cell-hmode|exact>|<cwith|1|1|3|3|cell-width|0.3par>|<cwith|1|1|3|3|cell-hmode|exact>|<cwith|1|1|2|2|cell-width|0.4par>|<cwith|1|1|2|2|cell-hmode|exact>|<cwith|1|1|1|1|cell-halign|l>|<cwith|1|1|3|3|cell-halign|r>|<table|<row|<cell|>|<cell|<page-the-page>>|<cell|>>>>>>
18+
<associate|page-even-header|>
19+
<associate|page-medium|paper>
20+
<associate|page-odd-footer|<tformat|<cwith|1|-1|1|-1|cell-halign|c>|<tformat|<twith|table-width|1par>|<twith|table-hmode|exact>|<cwith|1|1|1|1|cell-width|0.3par>|<cwith|1|1|1|1|cell-hmode|exact>|<cwith|1|1|3|3|cell-width|0.3par>|<cwith|1|1|3|3|cell-hmode|exact>|<cwith|1|1|2|2|cell-width|0.4par>|<cwith|1|1|2|2|cell-hmode|exact>|<cwith|1|1|1|1|cell-halign|l>|<cwith|1|1|3|3|cell-halign|r>|<table|<row|<cell|>|<cell|<page-the-page>>|<cell|>>>>>>
21+
<associate|page-odd-header|<tabular|<tformat|<cwith|1|1|1|1|cell-width|0.3par>|<cwith|1|1|1|1|cell-hmode|exact>|<cwith|1|1|3|3|cell-width|0.3par>|<cwith|1|1|3|3|cell-hmode|exact>|<cwith|1|1|2|2|cell-width|0.4par>|<cwith|1|1|2|2|cell-hmode|exact>|<cwith|1|1|1|1|cell-halign|l>|<cwith|1|1|3|3|cell-halign|r>|<cwith|1|1|2|2|cell-halign|c>|<table|<row|<cell|>|<cell|<page-the-page>>|<cell|>>>>>>
22+
<associate|page-screen-margin|false>
23+
<associate|par-first|2fn>
24+
</collection>
25+
</initial>

devel/0103.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# [0103] 修复文档级 par-first 导致页眉页脚缩进的问题
2+
3+
## 相关文档
4+
- [dddd.md](dddd.md) - 任务文档模板
5+
6+
## 任务相关的代码文件
7+
- `src/Typeset/Page/pager.cpp` - 页眉页脚排版逻辑
8+
9+
## 如何测试
10+
11+
### 手动验证
12+
1. 打开 `TeXmacs/tests/tmu/0103.tmu`
13+
2. 观察页眉是否居中
14+
3. 预期结果:页眉居中显示
15+
16+
> 注:Mogan v2026.2.4 中页眉不居中(偏右侧),当前分支已修复为居中。
17+
18+
## What
19+
20+
修复当文档的首行缩进设置为 2 个字符(内部实现为将文档级别的 `par-first` 设为 `2fn`)时,页眉和页脚也会被错误地应用段落首行缩进的问题。
21+
22+
1.`pager_rep::make_header` 中临时将 `PAR_FIRST` 设为 `0cm`
23+
2.`pager_rep::make_footer` 中临时将 `PAR_FIRST` 设为 `0cm`
24+
25+
## Why
26+
27+
`par-first`(段落首行缩进)是段落级别的排版属性。文档级别的 `par-first` 设置应当只影响正文段落,而不应影响页眉和页脚。目前 `section` 标题等已经正确处理了这一问题,但页眉和页脚在排版时直接继承了文档环境的 `PAR_FIRST` 值,导致出现不期望的缩进。
28+
29+
## How
30+
31+
`pager.cpp``make_header``make_footer` 函数中,排版页眉/页脚内容之前,使用 `env->local_begin(PAR_FIRST, "0cm")` 临时覆盖 `par-first` 值,排版完成后通过 `env->local_end(PAR_FIRST, old)` 恢复。这与函数中已有的 `PAR_COLUMNS` 临时覆盖方式一致。

src/Typeset/Page/pager.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,16 @@ pager_rep::make_header (bool empty_flag) {
240240
int current_page= N (pages) + 1 + page_offset;
241241
if (current_page <= 0) env->write (PAGE_NR, "");
242242
else env->write (PAGE_NR, as_string (current_page));
243-
tree old = env->local_begin (PAR_COLUMNS, "1");
244-
string which= (N (pages) & 1) == 0 ? PAGE_ODD_HEADER : PAGE_EVEN_HEADER;
243+
tree old_col = env->local_begin (PAR_COLUMNS, "1");
244+
tree old_first= env->local_begin (PAR_FIRST, "0cm");
245+
string which = (N (pages) & 1) == 0 ? PAGE_ODD_HEADER : PAGE_EVEN_HEADER;
245246
if (style[PAGE_THIS_HEADER] != "") which= PAGE_THIS_HEADER;
246247
tree header_tree= decode_images_in_tree (style[which]);
247248
box b = typeset_as_concat (
248249
env, attach_here (tree (PARA, header_tree), decorate ()));
249250
style (PAGE_THIS_HEADER)= "";
250-
env->local_end (PAR_COLUMNS, old);
251+
env->local_end (PAR_FIRST, old_first);
252+
env->local_end (PAR_COLUMNS, old_col);
251253
return b;
252254
}
253255

@@ -258,14 +260,16 @@ pager_rep::make_footer (bool empty_flag) {
258260
if (current_page <= 0) env->write (PAGE_NR, "");
259261
else env->write (PAGE_NR, as_string (current_page));
260262
env->write (PAGE_THE_PAGE, style[PAGE_THE_PAGE]);
261-
tree old = env->local_begin (PAR_COLUMNS, "1");
262-
string which= (N (pages) & 1) == 0 ? PAGE_ODD_FOOTER : PAGE_EVEN_FOOTER;
263+
tree old_col = env->local_begin (PAR_COLUMNS, "1");
264+
tree old_first= env->local_begin (PAR_FIRST, "0cm");
265+
string which = (N (pages) & 1) == 0 ? PAGE_ODD_FOOTER : PAGE_EVEN_FOOTER;
263266
if (style[PAGE_THIS_FOOTER] != "") which= PAGE_THIS_FOOTER;
264267
tree footer_tree= decode_images_in_tree (style[which]);
265268
box b = typeset_as_concat (
266269
env, attach_here (tree (PARA, footer_tree), decorate ()));
267270
style (PAGE_THIS_FOOTER)= "";
268-
env->local_end (PAR_COLUMNS, old);
271+
env->local_end (PAR_FIRST, old_first);
272+
env->local_end (PAR_COLUMNS, old_col);
269273
return b;
270274
}
271275

0 commit comments

Comments
 (0)