Closed cuinjune closed 5 years ago
I often don't have time to wrap more complicated/obscure parts of Openframeworks, so I simply ignore them. In the past, I have used unicode just fine via UTF8 in simple strings but nothing too complicated. What is your use case? Do you have some sample code of how this works as I've never used ofUnicode or ofAlphabet.
I just wanted to draw non-english texts in ofxLua project. Here's my sample code.
ofApp.cpp
file:
//--------------------------------------------------------------
void ofApp::setup() {
lua.init(true);
lua.addListener(this);
lua.doScript("scripts/unicodeExample.lua", true);
lua.scriptSetup();
}
//--------------------------------------------------------------
void ofApp::update() {
lua.scriptUpdate();
}
//--------------------------------------------------------------
void ofApp::draw() {
lua.scriptDraw();
}
//--------------------------------------------------------------
void ofApp::exit() {
lua.scriptExit();
lua.clear();
}
unicodeExample.lua
file:
font = of.TrueTypeFont()
----------------------------------------------------
function setup()
of.setWindowTitle("unicode example")
of.setBackgroundColor(0, 0, 0)
local settings = of.TrueTypeFontSettings("fonts/gungsuh.ttf", 30)
settings:addRange(of.Unicode.HangulSyllables)
font:load(settings)
end
----------------------------------------------------
function update()
end
----------------------------------------------------
function draw()
of.setColor(255, 255, 255)
font:drawString("안녕하세요", 100, 100)
end
----------------------------------------------------
function exit()
print("script finished")
end
It all seem to work fine except when using of.TrueTypeFontSettings:addRanges()
function which takes an argument std::initializer_list<ofUnicode::range> alphabet
but I think users can just use addRange()
multiple times instead. So I think it's probably okay to not ignore generating these bindings in the graphics.i
interface file. It is just my small opinion.
Ok, that makes sense.
It all seem to work fine except when using of.TrueTypeFontSettings:addRanges() function which takes an argument
std::initializer_list<ofUnicode::range> alphabet
Yeah, it's things like this which I ignore unless I have to deal with them as wrapping CPP iterators, etc is a pain in the ass. We simply use the basic function alternatives.
Fixed in edf4ddc95c479eaa5daf3acf8e4d1701cd6e1bbd.
Note, the ofAlphabet range naming is slightly different: of.Alphabet_Korean
, of.Alphabet_Latin
, etc as this is faked using an enum instead of the std::initializer_list
type.
Also, you can now use addRanges
:
settings:addRanges(of.Alphabet_Korean)
settings:addRanges(of.Alphabet_Latin)
...
font:drawString("hello world", 100, 100)
font:drawString("안녕하세요", 100, 150)
Hi, I wanted to use unicode strings in my
ofxLua
based project and I learned that these unicode related classes are disabled by default. So I openedopenframeworks/graphics.i
file and removed the following lines of code.And then generated bindings using
make desktop LANG=lua NAME=ofBindings
. When I rebuild my project using the new bindings, I could successfully draw a Korean text.May I ask why some of these classes are disabled in swig interface by default even they seem to work fine? Thank you in advance!