@@ -552,7 +552,9 @@ def put_char_vertical(font_size: int, cdpt: str, pen_l: Tuple[int, int], canvas_
552552 if border_size > 0 :
553553 glyph_border = get_char_border (cdpt , font_size , 1 )
554554 stroker = freetype .Stroker ()
555- stroke_radius = 64 * max (int (0.07 * font_size ), 1 )
555+ # Get stroke width from config, default to 0.07 if not specified
556+ stroke_ratio = config .render .stroke_width if (config and hasattr (config .render , 'stroke_width' )) else 0.07
557+ stroke_radius = 64 * max (int (stroke_ratio * font_size ), 1 )
556558 stroker .set (stroke_radius , freetype .FT_STROKER_LINEJOIN_ROUND , freetype .FT_STROKER_LINECAP_ROUND , 0 )
557559 glyph_border .stroke (stroker , destroy = True )
558560 blyph = glyph_border .to_bitmap (freetype .FT_RENDER_MODE_NORMAL , freetype .Vector (0 , 0 ), True )
@@ -603,17 +605,25 @@ def put_text_vertical(font_size: int, text: str, h: int, alignment: str, fg: Tup
603605 if not text :
604606 return
605607
606- bg_size = int (max (font_size * 0.07 , 1 )) if bg is not None else 0
608+ # Get stroke width from config, default to 0.07 if not specified
609+ stroke_ratio = config .render .stroke_width if (config and hasattr (config .render , 'stroke_width' )) else 0.07
610+ bg_size = int (max (font_size * stroke_ratio , 1 )) if bg is not None else 0
607611 spacing_x = int (font_size * (line_spacing or 0.2 ))
608612
609613 # Conditional wrapping logic based on disable_auto_wrap and region_count
610614 effective_max_height = h
611615 if config and config .render .disable_auto_wrap :
612616 # 当AI断句开启时,使用无限高度,让文本按AI断句标记换行
613617 effective_max_height = 99999
618+ logger .debug (f"[VERTICAL DEBUG] AI断句开启,effective_max_height=99999, region_count={ region_count } " )
614619 elif config and config .render .layout_mode == 'smart_scaling' :
615620 if region_count <= 1 :
616621 effective_max_height = 99999
622+ logger .debug (f"[VERTICAL DEBUG] Smart scaling单区域,effective_max_height=99999, region_count={ region_count } " )
623+ else :
624+ logger .debug (f"[VERTICAL DEBUG] Smart scaling多区域,effective_max_height={ h } , region_count={ region_count } " )
625+ else :
626+ logger .debug (f"[VERTICAL DEBUG] 默认模式,effective_max_height={ h } , region_count={ region_count } " )
617627
618628 # Use original font size for line breaking calculation
619629 line_text_list , line_height_list = calc_vertical (font_size , text , effective_max_height , config = config )
@@ -665,7 +675,7 @@ def put_text_vertical(font_size: int, text: str, h: int, alignment: str, fg: Tup
665675 for char_h in content :
666676 if char_h == '!' : char_h = '!'
667677 elif char_h == '?' : char_h = '?'
668- offset_x = put_char_horizontal (h_font_size , char_h , pen_h , temp_canvas_text , temp_canvas_border , border_size = bg_size )
678+ offset_x = put_char_horizontal (h_font_size , char_h , pen_h , temp_canvas_text , temp_canvas_border , border_size = bg_size , config = config )
669679 pen_h [0 ] += offset_x
670680
671681 combined_temp = cv2 .add (temp_canvas_text , temp_canvas_border )
@@ -1095,7 +1105,7 @@ def get_present_syllables(line_idx, word_pos):
10951105
10961106 return line_text_list , line_width_list
10971107
1098- def put_char_horizontal (font_size : int , cdpt : str , pen_l : Tuple [int , int ], canvas_text : np .ndarray , canvas_border : np .ndarray , border_size : int ):
1108+ def put_char_horizontal (font_size : int , cdpt : str , pen_l : Tuple [int , int ], canvas_text : np .ndarray , canvas_border : np .ndarray , border_size : int , config = None ):
10991109 if cdpt == '_' :
11001110 # For the placeholder, just advance the pen and do nothing else.
11011111 return get_char_offset_x (font_size , '_' )
@@ -1138,7 +1148,9 @@ def put_char_horizontal(font_size: int, cdpt: str, pen_l: Tuple[int, int], canva
11381148 if border_size > 0 :
11391149 glyph_border = get_char_border (cdpt , font_size , 0 )
11401150 stroker = freetype .Stroker ()
1141- stroke_radius = 64 * max (int (0.07 * font_size ), 1 )
1151+ # Get stroke width from config, default to 0.07 if not specified
1152+ stroke_ratio = config .render .stroke_width if (config and hasattr (config .render , 'stroke_width' )) else 0.07
1153+ stroke_radius = 64 * max (int (stroke_ratio * font_size ), 1 )
11421154 stroker .set (stroke_radius ,
11431155 freetype .FT_STROKER_LINEJOIN_ROUND ,
11441156 freetype .FT_STROKER_LINECAP_ROUND ,
@@ -1221,6 +1233,7 @@ def put_text_horizontal(font_size: int, text: str, width: int, height: int, alig
12211233 text = re .sub (r'\s*(\[BR\]|<br>|【BR】)\s*' , '\n ' , text , flags = re .IGNORECASE )
12221234 # 使用无限宽度,让文本完全按照AI断句标记换行
12231235 width = 99999
1236+ logger .debug (f"[HORIZONTAL DEBUG] AI断句开启,width=99999, region_count={ region_count } " )
12241237 elif layout_mode == 'smart_scaling' :
12251238 # In smart_scaling mode, wrapping is conditional.
12261239 # It wraps only if manual line breaks ([BR] or \n) are present.
@@ -1231,8 +1244,15 @@ def put_text_horizontal(font_size: int, text: str, width: int, height: int, alig
12311244 # No manual breaks found, so disable wrapping by setting a large width.
12321245 if region_count <= 1 :
12331246 width = 99999
1247+ logger .debug (f"[HORIZONTAL DEBUG] Smart scaling单区域无换行符,width=99999, region_count={ region_count } " )
1248+ else :
1249+ logger .debug (f"[HORIZONTAL DEBUG] Smart scaling多区域无换行符,width={ width } , region_count={ region_count } " )
1250+ else :
1251+ logger .debug (f"[HORIZONTAL DEBUG] Smart scaling有换行符,width={ width } , region_count={ region_count } , line_count={ text .count (chr (10 ))+ 1 } " )
12341252
1235- bg_size = int (max (font_size * 0.07 , 1 )) if bg is not None else 0
1253+ # Get stroke width from config, default to 0.07 if not specified
1254+ stroke_ratio = config .render .stroke_width if (config and hasattr (config .render , 'stroke_width' )) else 0.07
1255+ bg_size = int (max (font_size * stroke_ratio , 1 )) if bg is not None else 0
12361256 spacing_y = int (font_size * (line_spacing or 0.01 ))
12371257
12381258 # ✅ DEBUG: 输出渲染参数
@@ -1286,7 +1306,7 @@ def put_text_horizontal(font_size: int, text: str, width: int, height: int, alig
12861306 glyph = get_char_glyph (cdpt , font_size , 0 )
12871307 offset_x = glyph .metrics .horiAdvance >> 6
12881308 pen_line [0 ] -= offset_x
1289- offset_x = put_char_horizontal (font_size , c , pen_line , canvas_text , canvas_border , border_size = bg_size )
1309+ offset_x = put_char_horizontal (font_size , c , pen_line , canvas_text , canvas_border , border_size = bg_size , config = config )
12901310 if not reversed_direction :
12911311 pen_line [0 ] += offset_x
12921312 pen_orig [1 ] += spacing_y + font_size
0 commit comments