×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    May 2007
    Location
    Poland
    Posts
    606

    Custom Font release issue

    Hello,
    I have faced the following problem.
    Using example from wiki : http://wiki.forum.nokia.com/index.php/Custom_font
    I m trying to use my custom ttf font.
    I m loading it to the device using pkg file.

    After using it I call:
    Code:
    iScrDevice->ReleaseFont(myFont);
    iScrDevice->RemoveFile(aid);
    Unfortunately I m unable to uninstall and reinstall my application after closing my application.
    After restarting the device I can remove it without any problem.

    What am I doing wrong?

    Thanks in advance,
    nuker85

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    India
    Posts
    1,174

    Re: Custom Font release issue

    Unfortunately I m unable to uninstall and reinstall my application after closing my application.
    What kind of problem you are facing? Some error message/ phone is getting hanged or something else?

  3. #3
    Registered User
    Join Date
    May 2007
    Location
    Poland
    Posts
    606

    Re: Custom Font release issue

    Unable to delete file
    This is probably because my font file which i load in PKG is still in use in spite of fact that I have called:
    iScrDevice->ReleaseFont(myFont);
    iScrDevice->RemoveFile(aid);
    I ll paste my code:
    Code:
    void CMainContainer::Draw(const TRect& aRect) const
    	{
    
    	CWindowGc& gc = SystemGc();
    	gc.Clear(aRect);
    	CGraphicsDevice* iDevice = iCoeEnv->ScreenDevice();
    	 
    	TFileName iFileName;
    	iFileName.Copy(_L("c:\\data\\testFont.ttf"));
    	 
    	CWsScreenDevice* iScrDevice =iCoeEnv->ScreenDevice();
    	 
    	TInt aid =10001;//use any value 
    	iScrDevice->AddFile(iFileName,aid);
    	 
    	TFontSpec myFontSpec;
    	CFont *iFont;
    	iDevice->GetNearestFontInTwips(iFont,myFontSpec);
    	 
    	gc.UseFont(iFont);
    	gc.SetPenColor(KRgbBlack);
    	gc.DrawText(_L("hello"),TPoint(5,20));
    	
    	gc.SetBrushColor(TRgb(190, 190, 190));
    	gc.SetPenColor(TRgb(190, 190, 190));
    	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    	gc.UseFont(iFont);
    	gc.DrawText(_L("test"),TPoint(20,20));
    
    	iScrDevice->ReleaseFont(iFont);
    	iScrDevice->RemoveFile(aid);
    	}

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    India
    Posts
    1,174

    Re: Custom Font release issue

    In your code you are using below line twice

    Code:
    gc.UseFont(iFont); // used twice while it is already in use
    You are using it twice while deleting only once. So, try to remove its second occurrence as it is already in use and then try on device.

  5. #5
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,168

    Re: Custom Font release issue

    You definitely should not do that in the Draw function. Instead, release the font in destructor, and add it in your ConstructL function. And have the CFont* as your class member variable.

  6. #6
    Registered User
    Join Date
    May 2007
    Location
    Poland
    Posts
    606

    Re: Custom Font release issue

    You definitely should not do that in the Draw function.
    It was just effect of frustration, I have also tried it in such a way:
    Code:
    CMainContainer::~CMainContainer()
    	{
    ...
    	iScrDevice->ReleaseFont(iFont);
    	iScrDevice->RemoveFile(iFontFileId);
    
    ...
    }
    
    void CMainContainer::ConstructL(const TRect& aRect, const CCoeControl* aParent,
    		MEikCommandObserver* aCommandObserver)
    	{
    ...
    	iFileName.Copy(_L("c:\\data\\test.ttf"));
    	iScrDevice = iCoeEnv->ScreenDevice();
    	iFontFileId = 10001;//use any value 
    	iScrDevice->AddFile(iFileName, iFontFileId);
    	TFontSpec myFont(_L("test"), 120);
    	
    	iScrDevice->GetNearestFontInTwips(iFont, myFont);
    ....
    }
    
    void CMainContainer::Draw(const TRect& aRect) const
    	{
    
    	CWindowGc& gc = SystemGc();
    	gc.Clear(aRect);
    	
    	gc.UseFont(iFont);
    	gc.SetPenColor(KRgbBlack);
    	gc.SetBrushColor(KRgbBlack);
    	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    	gc.DrawText(_L("test"),TPoint(20,20));
    	
    ...
    }
    Thanks to it I draw text using this font but I m unable to uninstall application.

    You are using it twice while deleting only once
    I think that using it few times does not make problem because font was initialised only once. As you can see in code above i have also been using it only once but still unable to install

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,751

    Re: Custom Font release issue

    Comments may be a bit confusing. AddFile-RemoveFile are what you should do in ConstructL-destructor, UseFont-DiscardFont pairs are fine in Draw. I do not know if ReleaseFont is really necessary, DiscardFont probably invokes it internally.
    However this polishing attempts probably will not affect the issue.
    Check this one: http://wiki.forum.nokia.com/index.ph...uninstallation - technically you can also put that line into your destructor.

    EDIT: leave UseFont alone, any of you could read its documentation
    When the font is no longer required, use DiscardFont() to free up the memory used. If UseFont() is used again without using DiscardFont() then the previous font is discarded automatically.
    however in this case both fonts are the same, probably nothing happens at all. And these things have no effect when the application is not running anyway.

  8. #8
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    India
    Posts
    1,174

    Re: Custom Font release issue

    I think that using it few times does not make problem because font was initialised only once. As you can see in code above i have also been using it only once but still unable to install
    Yes, it was my mistake. Obviously we can use fonts n number of times which you were doing. Sorry for the inconvenience. May be I did not paid full attention in your code.

  9. #9
    Registered User
    Join Date
    May 2007
    Location
    Poland
    Posts
    606

    Re: Custom Font release issue

    Check this one: http://wiki.forum.nokia.com/index.ph...uninstallation - technically you can also put that line into your destructor.
    I have put it in destructor and it solved my problem. I can now uninstall application without any problem.

    Thanks all for help

Similar Threads

  1. Custom font
    By martin.wainamoinen in forum Mobile Java Media (Graphics & Sounds)
    Replies: 43
    Last Post: 2012-02-06, 06:32
  2. Custom font
    By Gustavo Ferreira in forum Mobile Java General
    Replies: 2
    Last Post: 2010-11-18, 12:18
  3. Replies: 0
    Last Post: 2007-08-08, 15:37
  4. Replies: 3
    Last Post: 2005-01-13, 02:53
  5. custom font
    By tolnaisz in forum Symbian
    Replies: 0
    Last Post: 1970-01-01, 02:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×