def mark_preferred_end_position(position, X, run_height): # remember it def get_run_size(character_iterator, X): call mark_preferred_end_position on interesting spots. stop if the next character doesn't fit on the line anymore. stop if the next character is '\n'. stop if there is no data anymore. otherwise consume character and recurse(increase X, increase width, fix height) def wrap(character_iterator): while not character_iterator.end_P(): run_size = get_run_size(character_iterator) # calls mark_preferred_end_position