@@ -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+
6278void
6379concater_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-
98106void
99107concater_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
0 commit comments