X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7c78e7c70271608b076b1dbed201b1204e6898d4..2035e10e83324c6925d12725b842768f6e2b00a2:/src/qt/font.cpp?ds=inline diff --git a/src/qt/font.cpp b/src/qt/font.cpp index 87c13dac55..a47c8e43ec 100644 --- a/src/qt/font.cpp +++ b/src/qt/font.cpp @@ -1,10 +1,11 @@ ///////////////////////////////////////////////////////////////////////////// // Name: font.cpp -// Purpose: -// Author: Robert Roebling -// Created: 01/02/97 -// Id: -// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem +// Purpose: wxFont class +// Author: AUTHOR +// Modified by: +// Created: ??/??/98 +// RCS-ID: $Id$ +// Copyright: (c) AUTHOR // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -13,201 +14,226 @@ #endif #include "wx/font.h" -#include "wx/utils.h" -#include - -//----------------------------------------------------------------------------- -// local data -//----------------------------------------------------------------------------- - -static char *wx_font_family [] = { - "wxDEFAULT", "wxDECORATIVE", "wxMODERN", "wxROMAN", "wxSCRIPT", - "wxSWISS", "wxTELETYPE", -}; -static char *wx_font_style [] = { - "wxDEFAULT", "wxNORMAL", "wxSLANT", "wxITALIC", -}; -static char *wx_font_weight [] = { - "wxDEFAULT", "wxNORMAL", "wxBOLD", "wxLIGHT", -}; - -extern wxFontNameDirectory wxTheFontNameDirectory; - -//----------------------------------------------------------------------------- -// wxFont -//----------------------------------------------------------------------------- - -class wxFontRefData: public wxObjectRefData -{ - public: - - wxFontRefData(void); - ~wxFontRefData(void); - - wxList m_scaled_xfonts; - int m_pointSize; - int m_family, m_style, m_weight; - bool m_underlined; - int m_fontId; - char* m_faceName; - -}; - -wxFontRefData::wxFontRefData(void) : m_scaled_xfonts(wxKEY_INTEGER) -{ - m_pointSize = -1; - m_family = -1; - m_style = -1; - m_weight = -1; - m_underlined = FALSE; - m_fontId = 0; - m_faceName = NULL; -}; - -wxFontRefData::~wxFontRefData(void) -{ - wxNode *node = m_scaled_xfonts.First(); - while (node) - { - wxNode *next = node->Next(); - node = next; - }; - if (m_faceName) - { - delete m_faceName; - m_faceName = NULL; - }; -}; - -//----------------------------------------------------------------------------- - -#define M_FONTDATA ((wxFontRefData *)m_refData) IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) -wxFont::wxFont(void) +wxFontRefData::wxFontRefData() { - if (wxTheFontList) wxTheFontList->Append( this ); -}; + m_style = 0; + m_pointSize = 0; + m_family = 0; + m_style = 0; + m_weight = 0; + m_underlined = 0; + m_faceName = ""; +/* TODO + m_hFont = 0; +*/ +} -wxFont::wxFont( char *xFontName ) +wxFontRefData::wxFontRefData(const wxFontRefData& data) { - if (!xFontName) return; - - m_refData = new wxFontRefData(); - -}; + 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; +/* TODO + m_hFont = 0; +*/ +} -wxFont::wxFont(int PointSize, int FontIdOrFamily, int Style, int Weight, - bool Underlined, const char* Face) +wxFontRefData::~wxFontRefData() { - m_refData = new wxFontRefData(); - - - if (wxTheFontList) wxTheFontList->Append( this ); -}; + // TODO: delete font data +} -wxFont::wxFont(int PointSize, const char *Face, int Family, int Style, - int Weight, bool Underlined) +wxFont::wxFont() { - m_refData = new wxFontRefData(); - + if ( wxTheFontList ) + wxTheFontList->Append(this); +} - if (wxTheFontList) wxTheFontList->Append( this ); -}; - -wxFont::wxFont( const wxFont& font ) -{ - Ref( font ); -}; +wxFont::wxFont(int pointSize, int family, int style, int weight, bool underlined, const wxString& faceName) +{ + Create(pointSize, family, style, weight, underlined, faceName); -wxFont::wxFont( const wxFont* font ) -{ - UnRef(); - if (font) Ref( *font ); -}; + if ( wxTheFontList ) + wxTheFontList->Append(this); +} -wxFont::~wxFont(void) +bool wxFont::Create(int pointSize, int family, int style, int weight, bool underlined, const wxString& faceName) { - if (wxTheFontList) wxTheFontList->DeleteObject( this ); -}; + UnRef(); + m_refData = new wxFontRefData; -wxFont& wxFont::operator = ( const wxFont& font ) -{ - if (*this == font) return (*this); - Ref( font ); - return *this; -}; + 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; -bool wxFont::operator == ( const wxFont& font ) -{ - return m_refData == font.m_refData; -}; + RealizeResource(); -bool wxFont::operator != ( const wxFont& font ) -{ - return m_refData != font.m_refData; -}; + return TRUE; +} -bool wxFont::Ok() +wxFont::~wxFont() { - return (m_refData != NULL); -}; + if (wxTheFontList) + wxTheFontList->DeleteObject(this); +} -int wxFont::GetPointSize(void) const +bool wxFont::RealizeResource() { - return M_FONTDATA->m_pointSize; -}; + // TODO: create the font (if there is a native font object) + return FALSE; +} -wxString wxFont::GetFaceString(void) const +void wxFont::Unshare() { - return ""; -}; + // Don't change shared data + if (!m_refData) + { + m_refData = new wxFontRefData(); + } + else + { + wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData); + UnRef(); + m_refData = ref; + } +} -wxString wxFont::GetFaceName(void) const +void wxFont::SetPointSize(int pointSize) { - return ""; -}; + Unshare(); -int wxFont::GetFamily(void) const -{ - return M_FONTDATA->m_family; -}; + M_FONTDATA->m_pointSize = pointSize; -wxString wxFont::GetFamilyString(void) const -{ - wxString s = wx_font_family[M_FONTDATA->m_family]; - return s; -}; + RealizeResource(); +} -int wxFont::GetFontId(void) const +void wxFont::SetFamily(int family) { - return M_FONTDATA->m_fontId; // stub -}; + Unshare(); + + M_FONTDATA->m_family = family; -int wxFont::GetStyle(void) const + RealizeResource(); +} + +void wxFont::SetStyle(int style) { - return M_FONTDATA->m_style; -}; + Unshare(); + + M_FONTDATA->m_style = style; + + RealizeResource(); +} -wxString wxFont::GetStyleString(void) const +void wxFont::SetWeight(int weight) { - wxString s = wx_font_style[M_FONTDATA->m_style]; - return s; -}; + Unshare(); -int wxFont::GetWeight(void) const + M_FONTDATA->m_weight = weight; + + RealizeResource(); +} + +void wxFont::SetFaceName(const wxString& faceName) { - return M_FONTDATA->m_weight; -}; + Unshare(); + + M_FONTDATA->m_faceName = faceName; -wxString wxFont::GetWeightString(void) const + RealizeResource(); +} + +void wxFont::SetUnderlined(bool underlined) { - wxString s = wx_font_weight[M_FONTDATA->m_weight]; - return s; -}; + Unshare(); + + M_FONTDATA->m_underlined = underlined; + + RealizeResource(); +} -bool wxFont::GetUnderlined(void) const +wxString wxFont::GetFamilyString() const { - return M_FONTDATA->m_underlined; -}; + 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; +} + +/* New font system */ +wxString wxFont::GetFaceName() const +{ + wxString str(""); + if (M_FONTDATA) + str = M_FONTDATA->m_faceName ; + return str; +} + +wxString wxFont::GetStyleString() const +{ + wxString styl(""); + switch (GetStyle()) + { + case wxITALIC: + styl = "wxITALIC"; + break; + case wxSLANT: + styl = "wxSLANT"; + break; + default: + styl = "wxNORMAL"; + break; + } + return styl; +} + +wxString wxFont::GetWeightString() const +{ + wxString w(""); + switch (GetWeight()) + { + case wxBOLD: + w = "wxBOLD"; + break; + case wxLIGHT: + w = "wxLIGHT"; + break; + default: + w = "wxNORMAL"; + break; + } + return w; +} +