Пользовательские шрифты работают только в первый раз QML

Я действительно борюсь с этим и не уверен, как решить эту проблему.

Вот код

Я запускаю это на Symbian ^ 3 (красавица)

У меня есть 2 пользовательских шрифта, которые мне нужно использовать.

In the example below i have created 3 buttons.
1. Display gurbaniwebthick.ttf
2. Display GurHindi.ttf.
3. Quit.

Это работает на N9

Я нажимаю на первую кнопку, а затем нажимаю на текстовое поле, оно отображает первую строку в Pubjabi.

Нажмите на вторую кнопку и затем нажмите на текстовый файл, он отображает первую строку на хинди.

Когда я закрываю приложение и затем снова запускаю приложение, шрифты не применяются. Как будто он не может заблокировать файл.

Посоветуйте, пожалуйста, как решить эту проблему.

import QtQuick 1.1
import com.nokia.symbian 1.1
Rectangle {
width: 360
height: 640
property string displaystr
property string displaystr1

FontLoader { id: localGurFont; source: "qrc:/gurbaniwebthick.ttf"}
FontLoader { id: localHinFont; source: "qrc:/Gurhindi.ttf"}
Column {
ButtonColumn {
checkedButton: b1
spacing: 5
Button{
id:b1
text:"<> siq nwmu krqw purKu"font.family: localGurFont.name
//font.family: "Gurmukhi";
onClicked: {
displaystr1 =  '<font face= "'+localGurFont.name+'" size="6" color="black">kYsI AwrqI hoie Bv KMfnw qyrI AwrqI ]</font><br><br><font face= "Ariel" size="5" color="red">What A Beautiful Lamp-Lit Worship Service This Is! O Destroyer Of Fear, This Is Your Aartee, You r Worship Service.</font><br><br><font face= "Ariel" size="5" color="blue">Kehsi Aarti Hoee Bhv Khandna Teyri Aarti |</font>';
console.log(displaystr);
}
}
Button{
id:b6
text:"< siq nwmu krqw purKu"font.family: localHinFont.name
onClicked: {

displaystr1 = '<font face= "'+localHinFont.name+'" size="6" color="black">kYsI AwrqI hoie Bv KMfnw qyrI AwrqI ]</font><br><br><font face= "Ariel" size="5" color="red">What A Beautiful Lamp-Lit Worship Service This Is! O Destroyer Of Fear, This Is Your Aartee, You r Worship Service.</font><br><br><font face= "Ariel" size="5" color="blue">Kehsi Aarti Hoee Bhv Khandna Teyri Aarti |</font>';
console.log(displaystr);

}
}

Button{
id:b7
text:"Quit"onClicked: {
Qt.quit();
}
}
}
TextArea {
id: t1
width: 360
height: 360
text: displaystr
wrapMode:Text.WordWrap

MouseArea {
anchors.fill: parent
onClicked: {
displaystr = displaystr1;
console.log(displaystr1);
}
}
}
}
}

Та же проблема с представлением списка
// импортируем QtQuick 1.0 // для S60 5th Edition или Maemo 5
импорт QtQuick 1.1
импорт com.nokia.symbian 1.1

Rectangle {
id: initialRect
height: 640
width: 360
property string fontName
// color: "black"FontLoader { id: localGurFont; source: "qrc:/gurbaniwebthick.ttf"}
FontLoader { id: localHinFont; source: "qrc:/Gurhindi.ttf"}
ListModel {
id: contactModel
ListElement {
baani: 'kYsI AwrqI hoie Bv KMfnw qyrI AwrqI ]'
displayColor: 'black'
displayfont: 'GurbaniWebThick'
}
ListElement {
baani: 'What A Beautiful Lamp-Lit Worship Service This Is! O Destroyer Of Fear, This Is Your Aartee,ou r Worship Service.'
displayColor: 'red'
displayfont: 'Arial'
}
ListElement {
baani: 'Kehsi Aarti Hoee Bhv Khandna Teyri Aarti |'
displayColor: 'blue'
displayfont: 'Arial'
}
ListElement {
baani: 'kYsI AwrqI hoie Bv KMfnw qyrI AwrqI ]'
displayColor: 'black'
displayfont: 'GurbaniWebThick'
}
ListElement {
baani: 'What A Beautiful Lamp-Lit Worship Service This Is! O Destroyer Of Fear, This Is Your Aartee,ou r Worship Service.'
displayColor: 'red'
displayfont: 'Arial'
}
ListElement {
baani: 'Kehsi Aarti Hoee Bhv Khandna Teyri Aarti |'
displayColor: 'blue'
displayfont: 'Arial'
}
}

Component {
id: baaniDelegate
Item {
width: parent.width ; height:parent.height/contactModel.count
Text {
width: parent.width
text: baani
font.family: displayfont
color: displayColor
wrapMode:  Text.WordWrap
}
}
}ListView{

anchors.fill: parent
model: contactModel
delegate: baaniDelegate
// highlight: Rectangle { color: "lightsteelblue"; radius:5}
// focus: true
}
Button{
id:b7
text:"Quit"onClicked: {
Qt.quit();
localHinFont.deleteLater;
localGurFont.deleteLater;
localGurFont.Null;
localHinFont.Null;
}
}
}

1

Решение

решаемая

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

Убедитесь, что вы перезагрузите телефон.

.про файл

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
1

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]