diff options
author | the lemons <citrons@mondecitronne.com> | 2022-12-27 13:28:21 -0600 |
---|---|---|
committer | the lemons <citrons@mondecitronne.com> | 2022-12-27 13:28:21 -0600 |
commit | defa88d271ae7375ec2773f839881474c3bd50ed (patch) | |
tree | 3cefb8c3a57ff9cde833fb9f9f10ce19c91b1e99 | |
parent | db39f51f24406805ee50ad6fef89c32a71b179a7 (diff) |
11¹¹¹ font (incomplete)
-rw-r--r-- | font.lua | 126 | ||||
-rw-r--r-- | text.lua | 37 |
2 files changed, 163 insertions, 0 deletions
diff --git a/font.lua b/font.lua new file mode 100644 index 0000000..023c739 --- /dev/null +++ b/font.lua @@ -0,0 +1,126 @@ +local font = {} + +font[" "] = {width = 2} +font["\t"] = {width = 8} +font["!"] = {width = 1, + {0, -8, 0, 2}, + {-0.25, 4, 0, 3.75, 0.25, 4, 0, 4.25, -0.25, 4} +} +font['"'] = {width = 2, + {-1, -8, -1, -6}, + {1, -8, 1, -6} +} +font["#"] = {width = 6, + {-2, 4, -1, -8}, + {1, 4, 2, -8}, + {4, -3, -4, -3}, + {-4, 0, 4, 0} +} +font[","] = {width = 0.05, + {1, 3, -1, 5} +} +font["a"] = {width = 6, + {-3, -2, -1, -4, 1, -4, 3, -2, 3, 4}, + {3, 2, 1, 4, -1, 4, -3, 2, -1, 0, 3, 0} +} +font["b"] = {width = 6, + {-3, 4, -3, -8}, + {-3, -2, -1, -4, 1, -4, 3, -2, 3, 2, 1, 4, -1, 4, -3, 2} +} +font["c"] = {width = 6, + {3, -2, 1, -4, -1, -4, -3, -2, -3, 2, -1, 4, 1, 4, 3, 2} +} +font["d"] = {width = 6, + {3, -8, 3, 4}, + {3, -2, 1, -4, -1, -4, -3, -2, -3, 2, -1, 4, 1, 4, 3, 2} +} +font["e"] = {width = 6, + {-3, 0, 3, 0, 3, -2, 1, -4, -1, -4, -3, -2, -3, 2, -1, 4, 1, 4, 3, 2} +} +font["f"] = {width = 4, + {-2, -4, 2, -4}, + {0, 4, 0, -6, 2, -8, 4, -8} +} +font["g"] = {width = 6, + {3, -4, 3, 6, 1, 8, -1, 8, -3, 6}, + {3, 2, 1, 4, -1, 4, -3, 2, -3, -2, -1, -4, 1, -4, 3, -2} +} +font["h"] = {width = 6, + {-3, -8, -3, 4}, + {-3, -2, -1, -4, 1, -4, 3, -2, 3, 4} +} +font["i"] = {width = 2, + {0, 4, 0, -4}, + {0, -5.75, -0.25, -6, 0, -6.25, 0.25, -6, 0, -5.75} +} +font["j"] = {width = 2, + {1, -4, 1, 4, -1, 6}, + {1, -5.75, 0.75, -6, 1, -6.25, 1.25, -6, 1, -5.75} +} +font["k"] = {width = 4, + {-2, -8, -2, 4}, + {-2, 0, 2, 4}, + {-2, 0, 2, -4} +} +font["l"] = {width = 2, + {-0.5, -8, 0, -8, 0, 3, 1, 4} +} +font["m"] = {width = 8, + {-4, -4, -4, 4}, + {-4, -2, -2, -4, 0, -2, 2, -4, 4, -2, 4, 4}, + {0, -2, 0, 4} +} +font["n"] = {width = 6, + {-3, 4, -3, -4}, + {-3, -2, -1, -4, 1, -4, 3, -2, 3, 4} +} +font["o"] = {width = 6, + {-3, -2, -1, -4, 1, -4, 3, -2, 3, 2, 1, 4, -1, 4, -3, 2, -3, -2} +} +font["p"] = {width = 6, + {-3, -4, -3, 8}, + {-3, 2, -1, 4, 1, 4, 3, 2, 3, -2, 1, -4, -1, -4, -3, -2} +} +font["q"] = {width = 6, + {3, -4, 3, 8}, + {3, 2, 1, 4, -1, 4, -3, 2, -3, -2, -1, -4, 1, -4, 3, -2} +} +font["r"] = {width = 3, + {-1.5, -4, -1.5, 4}, + {-1.5, -2, 0.5, -4, 3, -4} +} +font["s"] = {width = 6, + {3, -2, 1, -4, -1, -4, -3, -2, -1, 0, 1, 0, 3, 2, 1, 4, -1, 4, -3, 2} +} +font["t"] = {width = 4, + {0, 4, 0, -8}, + {-2, -4, 2, -4} +} +font["u"] = {width = 6, + {-3, -4, -3, 2, -1, 4, 1, 4, 3, 2}, + {3, 4, 3, -4} +} +font["v"] = {width = 6, + {-3, -4, 0, 4, 3, -4} +} +font["w"] = {width = 8, + {-4, -4, -4, 2, -2, 4, 0, 2, 2, 4, 4, 2, 4, -4}, + {4, -4, 4, 4}, + {0, 2, 0, -4} +} +font["x"] = {width = 6, + {-3, -4, 3, 4}, + {-3, 4, 3, -4} +} +font["y"] = {width = 6, + {-3, -4, -3, 2, -1, 4, 1, 4, 3, 2}, + {3, -4, 3, 6, 1, 8, -1, 8, -3, 6} +} +font["z"] = {width = 6, + {-3, -4, 3, -4, -3, 4, 3, 4} +} +font["□"] = {width = 8, + {-4, -4, 4, -4, 4, 4, -4, 4, -4, -4} +} + +return font 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 |