TTF Introduction
TTF (Truetypefont) is a font file format jointly launched by Apple and Microsoft, and TTF has become one of the most commonly used font file representations since Windows became popular for more than 20 of years. The biggest advantage of TrueType fonts is that you can easily convert the font contour to a curve, you can fill the curve, make a variety of colors and effects, it can be further distorted, make special effect font, so often used to make some title word or pattern word.
There are two criteria used by the desktop publishing system: PostScript and TrueType fonts. Both of these font standards describe the font contour in a curved way, so you can output a very high quality glyph. TrueType fonts are also used as a postscript to display the word font, the font companies have both the standard products. So when you use TrueType fonts to make a layout, you can still replace it with the PostScript font output. QT Example
Because I am in the embedded Linux platform to develop an interface program, need to display Chinese fonts, so download the Liheipro.ttf to use. So let's take a look at what should be done in Qt.
(TTF font path is/home/root/seat_imx/liheipro.ttf)
The code is as follows:
#include "gytboxwidget.h"
#include <QApplication>
#include <QTextCodec>
#include < qfontdatabase>
#include <QFont>
int main (int argc, char *argv[])
{
qapplication A (argc, argv );
Qtextcodec::setcodecforlocale (Qtextcodec::codecforname ("UTF-8"));
QTEXTCODEC::SETCODECFORTR (Qtextcodec::codecforname ("UTF-8"));
Qtextcodec::setcodecforcstrings (Qtextcodec::codecforname ("UTF-8"));
int index = Qfontdatabase::addapplicationfont ("/home/root/seat_imx/liheipro.ttf");
if (index!=-1) {
qstringlist fontlist (qfontdatabase::applicationfontfamilies (index));
/* FONT--Lihei Pro/
if (Fontlist.count () > 0) {
qfont Font_zh (fontlist.at (0));
Font_zh.setbold (false);
A.setfont (Font_zh);
}
Gytboxwidget W;
W.show ();
return a.exec ();
}
Then you can display Chinese, such as:
qlabel *label = new Qlabel (this); Label->settext (TR ("China"));