@@ -95,12 +95,7 @@ text_box_rep::text_box_rep (path ip, int pos2, string s, font fn2, pencil p2,
9595 : box_rep (ip), pos (pos2), str (s), fn (fn2), pen (p2), xk (xk2),
9696 bg_color (bg) {
9797
98- // 调试日志:检查字符串内容
99- bool all_spaces = is_all_spaces (s);
100- if (all_spaces) {
101- cout << " DEBUG text_box_rep: string='" << s << " ', length=" << N (s)
102- << " , all spaces\n " ;
103- }
98+ bool all_spaces= is_all_spaces (s);
10499
105100 metric ex;
106101 fn->get_extents (str, ex);
@@ -114,27 +109,15 @@ text_box_rep::text_box_rep (path ip, int pos2, string s, font fn2, pencil p2,
114109 y4= ex->y4 ;
115110
116111 // 特殊处理:如果字符串全部由空格组成,手动计算宽度
117- if (all_spaces && N (s) > 0 ) {
112+ if (all_spaces && N (s) > 0 ) {
118113 // 获取单个空格的宽度
119114 metric space_ex;
120115 fn->get_extents (" " , space_ex);
121- SI single_space_width = space_ex->x2 - space_ex->x1 ;
116+ SI single_space_width= space_ex->x2 - space_ex->x1 ;
122117
123118 // 计算总宽度
124- SI total_width = single_space_width * N (s);
125- x2 = x1 + total_width;
126-
127- cout << " DEBUG text_box_rep: all spaces string, N(s)=" << N (s)
128- << " , single_space_width=" << single_space_width
129- << " , total_width=" << total_width
130- << " , adjusted x2=" << x2 << " \n " ;
131- }
132-
133- // 调试日志:显示尺寸信息
134- if (all_spaces) {
135- cout << " DEBUG text_box_rep: extents - x1=" << x1 << " , x2=" << x2
136- << " , width=" << (x2 - x1) << " , y1=" << y1 << " , y2=" << y2
137- << " , height=" << (y2 - y1) << " \n " ;
119+ SI total_width= single_space_width * N (s);
120+ x2 = x1 + total_width;
138121 }
139122
140123 // 特殊处理:对于全空格字符串,确保有最小高度以便背景色可见
@@ -145,27 +128,25 @@ text_box_rep::text_box_rep (path ip, int pos2, string s, font fn2, pencil p2,
145128
146129 if (m_ex->y1 != m_ex->y2 ) {
147130 // 如果"M"有有效的高度,使用它的y1和y2
148- y1 = m_ex->y1 ;
149- y2 = m_ex->y2 ;
150- cout << " DEBUG text_box_rep: using 'M' height, y1=" << y1
151- << " , y2=" << y2 << " , height=" << (y2 - y1) << " \n " ;
152- } else {
131+ y1= m_ex->y1 ;
132+ y2= m_ex->y2 ;
133+ }
134+ else {
153135 // 如果"M"的高度也无效,使用字体的上升和下降值
154136 SI font_ascender = fn->y1 ;
155- SI font_descender = fn->y2 ;
137+ SI font_descender= fn->y2 ;
156138
157139 if (font_ascender == 0 && font_descender == 0 ) {
158140 // 如果字体没有提供上升/下降值,使用默认比例
159- SI font_height = fn->yx ;
160- y1 = -font_height / 4 ; // 基线以下1/4高度
161- y2 = font_height * 3 / 4 ; // 基线以上3/4高度
162- } else {
141+ SI font_height= fn->yx ;
142+ y1 = -font_height / 4 ; // 基线以下1/4高度
143+ y2 = font_height * 3 / 4 ; // 基线以上3/4高度
144+ }
145+ else {
163146 // 使用字体的实际上升和下降值
164- y1 = font_descender;
165- y2 = font_ascender;
147+ y1= font_descender;
148+ y2= font_ascender;
166149 }
167- cout << " DEBUG text_box_rep: using font metrics, y1=" << y1
168- << " , y2=" << y2 << " , height=" << (y2 - y1) << " \n " ;
169150 }
170151 }
171152
0 commit comments