X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/68c957045a3919d9ac241a1e775c233bb6d1a793..f645356813e0479e74db69e15e915384922001ea:/src/dfb/font.cpp?ds=sidebyside diff --git a/src/dfb/font.cpp b/src/dfb/font.cpp index fe57bbb73a..cb36d55968 100644 --- a/src/dfb/font.cpp +++ b/src/dfb/font.cpp @@ -29,91 +29,16 @@ #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, @@ -121,9 +46,9 @@ bool wxFont::Create(const wxNativeFontInfo& info) } bool wxFont::Create(int pointSize, - int family, - int style, - int weight, + wxFontFamily family, + wxFontStyle style, + wxFontWeight weight, bool underlined, const wxString& face, wxFontEncoding encoding) @@ -133,12 +58,12 @@ bool wxFont::Create(int pointSize, 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); } @@ -148,53 +73,53 @@ wxObjectRefData *wxFont::CloneRefData(const wxObjectRefData *data) const // accessors // ---------------------------------------------------------------------------- -wxIDirectFBFontPtr wxFont::GetDirectFBFont() const +wxIDirectFBFontPtr wxFont::GetDirectFBFont(bool antialiased) const { wxCHECK_MSG( Ok(), 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") ); - return M_FONTDATA->m_info.pointSize; + return M_FONTDATA->GetPointSize(); } wxString wxFont::GetFaceName() const { wxCHECK_MSG( Ok(), 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( Ok(), 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( Ok(), 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") ); - return M_FONTDATA->m_info.underlined; + return M_FONTDATA->GetUnderlined(); } @@ -202,21 +127,21 @@ wxFontEncoding wxFont::GetEncoding() const { wxCHECK_MSG( Ok(), 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") ); - return true; // FIXME_DFB + return M_FONTDATA->IsFixedWidth(); } const wxNativeFontInfo *wxFont::GetNativeFontInfo() const { wxCHECK_MSG( Ok(), NULL, wxT("invalid font") ); - return &(M_FONTDATA->m_info); + return M_FONTDATA->GetNativeFontInfo(); } // ---------------------------------------------------------------------------- @@ -226,50 +151,43 @@ const wxNativeFontInfo *wxFont::GetNativeFontInfo() const 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); } +