Font updates for OS/2

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8906 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
David Webster
2000-12-11 04:36:46 +00:00
parent 2f2dc32851
commit e99762c031
8 changed files with 994 additions and 721 deletions

View File

@@ -13,6 +13,7 @@
#define _WX_FONT_H_ #define _WX_FONT_H_
#include "wx/gdiobj.h" #include "wx/gdiobj.h"
#include "wx/os2/private.h"
WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString; WXDLLEXPORT_DATA(extern const wxChar*) wxEmptyString;
@@ -25,73 +26,83 @@ class WXDLLEXPORT wxFont : public wxFontBase
public: public:
// ctors and such // ctors and such
wxFont() { Init(); } wxFont() { Init(); }
wxFont(const wxFont& font) { Init(); Ref(font); } wxFont(const wxFont& rFont) { Init(); Ref(rFont); }
wxFont(int size, wxFont( int nSize
int family, ,int nFamily
int style, ,int nStyle
int weight, ,int nWeight
bool underlined = FALSE, ,bool bUnderlined = FALSE
const wxString& face = wxEmptyString, ,const wxString& rsFace = wxEmptyString
wxFontEncoding encoding = wxFONTENCODING_DEFAULT) ,wxFontEncoding vEncoding = wxFONTENCODING_DEFAULT
)
{ {
Init(); Init();
(void)Create(size, family, style, weight, underlined, face, encoding); (void)Create(nSize, nFamily, nStyle, nWeight, bUnderlined, rsFace, vEncoding);
} }
bool Create(int size, bool Create( int nSize
int family, ,int nFamily
int style, ,int nStyle
int weight, ,int nWeight
bool underlined = FALSE, ,bool bUnderlined = FALSE
const wxString& face = wxEmptyString, ,const wxString& rsFace = wxEmptyString
wxFontEncoding encoding = wxFONTENCODING_DEFAULT); ,wxFontEncoding vEncoding = wxFONTENCODING_DEFAULT
);
virtual ~wxFont(); virtual ~wxFont();
// assignment //
wxFont& operator=(const wxFont& font); // Assignment
//
wxFont& operator=(const wxFont& rFont);
// implement base class pure virtuals //
virtual int GetPointSize() const; // Implement base class pure virtuals
virtual int GetFamily() const; //
virtual int GetStyle() const; virtual int GetPointSize(void) const;
virtual int GetWeight() const; virtual int GetFamily(void) const;
virtual bool GetUnderlined() const; virtual int GetStyle(void) const;
virtual wxString GetFaceName() const; virtual int GetWeight(void) const;
virtual wxFontEncoding GetEncoding() const; virtual bool GetUnderlined(void) const;
virtual wxString GetFaceName(void) const;
virtual wxFontEncoding GetEncoding(void) const;
virtual HPS GetPS(void) const;
virtual void SetPointSize(int pointSize); virtual void SetPointSize(int nPointSize);
virtual void SetFamily(int family); virtual void SetFamily(int nFamily);
virtual void SetStyle(int style); virtual void SetStyle(int nStyle);
virtual void SetWeight(int weight); virtual void SetWeight(int nWeight);
virtual void SetFaceName(const wxString& faceName); virtual void SetFaceName(const wxString& rsFaceName);
virtual void SetUnderlined(bool underlined); virtual void SetUnderlined(bool bUnderlined);
virtual void SetEncoding(wxFontEncoding encoding); virtual void SetEncoding(wxFontEncoding vEncoding);
virtual void SetPS(HPS hPS);
virtual void SetFM( PFONTMETRICS pFM
,int nNumFonts
);
// implementation only from now on //
// Implementation only from now on
// ------------------------------- // -------------------------------
//
int GetFontId() const; int GetFontId(void) const;
virtual bool IsFree() const; virtual bool IsFree(void) const;
virtual bool RealizeResource(); virtual bool RealizeResource(void);
virtual WXHANDLE GetResourceHandle(); virtual WXHANDLE GetResourceHandle(void);
virtual bool FreeResource(bool force = FALSE); virtual bool FreeResource(bool bForce = FALSE);
/*
virtual bool UseResource();
virtual bool ReleaseResource();
*/
protected: protected:
// common part of all ctors //
void Init(); // Common part of all ctors
//
void Unshare(); void Init(void);
void Unshare(void);
private: private:
DECLARE_DYNAMIC_CLASS(wxFont) void OS2SelectMatchingFontByName(void);
};
#endif DECLARE_DYNAMIC_CLASS(wxFont)
// _WX_FONT_H_ }; // end of wxFont
#endif // _WX_FONT_H_

View File

