]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/font.cpp
Added optional parameter to SelectDocumentType() and SelectViewType() to allow the...
[wxWidgets.git] / src / msw / font.cpp
index 54ef9aced840e1700b153be9ca7939e08dfd581a..4fcafbeb96f444da105ee5b84687b301e18cae81 100644 (file)
 #endif
 
 #ifndef WX_PRECOMP
 #endif
 
 #ifndef WX_PRECOMP
-    #include <stdio.h>
     #include "wx/setup.h"
     #include "wx/list.h"
     #include "wx/utils.h"
     #include "wx/app.h"
     #include "wx/font.h"
     #include "wx/setup.h"
     #include "wx/list.h"
     #include "wx/utils.h"
     #include "wx/app.h"
     #include "wx/font.h"
+    #include "wx/log.h"
 #endif // WX_PRECOMP
 
 #endif // WX_PRECOMP
 
+#include "wx/fontutil.h"
+
 #include "wx/msw/private.h"
 
 #include "wx/msw/private.h"
 
-    IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
+IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
+
+// ----------------------------------------------------------------------------
+// constants
+// ----------------------------------------------------------------------------
 
 
-    #if wxUSE_PORTABLE_FONTS_IN_MSW
-        IMPLEMENT_DYNAMIC_CLASS(wxFontNameDirectory, wxObject)
-    #endif
+// the default font size in points
+static const int wxDEFAULT_FONT_SIZE = 12;
 
 // ----------------------------------------------------------------------------
 // wxFontRefData - the internal description of the font
 
 // ----------------------------------------------------------------------------
 // wxFontRefData - the internal description of the font
@@ -56,7 +61,7 @@ friend class WXDLLEXPORT wxFont;
 public:
     wxFontRefData()
     {
 public:
     wxFontRefData()
     {
-        Init(12, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE,
+        Init(wxDEFAULT_FONT_SIZE, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE,
              "", wxFONTENCODING_DEFAULT);
     }
 
              "", wxFONTENCODING_DEFAULT);
     }
 
@@ -147,7 +152,7 @@ wxFontRefData::~wxFontRefData()
     {
         if ( !::DeleteObject((HFONT) m_hFont) )
         {
     {
         if ( !::DeleteObject((HFONT) m_hFont) )
         {
-            wxLogLastError("DeleteObject(font)");
+            wxLogLastError(wxT("DeleteObject(font)"));
         }
     }
 }
         }
     }
 }
@@ -162,6 +167,19 @@ void wxFont::Init()
         wxTheFontList->Append(this);
 }
 
         wxTheFontList->Append(this);
 }
 
+bool wxFont::Create(const wxNativeFontInfo& info)
+{
+    return Create(info.pointSize, info.family, info.style, info.weight,
+                  info.underlined, info.faceName, info.encoding);
+}
+
+wxFont::wxFont(const wxString& fontdesc)
+{
+    wxNativeFontInfo info;
+    if ( info.FromString(fontdesc) )
+        (void)Create(info);
+}
+
 /* Constructor for a font. Note that the real construction is done
  * in wxDC::SetFont, when information is available about scaling etc.
  */
 /* Constructor for a font. Note that the real construction is done
  * in wxDC::SetFont, when information is available about scaling etc.
  */
@@ -174,6 +192,12 @@ bool wxFont::Create(int pointSize,
                     wxFontEncoding encoding)
 {
     UnRef();
                     wxFontEncoding encoding)
 {
     UnRef();
+
+    // wxDEFAULT is a valid value for the font size too so we must treat it
+    // specially here (otherwise the size would be 70 == wxDEFAULT value)
+    if ( pointSize == wxDEFAULT )
+        pointSize = wxDEFAULT_FONT_SIZE;
+
     m_refData = new wxFontRefData(pointSize, family, style, weight,
                                   underlined, faceName, encoding);
 
     m_refData = new wxFontRefData(pointSize, family, style, weight,
                                   underlined, faceName, encoding);
 
@@ -207,7 +231,7 @@ bool wxFont::RealizeResource()
     M_FONTDATA->m_faceName = lf.lfFaceName;
     if ( !M_FONTDATA->m_hFont )
     {
     M_FONTDATA->m_faceName = lf.lfFaceName;
     if ( !M_FONTDATA->m_hFont )
     {
-        wxLogLastError("CreateFont");
+        wxLogLastError(wxT("CreateFont"));
 
         return FALSE;
     }
 
         return FALSE;
     }
@@ -221,7 +245,7 @@ bool wxFont::FreeResource(bool force)
     {
         if ( !::DeleteObject((HFONT) M_FONTDATA->m_hFont) )
         {
     {
         if ( !::DeleteObject((HFONT) M_FONTDATA->m_hFont) )
         {
-            wxLogLastError("DeleteObject(font)");
+            wxLogLastError(wxT("DeleteObject(font)"));
         }
 
         M_FONTDATA->m_hFont = 0;
         }
 
         M_FONTDATA->m_hFont = 0;
@@ -232,6 +256,11 @@ bool wxFont::FreeResource(bool force)
 }
 
 WXHANDLE wxFont::GetResourceHandle()
 }
 
 WXHANDLE wxFont::GetResourceHandle()
+{
+    return GetHFONT();
+}
+
+WXHFONT wxFont::GetHFONT() const
 {
     if ( !M_FONTDATA )
         return 0;
 {
     if ( !M_FONTDATA )
         return 0;