]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/font.cpp
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
;
64 wxFontRefData::~wxFontRefData()
68 void wxFontRefData::MacFindFont()
70 if( m_faceName
== "" )
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 CopyPascalStringToC( name
, (char*) name
) ;
96 m_faceName
= (char*) name
;
100 if ( m_faceName
== "systemfont" )
101 m_macFontNum
= ::GetSysFont() ;
102 else if ( m_faceName
== "applicationfont" )
103 m_macFontNum
= ::GetAppFont() ;
107 wxMacStringToPascal( m_faceName
, fontname
) ;
108 ::GetFNum( fontname
, &m_macFontNum
);
113 if (m_weight
== wxBOLD
)
114 m_macFontStyle
|= bold
;
115 if (m_style
== wxITALIC
|| m_style
== wxSLANT
)
116 m_macFontStyle
|= italic
;
118 m_macFontStyle
|= underline
;
119 m_macFontSize
= m_pointSize
;
121 //TODO:if we supply the style as an additional parameter we must make a testing
122 //sequence in order to degrade gracefully while trying to maintain most of the style
123 //information, meanwhile we just take the normal font and apply the features after
124 OSStatus status
= ::ATSUFONDtoFontID(m_macFontNum
, normal
/*qdStyle*/, (UInt32
*)&m_macATSUFontID
);
126 status = ATSUFindFontFromName ( (Ptr) m_faceName , strlen( m_faceName ) ,
127 kFontFullName, kFontMacintoshPlatform, kFontRomanScript , kFontNoLanguage , (UInt32*)&m_macATSUFontID ) ;
129 wxASSERT_MSG( status
== noErr
, "couldn't retrieve font identifier" ) ;
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
140 bool wxFont::Create(const wxNativeFontInfo
& info
)
142 return Create(info
.pointSize
, info
.family
, info
.style
, info
.weight
,
143 info
.underlined
, info
.faceName
, info
.encoding
);
146 wxFont::wxFont(const wxString
& fontdesc
)
148 wxNativeFontInfo info
;
149 if ( info
.FromString(fontdesc
) )
153 bool wxFont::Create(int pointSize
,
158 const wxString
& faceName
,
159 wxFontEncoding encoding
)
162 m_refData
= new wxFontRefData(pointSize
, family
, style
, weight
,
163 underlined
, faceName
, encoding
);
174 bool wxFont::RealizeResource()
176 M_FONTDATA
->MacFindFont() ;
180 void wxFont::SetEncoding(wxFontEncoding encoding
)
184 M_FONTDATA
->m_encoding
= encoding
;
189 void wxFont::Unshare()
191 // Don't change shared data
194 m_refData
= new wxFontRefData();
198 wxFontRefData
* ref
= new wxFontRefData(*(wxFontRefData
*)m_refData
);
204 void wxFont::SetPointSize(int pointSize
)
208 M_FONTDATA
->m_pointSize
= pointSize
;
213 void wxFont::SetFamily(int family
)
217 M_FONTDATA
->m_family
= family
;
222 void wxFont::SetStyle(int style
)
226 M_FONTDATA
->m_style
= style
;
231 void wxFont::SetWeight(int weight
)
235 M_FONTDATA
->m_weight
= weight
;
240 void wxFont::SetFaceName(const wxString
& faceName
)
244 M_FONTDATA
->m_faceName
= faceName
;
249 void wxFont::SetUnderlined(bool underlined
)
253 M_FONTDATA
->m_underlined
= underlined
;
258 void wxFont::SetNoAntiAliasing( bool no
)
262 M_FONTDATA
->SetNoAntiAliasing( no
);
267 // ----------------------------------------------------------------------------
269 // ----------------------------------------------------------------------------
271 int wxFont::GetPointSize() const
273 return M_FONTDATA
->m_pointSize
;
276 int wxFont::GetFamily() const
278 return M_FONTDATA
->m_family
;
281 int wxFont::GetStyle() const
283 return M_FONTDATA
->m_style
;
286 int wxFont::GetWeight() const
288 return M_FONTDATA
->m_weight
;
291 bool wxFont::GetUnderlined() const
293 return M_FONTDATA
->m_underlined
;
296 wxString
wxFont::GetFaceName() const
300 str
= M_FONTDATA
->m_faceName
;
304 wxFontEncoding
wxFont::GetEncoding() const
306 return M_FONTDATA
->m_encoding
;
309 bool wxFont::GetNoAntiAliasing()
311 return M_FONTDATA
->m_noAA
;