Removed font renderer.

This commit is contained in:
Adam Harrison
2021-09-24 11:22:39 -04:00
parent 8c32950f4b
commit e25f2e9c5c
24 changed files with 420 additions and 3127 deletions
+8 -15
View File
@@ -150,14 +150,14 @@ function DocView:get_col_x_offset(line, col)
local font = style.syntax_fonts[type] or default_font
for char in common.utf8_chars(text) do
if column == col then
return xoffset / font:subpixel_scale()
return xoffset
end
xoffset = xoffset + font:get_width_subpixel(char)
xoffset = xoffset + font:get_width(char)
column = column + #char
end
end
return xoffset / default_font:subpixel_scale()
return xoffset
end
@@ -166,14 +166,12 @@ function DocView:get_x_offset_col(line, x)
local xoffset, last_i, i = 0, 1, 1
local default_font = self:get_font()
local subpixel_scale = default_font:subpixel_scale()
local x_subpixel = subpixel_scale * x + subpixel_scale / 2
for _, type, text in self.doc.highlighter:each_token(line) do
local font = style.syntax_fonts[type] or default_font
for char in common.utf8_chars(text) do
local w = font:get_width_subpixel(char)
if xoffset >= subpixel_scale * x then
return (xoffset - x_subpixel > w / 2) and last_i or i
local w = font:get_width(char)
if xoffset >= x then
return (xoffset - x > w / 2) and last_i or i
end
xoffset = xoffset + w
last_i = i
@@ -339,16 +337,11 @@ end
function DocView:draw_line_text(idx, x, y)
local default_font = self:get_font()
local subpixel_scale = default_font:subpixel_scale()
local tx, ty = subpixel_scale * x, y + self:get_line_text_y_offset()
local tx, ty = x, y + self:get_line_text_y_offset()
for _, type, text in self.doc.highlighter:each_token(idx) do
local color = style.syntax[type]
local font = style.syntax_fonts[type] or default_font
if config.draw_whitespace then
tx = renderer.draw_text_subpixel(font, text, tx, ty, color, core.replacements, style.syntax.comment)
else
tx = renderer.draw_text_subpixel(font, text, tx, ty, color)
end
tx = renderer.draw_text(font, text, tx, ty, color)
end
end
-10
View File
@@ -393,15 +393,6 @@ function core.remove_project_directory(path)
return false
end
local function whitespace_replacements()
local r = renderer.replacements.new()
r:add(" ", "·")
r:add("\t", "»")
return r
end
local function reload_on_user_module_save()
-- auto-realod style when user's module is saved by overriding Doc:Save()
local doc_save = Doc.save
@@ -499,7 +490,6 @@ function core.init()
core.visited_files = {}
core.restart_request = false
core.quit_request = false
core.replacements = whitespace_replacements()
core.root_view = RootView()
core.command_view = CommandView()
+31
View File
@@ -0,0 +1,31 @@
-- mod-version:2 -- lite-xl 2.0
local style = require "core.style"
local DocView = require "core.docview"
local common = require "core.common"
local draw_line_text = DocView.draw_line_text
function DocView:draw_line_text(idx, x, y)
local font = (self:get_font() or style.syntax_fonts["comment"])
local color = style.syntax.comment
local ty, tx = y + self:get_line_text_y_offset()
local text, offset, s, e = self.doc.lines[idx], 1
while true do
s, e = text:find(" +", offset)
if not s then break end
tx = self:get_col_x_offset(idx, s) + x
renderer.draw_text(font, string.rep("·", e - s + 1), tx, ty, color)
offset = e + 1
end
while true do
s, e = text:find("\t", offset)
if not s then break end
tx = self:get_col_x_offset(idx, s) + x
renderer.draw_text(font, "»", tx, ty, color)
offset = e + 1
end
draw_line_text(self, idx, x, y)
end