I’ve been working on some unicode-aware gui for the OpenFrameworks :
Here is what I got thus fur:
unicode textboxes for inputing multiline autoformated unicode text in mac+ pc
with
drop down semitrasparent menus
lists for inputing values and auto-refresh dropdown menus
copy paste dropdown menu (this is released at my github)
and a calendar that is able to do stuff like goTo(40,“12/2/2014”) that means go to 40 days from that day or to the past etc
also many other useful calendar stuff like get Howmany days a month has etc.
here is an example of the gui in action:
The
Problem:
so in ascci a char = a character
in utf8 a character can be two chars or bytes etc
say you have a unicode text: “κείμενο”
it’s not an array of 8 chars but 16+
so let’s say you place your cursor at the end and you pressbackspace
if you only remove one char you will mess up your string , so you need to understand how many bytes / numbers are used to represent that string you are seeing
I’ve tried some ideas I had, but I couldn’t find a way to be 100% accurate
so right now I hard code stuff,
Is there a smart way to do this?
I mean what if you put a Chinese char in the text how do I know when my actual character begins in a utf8 string and where it begins so that I can
place the cursor in the correct place in the array
remove the correct number of bytes ??
here is a video of the problem in action
the bug occurs at the end of the video where I place a “Π” that messed up the hard coded algorithm I used
something irrelevant:
finally got around to create two examples for ofOpenFile function:
if anybody wants to use this:
I’m really really interested on that addon!! Maybe I could give you a hand on that issue.
I actually had to deal with something similar last week because my program was crashing when emojis appeared in a UTF8 string. I didn’t know anything about UTF8 and all so I had to read a lot to find my way. I can reccomend you too good readings:
A very good introduction to the topic:
And a precise answer to how long is each glyph:
I uploaded my sketch (a bit dirty) that I used to understand a bit on the topic. Maybe it will help you to understand some things… It is very simple… just printing values to understand the size of a string and all…
One more thing here. I’m aware that @bakercp is working on the “next level” text tools for OF. I don’t know what is the state of his work but I’m totally confident that he is The Guru about this topic (and everything else;)
yes bakercp is the utf8 guru indeed hopefully one day OF is going to be uft8 aware !
in the meanwhile
I have modified the ofsystemUtils OF files so that OF ofSystemAlert and textinut dialogs are working with non english characters sutils.zip (9.0 KB)
thanks for the
Example-parse_UTF8_string link I am going to study this
it might help me finish what I’ve started , it seems like a good place to start!!
maybe you can take a look at my utf8 ofCopyPaste example
The CopyPaste menu will be part of the textbox it’s unicode aware and works great both on windows and mac
my testing with utf8 strings for the past few months has been bug-free - you can try it as well
I’ve made a couple of textboxes thus far…
some using fontStash auto resize draw multiline and others using a heavily modified ofxTextInputField class… but you need to modify OF, and none of them is 100% perfect thus far I will let you know if I have a breakthrough!
Hey friends – getting really close to dropping the latest utf8 aware ofxFont … I’m rushing to get it done so hopefully we can document it in time for ofBook. I’ll keep you posted … regarding clipboard support, this PR has been sitting around for a long while:
The clipboard code is mostly implemented by glfw on windows for the moment – so I’d dig into GLFW source to see how it deals with … I’m not sure on specifics.
The problem that I see remaining though is with keyboard input.
On Macintosh when you press a key on another language OF (glut) -> ofKeyPressed will return a unicode string with two int numbers or more depending on the bytes of the char
pressing the letter ‘λ’ on a PC Greek widechar keyboard glutKeyboardFunc will return a single number: 235 in our OpenFrameworks::keyPressed (compiled with Codeblocks)
So my question is. is that number remotely correct in any encoding format?
or is it inherently wrong because our app in CB is not compiled like VS wants it to be compiled? (widecharWindows)
AS IS
Can we transform that number to a unicode char λ?
or any other char whatsoever?
it’s really easy to test what I am saying by adding a language on your keyboard in ControlPanel language settings and run the oscText example
so do you think this will only work for windows? i really need this kind of features… but i need them also in mac and with any font type…
did you try to write kanji on it?
Loading specific fonts and drawing Chinese/russian/greek/ whatever text is not an issue, we can do this already, (using ofxUnicode Fontstash etc)
so you can just take the string from the texbox in the video and write a skin above it and you can theoretically do whatever you please with it.
Right now
The problem is inputing text in a PERFECT manner in other languages
OpenFrameworks was created to implement easily OPEN GL
and it does so by using : GLUT (& very recently GLFW )
Glut as is implemented it does not have a way to connect to NStextField
I come from an Obj-c Background , implementing Textboxes is not very difficult but you need to use apple’s NSWINDOW instead of Glut
so theoritically you can achive a crossplatform textbox by using that in the mac code
There is an addon that combines OF with a NSWINDOW : ofxNSWindower
as well. (needs modification to the Core)
So as I see it.
If we want cross a platform textbox Openframeworks needs to officially support NSWINDOW .
Regarding GLFW.
not sure if this is the answer either, seems to have similar if not more issues with GLUT. I think @bakercp and the lads are waiting how the new version goes to see how they make their plans… (?)
If you ask me ofxUnicode +fontStash+ofutf8TruetypeFont should be a part of the CORE
If that happens then it’s just a matter of time till we have a proper powerfull unicode textbox.
I’ve extended a few objective-c classes inside system Utils and overloaded some of their functions so that they can be used in a different way. (attached above openGl)
As is - the core is modified since SystemUtils.cpp is the only place that we are able to call windows or obj-functions, but it’s possible to just move everything to a single addon, we will see. I might not have a choice anyway because I need some values from the main window for the mac vrsion., like knowing if it’s focused or not. and I can’t do it as OF is structured right now. but this is solvable if I move the addon on a higher level , or use pointers etc.
surely the more advanced OF folks can help with these issues if we decide to move this to the core.
anyway
I have everything solved inside my head J, I just need time to sit down and write it,
The positive is that it seems that the text box is working with both Glut and GLFW.
I am making the object by default multiline but a single line version of it can be called using .setMultiline(false)
Also Password mode is available. and ofcourse a scrolbar.
it works just fine I use it all the time
I just never got around to wrap it into official cloths
basically it uses the same philosophy as the iosTextbox in the ios openframeworks,
but works on windows and mac
maybe it should all be merged into one textbox itm