Spaces:
Running
Running
Update app.py
Browse filesTHIS IS THE ONE I finally fixed cell padding.
Now on to interface design
111 unmodified lines11211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114218 unmodified lines16116216316416516616716816917017133 unmodified lines20520620720820921021111 unmodified lines223224225226227228229230111 unmodified linesdef get_minimum_column_width_in(word_dict, is_reference_block=False, ref_text="", ms_text=""):"""Measures character lengths to establish the minimum width in inchesneeded to hold content cleanly on a single line without wrapping."""char_width_in = 0.072hebrew_char_width_in = 0.140# Precise padding safety buffer: 0.069 inches on both sides = 0.138 inchespadding_buffer_in = 0.069 * 2if is_reference_block:max_chars = max(len(ref_text), len(ms_text))return (max_chars * char_width_in) + padding_buffer_inw_hebrew = len(word_dict.get("hebrew", "")) * hebrew_char_width_inw_translit = len(word_dict.get("transliteration", "")) * char_width_inw_trans = len(word_dict.get("translation", "")) * char_width_inw_morph = len(word_dict.get("morphology", "")) * char_width_inmax_content_width = max(w_hebrew, w_translit, w_trans, w_morph)return max(max_content_width, 0.65) + padding_buffer_indef calculate_recursive_table_chunks(words_data, reference, manuscript):"""ESSENTIAL PROCEDURE: Groups words. If a 7-column layout requires more than7.0 inches to prevent wrapping, the last word drops down recursively."""total_allowed_width_in = 7.0final_row_chunks = []18 unmodified linestotal_required_row_width = sum(minimum_widths)# If the combined row width fits comfortably inside 7 inches, we break and lock itif total_required_row_width <= total_allowed_width_in:break# If it exceeds 7 inches, drop the last word to the next row poolcurrent_row_words.pop()final_row_chunks.append(current_row_words)33 unmodified linescurrent_chunk.append({"hebrew": " ", "transliteration": " ", "translation": " ", "morphology": " "})slot_minimums.append(0.75)# Proportional balancing math ensures all columns total exactly 7.0 inches overalltotal_minimum_score = sum(slot_minimums)calculated_widths = []for min_w in slot_minimums:11 unmodified lineshtml_output.append(f' <col style="width: {c_width}in !important; min-width: {c_width}in !important; max-width: {c_width}in !important;">')html_output.append(' </colgroup>')# Symmetrical cell padding exactly 0.069in on all 4 sides with wrap suppressed safelybase_cell = "border: 1pt solid #b7b7b7; padding: 0.069in !important; height: auto; overflow: hidden; white-space: nowrap !important; box-sizing: border-box !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}"111 unmodified lines11211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814918 unmodified lines16816917017117217317417517633 unmodified lines21021121221321421521611 unmodified lines228229230231232233234235111 unmodified linesdef get_minimum_column_width_in(word_dict, is_reference_block=False, ref_text="", ms_text=""):"""Finds the absolute longest single word token in a cell to establish thewrapping safety layout width, factoring in your 0.069in side borders."""char_width_in = 0.076hebrew_char_width_in = 0.145padding_buffer_in = 0.069 * 2if is_reference_block:# Reference blocks can split naturally on spaces (e.g., 'Luke' vs '12:3')ref_tokens = ref_text.split(" ")ms_tokens = ms_text.split(" ")max_chars = max([len(t) for t in (ref_tokens + ms_tokens)] + [5])return (max_chars * char_width_in) + padding_buffer_in# Split each multi-word text string by spaces to find the single longest unbroken word tokenhebrew_tokens = word_dict.get("hebrew", "").split(" ")translit_tokens = word_dict.get("transliteration", "").split(" ")translation_tokens = word_dict.get("translation", "").split(" ")morph_tokens = word_dict.get("morphology", "").split(" ")max_w_hebrew = max([len(t) for t in hebrew_tokens]) * hebrew_char_width_inmax_w_translit = max([len(t) for t in translit_tokens]) * char_width_inmax_w_trans = max([len(t) for t in translation_tokens]) * char_width_inmax_w_morph = max([len(t) for t in morph_tokens]) * char_width_inlongest_single_token_width = max(max_w_hebrew, max_w_translit, max_w_trans, max_w_morph)return max(longest_single_token_width, 0.60) + padding_buffer_indef calculate_recursive_table_chunks(words_data, reference, manuscript):"""Groups your text words. If a single unbroken word token causes a columnfootprint to exceed 7.0 inches total, the last word drops recursively."""total_allowed_width_in = 7.0final_row_chunks = []18 unmodified linestotal_required_row_width = sum(minimum_widths)if total_required_row_width <= total_allowed_width_in:breakcurrent_row_words.pop()final_row_chunks.append(current_row_words)33 unmodified linescurrent_chunk.append({"hebrew": " ", "transliteration": " ", "translation": " ", "morphology": " "})slot_minimums.append(0.75)# Proportional balancing math safely distributes space up to exactly 7.0 inches overalltotal_minimum_score = sum(slot_minimums)calculated_widths = []for min_w in slot_minimums:11 unmodified lineshtml_output.append(f' <col style="width: {c_width}in !important; min-width: {c_width}in !important; max-width: {c_width}in !important;">')html_output.append(' </colgroup>')# FIXED LOGIC: white-space flipped back to normal to allow soft phrase breaks at spaces, while break-word prevents middle-word splitsbase_cell = "border: 1pt solid #b7b7b7; padding: 0.069in !important; height: auto; overflow: hidden; white-space: normal !important; word-wrap: break-word !important; box-sizing: border-box !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}"
app.py+25-20