PFT5Y2ZYGQA6XXOZ5HH75WVUGA4B3KTDRHSFOZRAUKTPSFOPMNRAC function Text.compute_fragments(line, line_width)line.fragments = {}local x = 25-- try to wrap at word boundariesfor frag in line.data:gmatch('%S*%s*') dolocal frag_text = love.graphics.newText(love.graphics.getFont(), frag)local frag_width = math.floor(frag_text:getWidth()*Zoom)--? print('x: '..tostring(x)..'; '..tostring(line_width-x)..'px to go')--? print('frag: ^'..frag..'$ is '..tostring(frag_width)..'px wide')if x + frag_width > line_width thenwhile x + frag_width > line_width doif x < 0.8*line_width then-- long word; chop it at some letter-- We're not going to reimplement TeX here.local b = Text.nearest_cursor_pos(frag, line_width - x)--? print('space for '..tostring(b)..' graphemes')local frag1 = string.sub(frag, 1, b)local frag1_text = love.graphics.newText(love.graphics.getFont(), frag1)local frag1_width = math.floor(frag1_text:getWidth()*Zoom)--? print('inserting '..frag1..' of width '..tostring(frag1_width)..'px')table.insert(line.fragments, {data=frag1, text=frag1_text})frag = string.sub(frag, b+1)frag_text = love.graphics.newText(love.graphics.getFont(), frag)frag_width = math.floor(frag_text:getWidth()*Zoom)endx = 25 -- new lineendendif #frag > 0 then--? print('inserting '..frag..' of width '..tostring(frag_width)..'px')table.insert(line.fragments, {data=frag, text=frag_text})endendend
function Text.compute_fragments(line, line_width)line.fragments = {}local x = 25-- try to wrap at word boundariesfor frag in line.data:gmatch('%S*%s*') dolocal frag_text = love.graphics.newText(love.graphics.getFont(), frag)local frag_width = math.floor(frag_text:getWidth()*Zoom)--? print('x: '..tostring(x)..'; '..tostring(line_width-x)..'px to go')--? print('frag: ^'..frag..'$ is '..tostring(frag_width)..'px wide')if x + frag_width > line_width thenwhile x + frag_width > line_width doif x < 0.8*line_width then-- long word; chop it at some letter-- We're not going to reimplement TeX here.local b = Text.nearest_cursor_pos(frag, line_width - x)--? print('space for '..tostring(b)..' graphemes')local frag1 = string.sub(frag, 1, b)local frag1_text = love.graphics.newText(love.graphics.getFont(), frag1)local frag1_width = math.floor(frag1_text:getWidth()*Zoom)--? print('inserting '..frag1..' of width '..tostring(frag1_width)..'px')table.insert(line.fragments, {data=frag1, text=frag1_text})frag = string.sub(frag, b+1)frag_text = love.graphics.newText(love.graphics.getFont(), frag)frag_width = math.floor(frag_text:getWidth()*Zoom)endx = 25 -- new lineendendif #frag > 0 then--? print('inserting '..frag..' of width '..tostring(frag_width)..'px')table.insert(line.fragments, {data=frag, text=frag_text})endendend