From defa88d271ae7375ec2773f839881474c3bd50ed Mon Sep 17 00:00:00 2001 From: the lemons Date: Tue, 27 Dec 2022 13:28:21 -0600 Subject: =?UTF-8?q?11=C2=B9=C2=B9=C2=B9=20font=20(incomplete)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- text.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 text.lua (limited to 'text.lua') diff --git a/text.lua b/text.lua new file mode 100644 index 0000000..a885b39 --- /dev/null +++ b/text.lua @@ -0,0 +1,37 @@ +local font = require "font" +local utf8 = require "utf8" + +local text = {} + +local function draw_char(c, center) + love.graphics.push() + local c = font[c] or font["□"] + if not center then + love.graphics.translate(c.width / 2, 0) + end + for _, l in ipairs(c) do + line(unpack(l)) + end + love.graphics.pop() + return c.width +end + +function text.draw(str, x, y, opt) + opt = opt or {} + opt.scale = opt.scale or 1 + opt.spacing = opt.spacing or 3 + + local lw = love.graphics.getLineWidth(lw) + love.graphics.push() + love.graphics.translate(x or 0, y or 0) + love.graphics.scale(opt.scale) + love.graphics.setLineWidth(lw / opt.scale) + for _, c in utf8.codes(str) do + love.graphics.translate(draw_char(utf8.char(c)), 0) + love.graphics.translate(opt.spacing, 0) + end + love.graphics.pop() + love.graphics.setLineWidth(lw) +end + +return text -- cgit v1.2.3