wxFontData as wxString

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 334
Joined: Wed Jan 20, 2010 1:15 pm

wxFontData as wxString

Post by dkaip »

There is a sort way to save all wxFontData and then load the string and construct wxFontData from that string?
Thanks
Jim
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxFontData as wxString

Post by doublemax »

wxFont::GetNativeFontInfoDesc() and wxFont::SetNativeFontInfo()
Use the source, Luke!
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 334
Joined: Wed Jan 20, 2010 1:15 pm

Re: wxFontData as wxString

Post by dkaip »

Hello, thanks, but after data=wxFontData type object add choosing font and then i am taking error ..
../src/common/fontcmn.cpp(321): assert "IsOk()" failed in GetNativeFontInfoDesc(): invalid font
Any Idea why? Compilation is ok.

Code: Select all

wxFontDialog fnt(this, data);
    if ( fnt.ShowModal() == wxID_OK )
    {
        data = fnt.GetFontData();
    }
    wxString f=data.GetInitialFont().GetNativeFontInfoDesc();
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxFontData as wxString

Post by doublemax »

This has nothing to do with GetNativeFontInfoDesc(), you just have to make sure the font is valid.

Use GetChosenFont() instead of GetInitialFont(), of course this is only valid if ShowModal returned wxID_OK.
Use the source, Luke!
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 334
Joined: Wed Jan 20, 2010 1:15 pm

Re: wxFontData as wxString

Post by dkaip »

Thanks very much.
Works fine.
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 334
Joined: Wed Jan 20, 2010 1:15 pm

Re: wxFontData as wxString

Post by dkaip »

Hello loosing my code, i just make a new, but i have bugs.
In code i haven’t error in compiling and running .., but at dc text is ok, but with no font tha i have choose.
Any wrong in code?
Thank's
Jim

Code: Select all

wxFontData data;
wxFontDialog fnt(this, data);
if ( fnt.ShowModal() != wxID_OK )return;
data = fnt.GetFontData();
wxString FontData=wxToString(data.GetInitialFont());
------------------------
in other place ...
wxDC* dc;
wxFont font;
wxFromString(FontData,&font);
dc->SetFont(font); /// no error in compiling and running ..
Ok Just find
I just find, just must put data.GetChosenFont().GetNativeFontInfoDesc();
or
FontData=wxToString(data.GetChosenFont());
Post Reply