1+ from __future__ import annotations
2+
13from typing import Any
24
3- import polars as pl
5+ from rtflite import RTFDocument
46
57from ..attributes import BroadcastValue
6- from .base import EncodingStrategy
78from ..pagination .processor import PageFeatureProcessor
89from ..pagination .strategies import PageContext , PaginationContext , StrategyRegistry
910from ..pagination .strategies .defaults import DefaultPaginationStrategy
1516from ..services .figure_service import RTFFigureService
1617from ..services .grouping_service import grouping_service
1718from ..type_guards import is_single_body
19+ from .base import EncodingStrategy
1820from .renderer import PageRenderer
1921
2022
@@ -40,7 +42,7 @@ def encode(self, document: Any) -> str:
4042 # 1. Figure-only handling
4143 if document .df is None :
4244 # Reuse the logic from previous implementation, adapted slightly
43- # For now, we can't easily unify figure-only documents into the same pipeline
45+ # Unifying figure-only documents into one pipeline is not straightforward.
4446 # without a "FigurePaginationStrategy".
4547 # So we defer to a helper method similar to the old one.
4648 return self ._encode_figure_only (document )
@@ -112,7 +114,7 @@ def encode(self, document: Any) -> str:
112114
113115 # Handle case where no pages are generated (e.g. empty dataframe)
114116 if not pages :
115- # Create a single empty page to ensure document structure (title, etc.) is rendered
117+ # Create empty page to ensure document structure (title, etc.) is rendered.
116118 # We use processed_df which might be empty but has correct schema
117119 pages = [
118120 PageContext (
@@ -127,7 +129,7 @@ def encode(self, document: Any) -> str:
127129 ]
128130
129131 # Post-pagination fixup: Replace data with processed data (sliced correctly)
130- # The strategy used original_df for calculation , but we want to render processed_df
132+ # Strategy used original_df, but we render processed_df.
131133 # (which has removed columns).
132134 if is_single_body (document .rtf_body ):
133135 self ._apply_data_post_processing (pages , processed_df , document .rtf_body )
@@ -205,13 +207,14 @@ def _apply_data_post_processing(self, pages, processed_df, rtf_body):
205207 p .data = restored .slice (curr , rows )
206208 curr += rows
207209
208- def _encode_figure_only (self , document ):
210+ def _encode_figure_only (self , document : RTFDocument ):
209211 # (Legacy support for figure only)
210212 # For brevity, I will rely on the existing FigureService logic if possible
211213 # or just reproduce the simple loop.
212- # ... (Implementation omitted for brevity, would match PaginatedStrategy._encode_figure_only_document_with_pagination)
214+ # Matches PaginatedStrategy._encode_figure_only_document_with_pagination.
213215 # Since the user wants a WORKING system, I must implement it.
214216 from copy import deepcopy
217+
215218 from ..figure import rtf_read_figure
216219
217220 if not document .rtf_figure or not document .rtf_figure .figures :
@@ -318,7 +321,7 @@ def _encode_figure_only(self, document):
318321 parts .append ("\n \n }" )
319322 return "" .join ([p for p in parts if p ])
320323
321- def _encode_multi_section (self , document : " RTFDocument" ) -> str :
324+ def _encode_multi_section (self , document : RTFDocument ) -> str :
322325 """Encode a multi-section document where sections are concatenated row by row.
323326
324327 Args:
@@ -329,7 +332,6 @@ def _encode_multi_section(self, document: "RTFDocument") -> str:
329332 """
330333 from copy import deepcopy
331334
332- from ..attributes import BroadcastValue
333335 from ..input import RTFColumnHeader
334336 from ..type_guards import (
335337 is_flat_header_list ,
0 commit comments