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 #if !USE_SHARED_LIBRARIES
29 IMPLEMENT_DYNAMIC_CLASS(wxFont
, wxGDIObject
)
32 class WXDLLEXPORT wxFontRefData
: public wxGDIRefData
34 friend class WXDLLEXPORT wxFont
;
43 , m_faceName(wxT("Geneva"))
44 , m_encoding(wxFONTENCODING_DEFAULT
)
50 Init(10, wxDEFAULT
, wxNORMAL
, wxNORMAL
, FALSE
,
51 wxT("Geneva"), wxFONTENCODING_DEFAULT
);
54 wxFontRefData(const wxFontRefData
& data
)
56 , m_fontId(data
.m_fontId
)
57 , m_pointSize(data
.m_pointSize
)
58 , m_family(data
.m_family
)
59 , m_style(data
.m_style
)
60 , m_weight(data
.m_weight
)
61 , m_underlined(data
.m_underlined
)
62 , m_faceName(data
.m_faceName
)
63 , m_encoding(data
.m_encoding
)
64 , m_macFontNum(data
.m_macFontNum
)
65 , m_macFontSize(data
.m_macFontSize
)
66 , m_macFontStyle(data
.m_macFontStyle
)
67 , m_macATSUFontID(data
.m_macATSUFontID
)
69 Init(data
.m_pointSize
, data
.m_family
, data
.m_style
, data
.m_weight
,
70 data
.m_underlined
, data
.m_faceName
, data
.m_encoding
);
73 wxFontRefData(int size
,
78 const wxString
& faceName
,
79 wxFontEncoding encoding
)
85 , m_underlined(underlined
)
86 , m_faceName(faceName
)
87 , m_encoding(encoding
)
93 Init(size
, family
, style
, weight
, underlined
, faceName
, encoding
);
96 virtual ~wxFontRefData();
97 void SetNoAntiAliasing( bool no
= TRUE
) { m_noAA
= no
; }
98 bool GetNoAntiAliasing() { return m_noAA
; }
101 // common part of all ctors
107 const wxString
& faceName
,
108 wxFontEncoding encoding
);
110 // font characterstics
118 wxFontEncoding m_encoding
;
119 bool m_noAA
; // No anti-aliasing
124 unsigned char m_macFontStyle
;
125 wxUint32 m_macATSUFontID
;
127 wxNativeFontInfo m_info
;
132 // ============================================================================
134 // ============================================================================
136 // ----------------------------------------------------------------------------
138 // ----------------------------------------------------------------------------
140 void wxFontRefData::Init(int pointSize
,
145 const wxString
& faceName
,
146 wxFontEncoding encoding
)
149 m_pointSize
= pointSize
;
153 m_underlined
= underlined
;
154 m_faceName
= faceName
;
155 m_encoding
= encoding
;
164 wxFontRefData::~wxFontRefData()
168 void wxFontRefData::MacFindFont()
170 if( m_faceName
.Length() == 0 )
175 m_macFontNum
= ::GetAppFont() ;
178 ::GetFNum( "\pTimes" , &m_macFontNum
) ;
181 ::GetFNum( "\pTimes" , &m_macFontNum
) ;
184 ::GetFNum( "\pTimes" , &m_macFontNum
) ;
187 ::GetFNum( "\pGeneva" , &m_macFontNum
) ;
190 ::GetFNum( "\pMonaco" , &m_macFontNum
) ;
194 GetFontName( m_macFontNum
, name
) ;
195 m_faceName
= wxMacMakeStringFromPascal( name
) ;
199 if ( m_faceName
== wxT("systemfont") )
200 m_macFontNum
= ::GetSysFont() ;
201 else if ( m_faceName
== wxT("applicationfont") )
202 m_macFontNum
= ::GetAppFont() ;
206 wxMacStringToPascal( m_faceName
, fontname
) ;
207 ::GetFNum( fontname
, &m_macFontNum
);
212 if (m_weight
== wxBOLD
)
213 m_macFontStyle
|= bold
;
214 if (m_style
== wxITALIC
|| m_style
== wxSLANT
)
215 m_macFontStyle
|= italic
;
217 m_macFontStyle
|= underline
;
218 m_macFontSize
= m_pointSize
;
220 //TODO:if we supply the style as an additional parameter we must make a testing
221 //sequence in order to degrade gracefully while trying to maintain most of the style
222 //information, meanwhile we just take the normal font and apply the features after
225 #endif // __WXDEBUG__
226 ::ATSUFONDtoFontID(m_macFontNum
, normal
/*qdStyle*/, (UInt32
*)&m_macATSUFontID
);
228 status = ATSUFindFontFromName ( (Ptr) m_faceName , strlen( m_faceName ) ,
229 kFontFullName, kFontMacintoshPlatform, kFontRomanScript , kFontNoLanguage , (UInt32*)&m_macATSUFontID ) ;
231 wxASSERT_MSG( status
== noErr
, wxT("couldn't retrieve font identifier") ) ;
234 // ----------------------------------------------------------------------------
236 // ----------------------------------------------------------------------------
242 bool wxFont::Create(const wxNativeFontInfo
& info
)
244 return Create(info
.pointSize
, info
.family
, info
.style
, info
.weight
,
245 info
.underlined
, info
.faceName
, info
.encoding
);
248 wxFont::wxFont(const wxString
& fontdesc
)
250 wxNativeFontInfo info
;
251 if ( info
.FromString(fontdesc
) )
255 bool wxFont::Create(int pointSize
,
260 const wxString
& faceName
,
261 wxFontEncoding encoding
)
264 m_refData
= new wxFontRefData(pointSize
, family
, style
, weight
,
265 underlined
, faceName
, encoding
);
276 bool wxFont::RealizeResource()
278 M_FONTDATA
->MacFindFont() ;
282 void wxFont::SetEncoding(wxFontEncoding encoding
)
286 M_FONTDATA
->m_encoding
= encoding
;
291 void wxFont::Unshare()
293 // Don't change shared data
296 m_refData
= new wxFontRefData();
300 wxFontRefData
* ref
= new wxFontRefData(*(wxFontRefData
*)m_refData
);
306 void wxFont::SetPointSize(int pointSize
)
310 M_FONTDATA
->m_pointSize
= pointSize
;
315 void wxFont::SetFamily(int family
)
319 M_FONTDATA
->m_family
= family
;
324 void wxFont::SetStyle(int style
)
328 M_FONTDATA
->m_style
= style
;
333 void wxFont::SetWeight(int weight
)
337 M_FONTDATA
->m_weight
= weight
;
342 void wxFont::SetFaceName(const wxString
& faceName
)
346 M_FONTDATA
->m_faceName
= faceName
;
351 void wxFont::SetUnderlined(bool underlined
)
355 M_FONTDATA
->m_underlined
= underlined
;
360 void wxFont::SetNoAntiAliasing( bool no
)
364 M_FONTDATA
->SetNoAntiAliasing( no
);
369 // ----------------------------------------------------------------------------
371 // ----------------------------------------------------------------------------
373 // TODO: insert checks everywhere for M_FONTDATA == NULL!
375 int wxFont::GetPointSize() const
377 return M_FONTDATA
->m_pointSize
;
380 int wxFont::GetFamily() const
382 return M_FONTDATA
->m_family
;
385 int wxFont::GetStyle() const
387 return M_FONTDATA
->m_style
;
390 int wxFont::GetWeight() const
392 return M_FONTDATA
->m_weight
;
395 bool wxFont::GetUnderlined() const
397 return M_FONTDATA
->m_underlined
;
400 wxString
wxFont::GetFaceName() const
404 str
= M_FONTDATA
->m_faceName
;
408 wxFontEncoding
wxFont::GetEncoding() const
410 return M_FONTDATA
->m_encoding
;
413 bool wxFont::GetNoAntiAliasing()
415 return M_FONTDATA
->m_noAA
;
418 short wxFont::GetMacFontNum() const
420 return M_FONTDATA
->m_macFontNum
;
423 short wxFont::GetMacFontSize() const
425 return M_FONTDATA
->m_macFontSize
;
428 wxByte
wxFont::GetMacFontStyle() const
430 return M_FONTDATA
->m_macFontStyle
;
433 wxUint32
wxFont::GetMacATSUFontID() const
435 return M_FONTDATA
->m_macATSUFontID
;
438 const wxNativeFontInfo
*wxFont::GetNativeFontInfo() const
440 wxCHECK_MSG( Ok(), NULL
, wxT("invalid font") );
442 M_FONTDATA
->m_info
.InitFromFont(*this);
444 return &(M_FONTDATA
->m_info
);