@@ -175,8 +175,15 @@ WXDLLEXPORT void wxSetInstance(HINSTANCE hInst);
WXDLLEXPORT wxWindow* wxFindWinFromHandle(WXHWND hWnd); WXDLLEXPORT wxWindow* wxFindWinFromHandle(WXHWND hWnd);
WXDLLEXPORT void wxGetCharSize(WXHWND wnd, int *x, int *y,wxFont *the_font); WXDLLEXPORT void wxGetCharSize(WXHWND wnd, int *x, int *y,wxFont *the_font);
WXDLLEXPORT void wxFillLogFont(LOGFONT *logFont, wxFont *font); WXDLLEXPORT void wxFillLogFont( LOGFONT* pLogFont
WXDLLEXPORT wxFont wxCreateFontFromLogFont(LOGFONT *logFont); ,PFACENAMEDESC pFaceName
,const wxFont* pFont
);
WXDLLEXPORT wxFont wxCreateFontFromLogFont( LOGFONT* pLogFont
,PFONTMETRICS pFM
,PFACENAMEDESC pFace
);
WXDLLEXPORT int wxGpiStrcmp(char* s0, char* s1);
WXDLLEXPORT void wxSliderEvent(WXHWND control, WXWORD wParam, WXWORD pos); WXDLLEXPORT void wxSliderEvent(WXHWND control, WXWORD wParam, WXWORD pos);
WXDLLEXPORT void wxScrollBarEvent(WXHWND hbar, WXWORD wParam, WXWORD pos); WXDLLEXPORT void wxScrollBarEvent(WXHWND hbar, WXWORD wParam, WXWORD pos);

View File

