@@ -163,6 +163,12 @@ def __init__(
163
163
self .l_margin = l_margin
164
164
self .b_margin = b_margin
165
165
166
+ def __repr__ (self ):
167
+ return (
168
+ super ().__repr__ ()[:- 1 ]
169
+ + f", t_margin={ self .t_margin } , l_margin={ self .l_margin } , b_margin={ self .b_margin } )"
170
+ )
171
+
166
172
167
173
class ToCPlaceholder (NamedTuple ):
168
174
render_function : Callable
@@ -1918,7 +1924,7 @@ def set_font(self, family=None, style="", size=0):
1918
1924
)
1919
1925
style = ""
1920
1926
1921
- if size == 0 :
1927
+ if not size :
1922
1928
size = self .font_size_pt
1923
1929
1924
1930
# Test if font is already selected
@@ -4863,23 +4869,33 @@ def start_section(self, name, level=0, strict=True):
4863
4869
dest = DestinationXYZ (self .page , top = self .h_pt - self .y * self .k )
4864
4870
outline_struct_elem = None
4865
4871
if self .section_title_styles :
4872
+ title_style = self .section_title_styles [level ]
4866
4873
# We first check if adding this multi-cell will trigger a page break:
4867
- with self .offset_rendering () as pdf :
4868
- # pylint: disable=protected-access
4869
- with pdf ._use_title_style (pdf .section_title_styles [level ]):
4870
- pdf .multi_cell (
4871
- w = pdf .epw ,
4872
- h = pdf .font_size ,
4873
- text = name ,
4874
- new_x = XPos .LMARGIN ,
4875
- new_y = YPos .NEXT ,
4876
- )
4877
- if pdf .page_break_triggered :
4874
+ if title_style .size_pt is not None :
4875
+ prev_font_size_pt = self .font_size_pt
4876
+ self .font_size_pt = title_style .size_pt
4877
+ page_break_triggered = self .multi_cell (
4878
+ w = self .epw ,
4879
+ h = self .font_size ,
4880
+ text = name ,
4881
+ new_x = XPos .LMARGIN ,
4882
+ new_y = YPos .NEXT ,
4883
+ dry_run = True , # => does not produce any output
4884
+ output = MethodReturnValue .PAGE_BREAK ,
4885
+ padding = Padding (
4886
+ top = title_style .t_margin or 0 ,
4887
+ left = title_style .l_margin or 0 ,
4888
+ bottom = title_style .b_margin or 0 ,
4889
+ ),
4890
+ )
4891
+ if title_style .size_pt is not None :
4892
+ self .font_size_pt = prev_font_size_pt
4893
+ if page_break_triggered :
4878
4894
# If so, we trigger a page break manually beforehand:
4879
4895
self .add_page ()
4880
4896
with self ._marked_sequence (title = name ) as struct_elem :
4881
4897
outline_struct_elem = struct_elem
4882
- with self ._use_title_style (self . section_title_styles [ level ] ):
4898
+ with self ._use_title_style (title_style ):
4883
4899
self .multi_cell (
4884
4900
w = self .epw ,
4885
4901
h = self .font_size ,
0 commit comments