X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1ac162ad06ea4f97a768a9d0adaf3abbcf6e5f10..8b713759b615fc1530d1f476f37d6d213e7934a5:/src/mgl/font.cpp diff --git a/src/mgl/font.cpp b/src/mgl/font.cpp index 4deda242cf..2cce8212f1 100644 --- a/src/mgl/font.cpp +++ b/src/mgl/font.cpp @@ -1,8 +1,8 @@ ///////////////////////////////////////////////////////////////////////////// -// 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 ///////////////////////////////////////////////////////////////////////////// @@ -14,20 +14,26 @@ // 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" + +#ifndef WX_PRECOMP + #include "wx/log.h" + #include "wx/utils.h" + #include "wx/settings.h" + #include "wx/cmndata.h" +#endif + #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 +#include "wx/mgl/private.h" // ---------------------------------------------------------------------------- // wxFontRefData @@ -40,7 +46,7 @@ public: int family = wxDEFAULT, int style = wxDEFAULT, int weight = wxDEFAULT, - bool underlined = FALSE, + bool underlined = false, const wxString& faceName = wxEmptyString, wxFontEncoding encoding = wxFONTENCODING_DEFAULT); wxFontRefData(const wxFontRefData& data); @@ -68,6 +74,8 @@ private: wxMGLFontLibrary *m_library; bool m_valid; + wxNativeFontInfo m_info; + friend class wxFont; }; @@ -113,7 +121,7 @@ void wxFontRefData::Init(int pointSize, m_encoding = encoding; m_library = NULL; - m_valid = FALSE; + m_valid = false; } wxFontRefData::wxFontRefData(const wxFontRefData& data) @@ -150,12 +158,6 @@ wxFontRefData::~wxFontRefData() 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, @@ -172,12 +174,11 @@ bool wxFont::Create(int pointSize, { 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) { - // FIXME_MGL -- no antialiasing for fonts smaller than certain treshold! if ( !M_FONTDATA->m_valid ) { wxMGLFontLibrary *old = M_FONTDATA->m_library; @@ -187,32 +188,23 @@ struct font_t *wxFont::GetMGLfont_t(float scale, bool antialiased) old->DecRef(); } - wxMGLFontInstance *instance = + wxMGLFontInstance *instance = M_FONTDATA->m_library->GetFontInstance(this, scale, antialiased); return instance->GetMGLfont_t(); } -void wxFont::Unshare() +wxObjectRefData *wxFont::CreateRefData() const { - if ( !m_refData ) - { - m_refData = new wxFontRefData(); - } - else - { - wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData); - UnRef(); - m_refData = ref; - } + return new wxFontRefData; } -wxFont::~wxFont() +wxObjectRefData *wxFont::CloneRefData(const wxObjectRefData *data) const { - if (wxTheFontList) - wxTheFontList->DeleteObject(this); + return new wxFontRefData(*(wxFontRefData *)data); } + // ---------------------------------------------------------------------------- // accessors // ---------------------------------------------------------------------------- @@ -226,7 +218,7 @@ int wxFont::GetPointSize() const wxString wxFont::GetFaceName() const { - wxCHECK_MSG( Ok(), wxT(""), wxT("invalid font") ); + wxCHECK_MSG( Ok(), wxEmptyString, wxT("invalid font") ); return M_FONTDATA->m_faceName; } @@ -254,7 +246,7 @@ int wxFont::GetWeight() const bool wxFont::GetUnderlined() const { - wxCHECK_MSG( Ok(), FALSE, wxT("invalid font") ); + wxCHECK_MSG( Ok(), false, wxT("invalid font") ); return M_FONTDATA->m_underlined; } @@ -267,6 +259,21 @@ wxFontEncoding wxFont::GetEncoding() const return M_FONTDATA->m_encoding; } +bool wxFont::IsFixedWidth() const +{ + wxCHECK_MSG( Ok(), false, wxT("invalid font") ); + + return (bool)(M_FONTDATA->m_library->GetFamily()->GetInfo()->isFixed); +} + +const wxNativeFontInfo *wxFont::GetNativeFontInfo() const +{ + wxCHECK_MSG( Ok(), NULL, wxT("invalid font") ); + + M_FONTDATA->m_info.InitFromFont(*this); + + return &(M_FONTDATA->m_info); +} // ---------------------------------------------------------------------------- // change font attributes @@ -274,55 +281,55 @@ wxFontEncoding wxFont::GetEncoding() const void wxFont::SetPointSize(int pointSize) { - Unshare(); + AllocExclusive(); M_FONTDATA->m_pointSize = pointSize; - M_FONTDATA->m_valid = FALSE; + M_FONTDATA->m_valid = false; } void wxFont::SetFamily(int family) { - Unshare(); + AllocExclusive(); M_FONTDATA->m_family = family; - M_FONTDATA->m_valid = FALSE; + M_FONTDATA->m_valid = false; } void wxFont::SetStyle(int style) { - Unshare(); + AllocExclusive(); M_FONTDATA->m_style = style; - M_FONTDATA->m_valid = FALSE; + M_FONTDATA->m_valid = false; } void wxFont::SetWeight(int weight) { - Unshare(); + AllocExclusive(); M_FONTDATA->m_weight = weight; - M_FONTDATA->m_valid = FALSE; + M_FONTDATA->m_valid = false; } void wxFont::SetFaceName(const wxString& faceName) { - Unshare(); + AllocExclusive(); M_FONTDATA->m_faceName = faceName; - M_FONTDATA->m_valid = FALSE; + M_FONTDATA->m_valid = false; } void wxFont::SetUnderlined(bool underlined) { - Unshare(); + AllocExclusive(); M_FONTDATA->m_underlined = underlined; } void wxFont::SetEncoding(wxFontEncoding encoding) { - Unshare(); + AllocExclusive(); M_FONTDATA->m_encoding = encoding; - M_FONTDATA->m_valid = FALSE; + M_FONTDATA->m_valid = false; }