1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFont demo
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
19 // for all others, include the necessary headers (this file is usually all you
20 // need because it includes almost all standard wxWidgets headers
27 #include "wx/choicdlg.h"
28 #include "wx/fontdlg.h"
29 #include "wx/fontenum.h"
30 #include "wx/fontmap.h"
31 #include "wx/encconv.h"
32 #include "wx/splitter.h"
33 #include "wx/textfile.h"
35 #include "../sample.xpm"
39 #include "wx/mac/fontdlg.h"
42 // used as title for several dialog boxes
43 static const wxChar SAMPLE_TITLE
[] = "wxWidgets Font Sample";
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 // Define a new application type, each program should derive a class from wxApp
50 class MyApp
: public wxApp
53 // override base class virtuals
54 // ----------------------------
56 // this one is called on application startup and is a good place for the app
57 // initialization (doing it here and not in the ctor allows to have an error
58 // return: if OnInit() returns false, the application terminates)
59 virtual bool OnInit();
62 // MyCanvas is a canvas on which we show the font sample
63 class MyCanvas
: public wxWindow
66 MyCanvas( wxWindow
*parent
);
67 virtual ~MyCanvas(){};
69 // accessors for the frame
70 const wxFont
& GetTextFont() const { return m_font
; }
71 const wxColour
& GetColour() const { return m_colour
; }
72 void SetTextFont(const wxFont
& font
) { m_font
= font
; }
73 void SetColour(const wxColour
& colour
) { m_colour
= colour
; }
76 void OnPaint( wxPaintEvent
&event
);
85 // Define a new frame type: this is going to be our main frame
86 class MyFrame
: public wxFrame
90 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
93 MyCanvas
*GetCanvas() const { return m_canvas
; }
95 // event handlers (these functions should _not_ be virtual)
96 void OnQuit(wxCommandEvent
& event
);
97 void OnAbout(wxCommandEvent
& event
);
99 void OnIncFont(wxCommandEvent
& WXUNUSED(event
)) { DoResizeFont(+2); }
100 void OnDecFont(wxCommandEvent
& WXUNUSED(event
)) { DoResizeFont(-2); }
102 void OnBold(wxCommandEvent
& event
);
103 void OnItalic(wxCommandEvent
& event
);
104 void OnUnderline(wxCommandEvent
& event
);
106 void OnwxPointerFont(wxCommandEvent
& event
);
108 void OnViewMsg(wxCommandEvent
& event
);
109 void OnSelectFont(wxCommandEvent
& event
);
110 void OnEnumerateFamiliesForEncoding(wxCommandEvent
& event
);
111 void OnEnumerateFamilies(wxCommandEvent
& WXUNUSED(event
))
112 { DoEnumerateFamilies(false); }
113 void OnEnumerateFixedFamilies(wxCommandEvent
& WXUNUSED(event
))
114 { DoEnumerateFamilies(true); }
115 void OnEnumerateEncodings(wxCommandEvent
& event
);
117 void OnSetNativeDesc(wxCommandEvent
& event
);
118 void OnSetNativeUserDesc(wxCommandEvent
& event
);
119 void OnSetFaceName(wxCommandEvent
& event
);
120 void OnSetEncoding(wxCommandEvent
& event
);
123 bool DoEnumerateFamilies(bool fixedWidthOnly
,
124 wxFontEncoding encoding
= wxFONTENCODING_SYSTEM
,
125 bool silent
= false);
127 void DoResizeFont(int diff
);
128 void DoChangeFont(const wxFont
& font
, const wxColour
& col
= wxNullColour
);
130 // ask the user to choose an encoding and return it or
131 // wxFONTENCODING_SYSTEM if the dialog was cancelled
132 wxFontEncoding
GetEncodingFromUser();
135 size_t m_fontSize
; // in points
137 wxTextCtrl
*m_textctrl
;
141 // any class wishing to process wxWidgets events must use this macro
142 DECLARE_EVENT_TABLE()
145 // ----------------------------------------------------------------------------
147 // ----------------------------------------------------------------------------
149 // IDs for the controls and the menu commands
168 Font_EnumFamiliesForEncoding
,
170 Font_EnumFixedFamilies
,
173 Font_SetNativeUserDesc
,
179 // ----------------------------------------------------------------------------
180 // event tables and other macros for wxWidgets
181 // ----------------------------------------------------------------------------
183 // the event tables connect the wxWidgets events with the functions (event
184 // handlers) which process them. It can be also done at run-time, but for the
185 // simple menu events like this the static method is much simpler.
186 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
187 EVT_MENU(Font_Quit
, MyFrame::OnQuit
)
188 EVT_MENU(Font_ViewMsg
, MyFrame::OnViewMsg
)
189 EVT_MENU(Font_About
, MyFrame::OnAbout
)
191 EVT_MENU(Font_IncSize
, MyFrame::OnIncFont
)
192 EVT_MENU(Font_DecSize
, MyFrame::OnDecFont
)
193 EVT_MENU(Font_Bold
, MyFrame::OnBold
)
194 EVT_MENU(Font_Italic
, MyFrame::OnItalic
)
195 EVT_MENU(Font_Underlined
, MyFrame::OnUnderline
)
197 EVT_MENU(Font_wxNORMAL_FONT
, MyFrame::OnwxPointerFont
)
198 EVT_MENU(Font_wxSMALL_FONT
, MyFrame::OnwxPointerFont
)
199 EVT_MENU(Font_wxITALIC_FONT
, MyFrame::OnwxPointerFont
)
200 EVT_MENU(Font_wxSWISS_FONT
, MyFrame::OnwxPointerFont
)
203 EVT_MENU(Font_SetNativeDesc
, MyFrame::OnSetNativeDesc
)
204 EVT_MENU(Font_SetNativeUserDesc
, MyFrame::OnSetNativeUserDesc
)
205 EVT_MENU(Font_SetFaceName
, MyFrame::OnSetFaceName
)
206 EVT_MENU(Font_SetEncoding
, MyFrame::OnSetEncoding
)
208 EVT_MENU(Font_Choose
, MyFrame::OnSelectFont
)
209 EVT_MENU(Font_EnumFamiliesForEncoding
, MyFrame::OnEnumerateFamiliesForEncoding
)
210 EVT_MENU(Font_EnumFamilies
, MyFrame::OnEnumerateFamilies
)
211 EVT_MENU(Font_EnumFixedFamilies
, MyFrame::OnEnumerateFixedFamilies
)
212 EVT_MENU(Font_EnumEncodings
, MyFrame::OnEnumerateEncodings
)
215 // Create a new application object: this macro will allow wxWidgets to create
216 // the application object during program execution (it's better than using a
217 // static object for many reasons) and also declares the accessor function
218 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
222 // ============================================================================
224 // ============================================================================
226 // ----------------------------------------------------------------------------
227 // the application class
228 // ----------------------------------------------------------------------------
230 // `Main program' equivalent: the program execution "starts" here
233 // Create the main application window
234 MyFrame
*frame
= new MyFrame(wxT("Font wxWidgets demo"),
235 wxPoint(50, 50), wxSize(600, 400));
237 // Show it and tell the application that it's our main window
241 // success: wxApp::OnRun() will be called which will enter the main message
242 // loop and the application will run. If we returned 'false' here, the
243 // application would exit immediately.
247 // ----------------------------------------------------------------------------
249 // ----------------------------------------------------------------------------
252 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
253 : wxFrame((wxFrame
*)NULL
, wxID_ANY
, title
, pos
, size
), m_textctrl(NULL
)
257 SetIcon(wxIcon(sample_xpm
));
260 wxMenu
*menuFile
= new wxMenu
;
262 menuFile
->Append(Font_ViewMsg
, wxT("&View...\tCtrl-V"),
263 wxT("View an email message file"));
264 menuFile
->AppendSeparator();
265 menuFile
->Append(Font_About
, wxT("&About...\tCtrl-A"), wxT("Show about dialog"));
266 menuFile
->AppendSeparator();
267 menuFile
->Append(Font_Quit
, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
269 wxMenu
*menuFont
= new wxMenu
;
270 menuFont
->Append(Font_IncSize
, wxT("&Increase font size by 2 points\tCtrl-I"));
271 menuFont
->Append(Font_DecSize
, wxT("&Decrease font size by 2 points\tCtrl-D"));
272 menuFont
->AppendSeparator();
273 menuFont
->AppendCheckItem(Font_Bold
, wxT("&Bold\tCtrl-B"), wxT("Toggle bold state"));
274 menuFont
->AppendCheckItem(Font_Italic
, wxT("&Oblique\tCtrl-O"), wxT("Toggle italic state"));
275 menuFont
->AppendCheckItem(Font_Underlined
, wxT("&Underlined\tCtrl-U"),
276 wxT("Toggle underlined state"));
278 menuFont
->AppendSeparator();
279 menuFont
->Append(Font_SetNativeDesc
,
280 wxT("Set native font &description\tShift-Ctrl-D"));
281 menuFont
->Append(Font_SetNativeUserDesc
,
282 wxT("Set &user font description\tShift-Ctrl-U"));
283 menuFont
->Append(Font_SetFaceName
, wxT("Check font face name"));
284 menuFont
->Append(Font_SetEncoding
, wxT("Set font &encoding\tShift-Ctrl-E"));
286 wxMenu
*menuSelect
= new wxMenu
;
287 menuSelect
->Append(Font_Choose
, wxT("&Select font...\tCtrl-S"),
288 wxT("Select a standard font"));
290 wxMenu
*menuStdFonts
= new wxMenu
;
291 menuStdFonts
->Append(Font_wxNORMAL_FONT
, wxT("wxNORMAL_FONT"), wxT("Normal font used by wxWidgets"));
292 menuStdFonts
->Append(Font_wxSMALL_FONT
, wxT("wxSMALL_FONT"), wxT("Small font used by wxWidgets"));
293 menuStdFonts
->Append(Font_wxITALIC_FONT
, wxT("wxITALIC_FONT"), wxT("Italic font used by wxWidgets"));
294 menuStdFonts
->Append(Font_wxSWISS_FONT
, wxT("wxSWISS_FONT"), wxT("Swiss font used by wxWidgets"));
295 menuSelect
->Append(Font_Standard
, wxT("Standar&d fonts"), menuStdFonts
);
297 menuSelect
->AppendSeparator();
298 menuSelect
->Append(Font_EnumFamilies
, wxT("Enumerate font &families\tCtrl-F"));
299 menuSelect
->Append(Font_EnumFixedFamilies
,
300 wxT("Enumerate fi&xed font families\tCtrl-X"));
301 menuSelect
->Append(Font_EnumEncodings
,
302 wxT("Enumerate &encodings\tCtrl-E"));
303 menuSelect
->Append(Font_EnumFamiliesForEncoding
,
304 wxT("Find font for en&coding...\tCtrl-C"),
305 wxT("Find font families for given encoding"));
307 // now append the freshly created menu to the menu bar...
308 wxMenuBar
*menuBar
= new wxMenuBar
;
309 menuBar
->Append(menuFile
, wxT("&File"));
310 menuBar
->Append(menuFont
, wxT("F&ont"));
311 menuBar
->Append(menuSelect
, wxT("&Select"));
313 // ... and attach this menu bar to the frame
316 wxSplitterWindow
*splitter
= new wxSplitterWindow(this);
318 m_textctrl
= new wxTextCtrl(splitter
, wxID_ANY
,
319 wxT("Paste text here to see how it looks\nlike in the given font"),
320 wxDefaultPosition
, wxDefaultSize
,
323 m_canvas
= new MyCanvas(splitter
);
325 splitter
->SplitHorizontally(m_textctrl
, m_canvas
, 100);
328 // create a status bar just for fun (by default with 1 pane only)
330 SetStatusText(wxT("Welcome to wxWidgets font demo!"));
331 #endif // wxUSE_STATUSBAR
334 // --------------------------------------------------------
336 class MyEncodingEnumerator
: public wxFontEnumerator
339 MyEncodingEnumerator()
342 const wxString
& GetText() const
346 virtual bool OnFontEncoding(const wxString
& facename
,
347 const wxString
& encoding
)
350 text
.Printf(wxT("Encoding %u: %s (available in facename '%s')\n"),
351 (unsigned int) ++m_n
, encoding
.c_str(), facename
.c_str());
361 void MyFrame::OnEnumerateEncodings(wxCommandEvent
& WXUNUSED(event
))
363 MyEncodingEnumerator fontEnumerator
;
365 fontEnumerator
.EnumerateEncodings();
367 wxLogMessage(wxT("Enumerating all available encodings:\n%s"),
368 fontEnumerator
.GetText().c_str());
371 // -------------------------------------------------------------
373 class MyFontEnumerator
: public wxFontEnumerator
377 { return !m_facenames
.IsEmpty(); }
379 const wxArrayString
& GetFacenames() const
380 { return m_facenames
; }
383 virtual bool OnFacename(const wxString
& facename
)
385 m_facenames
.Add(facename
);
390 wxArrayString m_facenames
;
393 bool MyFrame::DoEnumerateFamilies(bool fixedWidthOnly
,
394 wxFontEncoding encoding
,
397 MyFontEnumerator fontEnumerator
;
399 fontEnumerator
.EnumerateFacenames(encoding
, fixedWidthOnly
);
401 if ( fontEnumerator
.GotAny() )
403 int nFacenames
= fontEnumerator
.GetFacenames().GetCount();
406 wxLogStatus(this, wxT("Found %d %sfonts"),
407 nFacenames
, fixedWidthOnly
? wxT("fixed width ") : wxT(""));
415 facename
= fontEnumerator
.GetFacenames().Item(0);
419 // let the user choose
420 wxString
*facenames
= new wxString
[nFacenames
];
422 for ( n
= 0; n
< nFacenames
; n
++ )
423 facenames
[n
] = fontEnumerator
.GetFacenames().Item(n
);
425 n
= wxGetSingleChoiceIndex
427 wxT("Choose a facename"),
435 facename
= facenames
[n
];
440 if ( !facename
.empty() )
442 wxFont
font(12, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
,
443 wxFONTWEIGHT_NORMAL
, false, facename
, encoding
);
452 wxLogWarning(wxT("No such fonts found."));
458 void MyFrame::OnEnumerateFamiliesForEncoding(wxCommandEvent
& WXUNUSED(event
))
460 wxFontEncoding enc
= GetEncodingFromUser();
461 if ( enc
!= wxFONTENCODING_SYSTEM
)
463 DoEnumerateFamilies(false, enc
);
467 void MyFrame::OnSetNativeDesc(wxCommandEvent
& WXUNUSED(event
))
469 wxString fontInfo
= wxGetTextFromUser
471 wxT("Enter native font string"),
472 wxT("Input font description"),
473 m_canvas
->GetTextFont().GetNativeFontInfoDesc(),
476 if ( fontInfo
.empty() )
477 return; // user clicked "Cancel" - do nothing
480 font
.SetNativeFontInfo(fontInfo
);
483 wxLogError(wxT("Font info string \"%s\" is invalid."),
491 void MyFrame::OnSetFaceName(wxCommandEvent
& WXUNUSED(event
))
493 wxString facename
= GetCanvas()->GetTextFont().GetFaceName();
494 wxString newFaceName
= wxGetTextFromUser(
495 wxT("Here you can edit current font face name."),
496 wxT("Input font facename"), facename
,
498 if (newFaceName
.IsEmpty())
499 return; // user clicked "Cancel" - do nothing
501 wxFont
font(GetCanvas()->GetTextFont());
502 if (font
.SetFaceName(newFaceName
)) // change facename only
504 wxASSERT_MSG(font
.Ok(), wxT("The font should now be valid"));
509 wxASSERT_MSG(!font
.Ok(), wxT("The font should now be invalid"));
510 wxMessageBox(wxT("There is no font with such face name..."),
511 wxT("Invalid face name"), wxOK
|wxICON_ERROR
, this);
515 void MyFrame::OnSetNativeUserDesc(wxCommandEvent
& WXUNUSED(event
))
517 wxString fontdesc
= GetCanvas()->GetTextFont().GetNativeFontInfoUserDesc();
518 wxString fontUserInfo
= wxGetTextFromUser(
519 wxT("Here you can edit current font description"),
520 wxT("Input font description"), fontdesc
,
522 if (fontUserInfo
.IsEmpty())
523 return; // user clicked "Cancel" - do nothing
526 if (font
.SetNativeFontInfoUserDesc(fontUserInfo
))
528 wxASSERT_MSG(font
.Ok(), wxT("The font should now be valid"));
533 wxASSERT_MSG(!font
.Ok(), wxT("The font should now be invalid"));
534 wxMessageBox(wxT("Error trying to create a font with such description..."));
538 void MyFrame::OnSetEncoding(wxCommandEvent
& WXUNUSED(event
))
540 wxFontEncoding enc
= GetEncodingFromUser();
541 if ( enc
== wxFONTENCODING_SYSTEM
)
544 wxFont font
= m_canvas
->GetTextFont();
545 font
.SetEncoding(enc
);
549 wxFontEncoding
MyFrame::GetEncodingFromUser()
552 wxArrayInt encodings
;
554 const size_t count
= wxFontMapper::GetSupportedEncodingsCount();
555 names
.reserve(count
);
556 encodings
.reserve(count
);
558 for ( size_t n
= 0; n
< count
; n
++ )
560 wxFontEncoding enc
= wxFontMapper::GetEncoding(n
);
561 encodings
.push_back(enc
);
562 names
.push_back(wxFontMapper::GetEncodingName(enc
));
565 int i
= wxGetSingleChoiceIndex
567 wxT("Choose the encoding"),
573 return i
== -1 ? wxFONTENCODING_SYSTEM
: (wxFontEncoding
)encodings
[i
];
576 void MyFrame::DoResizeFont(int diff
)
578 wxFont font
= m_canvas
->GetTextFont();
580 font
.SetPointSize(font
.GetPointSize() + diff
);
584 void MyFrame::OnBold(wxCommandEvent
& event
)
586 wxFont font
= m_canvas
->GetTextFont();
588 font
.SetWeight(event
.IsChecked() ? wxFONTWEIGHT_BOLD
: wxFONTWEIGHT_NORMAL
);
592 void MyFrame::OnItalic(wxCommandEvent
& event
)
594 wxFont font
= m_canvas
->GetTextFont();
596 font
.SetStyle(event
.IsChecked() ? wxFONTSTYLE_ITALIC
: wxFONTSTYLE_NORMAL
);
600 void MyFrame::OnUnderline(wxCommandEvent
& event
)
602 wxFont font
= m_canvas
->GetTextFont();
604 font
.SetUnderlined(event
.IsChecked());
608 void MyFrame::OnwxPointerFont(wxCommandEvent
& event
)
612 switch ( event
.GetId() )
614 case Font_wxNORMAL_FONT
:
615 font
= *wxNORMAL_FONT
;
618 case Font_wxSMALL_FONT
:
619 font
= *wxSMALL_FONT
;
622 case Font_wxITALIC_FONT
:
623 font
= *wxITALIC_FONT
;
626 case Font_wxSWISS_FONT
:
627 font
= *wxSWISS_FONT
;
631 wxFAIL_MSG( wxT("unknown standard font") );
638 void MyFrame::DoChangeFont(const wxFont
& font
, const wxColour
& col
)
640 m_canvas
->SetTextFont(font
);
642 m_canvas
->SetColour(col
);
645 m_textctrl
->SetFont(font
);
647 m_textctrl
->SetForegroundColour(col
);
649 // update the state of the bold/italic/underlined menu items
650 wxMenuBar
*mbar
= GetMenuBar();
653 mbar
->Check(Font_Bold
, font
.GetWeight() == wxFONTWEIGHT_BOLD
);
654 mbar
->Check(Font_Italic
, font
.GetStyle() == wxFONTSTYLE_ITALIC
);
655 mbar
->Check(Font_Underlined
, font
.GetUnderlined());
659 void MyFrame::OnSelectFont(wxCommandEvent
& WXUNUSED(event
))
662 data
.SetInitialFont(m_canvas
->GetTextFont());
663 data
.SetColour(m_canvas
->GetColour());
665 wxFontDialog
dialog(this, data
);
666 if ( dialog
.ShowModal() == wxID_OK
)
668 wxFontData retData
= dialog
.GetFontData();
669 wxFont font
= retData
.GetChosenFont();
670 wxColour colour
= retData
.GetColour();
672 DoChangeFont(font
, colour
);
676 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
678 // true is to force the frame to close
682 void MyFrame::OnViewMsg(wxCommandEvent
& WXUNUSED(event
))
685 // first, choose the file
686 static wxString s_dir
, s_file
;
687 wxFileDialog
dialog(this, wxT("Open an email message file"),
689 if ( dialog
.ShowModal() != wxID_OK
)
692 // save for the next time
693 s_dir
= dialog
.GetDirectory();
694 s_file
= dialog
.GetFilename();
696 wxString filename
= dialog
.GetPath();
698 // load it and search for Content-Type header
699 wxTextFile
file(filename
);
705 static const wxChar
*prefix
= wxT("Content-Type: text/plain; charset=");
706 const size_t len
= wxStrlen(prefix
);
708 size_t n
, count
= file
.GetLineCount();
709 for ( n
= 0; n
< count
; n
++ )
711 wxString line
= file
[n
];
715 // if it is an email message, headers are over, no need to parse
720 if ( line
.Left(len
) == prefix
)
723 const wxChar
*pc
= line
.c_str() + len
;
724 if ( *pc
== wxT('"') )
727 while ( *pc
&& *pc
!= wxT('"') )
738 wxLogError(wxT("The file '%s' doesn't contain charset information."),
744 // ok, now get the corresponding encoding
745 wxFontEncoding fontenc
= wxFontMapper::Get()->CharsetToEncoding(charset
);
746 if ( fontenc
== wxFONTENCODING_SYSTEM
)
748 wxLogError(wxT("Charset '%s' is unsupported."), charset
.c_str());
752 m_textctrl
->LoadFile(filename
);
754 if ( fontenc
== wxFONTENCODING_UTF8
||
755 !wxFontMapper::Get()->IsEncodingAvailable(fontenc
) )
757 // try to find some similar encoding:
758 wxFontEncoding encAlt
;
759 if ( wxFontMapper::Get()->GetAltForEncoding(fontenc
, &encAlt
) )
761 wxEncodingConverter conv
;
763 if (conv
.Init(fontenc
, encAlt
))
766 m_textctrl
-> SetValue(conv
.Convert(m_textctrl
-> GetValue()));
770 wxLogWarning(wxT("Cannot convert from '%s' to '%s'."),
771 wxFontMapper::GetEncodingDescription(fontenc
).c_str(),
772 wxFontMapper::GetEncodingDescription(encAlt
).c_str());
776 wxLogWarning(wxT("No fonts for encoding '%s' on this system."),
777 wxFontMapper::GetEncodingDescription(fontenc
).c_str());
780 // and now create the correct font
781 if ( !DoEnumerateFamilies(false, fontenc
, true /* silent */) )
783 wxFont
font(12, wxFONTFAMILY_DEFAULT
, wxFONTSTYLE_NORMAL
,
784 wxFONTWEIGHT_NORMAL
, false /* !underlined */,
785 wxEmptyString
/* facename */, fontenc
);
792 wxLogWarning(wxT("No fonts for encoding '%s' on this system."),
793 wxFontMapper::GetEncodingDescription(fontenc
).c_str());
796 #endif // wxUSE_FILEDLG
799 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
801 wxMessageBox(wxT("wxWidgets font demo\n")
802 wxT("(c) 1999 Vadim Zeitlin"),
804 wxOK
| wxICON_INFORMATION
, this);
807 // ----------------------------------------------------------------------------
809 // ----------------------------------------------------------------------------
811 BEGIN_EVENT_TABLE(MyCanvas
, wxWindow
)
812 EVT_PAINT(MyCanvas::OnPaint
)
815 MyCanvas::MyCanvas( wxWindow
*parent
)
816 : wxWindow( parent
, wxID_ANY
),
817 m_colour(*wxRED
), m_font(*wxNORMAL_FONT
)
821 void MyCanvas::OnPaint( wxPaintEvent
&WXUNUSED(event
) )
827 dc
.SetBackground(wxBrush(wxT("white"), wxSOLID
));
830 // one text line height
831 wxCoord hLine
= dc
.GetCharHeight();
833 // the current text origin
837 // output the font name/info
839 fontInfo
.Printf(wxT("Font size is %d points, family: %s, encoding: %s"),
840 m_font
.GetPointSize(),
841 m_font
.GetFamilyString().c_str(),
843 GetEncodingDescription(m_font
.GetEncoding()).c_str());
845 dc
.DrawText(fontInfo
, x
, y
);
848 fontInfo
.Printf(wxT("Style: %s, weight: %s, fixed width: %s"),
849 m_font
.GetStyleString().c_str(),
850 m_font
.GetWeightString().c_str(),
851 m_font
.IsFixedWidth() ? _T("yes") : _T("no"));
853 dc
.DrawText(fontInfo
, x
, y
);
858 const wxNativeFontInfo
*info
= m_font
.GetNativeFontInfo();
861 wxString fontDesc
= m_font
.GetNativeFontInfoUserDesc();
862 fontInfo
.Printf(wxT("Native font info: %s"), fontDesc
.c_str());
864 dc
.DrawText(fontInfo
, x
, y
);
871 // prepare to draw the font
873 dc
.SetTextForeground(m_colour
);
875 // the size of one cell (Normally biggest char + small margin)
876 long maxCharWidth
, maxCharHeight
;
877 dc
.GetTextExtent(wxT("W"), &maxCharWidth
, &maxCharHeight
);
878 int w
= maxCharWidth
+ 5,
879 h
= maxCharHeight
+ 4;
882 // print all font symbols from 32 to 256 in 7 rows of 32 chars each
883 for ( int i
= 0; i
< 7; i
++ )
885 for ( int j
= 0; j
< 32; j
++ )
887 wxChar c
= (wxChar
)(32 * (i
+ 1) + j
);
889 long charWidth
, charHeight
;
890 dc
.GetTextExtent(c
, &charWidth
, &charHeight
);
894 x
+ w
*j
+ (maxCharWidth
- charWidth
) / 2 + 1,
895 y
+ h
*i
+ (maxCharHeight
- charHeight
) / 2
900 // draw the lines between them
901 dc
.SetPen(wxPen(wxColour(_T("blue")), 1, wxSOLID
));
905 for ( l
= 0; l
< 8; l
++ )
907 int yl
= y
+ h
*l
- 2;
908 dc
.DrawLine(x
- 2, yl
, x
+ 32*w
- 1, yl
);
912 for ( l
= 0; l
< 33; l
++ )
914 int xl
= x
+ w
*l
- 2;
915 dc
.DrawLine(xl
, y
- 2, xl
, y
+ 7*h
- 1);