Loading font with more than 127 Chars

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Wilma456
Prole
Posts: 12
Joined: Mon Jul 03, 2017 2:27 pm
Location: Germany

Loading font with more than 127 Chars

Post by Wilma456 »

I had this code to lode a font:

Code: Select all

local glyphs = ""
for i = 0,127 do
	glyphs = glyphs .. string.char(i)
end
Screen.font = love.graphics.newImageFont("res/font.png",glyphs)
The font has 255 Chars, but If I use a number bigger than 127, I get the error "Error: UTF-8 decoding error: Invalid UTF-8". How can I solve this?
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Loading font with more than 127 Chars

Post by raidho36 »

LOVE uses utf-8 encoding. It's a multi byte encoding compatible with ASCII, which is single byte. It detects multi byte characters by most significant bit - all ASCII characters have this bit set to 0, so if it's 1 then it's a multi byte character. In an unsigned 8 bit integer, most significant bit set to 1 adds 128, and vice versa. If this bit is set, then it expects this and following bytes to encode a utf-8 character. Which in your case they obviously don't.

The solution to your problem is to supply character list manually. Which is what you should do either way.
User avatar
Wilma456
Prole
Posts: 12
Joined: Mon Jul 03, 2017 2:27 pm
Location: Germany

Re: Loading font with more than 127 Chars

Post by Wilma456 »

What did you mena with "supply character list manually"?
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Loading font with more than 127 Chars

Post by raidho36 »

Code: Select all

"abcdefghijklmnopqrstuvwxyz1234567890àáâèéêòóöùúüũ"
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Loading font with more than 127 Chars

Post by zorg »

raidho36 wrote: Thu Aug 03, 2017 3:21 pm

Code: Select all

"abcdefghijklmnopqrstuvwxyz1234567890àáâèéêòóöùúüũ"
Or in other words, write out all the characters you want it to have... and make sure they're saved with UTF-8 encoding (without byte-order mark) otherwise you will have the same problem.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Inny
Party member
Posts: 652
Joined: Fri Jan 30, 2009 3:41 am
Location: New York

Re: Loading font with more than 127 Chars

Post by Inny »

Are you loading 256 characters because you want ANSI line drawing characters?
User avatar
Wilma456
Prole
Posts: 12
Joined: Mon Jul 03, 2017 2:27 pm
Location: Germany

Re: Loading font with more than 127 Chars

Post by Wilma456 »

I'm tying to load this File

I have executed

Code: Select all

for i=1,255 do io.write(string.char(i)) end
in the LUA Console and this was the Output:

Code: Select all




 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~��������������������������������������������������������������������������������������������������������������������������������
The first Chars are not there. It is just space, I can't copy it into my file. Any other Idea?
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Loading font with more than 127 Chars

Post by ivan »

Wilma456 wrote: Thu Aug 10, 2017 5:15 pm The first Chars are not there. It is just space, I can't copy it into my file. Any other Idea?
The first 32 ANSI characters are not printable, so you're not going to be able to draw them using Love2D.
The Lua console will probably fail to display UTF8 too.
If you're trying to draw a string that contains these control characters,
you can take your Lua string and replace the specific chars with something like \1, \2, \3, etc.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Loading font with more than 127 Chars

Post by raidho36 »

Windows terminal could fail to print UTF-8, but I know for a fact that in Linux any terminal would print it just fine.
User avatar
Wilma456
Prole
Posts: 12
Joined: Mon Jul 03, 2017 2:27 pm
Location: Germany

Re: Loading font with more than 127 Chars

Post by Wilma456 »

I've tried it with this:

Code: Select all

local glyphs = "\1\2\3\4\5\6\7\8\9\10\11\12\13\14\15\16\17\18\19\20\21\22\23\24\25\26\27\28\29\30\31\32\33\34\35\36\37\38\39\40\41\42\43\44\45\46\47\48\49\50\51\52\53\54\55\56\57\58\59\60\61\62\63\64\65\66\67\68\69\70\71\72\73\74\75\76\77\78\79\80\81\82\83\84\85\86\87\88\89\90\91\92\93\94\95\96\97\98\99\100\101\102\103\104\105\106\107\108\109\110\111\112\113\114\115\116\117\118\119\120\121\122\123\124\125\126\127\128\129\130\131\132\133\134\135\136\137\138\139\140\141\142\143\144\145\146\147\148\149\150\151\152\153\154\155\156\157\158\159\160\161\162\163\164\165\166\167\168\169\170\171\172\173\174\175\176\177\178\179\180\181\182\183\184\185\186\187\188\189\190\191\192\193\194\195\196\197\198\199\200\201\202\203\204\205\206\207\208\209\210\211\212\213\214\215\216\217\218\219\220\221\222\223\224\225\226\227\228\229\230\231\232\233\234\235\236\237\238\239\240\241\242\243\244\245\246\247\248\249\250\251\252\253\254\255"
Screen.font = love.graphics.newImageFont("res/font.png",glyphs)
But I got the UTF-8 error.
raidho36 wrote: Thu Aug 10, 2017 9:25 pm Windows terminal could fail to print UTF-8, but I know for a fact that in Linux any terminal would print it just fine.
I' using Ubuntu.
Post Reply

Who is online

Users browsing this forum: No registered users and 75 guests