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
This commit is contained in:
Vadim Zeitlin
1999-10-29 17:54:13 +00:00
parent 8b99adf475
commit 36f210c81e
8 changed files with 279 additions and 125 deletions

View File

@@ -25,9 +25,15 @@
class WXDLLEXPORT wxFontEnumerator class WXDLLEXPORT wxFontEnumerator
{ {
public: public:
// start enumerating font families - will result in OnFontFamily() being // start enumerating font families (either all of them or those which
// called for each available font family (unless it returns FALSE) // support the given encoding) - will result in OnFontFamily() being
virtual bool EnumerateFamilies(bool fixedWidthOnly = FALSE); // 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 // enumerate the different encodings either for given font family or for
// all font families - will result in OnFontEncoding() being called for // all font families - will result in OnFontEncoding() being called for
@@ -46,6 +52,9 @@ public:
virtual bool OnFontEncoding(const wxString& WXUNUSED(family), virtual bool OnFontEncoding(const wxString& WXUNUSED(family),
const wxString& WXUNUSED(encoding)) const wxString& WXUNUSED(encoding))
{ return FALSE; } { return FALSE; }
// virtual dtor for the base class
virtual ~wxFontEnumerator() { }
}; };
#endif // _WX_FONTENUM_H_ #endif // _WX_FONTENUM_H_

View File

@@ -34,6 +34,7 @@ public:
virtual int GetMax() const { return m_max; } virtual int GetMax() const { return m_max; }
// operations // operations
virtual void SetValue(const wxString& value) = 0;
virtual void SetValue(int val) = 0; virtual void SetValue(int val) = 0;
virtual void SetRange(int minVal, int maxVal) = 0; virtual void SetRange(int minVal, int maxVal) = 0;
@@ -57,7 +58,7 @@ protected:
#elif defined(__WXGTK__) #elif defined(__WXGTK__)
#include "wx/gtk/spinctrl.h" #include "wx/gtk/spinctrl.h"
#else // Win16 || !Win #else // Win16 || !Win
#include "wx/generic/spinctrl.h" #include "wx/generic/spinctlg.h"
#endif // platform #endif // platform
#endif // _WX_SPINCTRL_H_ #endif // _WX_SPINCTRL_H_

View File

@@ -400,6 +400,13 @@ extern wxNativeFont wxLoadQueryNearestFont(int pointSize,
const wxString &facename, const wxString &facename,
wxFontEncoding encoding); 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 // X || GTK
#endif // wxUSE_GUI #endif // wxUSE_GUI

View File

