From 36f210c81e5f8cdc65b80e57aad0c11bf2d08e63 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 29 Oct 1999 17:54:13 +0000 Subject: [PATCH] 1. added encoding param to wxFontEncoding::EnumFamilies() which allows to get the list of families supporting the given encoding 2. added encoding decoding logic to src/gtk/font.cpp so that now choosing an encoding different from default in GTK+ font selector dialog actually works git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4258 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/fontenum.h | 15 +++- include/wx/spinctrl.h | 3 +- include/wx/utils.h | 7 ++ samples/font/font.cpp | 184 +++++++++++++++++++++++++----------------- src/gtk/font.cpp | 59 +++++++++++--- src/gtk1/font.cpp | 59 +++++++++++--- src/unix/fontenum.cpp | 29 ++++--- src/unix/utilsunx.cpp | 48 ++++++----- 8 files changed, 279 insertions(+), 125 deletions(-) diff --git a/include/wx/fontenum.h b/include/wx/fontenum.h index 78d4371371..97352c7f77 100644 --- a/include/wx/fontenum.h +++ b/include/wx/fontenum.h @@ -25,9 +25,15 @@ class WXDLLEXPORT wxFontEnumerator { public: - // start enumerating font families - will result in OnFontFamily() being - // called for each available font family (unless it returns FALSE) - virtual bool EnumerateFamilies(bool fixedWidthOnly = FALSE); + // start enumerating font families (either all of them or those which + // support the given encoding) - will result in OnFontFamily() being + // called for each available font family (until they are exhausted or + // OnFontFamily returns FALSE) + virtual bool EnumerateFamilies + ( + wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all + bool fixedWidthOnly = FALSE + ); // enumerate the different encodings either for given font family or for // all font families - will result in OnFontEncoding() being called for @@ -46,6 +52,9 @@ public: virtual bool OnFontEncoding(const wxString& WXUNUSED(family), const wxString& WXUNUSED(encoding)) { return FALSE; } + + // virtual dtor for the base class + virtual ~wxFontEnumerator() { } }; #endif // _WX_FONTENUM_H_ diff --git a/include/wx/spinctrl.h b/include/wx/spinctrl.h index db8ddd129f..ee3dcb2c53 100644 --- a/include/wx/spinctrl.h +++ b/include/wx/spinctrl.h @@ -34,6 +34,7 @@ public: virtual int GetMax() const { return m_max; } // operations + virtual void SetValue(const wxString& value) = 0; virtual void SetValue(int val) = 0; virtual void SetRange(int minVal, int maxVal) = 0; @@ -57,7 +58,7 @@ protected: #elif defined(__WXGTK__) #include "wx/gtk/spinctrl.h" #else // Win16 || !Win - #include "wx/generic/spinctrl.h" + #include "wx/generic/spinctlg.h" #endif // platform #endif // _WX_SPINCTRL_H_ diff --git a/include/wx/utils.h b/include/wx/utils.h index 1b63cccae0..08e4575b57 100644 --- a/include/wx/utils.h +++ b/include/wx/utils.h @@ -400,6 +400,13 @@ extern wxNativeFont wxLoadQueryNearestFont(int pointSize, const wxString &facename, wxFontEncoding encoding); +// fills xencoding and xregistry with the X font spec parts for the given +// encoding ('*' if encoding == wxFONTENCODING_SYSTEM) and returns TRUE if any +// fonts with this encoding exist or FALSE if it's unknown (it does *not* mean +// that they don't exist!) +extern bool wxGetXFontEncoding(wxFontEncoding encoding, + wxString *xencoding, wxString *xregistry); + #endif // X || GTK #endif // wxUSE_GUI diff --git a/samples/font/font.cpp b/samples/font/font.cpp index d2764e0367..2873c93ef7 100644 --- a/samples/font/font.cpp +++ b/samples/font/font.cpp @@ -5,7 +5,7 @@ // Modified by: // Created: 30.09.99 // RCS-ID: $Id$ -// Copyright: (c) Vadim Zeitlin +// Copyright: (c) 1999 Vadim Zeitlin // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -24,6 +24,7 @@ #include #endif +#include #include #include @@ -81,41 +82,29 @@ public: void OnQuit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); void OnSelectFont(wxCommandEvent& event); - void OnCreateFont(wxCommandEvent& event); + void OnEnumerateFamiliesForEncoding(wxCommandEvent& event); void OnEnumerateFamilies(wxCommandEvent& WXUNUSED(event)) { DoEnumerateFamilies(FALSE); } void OnEnumerateFixedFamilies(wxCommandEvent& WXUNUSED(event)) { DoEnumerateFamilies(TRUE); } void OnEnumerateEncodings(wxCommandEvent& event); + void OnSize(wxSizeEvent& event); + protected: - void DoEnumerateFamilies(bool fixedWidthOnly); + void DoEnumerateFamilies(bool fixedWidthOnly, + wxFontEncoding encoding = wxFONTENCODING_SYSTEM); + + void Resize(const wxSize& size, const wxFont& font = wxNullFont); - MyCanvas *m_canvas; + wxTextCtrl *m_textctrl; + MyCanvas *m_canvas; private: // any class wishing to process wxWindows events must use this macro DECLARE_EVENT_TABLE() }; -// A custom font dialog which allows to directly edit wxFont proprieties -class MyFontDialog : public wxDialog -{ -public: - MyFontDialog(MyFrame *frame); - - // event handlers - void OnApply(wxCommandEvent& WXUNUSED(event)) { DoApply(); } - -protected: - void DoApply(); - - MyCanvas *m_canvas; - -private: - //DECLARE_EVENT_TABLE() TODO -}; - // ---------------------------------------------------------------------------- // constants // ---------------------------------------------------------------------------- @@ -127,7 +116,7 @@ enum Font_Quit = 1, Font_About, Font_Choose = 100, - Font_Create, + Font_EnumFamiliesForEncoding, Font_EnumFamilies, Font_EnumFixedFamilies, Font_EnumEncodings, @@ -145,10 +134,12 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(Font_Quit, MyFrame::OnQuit) EVT_MENU(Font_About, MyFrame::OnAbout) EVT_MENU(Font_Choose, MyFrame::OnSelectFont) - EVT_MENU(Font_Create, MyFrame::OnCreateFont) + EVT_MENU(Font_EnumFamiliesForEncoding, MyFrame::OnEnumerateFamiliesForEncoding) EVT_MENU(Font_EnumFamilies, MyFrame::OnEnumerateFamilies) EVT_MENU(Font_EnumFixedFamilies, MyFrame::OnEnumerateFixedFamilies) EVT_MENU(Font_EnumEncodings, MyFrame::OnEnumerateEncodings) + + EVT_SIZE(MyFrame::OnSize) END_EVENT_TABLE() // Create a new application object: this macro will allow wxWindows to create @@ -201,14 +192,15 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) wxMenu *menuFont = new wxMenu; menuFont->Append(Font_Choose, "&Select font...\tCtrl-S", "Select a standard font"); - menuFont->Append(Font_Create, "&Create font...\tCtrl-C", - "Create a custom font"); menuFont->AppendSeparator(); menuFont->Append(Font_EnumFamilies, "Enumerate font &families\tCtrl-F"); menuFont->Append(Font_EnumFixedFamilies, "Enumerate f&ixed font families\tCtrl-I"); menuFont->Append(Font_EnumEncodings, "Enumerate &encodings\tCtrl-E"); + menuFont->Append(Font_EnumFamiliesForEncoding, + "Find font for en&coding...\tCtrl-C", + "Find font families for given encoding"); // now append the freshly created menu to the menu bar... wxMenuBar *menuBar = new wxMenuBar; @@ -218,6 +210,12 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) // ... and attach this menu bar to the frame SetMenuBar(menuBar); + m_textctrl = new wxTextCtrl(this, -1, + "Paste text here to see how it looks\n" + "like in the given font", + wxDefaultPosition, wxDefaultSize, + wxTE_MULTILINE); + m_canvas = new MyCanvas(this); // create a status bar just for fun (by default with 1 pane only) @@ -260,13 +258,15 @@ void MyFrame::OnEnumerateEncodings(wxCommandEvent& WXUNUSED(event)) fontEnumerator.GetText().c_str()); } -void MyFrame::DoEnumerateFamilies(bool fixedWidthOnly) +void MyFrame::DoEnumerateFamilies(bool fixedWidthOnly, wxFontEncoding encoding) { class MyFontEnumerator : public wxFontEnumerator { public: MyFontEnumerator() { m_n = 0; } + bool GotAny() const { return m_n; } + const wxString& GetText() const { return m_text; } protected: @@ -285,18 +285,56 @@ void MyFrame::DoEnumerateFamilies(bool fixedWidthOnly) wxString m_text; } fontEnumerator; - fontEnumerator.EnumerateFamilies(fixedWidthOnly); + fontEnumerator.EnumerateFamilies(encoding, fixedWidthOnly); - wxLogMessage("Enumerating %s font families:\n%s", - fixedWidthOnly ? "fixed width" : "all", - fontEnumerator.GetText().c_str()); + if ( fontEnumerator.GotAny() ) + { + wxLogMessage("Enumerating %s font families:\n%s", + fixedWidthOnly ? "fixed width" : "all", + fontEnumerator.GetText().c_str()); + } + else + { + wxLogWarning("No such fonts found."); + } } -void MyFrame::OnCreateFont(wxCommandEvent& WXUNUSED(event)) +void MyFrame::OnEnumerateFamiliesForEncoding(wxCommandEvent& WXUNUSED(event)) { - MyFontDialog dialog(this); - - (void)dialog.ShowModal(); + static wxFontEncoding encodings[] = + { + wxFONTENCODING_ISO8859_1, + wxFONTENCODING_ISO8859_2, + wxFONTENCODING_ISO8859_5, + wxFONTENCODING_ISO8859_7, + wxFONTENCODING_ISO8859_15, + wxFONTENCODING_KOI8, + wxFONTENCODING_CP1250, + wxFONTENCODING_CP1251, + wxFONTENCODING_CP1252, + }; + + static const char *encodingNames[] = + { + "West European (Latin 1)", + "Central European (Latin 2)", + "Cyrillic (Latin 5)", + "Greek (Latin 7)", + "West European new (Latin 0)", + "KOI8-R", + "Windows Latin 2", + "Windows Cyrillic", + "Windows Latin 1", + }; + + int n = wxGetSingleChoiceIndex("Choose an encoding", "Font demo", + WXSIZEOF(encodingNames), encodingNames, + this); + + if ( n != -1 ) + { + DoEnumerateFamilies(FALSE, encodings[n]); + } } void MyFrame::OnSelectFont(wxCommandEvent& WXUNUSED(event)) @@ -309,9 +347,17 @@ void MyFrame::OnSelectFont(wxCommandEvent& WXUNUSED(event)) if ( dialog.ShowModal() == wxID_OK ) { wxFontData retData = dialog.GetFontData(); - m_canvas->SetTextFont(retData.GetChosenFont()); - m_canvas->SetColour(retData.GetColour()); + wxFont font = retData.GetChosenFont(); + wxColour colour = retData.GetColour(); + + Resize(GetSize(), font); + + m_canvas->SetTextFont(font); + m_canvas->SetColour(colour); m_canvas->Refresh(); + + m_textctrl->SetFont(font); + m_textctrl->SetForegroundColour(colour); } } @@ -323,10 +369,37 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { - wxMessageBox("wxWindows font demo.", "About Font", + wxMessageBox("wxWindows font demo\n" + "(c) 1999 Vadim Zeitlin", + "About Font", wxOK | wxICON_INFORMATION, this); } +void MyFrame::OnSize(wxSizeEvent& event) +{ + wxSize size = event.GetSize(); + + Resize(size); +} + +void MyFrame::Resize(const wxSize& size, const wxFont& font) +{ + wxCoord h; + if ( font.Ok() ) + { + wxClientDC dc(this); + dc.SetFont(font); + + h = 4*dc.GetCharHeight() + 4; + } + else + { + h = m_textctrl->GetSize().y; + } + + m_textctrl->SetSize(0, 0, size.x, h); + m_canvas->SetSize(0, h, size.x, size.y - h); +} // ---------------------------------------------------------------------------- // MyCanvas @@ -375,7 +448,7 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) // the origin for our table int x = 5, - y = 2*h + 5; + y = 2*h; // print all font symbols from 32 to 256 in 7 rows of 32 chars each for ( int i = 1; i < 8; i++ ) @@ -405,36 +478,3 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) dc.DrawLine(xl, y, xl, y + 7*h - 2); } } - -// ---------------------------------------------------------------------------- -// MyFontDialog -// ---------------------------------------------------------------------------- - -MyFontDialog::MyFontDialog(MyFrame *frame) - : wxDialog(frame, -1, wxString("Edit font attributes")) -{ - m_canvas = frame->GetCanvas(); - - // create controls - wxSize sizeBtn = wxButton::GetDefaultSize(); - - // TODO - - // position and size the dialog - SetClientSize(4*sizeBtn.x, 10*sizeBtn.y); - Centre(); -} - -void MyFontDialog::DoApply() -{ - wxFont font; //(size, family, style, weight, underlined, face, encoding); - if ( !font.Ok() ) - { - wxLogError("Font creation failed."); - } - else - { - m_canvas->SetTextFont(font); - m_canvas->Refresh(); - } -} diff --git a/src/gtk/font.cpp b/src/gtk/font.cpp index 0457bda88e..738981520b 100644 --- a/src/gtk/font.cpp +++ b/src/gtk/font.cpp @@ -166,9 +166,9 @@ wxFont::wxFont( GdkFont *WXUNUSED(font), char *xFontName ) tn.GetNextToken(); // foundry - M_FONTDATA->m_faceName = tn.GetNextToken(); // courier + M_FONTDATA->m_faceName = tn.GetNextToken(); // family - tmp = tn.GetNextToken().MakeUpper(); + tmp = tn.GetNextToken().MakeUpper(); // weight if (tmp == wxT("BOLD")) M_FONTDATA->m_weight = wxBOLD; if (tmp == wxT("BLACK")) M_FONTDATA->m_weight = wxBOLD; if (tmp == wxT("EXTRABOLD")) M_FONTDATA->m_weight = wxBOLD; @@ -178,12 +178,12 @@ wxFont::wxFont( GdkFont *WXUNUSED(font), char *xFontName ) if (tmp == wxT("LIGHT")) M_FONTDATA->m_weight = wxLIGHT; if (tmp == wxT("THIN")) M_FONTDATA->m_weight = wxLIGHT; - tmp = tn.GetNextToken().MakeUpper(); + tmp = tn.GetNextToken().MakeUpper(); // slant if (tmp == wxT("I")) M_FONTDATA->m_style = wxITALIC; if (tmp == wxT("O")) M_FONTDATA->m_style = wxITALIC; tn.GetNextToken(); // set width - tn.GetNextToken(); // ? + tn.GetNextToken(); // add. style tn.GetNextToken(); // pixel size tmp = tn.GetNextToken(); // pointsize @@ -193,13 +193,50 @@ wxFont::wxFont( GdkFont *WXUNUSED(font), char *xFontName ) tn.GetNextToken(); // x-res tn.GetNextToken(); // y-res - tmp = tn.GetNextToken().MakeUpper(); - if (tmp == wxT("M")) M_FONTDATA->m_family = wxMODERN; - else if (M_FONTDATA->m_faceName == wxT("TIMES")) M_FONTDATA->m_family = wxROMAN; - else if (M_FONTDATA->m_faceName == wxT("HELVETICA")) M_FONTDATA->m_family = wxSWISS; - else if (M_FONTDATA->m_faceName == wxT("LUCIDATYPEWRITER")) M_FONTDATA->m_family = wxTELETYPE; - else if (M_FONTDATA->m_faceName == wxT("LUCIDA")) M_FONTDATA->m_family = wxDECORATIVE; - else if (M_FONTDATA->m_faceName == wxT("UTOPIA")) M_FONTDATA->m_family = wxSCRIPT; + tmp = tn.GetNextToken().MakeUpper(); // spacing + + if (tmp == wxT("M")) + M_FONTDATA->m_family = wxMODERN; + else if (M_FONTDATA->m_faceName == wxT("TIMES")) + M_FONTDATA->m_family = wxROMAN; + else if (M_FONTDATA->m_faceName == wxT("HELVETICA")) + M_FONTDATA->m_family = wxSWISS; + else if (M_FONTDATA->m_faceName == wxT("LUCIDATYPEWRITER")) + M_FONTDATA->m_family = wxTELETYPE; + else if (M_FONTDATA->m_faceName == wxT("LUCIDA")) + M_FONTDATA->m_family = wxDECORATIVE; + else if (M_FONTDATA->m_faceName == wxT("UTOPIA")) + M_FONTDATA->m_family = wxSCRIPT; + + tn.GetNextToken(); // avg width + + // deal with font encoding + wxString registry = tn.GetNextToken().MakeUpper(), + encoding = tn.GetNextToken().MakeUpper(); + + if ( registry == _T("ISO8859") ) + { + int cp; + if ( wxSscanf(encoding, "%d", &cp) == 1 ) + { + M_FONTDATA->m_encoding = + (wxFontEncoding)(wxFONTENCODING_ISO8859_1 + cp - 1); + } + } + else if ( registry == _T("MICROSOFT") ) + { + int cp; + if ( wxSscanf(encoding, "cp125%d", &cp) == 1 ) + { + M_FONTDATA->m_encoding = + (wxFontEncoding)(wxFONTENCODING_CP1250 + cp); + } + } + else if ( registry == _T("KOI8") ) + { + M_FONTDATA->m_encoding = wxFONTENCODING_KOI8; + } + //else: unknown encoding - may be give a warning here? } bool wxFont::Create( int pointSize, diff --git a/src/gtk1/font.cpp b/src/gtk1/font.cpp index 0457bda88e..738981520b 100644 --- a/src/gtk1/font.cpp +++ b/src/gtk1/font.cpp @@ -166,9 +166,9 @@ wxFont::wxFont( GdkFont *WXUNUSED(font), char *xFontName ) tn.GetNextToken(); // foundry - M_FONTDATA->m_faceName = tn.GetNextToken(); // courier + M_FONTDATA->m_faceName = tn.GetNextToken(); // family - tmp = tn.GetNextToken().MakeUpper(); + tmp = tn.GetNextToken().MakeUpper(); // weight if (tmp == wxT("BOLD")) M_FONTDATA->m_weight = wxBOLD; if (tmp == wxT("BLACK")) M_FONTDATA->m_weight = wxBOLD; if (tmp == wxT("EXTRABOLD")) M_FONTDATA->m_weight = wxBOLD; @@ -178,12 +178,12 @@ wxFont::wxFont( GdkFont *WXUNUSED(font), char *xFontName ) if (tmp == wxT("LIGHT")) M_FONTDATA->m_weight = wxLIGHT; if (tmp == wxT("THIN")) M_FONTDATA->m_weight = wxLIGHT; - tmp = tn.GetNextToken().MakeUpper(); + tmp = tn.GetNextToken().MakeUpper(); // slant if (tmp == wxT("I")) M_FONTDATA->m_style = wxITALIC; if (tmp == wxT("O")) M_FONTDATA->m_style = wxITALIC; tn.GetNextToken(); // set width - tn.GetNextToken(); // ? + tn.GetNextToken(); // add. style tn.GetNextToken(); // pixel size tmp = tn.GetNextToken(); // pointsize @@ -193,13 +193,50 @@ wxFont::wxFont( GdkFont *WXUNUSED(font), char *xFontName ) tn.GetNextToken(); // x-res tn.GetNextToken(); // y-res - tmp = tn.GetNextToken().MakeUpper(); - if (tmp == wxT("M")) M_FONTDATA->m_family = wxMODERN; - else if (M_FONTDATA->m_faceName == wxT("TIMES")) M_FONTDATA->m_family = wxROMAN; - else if (M_FONTDATA->m_faceName == wxT("HELVETICA")) M_FONTDATA->m_family = wxSWISS; - else if (M_FONTDATA->m_faceName == wxT("LUCIDATYPEWRITER")) M_FONTDATA->m_family = wxTELETYPE; - else if (M_FONTDATA->m_faceName == wxT("LUCIDA")) M_FONTDATA->m_family = wxDECORATIVE; - else if (M_FONTDATA->m_faceName == wxT("UTOPIA")) M_FONTDATA->m_family = wxSCRIPT; + tmp = tn.GetNextToken().MakeUpper(); // spacing + + if (tmp == wxT("M")) + M_FONTDATA->m_family = wxMODERN; + else if (M_FONTDATA->m_faceName == wxT("TIMES")) + M_FONTDATA->m_family = wxROMAN; + else if (M_FONTDATA->m_faceName == wxT("HELVETICA")) + M_FONTDATA->m_family = wxSWISS; + else if (M_FONTDATA->m_faceName == wxT("LUCIDATYPEWRITER")) + M_FONTDATA->m_family = wxTELETYPE; + else if (M_FONTDATA->m_faceName == wxT("LUCIDA")) + M_FONTDATA->m_family = wxDECORATIVE; + else if (M_FONTDATA->m_faceName == wxT("UTOPIA")) + M_FONTDATA->m_family = wxSCRIPT; + + tn.GetNextToken(); // avg width + + // deal with font encoding + wxString registry = tn.GetNextToken().MakeUpper(), + encoding = tn.GetNextToken().MakeUpper(); + + if ( registry == _T("ISO8859") ) + { + int cp; + if ( wxSscanf(encoding, "%d", &cp) == 1 ) + { + M_FONTDATA->m_encoding = + (wxFontEncoding)(wxFONTENCODING_ISO8859_1 + cp - 1); + } + } + else if ( registry == _T("MICROSOFT") ) + { + int cp; + if ( wxSscanf(encoding, "cp125%d", &cp) == 1 ) + { + M_FONTDATA->m_encoding = + (wxFontEncoding)(wxFONTENCODING_CP1250 + cp); + } + } + else if ( registry == _T("KOI8") ) + { + M_FONTDATA->m_encoding = wxFONTENCODING_KOI8; + } + //else: unknown encoding - may be give a warning here? } bool wxFont::Create( int pointSize, diff --git a/src/unix/fontenum.cpp b/src/unix/fontenum.cpp index fceeff6ca2..d81c674276 100644 --- a/src/unix/fontenum.cpp +++ b/src/unix/fontenum.cpp @@ -34,8 +34,9 @@ // private functions // ---------------------------------------------------------------------------- -// create the list of all fonts with the given spacing -static char **CreateFontList(wxChar spacing, int *nFonts); +// create the list of all fonts with the given spacing and encoding +static char **CreateFontList(wxChar spacing, wxFontEncoding encoding, + int *nFonts); // extract all font families from the given font list and call our // OnFontFamily() for each of them @@ -56,10 +57,16 @@ static bool ProcessFamiliesFromFontList(wxFontEnumerator *This, // helpers // ---------------------------------------------------------------------------- -static char **CreateFontList(wxChar spacing, int *nFonts) +static char **CreateFontList(wxChar spacing, + wxFontEncoding encoding, + int *nFonts) { + wxString xencoding, xregistry; + wxGetXFontEncoding(encoding, &xencoding, &xregistry); + wxString pattern; - pattern.Printf(wxT("-*-*-*-*-*-*-*-*-*-*-%c-*-*-*"), spacing); + pattern.Printf(wxT("-*-*-*-*-*-*-*-*-*-*-%c-*-%s-%s"), + spacing, xregistry.c_str(), xencoding.c_str()); // get the list of all fonts return XListFonts((Display *)wxGetDisplay(), pattern.mb_str(), 32767, nFonts); @@ -106,7 +113,8 @@ static bool ProcessFamiliesFromFontList(wxFontEnumerator *This, // wxFontEnumerator // ---------------------------------------------------------------------------- -bool wxFontEnumerator::EnumerateFamilies(bool fixedWidthOnly) +bool wxFontEnumerator::EnumerateFamilies(wxFontEncoding encoding, + bool fixedWidthOnly) { int nFonts; char **fonts; @@ -114,7 +122,7 @@ bool wxFontEnumerator::EnumerateFamilies(bool fixedWidthOnly) if ( fixedWidthOnly ) { bool cont = TRUE; - fonts = CreateFontList(wxT('m'), &nFonts); + fonts = CreateFontList(wxT('m'), encoding, &nFonts); if ( fonts ) { cont = ProcessFamiliesFromFontList(this, fonts, nFonts); @@ -127,7 +135,7 @@ bool wxFontEnumerator::EnumerateFamilies(bool fixedWidthOnly) return TRUE; } - fonts = CreateFontList(wxT('c'), &nFonts); + fonts = CreateFontList(wxT('c'), encoding, &nFonts); if ( !fonts ) { return TRUE; @@ -135,11 +143,14 @@ bool wxFontEnumerator::EnumerateFamilies(bool fixedWidthOnly) } else { - fonts = CreateFontList(wxT('*'), &nFonts); + fonts = CreateFontList(wxT('*'), encoding, &nFonts); if ( !fonts ) { - wxFAIL_MSG(wxT("No fonts at all on this system?")); + // it's ok if there are no fonts in given encoding - but it's not + // ok if there are no fonts at all + wxASSERT_MSG(encoding != wxFONTENCODING_SYSTEM, + wxT("No fonts at all on this system?")); return FALSE; } diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index 8beb525c11..d3e1dd7ba8 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -780,6 +780,34 @@ static wxNativeFont wxLoadQueryFont(int pointSize, } wxString xregistry, xencoding; + if ( !wxGetXFontEncoding(encoding, &xregistry, &xencoding) ) + { + fontSpec.Printf(wxT("-*-*-*-*-*-*-*-*-*-*-*-*-%s-%s"), + xregistry.c_str(), xencoding.c_str()); + if ( !wxTestFontSpec(fontSpec) ) + { + // this encoding isn't available - what to do? + xregistry = + xencoding = wxT("*"); + } + } + + // construct the X font spec from our data + fontSpec.Printf(wxT("-*-%s-%s-%s-normal-*-*-%d-*-*-*-*-%s-%s"), + xfamily.c_str(), xweight.c_str(), xstyle.c_str(), + pointSize, xregistry.c_str(), xencoding.c_str()); + + return wxLoadFont(fontSpec); +} + +bool wxGetXFontEncoding(wxFontEncoding encoding, + wxString *pregistry, wxString *pencoding) +{ + wxCHECK_MSG( pencoding && pregistry, FALSE, wxT("bad pointer") ); + + wxString& xencoding = *pencoding; + wxString& xregistry = *pregistry; + if ( encoding == wxFONTENCODING_DEFAULT ) { // use the apps default @@ -830,6 +858,7 @@ static wxNativeFont wxLoadQueryFont(int pointSize, case wxFONTENCODING_CP1252: { int cp = encoding - wxFONTENCODING_CP1250 + 1250; + wxString fontSpec; fontSpec.Printf(wxT("-*-*-*-*-*-*-*-*-*-*-*-*-microsoft-cp%d"), cp); if ( wxTestFontSpec(fontSpec) ) @@ -856,24 +885,7 @@ static wxNativeFont wxLoadQueryFont(int pointSize, xencoding = wxT("*"); } - if ( test ) - { - fontSpec.Printf(wxT("-*-*-*-*-*-*-*-*-*-*-*-*-%s-%s"), - xregistry.c_str(), xencoding.c_str()); - if ( !wxTestFontSpec(fontSpec) ) - { - // this encoding isn't available - what to do? - xregistry = - xencoding = wxT("*"); - } - } - - // construct the X font spec from our data - fontSpec.Printf(wxT("-*-%s-%s-%s-normal-*-*-%d-*-*-*-*-%s-%s"), - xfamily.c_str(), xweight.c_str(), xstyle.c_str(), - pointSize, xregistry.c_str(), xencoding.c_str()); - - return wxLoadFont(fontSpec); + return !test; } wxNativeFont wxLoadQueryNearestFont(int pointSize, -- 2.45.2