bugfix: UTF-8 in compute_fragments

[?]
Jun 14, 2022, 2:30 PM
DGK5BPVI6PAD3WK2ZB2ITMBE6WYSU3ZR7TV7RTCQ2WJQ4RGJE5RQC

Dependencies

Change contents

  • edit in text_tests.lua at line 110
    [2.2452]
    [2.2452]
    end
    function test_draw_wrapping_text_containing_non_ascii()
    -- draw a long line containing non-ASCII
    io.write('\ntest_draw_wrapping_text_containing_non_ascii')
    App.screen.init{width=60, height=60}
    Lines = load_array{'madam I’m adam', 'xyz'} -- notice the non-ASCII apostrophe
    Line_width = App.screen.width
    Cursor1 = {line=1, pos=1}
    Screen_top1 = {line=1, pos=1}
    Screen_bottom1 = {}
    App.draw()
    local y = Margin_top
    App.screen.check(y, 'mada', 'F - test_draw_wrapping_text_containing_non_ascii/screen:1')
    y = y + Line_height
    App.screen.check(y, 'm I’', 'F - test_draw_wrapping_text_containing_non_ascii/screen:2')
    y = y + Line_height
    App.screen.check(y, 'm ad', 'F - test_draw_wrapping_text_containing_non_ascii/screen:3')
  • replacement in text.lua at line 113
    [3.672][3.6847:6916](),[3.6916][3.1529:1603](),[3.1603][3.738:846](),[3.6916][3.738:846](),[3.738][3.738:846]()
    local b = Text.nearest_pos_less_than(frag, line_width - x)
    assert(b > 0) -- avoid infinite loop when window is too narrow
    --? print('space for '..tostring(b)..' graphemes')
    local frag1 = string.sub(frag, 1, b)
    [3.672]
    [3.809]
    local bpos = Text.nearest_pos_less_than(frag, line_width - x)
    assert(bpos > 0) -- avoid infinite loop when window is too narrow
    local boffset = utf8.offset(frag, bpos+1) -- byte _after_ bpos
    assert(boffset)
    --? print('space for '..tostring(bpos)..' graphemes, '..tostring(boffset)..' bytes')
    local frag1 = string.sub(frag, 1, boffset-1)
  • replacement in text.lua at line 125
    [3.1152][3.1152:1191]()
    frag = string.sub(frag, b+1)
    [3.1152]
    [3.952]
    frag = string.sub(frag, boffset)
  • edit in main.lua at line 197
    [11.337]
    [10.302]
    --? love.graphics.setColor(0, 1, 0)
    --? love.graphics.line(Line_width,0, Line_width,App.screen.height)