@@ -5,7 +5,7 @@
// Modified by: // Modified by:
// Created: 30.09.99 // Created: 30.09.99
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Vadim Zeitlin // Copyright: (c) 1999 Vadim Zeitlin
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@@ -24,6 +24,7 @@
#include <wx/log.h> #include <wx/log.h>
#endif #endif
#include <wx/choicdlg.h>
#include <wx/fontdlg.h> #include <wx/fontdlg.h>
#include <wx/fontenum.h> #include <wx/fontenum.h>
@@ -81,16 +82,22 @@ public:
void OnQuit(wxCommandEvent& event); void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event); void OnAbout(wxCommandEvent& event);
void OnSelectFont(wxCommandEvent& event); void OnSelectFont(wxCommandEvent& event);
void OnCreateFont(wxCommandEvent& event); void OnEnumerateFamiliesForEncoding(wxCommandEvent& event);
void OnEnumerateFamilies(wxCommandEvent& WXUNUSED(event)) void OnEnumerateFamilies(wxCommandEvent& WXUNUSED(event))
{ DoEnumerateFamilies(FALSE); } { DoEnumerateFamilies(FALSE); }
void OnEnumerateFixedFamilies(wxCommandEvent& WXUNUSED(event)) void OnEnumerateFixedFamilies(wxCommandEvent& WXUNUSED(event))
{ DoEnumerateFamilies(TRUE); } { DoEnumerateFamilies(TRUE); }
void OnEnumerateEncodings(wxCommandEvent& event); void OnEnumerateEncodings(wxCommandEvent& event);
protected: void OnSize(wxSizeEvent& event);
void DoEnumerateFamilies(bool fixedWidthOnly);
protected:
void DoEnumerateFamilies(bool fixedWidthOnly,
wxFontEncoding encoding = wxFONTENCODING_SYSTEM);
void Resize(const wxSize& size, const wxFont& font = wxNullFont);
wxTextCtrl *m_textctrl;
MyCanvas *m_canvas; MyCanvas *m_canvas;
private: private:
@@ -98,24 +105,6 @@ private:
DECLARE_EVENT_TABLE() 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 // constants
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -127,7 +116,7 @@ enum
Font_Quit = 1, Font_Quit = 1,
Font_About, Font_About,
Font_Choose = 100, Font_Choose = 100,
Font_Create, Font_EnumFamiliesForEncoding,
Font_EnumFamilies, Font_EnumFamilies,
Font_EnumFixedFamilies, Font_EnumFixedFamilies,
Font_EnumEncodings, Font_EnumEncodings,
@@ -145,10 +134,12 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(Font_Quit, MyFrame::OnQuit) EVT_MENU(Font_Quit, MyFrame::OnQuit)
EVT_MENU(Font_About, MyFrame::OnAbout) EVT_MENU(Font_About, MyFrame::OnAbout)
EVT_MENU(Font_Choose, MyFrame::OnSelectFont) 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_EnumFamilies, MyFrame::OnEnumerateFamilies)
EVT_MENU(Font_EnumFixedFamilies, MyFrame::OnEnumerateFixedFamilies) EVT_MENU(Font_EnumFixedFamilies, MyFrame::OnEnumerateFixedFamilies)
EVT_MENU(Font_EnumEncodings, MyFrame::OnEnumerateEncodings) EVT_MENU(Font_EnumEncodings, MyFrame::OnEnumerateEncodings)
EVT_SIZE(MyFrame::OnSize)
END_EVENT_TABLE() END_EVENT_TABLE()
// Create a new application object: this macro will allow wxWindows to create // 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; wxMenu *menuFont = new wxMenu;
menuFont->Append(Font_Choose, "&Select font...\tCtrl-S", menuFont->Append(Font_Choose, "&Select font...\tCtrl-S",
"Select a standard font"); "Select a standard font");
menuFont->Append(Font_Create, "&Create font...\tCtrl-C",
"Create a custom font");
menuFont->AppendSeparator(); menuFont->AppendSeparator();
menuFont->Append(Font_EnumFamilies, "Enumerate font &families\tCtrl-F"); menuFont->Append(Font_EnumFamilies, "Enumerate font &families\tCtrl-F");
menuFont->Append(Font_EnumFixedFamilies, menuFont->Append(Font_EnumFixedFamilies,
"Enumerate f&ixed font families\tCtrl-I"); "Enumerate f&ixed font families\tCtrl-I");
menuFont->Append(Font_EnumEncodings, menuFont->Append(Font_EnumEncodings,
"Enumerate &encodings\tCtrl-E"); "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... // now append the freshly created menu to the menu bar...
wxMenuBar *menuBar = new wxMenuBar; 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 // ... and attach this menu bar to the frame
SetMenuBar(menuBar); 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); m_canvas = new MyCanvas(this);
// create a status bar just for fun (by default with 1 pane only) // 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()); fontEnumerator.GetText().c_str());
} }
void MyFrame::DoEnumerateFamilies(bool fixedWidthOnly) void MyFrame::DoEnumerateFamilies(bool fixedWidthOnly, wxFontEncoding encoding)
{ {
class MyFontEnumerator : public wxFontEnumerator class MyFontEnumerator : public wxFontEnumerator
{ {
public: public:
MyFontEnumerator() { m_n = 0; } MyFontEnumerator() { m_n = 0; }
bool GotAny() const { return m_n; }
const wxString& GetText() const { return m_text; } const wxString& GetText() const { return m_text; }
protected: protected:
@@ -285,18 +285,56 @@ void MyFrame::DoEnumerateFamilies(bool fixedWidthOnly)
wxString m_text; wxString m_text;
} fontEnumerator; } fontEnumerator;
fontEnumerator.EnumerateFamilies(fixedWidthOnly); fontEnumerator.EnumerateFamilies(encoding, fixedWidthOnly);
if ( fontEnumerator.GotAny() )
{
wxLogMessage("Enumerating %s font families:\n%s", wxLogMessage("Enumerating %s font families:\n%s",
fixedWidthOnly ? "fixed width" : "all", fixedWidthOnly ? "fixed width" : "all",
fontEnumerator.GetText().c_str()); fontEnumerator.GetText().c_str());
} }
else
void MyFrame::OnCreateFont(wxCommandEvent& WXUNUSED(event))
{ {
MyFontDialog dialog(this); wxLogWarning("No such fonts found.");
}
}
(void)dialog.ShowModal(); void MyFrame::OnEnumerateFamiliesForEncoding(wxCommandEvent& WXUNUSED(event))
{
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)) void MyFrame::OnSelectFont(wxCommandEvent& WXUNUSED(event))
@@ -309,9 +347,17 @@ void MyFrame::OnSelectFont(wxCommandEvent& WXUNUSED(event))
if ( dialog.ShowModal() == wxID_OK ) if ( dialog.ShowModal() == wxID_OK )
{ {
wxFontData retData = dialog.GetFontData(); wxFontData retData = dialog.GetFontData();
m_canvas->SetTextFont(retData.GetChosenFont()); wxFont font = retData.GetChosenFont();
m_canvas->SetColour(retData.GetColour()); wxColour colour = retData.GetColour();
Resize(GetSize(), font);
m_canvas->SetTextFont(font);
m_canvas->SetColour(colour);
m_canvas->Refresh(); 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)) 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); 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 // MyCanvas
@@ -375,7 +448,7 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
// the origin for our table // the origin for our table
int x = 5, 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 // print all font symbols from 32 to 256 in 7 rows of 32 chars each
for ( int i = 1; i < 8; i++ ) 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); 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();
}
}

