]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/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 c2pstrcpy( (StringPtr
) wxBuffer
, m_faceName
) ;
109 strcpy( (char *) wxBuffer
, m_faceName
) ;
110 c2pstr( (char *) wxBuffer
) ;
112 ::GetFNum( (StringPtr
) wxBuffer
, &m_macFontNum
);
117 if (m_weight
== wxBOLD
)
118 m_macFontStyle
|= bold
;
119 if (m_style
== wxITALIC
|| m_style
== wxSLANT
)
120 m_macFontStyle
|= italic
;
122 m_macFontStyle
|= underline
;
123 m_macFontSize
= m_pointSize
;
125 //TODO:if we supply the style as an additional parameter we must make a testing
126 //sequence in order to degrade gracefully while trying to maintain most of the style
127 //information, meanwhile we just take the normal font and apply the features after
128 OSStatus status
= ::ATSUFONDtoFontID(m_macFontNum
, normal
/*qdStyle*/, (UInt32
*)&m_macATSUFontID
);
130 status = ATSUFindFontFromName ( (Ptr) m_faceName , strlen( m_faceName ) ,
131 kFontFullName, kFontMacintoshPlatform, kFontRomanScript , kFontNoLanguage , (UInt32*)&m_macATSUFontID ) ;
133 wxASSERT_MSG( status
== noErr
, "couldn't retrieve font identifier" ) ;
136 // ----------------------------------------------------------------------------
138 // ----------------------------------------------------------------------------
144 bool wxFont::Create(const wxNativeFontInfo
& info
)
146 return Create(info
.pointSize
, info
.family
, info
.style
, info
.weight
,
147 info
.underlined
, info
.faceName
, info
.encoding
);
150 wxFont::wxFont(const wxString
& fontdesc
)
152 wxNativeFontInfo info
;
153 if ( info
.FromString(fontdesc
) )
157 bool wxFont::Create(int pointSize
,
162 const wxString
& faceName
,
163 wxFontEncoding encoding
)
166 m_refData
= new wxFontRefData(pointSize
, family
, style
, weight
,
167 underlined
, faceName
, encoding
);
178 bool wxFont::RealizeResource()
180 M_FONTDATA
->MacFindFont() ;
184 void wxFont::SetEncoding(wxFontEncoding encoding
)
188 M_FONTDATA
->m_encoding
= encoding
;
193 void wxFont::Unshare()
195 // Don't change shared data
198 m_refData
= new wxFontRefData();
202 wxFontRefData
* ref
= new wxFontRefData(*(wxFontRefData
*)m_refData
);
208 void wxFont::SetPointSize(int pointSize
)
212 M_FONTDATA
->m_pointSize
= pointSize
;
217 void wxFont::SetFamily(int family
)
221 M_FONTDATA
->m_family
= family
;
226 void wxFont::SetStyle(int style
)
230 M_FONTDATA
->m_style
= style
;
235 void wxFont::SetWeight(int weight
)
239 M_FONTDATA
->m_weight
= weight
;
244 void wxFont::SetFaceName(const wxString
& faceName
)
248 M_FONTDATA
->m_faceName
= faceName
;
253 void wxFont::SetUnderlined(bool underlined
)
257 M_FONTDATA
->m_underlined
= underlined
;
262 void wxFont::SetNoAntiAliasing( bool no
)
266 M_FONTDATA
->SetNoAntiAliasing( no
);
271 // ----------------------------------------------------------------------------
273 // ----------------------------------------------------------------------------
275 int wxFont::GetPointSize() const
277 return M_FONTDATA
->m_pointSize
;
280 int wxFont::GetFamily() const
282 return M_FONTDATA
->m_family
;
285 int wxFont::GetStyle() const
287 return M_FONTDATA
->m_style
;
290 int wxFont::GetWeight() const
292 return M_FONTDATA
->m_weight
;
295 bool wxFont::GetUnderlined() const
297 return M_FONTDATA
->m_underlined
;
300 wxString
wxFont::GetFaceName() const
304 str
= M_FONTDATA
->m_faceName
;
308 wxFontEncoding
wxFont::GetEncoding() const
310 return M_FONTDATA
->m_encoding
;
313 bool wxFont::GetNoAntiAliasing()
315 return M_FONTDATA
->m_noAA
;