@@ -301,7 +301,7 @@ bool wxApp::RegisterWindowClasses(
if (!::WinRegisterClass( vHab if (!::WinRegisterClass( vHab
,wxCanvasClassName ,wxCanvasClassName
,wxWndProc ,wxWndProc
,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_HITTEST | CS_SAVEBITS | CS_SYNCPAINT ,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_HITTEST | CS_SAVEBITS | CS_SYNCPAINT | CS_CLIPCHILDREN
,sizeof(ULONG) ,sizeof(ULONG)
)) ))
{ {

View File

@@ -146,13 +146,12 @@ wxDC::wxDC(void)
m_nDCCount = 0; m_nDCCount = 0;
m_hOldPS = NULL; m_hOldPS = NULL;
m_hPS = NULL; m_hPS = NULL;
m_bIsPaintTime = FALSE;// True at Paint Time m_bIsPaintTime = FALSE; // True at Paint Time
}; }
wxDC::~wxDC(void) wxDC::~wxDC(void)
{ {
// TODO: }
};
// This will select current objects out of the DC, // This will select current objects out of the DC,
// which is what you have to do before deleting the // which is what you have to do before deleting the
@@ -425,19 +424,13 @@ void wxDC::DoDrawArc(
dAnglmid = (dAngl1 + dAngl2)/2. + M_PI; dAnglmid = (dAngl1 + dAngl2)/2. + M_PI;
vXm = vXc + dRadius * cos(dAnglmid); vXm = vXc + dRadius * cos(dAnglmid);
vYm = vYc + dRadius * sin(dAnglmid); vYm = vYc + dRadius * sin(dAnglmid);
DoDrawArc( vX1 DoDrawArc( vX1, vY1
,vY1 ,vXm, vYm
,vXm ,vXc, vYc
,vYm
,vXc
,vYc
); );
DoDrawArc( vXm DoDrawArc( vXm, vYm
,vYm ,vX2, vY2
,vX2 ,vXc, vYc
,vY2
,vXc
,vYc
); );
return; return;
} }
@@ -962,22 +955,19 @@ void wxDC::SetFont(
// //
if (m_hOldFont) if (m_hOldFont)
{ {
// ::SelectObject(GetHdc(), (HFONT) m_hOldFont);
m_hOldFont = 0; m_hOldFont = 0;
} }
m_font = rFont; m_font = rFont;
if (!rFont.Ok()) if (!rFont.Ok())
{ {
if (m_hOldFont)
// ::SelectObject(GetHdc(), (HFONT) m_hOldFont);
m_hOldFont = 0; m_hOldFont = 0;
} }
if (m_font.Ok() && m_font.GetResourceHandle()) m_font.SetPS(m_hPS); // this will realize the font
if (m_font.Ok())
{ {
HFONT hFont = (HFONT)0; //::SelectObject(GetHdc(), (HFONT) m_font.GetResourceHandle()); HFONT hFont = m_font.GetResourceHandle();
if (hFont == (HFONT) NULL) if (hFont == (HFONT) NULL)
{ {
wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont.")); wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
@@ -985,7 +975,7 @@ void wxDC::SetFont(
if (!m_hOldFont) if (!m_hOldFont)
m_hOldFont = (WXHFONT) hFont; m_hOldFont = (WXHFONT) hFont;
} }
} } // end of wxDC::SetFont
void wxDC::SetPen( void wxDC::SetPen(
const wxPen& rPen const wxPen& rPen

View File

@@ -34,17 +34,19 @@
struct WXDLLEXPORT wxPaintDCInfo struct WXDLLEXPORT wxPaintDCInfo
{ {
wxPaintDCInfo(wxWindow *win, wxDC *dc) wxPaintDCInfo( wxWindow* pWin
,wxDC* pDC
)
{ {
hwnd = win->GetHWND(); m_hWnd = pWin->GetHWND();
hdc = dc->GetHDC(); m_hDC = pDC->GetHDC();
count = 1; m_nCount = 1;
} }
WXHWND hwnd; // window for this DC WXHWND m_hWnd; // window for this DC
WXHDC hdc; // the DC handle WXHDC m_hDC; // the DC handle
size_t count; // usage count size_t m_nCount; // usage count
}; }; // end of wxPaintDCInfot
#include "wx/arrimpl.cpp" #include "wx/arrimpl.cpp"
@@ -85,13 +87,15 @@ wxWindowDC::wxWindowDC()
m_pCanvas = NULL; m_pCanvas = NULL;
} }
wxWindowDC::wxWindowDC(wxWindow *the_canvas) wxWindowDC::wxWindowDC(
wxWindow* pTheCanvas
)
{ {
ERRORID vError; ERRORID vError;
wxString sError; wxString sError;
m_pCanvas = the_canvas; m_pCanvas = pTheCanvas;
m_hDC = (WXHDC) ::WinOpenWindowDC(GetWinHwnd(the_canvas) ); m_hDC = (WXHDC) ::WinOpenWindowDC(GetWinHwnd(pTheCanvas) );
m_nDCCount++; m_nDCCount++;
// //
// default under PM is that Window and Client DC's are the same // default under PM is that Window and Client DC's are the same
@@ -153,18 +157,20 @@ wxClientDC::wxClientDC()
m_pCanvas = NULL; m_pCanvas = NULL;
} }
wxClientDC::wxClientDC(wxWindow *the_canvas) wxClientDC::wxClientDC(
wxWindow* pTheCanvas
)
{ {
SIZEL vSizl = { 0,0}; SIZEL vSizl = { 0,0};
ERRORID vError; ERRORID vError;
wxString sError; wxString sError;
m_pCanvas = the_canvas; m_pCanvas = pTheCanvas;
// //
// default under PM is that Window and Client DC's are the same // default under PM is that Window and Client DC's are the same
// //
m_hDC = (WXHDC) ::WinOpenWindowDC(GetWinHwnd(the_canvas)); m_hDC = (WXHDC) ::WinOpenWindowDC(GetWinHwnd(pTheCanvas));
m_hPS = ::GpiCreatePS( wxGetInstance() m_hPS = ::GpiCreatePS( wxGetInstance()
,m_hDC ,m_hDC
,&vSizl ,&vSizl
@@ -191,7 +197,7 @@ wxClientDC::wxClientDC(wxWindow *the_canvas)
,wxSOLID ,wxSOLID
) )
); );
} } // end of wxClientDC::wxClientDC
wxClientDC::~wxClientDC() wxClientDC::~wxClientDC()
{ {
@@ -205,7 +211,7 @@ wxClientDC::~wxClientDC()
// //
m_hDC = 0; m_hDC = 0;
} }
} } // end of wxClientDC::~wxClientDC
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxPaintDC // wxPaintDC
@@ -259,13 +265,45 @@ wxPaintDC::wxPaintDC(
if (pInfo) if (pInfo)
{ {
m_hDC = pInfo->hdc; m_hDC = pInfo->m_hDC;
pInfo->count++; pInfo->m_nCount++;
} }
else // not in cache, create a new one else // not in cache, create a new one
{ {
SIZEL vSizl = { 0,0};
HPS hPS; HPS hPS;
HRGN hRgn;
memset(&g_paintStruct, '\0', sizeof(RECTL));
if (!::WinQueryUpdateRect(GetWinHwnd(m_pCanvas), &g_paintStruct))
{
wxLogLastError("CreateRectRgn");
// return;
}
m_hDC = (WXHDC) ::WinOpenWindowDC(GetWinHwnd(m_pCanvas));
m_hPS = ::GpiCreatePS( wxGetInstance()
,m_hDC
,&vSizl
,PU_PELS | GPIF_LONG | GPIA_ASSOC
);
// Set the wxWindows color table
::GpiCreateLogColorTable( m_hPS
,0L
,LCOLF_CONSECRGB
,0L
,(LONG)wxTheColourDatabase->m_nSize
,(PLONG)wxTheColourDatabase->m_palTable
);
::GpiCreateLogColorTable( m_hPS
,0L
,LCOLF_RGB
,0L
,0L
,NULL
);
#if 0
hPS = ::WinBeginPaint( GetWinHwnd(m_pCanvas) hPS = ::WinBeginPaint( GetWinHwnd(m_pCanvas)
,NULLHANDLE ,NULLHANDLE
,&g_paintStruct ,&g_paintStruct
@@ -289,6 +327,8 @@ wxPaintDC::wxPaintDC(
,NULL ,NULL
); );
} }
#endif
m_bIsPaintTime = TRUE; m_bIsPaintTime = TRUE;
m_hDC = (WXHDC) -1; // to satisfy those anonizmous efforts m_hDC = (WXHDC) -1; // to satisfy those anonizmous efforts
m_vRclPaint = g_paintStruct; m_vRclPaint = g_paintStruct;
@@ -303,17 +343,17 @@ wxPaintDC::~wxPaintDC()
{ {
SelectOldObjects(m_hDC); SelectOldObjects(m_hDC);
size_t index; size_t nIndex;
wxPaintDCInfo *info = FindInCache(&index); wxPaintDCInfo* pInfo = FindInCache(&nIndex);
wxCHECK_RET( info, wxT("existing DC should have a cache entry") ); wxCHECK_RET( pInfo, wxT("existing DC should have a cache entry") );
if ( !--info->count ) if ( !--pInfo->m_nCount )
{ {
::WinEndPaint(m_hPS); ::WinEndPaint(m_hPS);
m_hPS = m_hOldPS; m_hPS = m_hOldPS;
m_bIsPaintTime = FALSE; m_bIsPaintTime = FALSE;
ms_cache.Remove(index); ms_cache.Remove(nIndex);
} }
//else: cached DC entry is still in use //else: cached DC entry is still in use
@@ -322,20 +362,23 @@ wxPaintDC::~wxPaintDC()
} }
} }
wxPaintDCInfo *wxPaintDC::FindInCache(size_t *index) const wxPaintDCInfo* wxPaintDC::FindInCache(
size_t* pIndex
) const
{ {
wxPaintDCInfo *info = NULL; wxPaintDCInfo* pInfo = NULL;
size_t nCache = ms_cache.GetCount(); size_t nCache = ms_cache.GetCount();
for ( size_t n = 0; n < nCache; n++ )
for (size_t n = 0; n < nCache; n++)
{ {
info = &ms_cache[n]; pInfo = &ms_cache[n];
if ( info->hwnd == m_pCanvas->GetHWND() ) if (pInfo->m_hWnd == m_pCanvas->GetHWND())
{ {
if ( index ) if (pIndex)
*index = n; *pIndex = n;
break; break;
} }
} }
return pInfo;
} // end of wxPaintDC::FindInCache
return info;
}

