Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Custom fonts only works the first time

    QML and Qt Quick
    1
    2
    1622
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      Alvinder last edited by

      Guys,

      I am really struggling with this and not sure how to solve this issue.

      Here is the code.

      I am running this on symbian ^3 (belle). Works on N9 no issues.

      I have 2 custom fonts that i need to use.

      In the example below i have created 3 buttons.

      1. Display gurbaniwebthick.ttf
      2. Display GurHindi.ttf.
      3. Quit.

      I click on the first button and then click on text filed it displays the first line in Pubjabi.
      Click on the second button and then click on the text filed it displays the first line in Hindi.

      When i quit the app and then run the app again the fonts are not applied. Its like it can't get a lock on the file.

      Please advise how to solve this issue.

      Regards

      @
      // import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
      import QtQuick 1.1
      import com.nokia.symbian 1.1

      main.qml

      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);
                  }
              }
          }
      }
      

      }

      @

      Project File

      Add more folders to ship with the application, here

      folder_01.source = qml/testfont
      folder_01.target = qml
      DEPLOYMENTFOLDERS = folder_01

      Additional import path used to resolve QML modules in Creator's code model

      QML_IMPORT_PATH =

      #symbian:TARGET.UID3 = 0xE404178B

      Smart Installer package's UID

      This UID is from the protected range and therefore the package will

      fail to install if self-signed. By default qmake uses the unprotected

      range value if unprotected UID is defined for the application and

      0x2002CCCF value if protected UID is given to the application

      #symbian:DEPLOYMENT.installer_header = 0x2002CCCF

      Allow network access on Symbian

      symbian:TARGET.CAPABILITY += NetworkServices

      If your application uses the Qt Mobility libraries, uncomment the following

      lines and add the respective components to the MOBILITY variable.

      CONFIG += mobility

      MOBILITY +=

      Speed up launching on MeeGo/Harmattan when using applauncherd daemon

      CONFIG += qdeclarative-boostable

      Add dependency to Symbian components

      CONFIG += qt-components

      symbian {
      my_deployment.pkg_prerules +=
      "; Dependency to Symbian Qt Quick components"
      "(0x200346de), 1, 1, 0, {"Qt Quick components"}"
      #ICON= c:\QTproj\QTDeploy\GurbaniExplorer.svg
      TARGET.UID3 = 0xE404178B
      fonts.source = C:\QTproj\QTDeploy\gurbaniwebthick.ttf c:\QTProj\QTDeploy\Gurhindi.ttf
      fonts.path = C:\QTproj\QTDeploy
      fonts.target = font
      DEPLOYMENTFOLDERS += fonts

      INSTALLS += TARGET
      DEPLOYMENT += my_deployment

      }

      The .cpp file which was generated for your project. Feel free to hack it.

      SOURCES += main.cpp

      Please do not modify the following two lines. Required for deployment.

      include(qmlapplicationviewer/qmlapplicationviewer.pri)
      qtcAddDeployment()

      OTHER_FILES +=
      qtc_packaging/debian_harmattan/rules
      qtc_packaging/debian_harmattan/README
      qtc_packaging/debian_harmattan/manifest.aegis
      qtc_packaging/debian_harmattan/copyright
      qtc_packaging/debian_harmattan/control
      qtc_packaging/debian_harmattan/compat
      qtc_packaging/debian_harmattan/changelog
      qtc_packaging/debian_fremantle/rules
      qtc_packaging/debian_fremantle/README
      qtc_packaging/debian_fremantle/copyright
      qtc_packaging/debian_fremantle/control
      qtc_packaging/debian_fremantle/compat
      qtc_packaging/debian_fremantle/changelog

      RESOURCES +=
      testfont.qrc

      1 Reply Last reply Reply Quote 0
      • A
        Alvinder last edited by

        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&#40;id&#41;;
        }
        
        QStringList loadedFonts() {
            
            QStringList fonts;
            TRAPD(err, listFontsL(fonts));
            
            qt_symbian_throwIfError(err);
            return fonts;
        }
        
        void load(QString  path) {
            
            
            qDebug() <<";"<<path<<";";
            TPtrC fontFile&#40;path.utf16(&#41;, path.length());
            //    TPtrC fontFile&#40;qt_QString2TPtrC(path&#41;);
            //TPtrC fontFile&#40;path, path.length(&#41;);
            qDebug()<<"path" << path.utf16() << "length" <<path.length();
            
            
            int fontId;
            int err = m_screenDevice->AddFile&#40;fontFile, fontId&#41;;
            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

        1 Reply Last reply Reply Quote 0
        • First post
          Last post