PDA

View Full Version : Showing font symbols



drhex
4th March 2009, 21:53
Unicode has plenty of symbols in addition to the ordinary ASCII. I've been browsing thru them at http://www.iam.uni-bonn.de/~alt/html/unicode_3.html and would like to use some in my Qt programs.


#include <QApplication>
#include <QFont>
#include <QFontInfo>
#include <QLabel>

int main( int argc, char **argv )
{
QApplication app( argc, argv );

QFont f = app.font();
QFontInfo fi(f);
QLabel *lab = new QLabel;
QChar sym1(0xba, 0x25); // filled rightpointing triangle http://www.iam.uni-bonn.de/~alt/html/unicode_63.html
QChar sym2(0x00, 0x22); // upside-down "A" http://www.iam.uni-bonn.de/~alt/html/unicode_56.html

QFontMetrics fm(f);

QString txt = "QFont: " + f.toString() + "\n" +
"QFontInfo: " + fi.family() + " " + QString::number(fi.pointSize()) + "\n" +
"Substitute list: " + QFont::substitutions().join(", ") +
"\n\nNext" + sym1 + sym2 +
" widths:" + QString::number(fm.width(sym1)) +
" " + QString::number(fm.width(sym2));
lab->setText(txt);
lab->show();

return app.exec();
}

The above program shows the default font and the font actually used. After the word "Next" is inserted two symbols (a filled triangle and and upside-down "A"). This works fine when run on my Ubuntu 8.10 system.

A friend though, tested the same program on Debian Lenny, and there the two special characters were not shown.

Using qtconfig-qt4, we have both set the default font to "DejaVu Sans 9", and that is displayed on the first line when we run the program.
The QFontInfo object differs though: it displays the same "DejaVu Sans 9" font on the machine where the symbols shows correctly, but becomes "Bitstream Charter 9" on the other.

I don't think the problem is that the bitstream font lacks the special characters as I tried with that font as the default on my machine and the special symbols still shows.

My questions are:
1) Why does the QFontInfo-object on the Debian Lenny-machine pick another font, when DejaVu Sans is installed (i.e. it was available from the dropdown-menu in qtconfig-qt4 and he has the same files under /usr/share/fonts/truetype/ttf-dejavu as I have)
2) Why doesn't the symbols show up on the Debian Lenny machine (There are no problems inserting such symbols in an openoffice-document).

The "width" of the invisible symbols, as displayed by the program above, is non-zero. The substitute-lists are the same.