git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4458 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
268 lines
5.2 KiB
C++
268 lines
5.2 KiB
C++
/////////////////////////////////////////////////////////////////////////////
|
|
// Name: font.cpp
|
|
// Purpose: wxFont class
|
|
// Author: AUTHOR
|
|
// Modified by:
|
|
// Created: ??/??/98
|
|
// RCS-ID: $Id$
|
|
// Copyright: (c) AUTHOR
|
|
// Licence: wxWindows licence
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
#ifdef __GNUG__
|
|
#pragma implementation "font.h"
|
|
#endif
|
|
|
|
#include "wx/defs.h"
|
|
#include "wx/string.h"
|
|
#include "wx/font.h"
|
|
#include "wx/gdicmn.h"
|
|
|
|
#if !USE_SHARED_LIBRARIES
|
|
IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
// implementation
|
|
// ============================================================================
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// wxFontRefData
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void wxFontRefData::Init(int pointSize,
|
|
int family,
|
|
int style,
|
|
int weight,
|
|
bool underlined,
|
|
const wxString& faceName,
|
|
wxFontEncoding encoding)
|
|
{
|
|
m_style = style;
|
|
m_pointSize = pointSize;
|
|
m_family = family;
|
|
m_style = style;
|
|
m_weight = weight;
|
|
m_underlined = underlined;
|
|
m_faceName = faceName;
|
|
m_encoding = encoding;
|
|
|
|
m_macFontNum = 0 ;
|
|
m_macFontSize = 0;
|
|
m_macFontStyle = 0;
|
|
m_fontId = 0;
|
|
}
|
|
|
|
wxFontRefData::~wxFontRefData()
|
|
{
|
|
}
|
|
|
|
void wxFontRefData::MacFindFont()
|
|
{
|
|
if( m_faceName == "" )
|
|
{
|
|
switch( m_family )
|
|
{
|
|
case wxDEFAULT :
|
|
m_macFontNum = ::GetAppFont() ;
|
|
break ;
|
|
case wxDECORATIVE :
|
|
::GetFNum( "\pTimes" , &m_macFontNum) ;
|
|
break ;
|
|
case wxROMAN :
|
|
::GetFNum( "\pTimes" , &m_macFontNum) ;
|
|
break ;
|
|
case wxSCRIPT :
|
|
::GetFNum( "\pTimes" , &m_macFontNum) ;
|
|
break ;
|
|
case wxSWISS :
|
|
::GetFNum( "\pHelvetica" , &m_macFontNum) ;
|
|
break ;
|
|
case wxMODERN :
|
|
::GetFNum( "\pMonaco" , &m_macFontNum) ;
|
|
break ;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if ( m_faceName == "systemfont" )
|
|
m_macFontNum = ::GetSysFont() ;
|
|
else if ( m_faceName == "applicationfont" )
|
|
m_macFontNum = ::GetAppFont() ;
|
|
else
|
|
{
|
|
strcpy(wxBuffer, m_faceName);
|
|
C2PStr(wxBuffer);
|
|
::GetFNum( (unsigned char*) wxBuffer, &m_macFontNum);
|
|
}
|
|
}
|
|
|
|
m_macFontStyle = 0;
|
|
if (m_weight == wxBOLD)
|
|
m_macFontStyle |= bold;
|
|
if (m_style == wxITALIC || m_style == wxSLANT)
|
|
m_macFontStyle |= italic;
|
|
if (m_underlined)
|
|
m_macFontStyle |= underline;
|
|
m_macFontSize = m_pointSize ;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// wxFont
|
|
// ----------------------------------------------------------------------------
|
|
|
|
void wxFont::Init()
|
|
{
|
|
if ( wxTheFontList )
|
|
wxTheFontList->Append(this);
|
|
}
|
|
|
|
bool wxFont::Create(int pointSize,
|
|
int family,
|
|
int style,
|
|
int weight,
|
|
bool underlined,
|
|
const wxString& faceName,
|
|
wxFontEncoding encoding)
|
|
{
|
|
UnRef();
|
|
m_refData = new wxFontRefData(pointSize, family, style, weight,
|
|
underlined, faceName, encoding);
|
|
|
|
RealizeResource();
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
wxFont::~wxFont()
|
|
{
|
|
if (wxTheFontList)
|
|
wxTheFontList->DeleteObject(this);
|
|
}
|
|
|
|
bool wxFont::RealizeResource()
|
|
{
|
|
M_FONTDATA->MacFindFont() ;
|
|
return TRUE;
|
|
}
|
|
|
|
void wxFont::Unshare()
|
|
{
|
|
// Don't change shared data
|
|
if (!m_refData)
|
|
{
|
|
m_refData = new wxFontRefData();
|
|
}
|
|
else
|
|
{
|
|
wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
|
|
UnRef();
|
|
m_refData = ref;
|
|
}
|
|
}
|
|
|
|
void wxFont::SetPointSize(int pointSize)
|
|
{
|
|
Unshare();
|
|
|
|
M_FONTDATA->m_pointSize = pointSize;
|
|
|
|
RealizeResource();
|
|
}
|
|
|
|
void wxFont::SetFamily(int family)
|
|
{
|
|
Unshare();
|
|
|
|
M_FONTDATA->m_family = family;
|
|
|
|
RealizeResource();
|
|
}
|
|
|
|
void wxFont::SetStyle(int style)
|
|
{
|
|
Unshare();
|
|
|
|
M_FONTDATA->m_style = style;
|
|
|
|
RealizeResource();
|
|
}
|
|
|
|
void wxFont::SetWeight(int weight)
|
|
{
|
|
Unshare();
|
|
|
|
M_FONTDATA->m_weight = weight;
|
|
|
|
RealizeResource();
|
|
}
|
|
|
|
void wxFont::SetFaceName(const wxString& faceName)
|
|
{
|
|
Unshare();
|
|
|
|
M_FONTDATA->m_faceName = faceName;
|
|
|
|
RealizeResource();
|
|
}
|
|
|
|
void wxFont::SetUnderlined(bool underlined)
|
|
{
|
|
Unshare();
|
|
|
|
M_FONTDATA->m_underlined = underlined;
|
|
|
|
RealizeResource();
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// accessors
|
|
// ----------------------------------------------------------------------------
|
|
|
|
int wxFont::GetPointSize() const
|
|
{
|
|
return M_FONTDATA->m_pointSize;
|
|
}
|
|
|
|
int wxFont::GetFamily() const
|
|
{
|
|
return M_FONTDATA->m_family;
|
|
}
|
|
|
|
int wxFont::GetFontId() const
|
|
{
|
|
return M_FONTDATA->m_fontId;
|
|
}
|
|
|
|
int wxFont::GetStyle() const
|
|
{
|
|
return M_FONTDATA->m_style;
|
|
}
|
|
|
|
int wxFont::GetWeight() const
|
|
{
|
|
return M_FONTDATA->m_weight;
|
|
}
|
|
|
|
bool wxFont::GetUnderlined() const
|
|
{
|
|
return M_FONTDATA->m_underlined;
|
|
}
|
|
|
|
wxString wxFont::GetFaceName() const
|
|
{
|
|
wxString str;
|
|
if ( M_FONTDATA )
|
|
str = M_FONTDATA->m_faceName ;
|
|
return str;
|
|
}
|
|
|
|
wxFontEncoding wxFont::GetEncoding() const
|
|
{
|
|
return M_FONTDATA->m_encoding;
|
|
}
|
|
|