Small fix to alignement

master
Sébastien Miquel 2026-02-28 18:51:30 +01:00
parent e5140a460a
commit 5efae09664
3 changed files with 19 additions and 18 deletions

View File

@ -225,24 +225,26 @@ import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
from highlight_text import ax_text
def render_score_text(label, score, error, width_px, fontsize=18,
bg_color=(255, 255, 255, 255),
with_error=True):
# 1. Calculate Color Gradient
def color(score):
t = max(0.0, min(1.0, float(score) / 4.0))
t = t*1.5 - 0.25
t = max(0.0, min(1.0, t))
red = 200 * (1 - t)
green = 150 * t
hex_color = mcolors.to_hex((red/255, green/255, 0))
return mcolors.to_hex((red/255, green/255, 0))
def render_score_text(label, score, error, width_px, fontsize=18,
bg_color=(255, 255, 255, 255),
with_error=True):
# 1. Calculate Color Gradient
# 2. Build highlight-text String & Properties
# Wrap colored parts in < >
score_str = f"{label} ; Note : <{score}>"
hl_props = [{"color": hex_color, "fontweight": "bold"}]
score_str = f"{label} Note : <{score}>"
hl_props = [{"color": color(score), "fontweight": "bold"}]
if error and error != "null" and with_error:
score_str += f" | <Error: {error}>"
score_str += f" <{error}>"
hl_props.append({"color": "orange", "fontweight": "bold"})
# 3. Wrap Text
@ -250,19 +252,16 @@ def render_score_text(label, score, error, width_px, fontsize=18,
fig_width = width_px / dpi
chars_per_line = int(fig_width * 10)
# Note: Since there is no LaTeX anymore, standard textwrap works well here
import textwrap
wrapped_text = textwrap.fill(score_str, width=chars_per_line)
# wrapped_text = textwrap.fill(score_str, width=chars_per_line)
# 4. Render using highlight_text.ax_text
num_lines = wrapped_text.count('\n') + 1
fig_height = num_lines * 0.4 + 0.2
# fig_height = 0.4 + 0.2
fig_height = 0.8
fig, ax = plt.subplots(figsize=(fig_width, fig_height), dpi=dpi)
ax.axis('off')
# Replaces plt.text
ax_text(0.01, 0.95, wrapped_text,
ax_text(0.02, 0.98, score_str,
fontsize=fontsize,
verticalalignment='top',
horizontalalignment='left',
@ -270,7 +269,9 @@ def render_score_text(label, score, error, width_px, fontsize=18,
ax=ax)
buf = io.BytesIO()
plt.savefig(buf, format='png', bbox_inches='tight', pad_inches=0.1, transparent=True)
# Issues with tight bbox_inches.
# plt.savefig(buf, format='png', bbox_inches='tight', pad_inches=0.05, transparent=True)
plt.savefig(buf, format='png', pad_inches=0.05, transparent=True)
plt.close(fig)
buf.seek(0)

View File

@ -59,7 +59,7 @@ class CheckboxRenderer:
# Draw score boxes
start_x = pos['w'] + 20
for val in SCORES:
box = draw_checkbox(draw, start_x, pos['y'] + 5, BOX_SIZE, str(val))
box = draw_checkbox(draw, start_x, pos['y'] + 25, BOX_SIZE, str(val))
self.checkboxes.append({
"type": "score", "label": self.label, "value": val,
"rel_box": box # Will be adjusted for global Y later

View File

@ -17,7 +17,7 @@ def detect_checks_and_notes(output_dir):
notes_img: RGBA image of manual notes (checks masked out)
"""
names = ["Concat_annotated.pdf", "Concat_a.pdf"]
names = ["Concat_annotated.pdf"]
for name in names:
pdf_path = os.path.join(output_dir, name)
if os.path.exists(pdf_path):