View File

@@ -166,9 +166,9 @@ wxFont::wxFont( GdkFont *WXUNUSED(font), char *xFontName )
tn.GetNextToken(); // foundry 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("BOLD")) M_FONTDATA->m_weight = wxBOLD;
if (tmp == wxT("BLACK")) M_FONTDATA->m_weight = wxBOLD; if (tmp == wxT("BLACK")) M_FONTDATA->m_weight = wxBOLD;
if (tmp == wxT("EXTRABOLD")) 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("LIGHT")) M_FONTDATA->m_weight = wxLIGHT;
if (tmp == wxT("THIN")) 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("I")) M_FONTDATA->m_style = wxITALIC;
if (tmp == wxT("O")) M_FONTDATA->m_style = wxITALIC; if (tmp == wxT("O")) M_FONTDATA->m_style = wxITALIC;
tn.GetNextToken(); // set width tn.GetNextToken(); // set width
tn.GetNextToken(); // ? tn.GetNextToken(); // add. style
tn.GetNextToken(); // pixel size tn.GetNextToken(); // pixel size
tmp = tn.GetNextToken(); // pointsize tmp = tn.GetNextToken(); // pointsize
@@ -193,13 +193,50 @@ wxFont::wxFont( GdkFont *WXUNUSED(font), char *xFontName )
tn.GetNextToken(); // x-res tn.GetNextToken(); // x-res
tn.GetNextToken(); // y-res tn.GetNextToken(); // y-res
tmp = tn.GetNextToken().MakeUpper(); 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; if (tmp == wxT("M"))
else if (M_FONTDATA->m_faceName == wxT("HELVETICA")) M_FONTDATA->m_family = wxSWISS; M_FONTDATA->m_family = wxMODERN;
else if (M_FONTDATA->m_faceName == wxT("LUCIDATYPEWRITER")) M_FONTDATA->m_family = wxTELETYPE; else if (M_FONTDATA->m_faceName == wxT("TIMES"))
else if (M_FONTDATA->m_faceName == wxT("LUCIDA")) M_FONTDATA->m_family = wxDECORATIVE; M_FONTDATA->m_family = wxROMAN;
else if (M_FONTDATA->m_faceName == wxT("UTOPIA")) M_FONTDATA->m_family = wxSCRIPT; 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, bool wxFont::Create( int pointSize,

View File

@@ -166,9 +166,9 @@ wxFont::wxFont( GdkFont *WXUNUSED(font), char *xFontName )
tn.GetNextToken(); // foundry 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("BOLD")) M_FONTDATA->m_weight = wxBOLD;
if (tmp == wxT("BLACK")) M_FONTDATA->m_weight = wxBOLD; if (tmp == wxT("BLACK")) M_FONTDATA->m_weight = wxBOLD;
if (tmp == wxT("EXTRABOLD")) 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("LIGHT")) M_FONTDATA->m_weight = wxLIGHT;
if (tmp == wxT("THIN")) 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("I")) M_FONTDATA->m_style = wxITALIC;
if (tmp == wxT("O")) M_FONTDATA->m_style = wxITALIC; if (tmp == wxT("O")) M_FONTDATA->m_style = wxITALIC;
tn.GetNextToken(); // set width tn.GetNextToken(); // set width
tn.GetNextToken(); // ? tn.GetNextToken(); // add. style
tn.GetNextToken(); // pixel size tn.GetNextToken(); // pixel size
tmp = tn.GetNextToken(); // pointsize tmp = tn.GetNextToken(); // pointsize
@@ -193,13 +193,50 @@ wxFont::wxFont( GdkFont *WXUNUSED(font), char *xFontName )
tn.GetNextToken(); // x-res tn.GetNextToken(); // x-res
tn.GetNextToken(); // y-res tn.GetNextToken(); // y-res
tmp = tn.GetNextToken().MakeUpper(); 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; if (tmp == wxT("M"))
else if (M_FONTDATA->m_faceName == wxT("HELVETICA")) M_FONTDATA->m_family = wxSWISS; M_FONTDATA->m_family = wxMODERN;
else if (M_FONTDATA->m_faceName == wxT("LUCIDATYPEWRITER")) M_FONTDATA->m_family = wxTELETYPE; else if (M_FONTDATA->m_faceName == wxT("TIMES"))
else if (M_FONTDATA->m_faceName == wxT("LUCIDA")) M_FONTDATA->m_family = wxDECORATIVE; M_FONTDATA->m_family = wxROMAN;
else if (M_FONTDATA->m_faceName == wxT("UTOPIA")) M_FONTDATA->m_family = wxSCRIPT; 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, bool wxFont::Create( int pointSize,

View File

@@ -34,8 +34,9 @@
// private functions // private functions
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// create the list of all fonts with the given spacing // create the list of all fonts with the given spacing and encoding
static char **CreateFontList(wxChar spacing, int *nFonts); static char **CreateFontList(wxChar spacing, wxFontEncoding encoding,
int *nFonts);
// extract all font families from the given font list and call our // extract all font families from the given font list and call our
// OnFontFamily() for each of them // OnFontFamily() for each of them
@@ -56,10 +57,16 @@ static bool ProcessFamiliesFromFontList(wxFontEnumerator *This,
// helpers // 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; 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 // get the list of all fonts
return XListFonts((Display *)wxGetDisplay(), pattern.mb_str(), 32767, nFonts); return XListFonts((Display *)wxGetDisplay(), pattern.mb_str(), 32767, nFonts);
@@ -106,7 +113,8 @@ static bool ProcessFamiliesFromFontList(wxFontEnumerator *This,
// wxFontEnumerator // wxFontEnumerator
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
bool wxFontEnumerator::EnumerateFamilies(bool fixedWidthOnly) bool wxFontEnumerator::EnumerateFamilies(wxFontEncoding encoding,
bool fixedWidthOnly)
{ {
int nFonts; int nFonts;
char **fonts; char **fonts;
@@ -114,7 +122,7 @@ bool wxFontEnumerator::EnumerateFamilies(bool fixedWidthOnly)
if ( fixedWidthOnly ) if ( fixedWidthOnly )
{ {
bool cont = TRUE; bool cont = TRUE;
fonts = CreateFontList(wxT('m'), &nFonts); fonts = CreateFontList(wxT('m'), encoding, &nFonts);
if ( fonts ) if ( fonts )
{ {
cont = ProcessFamiliesFromFontList(this, fonts, nFonts); cont = ProcessFamiliesFromFontList(this, fonts, nFonts);
@@ -127,7 +135,7 @@ bool wxFontEnumerator::EnumerateFamilies(bool fixedWidthOnly)
return TRUE; return TRUE;
} }
fonts = CreateFontList(wxT('c'), &nFonts); fonts = CreateFontList(wxT('c'), encoding, &nFonts);
if ( !fonts ) if ( !fonts )
{ {
return TRUE; return TRUE;
@@ -135,11 +143,14 @@ bool wxFontEnumerator::EnumerateFamilies(bool fixedWidthOnly)
} }
else else
{ {
fonts = CreateFontList(wxT('*'), &nFonts); fonts = CreateFontList(wxT('*'), encoding, &nFonts);
if ( !fonts ) 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; return FALSE;
} }

View File

@@ -780,6 +780,34 @@ static wxNativeFont wxLoadQueryFont(int pointSize,
} }
wxString xregistry, xencoding; 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 ) if ( encoding == wxFONTENCODING_DEFAULT )
{ {
// use the apps default // use the apps default
@@ -830,6 +858,7 @@ static wxNativeFont wxLoadQueryFont(int pointSize,
case wxFONTENCODING_CP1252: case wxFONTENCODING_CP1252:
{ {
int cp = encoding - wxFONTENCODING_CP1250 + 1250; int cp = encoding - wxFONTENCODING_CP1250 + 1250;
wxString fontSpec;
fontSpec.Printf(wxT("-*-*-*-*-*-*-*-*-*-*-*-*-microsoft-cp%d"), fontSpec.Printf(wxT("-*-*-*-*-*-*-*-*-*-*-*-*-microsoft-cp%d"),
cp); cp);
if ( wxTestFontSpec(fontSpec) ) if ( wxTestFontSpec(fontSpec) )
@@ -856,24 +885,7 @@ static wxNativeFont wxLoadQueryFont(int pointSize,
xencoding = wxT("*"); xencoding = wxT("*");
} }
if ( test ) return !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);
} }
wxNativeFont wxLoadQueryNearestFont(int pointSize, wxNativeFont wxLoadQueryNearestFont(int pointSize,