Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display Unicode with FLTK?

According to the FLTK 1.3.2 documentation:

Unicode support was only recently added to FLTK and is still incomplete.

However, the following are supposedly implemented:

It is important to note that the initial implementation of Unicode and UTF-8 in FLTK involves three important areas:

  • provision of Unicode character tables and some simple related functions
  • conversion of char* variables and function parameters from single byte per character representation to UTF-8 variable length
    sequences
  • modifications to the display font interface to accept general Unicode character or UCS code numbers instead of just ASCII or Latin1 characters.

My question is, how do I actually display Unicode on my FLTK controls? I can't find any widget functions which accept Unicode. For example, this is the signature for the label function:

void Fl_Widget::label ( const char * text )

like image 895
JBentley Avatar asked Oct 05 '13 14:10

JBentley


1 Answers

From the link you posted:

FLTK will be entirely converted to Unicode using UTF-8 encoding. If a different encoding is required by the underlying operating system, FLTK will convert the string as needed.

The three bullet points you list are the areas that make up their implementation of Unicode support; That is, these are things they are doing or are planning to do.

  • FLTK implementers are going to provide Unicode character tables and some simple related functions
  • FLTK implementers are going to convert char* variables and function parameters from using SBCS to UTF-8. (That is, they are going to re-implement FLTK functions and variables to treat char* strings as UTF-8.)
  • FLTK implementers going to modify the display font interface to cover more than just ASCII and Latin1 characters.

My question is, how do I actually display Unicode on my FLTK controls? I can't find any widget functions which accept Unicode. For example, this is the signature for the label function:

void Fl_Widget::label ( const char * text )

There are many people that incorrectly use 'Unicode' to mean an encoding that uses 2-byte characters. The FLTK documentation you link to does not make this mistake. Understanding this, the documentation says quite clearly how you use Unicode with the above signature: You pass the Unicode data as a char* string using the UTF-8 encoding. For example if you're using a compiler that uses UTF-8 as the execution encoding:

widget.label("кошка 日本国");

Or if you have a C++11 compiler:

widget.label( u8"кошка 日本国");
like image 172
bames53 Avatar answered Oct 28 '22 21:10

bames53