File diff suppressed because it is too large Load Diff

View File

@@ -52,199 +52,231 @@
// convert to/from the string representation: format is // convert to/from the string representation: format is
// encodingid;facename[;charset] // encodingid;facename[;charset]
bool wxNativeEncodingInfo::FromString(const wxString& s) bool wxNativeEncodingInfo::FromString(
const wxString& rsStr
)
{ {
wxStringTokenizer tokenizer(s, _T(";")); wxStringTokenizer vTokenizer(rsStr, _T(";"));
wxString sEncid = vTokenizer.GetNextToken();
long lEnc;
wxString encid = tokenizer.GetNextToken(); if (!sEncid.ToLong(&lEnc))
long enc;
if ( !encid.ToLong(&enc) )
return FALSE; return FALSE;
encoding = (wxFontEncoding)enc; encoding = (wxFontEncoding)lEnc;
facename = vTokenizer.GetNextToken();
facename = tokenizer.GetNextToken(); if (!facename)
if ( !facename )
return FALSE; return FALSE;
wxString tmp = tokenizer.GetNextToken(); wxString sTmp = vTokenizer.GetNextToken();
if ( !tmp )
if (!sTmp)
{ {
// default charset (don't use DEFAULT_CHARSET though because of subtle charset = 850;
// Windows 9x/NT differences in handling it)
// TODO: what is this for OS/2?
// charset = ANSI_CHARSET;
} }
else else
{ {
if ( wxSscanf(tmp, _T("%u"), &charset) != 1 ) if ( wxSscanf(sTmp, _T("%u"), &charset) != 1 )
{ {
// should be a number! // should be a number!
return FALSE; return FALSE;
} }
} }
return TRUE; return TRUE;
} } // end of wxNativeEncodingInfo::FromString
wxString wxNativeEncodingInfo::ToString() const wxString wxNativeEncodingInfo::ToString() const
{ {
wxString s; wxString sStr;
s << (long)encoding << _T(';') << facename; sStr << (long)encoding << _T(';') << facename;
// TODO: what is this for OS/2? if (charset != 850)
/*
if ( charset != ANSI_CHARSET )
{ {
s << _T(';') << charset; sStr << _T(';') << charset;
} }
*/ return sStr;
return s; } // end of wxNativeEncodingInfo::ToString
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// helper functions // helper functions
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
bool wxGetNativeFontEncoding(wxFontEncoding encoding, bool wxGetNativeFontEncoding(
wxNativeEncodingInfo *info) wxFontEncoding vEncoding
, wxNativeEncodingInfo* pInfo
)
{ {
wxCHECK_MSG( info, FALSE, _T("bad pointer in wxGetNativeFontEncoding") ); wxCHECK_MSG(pInfo, FALSE, _T("bad pointer in wxGetNativeFontEncoding") );
if (vEncoding == wxFONTENCODING_DEFAULT)
if ( encoding == wxFONTENCODING_DEFAULT )
{ {
encoding = wxFont::GetDefaultEncoding(); vEncoding = wxFont::GetDefaultEncoding();
} }
switch (vEncoding)
switch ( encoding )
{ {
// TODO: fix this for OS2
/*
// although this function is supposed to return an exact match, do do
// some mappings here for the most common case of "standard" encoding
case wxFONTENCODING_SYSTEM:
case wxFONTENCODING_ISO8859_1: case wxFONTENCODING_ISO8859_1:
case wxFONTENCODING_ISO8859_15: case wxFONTENCODING_ISO8859_15:
case wxFONTENCODING_CP1252:
info->charset = ANSI_CHARSET;
break;
case wxFONTENCODING_CP1250: case wxFONTENCODING_CP1250:
info->charset = EASTEUROPE_CHARSET; pInfo->charset = 1250;
break; break;
case wxFONTENCODING_ISO8859_2:
case wxFONTENCODING_CP1252:
pInfo->charset = 1252;
break;
case wxFONTENCODING_ISO8859_4:
case wxFONTENCODING_ISO8859_10:
pInfo->charset = 921; // what is baltic?
break;
case wxFONTENCODING_ISO8859_5:
case wxFONTENCODING_CP1251: case wxFONTENCODING_CP1251:
info->charset = RUSSIAN_CHARSET; pInfo->charset = 1251;
break; break;
case wxFONTENCODING_CP1253: case wxFONTENCODING_ISO8859_6:
info->charset = GREEK_CHARSET; pInfo->charset = 864;
break; break;
case wxFONTENCODING_CP1254: case wxFONTENCODING_ISO8859_7:
info->charset = TURKISH_CHARSET; pInfo->charset = 869;
break; break;
case wxFONTENCODING_CP1255: case wxFONTENCODING_ISO8859_8:
info->charset = HEBREW_CHARSET; pInfo->charset = 862;
break; break;
case wxFONTENCODING_CP1256: case wxFONTENCODING_ISO8859_9:
info->charset = ARABIC_CHARSET; pInfo->charset = 857;
break; break;
case wxFONTENCODING_CP1257: case wxFONTENCODING_ISO8859_11:
info->charset = BALTIC_CHARSET; pInfo->charset = 874; // what is thai
break;
case wxFONTENCODING_CP874:
info->charset = THAI_CHARSET;
break; break;
case wxFONTENCODING_CP437: case wxFONTENCODING_CP437:
info->charset = OEM_CHARSET; pInfo->charset = 437;
break; break;
*/
default: default:
// no way to translate this encoding into a Windows charset wxFAIL_MSG(wxT("unsupported encoding"));
return FALSE; // fall through
case wxFONTENCODING_SYSTEM:
pInfo->charset = 850;
break;
} }
return TRUE; return TRUE;
} } // end of wxGetNativeFontEncoding
bool wxTestFontEncoding(const wxNativeEncodingInfo& info) bool wxTestFontEncoding(
const wxNativeEncodingInfo& rInfo
)
{ {
// TODO: FATTRS vLogFont;
/* HPS hPS;
// try to create such font
LOGFONT lf;
wxZeroMemory(lf); // all default values
lf.lfCharSet = info.charset; hPS = ::WinGetPS(HWND_DESKTOP);
strncpy(lf.lfFaceName, info.facename, sizeof(lf.lfFaceName));
HFONT hfont = ::CreateFontIndirect(&lf); memset(&vLogFont, '\0', sizeof(FATTRS)); // all default values
if ( !hfont ) vLogFont.usRecordLength = sizeof(FATTRS);
vLogFont.usCodePage = rInfo.charset;
vLogFont.lMaxBaselineExt = 0L; // Outline fonts should use 0
vLogFont.lAveCharWidth = 0L; // Outline fonts should use 0
vLogFont.fsFontUse = FATTR_FONTUSE_OUTLINE | // only outline fonts allowed
FATTR_FONTUSE_TRANSFORMABLE; // may be transformed
strncpy(vLogFont.szFacename, rInfo.facename.c_str(), sizeof(vLogFont.szFacename));
if (!::GpiCreateLogFont( hPS
,NULL
,1L
,&vLogFont
))
{ {
// no such font ::WinReleasePS(hPS);
return FALSE; return FALSE;
} }
::WinReleasePS(hPS);
::DeleteObject((HGDIOBJ)hfont);
*/
return TRUE; return TRUE;
} } // end of wxTestFontEncoding
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxFont <-> LOGFONT conversion // wxFont <-> LOGFONT conversion
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#if 0 void wxFillLogFont(
void wxFillLogFont(LOGFONT *logFont, const wxFont *font) LOGFONT* pLogFont // OS2 GPI FATTRS
, PFACENAMEDESC pFaceName
, const wxFont* pFont
)
{ {
int ff_family; wxString sFace;
wxString ff_face; USHORT uWeight;
int nItalic;
switch ( font->GetFamily() ) pLogFont->fsSelection = 0;
pLogFont->fsSelection = FATTR_SEL_OUTLINE; // we will alway use only outlines
pFaceName->usWeightClass = 0;
pFaceName->flOptions = 0;
switch (pFont->GetFamily())
{ {
case wxSCRIPT: case wxSCRIPT:
ff_family = FF_SCRIPT; sFace = _T("Script");
ff_face = _T("Script");
break; break;
case wxDECORATIVE: case wxDECORATIVE:
ff_family = FF_DECORATIVE;
break;
case wxROMAN: case wxROMAN:
ff_family = FF_ROMAN; sFace = _T("Times New Roman");
ff_face = _T("Times New Roman");
break; break;
case wxTELETYPE: case wxTELETYPE:
case wxMODERN: case wxMODERN:
ff_family = FF_MODERN; sFace = _T("Courier New");
ff_face = _T("Courier New");
break; break;
case wxSWISS: case wxSWISS:
ff_family = FF_SWISS; sFace = _T("WarpSans");
ff_face = _T("Arial");
break; break;
case wxDEFAULT: case wxDEFAULT:
default: default:
ff_family = FF_SWISS; sFace = _T("Helv");
ff_face = _T("MS Sans Serif");
} }
BYTE ff_italic; switch (pFont->GetWeight())
switch ( font->GetStyle() ) {
default:
wxFAIL_MSG(_T("unknown font weight"));
uWeight = FWEIGHT_DONT_CARE;
break;
case wxNORMAL:
uWeight = FWEIGHT_NORMAL;
break;
case wxLIGHT:
uWeight = FWEIGHT_LIGHT;
break;
case wxBOLD:
uWeight = FWEIGHT_BOLD;
pLogFont->fsSelection |= FATTR_SEL_BOLD;
break;
case wxFONTWEIGHT_MAX:
uWeight = FWEIGHT_ULTRA_BOLD;
pLogFont->fsSelection |= FATTR_SEL_BOLD;
break;
}
pFaceName->usWeightClass |= uWeight;
switch (pFont->GetStyle())
{ {
case wxITALIC: case wxITALIC:
case wxSLANT: case wxSLANT:
ff_italic = 1; nItalic = FTYPE_ITALIC;
pLogFont->fsSelection |= FATTR_SEL_ITALIC;
break; break;
default: default:
@@ -252,214 +284,236 @@ void wxFillLogFont(LOGFONT *logFont, const wxFont *font)
// fall through // fall through
case wxNORMAL: case wxNORMAL:
ff_italic = 0; nItalic = 0;
}
int ff_weight;
switch ( font->GetWeight() )
{
default:
wxFAIL_MSG(_T("unknown font weight"));
// fall through
case wxNORMAL:
ff_weight = FW_NORMAL;
break;
case wxLIGHT:
ff_weight = FW_LIGHT;
break;
case wxBOLD:
ff_weight = FW_BOLD;
break; break;
} }
pFaceName->flOptions |= nItalic;
if(pFont->GetUnderlined())
pLogFont->fsSelection |= FATTR_SEL_UNDERSCORE;
#if 0 //
HDC dc = ::GetDC(NULL); // In PM a font's height is expressed in points. A point equals
int ppInch = ::GetDeviceCaps(dc, LOGPIXELSY); // approximately 1/72 of an inch. We'll assume for now that,
::ReleaseDC(NULL, dc); // like Windows, that fonts are 96 dpi.
#else //
// New behaviour: apparently ppInch varies according to Large/Small Fonts DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
// setting in Windows. This messes up fonts. So, set ppInch to a constant HDC hDC = ::DevOpenDC(vHabmain, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&vDop, NULLHANDLE);
// 96 dpi. LONG lStart = CAPS_FAMILY;
static const int ppInch = 96; LONG lCount = CAPS_VERTICAL_RESOLUTION;
#endif // 0/1 LONG alArray[CAPS_VERTICAL_RESOLUTION];
LONG lRes;
int nPpInch;
#if wxFONT_SIZE_COMPATIBILITY
// Incorrect, but compatible with old wxWindows behaviour
int nHeight = (font->GetPointSize()*ppInch/72);
#else
// Correct for Windows compatibility
int nHeight = - (font->GetPointSize()*ppInch/72);
#endif
wxString facename = font->GetFaceName(); ::DevQueryCaps(hDC, lStart, lCount, alArray);
if ( !!facename ) lRes = alArray[CAPS_VERTICAL_RESOLUTION-1];
if (lRes > 0)
nPpInch = (int)(lRes/39.6); // lres is in pixels per meter
else
nPpInch = 96;
int nHeight = (pFont->GetPointSize() * nPpInch/72);
wxString sFacename = pFont->GetFaceName();
if (!!sFacename)
{ {
ff_face = facename; sFace = sFacename;
} }
//else: ff_face is a reasonable default facename for this font family //else: ff_face is a reasonable default facename for this font family
// deal with encoding now //
wxNativeEncodingInfo info; // Deal with encoding now
wxFontEncoding encoding = font->GetEncoding(); //
if ( !wxGetNativeFontEncoding(encoding, &info) ) wxNativeEncodingInfo vInfo;
wxFontEncoding vEncoding = pFont->GetEncoding();
if (!wxGetNativeFontEncoding( vEncoding
,&vInfo
))
{ {
if ( !wxTheFontMapper->GetAltForEncoding(encoding, &info) ) if ( !wxTheFontMapper->GetAltForEncoding( vEncoding
,&vInfo
))
{ {
// unsupported encoding, replace with the default //
info.charset = ANSI_CHARSET; // Unsupported encoding, replace with the default
//
vInfo.charset = 850;
} }
} }
if ( !info.facename.IsEmpty() ) if (!vInfo.facename.IsEmpty() )
{ {
// the facename determined by the encoding overrides everything else //
ff_face = info.facename; // The facename determined by the encoding overrides everything else
//
sFace = vInfo.facename;
} }
// transfer all the data to LOGFONT //
logFont->lfHeight = nHeight; // Transfer all the data to LOGFONT
logFont->lfWidth = 0; //
logFont->lfEscapement = 0; pLogFont->usRecordLength = sizeof(FATTRS);
logFont->lfOrientation = 0; wxStrcpy(pLogFont->szFacename, sFace.c_str());
logFont->lfWeight = ff_weight; pLogFont->usCodePage = vInfo.charset;
logFont->lfItalic = ff_italic; pLogFont->fsFontUse |= FATTR_FONTUSE_OUTLINE |
logFont->lfUnderline = (BYTE)font->GetUnderlined(); FATTR_FONTUSE_TRANSFORMABLE;
logFont->lfStrikeOut = 0; } // end of wxFillLogFont
logFont->lfCharSet = info.charset;
logFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
logFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
logFont->lfQuality = PROOF_QUALITY;
logFont->lfPitchAndFamily = DEFAULT_PITCH | ff_family;
wxStrncpy(logFont->lfFaceName, ff_face, WXSIZEOF(logFont->lfFaceName));
}
wxFont wxCreateFontFromLogFont(const LOGFONT *logFont) wxFont wxCreateFontFromLogFont(
const LOGFONT* pLogFont
, const PFONTMETRICS pFM
, PFACENAMEDESC pFaceName
)
{ {
DEBUG_PRINTF(wxCreateFontFromLogFont) //
// Extract family from facename
//
int nFontFamily;
// extract family from pitch-and-family if (strcmp(pLogFont->szFacename, "Times New Roman") == 0)
int lfFamily = logFont->lfPitchAndFamily; nFontFamily = wxROMAN;
if ( lfFamily & FIXED_PITCH ) else if (strcmp(pLogFont->szFacename, "WarpSans") == 0)
lfFamily -= FIXED_PITCH; nFontFamily = wxSWISS;
if ( lfFamily & VARIABLE_PITCH ) else if (strcmp(pLogFont->szFacename, "Script") == 0)
lfFamily -= VARIABLE_PITCH; nFontFamily = wxSCRIPT;
else if (strcmp(pLogFont->szFacename, "Courier New") == 0)
nFontFamily = wxMODERN;
else
nFontFamily = wxSWISS;
int fontFamily; //
switch ( lfFamily ) // Weight and Style
//
int nFontWeight = wxNORMAL;
switch (pFaceName->usWeightClass)
{ {
case FF_ROMAN: case FWEIGHT_LIGHT:
fontFamily = wxROMAN; nFontWeight = wxLIGHT;
break;
case FF_SWISS:
fontFamily = wxSWISS;
break;
case FF_SCRIPT:
fontFamily = wxSCRIPT;
break;
case FF_MODERN:
fontFamily = wxMODERN;
break;
case FF_DECORATIVE:
fontFamily = wxDECORATIVE;
break; break;
default: default:
fontFamily = wxSWISS; case FWEIGHT_NORMAL:
} nFontWeight = wxNORMAL;
// weight and style
int fontWeight = wxNORMAL;
switch ( logFont->lfWeight )
{
case FW_LIGHT:
fontWeight = wxLIGHT;
break; break;
default: case FWEIGHT_BOLD:
case FW_NORMAL: nFontWeight = wxBOLD;
fontWeight = wxNORMAL;
break;
case FW_BOLD:
fontWeight = wxBOLD;
break; break;
} }
int fontStyle = logFont->lfItalic ? wxITALIC : wxNORMAL; int nFontStyle;
bool fontUnderline = logFont->lfUnderline != 0; if(pLogFont->fsSelection & FATTR_SEL_ITALIC)
nFontStyle = wxITALIC;
else
nFontStyle = wxNORMAL;
wxString fontFace = logFont->lfFaceName; bool bFontUnderline = (pLogFont->fsSelection & FATTR_SEL_UNDERSCORE);
wxString sFontFace = pLogFont->szFacename;
int nFontPoints = pFM->lEmHeight;
wxFontEncoding vFontEncoding;
// font size switch (pLogFont->usCodePage)
HDC dc = ::GetDC(NULL);
// remember that 1pt = 1/72inch
int height = abs(logFont->lfHeight);
int fontPoints = (72*height)/GetDeviceCaps(dc, LOGPIXELSY);
::ReleaseDC(NULL, dc);
wxFontEncoding fontEncoding;
switch ( logFont->lfCharSet )
{ {
default: default:
wxFAIL_MSG(wxT("unsupported charset")); wxFAIL_MSG(wxT("unsupported charset"));
// fall through // fall through
case ANSI_CHARSET: case 850:
fontEncoding = wxFONTENCODING_CP1252; vFontEncoding = wxFONTENCODING_CP1252;
break; break;
#ifdef __WIN32__ case 1250:
case EASTEUROPE_CHARSET: vFontEncoding = wxFONTENCODING_CP1250;
fontEncoding = wxFONTENCODING_CP1250;
break; break;
case BALTIC_CHARSET: case 921:
fontEncoding = wxFONTENCODING_CP1257; vFontEncoding = wxFONTENCODING_CP1257;
break; break;
case RUSSIAN_CHARSET: case 866:
fontEncoding = wxFONTENCODING_CP1251; vFontEncoding = wxFONTENCODING_CP1251;
break; break;
case ARABIC_CHARSET: case 864:
fontEncoding = wxFONTENCODING_CP1256; vFontEncoding = wxFONTENCODING_CP1256;
break; break;
case GREEK_CHARSET: case 869:
fontEncoding = wxFONTENCODING_CP1253; vFontEncoding = wxFONTENCODING_CP1253;
break; break;
case HEBREW_CHARSET: case 862:
fontEncoding = wxFONTENCODING_CP1255; vFontEncoding = wxFONTENCODING_CP1255;
break; break;
case TURKISH_CHARSET: case 857:
fontEncoding = wxFONTENCODING_CP1254; vFontEncoding = wxFONTENCODING_CP1254;
break; break;
case THAI_CHARSET: case 874:
fontEncoding = wxFONTENCODING_CP437; vFontEncoding = wxFONTENCODING_CP437;
break; break;
#endif
case OEM_CHARSET: case 437:
fontEncoding = wxFONTENCODING_CP437; vFontEncoding = wxFONTENCODING_CP437;
break; break;
} }
return wxFont(fontPoints, fontFamily, fontStyle, return wxFont( nFontPoints
fontWeight, fontUnderline, fontFace, ,nFontFamily
fontEncoding); ,nFontStyle
} ,nFontWeight
#endif // 0 ,bFontUnderline
,sFontFace
,vFontEncoding
);
} // end of wxCreateFontFromLogFont
int wxGpiStrcmp(
char* s0
, char* s1
)
{ int l0;
int l1;
int l;
int d;
int d1;
int i;
int rc;
rc = 0;
if(s0 == NULL)
{
if(s1 == NULL)
return 0;
else
return 32;
}
else if(s1 == NULL)
return 32;
l0 = strlen(s0);
l1 = strlen(s1);
l = l0;
if(l0 != l1)
{
rc++;
if(l1 < l0)
l = l1;
}
for(i=0;i<l;i++)
{
d = s0[i]-s1[i];
if(!d)
continue;
d1 = toupper(s0[i]) - toupper(s1[i]);
if(!d1)
continue;
rc += abs(d);
}
return rc;
}

