// Purpose: wxFont implementation
// Author: Vaclav Slavik
// Created: 2006-08-08
-// RCS-ID: $Id$
// Copyright: (c) 2006 REA Elektronik GmbH
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/app.h"
#endif
-#include "wx/fontutil.h"
#include "wx/dfb/private.h"
+#include "wx/private/fontmgr.h"
-// ----------------------------------------------------------------------------
-// wxFontRefData
-// ----------------------------------------------------------------------------
-
-// FIXME: for now, always use single font
-static wxIDirectFBFontPtr gs_font = NULL;
-static unsigned gs_fontRefCnt = 0;
-
-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)
- {
- if ( family == wxDEFAULT )
- family = wxSWISS;
- if ( style == wxDEFAULT )
- style = wxNORMAL;
- if ( weight == wxDEFAULT )
- weight = wxNORMAL;
- if ( size == wxDEFAULT )
- size = 12;
-
- m_info.family = (wxFontFamily)family;
- m_info.faceName = faceName;
- m_info.style = (wxFontStyle)style;
- m_info.weight = (wxFontWeight)weight;
- m_info.pointSize = size;
- m_info.underlined = underlined;
- m_info.encoding = encoding;
-
- // FIXME: always use default font for now
- if ( !gs_font )
- {
- DFBFontDescription desc;
- desc.flags = (DFBFontDescriptionFlags)0;
- wxIDirectFBFontPtr f(wxIDirectFB::Get()->CreateFont(NULL, &desc));
- if ( f )
- gs_font = f;
- }
- if ( gs_font ) // the above may fail
- {
- gs_fontRefCnt++;
- m_font = gs_font;
- }
- }
-
- wxFontRefData(const wxFontRefData& data)
- {
- m_info = data.m_info;
- m_font = data.m_font;
- }
-
- ~wxFontRefData()
- {
- if ( m_font )
- {
- m_font.Reset();
- // FIXME
- if ( --gs_fontRefCnt == 0 )
- gs_font = NULL;
- }
- }
-
- wxNativeFontInfo m_info;
- wxIDirectFBFontPtr m_font;
-};
-
+typedef wxFontMgrFontRefData wxFontRefData;
#define M_FONTDATA ((wxFontRefData*)m_refData)
-
// ----------------------------------------------------------------------------
// wxFont
// ----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
-
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)
return true;
}
-wxObjectRefData *wxFont::CreateRefData() const
+wxGDIRefData *wxFont::CreateGDIRefData() const
{
return new wxFontRefData;
}
-wxObjectRefData *wxFont::CloneRefData(const wxObjectRefData *data) const
+wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const
{
return new wxFontRefData(*(wxFontRefData *)data);
}
// accessors
// ----------------------------------------------------------------------------
-wxIDirectFBFontPtr wxFont::GetDirectFBFont() const
+wxIDirectFBFontPtr wxFont::GetDirectFBFont(bool antialiased) const
{
- wxCHECK_MSG( Ok(), NULL, wxT("invalid font") );
+ wxCHECK_MSG( IsOk(), NULL, wxT("invalid font") );
- return M_FONTDATA->m_font;
+ // we don't support DC scaling yet, so use scale=1
+ wxFontInstance *i = M_FONTDATA->GetFontInstance(1.0, antialiased);
+ return i ? i->GetDirectFBFont() : wxIDirectFBFontPtr();
}
int wxFont::GetPointSize() const
{
- wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
+ wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
- return M_FONTDATA->m_info.pointSize;
+ return M_FONTDATA->GetPointSize();
}
wxString wxFont::GetFaceName() const
{
- wxCHECK_MSG( Ok(), wxEmptyString, wxT("invalid font") );
+ wxCHECK_MSG( IsOk(), wxEmptyString, wxT("invalid font") );
- return M_FONTDATA->m_info.faceName;
+ return M_FONTDATA->GetFaceName();
}
-int wxFont::GetFamily() const
+wxFontFamily wxFont::DoGetFamily() const
{
- wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
-
- return M_FONTDATA->m_info.family;
+ return M_FONTDATA->GetFamily();
}
-int wxFont::GetStyle() const
+wxFontStyle wxFont::GetStyle() const
{
- wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
+ wxCHECK_MSG( IsOk(), wxFONTSTYLE_MAX, wxT("invalid font") );
- return M_FONTDATA->m_info.style;
+ return M_FONTDATA->GetStyle();
}
-int wxFont::GetWeight() const
+wxFontWeight wxFont::GetWeight() const
{
- wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
+ wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font") );
- return M_FONTDATA->m_info.weight;
+ return M_FONTDATA->GetWeight();
}
bool wxFont::GetUnderlined() const
{
- wxCHECK_MSG( Ok(), false, wxT("invalid font") );
+ wxCHECK_MSG( IsOk(), false, wxT("invalid font") );
- return M_FONTDATA->m_info.underlined;
+ return M_FONTDATA->GetUnderlined();
}
wxFontEncoding wxFont::GetEncoding() const
{
- wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") );
+ wxCHECK_MSG( IsOk(), wxFONTENCODING_DEFAULT, wxT("invalid font") );
- return M_FONTDATA->m_info.encoding;
+ return M_FONTDATA->GetEncoding();
}
bool wxFont::IsFixedWidth() const
{
- wxCHECK_MSG( Ok(), false, wxT("invalid font") );
+ wxCHECK_MSG( IsOk(), false, wxT("invalid font") );
- return true; // FIXME_DFB
+ return M_FONTDATA->IsFixedWidth();
}
const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
{
- wxCHECK_MSG( Ok(), NULL, wxT("invalid font") );
+ wxCHECK_MSG( IsOk(), NULL, wxT("invalid font") );
- return &(M_FONTDATA->m_info);
+ return M_FONTDATA->GetNativeFontInfo();
}
// ----------------------------------------------------------------------------
void wxFont::SetPointSize(int pointSize)
{
AllocExclusive();
-
- M_FONTDATA->m_info.pointSize = pointSize;
+ M_FONTDATA->SetPointSize(pointSize);
}
-void wxFont::SetFamily(int family)
+void wxFont::SetFamily(wxFontFamily family)
{
AllocExclusive();
-
- M_FONTDATA->m_info.family = (wxFontFamily)family;
+ M_FONTDATA->SetFamily(family);
}
-void wxFont::SetStyle(int style)
+void wxFont::SetStyle(wxFontStyle style)
{
AllocExclusive();
-
- M_FONTDATA->m_info.style = (wxFontStyle)style;
+ M_FONTDATA->SetStyle(style);
}
-void wxFont::SetWeight(int weight)
+void wxFont::SetWeight(wxFontWeight weight)
{
AllocExclusive();
-
- M_FONTDATA->m_info.weight = (wxFontWeight)weight;
+ M_FONTDATA->SetWeight(weight);
}
bool wxFont::SetFaceName(const wxString& faceName)
{
AllocExclusive();
-
- M_FONTDATA->m_info.faceName = faceName;
-
+ M_FONTDATA->SetFaceName(faceName);
return wxFontBase::SetFaceName(faceName);
}
void wxFont::SetUnderlined(bool underlined)
{
AllocExclusive();
-
- M_FONTDATA->m_info.underlined = underlined;
+ M_FONTDATA->SetUnderlined(underlined);
}
void wxFont::SetEncoding(wxFontEncoding encoding)
{
AllocExclusive();
-
- M_FONTDATA->m_info.encoding = encoding;
+ M_FONTDATA->SetEncoding(encoding);
}
+