/////////////////////////////////////////////////////////////////////////////
-// Name: font.cpp
+// Name: src/mgl/font.cpp
// Author: Vaclav Slavik
// Id: $Id$
-// Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
+// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// headers
// ----------------------------------------------------------------------------
-#ifdef __GNUG__
- #pragma implementation "font.h"
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+ #pragma hdrstop
#endif
#include "wx/font.h"
-#include "wx/fontutil.h"
-#include "wx/cmndata.h"
-#include "wx/utils.h"
-#include "wx/log.h"
-#include "wx/gdicmn.h"
-#include "wx/tokenzr.h"
-#include "wx/settings.h"
-
-#include <strings.h>
-
-// ----------------------------------------------------------------------------
-// wxFontRefData
-// ----------------------------------------------------------------------------
-class wxFontRefData : public wxObjectRefData
-{
-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);
- wxFontRefData(const wxFontRefData& data);
- virtual ~wxFontRefData();
-
-protected:
- // common part of all ctors
- void Init(int pointSize,
- int family,
- int style,
- int weight,
- bool underlined,
- const wxString& faceName,
- wxFontEncoding encoding);
-
-private:
- int m_pointSize;
- int m_family,
- m_style,
- m_weight;
- bool m_underlined;
- wxString m_faceName;
- wxFontEncoding m_encoding;
-
- wxMGLFontLibrary *m_library;
- bool m_valid;
-
- friend class wxFont;
-};
+#include "wx/private/fontmgr.h"
// ============================================================================
// implementation
// ============================================================================
-// ----------------------------------------------------------------------------
-// wxFontRefData
-// ----------------------------------------------------------------------------
-
-void wxFontRefData::Init(int pointSize,
- int family,
- int style,
- int weight,
- bool underlined,
- const wxString& faceName,
- wxFontEncoding encoding)
-{
- if ( family == wxDEFAULT )
- m_family = wxSWISS;
- else
- m_family = family;
-
- 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;
-
- m_library = NULL;
- m_valid = FALSE;
-}
-
-wxFontRefData::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);
-
- m_library = data.m_library;
- m_valid = data.m_valid;
- if ( m_library )
- m_library->IncRef();
- wxLogTrace("mgl_font", "created fntrefdata %p, library is %p", this, m_library);
-}
-
-wxFontRefData::wxFontRefData(int size, int family, int style,
- int weight, bool underlined,
- const wxString& faceName,
- wxFontEncoding encoding)
-{
- Init(size, family, style, weight, underlined, faceName, encoding);
- wxLogTrace("mgl_font", "created fntrefdata %p, library is %p", this, m_library);
-}
-
-wxFontRefData::~wxFontRefData()
-{
- wxLogTrace("mgl_font", "destructing fntrefdata %p, library is %p", this, m_library);
- if ( m_library )
- m_library->DecRef();
-}
+typedef wxFontMgrFontRefData wxFontRefData;
+#define M_FONTDATA ((wxFontRefData*)m_refData)
// ----------------------------------------------------------------------------
// wxFont
IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
-void wxFont::Init()
-{
- if (wxTheFontList)
- wxTheFontList->Append(this);
-}
-
bool wxFont::Create(const wxNativeFontInfo& info)
{
return Create(info.pointSize, info.family, info.style, info.weight,
}
bool wxFont::Create(int pointSize,
- int family,
- int style,
- int weight,
+ wxFontFamily family,
+ wxFontStyle style,
+ wxFontWeight weight,
bool underlined,
const wxString& face,
wxFontEncoding encoding)
{
m_refData = new wxFontRefData(pointSize, family, style, weight,
underlined, face, encoding);
- return TRUE;
+ return true;
}
-struct font_t *wxFont::GetMGLfont_t(float scale, bool antialiased)
+wxGDIRefData *wxFont::CreateGDIRefData() const
{
- // FIXME_MGL -- no antialiasing for fonts smaller than certain treshold!
- if ( !M_FONTDATA->m_valid )
- {
- wxMGLFontLibrary *old = M_FONTDATA->m_library;
- M_FONTDATA->m_library = wxTheFontsManager->GetFontLibrary(this);
- M_FONTDATA->m_library->IncRef();
- if ( old )
- old->DecRef();
- }
-
- wxMGLFontInstance *instance =
- M_FONTDATA->m_library->GetFontInstance(this, scale, antialiased);
-
- return instance->GetMGLfont_t();
+ return new wxFontRefData;
}
-void wxFont::Unshare()
+wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const
{
- if ( !m_refData )
- {
- m_refData = new wxFontRefData();
- }
- else
- {
- wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
- UnRef();
- m_refData = ref;
- }
+ return new wxFontRefData(*(wxFontRefData *)data);
}
-wxFont::~wxFont()
-{
- if (wxTheFontList)
- wxTheFontList->DeleteObject(this);
-}
// ----------------------------------------------------------------------------
// accessors
// ----------------------------------------------------------------------------
+struct font_t *wxFont::GetMGLfont_t(float scale, bool antialiased)
+{
+ wxCHECK_MSG( Ok(), NULL, wxT("invalid font") );
+
+ // we don't support DC scaling yet, so use scale=1
+ wxFontInstance *i = M_FONTDATA->GetFontInstance(1.0, antialiased);
+ return i ? i->GetMGLfont_t() : NULL;
+}
+
int wxFont::GetPointSize() const
{
wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
- return M_FONTDATA->m_pointSize;
+ return M_FONTDATA->GetPointSize();
}
wxString wxFont::GetFaceName() const
{
- wxCHECK_MSG( Ok(), wxT(""), wxT("invalid font") );
+ wxCHECK_MSG( Ok(), wxEmptyString, wxT("invalid font") );
- return M_FONTDATA->m_faceName;
+ return M_FONTDATA->GetFaceName();
}
-int wxFont::GetFamily() const
+wxFontFamily wxFont::GetFamily() const
{
- wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
+ wxCHECK_MSG( Ok(), wxFONTFAMILY_MAX, wxT("invalid font") );
- return M_FONTDATA->m_family;
+ return M_FONTDATA->GetFamily();
}
-int wxFont::GetStyle() const
+wxFontStyle wxFont::GetStyle() const
{
- wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
+ wxCHECK_MSG( Ok(), wxFONTSTYLE_MAX, wxT("invalid font") );
- return M_FONTDATA->m_style;
+ return M_FONTDATA->GetStyle();
}
-int wxFont::GetWeight() const
+wxFontWeight wxFont::GetWeight() const
{
- wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
+ wxCHECK_MSG( Ok(), wxFONTWEIGHT_MAX, wxT("invalid font") );
- return M_FONTDATA->m_weight;
+ return M_FONTDATA->GetWeight();
}
bool wxFont::GetUnderlined() const
{
- wxCHECK_MSG( Ok(), FALSE, wxT("invalid font") );
+ wxCHECK_MSG( Ok(), false, wxT("invalid font") );
- return M_FONTDATA->m_underlined;
+ return M_FONTDATA->GetUnderlined();
}
{
wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") );
- return M_FONTDATA->m_encoding;
+ return M_FONTDATA->GetEncoding();
}
+bool wxFont::IsFixedWidth() const
+{
+ wxCHECK_MSG( Ok(), false, wxT("invalid font") );
-// ----------------------------------------------------------------------------
-// change font attributes
-// ----------------------------------------------------------------------------
+ return M_FONTDATA->IsFixedWidth();
+}
-void wxFont::SetPointSize(int pointSize)
+const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
{
- Unshare();
+ wxCHECK_MSG( Ok(), NULL, wxT("invalid font") );
- M_FONTDATA->m_pointSize = pointSize;
- M_FONTDATA->m_valid = FALSE;
+ return M_FONTDATA->GetNativeFontInfo();
}
-void wxFont::SetFamily(int family)
+bool wxFont::GetNoAntiAliasing() const
{
- Unshare();
+ wxCHECK_MSG( Ok(), false, wxT("invalid font") );
- M_FONTDATA->m_family = family;
- M_FONTDATA->m_valid = FALSE;
+ return M_FONTDATA->GetNoAntiAliasing();
}
-void wxFont::SetStyle(int style)
-{
- Unshare();
+// ----------------------------------------------------------------------------
+// change font attributes
+// ----------------------------------------------------------------------------
- M_FONTDATA->m_style = style;
- M_FONTDATA->m_valid = FALSE;
+void wxFont::SetPointSize(int pointSize)
+{
+ AllocExclusive();
+ M_FONTDATA->SetPointSize(pointSize);
}
-void wxFont::SetWeight(int weight)
+void wxFont::SetFamily(wxFontFamily family)
{
- Unshare();
+ AllocExclusive();
+ M_FONTDATA->SetFamily(family);
+}
- M_FONTDATA->m_weight = weight;
- M_FONTDATA->m_valid = FALSE;
+void wxFont::SetStyle(wxFontStyle style)
+{
+ AllocExclusive();
+ M_FONTDATA->SetStyle(style);
}
-void wxFont::SetFaceName(const wxString& faceName)
+void wxFont::SetWeight(wxFontWeight weight)
{
- Unshare();
+ AllocExclusive();
+ M_FONTDATA->SetWeight(weight);
+}
- M_FONTDATA->m_faceName = faceName;
- M_FONTDATA->m_valid = FALSE;
+bool wxFont::SetFaceName(const wxString& faceName)
+{
+ AllocExclusive();
+ M_FONTDATA->SetFaceName(faceName);
+ return wxFontBase::SetFaceName(faceName);
}
void wxFont::SetUnderlined(bool underlined)
{
- Unshare();
-
- M_FONTDATA->m_underlined = underlined;
+ AllocExclusive();
+ M_FONTDATA->SetUnderlined(underlined);
}
void wxFont::SetEncoding(wxFontEncoding encoding)
{
- Unshare();
+ AllocExclusive();
+ M_FONTDATA->SetEncoding(encoding);
+}
- M_FONTDATA->m_encoding = encoding;
- M_FONTDATA->m_valid = FALSE;
+void wxFont::SetNoAntiAliasing(bool no)
+{
+ AllocExclusive();
+ M_FONTDATA->SetNoAntiAliasing(no);
}