Spaces:
Running
Running
Update app.py
Browse filesanother width fix
144 unmodified lines1451461471481491501511481491501541511521571531541551563 unmodified lines160161162167163164169165166172167168169170171172178173174175176182177178179180186181182183184191185186193187188189190197191199200201192193194195196204197198199200201202211203204205206207217218208209210211212213223214215216217144 unmodified lines return chunks
def 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 targeted layout boundary matching your template total_table_width_in = 7.0 # Static overall structural boundaries matching your publishing layout template table_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; " 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 lines for idx, current_chunk in enumerate(table_chunks): is_first = (idx == 0) total_slots = 7 # Maximum columns allowed per grid matrix total_slots = 7 # Determine actual textual length score for each available linguistic slot slot_weights = [] # If it's the first table block, column 1 is reserved for the reference metadata headers 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 Arial w_hebrew = len(word.get("hebrew", "")) w_hebrew = len(word.get("hebrew", "")) * 1.8 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 metrics 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) # Pad trailing empty cells for terminal tables to keep matrix symmetry clean 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) # Base padding allocation score for blank spaces slot_weights.append(5) # --- EXECUTE THREE-STEP PROPORTIONAL COLUMN BALANCING ENGINE --- # --- EXECUTE PROPORTIONAL COLUMN BALANCING --- total_weight_score = sum(slot_weights) calculated_widths = [] for w in slot_weights: # Distribute 7 inches proportionally using character scores allocated_width = (w / total_weight_score) * total_table_width_in # Enforce micro baseline minimum constraints to block rendering overflows if allocated_width < 0.65: allocated_width = 0.65 # Guard against columns getting crushed too narrow if allocated_width < 0.70: allocated_width = 0.70 calculated_widths.append(round(allocated_width, 3)) # Re-verify layout sum constraints and adjust minor float round errors into the final cell column 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}">') # Define structural colgroup bounds using the newly calculated balanced widths 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>') # Core Cell Typography Styling base_cell = "border: 1pt solid #b7b7b7; padding: 0.069in !important; height: auto; overflow: hidden; word-wrap: break-word;" # FIXED STEP: white-space flipped to normal to allow text to wrap within balanced bounds, preserving 0.069in padding base_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 Metadata --- # --- 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