How to display Unicode with FLTK?
Asked Answered
R

1

6

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 )

Repetitive answered 5/10, 2013 at 14:27 Comment(0)
C
5

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"кошка 日本国");
Coracoid answered 7/10, 2013 at 13:30 Comment(4)
Note that the last bits require the compiler to understand the encoding of the source file containing the string literal.Hydric
Thank you. In light of your answer I've taken the time to educate myself about Unicode.Repetitive
@rubenvb: yes, and more than that: for the next to last example the compiler must support UTF-8 as its narrow execution character set, and e.g. Visual C++ does not, and for the last example the compiler must support the C++11 u8 literal prefix, and e.g. Visual C++ does not. In short those are unportable examples. Wide string literals are portable but they must be converted to UTF-8 at run time.Lactic
That said, using UTF-8 as a general convention for char based strings is pretty *nix-specific, a bad choice for a portable GUI framework, so it's very understandable that @Repetitive didn't grok it at first sight (I generally fail to understand, at first, things that don't make sense, because I expect one of more meaningful ways I know of, or else something entirely new to me).Lactic

© 2022 - 2024 — McMap. All rights reserved.