Solved
SymbianFontLoader.h
@
#ifndef SYMBIANFONTLOADER_H
#define SYMBIANFONTLOADER_H
#include <QString>
#include <coemain.h>
#include <w32std.h>
#include <badesca.h>
#include <gulutil.h>
class SymbianFontLoader
{
public:
SymbianFontLoader(bool retainFonts = false) {
m_retainFonts = retainFonts;
m_screenDevice = CCoeEnv::Static()->ScreenDevice();
}
~SymbianFontLoader() {
if (!m_retainFonts)
foreach(int id, m_fontIds)
m_screenDevice->RemoveFile(id);
}
QStringList loadedFonts() {
QStringList fonts;
TRAPD(err, listFontsL(fonts));
qt_symbian_throwIfError(err);
return fonts;
}
void load(QString path) {
qDebug() <<";"<<path<<";";
TPtrC fontFile(path.utf16(), path.length());
// TPtrC fontFile(qt_QString2TPtrC(path));
//TPtrC fontFile(path, path.length());
qDebug()<<"path" << path.utf16() << "length" <<path.length();
int fontId;
int err = m_screenDevice->AddFile(fontFile, fontId);
qDebug() <<err;
qt_symbian_throwIfError(err);
qDebug() << "after error";
if (!m_retainFonts)
m_fontIds << fontId;
}
private:
void listFontsL(QStringList& fonts) {
CDesCArrayFlat *fontNames = new (ELeave) CDesCArrayFlat(5);
CleanupStack::PushL(fontNames);
FontUtils::GetAvailableFontsL(*m_screenDevice, *fontNames, EGulAllFonts);
int fontCount = fontNames->Length();
for (int i=0; i < fontCount; i++) {
TPtrC fontName = fontNames->MdcaPoint(i);
QString font = QString::fromUtf16(fontName.Ptr(), fontName.Length());
fonts << font;
}
CleanupStack::PopAndDestroy();
}
private:
CWsScreenDevice* m_screenDevice;
bool m_retainFonts;
QList<int> m_fontIds;
};
#endif // SYMBIANFONTLOADER_H
@
main.cpp
@
#ifdef Q_OS_SYMBIAN
SymbianFontLoader fontLoader(true);
fontLoader.load("C:\\data\\2006126c\\gurbaniwebthick.ttf");
fontLoader.load("C:\\data\\2006126c\\Gurhindi.ttf");
#endif
@
Make sure you restart the phone.
.pro file
LIBS += -lcone -lws32 -lbafl -legul
font_files.pkg_postrules += ""C:\QTproj\QTDeploy\gurbaniwebthick.ttf" - "C:\data\2006126c\gurbaniwebthick.ttf""
font_files.pkg_postrules += ""C:\QTproj\QTDeploy\Gurhindi.ttf" - "C:\data\2006126c\Gurhindi.ttf""
DEPLOYMENT += font_files my_deployment