Skip to content

Commit ca8faca

Browse files
authored
[204_24] 改进bg-color属性相关代码,marked仍旧使用表格实现 (#2344)
1 parent b622daf commit ca8faca

File tree

5 files changed

+41
-71
lines changed

5 files changed

+41
-71
lines changed

TeXmacs/packages/standard/std-markup.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,9 @@
476476

477477
<assign|marked-color|#ffe47f>
478478

479-
<assign|marked|<macro|body|<with|bg-color|<value|marked-color>|<arg|body>>>>
479+
<assign|marked-padding|0.2fn>
480+
481+
<assign|marked|<macro|body|<quasi|<style-with|src-compact|none|<datoms|<macro|x|<style-with|src-compact|none|<tabular|<tformat|<cwith|1|1|1|1|cell-background|<unquote|<value|marked-color>>>|<cwith|1|1|1|1|cell-lsep|<unquote|<value|marked-padding>>>|<cwith|1|1|1|1|cell-rsep|<unquote|<value|marked-padding>>>|<cwith|1|1|1|1|cell-bsep|<unquote|<value|marked-padding>>>|<cwith|1|1|1|1|cell-tsep|<unquote|<value|marked-padding>>>|<cwith|1|-1|1|-1|cell-lborder|0ln>|<cwith|1|-1|1|-1|cell-rborder|0ln>|<cwith|1|-1|1|-1|cell-bborder|0ln>|<cwith|1|-1|1|-1|cell-tborder|0ln>|<twith|table-width|>|<twith|table-valign|B>|<twith|table-hmode|auto>|<twith|table-block|no>|<table|<row|<cell|<arg|x>>>>>>>>|<arg|body>>>>>>
480482

481483
<drd-props|marked|with-like|yes|arity|1|accessible|all>
482484

TeXmacs/tests/tmu/204_24.tmu

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,67 +7,56 @@
77

88
<section|文本>
99

10-
普通文本,无背景色
10+
采用bg-color属性调整背景色。
1111

12-
\;
12+
普通文本,无背景色
1313

1414
<with|bg-color|yellow|黄色背景的文本>
1515

16-
\;
17-
1816
<with|bg-color|light gray|浅灰色背景的文本>
1917

20-
\;
21-
2218
<with|bg-color|#e0e0ff|#e0e0ff 颜色背景的文本>
2319

24-
\;
25-
2620
<with|bg-color|#ffcccc|<with|color|red|红色文字配粉色背景>>
2721

28-
\;
29-
3022
<with|bg-color|#ccffcc|<with|color|dark green|深绿色文字配浅绿色背景>>
3123

3224
<\with|bg-color|#ffffcc>
3325
多行文本块带有浅黄色背景。 这是对多行背景色支持的测试。 背景应该覆盖整个文本块。我们需要提供更多文字,才能覆盖多行。
3426
</with>
3527

36-
<\with|bg-color|#ffffcc>
28+
<\with|bg-color|#ffffcc99>
3729
多行文本块带有浅黄色背景。 这是对多行背景色支持的测试。\
3830

3931
背景应该覆盖整个文本块。
4032
</with>
4133

42-
单个空格:<marked| >
43-
44-
两个空格:<marked| \ >
45-
46-
空格在字符左边:<marked| abc>
47-
48-
空格在字符右边:<marked|abc >\
49-
5034
<section|数学模式>
5135

52-
\;
36+
采用marked标记调整背景色,实际上是表格。
5337

5438
数学公式背景测试:
5539

5640
<\with|bg-color|light blue>
5741
<\equation*>
58-
E=mc<rsup|2>
42+
<with|marked-color|pastel cyan|<marked|E=mc<rsup|2>>>
5943
</equation*>
6044
</with>
6145

46+
<\equation*>
47+
<marked|<big|int>x\<mathd\>x>
48+
</equation*>
49+
6250
\;
6351

64-
<with|bg-color|#ffeeee|行内数学 <with|mode|math|<frac|a|b>> 带背景>
52+
<marked|行内数学 <with|mode|math|<frac|a|b>> 带背景>
6553
</body>
6654

6755
<\initial>
6856
<\collection>
6957
<associate|page-medium|paper>
7058
<associate|page-screen-margin|false>
59+
<associate|preamble|false>
7160
</collection>
7261
</initial>
7362

devel/204_24.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
1. 打开`TeXmacs/tests/tmu/204_24.tmu`,直接观察文档的颜色是否合理
44
2. 调整文档的语言,比如换成英语,观察文档颜色是否合理
55

6+
## 2025/12/25 marked仍旧使用表格实现
7+
68
## 2025/12/25 支持bg-color属性
79
### What
810
1. marked改为使用bg-color实现

src/Typeset/Concat/concat_text.cpp

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,39 @@ get_background_color (edit_env env) {
4242
return named_color (bg_color_str, env->alpha);
4343
}
4444

45+
static inline color
46+
apply_alpha (color c, int alpha) {
47+
if (alpha == 255) return c;
48+
int r, g, b, a;
49+
get_rgb_color (c, r, g, b, a);
50+
return rgb_color (r, g, b, alpha);
51+
}
52+
4553
/******************************************************************************
46-
* Typesetting strings
54+
* Unified text box builder
4755
******************************************************************************/
48-
49-
void
50-
concater_rep::typeset_substring (string s, path ip, int pos) {
56+
static inline box
57+
build_text_box (path ip, int pos, string s, edit_env env) {
5158
if (has_background_color (env)) {
52-
// 有背景色设置,使用 typeset_background_substring
53-
typeset_background_substring (s, ip, pos, get_background_color_str (env));
59+
color bg_color= get_background_color (env);
60+
return text_box_with_bg (ip, pos, s, env->fn, env->pen, bg_color,
61+
xkerning ());
5462
}
5563
else {
56-
// 没有背景色设置,使用普通文本框
57-
box b= text_box (ip, pos, s, env->fn, env->pen);
58-
a << line_item (STRING_ITEM, OP_TEXT, b, HYPH_INVALID, env->lan);
64+
return text_box (ip, pos, s, env->fn, env->pen);
5965
}
6066
}
6167

68+
/******************************************************************************
69+
* Typesetting strings
70+
******************************************************************************/
71+
72+
void
73+
concater_rep::typeset_substring (string s, path ip, int pos) {
74+
box b= build_text_box (ip, pos, s, env);
75+
a << line_item (STRING_ITEM, OP_TEXT, b, HYPH_INVALID, env->lan);
76+
}
77+
6278
void
6379
concater_rep::typeset_math_substring (string s, path ip, int pos, int otype) {
6480
box b= text_box (ip, pos, s, env->fn, env->pen);
@@ -87,14 +103,6 @@ concater_rep::typeset_math_macro (string s, tree_label m, path ip, int p1,
87103
marker (descend (ip, p2));
88104
}
89105

90-
static inline color
91-
apply_alpha (color c, int alpha) {
92-
if (alpha == 255) return c;
93-
int r, g, b, a;
94-
get_rgb_color (c, r, g, b, a);
95-
return rgb_color (r, g, b, alpha);
96-
}
97-
98106
void
99107
concater_rep::typeset_colored_substring (string s, path ip, int pos,
100108
string col) {
@@ -110,36 +118,6 @@ concater_rep::typeset_colored_substring (string s, path ip, int pos,
110118
a << line_item (STRING_ITEM, OP_TEXT, b, HYPH_INVALID, env->lan);
111119
}
112120

113-
void
114-
concater_rep::typeset_background_substring (string s, path ip, int pos,
115-
string bg_col) {
116-
117-
// 获取背景颜色
118-
color bg_color;
119-
if (bg_col == "") {
120-
bg_color= apply_alpha (env->pen->get_color (), env->alpha);
121-
}
122-
else if (env->provides (bg_col)) {
123-
tree t= env->read (bg_col);
124-
if (t == "") {
125-
bg_color= apply_alpha (env->pen->get_color (), env->alpha);
126-
}
127-
else {
128-
string t_str= as_string (t);
129-
bg_color = named_color (t_str, env->alpha);
130-
}
131-
}
132-
else {
133-
bg_color= named_color (bg_col, env->alpha);
134-
}
135-
136-
// 创建带有背景色的文本框
137-
box b=
138-
text_box_with_bg (ip, pos, s, env->fn, env->pen, bg_color, xkerning ());
139-
140-
a << line_item (STRING_ITEM, OP_TEXT, b, HYPH_INVALID, env->lan);
141-
}
142-
143121
#define PRINT_SPACE(spc_type) \
144122
if (spc_type != SPC_NONE) print (spc_tab[spc_type]);
145123

src/Typeset/Concat/concater.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class concater_rep {
4747
void typeset_math_macro (string s, tree_label m, path ip, int p1, int p2,
4848
int ot);
4949
void typeset_colored_substring (string s, path ip, int pos, string col);
50-
void typeset_background_substring (string s, path ip, int pos, string bg_col);
5150
void typeset_text_string (tree t, path ip, int start, int end);
5251
void typeset_math_string (tree t, path ip, int start, int end);
5352
void typeset_prog_string (tree t, path ip, int start, int end);

0 commit comments

Comments
 (0)