View File

@@ -1026,20 +1026,6 @@ bool wxFrame::OS2Create(
wxLogError("Error sizing client. Error: %s\n", sError); wxLogError("Error sizing client. Error: %s\n", sError);
return FALSE; return FALSE;
} }
/*
uCtlCount = SHORT1FROMMP(::WinSendMsg(GetHWND(), WM_FORMATFRAME, (MPARAM)vSwp, (MPARAM)vRect));
for (int i = 0; i < uCtlCount; i++)
{
if (vSwp[i].hwnd == GetHWND())
memcpy(&m_vSwp, &vSwp[i], sizeof(SWP));
else if (vSwp[i].hwnd == m_hVScroll)
memcpy(&m_vSwpVScroll, &vSwp[i], sizeof(SWP));
else if (vSwp[i].hwnd == m_hHScroll)
memcpy(&m_vSwpVScroll, &vSwp[i], sizeof(SWP));
else if (vSwp[i].hwnd == m_hTitleBar)
memcpy(&m_vSwpTitleBar, &vSwp[i], sizeof(SWP));
}*/
return TRUE; return TRUE;
} // end of wxFrame::OS2Create } // end of wxFrame::OS2Create
@@ -1290,7 +1276,8 @@ bool wxFrame::HandlePaint()
} }
else else
{ {
return wxWindow::HandlePaint(); wxWindow::HandlePaint();
return TRUE;
} }
} }
else else