]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/font.cpp
d30015eaf9e533df8061bf055a112e549ad5d9b6
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFont class
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "font.h"
17 #include "wx/string.h"
19 #include "wx/fontutil.h"
20 #include "wx/gdicmn.h"
23 #include "wx/fontutil.h"
25 #include "wx/mac/private.h"
26 #include "ATSUnicode.h"
28 #if !USE_SHARED_LIBRARIES
29 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
32 // ============================================================================
34 // ============================================================================
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
40 void wxFontRefData::Init(int pointSize
,
45 const wxString
& faceName
,
46 wxFontEncoding encoding
)
49 m_pointSize
= pointSize
;
53 m_underlined
= underlined
;
54 m_faceName
= faceName
;
55 m_encoding
= encoding
;
63 wxFontRefData::~wxFontRefData()
67 void wxFontRefData::MacFindFont()
69 if( m_faceName
== "" )
74 m_macFontNum
= ::GetAppFont() ;
77 ::GetFNum( "\pTimes" , &m_macFontNum
) ;
80 ::GetFNum( "\pTimes" , &m_macFontNum
) ;
83 ::GetFNum( "\pTimes" , &m_macFontNum
) ;
86 ::GetFNum( "\pGeneva" , &m_macFontNum
) ;
89 ::GetFNum( "\pMonaco" , &m_macFontNum
) ;
95 if ( m_faceName
== "systemfont" )
96 m_macFontNum
= ::GetSysFont() ;
97 else if ( m_faceName
== "applicationfont" )
98 m_macFontNum
= ::GetAppFont() ;
102 c2pstrcpy( (StringPtr
) wxBuffer
, m_faceName
) ;
104 strcpy( (char *) wxBuffer
, m_faceName
) ;
105 c2pstr( (char *) wxBuffer
) ;
107 ::GetFNum( (StringPtr
) wxBuffer
, &m_macFontNum
);
112 if (m_weight
== wxBOLD
)
113 m_macFontStyle
|= bold
;
114 if (m_style
== wxITALIC
|| m_style
== wxSLANT
)
115 m_macFontStyle
|= italic
;
117 m_macFontStyle
|= underline
;
118 m_macFontSize
= m_pointSize
;
120 //TODO:if we supply the style as an additional parameter we must make a testing
121 //sequence in order to degrade gracefully while trying to maintain most of the style
122 //information, meanwhile we just take the normal font and apply the features after
123 OSStatus status
= ::ATSUFONDtoFontID(m_macFontNum
, normal
/*qdStyle*/, (UInt32
*)&m_macATSUFontID
);
124 wxASSERT_MSG( status
== noErr
, "couldn't retrieve font identifier" ) ;
127 // ----------------------------------------------------------------------------
129 // ----------------------------------------------------------------------------
135 bool wxFont::Create(const wxNativeFontInfo
& info
)
137 return Create(info
.pointSize
, info
.family
, info
.style
, info
.weight
,
138 info
.underlined
, info
.faceName
, info
.encoding
);
141 wxFont::wxFont(const wxString
& fontdesc
)
143 wxNativeFontInfo info
;
144 if ( info
.FromString(fontdesc
) )
148 bool wxFont::Create(int pointSize
,
153 const wxString
& faceName
,
154 wxFontEncoding encoding
)
157 m_refData
= new wxFontRefData(pointSize
, family
, style
, weight
,
158 underlined
, faceName
, encoding
);
169 bool wxFont::RealizeResource()
171 M_FONTDATA
->MacFindFont() ;
175 void wxFont::SetEncoding(wxFontEncoding encoding
)
179 M_FONTDATA
->m_encoding
= encoding
;
184 void wxFont::Unshare()
186 // Don't change shared data
189 m_refData
= new wxFontRefData();
193 wxFontRefData
* ref
= new wxFontRefData(*(wxFontRefData
*)m_refData
);
199 void wxFont::SetPointSize(int pointSize
)
203 M_FONTDATA
->m_pointSize
= pointSize
;
208 void wxFont::SetFamily(int family
)
212 M_FONTDATA
->m_family
= family
;
217 void wxFont::SetStyle(int style
)
221 M_FONTDATA
->m_style
= style
;
226 void wxFont::SetWeight(int weight
)
230 M_FONTDATA
->m_weight
= weight
;
235 void wxFont::SetFaceName(const wxString
& faceName
)
239 M_FONTDATA
->m_faceName
= faceName
;
244 void wxFont::SetUnderlined(bool underlined
)
248 M_FONTDATA
->m_underlined
= underlined
;
253 // ----------------------------------------------------------------------------
255 // ----------------------------------------------------------------------------
257 int wxFont::GetPointSize() const
259 return M_FONTDATA
->m_pointSize
;
262 int wxFont::GetFamily() const
264 return M_FONTDATA
->m_family
;
267 int wxFont::GetStyle() const
269 return M_FONTDATA
->m_style
;
272 int wxFont::GetWeight() const
274 return M_FONTDATA
->m_weight
;
277 bool wxFont::GetUnderlined() const
279 return M_FONTDATA
->m_underlined
;
282 wxString
wxFont::GetFaceName() const
286 str
= M_FONTDATA
->m_faceName
;
290 wxFontEncoding
wxFont::GetEncoding() const
292 return M_FONTDATA
->m_encoding
;