wxMotif::wxFont supports encodings too (and shares 99% of font code with wxGTK)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3779 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-10-01 14:59:52 +00:00
parent d391a34510
commit 93ccaed869
14 changed files with 569 additions and 729 deletions

View File

@@ -334,7 +334,7 @@ utilsres.cpp R
wave.cpp R wave.cpp R
window.cpp R window.cpp R
gsockmot.cpp X gsockmot.c X S
accel.cpp X accel.cpp X
app.cpp X app.cpp X
bitmap.cpp X bitmap.cpp X

View File

@@ -13,120 +13,93 @@
#define _WX_FONT_H_ #define _WX_FONT_H_
#ifdef __GNUG__ #ifdef __GNUG__
#pragma interface "font.h" #pragma interface "font.h"
#endif #endif
#include "wx/gdiobj.h"
#include "wx/list.h"
class WXDLLEXPORT wxFont;
// For every wxFont, there must be a font for each display and scale requested.
// So these objects are stored in wxFontRefData::m_fonts
class WXDLLEXPORT wxXFont: public wxObject
{
public:
wxXFont();
~wxXFont();
WXFontStructPtr m_fontStruct; // XFontStruct
WXFontList m_fontList; // Motif XmFontList
WXDisplay* m_display; // XDisplay
int m_scale; // Scale * 100
};
class WXDLLEXPORT wxFontRefData: public wxGDIRefData
{
friend class WXDLLEXPORT wxFont;
public:
wxFontRefData();
wxFontRefData(const wxFontRefData& data);
~wxFontRefData();
protected:
int m_pointSize;
int m_family;
int m_style;
int m_weight;
bool m_underlined;
wxString m_faceName;
// A list of wxXFonts
wxList m_fonts;
};
#define M_FONTDATA ((wxFontRefData *)m_refData)
WXDLLEXPORT_DATA(extern const char*) wxEmptyString;
// Font // Font
class WXDLLEXPORT wxFont: public wxGDIObject class wxFont : public wxFontBase
{ {
DECLARE_DYNAMIC_CLASS(wxFont)
public: public:
wxFont(); // ctors and such
wxFont(int pointSize, int family, int style, int weight, bool underlined = FALSE, const wxString& faceName = wxEmptyString); wxFont() { Init(); }
inline wxFont(const wxFont& font) { Ref(font); } wxFont(const wxFont& font) { Init(); Ref(font); }
~wxFont(); wxFont(int size,
int family,
int style,
int weight,
bool underlined = FALSE,
const wxString& face = wxEmptyString,
wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
{
Init();
bool Create(int pointSize, int family, int style, int weight, bool underlined = FALSE, const wxString& faceName = wxEmptyString); (void)Create(size, family, style, weight, underlined, face, encoding);
}
virtual bool Ok() const { return (m_refData != NULL) ; } bool Create(int size,
int family,
int style,
int weight,
bool underlined = FALSE,
const wxString& face = wxEmptyString,
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
inline int GetPointSize() const { return M_FONTDATA->m_pointSize; } virtual ~wxFont();
inline int GetFamily() const { return M_FONTDATA->m_family; }
inline int GetStyle() const { return M_FONTDATA->m_style; }
inline int GetWeight() const { return M_FONTDATA->m_weight; }
wxString GetFamilyString() const ;
wxString GetFaceName() const ;
wxString GetStyleString() const ;
wxString GetWeightString() const ;
inline bool GetUnderlined() const { return M_FONTDATA->m_underlined; }
void SetPointSize(int pointSize); // assignment
void SetFamily(int family); wxFont& operator=(const wxFont& font);
void SetStyle(int style);
void SetWeight(int weight);
void SetFaceName(const wxString& faceName);
void SetUnderlined(bool underlined);
inline wxFont& operator = (const wxFont& font) { if (*this == font) return (*this); Ref(font); return *this; } // implement base class pure virtuals
inline bool operator == (const wxFont& font) const { return m_refData == font.m_refData; } virtual int GetPointSize() const;
inline bool operator != (const wxFont& font) const { return m_refData != font.m_refData; } virtual int GetFamily() const;
virtual int GetStyle() const;
virtual int GetWeight() const;
virtual bool GetUnderlined() const;
virtual wxString GetFaceName() const;
virtual wxFontEncoding GetEncoding() const;
// Implementation virtual void SetPointSize(int pointSize);
virtual void SetFamily(int family);
virtual void SetStyle(int style);
virtual void SetWeight(int weight);
virtual void SetFaceName(const wxString& faceName);
virtual void SetUnderlined(bool underlined);
virtual void SetEncoding(wxFontEncoding encoding);
// Find an existing, or create a new, XFontStruct // Implementation
// based on this wxFont and the given scale. Append the
// font to list in the private data for future reference.
// TODO This is a fairly basic implementation, that doesn't // Find an existing, or create a new, XFontStruct
// allow for different facenames, and also doesn't do a mapping // based on this wxFont and the given scale. Append the
// between 'standard' facenames (e.g. Arial, Helvetica, Times Roman etc.) // font to list in the private data for future reference.
// and the fonts that are available on a particular system.
// Maybe we need to scan the user's machine to build up a profile
// of the fonts and a mapping file.
// Return font struct, and optionally the Motif font list // TODO This is a fairly basic implementation, that doesn't
wxXFont* GetInternalFont(double scale = 1.0, WXDisplay* display = NULL) const; // allow for different facenames, and also doesn't do a mapping
// between 'standard' facenames (e.g. Arial, Helvetica, Times Roman etc.)
// and the fonts that are available on a particular system.
// Maybe we need to scan the user's machine to build up a profile
// of the fonts and a mapping file.
// These two are helper functions for convenient access of the above. // Return font struct, and optionally the Motif font list
inline WXFontStructPtr GetFontStruct(double scale = 1.0, WXDisplay* display = NULL) const class wxXFont* GetInternalFont(double scale = 1.0,
{ WXDisplay* display = NULL) const;
wxXFont* f = GetInternalFont(scale, display);
return (f ? f->m_fontStruct : (WXFontStructPtr) 0); // These two are helper functions for convenient access of the above.
} WXFontStructPtr GetFontStruct(double scale = 1.0,
WXFontList GetFontList(double scale = 1.0, WXDisplay* display = NULL) const WXDisplay* display = NULL) const;
{ WXFontList GetFontList(double scale = 1.0,
wxXFont* f = GetInternalFont(scale, display); WXDisplay* display = NULL) const;
return (f ? f->m_fontList : (WXFontList) 0);
}
WXFontStructPtr LoadQueryFont(int pointSize, int family, int style,
int weight, bool underlined) const;
protected: protected:
bool RealizeResource(); // common part of all ctors
void Unshare(); void Init();
// VZ: IMHO, we don't need it at all...
bool RealizeResource() { return TRUE; }
void Unshare();
private:
DECLARE_DYNAMIC_CLASS(wxFont)
}; };
#endif #endif

View File

@@ -363,5 +363,30 @@ void wxAllocColor(Display *display,Colormap colormap,XColor *xcolor);
#endif //__X__ #endif //__X__
// ----------------------------------------------------------------------------
// font-related functions (X and GTK)
// ----------------------------------------------------------------------------
#if defined(__X__) || defined(__WXGTK__)
#ifdef __X__
typedef XFontStruct *wxNativeFont;
#else // GDK
typedef GdkFont *wxNativeFont;
#endif
#include "wx/font.h" // for wxFontEncoding
// returns the handle of the nearest available font or 0
extern wxNativeFont wxLoadQueryNearestFont(int pointSize,
int family,
int style,
int weight,
bool underlined,
const wxString &facename,
wxFontEncoding encoding);
#endif // X || GTK
#endif #endif
// _WX_UTILSH__ // _WX_UTILSH__

View File

@@ -41,9 +41,6 @@
// private functions // private functions
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// returns TRUE if there are any fonts matching this font spec
static bool wxTestFontSpec(const wxString& fontspec);
static GdkFont *wxLoadQueryFont( int pointSize, static GdkFont *wxLoadQueryFont( int pointSize,
int family, int family,
int style, int style,
@@ -450,221 +447,6 @@ GdkFont *wxFont::GetInternalFont( float scale ) const
// local utilities to find a X font // local utilities to find a X font
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// returns TRUE if there are any fonts matching this font spec
static bool wxTestFontSpec(const wxString& fontSpec)
{
GdkFont *test = gdk_font_load( wxConvCurrent->cWX2MB(fontSpec) );
if ( test )
{
gdk_font_unref( test );
return TRUE;
}
else
{
return FALSE;
}
}
static GdkFont *wxLoadQueryFont( int pointSize,
int family,
int style,
int weight,
bool WXUNUSED(underlined),
const wxString &facename,
wxFontEncoding encoding )
{
wxString xfamily;
switch (family)
{
case wxDECORATIVE: xfamily = _T("lucida"); break;
case wxROMAN: xfamily = _T("times"); break;
case wxMODERN: xfamily = _T("courier"); break;
case wxSWISS: xfamily = _T("helvetica"); break;
case wxTELETYPE: xfamily = _T("lucidatypewriter"); break;
case wxSCRIPT: xfamily = _T("utopia"); break;
default: xfamily = _T("*");
}
wxString fontSpec;
if (!facename.IsEmpty())
{
fontSpec.Printf(_T("-*-%s-*-*-normal-*-*-*-*-*-*-*-*-*"),
facename.c_str());
if ( wxTestFontSpec(fontSpec) )
{
xfamily = facename;
}
//else: no such family, use default one instead
}
wxString xstyle;
switch (style)
{
case wxITALIC: xstyle = _T("i"); break;
case wxSLANT: xstyle = _T("o"); break;
case wxNORMAL: xstyle = _T("r"); break;
default: xstyle = _T("*"); break;
}
wxString xweight;
switch (weight)
{
case wxBOLD: xweight = _T("bold"); break;
case wxLIGHT:
case wxNORMAL: xweight = _T("medium"); break;
default: xweight = _T("*"); break;
}
wxString xregistry, xencoding;
if ( encoding == wxFONTENCODING_DEFAULT )
{
// use the apps default
encoding = wxFont::GetDefaultEncoding();
}
bool test = TRUE; // should we test for availability of encoding?
switch ( encoding )
{
case wxFONTENCODING_ISO8859_1:
case wxFONTENCODING_ISO8859_2:
case wxFONTENCODING_ISO8859_3:
case wxFONTENCODING_ISO8859_4:
case wxFONTENCODING_ISO8859_5:
case wxFONTENCODING_ISO8859_6:
case wxFONTENCODING_ISO8859_7:
case wxFONTENCODING_ISO8859_8:
case wxFONTENCODING_ISO8859_9:
case wxFONTENCODING_ISO8859_10:
case wxFONTENCODING_ISO8859_11:
case wxFONTENCODING_ISO8859_13:
case wxFONTENCODING_ISO8859_14:
case wxFONTENCODING_ISO8859_15:
{
int cp = encoding - wxFONTENCODING_ISO8859_1 + 1;
xregistry = _T("iso8859");
xencoding.Printf(_T("%d"), cp);
}
break;
case wxFONTENCODING_KOI8:
xregistry = _T("koi8");
if ( wxTestFontSpec(_T("-*-*-*-*-*-*-*-*-*-*-*-*-koi8-1")) )
{
xencoding = _T("1");
// test passed, no need to do it once more
test = FALSE;
}
else
{
xencoding = _T("*");
}
break;
case wxFONTENCODING_CP1250:
case wxFONTENCODING_CP1251:
case wxFONTENCODING_CP1252:
{
int cp = encoding - wxFONTENCODING_CP1250 + 1250;
fontSpec.Printf(_T("-*-*-*-*-*-*-*-*-*-*-*-*-microsoft-cp%d"),
cp);
if ( wxTestFontSpec(fontSpec) )
{
xregistry = _T("microsoft");
xencoding.Printf(_T("cp%d"), cp);
// test passed, no need to do it once more
test = FALSE;
}
else
{
// fall back to LatinX
xregistry = _T("iso8859");
xencoding.Printf(_T("%d"), cp - 1249);
}
}
break;
case wxFONTENCODING_SYSTEM:
default:
test = FALSE;
xregistry =
xencoding = _T("*");
}
if ( test )
{
fontSpec.Printf(_T("-*-*-*-*-*-*-*-*-*-*-*-*-%s-%s"),
xregistry.c_str(), xencoding.c_str());
if ( !wxTestFontSpec(fontSpec) )
{
// this encoding isn't available - what to do?
xregistry =
xencoding = _T("*");
}
}
// construct the X font spec from our data
fontSpec.Printf(_T("-*-%s-%s-%s-normal-*-*-%d-*-*-*-*-%s-%s"),
xfamily.c_str(), xweight.c_str(), xstyle.c_str(),
pointSize, xregistry.c_str(), xencoding.c_str());
return gdk_font_load( wxConvCurrent->cWX2MB(fontSpec) );
}
static GdkFont *wxLoadQueryNearestFont( int pointSize,
int family,
int style,
int weight,
bool underlined,
const wxString &facename,
wxFontEncoding encoding )
{
GdkFont *font = wxLoadQueryFont( pointSize, family, style, weight,
underlined, facename, encoding );
if (!font)
{
/* search up and down by stepsize 10 */
int max_size = pointSize + 20 * (1 + (pointSize/180));
int min_size = pointSize - 20 * (1 + (pointSize/180));
int i;
/* Search for smaller size (approx.) */
for ( i = pointSize - 10; !font && i >= 10 && i >= min_size; i -= 10 )
{
font = wxLoadQueryFont(i, family, style, weight, underlined,
facename, encoding );
}
/* Search for larger size (approx.) */
for ( i = pointSize + 10; !font && i <= max_size; i += 10 )
{
font = wxLoadQueryFont( i, family, style, weight, underlined,
facename, encoding );
}
/* Try default family */
if ( !font && family != wxDEFAULT )
{
font = wxLoadQueryFont( pointSize, wxDEFAULT, style, weight,
underlined, facename, encoding );
}
/* Bogus font */
if ( !font )
{
font = wxLoadQueryFont(120, wxDEFAULT, wxNORMAL, wxNORMAL,
underlined, facename, encoding );
}
}
return font;
}
// wow, what's this stuff? Is it used/useful? (VZ) // wow, what's this stuff? Is it used/useful? (VZ)
#if 0 #if 0

View File

@@ -41,9 +41,6 @@
// private functions // private functions
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// returns TRUE if there are any fonts matching this font spec
static bool wxTestFontSpec(const wxString& fontspec);
static GdkFont *wxLoadQueryFont( int pointSize, static GdkFont *wxLoadQueryFont( int pointSize,
int family, int family,
int style, int style,
@@ -450,221 +447,6 @@ GdkFont *wxFont::GetInternalFont( float scale ) const
// local utilities to find a X font // local utilities to find a X font
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// returns TRUE if there are any fonts matching this font spec
static bool wxTestFontSpec(const wxString& fontSpec)
{
GdkFont *test = gdk_font_load( wxConvCurrent->cWX2MB(fontSpec) );
if ( test )
{
gdk_font_unref( test );
return TRUE;
}
else
{
return FALSE;
}
}
static GdkFont *wxLoadQueryFont( int pointSize,
int family,
int style,
int weight,
bool WXUNUSED(underlined),
const wxString &facename,
wxFontEncoding encoding )
{
wxString xfamily;
switch (family)
{
case wxDECORATIVE: xfamily = _T("lucida"); break;
case wxROMAN: xfamily = _T("times"); break;
case wxMODERN: xfamily = _T("courier"); break;
case wxSWISS: xfamily = _T("helvetica"); break;
case wxTELETYPE: xfamily = _T("lucidatypewriter"); break;
case wxSCRIPT: xfamily = _T("utopia"); break;
default: xfamily = _T("*");
}
wxString fontSpec;
if (!facename.IsEmpty())
{
fontSpec.Printf(_T("-*-%s-*-*-normal-*-*-*-*-*-*-*-*-*"),
facename.c_str());
if ( wxTestFontSpec(fontSpec) )
{
xfamily = facename;
}
//else: no such family, use default one instead
}
wxString xstyle;
switch (style)
{
case wxITALIC: xstyle = _T("i"); break;
case wxSLANT: xstyle = _T("o"); break;
case wxNORMAL: xstyle = _T("r"); break;
default: xstyle = _T("*"); break;
}
wxString xweight;
switch (weight)
{
case wxBOLD: xweight = _T("bold"); break;
case wxLIGHT:
case wxNORMAL: xweight = _T("medium"); break;
default: xweight = _T("*"); break;
}
wxString xregistry, xencoding;
if ( encoding == wxFONTENCODING_DEFAULT )
{
// use the apps default
encoding = wxFont::GetDefaultEncoding();
}
bool test = TRUE; // should we test for availability of encoding?
switch ( encoding )
{
case wxFONTENCODING_ISO8859_1:
case wxFONTENCODING_ISO8859_2:
case wxFONTENCODING_ISO8859_3:
case wxFONTENCODING_ISO8859_4:
case wxFONTENCODING_ISO8859_5:
case wxFONTENCODING_ISO8859_6:
case wxFONTENCODING_ISO8859_7:
case wxFONTENCODING_ISO8859_8:
case wxFONTENCODING_ISO8859_9:
case wxFONTENCODING_ISO8859_10:
case wxFONTENCODING_ISO8859_11:
case wxFONTENCODING_ISO8859_13:
case wxFONTENCODING_ISO8859_14:
case wxFONTENCODING_ISO8859_15:
{
int cp = encoding - wxFONTENCODING_ISO8859_1 + 1;
xregistry = _T("iso8859");
xencoding.Printf(_T("%d"), cp);
}
break;
case wxFONTENCODING_KOI8:
xregistry = _T("koi8");
if ( wxTestFontSpec(_T("-*-*-*-*-*-*-*-*-*-*-*-*-koi8-1")) )
{
xencoding = _T("1");
// test passed, no need to do it once more
test = FALSE;
}
else
{
xencoding = _T("*");
}
break;
case wxFONTENCODING_CP1250:
case wxFONTENCODING_CP1251:
case wxFONTENCODING_CP1252:
{
int cp = encoding - wxFONTENCODING_CP1250 + 1250;
fontSpec.Printf(_T("-*-*-*-*-*-*-*-*-*-*-*-*-microsoft-cp%d"),
cp);
if ( wxTestFontSpec(fontSpec) )
{
xregistry = _T("microsoft");
xencoding.Printf(_T("cp%d"), cp);
// test passed, no need to do it once more
test = FALSE;
}
else
{
// fall back to LatinX
xregistry = _T("iso8859");
xencoding.Printf(_T("%d"), cp - 1249);
}
}
break;
case wxFONTENCODING_SYSTEM:
default:
test = FALSE;
xregistry =
xencoding = _T("*");
}
if ( test )
{
fontSpec.Printf(_T("-*-*-*-*-*-*-*-*-*-*-*-*-%s-%s"),
xregistry.c_str(), xencoding.c_str());
if ( !wxTestFontSpec(fontSpec) )
{
// this encoding isn't available - what to do?
xregistry =
xencoding = _T("*");
}
}
// construct the X font spec from our data
fontSpec.Printf(_T("-*-%s-%s-%s-normal-*-*-%d-*-*-*-*-%s-%s"),
xfamily.c_str(), xweight.c_str(), xstyle.c_str(),
pointSize, xregistry.c_str(), xencoding.c_str());
return gdk_font_load( wxConvCurrent->cWX2MB(fontSpec) );
}
static GdkFont *wxLoadQueryNearestFont( int pointSize,
int family,
int style,
int weight,
bool underlined,
const wxString &facename,
wxFontEncoding encoding )
{
GdkFont *font = wxLoadQueryFont( pointSize, family, style, weight,
underlined, facename, encoding );
if (!font)
{
/* search up and down by stepsize 10 */
int max_size = pointSize + 20 * (1 + (pointSize/180));
int min_size = pointSize - 20 * (1 + (pointSize/180));
int i;
/* Search for smaller size (approx.) */
for ( i = pointSize - 10; !font && i >= 10 && i >= min_size; i -= 10 )
{
font = wxLoadQueryFont(i, family, style, weight, underlined,
facename, encoding );
}
/* Search for larger size (approx.) */
for ( i = pointSize + 10; !font && i <= max_size; i += 10 )
{
font = wxLoadQueryFont( i, family, style, weight, underlined,
facename, encoding );
}
/* Try default family */
if ( !font && family != wxDEFAULT )
{
font = wxLoadQueryFont( pointSize, wxDEFAULT, style, weight,
underlined, facename, encoding );
}
/* Bogus font */
if ( !font )
{
font = wxLoadQueryFont(120, wxDEFAULT, wxNORMAL, wxNORMAL,
underlined, facename, encoding );
}
}
return font;
}
// wow, what's this stuff? Is it used/useful? (VZ) // wow, what's this stuff? Is it used/useful? (VZ)
#if 0 #if 0

View File

@@ -9,8 +9,16 @@
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation "font.h" #pragma implementation "font.h"
#endif #endif
#include "wx/defs.h" #include "wx/defs.h"
@@ -22,9 +30,82 @@
#include <Xm/Xm.h> #include <Xm/Xm.h>
#if !USE_SHARED_LIBRARIES #if !USE_SHARED_LIBRARIES
IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
#endif #endif
// ----------------------------------------------------------------------------
// private classes
// ----------------------------------------------------------------------------
// For every wxFont, there must be a font for each display and scale requested.
// So these objects are stored in wxFontRefData::m_fonts
class wxXFont: public wxObject
{
public:
wxXFont();
~wxXFont();
WXFontStructPtr m_fontStruct; // XFontStruct
WXFontList m_fontList; // Motif XmFontList
WXDisplay* m_display; // XDisplay
int m_scale; // Scale * 100
};
class wxFontRefData: public wxGDIRefData
{
friend class wxFont;
public:
wxFontRefData(int size = wxDEFAULT,
int family = wxDEFAULT,
int style = wxDEFAULT,
int weight = wxDEFAULT,
bool underlined = FALSE,
const wxString& faceName = wxEmptyString,
wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
{
Init(size, family, style, weight, underlined, faceName, encoding);
}
wxFontRefData(const wxFontRefData& data)
{
Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight,
data.m_underlined, data.m_faceName, data.m_encoding);
}
~wxFontRefData();
protected:
// common part of all ctors
void Init(int size,
int family,
int style,
int weight,
bool underlined,
const wxString& faceName,
wxFontEncoding encoding);
// font attributes
int m_pointSize;
int m_family;
int m_style;
int m_weight;
bool m_underlined;
wxString m_faceName;
wxFontEncoding m_encoding;
// A list of wxXFonts
wxList m_fonts;
};
// ============================================================================
// implementation
// ============================================================================
// ----------------------------------------------------------------------------
// wxXFont
// ----------------------------------------------------------------------------
wxXFont::wxXFont() wxXFont::wxXFont()
{ {
m_fontStruct = (WXFontStructPtr) 0; m_fontStruct = (WXFontStructPtr) 0;
@@ -45,29 +126,42 @@ wxXFont::~wxXFont()
// XFreeFont((Display*) m_display, fontStruct); // XFreeFont((Display*) m_display, fontStruct);
} }
wxFontRefData::wxFontRefData() // ----------------------------------------------------------------------------
{ // wxFontRefData
m_style = 0; // ----------------------------------------------------------------------------
m_pointSize = 0;
m_family = 0;
m_style = 0;
m_weight = 0;
m_underlined = 0;
m_faceName = "";
}
wxFontRefData::wxFontRefData(const wxFontRefData& data) void wxFontRefData::Init(int pointSize,
int family,
int style,
int weight,
bool underlined,
const wxString& faceName,
wxFontEncoding encoding)
{ {
m_style = data.m_style; if (family == wxDEFAULT)
m_pointSize = data.m_pointSize; m_family = wxSWISS;
m_family = data.m_family; else
m_style = data.m_style; m_family = family;
m_weight = data.m_weight;
m_underlined = data.m_underlined;
m_faceName = data.m_faceName;
// Don't have to copy actual fonts, because they'll be created m_faceName = faceName;
// on demand.
if (style == wxDEFAULT)
m_style = wxNORMAL;
else
m_style = style;
if (weight == wxDEFAULT)
m_weight = wxNORMAL;
else
m_weight = weight;
if (pointSize == wxDEFAULT)
m_pointSize = 12;
else
m_pointSize = pointSize;
m_underlined = underlined;
m_encoding = encoding;
} }
wxFontRefData::~wxFontRefData() wxFontRefData::~wxFontRefData()
@@ -82,31 +176,27 @@ wxFontRefData::~wxFontRefData()
m_fonts.Clear(); m_fonts.Clear();
} }
wxFont::wxFont() // ----------------------------------------------------------------------------
// wxFont
// ----------------------------------------------------------------------------
void wxFont::Init()
{ {
if ( wxTheFontList ) if ( wxTheFontList )
wxTheFontList->Append(this); wxTheFontList->Append(this);
} }
wxFont::wxFont(int pointSize, int family, int style, int weight, bool underlined, const wxString& faceName) bool wxFont::Create(int pointSize,
{ int family,
Create(pointSize, family, style, weight, underlined, faceName); int style,
int weight,
if ( wxTheFontList ) bool underlined,
wxTheFontList->Append(this); const wxString& faceName,
} wxFontEncoding encoding)
bool wxFont::Create(int pointSize, int family, int style, int weight, bool underlined, const wxString& faceName)
{ {
UnRef(); UnRef();
m_refData = new wxFontRefData; m_refData = new wxFontRefData(pointSize, family, style, weight,
underlined, faceName, encoding);
M_FONTDATA->m_family = family;
M_FONTDATA->m_style = style;
M_FONTDATA->m_weight = weight;
M_FONTDATA->m_pointSize = pointSize;
M_FONTDATA->m_underlined = underlined;
M_FONTDATA->m_faceName = faceName;
RealizeResource(); RealizeResource();
@@ -115,15 +205,13 @@ bool wxFont::Create(int pointSize, int family, int style, int weight, bool under
wxFont::~wxFont() wxFont::~wxFont()
{ {
if (wxTheFontList) if ( wxTheFontList )
wxTheFontList->DeleteObject(this); wxTheFontList->DeleteObject(this);
} }
bool wxFont::RealizeResource() // ----------------------------------------------------------------------------
{ // change the font attributes
// TODO: create the font (if there is a native font object) // ----------------------------------------------------------------------------
return FALSE;
}
void wxFont::Unshare() void wxFont::Unshare()
{ {
@@ -194,92 +282,73 @@ void wxFont::SetUnderlined(bool underlined)
RealizeResource(); RealizeResource();
} }
wxString wxFont::GetFamilyString() const void wxFont::SetEncoding(wxFontEncoding encoding)
{ {
wxString fam(""); Unshare();
switch (GetFamily())
{ M_FONTDATA->m_encoding = encoding;
case wxDECORATIVE:
fam = "wxDECORATIVE"; RealizeResource();
break; }
case wxROMAN:
fam = "wxROMAN"; // ----------------------------------------------------------------------------
break; // query font attributes
case wxSCRIPT: // ----------------------------------------------------------------------------
fam = "wxSCRIPT";
break; int wxFont::GetPointSize() const
case wxSWISS: {
fam = "wxSWISS"; return M_FONTDATA->m_pointSize;
break; }
case wxMODERN:
fam = "wxMODERN"; int wxFont::GetFamily() const
break; {
case wxTELETYPE: return M_FONTDATA->m_family;
fam = "wxTELETYPE"; }
break;
default: int wxFont::GetStyle() const
fam = "wxDEFAULT"; {
break; return M_FONTDATA->m_style;
} }
return fam;
int wxFont::GetWeight() const
{
return M_FONTDATA->m_weight;
}
bool wxFont::GetUnderlined() const
{
return M_FONTDATA->m_underlined;
} }
/* New font system */
wxString wxFont::GetFaceName() const wxString wxFont::GetFaceName() const
{ {
wxString str(""); wxString str;
if (M_FONTDATA) if ( M_FONTDATA )
str = M_FONTDATA->m_faceName ; str = M_FONTDATA->m_faceName ;
return str; return str;
} }
wxString wxFont::GetStyleString() const wxFontEncoding wxFont::GetEncoding() const
{ {
wxString styl(""); return M_FONTDATA->m_encoding;
switch (GetStyle())
{
case wxITALIC:
styl = "wxITALIC";
break;
case wxSLANT:
styl = "wxSLANT";
break;
default:
styl = "wxNORMAL";
break;
}
return styl;
} }
wxString wxFont::GetWeightString() const // ----------------------------------------------------------------------------
{ // real implementation
wxString w(""); // ----------------------------------------------------------------------------
switch (GetWeight())
{
case wxBOLD:
w = "wxBOLD";
break;
case wxLIGHT:
w = "wxLIGHT";
break;
default:
w = "wxNORMAL";
break;
}
return w;
}
// Find an existing, or create a new, XFontStruct // Find an existing, or create a new, XFontStruct
// based on this wxFont and the given scale. Append the // based on this wxFont and the given scale. Append the
// font to list in the private data for future reference. // font to list in the private data for future reference.
wxXFont* wxFont::GetInternalFont(double scale, WXDisplay* display) const wxXFont* wxFont::GetInternalFont(double scale, WXDisplay* display) const
{ {
if (!Ok()) if ( !Ok() )
return (wxXFont*) NULL; return (wxXFont *)NULL;
long intScale = long(scale * 100.0 + 0.5); // key for wxXFont long intScale = long(scale * 100.0 + 0.5); // key for wxXFont
int pointSize = (M_FONTDATA->m_pointSize * 10 * intScale) / 100; int pointSize = (M_FONTDATA->m_pointSize * 10 * intScale) / 100;
// search existing fonts first
wxNode* node = M_FONTDATA->m_fonts.First(); wxNode* node = M_FONTDATA->m_fonts.First();
while (node) while (node)
{ {
@@ -289,91 +358,42 @@ wxXFont* wxFont::GetInternalFont(double scale, WXDisplay* display) const
node = node->Next(); node = node->Next();
} }
WXFontStructPtr font = LoadQueryFont(pointSize, M_FONTDATA->m_family, // not found, create a new one
M_FONTDATA->m_style, M_FONTDATA->m_weight, M_FONTDATA->m_underlined); XFontStruct *font = wxLoadQueryNearestFont(pointSize,
M_FONTDATA->m_family,
M_FONTDATA->m_style,
M_FONTDATA->m_weight,
M_FONTDATA->m_underlined,
_T(""),
M_FONTDATA->m_encoding);
if (!font) if ( !font )
{ {
// search up and down by stepsize 10 wxFAIL_MSG( _T("Could not allocate even a default font -- something is wrong.") );
int max_size = pointSize + 20 * (1 + (pointSize/180));
int min_size = pointSize - 20 * (1 + (pointSize/180));
int i;
// Search for smaller size (approx.) return (wxXFont*) NULL;
for (i=pointSize-10; !font && i >= 10 && i >= min_size; i -= 10)
font = LoadQueryFont(i, M_FONTDATA->m_family, M_FONTDATA->m_style, M_FONTDATA->m_weight, M_FONTDATA->m_underlined);
// Search for larger size (approx.)
for (i=pointSize+10; !font && i <= max_size; i += 10)
font = LoadQueryFont(i, M_FONTDATA->m_family, M_FONTDATA->m_style, M_FONTDATA->m_weight, M_FONTDATA->m_underlined);
// Try default family
if (!font && M_FONTDATA->m_family != wxDEFAULT)
font = LoadQueryFont(pointSize, wxDEFAULT, M_FONTDATA->m_style,
M_FONTDATA->m_weight, M_FONTDATA->m_underlined);
// Bogus font
if (!font)
font = LoadQueryFont(120, wxDEFAULT, wxNORMAL, wxNORMAL,
M_FONTDATA->m_underlined);
wxASSERT_MSG( (font != (XFontStruct*) NULL), "Could not allocate even a default font -- something is wrong." );
} }
if (font)
{ wxXFont* f = new wxXFont;
wxXFont* f = new wxXFont; f->m_fontStruct = (WXFontStructPtr)font;
f->m_fontStruct = font; f->m_display = ( display ? display : wxGetDisplay() );
f->m_display = ( display ? display : wxGetDisplay() ); f->m_scale = intScale;
f->m_scale = intScale; f->m_fontList = XmFontListCreate ((XFontStruct*) font, XmSTRING_DEFAULT_CHARSET);
f->m_fontList = XmFontListCreate ((XFontStruct*) font, XmSTRING_DEFAULT_CHARSET); M_FONTDATA->m_fonts.Append(f);
M_FONTDATA->m_fonts.Append(f);
return f; return f;
}
return (wxXFont*) NULL;
} }
WXFontStructPtr wxFont::LoadQueryFont(int pointSize, int family, int style, WXFontStructPtr wxFont::GetFontStruct(double scale, WXDisplay* display) const
int weight, bool underlined) const
{ {
char *xfamily; wxXFont* f = GetInternalFont(scale, display);
char *xstyle;
char *xweight;
switch (family)
{
case wxDECORATIVE: xfamily = "lucida";
break;
case wxROMAN: xfamily = "times";
break;
case wxMODERN: xfamily = "courier";
break;
case wxSWISS: xfamily = "lucida";
break;
case wxDEFAULT:
default: xfamily = "*";
}
switch (style)
{
case wxITALIC: xstyle = "i";
break;
case wxSLANT: xstyle = "o";
break;
case wxNORMAL: xstyle = "r";
break;
default: xstyle = "*";
break;
}
switch (weight)
{
case wxBOLD: xweight = "bold";
break;
case wxLIGHT:
case wxNORMAL: xweight = "medium";
break;
default: xweight = "*";
break;
}
sprintf(wxBuffer, "-*-%s-%s-%s-normal-*-*-%d-*-*-*-*-*-*", return (f ? f->m_fontStruct : (WXFontStructPtr) 0);
xfamily, xweight, xstyle, pointSize); }
Display *dpy = (Display*) wxGetDisplay(); WXFontList wxFont::GetFontList(double scale, WXDisplay* display) const
XFontStruct* font = XLoadQueryFont(dpy, wxBuffer); {
wxXFont* f = GetInternalFont(scale, display);
return (WXFontStructPtr) font;
return (f ? f->m_fontList : (WXFontList) 0);
} }

View File

@@ -1,6 +1,6 @@
# This file was automatically generated by tmake at 20:03, 1999/09/29 # This file was automatically generated by tmake at 15:48, 1999/10/01
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE B32.T! # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE B32.T!
# #

View File

@@ -1,6 +1,6 @@
# This file was automatically generated by tmake at 20:03, 1999/09/29 # This file was automatically generated by tmake at 15:48, 1999/10/01
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE BCC.T! # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE BCC.T!
# #

View File

@@ -1,6 +1,6 @@
# This file was automatically generated by tmake at 20:03, 1999/09/29 # This file was automatically generated by tmake at 15:48, 1999/10/01
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE DOS.T! # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE DOS.T!
# #
@@ -116,6 +116,7 @@ COMMONOBJS = \
$(COMMDIR)\gifdecod.obj \ $(COMMDIR)\gifdecod.obj \
$(COMMDIR)\hash.obj \ $(COMMDIR)\hash.obj \
$(COMMDIR)\helpbase.obj \ $(COMMDIR)\helpbase.obj \
$(COMMDIR)\imagall.obj \
$(COMMDIR)\imagbmp.obj \ $(COMMDIR)\imagbmp.obj \
$(COMMDIR)\image.obj \ $(COMMDIR)\image.obj \
$(COMMDIR)\imaggif.obj \ $(COMMDIR)\imaggif.obj \
@@ -815,6 +816,11 @@ $(COMMDIR)/helpbase.obj: $*.$(SRCSUFF)
$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF) $(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF)
<< <<
$(COMMDIR)/imagall.obj: $*.$(SRCSUFF)
cl @<<
$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF)
<<
$(COMMDIR)/imagbmp.obj: $*.$(SRCSUFF) $(COMMDIR)/imagbmp.obj: $*.$(SRCSUFF)
cl @<< cl @<<
$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF) $(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF)

View File

@@ -1,5 +1,5 @@
# This file was automatically generated by tmake at 20:03, 1999/09/29 # This file was automatically generated by tmake at 15:48, 1999/10/01
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE G95.T! # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE G95.T!
# #
@@ -91,6 +91,7 @@ COMMONOBJS = \
$(COMMDIR)/hash.$(OBJSUFF) \ $(COMMDIR)/hash.$(OBJSUFF) \
$(COMMDIR)/helpbase.$(OBJSUFF) \ $(COMMDIR)/helpbase.$(OBJSUFF) \
$(COMMDIR)/http.$(OBJSUFF) \ $(COMMDIR)/http.$(OBJSUFF) \
$(COMMDIR)/imagall.$(OBJSUFF) \
$(COMMDIR)/imagbmp.$(OBJSUFF) \ $(COMMDIR)/imagbmp.$(OBJSUFF) \
$(COMMDIR)/image.$(OBJSUFF) \ $(COMMDIR)/image.$(OBJSUFF) \
$(COMMDIR)/imaggif.$(OBJSUFF) \ $(COMMDIR)/imaggif.$(OBJSUFF) \

View File

@@ -1,6 +1,6 @@
# This file was automatically generated by tmake at 20:03, 1999/09/29 # This file was automatically generated by tmake at 15:48, 1999/10/01
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE SC.T! # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE SC.T!
# Symantec C++ makefile for the msw objects # Symantec C++ makefile for the msw objects
@@ -79,6 +79,7 @@ COMMONOBJS = \
$(COMMDIR)\hash.obj \ $(COMMDIR)\hash.obj \
$(COMMDIR)\helpbase.obj \ $(COMMDIR)\helpbase.obj \
$(COMMDIR)\http.obj \ $(COMMDIR)\http.obj \
$(COMMDIR)\imagall.obj \
$(COMMDIR)\imagbmp.obj \ $(COMMDIR)\imagbmp.obj \
$(COMMDIR)\image.obj \ $(COMMDIR)\image.obj \
$(COMMDIR)\imaggif.obj \ $(COMMDIR)\imaggif.obj \

View File

@@ -1,4 +1,4 @@
# This file was automatically generated by tmake at 14:12, 1999/09/30 # This file was automatically generated by tmake at 15:48, 1999/10/01
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE VC.T! # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE VC.T!
# File: makefile.vc # File: makefile.vc

View File

@@ -1,6 +1,6 @@
# This file was automatically generated by tmake at 20:03, 1999/09/29 # This file was automatically generated by tmake at 15:48, 1999/10/01
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE WAT.T! # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE WAT.T!
#!/binb/wmake.exe #!/binb/wmake.exe
@@ -105,6 +105,7 @@ COMMONOBJS = &
hash.obj & hash.obj &
helpbase.obj & helpbase.obj &
http.obj & http.obj &
imagall.obj &
imagbmp.obj & imagbmp.obj &
image.obj & image.obj &
imaggif.obj & imaggif.obj &
@@ -644,6 +645,9 @@ helpbase.obj: $(COMMDIR)\helpbase.cpp
http.obj: $(COMMDIR)\http.cpp http.obj: $(COMMDIR)\http.cpp
*$(CCC) $(CPPFLAGS) $(IFLAGS) $< *$(CCC) $(CPPFLAGS) $(IFLAGS) $<
imagall.obj: $(COMMDIR)\imagall.cpp
*$(CCC) $(CPPFLAGS) $(IFLAGS) $<
imagbmp.obj: $(COMMDIR)\imagbmp.cpp imagbmp.obj: $(COMMDIR)\imagbmp.cpp
*$(CCC) $(CPPFLAGS) $(IFLAGS) $< *$(CCC) $(CPPFLAGS) $(IFLAGS) $<

View File

@@ -569,3 +569,249 @@ void wxFatalError( const wxString &msg, const wxString &title )
wxFprintf( stderr, _T(".\n") ); wxFprintf( stderr, _T(".\n") );
exit(3); // the same exit code as for abort() exit(3); // the same exit code as for abort()
} }
// ----------------------------------------------------------------------------
// font-related functions
// ----------------------------------------------------------------------------
// define the functions to create and destroy native fonts for this toolkit
#ifdef __X__
static inline wxNativeFont wxLoadFont(const wxString& fontSpec)
{
return XLoadQueryFont((Display *)wxGetDisplay(), fontSpec);
}
static inline void wxFreeFont(wxNativeFont font)
{
XFreeFont((Display *)wxGetDisplay(), font);
}
#elif defined(__WXGTK__)
static inline wxNativeFont wxLoadFont(const wxString& fontSpec)
{
return gdk_font_load( wxConvCurrent->cWX2MB(fontSpec) );
}
static inline void wxFreeFont(wxNativeFont font)
{
gdk_font_unref(font);
}
#else
#error "Unknown GUI toolkit"
#endif
// returns TRUE if there are any fonts matching this font spec
static bool wxTestFontSpec(const wxString& fontspec)
{
wxNativeFont test = wxLoadFont(fontspec);
if ( test )
{
wxFreeFont(test);
return TRUE;
}
else
{
return FALSE;
}
}
// TODO encoding test logic should be moved to wxLoadQueryNearestFont()
static wxNativeFont wxLoadQueryFont(int pointSize,
int family,
int style,
int weight,
bool WXUNUSED(underlined),
const wxString &facename,
wxFontEncoding encoding )
{
wxString xfamily;
switch (family)
{
case wxDECORATIVE: xfamily = _T("lucida"); break;
case wxROMAN: xfamily = _T("times"); break;
case wxMODERN: xfamily = _T("courier"); break;
case wxSWISS: xfamily = _T("helvetica"); break;
case wxTELETYPE: xfamily = _T("lucidatypewriter"); break;
case wxSCRIPT: xfamily = _T("utopia"); break;
default: xfamily = _T("*");
}
wxString fontSpec;
if (!facename.IsEmpty())
{
fontSpec.Printf(_T("-*-%s-*-*-normal-*-*-*-*-*-*-*-*-*"),
facename.c_str());
if ( wxTestFontSpec(fontSpec) )
{
xfamily = facename;
}
//else: no such family, use default one instead
}
wxString xstyle;
switch (style)
{
case wxITALIC: xstyle = _T("i"); break;
case wxSLANT: xstyle = _T("o"); break;
case wxNORMAL: xstyle = _T("r"); break;
default: xstyle = _T("*"); break;
}
wxString xweight;
switch (weight)
{
case wxBOLD: xweight = _T("bold"); break;
case wxLIGHT:
case wxNORMAL: xweight = _T("medium"); break;
default: xweight = _T("*"); break;
}
wxString xregistry, xencoding;
if ( encoding == wxFONTENCODING_DEFAULT )
{
// use the apps default
encoding = wxFont::GetDefaultEncoding();
}
bool test = TRUE; // should we test for availability of encoding?
switch ( encoding )
{
case wxFONTENCODING_ISO8859_1:
case wxFONTENCODING_ISO8859_2:
case wxFONTENCODING_ISO8859_3:
case wxFONTENCODING_ISO8859_4:
case wxFONTENCODING_ISO8859_5:
case wxFONTENCODING_ISO8859_6:
case wxFONTENCODING_ISO8859_7:
case wxFONTENCODING_ISO8859_8:
case wxFONTENCODING_ISO8859_9:
case wxFONTENCODING_ISO8859_10:
case wxFONTENCODING_ISO8859_11:
case wxFONTENCODING_ISO8859_13:
case wxFONTENCODING_ISO8859_14:
case wxFONTENCODING_ISO8859_15:
{
int cp = encoding - wxFONTENCODING_ISO8859_1 + 1;
xregistry = _T("iso8859");
xencoding.Printf(_T("%d"), cp);
}
break;
case wxFONTENCODING_KOI8:
xregistry = _T("koi8");
if ( wxTestFontSpec(_T("-*-*-*-*-*-*-*-*-*-*-*-*-koi8-1")) )
{
xencoding = _T("1");
// test passed, no need to do it once more
test = FALSE;
}
else
{
xencoding = _T("*");
}
break;
case wxFONTENCODING_CP1250:
case wxFONTENCODING_CP1251:
case wxFONTENCODING_CP1252:
{
int cp = encoding - wxFONTENCODING_CP1250 + 1250;
fontSpec.Printf(_T("-*-*-*-*-*-*-*-*-*-*-*-*-microsoft-cp%d"),
cp);
if ( wxTestFontSpec(fontSpec) )
{
xregistry = _T("microsoft");
xencoding.Printf(_T("cp%d"), cp);
// test passed, no need to do it once more
test = FALSE;
}
else
{
// fall back to LatinX
xregistry = _T("iso8859");
xencoding.Printf(_T("%d"), cp - 1249);
}
}
break;
case wxFONTENCODING_SYSTEM:
default:
test = FALSE;
xregistry =
xencoding = _T("*");
}
if ( test )
{
fontSpec.Printf(_T("-*-*-*-*-*-*-*-*-*-*-*-*-%s-%s"),
xregistry.c_str(), xencoding.c_str());
if ( !wxTestFontSpec(fontSpec) )
{
// this encoding isn't available - what to do?
xregistry =
xencoding = _T("*");
}
}
// construct the X font spec from our data
fontSpec.Printf(_T("-*-%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,
int family,
int style,
int weight,
bool underlined,
const wxString &facename,
wxFontEncoding encoding)
{
wxNativeFont font = wxLoadQueryFont( pointSize, family, style, weight,
underlined, facename, encoding );
if (!font)
{
// search up and down by stepsize 10
int max_size = pointSize + 20 * (1 + (pointSize/180));
int min_size = pointSize - 20 * (1 + (pointSize/180));
int i;
// Search for smaller size (approx.)
for ( i = pointSize - 10; !font && i >= 10 && i >= min_size; i -= 10 )
{
font = wxLoadQueryFont(i, family, style, weight, underlined,
facename, encoding );
}
// Search for larger size (approx.)
for ( i = pointSize + 10; !font && i <= max_size; i += 10 )
{
font = wxLoadQueryFont( i, family, style, weight, underlined,
facename, encoding );
}
// Try default family
if ( !font && family != wxDEFAULT )
{
font = wxLoadQueryFont( pointSize, wxDEFAULT, style, weight,
underlined, facename, encoding );
}
// Bogus font
if ( !font )
{
font = wxLoadQueryFont(120, wxDEFAULT, wxNORMAL, wxNORMAL,
underlined, facename, encoding );
}
}
return font;
}