Skip to content

Commit 99f6d0c

Browse files
authored
feat(pdf): adjust page margins in no-gutter mode (#163)
enhancement Align generated PDF no-gutter horizontal content margins with Swift-DocC-Render's full-width container padding instead of using paper-size-specific LaTeX margins.
1 parent 7e25075 commit 99f6d0c

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3838
- Align generated PDF inline image spacing with DocC content-node spacing and surrounding block-state handling.
3939
- Improve handling of special characters in generated PDF code blocks and inline text with PUA escapes.
4040
- Adjust the generated PDF LaTeX template geometry so guttered body content aligns more closely with header and footer text at the outer page edge.
41+
- Align generated PDF no-gutter horizontal content margins with Swift-DocC-Render's full-width container padding instead of using paper-size-specific LaTeX margins.
4142

4243
### Fixed
4344
- Fix an issue where the header text in the generated PDF document could be misaligned between odd and even pages.

src/swift_book_pdf/pdf/latex/preamble/geometry.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,43 @@
1515
"""LaTeX page geometry helpers."""
1616

1717
from swift_book_pdf.pdf.config import PaperSize
18+
from swift_book_pdf.pdf.latex.styling.typography import get_css_dimension
1819

1920

20-
def get_geometry_opts(paper_size: PaperSize, gutter: bool = True) -> str:
21+
def get_geometry_opts(
22+
paper_size: PaperSize,
23+
gutter: bool = True,
24+
body_font_size: float | None = None,
25+
) -> str:
2126
"""Return LaTeX geometry options for the requested page layout.
2227
2328
Args:
2429
paper_size: Output paper size.
2530
gutter: Whether to reserve extra inner margin for book binding.
31+
body_font_size: Base paragraph font size in PDF points.
2632
2733
Returns:
2834
Comma-separated geometry package options.
2935
"""
36+
if gutter:
37+
layout_margins = {
38+
PaperSize.A4: "inner=1.67in,outer=0.75in",
39+
PaperSize.LETTER: "inner=1.9in,outer=0.75in",
40+
PaperSize.LEGAL: "inner=1.9in,outer=0.75in",
41+
}[paper_size]
42+
else:
43+
if body_font_size is None:
44+
raise ValueError(
45+
"body_font_size is required for no-gutter geometry"
46+
)
47+
no_gutter_hmargin = get_css_dimension(
48+
"documentation_layout_full_width_container_padding_inline",
49+
body_font_size,
50+
)
51+
layout_margins = f"hmargin={no_gutter_hmargin}"
52+
3053
return {
31-
PaperSize.A4: f"a4paper,{'inner=1.67in,outer=0.75in' if gutter else 'hmargin=1.285in'}",
32-
PaperSize.LETTER: f"letterpaper,{'inner=1.9in,outer=0.75in' if gutter else 'hmargin=1.4in'}",
33-
PaperSize.LEGAL: f"legalpaper,{'inner=1.9in,outer=0.75in' if gutter else 'hmargin=1.4in'}",
54+
PaperSize.A4: f"a4paper,{layout_margins}",
55+
PaperSize.LETTER: f"letterpaper,{layout_margins}",
56+
PaperSize.LEGAL: f"legalpaper,{layout_margins}",
3457
}[paper_size]

src/swift_book_pdf/pdf/latex/preamble/template.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def build_preamble_substitutions(
9393
"geometry_opts": get_geometry_opts(
9494
config.doc_config.paper_size,
9595
config.doc_config.gutter,
96+
config.doc_config.font_size,
9697
),
9798
"fancyhead_fancyfoot_hero": header_footer_hero,
9899
"main_font": font_config.main_font,

src/swift_book_pdf/pdf/latex/styling/typography.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"article_hero_intro_line_height": "29px",
4141
"article_hero_padding_top": "30px",
4242
"article_hero_padding_bottom": "30px",
43+
"documentation_layout_full_width_container_padding_inline": "80px",
4344
"documentation_topic_title_margin_bottom": "12px",
4445
"documentation_topic_content_table_title_font_size": "32px",
4546
"documentation_topic_content_table_title_line_height": "36px",

0 commit comments

Comments
 (0)