]>
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
;
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
) ;
93 GetFontName( m_macFontNum
, name
) ;
94 CopyPascalStringToC( name
, (char*) name
) ;
95 m_faceName
= (char*) name
;
99 if ( m_faceName
== "systemfont" )
100 m_macFontNum
= ::GetSysFont() ;
101 else if ( m_faceName
== "applicationfont" )
102 m_macFontNum
= ::GetAppFont() ;
106 c2pstrcpy( (StringPtr
) wxBuffer
, m_faceName
) ;
108 strcpy( (char *) wxBuffer
, m_faceName
) ;
109 c2pstr( (char *) wxBuffer
) ;
111 ::GetFNum( (StringPtr
) wxBuffer
, &m_macFontNum
);
116 if (m_weight
== wxBOLD
)
117 m_macFontStyle
|= bold
;
118 if (m_style
== wxITALIC
|| m_style
== wxSLANT
)
119 m_macFontStyle
|= italic
;
121 m_macFontStyle
|= underline
;
122 m_macFontSize
= m_pointSize
;
124 //TODO:if we supply the style as an additional parameter we must make a testing
125 //sequence in order to degrade gracefully while trying to maintain most of the style
126 //information, meanwhile we just take the normal font and apply the features after
127 OSStatus status
= ::ATSUFONDtoFontID(m_macFontNum
, normal
/*qdStyle*/, (UInt32
*)&m_macATSUFontID
);
129 status = ATSUFindFontFromName ( (Ptr) m_faceName , strlen( m_faceName ) ,
130 kFontFullName, kFontMacintoshPlatform, kFontRomanScript , kFontNoLanguage , (UInt32*)&m_macATSUFontID ) ;
132 wxASSERT_MSG( status
== noErr
, "couldn't retrieve font identifier" ) ;
135 // ----------------------------------------------------------------------------
137 // ----------------------------------------------------------------------------
143 bool wxFont::Create(const wxNativeFontInfo
& info
)
145 return Create(info
.pointSize
, info
.family
, info
.style
, info
.weight
,
146 info
.underlined
, info
.faceName
, info
.encoding
);
149 wxFont::wxFont(const wxString
& fontdesc
)
151 wxNativeFontInfo info
;
152 if ( info
.FromString(fontdesc
) )
156 bool wxFont::Create(int pointSize
,
161 const wxString
& faceName
,
162 wxFontEncoding encoding
)
165 m_refData
= new wxFontRefData(pointSize
, family
, style
, weight
,
166 underlined
, faceName
, encoding
);
177 bool wxFont::RealizeResource()
179 M_FONTDATA
->MacFindFont() ;
183 void wxFont::SetEncoding(wxFontEncoding encoding
)
187 M_FONTDATA
->m_encoding
= encoding
;
192 void wxFont::Unshare()
194 // Don't change shared data
197 m_refData
= new wxFontRefData();
201 wxFontRefData
* ref
= new wxFontRefData(*(wxFontRefData
*)m_refData
);
207 void wxFont::SetPointSize(int pointSize
)
211 M_FONTDATA
->m_pointSize
= pointSize
;
216 void wxFont::SetFamily(int family
)
220 M_FONTDATA
->m_family
= family
;
225 void wxFont::SetStyle(int style
)
229 M_FONTDATA
->m_style
= style
;
234 void wxFont::SetWeight(int weight
)
238 M_FONTDATA
->m_weight
= weight
;
243 void wxFont::SetFaceName(const wxString
& faceName
)
247 M_FONTDATA
->m_faceName
= faceName
;
252 void wxFont::SetUnderlined(bool underlined
)
256 M_FONTDATA
->m_underlined
= underlined
;
261 // ----------------------------------------------------------------------------
263 // ----------------------------------------------------------------------------
265 int wxFont::GetPointSize() const
267 return M_FONTDATA
->m_pointSize
;
270 int wxFont::GetFamily() const
272 return M_FONTDATA
->m_family
;
275 int wxFont::GetStyle() const
277 return M_FONTDATA
->m_style
;
280 int wxFont::GetWeight() const
282 return M_FONTDATA
->m_weight
;
285 bool wxFont::GetUnderlined() const
287 return M_FONTDATA
->m_underlined
;
290 wxString
wxFont::GetFaceName() const
294 str
= M_FONTDATA
->m_faceName
;
298 wxFontEncoding
wxFont::GetEncoding() const
300 return M_FONTDATA
->m_encoding
;