×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    148

    Font changes on device, not on emulator

    I am rendering a box with a number inside it using the following code:
    void CContainer:rawNumberInBox(TInt aIndex, TBool aHighlight) const
    {
    CWindowGc& gc = SystemGc();

    gc.SetPenSize(TSize(1, 1));
    gc.SetPenColor(KRgbBlack);
    gc.SetPenStyle(CGraphicsContext::ESolidPen);

    gc.SetBrushColor(TRgb(230, 230, 230));

    const CFont* font = AknLayoutUtils::FontFromId(EAknLogicalFontPrimaryFont);

    gc.UseFont(font /* iEikonEnv->NormalFont()*/);

    _LIT(KKeys, "123456789");

    // draw the number
    gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    TInt baseline(iKeys[aIndex].Height() /2 + iEikonEnv->NormalFont()->AscentInPixels()/2);
    gc.DrawText(KKeys().Mid(aIndex, 1), iKeys[aIndex], baseline, CGraphicsContext::ECenter);

    gc.DiscardFont();

    // draw the box
    gc.SetBrushStyle(CGraphicsContext::ENullBrush);
    TRect rect(iKeys[aIndex]);
    if (aHighlight)
    {
    gc.SetPenSize(TSize(3, 3));
    rect.Shrink(1, 1);
    }
    gc.DrawRect(rect);
    }

    This routine is called in two situations, from inside a CCoeControl:raw() situation and inside a DrawXXXNow() kind of routine, which looks like below, and which is called when the rect is pressed or not

    void CContainer:rawXXXNow(TInt aIndex, TBool aHighlight) const
    {
    const TRect rect(iKeys[aIndex]);
    Window().Invalidate(rect);
    ActivateGc();
    Window().BeginRedraw(rect);
    DrawNumberInBox(aIndex, aHighlight);
    Window().EndRedraw();
    DeactivateGc();
    }

    On the N97 emulator, this results in a bold number being drawn, when called through Draw() and when called through the DrawXXXNow() routine.

    However, on real devices (5800, N97) a bold number is only drawn when called through Draw(). When called through DrawXXXNow(), the number is not bold.

    Is this a known bug in the platform, because the used font must be the same in both situation.

    Also, the bug happens too the iEikonEnv->NormalFont() is used.

    This problem can be circumvented by only calling DrawNow() on the control, but that is flicker-prone.
    Sander van der Wal
    www.mBrainSoftware.com

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: Font changes on device, not on emulator

    You can check the implementation of DrawNow: http://developer.symbian.org/xref/os...CNTRL.CPP#1523
    Note that although drawing outside of Draw is possible, but the result can easily disappear since the framework may issue a redraw on your control at any time.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    148

    Re: Font changes on device, not on emulator

    Quote Originally Posted by wizard_hu_ View Post
    You can check the implementation of DrawNow: http://developer.symbian.org/xref/os...CNTRL.CPP#1523
    The code is also available the numerous Symbian C++ books that are available.

    Note that although drawing outside of Draw is possible, but the result can easily disappear since the framework may issue a redraw on your control at any time.
    If Draw() is implemented properly (which it is in my case as the control appears fine initially and also after a generic DrawNow(), replacing the DrawXXXNow() calls), then there is no issue at all.

    Also, the DrawXXXNow() pattern has been advocated by Symbian since EPOC 3/Psion days in the previous century, and it works fine in the emulator. The drawing itself is also ok, the only thing is that the font is wrong.
    Sander van der Wal
    www.mBrainSoftware.com

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,689

    Re: Font changes on device, not on emulator

    I do not know, I have no Symbian books dealing with UI stuff, and have not used EPOC. I have not noticed any differences on the first glance, but something has to differ, otherwise the result could not differ neither.
    You could use the normal Draw method (which works), blindly copy the code from the Symbian site, just rename it. Then check if invoking it still produces the intended output. If yes, there is something that matters.
    If not, you can still check how DrawNow (or anything else invoking Draw) gets invoked, perhaps from the event handler in CCoeEnv, and see if it (or CEikonEnv, or their extension CAknEnv) makes any additional settings between getting the event and invoking your Draw, and so on.

Similar Threads

  1. Using the same font on the emulator and device
    By andrew_ramsay in forum Symbian User Interface
    Replies: 3
    Last Post: 2009-01-30, 10:02
  2. How can I determine the font support for a device?
    By iulian_moldovan in forum Symbian
    Replies: 3
    Last Post: 2007-03-06, 08:59
  3. Replies: 0
    Last Post: 2005-09-08, 05:00
  4. installing font in mobile device
    By BanglaSMS in forum General Messaging
    Replies: 0
    Last Post: 2005-07-14, 08:01

Posting Permissions

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