lite-xl icon indicating copy to clipboard operation
lite-xl copied to clipboard

Loading fonts with non-ACP names

Open takase1121 opened this issue 3 years ago • 4 comments
trafficstars

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.

takase1121 avatar Jun 10 '22 15:06 takase1121

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.

adamharrison avatar Jun 10 '22 18:06 adamharrison

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.

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.

takase1121 avatar Jun 11 '22 04:06 takase1121

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.

Guldoman avatar Jun 11 '22 05:06 Guldoman

Here are the results memory wise: With reference counting: image

Without reference counting: image

Master: image

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.

takase1121 avatar Jun 11 '22 07:06 takase1121

Suceeded by #1201

takase1121 avatar Nov 14 '22 14:11 takase1121