@@ -100,30 +100,38 @@ def ensure_parity(self, target_parity):
100100 return True
101101 return False
102102
103- def draw_decorations (self , doc , start_page_num , book_title , section_title ):
104- font_name = "china-ss"
103+ def draw_decorations (self , doc , start_page_num , book_title , section_title , sub_title ):
104+ font_name = "china-sr" # 使用宋体/衬线体匹配 Noto Serif
105105 for i in range (len (doc )):
106106 page = doc [i ]
107107 abs_page = start_page_num + i
108108 if abs_page in self .skip_decoration_pages :
109109 continue
110+
110111 is_odd = abs_page % 2 != 0
111112 footer_font = "helv"
112113 footer_size = 9
113114 footer_y = page .rect .height - 30
114115 footer_text = f"{ abs_page } "
116+
117+ # 页脚:始终居中
115118 page .insert_text ((page .rect .width / 2 - 5 , footer_y ), footer_text , fontsize = footer_size , fontname = footer_font , color = (0.4 , 0.4 , 0.4 ))
119+
116120 header_y = 35
117121 line_y = 45
118122 header_size = 9
119123 color = (0.5 , 0.5 , 0.5 )
124+
120125 if is_odd :
126+ # 奇数页:页眉在左上,内容为章节标题 (L1)
121127 text = section_title
128+ page .insert_text ((40 , header_y ), text , fontsize = header_size , fontname = font_name , color = color )
129+ else :
130+ # 偶数页:页眉在右上,内容为小节标题 (L2)
131+ text = sub_title
122132 tw = fitz .get_text_length (text , fontname = font_name , fontsize = header_size )
123133 page .insert_text ((page .rect .width - tw - 40 , header_y ), text , fontsize = header_size , fontname = font_name , color = color )
124- else :
125- text = book_title
126- page .insert_text ((40 , header_y ), text , fontsize = header_size , fontname = font_name , color = color )
134+
127135 page .draw_line ((40 , line_y ), (page .rect .width - 40 , line_y ), color = (0.8 , 0.8 , 0.8 ), width = 0.4 )
128136
129137 def get_english_filename (self ):
@@ -217,7 +225,7 @@ def process(self):
217225 else :
218226 self .toc_data .append ([2 , sub_title , self .page_offset + 1 ])
219227 self .toc_data .extend (chapter_headings )
220- self .draw_decorations (doc , self .page_offset + 1 , book_title , sec_title )
228+ self .draw_decorations (doc , self .page_offset + 1 , book_title , sec_title , sub_title )
221229 self .final_doc .insert_pdf (doc )
222230 self .page_offset += len (doc )
223231 doc .close ()
0 commit comments