]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/font.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFont class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
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
;
64 wxFontRefData::~wxFontRefData()
68 void wxFontRefData::MacFindFont()
70 if( m_faceName
.Length() == 0 )
75 m_macFontNum
= ::GetAppFont() ;
78 ::GetFNum( "\pTimes" , &m_macFontNum
) ;
81 ::GetFNum( "\pTimes" , &m_macFontNum
) ;
84 ::GetFNum( "\pTimes" , &m_macFontNum
) ;
87 ::GetFNum( "\pGeneva" , &m_macFontNum
) ;
90 ::GetFNum( "\pMonaco" , &m_macFontNum
) ;
94 GetFontName( m_macFontNum
, name
) ;
95 m_faceName
= wxMacMakeStringFromPascal( name
) ;
99 if ( m_faceName
== wxT("systemfont") )
100 m_macFontNum
= ::GetSysFont() ;
101 else if ( m_faceName
== wxT("applicationfont") )
102 m_macFontNum
= ::GetAppFont() ;
106 wxMacStringToPascal( m_faceName
, fontname
) ;
107 ::GetFNum( fontname
, &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
125 #endif // __WXDEBUG__
126 ::ATSUFONDtoFontID(m_macFontNum
, normal
/*qdStyle*/, (UInt32
*)&m_macATSUFontID
);
128 status = ATSUFindFontFromName ( (Ptr) m_faceName , strlen( m_faceName ) ,
129 kFontFullName, kFontMacintoshPlatform, kFontRomanScript , kFontNoLanguage , (UInt32*)&m_macATSUFontID ) ;
131 wxASSERT_MSG( status
== noErr
, wxT("couldn't retrieve font identifier") ) ;
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
142 bool wxFont::Create(const wxNativeFontInfo
& info
)
144 return Create(info
.pointSize
, info
.family
, info
.style
, info
.weight
,
145 info
.underlined
, info
.faceName
, info
.encoding
);
148 wxFont::wxFont(const wxString
& fontdesc
)
150 wxNativeFontInfo info
;
151 if ( info
.FromString(fontdesc
) )
155 bool wxFont::Create(int pointSize
,
160 const wxString
& faceName
,
161 wxFontEncoding encoding
)
164 m_refData
= new wxFontRefData(pointSize
, family
, style
, weight
,
165 underlined
, faceName
, encoding
);
176 bool wxFont::RealizeResource()
178 M_FONTDATA
->MacFindFont() ;
182 void wxFont::SetEncoding(wxFontEncoding encoding
)
186 M_FONTDATA
->m_encoding
= encoding
;
191 void wxFont::Unshare()
193 // Don't change shared data
196 m_refData
= new wxFontRefData();
200 wxFontRefData
* ref
= new wxFontRefData(*(wxFontRefData
*)m_refData
);
206 void wxFont::SetPointSize(int pointSize
)
210 M_FONTDATA
->m_pointSize
= pointSize
;
215 void wxFont::SetFamily(int family
)
219 M_FONTDATA
->m_family
= family
;
224 void wxFont::SetStyle(int style
)
228 M_FONTDATA
->m_style
= style
;
233 void wxFont::SetWeight(int weight
)
237 M_FONTDATA
->m_weight
= weight
;
242 void wxFont::SetFaceName(const wxString
& faceName
)
246 M_FONTDATA
->m_faceName
= faceName
;
251 void wxFont::SetUnderlined(bool underlined
)
255 M_FONTDATA
->m_underlined
= underlined
;
260 void wxFont::SetNoAntiAliasing( bool no
)
264 M_FONTDATA
->SetNoAntiAliasing( no
);
269 // ----------------------------------------------------------------------------
271 // ----------------------------------------------------------------------------
273 int wxFont::GetPointSize() const
275 return M_FONTDATA
->m_pointSize
;
278 int wxFont::GetFamily() const
280 return M_FONTDATA
->m_family
;
283 int wxFont::GetStyle() const
285 return M_FONTDATA
->m_style
;
288 int wxFont::GetWeight() const
290 return M_FONTDATA
->m_weight
;
293 bool wxFont::GetUnderlined() const
295 return M_FONTDATA
->m_underlined
;
298 wxString
wxFont::GetFaceName() const
302 str
= M_FONTDATA
->m_faceName
;
306 wxFontEncoding
wxFont::GetEncoding() const
308 return M_FONTDATA
->m_encoding
;
311 bool wxFont::GetNoAntiAliasing()
313 return M_FONTDATA
->m_noAA
;