Page 1 of 1

Displaying Unicode text [Solved]

Posted: Tue Sep 05, 2017 6:44 am
by SirDust
Hello all,
I have a simple question, why is it when I run the following piece of code in main.lua, the japanese text in the .txt file does not display properly (the text is displayed as boxes) and how do I fix this?

Code: Select all

love.graphics.setFont(love.graphics.newFont'NotoMono.ttf')
local text = love.filesystem.read'japanese.txt'

function love.draw()
	love.graphics.print(text,0,0)
end
I am using Google's NotoMono font, which does support japanese text.

As you can guess, my larger question is how to display in the love window any string of Unicode text that a font supports.

Re: Displaying Unicode text

Posted: Tue Sep 05, 2017 7:03 am
by raidho36
You need a font that contains relevant characters. Either your font doesn't have kana or kanji characters or your text isn't japanese (and your font is missing those characters anyway).

I've lifted a random kanji font from the internet and tested it with a phrase in japanese i lifted from the same page, and it worked.

Code: Select all

function love.load ( )
	love.graphics.setFont ( love.graphics.newFont ( "senobi.ttf" ) )
end

function love.draw ( )
	love.graphics.print ( "このフォントの使用に関してはすべて無保証とさせていただきます", 10, 10 )
end

Re: Displaying Unicode text

Posted: Tue Sep 05, 2017 7:51 am
by SirDust
Whoops, I didn't realize that the version of the font I was using didn't support Japanese text, now that I found the Japanese version, it's working fine now. Thanks.