! ! Sample program that demonstrates wrap for proportional fonts. ! Makes use of a user defined lookup table that specifies ! character width factor for font+character combinations ! begin-program do main end-program begin-procedure main alter-printer font=4 ! ! Load the character width lookup table from the database ! load-lookup name=characters rows=52 table=characters key=character return_value=factor ! ! Test string with upper and lower case characters ! let $test_string = 'THIS is a TEST string for WRAP with PROPORTIONAL text. ' || 'THIS is a TEST string for WRAP with PROPORTIONAL text. ' || 'THIS is a TEST string for WRAP with PROPORTIONAL text. ' || 'THIS is a TEST string for WRAP with PROPORTIONAL text. ' || 'THIS is a TEST string for WRAP with PROPORTIONAL text. ' do wrap_proportional($test_string,'4',1,5,25) ! ! Test string with all lower case characters ! let $test_string = 'this is a test string for wrap with proportional text. ' || 'this is a test string for wrap with proportional text. ' || 'this is a test string for wrap with proportional text. ' || 'this is a test string for wrap with proportional text. ' || 'this is a test string for wrap with proportional text. ' do wrap_proportional($test_string,'4',10,10,25) end-procedure begin-procedure wrap_proportional($test_string,$font,#line_no,#col_no,#nochars) ! ! Arguments are: $test_string = the string to be wrapped ! $font = the number of the font ! #line_no = starting line number ! #col_no = column position ! #nochars = width of the wrap ! move 'TRUE' to $first_print let #max_factor = #nochars * 100 let #current_factor = 0 move 1 to #position move 1 to #last_position ! ! Loop reading each character from $test_string ! while #position <= length($test_string) let $chr = substr($test_string,#position,1) if $chr = ' ' move #position to #last_blank end-if ! ! Lookup the character width factor for current font+character combination ! let $key = $font || $chr lookup characters $key $factor ! ! Test whether current character factor causes current total to > max factor ! if #current_factor + to_number($factor) > #max_factor if $chr = ' ' ! ! If current character is a blank then split the string here. ! let $print_string = substr($test_string,#last_position,#position - #last_position) let #last_position = #position + 1 else ! ! If next character is a blank or this is the end of the string, ! then split the string here also. ! if #position < length($test_string) let $next_chr = substr($test_string,#position + 1,1) else let $next_chr = ' ' end-if if $next_chr = ' ' let $print_string = substr($test_string,#last_position,(#position - #last_position) + 1) let #last_position = #position + 2 add 1 to #position else ! ! Otherwise, back up to the last blank character. ! let $print_string = substr($test_string,#last_position,#last_blank - #last_position) let #position = #last_blank let #last_position = #position + 1 end-if end-if ! ! Print the current string ! if $first_print = 'TRUE' print $print_string (#line_no,#col_no) move 'FALSE' to $first_print else print $print_string (+1,#col_no) end-if move 0 to #current_factor else ! ! Add character factor to current total ! let #current_factor = #current_factor + to_number($factor) end-if add 1 to #position end-while ! ! Test whether there is any remaining string to print. ! if #last_position < length($test_string) let $print_string = substr($test_string,#last_position,length($test_string) - #last_position +1) if $first_print = 'TRUE' print $print_string (#line_no,#col_no) move 'FALSE' to $first_print else print $print_string (+1,#col_no) end-if end-if end-procedure ! wrap_proportional