1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFont class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #include "wx/string.h"
15 #include "wx/fontutil.h"
16 #include "wx/gdicmn.h"
19 #include "wx/fontutil.h"
21 #include "wx/mac/private.h"
22 #include <ATSUnicode.h>
24 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
26 class WXDLLEXPORT wxFontRefData
: public wxGDIRefData
28 friend class WXDLLEXPORT wxFont
;
37 , m_faceName(wxT("Geneva"))
38 , m_encoding(wxFONTENCODING_DEFAULT
)
44 Init(10, wxDEFAULT
, wxNORMAL
, wxNORMAL
, FALSE
,
45 wxT("Geneva"), wxFONTENCODING_DEFAULT
);
48 wxFontRefData(const wxFontRefData
& data
)
50 , m_fontId(data
.m_fontId
)
51 , m_pointSize(data
.m_pointSize
)
52 , m_family(data
.m_family
)
53 , m_style(data
.m_style
)
54 , m_weight(data
.m_weight
)
55 , m_underlined(data
.m_underlined
)
56 , m_faceName(data
.m_faceName
)
57 , m_encoding(data
.m_encoding
)
58 , m_macFontNum(data
.m_macFontNum
)
59 , m_macFontSize(data
.m_macFontSize
)
60 , m_macFontStyle(data
.m_macFontStyle
)
61 , m_macATSUFontID(data
.m_macATSUFontID
)
63 Init(data
.m_pointSize
, data
.m_family
, data
.m_style
, data
.m_weight
,
64 data
.m_underlined
, data
.m_faceName
, data
.m_encoding
);
67 wxFontRefData(int size
,
72 const wxString
& faceName
,
73 wxFontEncoding encoding
)
79 , m_underlined(underlined
)
80 , m_faceName(faceName
)
81 , m_encoding(encoding
)
87 Init(size
, family
, style
, weight
, underlined
, faceName
, encoding
);
90 virtual ~wxFontRefData();
91 void SetNoAntiAliasing( bool no
= TRUE
) { m_noAA
= no
; }
92 bool GetNoAntiAliasing() const { return m_noAA
; }
95 // common part of all ctors
101 const wxString
& faceName
,
102 wxFontEncoding encoding
);
104 // font characterstics
112 wxFontEncoding m_encoding
;
113 bool m_noAA
; // No anti-aliasing
118 unsigned char m_macFontStyle
;
119 wxUint32 m_macATSUFontID
;
121 wxNativeFontInfo m_info
;
126 // ============================================================================
128 // ============================================================================
130 // ----------------------------------------------------------------------------
132 // ----------------------------------------------------------------------------
134 void wxFontRefData::Init(int pointSize
,
139 const wxString
& faceName
,
140 wxFontEncoding encoding
)
143 m_pointSize
= pointSize
;
147 m_underlined
= underlined
;
148 m_faceName
= faceName
;
149 m_encoding
= encoding
;
158 wxFontRefData::~wxFontRefData()
162 void wxFontRefData::MacFindFont()
164 if( m_faceName
.Length() == 0 )
169 m_macFontNum
= ::GetAppFont() ;
172 ::GetFNum( "\pTimes" , &m_macFontNum
) ;
175 ::GetFNum( "\pTimes" , &m_macFontNum
) ;
178 ::GetFNum( "\pTimes" , &m_macFontNum
) ;
181 ::GetFNum( "\pGeneva" , &m_macFontNum
) ;
184 ::GetFNum( "\pMonaco" , &m_macFontNum
) ;
188 GetFontName( m_macFontNum
, name
) ;
189 m_faceName
= wxMacMakeStringFromPascal( name
) ;
193 if ( m_faceName
== wxT("systemfont") )
194 m_macFontNum
= ::GetSysFont() ;
195 else if ( m_faceName
== wxT("applicationfont") )
196 m_macFontNum
= ::GetAppFont() ;
200 wxMacStringToPascal( m_faceName
, fontname
) ;
201 ::GetFNum( fontname
, &m_macFontNum
);
206 if (m_weight
== wxBOLD
)
207 m_macFontStyle
|= bold
;
208 if (m_style
== wxITALIC
|| m_style
== wxSLANT
)
209 m_macFontStyle
|= italic
;
211 m_macFontStyle
|= underline
;
212 m_macFontSize
= m_pointSize
;
214 //TODO:if we supply the style as an additional parameter we must make a testing
215 //sequence in order to degrade gracefully while trying to maintain most of the style
216 //information, meanwhile we just take the normal font and apply the features after
219 #endif // __WXDEBUG__
220 ::ATSUFONDtoFontID(m_macFontNum
, normal
/*qdStyle*/, (UInt32
*)&m_macATSUFontID
);
222 status = ATSUFindFontFromName ( (Ptr) m_faceName , strlen( m_faceName ) ,
223 kFontFullName, kFontMacintoshPlatform, kFontRomanScript , kFontNoLanguage , (UInt32*)&m_macATSUFontID ) ;
225 wxASSERT_MSG( status
== noErr
, wxT("couldn't retrieve font identifier") ) ;
228 // ----------------------------------------------------------------------------
230 // ----------------------------------------------------------------------------
233 bool wxFont::Create(const wxNativeFontInfo
& info
)
235 return Create(info
.pointSize
, info
.family
, info
.style
, info
.weight
,
236 info
.underlined
, info
.faceName
, info
.encoding
);
239 wxFont::wxFont(const wxString
& fontdesc
)
241 wxNativeFontInfo info
;
242 if ( info
.FromString(fontdesc
) )
246 bool wxFont::Create(int pointSize
,
251 const wxString
& faceName
,
252 wxFontEncoding encoding
)
255 m_refData
= new wxFontRefData(pointSize
, family
, style
, weight
,
256 underlined
, faceName
, encoding
);
267 bool wxFont::RealizeResource()
269 M_FONTDATA
->MacFindFont() ;
273 void wxFont::SetEncoding(wxFontEncoding encoding
)
277 M_FONTDATA
->m_encoding
= encoding
;
282 void wxFont::Unshare()
284 // Don't change shared data
287 m_refData
= new wxFontRefData();
291 wxFontRefData
* ref
= new wxFontRefData(*(wxFontRefData
*)m_refData
);
297 void wxFont::SetPointSize(int pointSize
)
301 M_FONTDATA
->m_pointSize
= pointSize
;
306 void wxFont::SetFamily(int family
)
310 M_FONTDATA
->m_family
= family
;
315 void wxFont::SetStyle(int style
)
319 M_FONTDATA
->m_style
= style
;
324 void wxFont::SetWeight(int weight
)
328 M_FONTDATA
->m_weight
= weight
;
333 void wxFont::SetFaceName(const wxString
& faceName
)
337 M_FONTDATA
->m_faceName
= faceName
;
342 void wxFont::SetUnderlined(bool underlined
)
346 M_FONTDATA
->m_underlined
= underlined
;
351 void wxFont::SetNoAntiAliasing( bool no
)
355 M_FONTDATA
->SetNoAntiAliasing( no
);
360 // ----------------------------------------------------------------------------
362 // ----------------------------------------------------------------------------
364 // TODO: insert checks everywhere for M_FONTDATA == NULL!
366 int wxFont::GetPointSize() const
368 return M_FONTDATA
->m_pointSize
;
371 int wxFont::GetFamily() const
373 return M_FONTDATA
->m_family
;
376 int wxFont::GetStyle() const
378 return M_FONTDATA
->m_style
;
381 int wxFont::GetWeight() const
383 return M_FONTDATA
->m_weight
;
386 bool wxFont::GetUnderlined() const
388 return M_FONTDATA
->m_underlined
;
391 wxString
wxFont::GetFaceName() const
395 str
= M_FONTDATA
->m_faceName
;
399 wxFontEncoding
wxFont::GetEncoding() const
401 return M_FONTDATA
->m_encoding
;
404 bool wxFont::GetNoAntiAliasing() const
406 return M_FONTDATA
->m_noAA
;
409 short wxFont::GetMacFontNum() const
411 return M_FONTDATA
->m_macFontNum
;
414 short wxFont::GetMacFontSize() const
416 return M_FONTDATA
->m_macFontSize
;
419 wxByte
wxFont::GetMacFontStyle() const
421 return M_FONTDATA
->m_macFontStyle
;
424 wxUint32
wxFont::GetMacATSUFontID() const
426 return M_FONTDATA
->m_macATSUFontID
;
429 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
431 wxCHECK_MSG( Ok(), NULL
, wxT("invalid font") );
433 M_FONTDATA
->m_info
.InitFromFont(*this);
435 return &(M_FONTDATA
->m_info
);