I'm trying to make editable text box in LOVE. In order to place cursor and select texts with mouse, calculating which character x position of mouse cursor lays on is necessary. However, font:getKerning() function doesn't seem to be working. It always returns zero, even when font:getWidth() of two characters clearly returns value less than sum of two characters' width.
I have tested numbers of fonts including Noto Sans, Roboto, and other well known fonts but getKerning works with none of them. Example Code :
Code: Select all
font = love.graphics.newFont("notosans.otf", 1000)
print(font:getWidth("A"))
print(font:getWidth("V"))
print(font:getWidth("AV")) -- minus kerning
print(font:getKerning("A","V")) -- 0
print(font:getWidth("W"))
print(font:getWidth("a"))
print(font:getWidth("Wa")) -- minus kerning
print(font:getKerning("W","a")) -- 0
print(font:getWidth("X"))
print(font:getWidth("X"))
print(font:getWidth("XX")) -- 0 kerning
print(font:getKerning("X","X")) -- 0
for i=32, 126 do
for j=32, 126 do
if font:getKerning(i, j) ~= 0 then
print(i, j) -- no kerning other than zero is printed
end
end
end
Code: Select all
for i=1, #text do
if font:getWidth(text:sub(1, i)) > x then
-- ...
end
end