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 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
30 class WXDLLEXPORT wxFontRefData
: public wxGDIRefData
32 friend class WXDLLEXPORT wxFont
;
41 , m_faceName(wxT("Geneva"))
42 , m_encoding(wxFONTENCODING_DEFAULT
)
48 Init(10, wxDEFAULT
, wxNORMAL
, wxNORMAL
, FALSE
,
49 wxT("Geneva"), wxFONTENCODING_DEFAULT
);
52 wxFontRefData(const wxFontRefData
& data
)
54 , m_fontId(data
.m_fontId
)
55 , m_pointSize(data
.m_pointSize
)
56 , m_family(data
.m_family
)
57 , m_style(data
.m_style
)
58 , m_weight(data
.m_weight
)
59 , m_underlined(data
.m_underlined
)
60 , m_faceName(data
.m_faceName
)
61 , m_encoding(data
.m_encoding
)
62 , m_macFontNum(data
.m_macFontNum
)
63 , m_macFontSize(data
.m_macFontSize
)
64 , m_macFontStyle(data
.m_macFontStyle
)
65 , m_macATSUFontID(data
.m_macATSUFontID
)
67 Init(data
.m_pointSize
, data
.m_family
, data
.m_style
, data
.m_weight
,
68 data
.m_underlined
, data
.m_faceName
, data
.m_encoding
);
71 wxFontRefData(int size
,
76 const wxString
& faceName
,
77 wxFontEncoding encoding
)
83 , m_underlined(underlined
)
84 , m_faceName(faceName
)
85 , m_encoding(encoding
)
91 Init(size
, family
, style
, weight
, underlined
, faceName
, encoding
);
94 virtual ~wxFontRefData();
95 void SetNoAntiAliasing( bool no
= TRUE
) { m_noAA
= no
; }
96 bool GetNoAntiAliasing() const { return m_noAA
; }
99 // common part of all ctors
105 const wxString
& faceName
,
106 wxFontEncoding encoding
);
108 // font characterstics
116 wxFontEncoding m_encoding
;
117 bool m_noAA
; // No anti-aliasing
122 unsigned char m_macFontStyle
;
123 wxUint32 m_macATSUFontID
;
125 wxNativeFontInfo m_info
;
130 // ============================================================================
132 // ============================================================================
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
138 void wxFontRefData::Init(int pointSize
,
143 const wxString
& faceName
,
144 wxFontEncoding encoding
)
147 m_pointSize
= pointSize
;
151 m_underlined
= underlined
;
152 m_faceName
= faceName
;
153 m_encoding
= encoding
;
162 wxFontRefData::~wxFontRefData()
166 void wxFontRefData::MacFindFont()
168 if( m_faceName
.Length() == 0 )
173 m_macFontNum
= ::GetAppFont() ;
176 ::GetFNum( "\pTimes" , &m_macFontNum
) ;
179 ::GetFNum( "\pTimes" , &m_macFontNum
) ;
182 ::GetFNum( "\pTimes" , &m_macFontNum
) ;
185 ::GetFNum( "\pGeneva" , &m_macFontNum
) ;
188 ::GetFNum( "\pMonaco" , &m_macFontNum
) ;
192 GetFontName( m_macFontNum
, name
) ;
193 m_faceName
= wxMacMakeStringFromPascal( name
) ;
197 if ( m_faceName
== wxT("systemfont") )
198 m_macFontNum
= ::GetSysFont() ;
199 else if ( m_faceName
== wxT("applicationfont") )
200 m_macFontNum
= ::GetAppFont() ;
204 wxMacStringToPascal( m_faceName
, fontname
) ;
205 ::GetFNum( fontname
, &m_macFontNum
);
210 if (m_weight
== wxBOLD
)
211 m_macFontStyle
|= bold
;
212 if (m_style
== wxITALIC
|| m_style
== wxSLANT
)
213 m_macFontStyle
|= italic
;
215 m_macFontStyle
|= underline
;
216 m_macFontSize
= m_pointSize
;
218 //TODO:if we supply the style as an additional parameter we must make a testing
219 //sequence in order to degrade gracefully while trying to maintain most of the style
220 //information, meanwhile we just take the normal font and apply the features after
223 #endif // __WXDEBUG__
224 ::ATSUFONDtoFontID(m_macFontNum
, normal
/*qdStyle*/, (UInt32
*)&m_macATSUFontID
);
226 status = ATSUFindFontFromName ( (Ptr) m_faceName , strlen( m_faceName ) ,
227 kFontFullName, kFontMacintoshPlatform, kFontRomanScript , kFontNoLanguage , (UInt32*)&m_macATSUFontID ) ;
229 wxASSERT_MSG( status
== noErr
, wxT("couldn't retrieve font identifier") ) ;
232 // ----------------------------------------------------------------------------
234 // ----------------------------------------------------------------------------
240 bool wxFont::Create(const wxNativeFontInfo
& info
)
242 return Create(info
.pointSize
, info
.family
, info
.style
, info
.weight
,
243 info
.underlined
, info
.faceName
, info
.encoding
);
246 wxFont::wxFont(const wxString
& fontdesc
)
248 wxNativeFontInfo info
;
249 if ( info
.FromString(fontdesc
) )
253 bool wxFont::Create(int pointSize
,
258 const wxString
& faceName
,
259 wxFontEncoding encoding
)
262 m_refData
= new wxFontRefData(pointSize
, family
, style
, weight
,
263 underlined
, faceName
, encoding
);
274 bool wxFont::RealizeResource()
276 M_FONTDATA
->MacFindFont() ;
280 void wxFont::SetEncoding(wxFontEncoding encoding
)
284 M_FONTDATA
->m_encoding
= encoding
;
289 void wxFont::Unshare()
291 // Don't change shared data
294 m_refData
= new wxFontRefData();
298 wxFontRefData
* ref
= new wxFontRefData(*(wxFontRefData
*)m_refData
);
304 void wxFont::SetPointSize(int pointSize
)
308 M_FONTDATA
->m_pointSize
= pointSize
;
313 void wxFont::SetFamily(int family
)
317 M_FONTDATA
->m_family
= family
;
322 void wxFont::SetStyle(int style
)
326 M_FONTDATA
->m_style
= style
;
331 void wxFont::SetWeight(int weight
)
335 M_FONTDATA
->m_weight
= weight
;
340 void wxFont::SetFaceName(const wxString
& faceName
)
344 M_FONTDATA
->m_faceName
= faceName
;
349 void wxFont::SetUnderlined(bool underlined
)
353 M_FONTDATA
->m_underlined
= underlined
;
358 void wxFont::SetNoAntiAliasing( bool no
)
362 M_FONTDATA
->SetNoAntiAliasing( no
);
367 // ----------------------------------------------------------------------------
369 // ----------------------------------------------------------------------------
371 // TODO: insert checks everywhere for M_FONTDATA == NULL!
373 int wxFont::GetPointSize() const
375 return M_FONTDATA
->m_pointSize
;
378 int wxFont::GetFamily() const
380 return M_FONTDATA
->m_family
;
383 int wxFont::GetStyle() const
385 return M_FONTDATA
->m_style
;
388 int wxFont::GetWeight() const
390 return M_FONTDATA
->m_weight
;
393 bool wxFont::GetUnderlined() const
395 return M_FONTDATA
->m_underlined
;
398 wxString
wxFont::GetFaceName() const
402 str
= M_FONTDATA
->m_faceName
;
406 wxFontEncoding
wxFont::GetEncoding() const
408 return M_FONTDATA
->m_encoding
;
411 bool wxFont::GetNoAntiAliasing() const
413 return M_FONTDATA
->m_noAA
;
416 short wxFont::GetMacFontNum() const
418 return M_FONTDATA
->m_macFontNum
;
421 short wxFont::GetMacFontSize() const
423 return M_FONTDATA
->m_macFontSize
;
426 wxByte
wxFont::GetMacFontStyle() const
428 return M_FONTDATA
->m_macFontStyle
;
431 wxUint32
wxFont::GetMacATSUFontID() const
433 return M_FONTDATA
->m_macATSUFontID
;
436 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
438 wxCHECK_MSG( Ok(), NULL
, wxT("invalid font") );
440 M_FONTDATA
->m_info
.InitFromFont(*this);
442 return &(M_FONTDATA
->m_info
);