QLabel not displaying supplemental plane unicode characters (U+1000 to U+2000)
-
I've searched the forum and docs for this subject and not found any information on this subject. I want to display a unicode character in QLabel above U+FFFF. I'm able to display legitimate characters below U+FFFF successfully using a code fragment like:
@QString s = QChar(0x34);
ui->label->setText(s);@(ex: displays the number four) where I can set the hex code point to any legitimate vallue below 0xFFFF but if I try to display a code point above 0xFFFF it doesn't work. Since the characters above this range are stored as surrogate pairs using the above code with a value above 0xFFFF doesn't work (in my tests Qt just truncates the hex value). I tried using a code fragment like:
@QChar data[2]={0xd835,0xdc00};
QString s(data,2);
ui->label->setText(s);@0xd835 and 0xdc00 are the surrogate pairs for U+10400 (DESERET CAPITAL LETTER LONG I - just an example) but while this seems to create the surrogate pair successfully the label display doesn't show the correct symbol but only an empty box indicating that the font was not found.
I know the font must be on my system because I can display it using a web browser (⢠ using firefox and 𐐀 using the equivalent on IE). According to the Qt documentation if the character isn't found in the font specified then QFont will search installed fonts until it finds a match but this apparently isn't happening when the code point is above U+FFFF. I tried specifying the font directly but that didn't work either (according to BabelMap the character is available in the font Sagoe UI Symbol which is installed on my system).
I'm at a loss as to how to proceed. Is this a Qt bug or am I doing something wrong?
FYI: I'm using Creator 2.4.0 based on Qt 4.7.4 (32 bit) installed on windows 7.
-
OOPs, I made a transcription error. The surrogate pair (U+D835 U+DC00) corresponds to the code point U+1D400 (part of the Mathematical Alphanumeric Symbols block - the font is located in Cambria math on my system). I also tested this Qt failure in QTextEdit as well as QLabel with the same results.
Browser support for these code points is mixed. Firefox does the best at recognizing and displaying the code points expressed in either hex or decimal form. Since Firefox is able to access the system installed fonts for these code points correctly then Qt should be able to also access them. IE recognizes these code point if expressed in decimal form but not when expressed in hex form. Both Safari and Chrome (and presumably WebKit) fail completely to correctly display thesse code points. A convenient web test page where you can test browser support for these code points can be found "here":http://www.alanwood.net/unicode/mathematical_alphanumeric_symbols.html.
-
Does Qt pick up the necessary font? Neither firefox nor IE use Qt, so who knows whether they are seeing the same fonts.
Also note that Qt 4 is still using Unicode 4.0, so the code points might not yet be assigned in that version of unicode.
-
Tobias:
Thanks for the reply.
Qt picks up the font correctly if the code point is less than U+FFFF. The problem only occurs for me when using surrogate pairs. I'm too new to using Qt and c++ to quickly plow through the code yet but I did download the Firefox code and they use Qt in a number of class definitions so I presume they are using Qt in some fashion. I also noted that they embed some fonts in the code so this may be why they display the greater than U+FFFF code point fonts correctly even through they are using microsoft interfaces to obtain fonts on a windows system.
I have a prior commitment this week I have to honor but starting next week I'm going to try and inspect the Qt code in order to find out exactly why I'm having this problem and see if I can find a solution. Any suggestions on where to start looking would be appreciated.
-
Firefox has a Qt backend, but that is rather stupid, mostly pushing pixels through Qt and getting events from there, transforming them into Mozilla events and pushing them on.
I'd try Qt5 first, AFAIK that was updated to the latest and greatest unicode spec.
-
FYI: I finally was able to display U+FFFF code points by explicitly setting the QLabel, QTextEdit, or QLineEdit style sheets as follows:
@ font-family: "Segoe UI","Cambria Math";@
where Cambria Math is a font that contains the U+FFFF code points on my system.
For some reason the font matching algorithm doesn't find Cambria Math on my system unless the font-family explicitly includes a font with code points above U+FFFF. With the above font-family declaration my text is rendered as Sagoe UI except for the U+FFFF code points which is rendered as Cambria Math. Note: I tried setting various combinations of font families and styles but the above was the only method that worked. Even setting the font-family or directly setting the font to Cambria failed to find the U+FFFF code points.
I also checked on the lastResortFont(). It always came out as arial no matter how the font or font-family is set. I had hoped that I could set the last resort font to Cambria Math so I wouldn't have to worry about setting the stylesheet but I don't know where this parameter is set.