Generates different values after wxMemoryDC::SelectObject()

Ondra Holub ondra.holub at post.cz
Tue Sep 4 01:01:13 PDT 2007


On 3 Zá , 14:13, mar... at gmail.com ("Mario Figueiredo") wrote:
> Hello everyone,
>
> This is a short code snippet that, while not related to my own code,
> better displays the problem and its easier to copy/paste:
>
>     wxMemoryDC dc;
>
>     wxString str("Mountains");
>     wxCoord w, h;
>
>     wxLogDebug(wxT("Before SelectObject():"), NULL);
>
>     for (int i = wxFONTFAMILY_DEFAULT; i != wxFONTFAMILY_UNKNOWN; ++i) {
>
>         dc.SetFont (wxFont(8, i, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
>
>         dc.GetTextExtent(str, &w, &h);
>         wxLogDebug(wxT("%d, %s"), w, dc.GetFont().GetFamilyString());
>
>     }
>
>     wxBitmap base(68, 51); // arbitrary size
>     dc.SelectObject(base);
>
>     wxLogDebug(wxT("After SelectObject():"), NULL);
>
>     for (int i = wxFONTFAMILY_DEFAULT; i != wxFONTFAMILY_UNKNOWN; ++i) {
>
>         dc.SetFont (wxFont(8, i, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
>
>         dc.GetTextExtent(str, &w, &h);
>         wxLogDebug(wxT("%d, %s"), w, dc.GetFont().GetFamilyString());
>
>     }
>
> Result: (Library 2.8.4, Windows XP/SP2, Visual C++ 2005
> Express/SP1/SDK Server 2003 R2)
>
>                 03:10:42: Before SelectObject():
>                 03:10:42: 49, wxDEFAULT
>                 03:10:42: 42, wxDECORATIVE
>                 03:10:42: 49, wxROMAN
>                 03:10:42: 31, wxSCRIPT
>                 03:10:42: 49, wxSWISS
>                 03:10:42: 63, wxMODERN
>                 03:10:42: 63, wxTELETYPE
>                 03:10:42: After SelectObject():
>                 03:10:42: 50, wxDEFAULT
>                 03:10:42: 43, wxDECORATIVE
>                 03:10:42: 49, wxROMAN
>                 03:10:42: 31, wxSCRIPT
>                 03:10:42: 49, wxSWISS
>                 03:10:42: 63, wxMODERN
>                 03:10:42: 63, wxTELETYPE
>
> This is clearly to do with fonts. However, I'm unsure if this is a
> bug, or something else is happening in the background I'm not aware
> of.
>
> I do need to calculate GetTextExtent() before building the bitmap for
> the wxMemoryDC because it will be part of the calculation needed to
> determine that bitmap size. Later I need that value again (which I
> expect to be the same) to actually draw the text on the DC.
>
> So far I've been using wxFONTFAMILY_DEFAULT, but on my particular
> case, I can choose another font family where this behavior is not
> displayed. However I would like to learn more about this issue.
> Particularly if it is a bug, or something else I'm not aware of.
>
> Note that DECORATIVE also display similar behavior.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wx-users-unsubscr... at lists.wxwidgets.org
> For additional commands, e-mail: wx-users-h... at lists.wxwidgets.org

Hi.

I am not sure, but you can try following:

Try to test dc before call of SelectObject with dc.IsOk(). I think
that results of many wxDC methods could be unsure for uninitialized
DC.

You can also try to set another bitmap to wxmemoryDC and run your test
again. I think, you should get same results as in second test (after
SelectObject).

Maybe it has something with antialiasing, I do not know, I am just
guessing.







More information about the wx-users mailing list