lite-xl
lite-xl copied to clipboard
Loading fonts with non-ACP names
This is sort of a mixed bag because ideally fopen will intepret filename as current active code page, but as always Windows' active code page is ASCII (or its derivatives, just not UTF-8) by default.
However, the user config should be only contain UTF-8, so unless you somehow put some other encoding into it, this will be required.
Despite what the ft issue tell you, it does not apply to us. True, most font files are in a relatively "stable" directory, but lite-xl loads fonts from its DATADIR, which is prone to contain non-ASCII characters (because you can put it everywhere!). This is why this issue is important.
This PR does not break API compatibility. A new function is added to load files from memory, and both file loading and copying is modified to use it.
However, I did not observe any performance improvements (quite the opposite actually). A cache is still required.
Could we not simply just perform the load into memory directly in the ren_font_load? That way we don't add any extra structures, have to reference, or really do anything different outside that one function; we just fopen, fseek, ftell, and fread, and that's it.
Could we not simply just perform the load into memory directly in the
ren_font_load? That way we don't add any extra structures, have to reference, or really do anything different outside that one function; we justfopen,fseek,ftell, andfread, and that's it.
This PR will prevent multiple reads for systems that are really slow at reading. It also prevents reading file again whenever a copy is needed.
I think we could avoid both the refcount and the new struct by adding the buffer and the size directly into RenFont. Then when you need to copy a font, you memcpy the buffer from RenFont and feed it to ren_font_load_memory.
I wonder what's the memory impact tho.
Here are the results memory wise:
With reference counting:

Without reference counting:

Master:

The test plugin:
-- mod-version:3
local common = require "core.common"
local style = require "core.style"
collectgarbage "collect"
collectgarbage "stop"
for j = 1, 10 do
common.bench("optimized", function()
for i = 1, 100 do
style.code_font:copy(12)
end
end)
end
os.exit()
There seems to be a memory impact.
Suceeded by #1201