WIP: baseline on fix/retry-failure-root-causes
This commit is contained in:
+25
-3
@@ -181,6 +181,28 @@ def split_band_into_windows(band: BandInfo, max_chars: int = 4000) -> list[str]:
|
||||
|
||||
# ── 重组 ──────────────────────────────────────────────────────────
|
||||
|
||||
def _recalc_band_height(band_xml: str, margin: int = 20) -> str:
|
||||
"""根据波段内所有子元素的 y + height 重新计算波段 height。"""
|
||||
max_bottom = 0
|
||||
for m in re.finditer(r'<reportElement\b([^>]*)/>', band_xml):
|
||||
attrs = m.group(1)
|
||||
ym = re.search(r'\sy\s*=\s*"(\d+)"', attrs)
|
||||
hm = re.search(r'\sheight\s*=\s*"(\d+)"', attrs)
|
||||
if ym and hm:
|
||||
bottom = int(ym.group(1)) + int(hm.group(1))
|
||||
if bottom > max_bottom:
|
||||
max_bottom = bottom
|
||||
if max_bottom == 0:
|
||||
return band_xml
|
||||
new_height = max_bottom + margin
|
||||
return re.sub(
|
||||
r'(<band\b[^>]*\sheight\s*=\s*)"(\d+)"',
|
||||
rf'\g<1>"{new_height}"',
|
||||
band_xml,
|
||||
count=1,
|
||||
)
|
||||
|
||||
|
||||
def reassemble_band_windows(modified_windows: list[str]) -> str:
|
||||
"""将多个窗口的修改结果重新合并为一个 band XML。
|
||||
|
||||
@@ -188,12 +210,12 @@ def reassemble_band_windows(modified_windows: list[str]) -> str:
|
||||
中间拼接所有窗口内部的元素内容。
|
||||
"""
|
||||
if len(modified_windows) == 1:
|
||||
return modified_windows[0]
|
||||
return _recalc_band_height(modified_windows[0])
|
||||
|
||||
first = modified_windows[0]
|
||||
band_open_end = first.find(">")
|
||||
if band_open_end == -1:
|
||||
return "\n".join(modified_windows)
|
||||
return _recalc_band_height("\n".join(modified_windows))
|
||||
band_open = first[:band_open_end + 1]
|
||||
|
||||
last = modified_windows[-1]
|
||||
@@ -205,7 +227,7 @@ def reassemble_band_windows(modified_windows: list[str]) -> str:
|
||||
if inner:
|
||||
inner_parts.append(inner)
|
||||
|
||||
return band_open + "\n" + "\n".join(inner_parts) + "\n" + band_close
|
||||
return _recalc_band_height(band_open + "\n" + "\n".join(inner_parts) + "\n" + band_close)
|
||||
|
||||
|
||||
def reassemble_jrxml(parts: JRXMLParts, modified_bands: dict[str, str]) -> str:
|
||||
|
||||
Reference in New Issue
Block a user