Пример #1
0
def task_7():
    '''
    @summary: calculate scaling of wrapped text
    '''
    print '>> task 7 - calculate best font size and scaling for wrapped text\n'

    box_height = 400
    box_width = 800
    text = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est'

    line_cnt = split_lib.opt_line_cnt(box_width, box_height, text)
    line_txt_objs = split_lib.split_to_line_objects_v2(text, line_cnt, ' ')

    line_txt_objs.sort(key=lambda x: len(x), reverse=True)
    longest_line = line_txt_objs[0]

    dst_line_height = 1.0 * box_height / len(line_txt_objs)
    text_box = TextBox(box_width, dst_line_height)
    text_box.set_text(str(longest_line))

    scaling_params = text_box.get_scaling_advanced()
    print 'best font size:\t{font_size}\n' \
            'width_scaling:\t{width_scale}\n' \
            'height_scale:\t{height_scale}'.format(**scaling_params)
    
    print 50*'-'
Пример #2
0
def task_3():
    '''
    @summary: scale text box with default text size (1pt)
    @note: Write the code that will figure out and implement the scaling necessary for the text to fit in the box best.
    '''
    print '>>> task 3 -\tfitting text to box\n'

    text_box = TextBox(100, 50)
    text_box.set_text('foobar')
    width_scaling, height_scaling = text_box.get_scaling()
    
    print 'scale width:\t{0}'.format(width_scaling)
    print 'scale height:\t{0}'.format(height_scaling)
    print 50*'-'
Пример #3
0
def task_4():
    '''
    @summary: resize font and scale in a 2nd step 
    '''
    print '>> task 4 - fitting text to box with font scaling\n'

    text_box = TextBox(100, 50)
    text_box.set_text('foobar')
    
    scaling_params = text_box.get_scaling_advanced()
    
    print 'best font size:\t{font_size}\n' \
            'width_scaling:\t{width_scale}\n' \
            'height_scale:\t{height_scale}'.format(**scaling_params)
    print 50*'-'