MCPcopy Create free account
hub / github.com/Paper2Poster/Paper2Poster / split_textbox

Function split_textbox

PosterAgent/tree_split_layout.py:552–588  ·  view source on GitHub ↗

Splits a textbox dictionary horizontally into two parts. Parameters: textbox (dict): A dictionary with the keys 'panel_id', 'x', 'y', 'width', 'height', 'textbox_id', 'textbox_name' ratio (float or int): Ratio of top height to bottom height.

(textbox, ratio)

Source from the content-addressed store, hash-verified

550 return best_loss, best_arr
551
552def split_textbox(textbox, ratio):
553 """
554 Splits a textbox dictionary horizontally into two parts.
555
556 Parameters:
557 textbox (dict): A dictionary with the keys
558 'panel_id', 'x', 'y', 'width', 'height', 'textbox_id', 'textbox_name'
559 ratio (float or int): Ratio of top height to bottom height.
560 For example, if ratio is 3, then:
561 top_height = (3/4) * height
562 bottom_height = (1/4) * height
563
564 Returns:
565 tuple: Two dictionaries corresponding to the top and bottom split textboxes.
566 """
567 # Calculate the new heights
568 total_ratio = ratio + 1 # because the ratio represents top:bottom as (ratio):(1)
569 top_height = textbox['height'] * ratio / total_ratio
570 bottom_height = textbox['height'] * 1 / total_ratio
571
572 # Derive the base textbox name by splitting off the existing _t suffix if present.
573 # This assumes the original textbox_name ends with "_t<number>".
574 base_name = textbox['textbox_name'].rsplit('_t', 1)[0]
575
576 # Create the top textbox dictionary
577 top_box = dict(textbox) # make a shallow copy
578 top_box['height'] = top_height
579 # y remains the same for the top textbox
580 top_box['textbox_name'] = f"{base_name}_t0" # rename with _t0
581
582 # Create the bottom textbox dictionary
583 bottom_box = dict(textbox) # make a shallow copy
584 bottom_box['y'] = textbox['y'] + top_height # adjust the y position
585 bottom_box['height'] = bottom_height
586 bottom_box['textbox_name'] = f"{base_name}_t1" # rename with _t1
587
588 return top_box, bottom_box
589
590def generate_constrained_layout(paper_panels, poster_w, poster_h, title_height_ratio=0.1):
591 # Find title panel explicitly

Callers 1

new_pipeline.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected