wave.cpp R
window.cpp R
-gsockmot.cpp X
+gsockmot.c X S
accel.cpp X
app.cpp X
bitmap.cpp X
#define _WX_FONT_H_
#ifdef __GNUG__
-#pragma interface "font.h"
+ #pragma interface "font.h"
#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
+// Font
+class wxFont : public wxFontBase
{
public:
- wxXFont();
- ~wxXFont();
+ // ctors and such
+ wxFont() { Init(); }
+ wxFont(const wxFont& font) { Init(); Ref(font); }
+
+ wxFont(int size,
+ int family,
+ int style,
+ int weight,
+ bool underlined = FALSE,
+ const wxString& face = wxEmptyString,
+ wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
+ {
+ Init();
+
+ (void)Create(size, family, style, weight, underlined, face, encoding);
+ }
+
+ bool Create(int size,
+ int family,
+ int style,
+ int weight,
+ bool underlined = FALSE,
+ const wxString& face = wxEmptyString,
+ wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
+
+ virtual ~wxFont();
+
+ // assignment
+ wxFont& operator=(const wxFont& font);
+
+ // implement base class pure virtuals
+ virtual int GetPointSize() const;
+ virtual int GetFamily() const;
+ virtual int GetStyle() const;
+ virtual int GetWeight() const;
+ virtual bool GetUnderlined() const;
+ virtual wxString GetFaceName() const;
+ virtual wxFontEncoding GetEncoding() const;
+
+ 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);
+
+ // Implementation
+
+ // Find an existing, or create a new, XFontStruct
+ // 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
+ // 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.
+
+ // Return font struct, and optionally the Motif font list
+ class wxXFont* GetInternalFont(double scale = 1.0,
+ WXDisplay* display = NULL) const;
+
+ // These two are helper functions for convenient access of the above.
+ WXFontStructPtr GetFontStruct(double scale = 1.0,
+ WXDisplay* display = NULL) const;
+ WXFontList GetFontList(double scale = 1.0,
+ WXDisplay* display = NULL) const;
- 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)
+ // common part of all ctors
+ void Init();
-WXDLLEXPORT_DATA(extern const char*) wxEmptyString;
+ // VZ: IMHO, we don't need it at all...
+ bool RealizeResource() { return TRUE; }
+ void Unshare();
-// Font
-class WXDLLEXPORT wxFont: public wxGDIObject
-{
- DECLARE_DYNAMIC_CLASS(wxFont)
-public:
- wxFont();
- wxFont(int pointSize, int family, int style, int weight, bool underlined = FALSE, const wxString& faceName = wxEmptyString);
- inline wxFont(const wxFont& font) { Ref(font); }
-
- ~wxFont();
-
- bool Create(int pointSize, int family, int style, int weight, bool underlined = FALSE, const wxString& faceName = wxEmptyString);
-
- virtual bool Ok() const { return (m_refData != NULL) ; }
-
- inline int GetPointSize() const { return M_FONTDATA->m_pointSize; }
- 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);
- void SetFamily(int family);
- 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; }
- inline bool operator == (const wxFont& font) const { return m_refData == font.m_refData; }
- inline bool operator != (const wxFont& font) const { return m_refData != font.m_refData; }
-
-// Implementation
-
- // Find an existing, or create a new, XFontStruct
- // 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
- // 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.
-
- // Return font struct, and optionally the Motif font list
- wxXFont* GetInternalFont(double scale = 1.0, WXDisplay* display = NULL) const;
-
- // These two are helper functions for convenient access of the above.
- inline WXFontStructPtr GetFontStruct(double scale = 1.0, WXDisplay* display = NULL) const
- {
- wxXFont* f = GetInternalFont(scale, display);
- return (f ? f->m_fontStruct : (WXFontStructPtr) 0);
- }
- WXFontList GetFontList(double scale = 1.0, WXDisplay* display = NULL) const
- {
- wxXFont* f = GetInternalFont(scale, display);
- return (f ? f->m_fontList : (WXFontList) 0);
- }
-
- WXFontStructPtr LoadQueryFont(int pointSize, int family, int style,
- int weight, bool underlined) const;
-protected:
- bool RealizeResource();
- void Unshare();
+private:
+ DECLARE_DYNAMIC_CLASS(wxFont)
};
#endif
#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
// _WX_UTILSH__
// private functions
// ----------------------------------------------------------------------------
-// returns TRUE if there are any fonts matching this font spec
-static bool wxTestFontSpec(const wxString& fontspec);
-
static GdkFont *wxLoadQueryFont( int pointSize,
int family,
int style,
// 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)
#if 0
// private functions
// ----------------------------------------------------------------------------
-// returns TRUE if there are any fonts matching this font spec
-static bool wxTestFontSpec(const wxString& fontspec);
-
static GdkFont *wxLoadQueryFont( int pointSize,
int family,
int style,
// 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)
#if 0
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
#ifdef __GNUG__
-#pragma implementation "font.h"
+ #pragma implementation "font.h"
#endif
#include "wx/defs.h"
#include <Xm/Xm.h>
#if !USE_SHARED_LIBRARIES
-IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
+ IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
#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()
{
m_fontStruct = (WXFontStructPtr) 0;
// XFreeFont((Display*) m_display, fontStruct);
}
-wxFontRefData::wxFontRefData()
+// ----------------------------------------------------------------------------
+// wxFontRefData
+// ----------------------------------------------------------------------------
+
+void wxFontRefData::Init(int pointSize,
+ int family,
+ int style,
+ int weight,
+ bool underlined,
+ const wxString& faceName,
+ wxFontEncoding encoding)
{
- m_style = 0;
- m_pointSize = 0;
- m_family = 0;
- m_style = 0;
- m_weight = 0;
- m_underlined = 0;
- m_faceName = "";
-}
+ if (family == wxDEFAULT)
+ m_family = wxSWISS;
+ else
+ m_family = family;
-wxFontRefData::wxFontRefData(const wxFontRefData& data)
-{
- m_style = data.m_style;
- m_pointSize = data.m_pointSize;
- m_family = data.m_family;
- m_style = data.m_style;
- 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
- // on demand.
+ m_faceName = faceName;
+
+ 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()
m_fonts.Clear();
}
-wxFont::wxFont()
-{
- if ( wxTheFontList )
- wxTheFontList->Append(this);
-}
+// ----------------------------------------------------------------------------
+// wxFont
+// ----------------------------------------------------------------------------
-wxFont::wxFont(int pointSize, int family, int style, int weight, bool underlined, const wxString& faceName)
+void wxFont::Init()
{
- Create(pointSize, family, style, weight, underlined, faceName);
-
if ( wxTheFontList )
wxTheFontList->Append(this);
}
-bool wxFont::Create(int pointSize, int family, int style, int weight, bool underlined, const wxString& faceName)
+bool wxFont::Create(int pointSize,
+ int family,
+ int style,
+ int weight,
+ bool underlined,
+ const wxString& faceName,
+ wxFontEncoding encoding)
{
UnRef();
- m_refData = new wxFontRefData;
-
- 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;
+ m_refData = new wxFontRefData(pointSize, family, style, weight,
+ underlined, faceName, encoding);
RealizeResource();
wxFont::~wxFont()
{
- if (wxTheFontList)
+ if ( wxTheFontList )
wxTheFontList->DeleteObject(this);
}
-bool wxFont::RealizeResource()
-{
- // TODO: create the font (if there is a native font object)
- return FALSE;
-}
+// ----------------------------------------------------------------------------
+// change the font attributes
+// ----------------------------------------------------------------------------
void wxFont::Unshare()
{
RealizeResource();
}
-wxString wxFont::GetFamilyString() const
+void wxFont::SetEncoding(wxFontEncoding encoding)
{
- wxString fam("");
- switch (GetFamily())
- {
- case wxDECORATIVE:
- fam = "wxDECORATIVE";
- break;
- case wxROMAN:
- fam = "wxROMAN";
- break;
- case wxSCRIPT:
- fam = "wxSCRIPT";
- break;
- case wxSWISS:
- fam = "wxSWISS";
- break;
- case wxMODERN:
- fam = "wxMODERN";
- break;
- case wxTELETYPE:
- fam = "wxTELETYPE";
- break;
- default:
- fam = "wxDEFAULT";
- break;
- }
- return fam;
+ Unshare();
+
+ M_FONTDATA->m_encoding = encoding;
+
+ RealizeResource();
+}
+
+// ----------------------------------------------------------------------------
+// query font attributes
+// ----------------------------------------------------------------------------
+
+int wxFont::GetPointSize() const
+{
+ return M_FONTDATA->m_pointSize;
+}
+
+int wxFont::GetFamily() const
+{
+ return M_FONTDATA->m_family;
+}
+
+int wxFont::GetStyle() const
+{
+ return M_FONTDATA->m_style;
+}
+
+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 str("");
- if (M_FONTDATA)
+ wxString str;
+ if ( M_FONTDATA )
str = M_FONTDATA->m_faceName ;
return str;
}
-wxString wxFont::GetStyleString() const
+wxFontEncoding wxFont::GetEncoding() const
{
- wxString styl("");
- switch (GetStyle())
- {
- case wxITALIC:
- styl = "wxITALIC";
- break;
- case wxSLANT:
- styl = "wxSLANT";
- break;
- default:
- styl = "wxNORMAL";
- break;
- }
- return styl;
+ return M_FONTDATA->m_encoding;
}
-wxString wxFont::GetWeightString() const
-{
- wxString w("");
- switch (GetWeight())
- {
- case wxBOLD:
- w = "wxBOLD";
- break;
- case wxLIGHT:
- w = "wxLIGHT";
- break;
- default:
- w = "wxNORMAL";
- break;
- }
- return w;
-}
+// ----------------------------------------------------------------------------
+// real implementation
+// ----------------------------------------------------------------------------
// Find an existing, or create a new, XFontStruct
// based on this wxFont and the given scale. Append the
// font to list in the private data for future reference.
wxXFont* wxFont::GetInternalFont(double scale, WXDisplay* display) const
{
- if (!Ok())
- return (wxXFont*) NULL;
+ if ( !Ok() )
+ return (wxXFont *)NULL;
long intScale = long(scale * 100.0 + 0.5); // key for wxXFont
int pointSize = (M_FONTDATA->m_pointSize * 10 * intScale) / 100;
+ // search existing fonts first
wxNode* node = M_FONTDATA->m_fonts.First();
while (node)
{
node = node->Next();
}
- WXFontStructPtr font = LoadQueryFont(pointSize, M_FONTDATA->m_family,
- M_FONTDATA->m_style, M_FONTDATA->m_weight, M_FONTDATA->m_underlined);
+ // not found, create a new one
+ 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)
- {
- // 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 = 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)
+ if ( !font )
{
- wxXFont* f = new wxXFont;
- f->m_fontStruct = font;
- f->m_display = ( display ? display : wxGetDisplay() );
- f->m_scale = intScale;
- f->m_fontList = XmFontListCreate ((XFontStruct*) font, XmSTRING_DEFAULT_CHARSET);
- M_FONTDATA->m_fonts.Append(f);
- return f;
+ wxFAIL_MSG( _T("Could not allocate even a default font -- something is wrong.") );
+
+ return (wxXFont*) NULL;
}
- return (wxXFont*) NULL;
+
+ wxXFont* f = new wxXFont;
+ f->m_fontStruct = (WXFontStructPtr)font;
+ f->m_display = ( display ? display : wxGetDisplay() );
+ f->m_scale = intScale;
+ f->m_fontList = XmFontListCreate ((XFontStruct*) font, XmSTRING_DEFAULT_CHARSET);
+ M_FONTDATA->m_fonts.Append(f);
+
+ return f;
}
-WXFontStructPtr wxFont::LoadQueryFont(int pointSize, int family, int style,
- int weight, bool underlined) const
+WXFontStructPtr wxFont::GetFontStruct(double scale, WXDisplay* display) const
{
- char *xfamily;
- 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;
- }
+ wxXFont* f = GetInternalFont(scale, display);
- sprintf(wxBuffer, "-*-%s-%s-%s-normal-*-*-%d-*-*-*-*-*-*",
- xfamily, xweight, xstyle, pointSize);
+ return (f ? f->m_fontStruct : (WXFontStructPtr) 0);
+}
- Display *dpy = (Display*) wxGetDisplay();
- XFontStruct* font = XLoadQueryFont(dpy, wxBuffer);
+WXFontList wxFont::GetFontList(double scale, WXDisplay* display) const
+{
+ wxXFont* f = GetInternalFont(scale, display);
- return (WXFontStructPtr) font;
+ return (f ? f->m_fontList : (WXFontList) 0);
}
-# 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!
#
-# 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!
#
-# 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!
#
$(COMMDIR)\gifdecod.obj \
$(COMMDIR)\hash.obj \
$(COMMDIR)\helpbase.obj \
+ $(COMMDIR)\imagall.obj \
$(COMMDIR)\imagbmp.obj \
$(COMMDIR)\image.obj \
$(COMMDIR)\imaggif.obj \
$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF)
<<
+$(COMMDIR)/imagall.obj: $*.$(SRCSUFF)
+ cl @<<
+$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF)
+<<
+
$(COMMDIR)/imagbmp.obj: $*.$(SRCSUFF)
cl @<<
$(CPPFLAGS) /Fo$@ /c /Tp $*.$(SRCSUFF)
-# 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!
#
$(COMMDIR)/hash.$(OBJSUFF) \
$(COMMDIR)/helpbase.$(OBJSUFF) \
$(COMMDIR)/http.$(OBJSUFF) \
+ $(COMMDIR)/imagall.$(OBJSUFF) \
$(COMMDIR)/imagbmp.$(OBJSUFF) \
$(COMMDIR)/image.$(OBJSUFF) \
$(COMMDIR)/imaggif.$(OBJSUFF) \
-# 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!
# Symantec C++ makefile for the msw objects
$(COMMDIR)\hash.obj \
$(COMMDIR)\helpbase.obj \
$(COMMDIR)\http.obj \
+ $(COMMDIR)\imagall.obj \
$(COMMDIR)\imagbmp.obj \
$(COMMDIR)\image.obj \
$(COMMDIR)\imaggif.obj \
-# 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!
# File: makefile.vc
-# 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!
#!/binb/wmake.exe
hash.obj &
helpbase.obj &
http.obj &
+ imagall.obj &
imagbmp.obj &
image.obj &
imaggif.obj &
http.obj: $(COMMDIR)\http.cpp
*$(CCC) $(CPPFLAGS) $(IFLAGS) $<
+imagall.obj: $(COMMDIR)\imagall.cpp
+ *$(CCC) $(CPPFLAGS) $(IFLAGS) $<
+
imagbmp.obj: $(COMMDIR)\imagbmp.cpp
*$(CCC) $(CPPFLAGS) $(IFLAGS) $<
wxFprintf( stderr, _T(".\n") );
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;
+}
+