Spaces:
Running
Running
Update app.py
Browse filesanother width fix
144 unmodified lines1451461471481491501511521531541551561571581591603 unmodified lines164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226144 unmodified linesreturn chunksdef build_html_tables(manuscript, reference, words_data):"""Assembles right-to-left interlinear grids matching an exact 7-inch boundary template.Applies proportional cell calculations based on horizontal string weights."""total_table_width_in = 7.0# Static overall structural boundaries matching your publishing layout templatetable_style = (f"width: {total_table_width_in}in !important; min-width: {total_table_width_in}in !important; "f"max-width: {total_table_width_in}in !important; table-layout: fixed; border-collapse: collapse; ""margin-bottom: 4pt; direction: rtl; border: 1pt solid #b7b7b7; background-color: #ffffff; ""line-height: 1.0 !important; height: auto; margin-left: auto; margin-right: auto;")3 unmodified linesfor idx, current_chunk in enumerate(table_chunks):is_first = (idx == 0)total_slots = 7 # Maximum columns allowed per grid matrix# Determine actual textual length score for each available linguistic slotslot_weights = []# If it's the first table block, column 1 is reserved for the reference metadata headersif is_first:ref_len = max(len(reference), len(manuscript))slot_weights.append(ref_len)for word in current_chunk:w_hebrew = len(word.get("hebrew", ""))w_translit = len(word.get("transliteration", ""))w_trans = len(word.get("translation", ""))w_morph = len(word.get("morphology", ""))# Evaluate maximum content footprint across the stacked cell metricsmax_text_footprint = max(w_hebrew, w_translit, w_trans, w_morph)slot_weights.append(max_text_footprint if max_text_footprint > 0 else 5)# Pad trailing empty cells for terminal tables to keep matrix symmetry cleanis_last_table = (idx == len(table_chunks) - 1)if is_last_table:while (len(current_chunk) + (1 if is_first else 0)) < total_slots:current_chunk.append({"hebrew": " ", "transliteration": "", "translation": "", "morphology": ""})slot_weights.append(5) # Base padding allocation score for blank spaces# --- EXECUTE THREE-STEP PROPORTIONAL COLUMN BALANCING ENGINE ---total_weight_score = sum(slot_weights)calculated_widths = []for w in slot_weights:# Distribute 7 inches proportionally using character scoresallocated_width = (w / total_weight_score) * total_table_width_in# Enforce micro baseline minimum constraints to block rendering overflowsif allocated_width < 0.65:allocated_width = 0.65calculated_widths.append(round(allocated_width, 3))# Re-verify layout sum constraints and adjust minor float round errors into the final cell columnremainder_adjustment = round(total_table_width_in - sum(calculated_widths), 3)if remainder_adjustment != 0 and len(calculated_widths) > 0:calculated_widths[-1] = round(calculated_widths[-1] + remainder_adjustment, 3)html_output.append(f'<table style="{table_style}">')# Define structural colgroup bounds using the newly calculated balanced widthshtml_output.append(' <colgroup>')for c_width in calculated_widths:html_output.append(f' <col style="width: {c_width}in !important;">')html_output.append(' </colgroup>')# Core Cell Typography Stylingbase_cell = "border: 1pt solid #b7b7b7; padding: 0.069in !important; height: auto; overflow: hidden; word-wrap: break-word;"hebrew_cell_style = f"font-family: 'Times New Roman', serif !important; font-size: 24px !important; color: #000000 !important; text-align: right; vertical-align: middle; {base_cell}"english_cell_style = f"font-family: Arial, sans-serif !important; font-size: 14.6667px !important; color: #000000 !important; text-align: center; vertical-align: top; line-height: 1.0 !important; {base_cell}"heading_cell_style = f"font-family: 'Times New Roman', serif !important; font-size: 18.6667px !important; color: #000000 !important; text-align: center; vertical-align: middle; line-height: 1.0 !important; {base_cell}"# --- ROW 1: Hebrew Text / Reference Metadata ---html_output.append(' <tr style="height: auto; line-height: 1.0 !important;">')if is_first:html_output.append(f' <td style="{heading_cell_style}">{reference}</td>')144 unmodified lines1451461471481491501511521531541551563 unmodified lines160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217144 unmodified linesreturn chunksdef build_html_tables(manuscript, reference, words_data):# Total targeted layout boundary matching your templatetotal_table_width_in = 7.0table_style = (f"width: {total_table_width_in}in !important; min-width: {total_table_width_in}in !important; "f"max-width: {total_table_width_in}in !important; table-layout: fixed !important; border-collapse: collapse; ""margin-bottom: 4pt; direction: rtl; border: 1pt solid #b7b7b7; background-color: #ffffff; ""line-height: 1.0 !important; height: auto; margin-left: auto; margin-right: auto;")3 unmodified linesfor idx, current_chunk in enumerate(table_chunks):is_first = (idx == 0)total_slots = 7slot_weights = []if is_first:ref_len = max(len(reference), len(manuscript))slot_weights.append(ref_len)for word in current_chunk:# Multiply Hebrew character length by 1.8 because 24px font is visually much wider than 14px Arialw_hebrew = len(word.get("hebrew", "")) * 1.8w_translit = len(word.get("transliteration", ""))w_trans = len(word.get("translation", ""))w_morph = len(word.get("morphology", ""))max_text_footprint = max(w_hebrew, w_translit, w_trans, w_morph)slot_weights.append(max_text_footprint if max_text_footprint > 0 else 5)is_last_table = (idx == len(table_chunks) - 1)if is_last_table:while (len(current_chunk) + (1 if is_first else 0)) < total_slots:current_chunk.append({"hebrew": " ", "transliteration": "", "translation": "", "morphology": ""})slot_weights.append(5)# --- EXECUTE PROPORTIONAL COLUMN BALANCING ---total_weight_score = sum(slot_weights)calculated_widths = []for w in slot_weights:allocated_width = (w / total_weight_score) * total_table_width_in# Guard against columns getting crushed too narrowif allocated_width < 0.70:allocated_width = 0.70calculated_widths.append(round(allocated_width, 3))remainder_adjustment = round(total_table_width_in - sum(calculated_widths), 3)if remainder_adjustment != 0 and len(calculated_widths) > 0:calculated_widths[-1] = round(calculated_widths[-1] + remainder_adjustment, 3)html_output.append(f'<table style="{table_style}">')html_output.append(' <colgroup>')for c_width in calculated_widths:html_output.append(f' <col style="width: {c_width}in !important;">')html_output.append(' </colgroup>')# FIXED STEP: white-space flipped to normal to allow text to wrap within balanced bounds, preserving 0.069in paddingbase_cell = "border: 1pt solid #b7b7b7; padding: 0.069in !important; height: auto; overflow: hidden; word-wrap: break-word; white-space: normal !important;"hebrew_cell_style = f"font-family: 'Times New Roman', serif !important; font-size: 24px !important; color: #000000 !important; text-align: right; vertical-align: middle; {base_cell}"english_cell_style = f"font-family: Arial, sans-serif !important; font-size: 14.6667px !important; color: #000000 !important; text-align: center; vertical-align: top; line-height: 1.0 !important; {base_cell}"heading_cell_style = f"font-family: 'Times New Roman', serif !important; font-size: 18.6667px !important; color: #000000 !important; text-align: center; vertical-align: middle; line-height: 1.0 !important; {base_cell}"# --- ROW 1: Hebrew Text / Reference ---html_output.append(' <tr style="height: auto; line-height: 1.0 !important;">')if is_first:html_output.append(f' <td style="{heading_cell_style}">{reference}</td>')
app.py+14-23