I'm working on making a virtual terminal so I can make roguelikes and other textual things.
(Screenshot)
It does most of the things I need it to, except being able to draw box-drawing character and other utf-8 glyphs.
My question is, how would I be able to draw other characters besides letters? Would I just stick them in a string like letters?
Box-drawing characters/other UTF-8?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Box-drawing characters/other UTF-8?
In 0.7.2 I think you can go up to character 255 (ÿ) like so:
This breaks things in 0.8.0 though. It only goes up to \127.
Why? I haven't the foggiest.
Code: Select all
love.graphics.print("\255", 0, 0)
-- or
love.graphics.print("ÿ", 0, 0)
Why? I haven't the foggiest.
Kurosuke needs beta testers
Re: Box-drawing characters/other UTF-8?
0.8.0 switches strings to UTF-8, whose characters have variable length (in terms of bytes). The first 7 bits of UTF-8 constitute the ASCII character set. The 8th bit is used to tell Unicode that the character needs more bits to be described properly.tentus wrote:This breaks things in 0.8.0 though. It only goes up to \127.
Why? I haven't the foggiest.
Characters like ÿ are in the ANSI character set and use up that 8th bit, and therefore in UTF-8 they are placed in higher bytes. ASCII is a subset of UTF-8; ANSI is not.
This explanation should help you visualize it.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Box-drawing characters/other UTF-8?
A simple solution would be to just do
If you do that, you must use UTF-8 as the encoding for your source files.
Code: Select all
love.graphics.print("thìngś likæ thỹs¶¥×¤€", x, y)
Help us help you: attach a .love.
Re: Box-drawing characters/other UTF-8?
May I ask a related question?
Since we have utf-8 support now, how to get a single character from a utf-8 string? The lua function string.byte doesn't work obviously.
---
Edit*
OK, I just found a long article about that on the lua site. It appears there's no easy way, except interpreting the string byte by byte or using some complex regular expressions.
http://lua-users.org/wiki/LuaUnicode
Since we have utf-8 support now, how to get a single character from a utf-8 string? The lua function string.byte doesn't work obviously.
---
Edit*
OK, I just found a long article about that on the lua site. It appears there's no easy way, except interpreting the string byte by byte or using some complex regular expressions.
http://lua-users.org/wiki/LuaUnicode
Re: Box-drawing characters/other UTF-8?
You can easily use "string.sub", taking a substring starting and ending at the first character. For example:
Prints ¥.
Code: Select all
function love.draw()
x = string.sub("¥×¤€ìng? likæ th?s", 1, 1)
love.graphics.print(x, 400, 300)
end
Re: Box-drawing characters/other UTF-8?
I don't think that always works, if the character is utf-8 encoded (for example that ÿ takes 2 bytes and any Chinese character takes 3 bytes).
I figured it out a minute ago though:
I figured it out a minute ago though:
Code: Select all
function utf8iterate(str)
return string.gfind(str, "([%z\1-\127\194-\244][\128-\191]*)")
end
...blahblah
local line = 0
for c in utf8iterate(someutf8string) do
love.graphics.print(c, 10, 40+26*line)
line = line + 1
end
Re: Box-drawing characters/other UTF-8?
Is that...
...REGEX!?!?!?!?!?
(runs away screaming)
...REGEX!?!?!?!?!?
(runs away screaming)
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Box-drawing characters/other UTF-8?
Nope. Chuck Testa.MarekkPie wrote:Is that...
...REGEX!?!?!?!?!?
It's called patterns and less powerful than regular expressions. But they look a bit like them.
Help us help you: attach a .love.
Re: Box-drawing characters/other UTF-8?
Well that's no fun. I understand why string.sub() wouldn't work like you'd think in this case, but there should be an equally simple way to grab a subset of a string. I find that it's a common task.utunnels wrote:Code: Select all
function utf8iterate(str) return string.gfind(str, "([%z\1-\127\194-\244][\128-\191]*)") end ...blahblah local line = 0 for c in utf8iterate(someutf8string) do love.graphics.print(c, 10, 40+26*line) line = line + 1 end
What about a new LoveString type? New string module?
Code: Select all
s = love.string.sub('Hello, 世界', 5, 8)
love.graphics.print(s, 40, 40) --> "o, 世"
Who is online
Users browsing this forum: No registered users and 12 guests