Merge branch 'font-fixes'
Complete support for fractional point sizes and font weights other than light/bold. Also harmonize wxFont API and implementation among all ports (fixing compilation of those of them that were broken by recent changes). See https://github.com/wxWidgets/wxWidgets/pull/919
This commit is contained in:
7
configure
vendored
7
configure
vendored
@@ -38299,6 +38299,9 @@ $as_echo "$wx_cv_lib_gdiplus" >&6; }
|
|||||||
if test "$wx_cv_lib_gdiplus" = "yes"; then
|
if test "$wx_cv_lib_gdiplus" = "yes"; then
|
||||||
wx_has_graphics=1
|
wx_has_graphics=1
|
||||||
fi
|
fi
|
||||||
|
elif test "$WXGTK1" = "1"; then
|
||||||
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: wxGraphicsContext not supported with GTK +1" >&5
|
||||||
|
$as_echo "$as_me: WARNING: wxGraphicsContext not supported with GTK +1" >&2;}
|
||||||
elif test "$wxUSE_GTK" = 1 -o "$wxUSE_QT" = 1 -o "$wxUSE_X11" = 1; then
|
elif test "$wxUSE_GTK" = 1 -o "$wxUSE_QT" = 1 -o "$wxUSE_X11" = 1; then
|
||||||
|
|
||||||
pkg_failed=no
|
pkg_failed=no
|
||||||
@@ -38972,6 +38975,10 @@ case ".$ac_cv_cxxflags_gcc_option__Woverloaded_virtual" in
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
if test "$WXGTK1" = "1"; then
|
||||||
|
CXXWARNINGS="$CXXWARNINGS -Wno-deprecated-declarations -Wno-narrowing -Wno-write-strings"
|
||||||
|
fi
|
||||||
|
|
||||||
if test "$WXGTK4" != 1 -a \( "$WXGTK3" = 1 -o "$wxUSE_MAC" = 1 \) ; then
|
if test "$WXGTK4" != 1 -a \( "$WXGTK3" = 1 -o "$wxUSE_MAC" = 1 \) ; then
|
||||||
CXXWARNINGS="$CXXWARNINGS -Wno-deprecated-declarations"
|
CXXWARNINGS="$CXXWARNINGS -Wno-deprecated-declarations"
|
||||||
|
|
||||||
|
@@ -7518,6 +7518,8 @@ if test "$wxUSE_GRAPHICS_CONTEXT" = "yes"; then
|
|||||||
if test "$wx_cv_lib_gdiplus" = "yes"; then
|
if test "$wx_cv_lib_gdiplus" = "yes"; then
|
||||||
wx_has_graphics=1
|
wx_has_graphics=1
|
||||||
fi
|
fi
|
||||||
|
elif test "$WXGTK1" = "1"; then
|
||||||
|
AC_MSG_WARN([wxGraphicsContext not supported with GTK +1])
|
||||||
elif test "$wxUSE_GTK" = 1 -o "$wxUSE_QT" = 1 -o "$wxUSE_X11" = 1; then
|
elif test "$wxUSE_GTK" = 1 -o "$wxUSE_QT" = 1 -o "$wxUSE_X11" = 1; then
|
||||||
PKG_CHECK_MODULES(CAIRO, cairo,
|
PKG_CHECK_MODULES(CAIRO, cairo,
|
||||||
[wx_has_graphics=1],
|
[wx_has_graphics=1],
|
||||||
@@ -7867,6 +7869,13 @@ elif test "$GXX" = yes ; then
|
|||||||
CXXWARNINGS="-Wall -Wundef -Wunused-parameter -Wno-ctor-dtor-privacy"
|
CXXWARNINGS="-Wall -Wundef -Wunused-parameter -Wno-ctor-dtor-privacy"
|
||||||
AX_CXXFLAGS_GCC_OPTION(-Woverloaded-virtual, CXXWARNINGS)
|
AX_CXXFLAGS_GCC_OPTION(-Woverloaded-virtual, CXXWARNINGS)
|
||||||
|
|
||||||
|
dnl there are tons of warnings when building with GTK+ 1 which are never
|
||||||
|
dnl going to get fixed, so disable them to at least see new warnings/errors
|
||||||
|
dnl more clearly
|
||||||
|
if test "$WXGTK1" = "1"; then
|
||||||
|
CXXWARNINGS="$CXXWARNINGS -Wno-deprecated-declarations -Wno-narrowing -Wno-write-strings"
|
||||||
|
fi
|
||||||
|
|
||||||
dnl when building using GTK+ 3 or Cocoa we currently get tons of deprecation
|
dnl when building using GTK+ 3 or Cocoa we currently get tons of deprecation
|
||||||
dnl warnings from the standard headers -- disable them as we already know
|
dnl warnings from the standard headers -- disable them as we already know
|
||||||
dnl that they're deprecated but we still have to use them to support older
|
dnl that they're deprecated but we still have to use them to support older
|
||||||
|
@@ -104,6 +104,8 @@ All (GUI):
|
|||||||
|
|
||||||
- wxAdvanced library was merged into wxCore, simply remove all references
|
- wxAdvanced library was merged into wxCore, simply remove all references
|
||||||
to "adv" from your build system, it is not needed any longer.
|
to "adv" from your build system, it is not needed any longer.
|
||||||
|
- Add support for non-integer font sizes (e.g. 10.5pt fonts).
|
||||||
|
- Add support for font weights in 1..1000 interval and not just light/bold.
|
||||||
- Add wxDataViewToggleRenderer::ShowAsRadio().
|
- Add wxDataViewToggleRenderer::ShowAsRadio().
|
||||||
- Improve stock items consistency and aesthetics (dhowland).
|
- Improve stock items consistency and aesthetics (dhowland).
|
||||||
- Fix bug with missing items in overflowing AUI toolbar (Maarten Bent).
|
- Fix bug with missing items in overflowing AUI toolbar (Maarten Bent).
|
||||||
@@ -117,6 +119,7 @@ All (GUI):
|
|||||||
- Allow distinguishing between user- and script-opened windows in wxWebView.
|
- Allow distinguishing between user- and script-opened windows in wxWebView.
|
||||||
- Allow binding to events generated by their items in submenus too.
|
- Allow binding to events generated by their items in submenus too.
|
||||||
- Add wxGrid::SetCornerLabelValue() (Pavel Kalugin).
|
- Add wxGrid::SetCornerLabelValue() (Pavel Kalugin).
|
||||||
|
- Add strikethrough support for fonts defined in XRC.
|
||||||
|
|
||||||
wxGTK:
|
wxGTK:
|
||||||
|
|
||||||
|
@@ -403,19 +403,28 @@ and can be one of the following "sub-properties":
|
|||||||
|
|
||||||
@beginTable
|
@beginTable
|
||||||
@hdr3col{property, type, description}
|
@hdr3col{property, type, description}
|
||||||
@row3col{size, unsigned integer,
|
@row3col{size, float,
|
||||||
Pixel size of the font (default: wxNORMAL_FONT's size or @c sysfont's
|
Pixel size of the font (default: wxNORMAL_FONT's size or @c sysfont's
|
||||||
size if the @c sysfont property is used or the current size of the font
|
size if the @c sysfont property is used or the current size of the font
|
||||||
of the enclosing control if the @c inherit property is used.}
|
of the enclosing control if the @c inherit property is used. Note that
|
||||||
|
versions of wxWidgets until 3.1.2 only supported integer values for the
|
||||||
|
font size.}
|
||||||
@row3col{style, enum,
|
@row3col{style, enum,
|
||||||
One of "normal", "italic" or "slant" (default: normal).}
|
One of "normal", "italic" or "slant" (default: normal).}
|
||||||
@row3col{weight, enum,
|
@row3col{weight, enum or integer,
|
||||||
One of "normal", "bold" or "light" (default: normal).}
|
One of "thin", "extralight", "light", "normal", "medium", "semibold",
|
||||||
|
"bold", "extrabold", "heavy", "extraheavy", corresponding to the similarly
|
||||||
|
named elements of ::wxFontWeight enum, or a numeric value between 1 and
|
||||||
|
1000 (default: normal). Note that versions of wxWidgets until 3.1.2 only
|
||||||
|
supported "light", "normal" and "bold" values for weight.}
|
||||||
@row3col{family, enum,
|
@row3col{family, enum,
|
||||||
One of "default", "roman", "script", "decorative", "swiss", "modern" or "teletype"
|
One of "default", "roman", "script", "decorative", "swiss", "modern" or "teletype"
|
||||||
(default: default).}
|
(default: default).}
|
||||||
@row3col{underlined, @ref overview_xrcformat_type_bool,
|
@row3col{underlined, @ref overview_xrcformat_type_bool,
|
||||||
Whether the font should be underlined (default: 0).}
|
Whether the font should be underlined (default: 0).}
|
||||||
|
@row3col{strikethrough, @ref overview_xrcformat_type_bool,
|
||||||
|
Whether the strikethrough font should be used (default: 0). This property
|
||||||
|
is only supported since wxWidgets 3.1.2.}
|
||||||
@row3col{face, ,
|
@row3col{face, ,
|
||||||
Comma-separated list of face names; the first one available is used
|
Comma-separated list of face names; the first one available is used
|
||||||
(default: unspecified).}
|
(default: unspecified).}
|
||||||
|
@@ -72,19 +72,19 @@ public:
|
|||||||
bool Create(const wxNativeFontInfo& fontinfo);
|
bool Create(const wxNativeFontInfo& fontinfo);
|
||||||
|
|
||||||
// implement base class pure virtuals
|
// implement base class pure virtuals
|
||||||
virtual int GetPointSize() const;
|
virtual float GetFractionalPointSize() const;
|
||||||
virtual wxFontStyle GetStyle() const;
|
virtual wxFontStyle GetStyle() const;
|
||||||
virtual wxFontWeight GetWeight() const;
|
virtual int GetNumericWeight() const;
|
||||||
virtual wxString GetFaceName() const;
|
virtual wxString GetFaceName() const;
|
||||||
virtual bool GetUnderlined() const;
|
virtual bool GetUnderlined() const;
|
||||||
virtual wxFontEncoding GetEncoding() const;
|
virtual wxFontEncoding GetEncoding() const;
|
||||||
virtual bool IsFixedWidth() const;
|
virtual bool IsFixedWidth() const;
|
||||||
virtual const wxNativeFontInfo *GetNativeFontInfo() const;
|
virtual const wxNativeFontInfo *GetNativeFontInfo() const;
|
||||||
|
|
||||||
virtual void SetPointSize(int pointSize);
|
virtual void SetFractionalPointSize(float pointSize);
|
||||||
virtual void SetFamily(wxFontFamily family);
|
virtual void SetFamily(wxFontFamily family);
|
||||||
virtual void SetStyle(wxFontStyle style);
|
virtual void SetStyle(wxFontStyle style);
|
||||||
virtual void SetWeight(wxFontWeight weight);
|
virtual void SetNumericWeight(int weight);
|
||||||
virtual bool SetFaceName(const wxString& faceName);
|
virtual bool SetFaceName(const wxString& faceName);
|
||||||
virtual void SetUnderlined(bool underlined);
|
virtual void SetUnderlined(bool underlined);
|
||||||
virtual void SetEncoding(wxFontEncoding encoding);
|
virtual void SetEncoding(wxFontEncoding encoding);
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
#include "wx/fontenc.h" // the font encoding constants
|
#include "wx/fontenc.h" // the font encoding constants
|
||||||
#include "wx/gdiobj.h" // the base class
|
#include "wx/gdiobj.h" // the base class
|
||||||
#include "wx/gdicmn.h" // for wxGDIObjListBase
|
#include "wx/gdicmn.h" // for wxGDIObjListBase
|
||||||
|
#include "wx/math.h" // for wxRound()
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// forward declarations
|
// forward declarations
|
||||||
@@ -95,7 +96,7 @@ enum wxFontFlag
|
|||||||
wxFONTFLAG_ITALIC = 1 << 0,
|
wxFONTFLAG_ITALIC = 1 << 0,
|
||||||
wxFONTFLAG_SLANT = 1 << 1,
|
wxFONTFLAG_SLANT = 1 << 1,
|
||||||
|
|
||||||
// weight flags (default: medium)
|
// weight flags (default: medium):
|
||||||
wxFONTFLAG_LIGHT = 1 << 2,
|
wxFONTFLAG_LIGHT = 1 << 2,
|
||||||
wxFONTFLAG_BOLD = 1 << 3,
|
wxFONTFLAG_BOLD = 1 << 3,
|
||||||
|
|
||||||
@@ -128,14 +129,23 @@ public:
|
|||||||
// Default ctor uses the default font size appropriate for the current
|
// Default ctor uses the default font size appropriate for the current
|
||||||
// platform.
|
// platform.
|
||||||
wxFontInfo()
|
wxFontInfo()
|
||||||
{ InitPointSize(-1); }
|
{ InitPointSize(-1.0f); }
|
||||||
|
|
||||||
// These ctors specify the font size, either in points or in pixels.
|
// These ctors specify the font size, either in points or in pixels.
|
||||||
explicit wxFontInfo(int pointSize)
|
// Point size is a floating point number, however we also accept all
|
||||||
|
// integer sizes using the simple template ctor below.
|
||||||
|
explicit wxFontInfo(float pointSize)
|
||||||
{ InitPointSize(pointSize); }
|
{ InitPointSize(pointSize); }
|
||||||
explicit wxFontInfo(const wxSize& pixelSize) : m_pixelSize(pixelSize)
|
explicit wxFontInfo(const wxSize& pixelSize) : m_pixelSize(pixelSize)
|
||||||
{ Init(); }
|
{ Init(); }
|
||||||
|
|
||||||
|
// Need to define this one to avoid casting double to int too.
|
||||||
|
explicit wxFontInfo(double pointSize)
|
||||||
|
{ InitPointSize(pointSize); }
|
||||||
|
template <typename T>
|
||||||
|
explicit wxFontInfo(T pointSize)
|
||||||
|
{ InitPointSize(ToFloatPointSize(pointSize)); }
|
||||||
|
|
||||||
// Setters for the various attributes. All of them return the object itself
|
// Setters for the various attributes. All of them return the object itself
|
||||||
// so that the calls to them could be chained.
|
// so that the calls to them could be chained.
|
||||||
wxFontInfo& Family(wxFontFamily family)
|
wxFontInfo& Family(wxFontFamily family)
|
||||||
@@ -143,15 +153,27 @@ public:
|
|||||||
wxFontInfo& FaceName(const wxString& faceName)
|
wxFontInfo& FaceName(const wxString& faceName)
|
||||||
{ m_faceName = faceName; return *this; }
|
{ m_faceName = faceName; return *this; }
|
||||||
|
|
||||||
|
wxFontInfo& Weight(int weight)
|
||||||
|
{ m_weight = weight; return *this; }
|
||||||
wxFontInfo& Bold(bool bold = true)
|
wxFontInfo& Bold(bool bold = true)
|
||||||
{ SetFlag(wxFONTFLAG_BOLD, bold); return *this; }
|
{ return Weight(bold ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL); }
|
||||||
wxFontInfo& Light(bool light = true)
|
wxFontInfo& Light(bool light = true)
|
||||||
{ SetFlag(wxFONTFLAG_LIGHT, light); return *this; }
|
{ return Weight(light ? wxFONTWEIGHT_LIGHT : wxFONTWEIGHT_NORMAL); }
|
||||||
|
|
||||||
wxFontInfo& Italic(bool italic = true)
|
wxFontInfo& Italic(bool italic = true)
|
||||||
{ SetFlag(wxFONTFLAG_ITALIC, italic); return *this; }
|
{ SetFlag(wxFONTFLAG_ITALIC, italic); return *this; }
|
||||||
wxFontInfo& Slant(bool slant = true)
|
wxFontInfo& Slant(bool slant = true)
|
||||||
{ SetFlag(wxFONTFLAG_SLANT, slant); return *this; }
|
{ SetFlag(wxFONTFLAG_SLANT, slant); return *this; }
|
||||||
|
wxFontInfo& Style(wxFontStyle style)
|
||||||
|
{
|
||||||
|
if ( style == wxFONTSTYLE_ITALIC )
|
||||||
|
return Italic();
|
||||||
|
|
||||||
|
if ( style == wxFONTSTYLE_SLANT )
|
||||||
|
return Slant();
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
wxFontInfo& AntiAliased(bool antiAliased = true)
|
wxFontInfo& AntiAliased(bool antiAliased = true)
|
||||||
{ SetFlag(wxFONTFLAG_ANTIALIASED, antiAliased); return *this; }
|
{ SetFlag(wxFONTFLAG_ANTIALIASED, antiAliased); return *this; }
|
||||||
@@ -166,15 +188,29 @@ public:
|
|||||||
|
|
||||||
// Set all flags at once.
|
// Set all flags at once.
|
||||||
wxFontInfo& AllFlags(int flags)
|
wxFontInfo& AllFlags(int flags)
|
||||||
{ m_flags = flags; return *this; }
|
{
|
||||||
|
m_flags = flags;
|
||||||
|
|
||||||
|
m_weight = m_flags & wxFONTFLAG_BOLD
|
||||||
|
? wxFONTWEIGHT_BOLD
|
||||||
|
: m_flags & wxFONTFLAG_LIGHT
|
||||||
|
? wxFONTWEIGHT_LIGHT
|
||||||
|
: wxFONTWEIGHT_NORMAL;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Accessors are mostly meant to be used by wxFont itself to extract the
|
// Accessors are mostly meant to be used by wxFont itself to extract the
|
||||||
// various pieces of the font description.
|
// various pieces of the font description.
|
||||||
|
|
||||||
bool IsUsingSizeInPixels() const { return m_pixelSize != wxDefaultSize; }
|
bool IsUsingSizeInPixels() const { return m_pixelSize != wxDefaultSize; }
|
||||||
int GetPointSize() const { return m_pointSize; }
|
float GetFractionalPointSize() const { return m_pointSize; }
|
||||||
|
int GetPointSize() const { return ToIntPointSize(m_pointSize); }
|
||||||
wxSize GetPixelSize() const { return m_pixelSize; }
|
wxSize GetPixelSize() const { return m_pixelSize; }
|
||||||
|
|
||||||
|
// If face name is not empty, it has priority, otherwise use family.
|
||||||
|
bool HasFaceName() const { return !m_faceName.empty(); }
|
||||||
wxFontFamily GetFamily() const { return m_family; }
|
wxFontFamily GetFamily() const { return m_family; }
|
||||||
const wxString& GetFaceName() const { return m_faceName; }
|
const wxString& GetFaceName() const { return m_faceName; }
|
||||||
|
|
||||||
@@ -187,13 +223,14 @@ public:
|
|||||||
: wxFONTSTYLE_NORMAL;
|
: wxFONTSTYLE_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int GetNumericWeight() const
|
||||||
|
{
|
||||||
|
return m_weight;
|
||||||
|
}
|
||||||
|
|
||||||
wxFontWeight GetWeight() const
|
wxFontWeight GetWeight() const
|
||||||
{
|
{
|
||||||
return m_flags & wxFONTFLAG_LIGHT
|
return GetWeightClosestToNumericValue(m_weight);
|
||||||
? wxFONTWEIGHT_LIGHT
|
|
||||||
: m_flags & wxFONTFLAG_BOLD
|
|
||||||
? wxFONTWEIGHT_BOLD
|
|
||||||
: wxFONTWEIGHT_NORMAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsAntiAliased() const
|
bool IsAntiAliased() const
|
||||||
@@ -216,16 +253,57 @@ public:
|
|||||||
|
|
||||||
// Default copy ctor, assignment operator and dtor are OK.
|
// Default copy ctor, assignment operator and dtor are OK.
|
||||||
|
|
||||||
|
|
||||||
|
// Helper functions for converting between integer and fractional sizes.
|
||||||
|
static int ToIntPointSize(float pointSize) { return wxRound(pointSize); }
|
||||||
|
static float ToFloatPointSize(int pointSize)
|
||||||
|
{
|
||||||
|
wxCHECK_MSG( pointSize == -1 || pointSize >= 0,
|
||||||
|
-1, "Invalid font point size" );
|
||||||
|
|
||||||
|
// Huge values are not exactly representable as floats, so don't accept
|
||||||
|
// those neither as they can only be due to a mistake anyhow: nobody
|
||||||
|
// could possibly need a font of size 16777217pt (which is the first
|
||||||
|
// value for which this fails).
|
||||||
|
const float f = static_cast<float>(pointSize);
|
||||||
|
wxCHECK_MSG( static_cast<int>(f) == pointSize,
|
||||||
|
-1, "Font point size out of range" );
|
||||||
|
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Another helper for converting arbitrary numeric weight to the closest
|
||||||
|
// value of wxFontWeight enum. It should be avoided in the new code (also
|
||||||
|
// note that the function for the conversion in the other direction is
|
||||||
|
// trivial and so is not provided, we only have GetNumericWeightOf() which
|
||||||
|
// contains backwards compatibility hacks, but we don't need it here).
|
||||||
|
static wxFontWeight GetWeightClosestToNumericValue(int numWeight)
|
||||||
|
{
|
||||||
|
wxASSERT(numWeight > 0);
|
||||||
|
wxASSERT(numWeight <= 1000);
|
||||||
|
|
||||||
|
// round to nearest hundredth = wxFONTWEIGHT_ constant
|
||||||
|
int weight = ((numWeight + 50) / 100) * 100;
|
||||||
|
|
||||||
|
if (weight < wxFONTWEIGHT_THIN)
|
||||||
|
weight = wxFONTWEIGHT_THIN;
|
||||||
|
if (weight > wxFONTWEIGHT_MAX)
|
||||||
|
weight = wxFONTWEIGHT_MAX;
|
||||||
|
|
||||||
|
return static_cast<wxFontWeight>(weight);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
m_pointSize = -1;
|
m_pointSize = -1;
|
||||||
m_family = wxFONTFAMILY_DEFAULT;
|
m_family = wxFONTFAMILY_DEFAULT;
|
||||||
m_flags = wxFONTFLAG_DEFAULT;
|
m_flags = wxFONTFLAG_DEFAULT;
|
||||||
|
m_weight = wxFONTWEIGHT_NORMAL;
|
||||||
m_encoding = wxFONTENCODING_DEFAULT;
|
m_encoding = wxFONTENCODING_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitPointSize(int pointSize)
|
void InitPointSize(float pointSize)
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
|
|
||||||
@@ -244,15 +322,15 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The size information: if m_pixelSize is valid (!= wxDefaultSize), then
|
// The size information: if m_pixelSize is valid (!= wxDefaultSize), then
|
||||||
// it is used. Otherwise m_pointSize is used, taking into account that if
|
// it is used. Otherwise m_pointSize is used, except if it is < 0, which
|
||||||
// it is == -1, it means that the platform dependent font size should be
|
// means that the platform dependent font size should be used instead.
|
||||||
// used.
|
float m_pointSize;
|
||||||
int m_pointSize;
|
|
||||||
wxSize m_pixelSize;
|
wxSize m_pixelSize;
|
||||||
|
|
||||||
wxFontFamily m_family;
|
wxFontFamily m_family;
|
||||||
wxString m_faceName;
|
wxString m_faceName;
|
||||||
int m_flags;
|
int m_flags;
|
||||||
|
int m_weight;
|
||||||
wxFontEncoding m_encoding;
|
wxFontEncoding m_encoding;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -352,7 +430,6 @@ public:
|
|||||||
virtual bool IsUsingSizeInPixels() const;
|
virtual bool IsUsingSizeInPixels() const;
|
||||||
wxFontFamily GetFamily() const;
|
wxFontFamily GetFamily() const;
|
||||||
virtual wxFontStyle GetStyle() const = 0;
|
virtual wxFontStyle GetStyle() const = 0;
|
||||||
virtual wxFontWeight GetWeight() const = 0;
|
|
||||||
virtual int GetNumericWeight() const = 0;
|
virtual int GetNumericWeight() const = 0;
|
||||||
virtual bool GetUnderlined() const = 0;
|
virtual bool GetUnderlined() const = 0;
|
||||||
virtual bool GetStrikethrough() const { return false; }
|
virtual bool GetStrikethrough() const { return false; }
|
||||||
@@ -360,17 +437,20 @@ public:
|
|||||||
virtual wxFontEncoding GetEncoding() const = 0;
|
virtual wxFontEncoding GetEncoding() const = 0;
|
||||||
virtual const wxNativeFontInfo *GetNativeFontInfo() const = 0;
|
virtual const wxNativeFontInfo *GetNativeFontInfo() const = 0;
|
||||||
|
|
||||||
|
// Accessors that can be overridden in the platform-specific code but for
|
||||||
|
// which we provide a reasonable default implementation in the base class.
|
||||||
|
virtual wxFontWeight GetWeight() const;
|
||||||
virtual bool IsFixedWidth() const;
|
virtual bool IsFixedWidth() const;
|
||||||
|
|
||||||
wxString GetNativeFontInfoDesc() const;
|
wxString GetNativeFontInfoDesc() const;
|
||||||
wxString GetNativeFontInfoUserDesc() const;
|
wxString GetNativeFontInfoUserDesc() const;
|
||||||
|
|
||||||
// change the font characteristics
|
// change the font characteristics
|
||||||
virtual void SetPointSize( float pointSize ) = 0;
|
virtual void SetPointSize( int pointSize );
|
||||||
|
virtual void SetFractionalPointSize( float pointSize ) = 0;
|
||||||
virtual void SetPixelSize( const wxSize& pixelSize );
|
virtual void SetPixelSize( const wxSize& pixelSize );
|
||||||
virtual void SetFamily( wxFontFamily family ) = 0;
|
virtual void SetFamily( wxFontFamily family ) = 0;
|
||||||
virtual void SetStyle( wxFontStyle style ) = 0;
|
virtual void SetStyle( wxFontStyle style ) = 0;
|
||||||
virtual void SetWeight( wxFontWeight weight ) = 0;
|
|
||||||
virtual void SetNumericWeight( int weight ) = 0;
|
virtual void SetNumericWeight( int weight ) = 0;
|
||||||
|
|
||||||
virtual void SetUnderlined( bool underlined ) = 0;
|
virtual void SetUnderlined( bool underlined ) = 0;
|
||||||
@@ -380,6 +460,10 @@ public:
|
|||||||
void SetNativeFontInfo(const wxNativeFontInfo& info)
|
void SetNativeFontInfo(const wxNativeFontInfo& info)
|
||||||
{ DoSetNativeFontInfo(info); }
|
{ DoSetNativeFontInfo(info); }
|
||||||
|
|
||||||
|
// Similarly to the accessors above, the functions in this group have a
|
||||||
|
// reasonable default implementation in the base class.
|
||||||
|
virtual void SetWeight( wxFontWeight weight );
|
||||||
|
|
||||||
bool SetNativeFontInfo(const wxString& info);
|
bool SetNativeFontInfo(const wxString& info);
|
||||||
bool SetNativeFontInfoUserDesc(const wxString& info);
|
bool SetNativeFontInfoUserDesc(const wxString& info);
|
||||||
|
|
||||||
@@ -407,12 +491,30 @@ public:
|
|||||||
static wxFontEncoding GetDefaultEncoding() { return ms_encodingDefault; }
|
static wxFontEncoding GetDefaultEncoding() { return ms_encodingDefault; }
|
||||||
static void SetDefaultEncoding(wxFontEncoding encoding);
|
static void SetDefaultEncoding(wxFontEncoding encoding);
|
||||||
|
|
||||||
|
// Account for legacy font weight values: if the argument is one of
|
||||||
|
// wxNORMAL, wxLIGHT or wxBOLD, return the corresponding wxFONTWEIGHT_XXX
|
||||||
|
// enum value. Otherwise just return it unchanged.
|
||||||
|
static int ConvertFromLegacyWeightIfNecessary(int weight);
|
||||||
|
|
||||||
|
// Convert between symbolic and numeric font weights. This function uses
|
||||||
|
// ConvertFromLegacyWeightIfNecessary(), so takes legacy values into
|
||||||
|
// account as well.
|
||||||
|
static int GetNumericWeightOf(wxFontWeight weight);
|
||||||
|
|
||||||
// this doesn't do anything and is kept for compatibility only
|
// this doesn't do anything and is kept for compatibility only
|
||||||
#if WXWIN_COMPATIBILITY_2_8
|
#if WXWIN_COMPATIBILITY_2_8
|
||||||
wxDEPRECATED_INLINE(void SetNoAntiAliasing(bool no = true), wxUnusedVar(no);)
|
wxDEPRECATED_INLINE(void SetNoAntiAliasing(bool no = true), wxUnusedVar(no);)
|
||||||
wxDEPRECATED_INLINE(bool GetNoAntiAliasing() const, return false;)
|
wxDEPRECATED_INLINE(bool GetNoAntiAliasing() const, return false;)
|
||||||
#endif // WXWIN_COMPATIBILITY_2_8
|
#endif // WXWIN_COMPATIBILITY_2_8
|
||||||
|
|
||||||
|
wxDEPRECATED_MSG("use wxFONTWEIGHT_XXX constants instead of raw values")
|
||||||
|
void SetWeight(int weight)
|
||||||
|
{ SetWeight(static_cast<wxFontWeight>(weight)); }
|
||||||
|
|
||||||
|
wxDEPRECATED_MSG("use wxFONTWEIGHT_XXX constants instead of wxLIGHT/wxNORMAL/wxBOLD")
|
||||||
|
void SetWeight(wxDeprecatedGUIConstants weight)
|
||||||
|
{ SetWeight(static_cast<wxFontWeight>(weight)); }
|
||||||
|
|
||||||
// from the font components
|
// from the font components
|
||||||
wxDEPRECATED_MSG("use wxFONT{FAMILY,STYLE,WEIGHT}_XXX constants")
|
wxDEPRECATED_MSG("use wxFONT{FAMILY,STYLE,WEIGHT}_XXX constants")
|
||||||
static wxFont *New(
|
static wxFont *New(
|
||||||
@@ -479,6 +581,26 @@ protected:
|
|||||||
return (flags & wxFONTFLAG_STRIKETHROUGH) != 0;
|
return (flags & wxFONTFLAG_STRIKETHROUGH) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create wxFontInfo object from the parameters passed to the legacy wxFont
|
||||||
|
// ctor/Create() overload. This function implements the compatibility hack
|
||||||
|
// which interprets wxDEFAULT value of size as meaning -1 and also supports
|
||||||
|
// specifying wxNORMAL, wxLIGHT and wxBOLD as weight values.
|
||||||
|
static wxFontInfo InfoFromLegacyParams(int pointSize,
|
||||||
|
wxFontFamily family,
|
||||||
|
wxFontStyle style,
|
||||||
|
wxFontWeight weight,
|
||||||
|
bool underlined,
|
||||||
|
const wxString& face,
|
||||||
|
wxFontEncoding encoding);
|
||||||
|
|
||||||
|
static wxFontInfo InfoFromLegacyParams(const wxSize& pixelSize,
|
||||||
|
wxFontFamily family,
|
||||||
|
wxFontStyle style,
|
||||||
|
wxFontWeight weight,
|
||||||
|
bool underlined,
|
||||||
|
const wxString& face,
|
||||||
|
wxFontEncoding encoding);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// the currently default encoding: by default, it's the default system
|
// the currently default encoding: by default, it's the default system
|
||||||
// encoding, but may be changed by the application using
|
// encoding, but may be changed by the application using
|
||||||
@@ -500,18 +622,12 @@ WXDLLIMPEXP_CORE bool wxFromString(const wxString& str, wxFontBase* font);
|
|||||||
wxDEPRECATED_MSG("use wxFONTSTYLE_XXX constants") \
|
wxDEPRECATED_MSG("use wxFONTSTYLE_XXX constants") \
|
||||||
void SetStyle(int style) \
|
void SetStyle(int style) \
|
||||||
{ SetStyle((wxFontStyle)style); } \
|
{ SetStyle((wxFontStyle)style); } \
|
||||||
wxDEPRECATED_MSG("use wxFONTWEIGHT_XXX constants") \
|
|
||||||
void SetWeight(int weight) \
|
|
||||||
{ SetWeight((wxFontWeight)weight); } \
|
|
||||||
wxDEPRECATED_MSG("use wxFONTFAMILY_XXX constants") \
|
wxDEPRECATED_MSG("use wxFONTFAMILY_XXX constants") \
|
||||||
void SetFamily(wxDeprecatedGUIConstants family) \
|
void SetFamily(wxDeprecatedGUIConstants family) \
|
||||||
{ SetFamily((wxFontFamily)family); } \
|
{ SetFamily((wxFontFamily)family); } \
|
||||||
wxDEPRECATED_MSG("use wxFONTSTYLE_XXX constants") \
|
wxDEPRECATED_MSG("use wxFONTSTYLE_XXX constants") \
|
||||||
void SetStyle(wxDeprecatedGUIConstants style) \
|
void SetStyle(wxDeprecatedGUIConstants style) \
|
||||||
{ SetStyle((wxFontStyle)style); } \
|
{ SetStyle((wxFontStyle)style); } \
|
||||||
wxDEPRECATED_MSG("use wxFONTWEIGHT_XXX constants") \
|
|
||||||
void SetWeight(wxDeprecatedGUIConstants weight) \
|
|
||||||
{ SetWeight((wxFontWeight)weight); } \
|
|
||||||
\
|
\
|
||||||
/* functions for modifying font in place */ \
|
/* functions for modifying font in place */ \
|
||||||
wxFont& MakeBold(); \
|
wxFont& MakeBold(); \
|
||||||
|
@@ -118,9 +118,14 @@ public:
|
|||||||
// set the XFLD
|
// set the XFLD
|
||||||
void SetXFontName(const wxString& xFontName);
|
void SetXFontName(const wxString& xFontName);
|
||||||
#elif defined(__WXMSW__)
|
#elif defined(__WXMSW__)
|
||||||
wxNativeFontInfo(const LOGFONT& lf_) : lf(lf_) { }
|
wxNativeFontInfo(const LOGFONT& lf_) : lf(lf_), pointSize(0.0f) { }
|
||||||
|
|
||||||
LOGFONT lf;
|
LOGFONT lf;
|
||||||
|
|
||||||
|
// MSW only has limited support for fractional point sizes and we need to
|
||||||
|
// store the fractional point size separately if it was initially specified
|
||||||
|
// as we can't losslessly recover it from LOGFONT later.
|
||||||
|
float pointSize;
|
||||||
#elif defined(__WXOSX__)
|
#elif defined(__WXOSX__)
|
||||||
public:
|
public:
|
||||||
wxNativeFontInfo(const wxNativeFontInfo& info) { Init(info); }
|
wxNativeFontInfo(const wxNativeFontInfo& info) { Init(info); }
|
||||||
@@ -185,10 +190,10 @@ public :
|
|||||||
//
|
//
|
||||||
#define wxNO_NATIVE_FONTINFO
|
#define wxNO_NATIVE_FONTINFO
|
||||||
|
|
||||||
int pointSize;
|
float pointSize;
|
||||||
wxFontFamily family;
|
wxFontFamily family;
|
||||||
wxFontStyle style;
|
wxFontStyle style;
|
||||||
wxFontWeight weight;
|
int weight;
|
||||||
bool underlined;
|
bool underlined;
|
||||||
bool strikethrough;
|
bool strikethrough;
|
||||||
wxString faceName;
|
wxString faceName;
|
||||||
@@ -229,16 +234,16 @@ public:
|
|||||||
#else
|
#else
|
||||||
// translate all font parameters
|
// translate all font parameters
|
||||||
SetStyle((wxFontStyle)font.GetStyle());
|
SetStyle((wxFontStyle)font.GetStyle());
|
||||||
SetWeight((wxFontWeight)font.GetWeight());
|
SetNumericWeight(font.GetNumericWeight());
|
||||||
SetUnderlined(font.GetUnderlined());
|
SetUnderlined(font.GetUnderlined());
|
||||||
SetStrikethrough(font.GetStrikethrough());
|
SetStrikethrough(font.GetStrikethrough());
|
||||||
#if defined(__WXMSW__)
|
#if defined(__WXMSW__)
|
||||||
if ( font.IsUsingSizeInPixels() )
|
if ( font.IsUsingSizeInPixels() )
|
||||||
SetPixelSize(font.GetPixelSize());
|
SetPixelSize(font.GetPixelSize());
|
||||||
else
|
else
|
||||||
SetPointSize(font.GetPointSize());
|
SetFractionalPointSize(font.GetFractionalPointSize());
|
||||||
#else
|
#else
|
||||||
SetPointSize(font.GetPointSize());
|
SetFractionalPointSize(font.GetFractionalPointSize());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// set the family/facename
|
// set the family/facename
|
||||||
@@ -268,7 +273,8 @@ public:
|
|||||||
wxFontFamily GetFamily() const;
|
wxFontFamily GetFamily() const;
|
||||||
wxFontEncoding GetEncoding() const;
|
wxFontEncoding GetEncoding() const;
|
||||||
|
|
||||||
void SetPointSize(float pointsize);
|
void SetPointSize(int pointsize);
|
||||||
|
void SetFractionalPointSize(float pointsize);
|
||||||
void SetPixelSize(const wxSize& pixelSize);
|
void SetPixelSize(const wxSize& pixelSize);
|
||||||
void SetStyle(wxFontStyle style);
|
void SetStyle(wxFontStyle style);
|
||||||
void SetNumericWeight(int weight);
|
void SetNumericWeight(int weight);
|
||||||
@@ -279,6 +285,17 @@ public:
|
|||||||
void SetFamily(wxFontFamily family);
|
void SetFamily(wxFontFamily family);
|
||||||
void SetEncoding(wxFontEncoding encoding);
|
void SetEncoding(wxFontEncoding encoding);
|
||||||
|
|
||||||
|
// Helper used in many ports: use the normal font size if the input is
|
||||||
|
// negative, as we handle -1 as meaning this for compatibility.
|
||||||
|
void SetSizeOrDefault(float size)
|
||||||
|
{
|
||||||
|
SetFractionalPointSize
|
||||||
|
(
|
||||||
|
size < 0 ? wxNORMAL_FONT->GetFractionalPointSize()
|
||||||
|
: size
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// sets the first facename in the given array which is found
|
// sets the first facename in the given array which is found
|
||||||
// to be valid. If no valid facename is given, sets the
|
// to be valid. If no valid facename is given, sets the
|
||||||
// first valid facename returned by wxFontEnumerator::GetFacenames().
|
// first valid facename returned by wxFontEnumerator::GetFacenames().
|
||||||
|
@@ -66,7 +66,6 @@ public:
|
|||||||
// implement base class pure virtuals
|
// implement base class pure virtuals
|
||||||
virtual float GetFractionalPointSize() const wxOVERRIDE;
|
virtual float GetFractionalPointSize() const wxOVERRIDE;
|
||||||
virtual wxFontStyle GetStyle() const wxOVERRIDE;
|
virtual wxFontStyle GetStyle() const wxOVERRIDE;
|
||||||
virtual wxFontWeight GetWeight() const wxOVERRIDE;
|
|
||||||
virtual int GetNumericWeight() const wxOVERRIDE;
|
virtual int GetNumericWeight() const wxOVERRIDE;
|
||||||
virtual wxString GetFaceName() const wxOVERRIDE;
|
virtual wxString GetFaceName() const wxOVERRIDE;
|
||||||
virtual bool GetUnderlined() const wxOVERRIDE;
|
virtual bool GetUnderlined() const wxOVERRIDE;
|
||||||
@@ -75,10 +74,9 @@ public:
|
|||||||
virtual const wxNativeFontInfo *GetNativeFontInfo() const wxOVERRIDE;
|
virtual const wxNativeFontInfo *GetNativeFontInfo() const wxOVERRIDE;
|
||||||
virtual bool IsFixedWidth() const wxOVERRIDE;
|
virtual bool IsFixedWidth() const wxOVERRIDE;
|
||||||
|
|
||||||
virtual void SetPointSize(float pointSize) wxOVERRIDE;
|
virtual void SetFractionalPointSize(float pointSize) wxOVERRIDE;
|
||||||
virtual void SetFamily(wxFontFamily family) wxOVERRIDE;
|
virtual void SetFamily(wxFontFamily family) wxOVERRIDE;
|
||||||
virtual void SetStyle(wxFontStyle style) wxOVERRIDE;
|
virtual void SetStyle(wxFontStyle style) wxOVERRIDE;
|
||||||
virtual void SetWeight(wxFontWeight weight) wxOVERRIDE;
|
|
||||||
virtual void SetNumericWeight(int weight) wxOVERRIDE;
|
virtual void SetNumericWeight(int weight) wxOVERRIDE;
|
||||||
virtual bool SetFaceName( const wxString& faceName ) wxOVERRIDE;
|
virtual bool SetFaceName( const wxString& faceName ) wxOVERRIDE;
|
||||||
virtual void SetUnderlined( bool underlined ) wxOVERRIDE;
|
virtual void SetUnderlined( bool underlined ) wxOVERRIDE;
|
||||||
|
@@ -90,19 +90,19 @@ public:
|
|||||||
virtual ~wxFont();
|
virtual ~wxFont();
|
||||||
|
|
||||||
// implement base class pure virtuals
|
// implement base class pure virtuals
|
||||||
virtual int GetPointSize() const;
|
virtual float GetFractionalPointSize() const;
|
||||||
virtual wxFontStyle GetStyle() const;
|
virtual wxFontStyle GetStyle() const;
|
||||||
virtual wxFontWeight GetWeight() const;
|
virtual int GetNumericWeight() const;
|
||||||
virtual wxString GetFaceName() const;
|
virtual wxString GetFaceName() const;
|
||||||
virtual bool GetUnderlined() const;
|
virtual bool GetUnderlined() const;
|
||||||
virtual wxFontEncoding GetEncoding() const;
|
virtual wxFontEncoding GetEncoding() const;
|
||||||
virtual const wxNativeFontInfo *GetNativeFontInfo() const;
|
virtual const wxNativeFontInfo *GetNativeFontInfo() const;
|
||||||
virtual bool IsFixedWidth() const;
|
virtual bool IsFixedWidth() const;
|
||||||
|
|
||||||
virtual void SetPointSize( int pointSize );
|
virtual void SetFractionalPointSize(float pointSize);
|
||||||
virtual void SetFamily(wxFontFamily family);
|
virtual void SetFamily(wxFontFamily family);
|
||||||
virtual void SetStyle(wxFontStyle style);
|
virtual void SetStyle(wxFontStyle style);
|
||||||
virtual void SetWeight(wxFontWeight weight);
|
virtual void SetNumericWeight(int weight);
|
||||||
virtual bool SetFaceName( const wxString& faceName );
|
virtual bool SetFaceName( const wxString& faceName );
|
||||||
virtual void SetUnderlined( bool underlined );
|
virtual void SetUnderlined( bool underlined );
|
||||||
virtual void SetEncoding(wxFontEncoding encoding);
|
virtual void SetEncoding(wxFontEncoding encoding);
|
||||||
|
@@ -27,19 +27,7 @@ public:
|
|||||||
// ctors and such
|
// ctors and such
|
||||||
wxFont() { }
|
wxFont() { }
|
||||||
|
|
||||||
wxFont(const wxFontInfo& info)
|
wxFont(const wxFontInfo& info);
|
||||||
{
|
|
||||||
Create(info.GetPointSize(),
|
|
||||||
info.GetFamily(),
|
|
||||||
info.GetStyle(),
|
|
||||||
info.GetWeight(),
|
|
||||||
info.IsUnderlined(),
|
|
||||||
info.GetFaceName(),
|
|
||||||
info.GetEncoding());
|
|
||||||
|
|
||||||
if ( info.IsUsingSizeInPixels() )
|
|
||||||
SetPixelSize(info.GetPixelSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
wxFont(const wxNativeFontInfo& info);
|
wxFont(const wxNativeFontInfo& info);
|
||||||
|
|
||||||
@@ -82,18 +70,18 @@ public:
|
|||||||
virtual ~wxFont();
|
virtual ~wxFont();
|
||||||
|
|
||||||
// implement base class pure virtuals
|
// implement base class pure virtuals
|
||||||
virtual int GetPointSize() const;
|
virtual float GetFractionalPointSize() const;
|
||||||
virtual wxFontStyle GetStyle() const;
|
virtual wxFontStyle GetStyle() const;
|
||||||
virtual wxFontWeight GetWeight() const;
|
virtual int GetNumericWeight() const;
|
||||||
virtual bool GetUnderlined() const;
|
virtual bool GetUnderlined() const;
|
||||||
virtual wxString GetFaceName() const;
|
virtual wxString GetFaceName() const;
|
||||||
virtual wxFontEncoding GetEncoding() const;
|
virtual wxFontEncoding GetEncoding() const;
|
||||||
virtual const wxNativeFontInfo *GetNativeFontInfo() const;
|
virtual const wxNativeFontInfo *GetNativeFontInfo() const;
|
||||||
|
|
||||||
virtual void SetPointSize(int pointSize);
|
virtual void SetFractionalPointSize(float pointSize);
|
||||||
virtual void SetFamily(wxFontFamily family);
|
virtual void SetFamily(wxFontFamily family);
|
||||||
virtual void SetStyle(wxFontStyle style);
|
virtual void SetStyle(wxFontStyle style);
|
||||||
virtual void SetWeight(wxFontWeight weight);
|
virtual void SetNumericWeight(int weight);
|
||||||
virtual bool SetFaceName(const wxString& faceName);
|
virtual bool SetFaceName(const wxString& faceName);
|
||||||
virtual void SetUnderlined(bool underlined);
|
virtual void SetUnderlined(bool underlined);
|
||||||
virtual void SetEncoding(wxFontEncoding encoding);
|
virtual void SetEncoding(wxFontEncoding encoding);
|
||||||
|
@@ -44,8 +44,13 @@ public:
|
|||||||
const wxString& face = wxEmptyString,
|
const wxString& face = wxEmptyString,
|
||||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
|
wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
|
||||||
{
|
{
|
||||||
return DoCreate(size, wxDefaultSize, false, family, style,
|
return DoCreate(InfoFromLegacyParams(size,
|
||||||
weight, underlined, face, encoding);
|
family,
|
||||||
|
style,
|
||||||
|
weight,
|
||||||
|
underlined,
|
||||||
|
face,
|
||||||
|
encoding));
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFont(const wxSize& pixelSize,
|
wxFont(const wxSize& pixelSize,
|
||||||
@@ -76,8 +81,13 @@ public:
|
|||||||
const wxString& face = wxEmptyString,
|
const wxString& face = wxEmptyString,
|
||||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
|
wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
|
||||||
{
|
{
|
||||||
return DoCreate(-1, pixelSize, true, family, style,
|
return DoCreate(InfoFromLegacyParams(pixelSize,
|
||||||
weight, underlined, face, encoding);
|
family,
|
||||||
|
style,
|
||||||
|
weight,
|
||||||
|
underlined,
|
||||||
|
face,
|
||||||
|
encoding));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Create(const wxNativeFontInfo& info, WXHFONT hFont = 0);
|
bool Create(const wxNativeFontInfo& info, WXHFONT hFont = 0);
|
||||||
@@ -89,7 +99,6 @@ public:
|
|||||||
virtual wxSize GetPixelSize() const wxOVERRIDE;
|
virtual wxSize GetPixelSize() const wxOVERRIDE;
|
||||||
virtual bool IsUsingSizeInPixels() const wxOVERRIDE;
|
virtual bool IsUsingSizeInPixels() const wxOVERRIDE;
|
||||||
virtual wxFontStyle GetStyle() const wxOVERRIDE;
|
virtual wxFontStyle GetStyle() const wxOVERRIDE;
|
||||||
virtual wxFontWeight GetWeight() const wxOVERRIDE;
|
|
||||||
virtual int GetNumericWeight() const wxOVERRIDE;
|
virtual int GetNumericWeight() const wxOVERRIDE;
|
||||||
virtual bool GetUnderlined() const wxOVERRIDE;
|
virtual bool GetUnderlined() const wxOVERRIDE;
|
||||||
virtual bool GetStrikethrough() const wxOVERRIDE;
|
virtual bool GetStrikethrough() const wxOVERRIDE;
|
||||||
@@ -97,11 +106,10 @@ public:
|
|||||||
virtual wxFontEncoding GetEncoding() const wxOVERRIDE;
|
virtual wxFontEncoding GetEncoding() const wxOVERRIDE;
|
||||||
virtual const wxNativeFontInfo *GetNativeFontInfo() const wxOVERRIDE;
|
virtual const wxNativeFontInfo *GetNativeFontInfo() const wxOVERRIDE;
|
||||||
|
|
||||||
virtual void SetPointSize(float pointSize) wxOVERRIDE;
|
virtual void SetFractionalPointSize(float pointSize) wxOVERRIDE;
|
||||||
virtual void SetPixelSize(const wxSize& pixelSize) wxOVERRIDE;
|
virtual void SetPixelSize(const wxSize& pixelSize) wxOVERRIDE;
|
||||||
virtual void SetFamily(wxFontFamily family) wxOVERRIDE;
|
virtual void SetFamily(wxFontFamily family) wxOVERRIDE;
|
||||||
virtual void SetStyle(wxFontStyle style) wxOVERRIDE;
|
virtual void SetStyle(wxFontStyle style) wxOVERRIDE;
|
||||||
virtual void SetWeight(wxFontWeight weight) wxOVERRIDE;
|
|
||||||
virtual void SetNumericWeight(int weight) wxOVERRIDE;
|
virtual void SetNumericWeight(int weight) wxOVERRIDE;
|
||||||
virtual bool SetFaceName(const wxString& faceName) wxOVERRIDE;
|
virtual bool SetFaceName(const wxString& faceName) wxOVERRIDE;
|
||||||
virtual void SetUnderlined(bool underlined) wxOVERRIDE;
|
virtual void SetUnderlined(bool underlined) wxOVERRIDE;
|
||||||
@@ -149,16 +157,8 @@ public:
|
|||||||
WXHFONT GetHFONT() const;
|
WXHFONT GetHFONT() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// real font creation function, used in all cases
|
// Common helper of overloaded Create() methods.
|
||||||
bool DoCreate(int size,
|
bool DoCreate(const wxFontInfo& info);
|
||||||
const wxSize& pixelSize,
|
|
||||||
bool sizeUsingPixels,
|
|
||||||
wxFontFamily family,
|
|
||||||
wxFontStyle style,
|
|
||||||
wxFontWeight weight,
|
|
||||||
bool underlined = false,
|
|
||||||
const wxString& face = wxEmptyString,
|
|
||||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
|
||||||
|
|
||||||
virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info) wxOVERRIDE;
|
virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info) wxOVERRIDE;
|
||||||
virtual wxFontFamily DoGetFamily() const wxOVERRIDE;
|
virtual wxFontFamily DoGetFamily() const wxOVERRIDE;
|
||||||
|
@@ -36,19 +36,7 @@ public:
|
|||||||
// ctors and such
|
// ctors and such
|
||||||
wxFont() { }
|
wxFont() { }
|
||||||
|
|
||||||
wxFont(const wxFontInfo& info)
|
wxFont(const wxFontInfo& info);
|
||||||
{
|
|
||||||
Create(info.GetPointSize(),
|
|
||||||
info.GetFamily(),
|
|
||||||
info.GetStyle(),
|
|
||||||
info.GetWeight(),
|
|
||||||
info.IsUnderlined(),
|
|
||||||
info.GetFaceName(),
|
|
||||||
info.GetEncoding());
|
|
||||||
|
|
||||||
if ( info.IsUsingSizeInPixels() )
|
|
||||||
SetPixelSize(info.GetPixelSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
wxFont( wxOSXSystemFont systemFont );
|
wxFont( wxOSXSystemFont systemFont );
|
||||||
wxFont(CTFontRef font);
|
wxFont(CTFontRef font);
|
||||||
@@ -68,17 +56,6 @@ public:
|
|||||||
Create(size, family, style, weight, underlined, face, encoding);
|
Create(size, family, style, weight, underlined, face, encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFont(float size,
|
|
||||||
wxFontFamily family,
|
|
||||||
wxFontStyle style,
|
|
||||||
wxFontWeight weight,
|
|
||||||
bool underlined = false,
|
|
||||||
const wxString& face = wxEmptyString,
|
|
||||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
|
|
||||||
{
|
|
||||||
Create(size, family, style, weight, underlined, face, encoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
wxFont(const wxSize& pixelSize,
|
wxFont(const wxSize& pixelSize,
|
||||||
wxFontFamily family,
|
wxFontFamily family,
|
||||||
wxFontStyle style,
|
wxFontStyle style,
|
||||||
@@ -99,14 +76,6 @@ public:
|
|||||||
const wxString& face = wxEmptyString,
|
const wxString& face = wxEmptyString,
|
||||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
||||||
|
|
||||||
bool Create(float size,
|
|
||||||
wxFontFamily family,
|
|
||||||
wxFontStyle style,
|
|
||||||
wxFontWeight weight,
|
|
||||||
bool underlined = false,
|
|
||||||
const wxString& face = wxEmptyString,
|
|
||||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
|
||||||
|
|
||||||
wxFont(const wxNativeFontInfo& info)
|
wxFont(const wxNativeFontInfo& info)
|
||||||
{
|
{
|
||||||
(void)Create(info);
|
(void)Create(info);
|
||||||
@@ -122,7 +91,6 @@ public:
|
|||||||
virtual float GetFractionalPointSize() const wxOVERRIDE;
|
virtual float GetFractionalPointSize() const wxOVERRIDE;
|
||||||
virtual wxSize GetPixelSize() const wxOVERRIDE;
|
virtual wxSize GetPixelSize() const wxOVERRIDE;
|
||||||
virtual wxFontStyle GetStyle() const wxOVERRIDE;
|
virtual wxFontStyle GetStyle() const wxOVERRIDE;
|
||||||
virtual wxFontWeight GetWeight() const wxOVERRIDE;
|
|
||||||
virtual int GetNumericWeight() const wxOVERRIDE;
|
virtual int GetNumericWeight() const wxOVERRIDE;
|
||||||
virtual bool GetUnderlined() const wxOVERRIDE;
|
virtual bool GetUnderlined() const wxOVERRIDE;
|
||||||
virtual bool GetStrikethrough() const wxOVERRIDE;
|
virtual bool GetStrikethrough() const wxOVERRIDE;
|
||||||
@@ -132,10 +100,9 @@ public:
|
|||||||
|
|
||||||
virtual bool IsFixedWidth() const wxOVERRIDE;
|
virtual bool IsFixedWidth() const wxOVERRIDE;
|
||||||
|
|
||||||
virtual void SetPointSize(float pointSize) wxOVERRIDE;
|
virtual void SetFractionalPointSize(float pointSize) wxOVERRIDE;
|
||||||
virtual void SetFamily(wxFontFamily family) wxOVERRIDE;
|
virtual void SetFamily(wxFontFamily family) wxOVERRIDE;
|
||||||
virtual void SetStyle(wxFontStyle style) wxOVERRIDE;
|
virtual void SetStyle(wxFontStyle style) wxOVERRIDE;
|
||||||
virtual void SetWeight(wxFontWeight weight) wxOVERRIDE;
|
|
||||||
virtual void SetNumericWeight(int weight) wxOVERRIDE;
|
virtual void SetNumericWeight(int weight) wxOVERRIDE;
|
||||||
virtual bool SetFaceName(const wxString& faceName) wxOVERRIDE;
|
virtual bool SetFaceName(const wxString& faceName) wxOVERRIDE;
|
||||||
virtual void SetUnderlined(bool underlined) wxOVERRIDE;
|
virtual void SetUnderlined(bool underlined) wxOVERRIDE;
|
||||||
|
@@ -204,7 +204,7 @@ public:
|
|||||||
wxFontMgrFontRefData(int size = wxDEFAULT,
|
wxFontMgrFontRefData(int size = wxDEFAULT,
|
||||||
wxFontFamily family = wxFONTFAMILY_DEFAULT,
|
wxFontFamily family = wxFONTFAMILY_DEFAULT,
|
||||||
wxFontStyle style = wxFONTSTYLE_NORMAL,
|
wxFontStyle style = wxFONTSTYLE_NORMAL,
|
||||||
wxFontWeight weight = wxFONTWEIGHT_NORMAL,
|
int weight = wxFONTWEIGHT_NORMAL,
|
||||||
bool underlined = false,
|
bool underlined = false,
|
||||||
const wxString& faceName = wxEmptyString,
|
const wxString& faceName = wxEmptyString,
|
||||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
||||||
@@ -218,18 +218,18 @@ public:
|
|||||||
|
|
||||||
const wxNativeFontInfo *GetNativeFontInfo() const { return &m_info; }
|
const wxNativeFontInfo *GetNativeFontInfo() const { return &m_info; }
|
||||||
|
|
||||||
int GetPointSize() const { return m_info.pointSize; }
|
float GetFractionalPointSize() const { return m_info.pointSize; }
|
||||||
wxString GetFaceName() const { return m_info.faceName; }
|
wxString GetFaceName() const { return m_info.faceName; }
|
||||||
wxFontFamily GetFamily() const { return m_info.family; }
|
wxFontFamily GetFamily() const { return m_info.family; }
|
||||||
wxFontStyle GetStyle() const { return m_info.style; }
|
wxFontStyle GetStyle() const { return m_info.style; }
|
||||||
wxFontWeight GetWeight() const { return m_info.weight; }
|
int GetNumericWeight() const { return m_info.weight; }
|
||||||
bool GetUnderlined() const { return m_info.underlined; }
|
bool GetUnderlined() const { return m_info.underlined; }
|
||||||
wxFontEncoding GetEncoding() const { return m_info.encoding; }
|
wxFontEncoding GetEncoding() const { return m_info.encoding; }
|
||||||
|
|
||||||
void SetPointSize(int pointSize);
|
void SetFractionalPointSize(float pointSize);
|
||||||
void SetFamily(wxFontFamily family);
|
void SetFamily(wxFontFamily family);
|
||||||
void SetStyle(wxFontStyle style);
|
void SetStyle(wxFontStyle style);
|
||||||
void SetWeight(wxFontWeight weight);
|
void SetNumericWeight(int weight);
|
||||||
void SetFaceName(const wxString& faceName);
|
void SetFaceName(const wxString& faceName);
|
||||||
void SetUnderlined(bool underlined);
|
void SetUnderlined(bool underlined);
|
||||||
void SetEncoding(wxFontEncoding encoding);
|
void SetEncoding(wxFontEncoding encoding);
|
||||||
|
@@ -135,7 +135,9 @@ public:
|
|||||||
font, &wxFont::SetUnderlined,
|
font, &wxFont::SetUnderlined,
|
||||||
false, true);
|
false, true);
|
||||||
|
|
||||||
// TODO: No support for strike-through yet.
|
FontModifier<bool>()(spanAttr.m_isStrikethrough,
|
||||||
|
font, &wxFont::SetStrikethrough,
|
||||||
|
false, true);
|
||||||
|
|
||||||
switch ( spanAttr.m_sizeKind )
|
switch ( spanAttr.m_sizeKind )
|
||||||
{
|
{
|
||||||
@@ -159,7 +161,7 @@ public:
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case wxMarkupSpanAttributes::Size_PointParts:
|
case wxMarkupSpanAttributes::Size_PointParts:
|
||||||
font.SetPointSize((spanAttr.m_fontSize + 1023)/1024);
|
font.SetFractionalPointSize(spanAttr.m_fontSize/1024.);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,6 +32,7 @@ public:
|
|||||||
const wxString& face = wxEmptyString,
|
const wxString& face = wxEmptyString,
|
||||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
||||||
|
|
||||||
|
wxDEPRECATED_MSG("use wxFONT{FAMILY,STYLE,WEIGHT}_XXX constants")
|
||||||
wxFont(int size,
|
wxFont(int size,
|
||||||
int family,
|
int family,
|
||||||
int style,
|
int style,
|
||||||
@@ -49,20 +50,20 @@ public:
|
|||||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
||||||
|
|
||||||
// accessors: get the font characteristics
|
// accessors: get the font characteristics
|
||||||
virtual int GetPointSize() const;
|
virtual float GetFractionalPointSize() const wxOVERRIDE;
|
||||||
virtual wxFontStyle GetStyle() const;
|
virtual wxFontStyle GetStyle() const;
|
||||||
virtual wxFontWeight GetWeight() const;
|
virtual int GetNumericWeight() const wxOVERRIDE;
|
||||||
virtual bool GetUnderlined() const;
|
virtual bool GetUnderlined() const;
|
||||||
virtual wxString GetFaceName() const;
|
virtual wxString GetFaceName() const;
|
||||||
virtual wxFontEncoding GetEncoding() const;
|
virtual wxFontEncoding GetEncoding() const;
|
||||||
virtual const wxNativeFontInfo *GetNativeFontInfo() const;
|
virtual const wxNativeFontInfo *GetNativeFontInfo() const;
|
||||||
|
|
||||||
// change the font characteristics
|
// change the font characteristics
|
||||||
virtual void SetPointSize( int pointSize );
|
virtual void SetFractionalPointSize(float pointSize) wxOVERRIDE;
|
||||||
virtual void SetFamily( wxFontFamily family );
|
virtual void SetFamily( wxFontFamily family );
|
||||||
virtual void SetStyle( wxFontStyle style );
|
virtual void SetStyle( wxFontStyle style );
|
||||||
|
virtual void SetNumericWeight(int weight) wxOVERRIDE;
|
||||||
virtual bool SetFaceName(const wxString& facename);
|
virtual bool SetFaceName(const wxString& facename);
|
||||||
virtual void SetWeight( wxFontWeight weight );
|
|
||||||
virtual void SetUnderlined( bool underlined );
|
virtual void SetUnderlined( bool underlined );
|
||||||
virtual void SetEncoding(wxFontEncoding encoding);
|
virtual void SetEncoding(wxFontEncoding encoding);
|
||||||
|
|
||||||
|
@@ -21,10 +21,10 @@
|
|||||||
|
|
||||||
// returns the handle of the nearest available font or 0
|
// returns the handle of the nearest available font or 0
|
||||||
extern wxNativeFont
|
extern wxNativeFont
|
||||||
wxLoadQueryNearestFont(int pointSize,
|
wxLoadQueryNearestFont(float pointSize,
|
||||||
wxFontFamily family,
|
wxFontFamily family,
|
||||||
wxFontStyle style,
|
wxFontStyle style,
|
||||||
wxFontWeight weight,
|
int weight,
|
||||||
bool underlined,
|
bool underlined,
|
||||||
const wxString &facename,
|
const wxString &facename,
|
||||||
wxFontEncoding encoding,
|
wxFontEncoding encoding,
|
||||||
|
@@ -81,9 +81,9 @@ public:
|
|||||||
virtual ~wxFont();
|
virtual ~wxFont();
|
||||||
|
|
||||||
// implement base class pure virtuals
|
// implement base class pure virtuals
|
||||||
virtual int GetPointSize() const;
|
virtual float GetFractionalPointSize() const;
|
||||||
virtual wxFontStyle GetStyle() const;
|
virtual wxFontStyle GetStyle() const;
|
||||||
virtual wxFontWeight GetWeight() const;
|
virtual int GetNumericWeight() const;
|
||||||
virtual bool GetUnderlined() const;
|
virtual bool GetUnderlined() const;
|
||||||
virtual bool GetStrikethrough() const wxOVERRIDE;
|
virtual bool GetStrikethrough() const wxOVERRIDE;
|
||||||
virtual wxString GetFaceName() const;
|
virtual wxString GetFaceName() const;
|
||||||
@@ -92,10 +92,10 @@ public:
|
|||||||
|
|
||||||
virtual bool IsFixedWidth() const;
|
virtual bool IsFixedWidth() const;
|
||||||
|
|
||||||
virtual void SetPointSize(int pointSize);
|
virtual void SetFractionalPointSize(float pointSize);
|
||||||
virtual void SetFamily(wxFontFamily family);
|
virtual void SetFamily(wxFontFamily family);
|
||||||
virtual void SetStyle(wxFontStyle style);
|
virtual void SetStyle(wxFontStyle style);
|
||||||
virtual void SetWeight(wxFontWeight weight);
|
virtual void SetNumericWeight(int weight);
|
||||||
virtual bool SetFaceName(const wxString& faceName);
|
virtual bool SetFaceName(const wxString& faceName);
|
||||||
virtual void SetUnderlined(bool underlined);
|
virtual void SetUnderlined(bool underlined);
|
||||||
virtual void SetStrikethrough(bool strikethrough) wxOVERRIDE;
|
virtual void SetStrikethrough(bool strikethrough) wxOVERRIDE;
|
||||||
|
@@ -322,9 +322,16 @@ public:
|
|||||||
/**
|
/**
|
||||||
Constructor setting the font size in points to use.
|
Constructor setting the font size in points to use.
|
||||||
|
|
||||||
|
The canonical type of @a pointSize argument is @c float, however any
|
||||||
|
other integer type, as well as @c double, is also accepted for
|
||||||
|
compatibility.
|
||||||
|
|
||||||
|
Notice that until wxWidgets 3.1.2, the type could only be @c int.
|
||||||
|
|
||||||
@see wxFont::SetPointSize()
|
@see wxFont::SetPointSize()
|
||||||
*/
|
*/
|
||||||
explicit wxFontInfo(int pointSize);
|
template <typename T>
|
||||||
|
explicit wxFontInfo(T pointSize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructor setting the font size in pixels to use.
|
Constructor setting the font size in pixels to use.
|
||||||
@@ -356,9 +363,24 @@ public:
|
|||||||
*/
|
*/
|
||||||
wxFontInfo& FaceName(const wxString& faceName);
|
wxFontInfo& FaceName(const wxString& faceName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Specify the weight of the font.
|
||||||
|
|
||||||
|
@param weight
|
||||||
|
A font weight in the range from 1 to 1000, inclusive, with 1 being
|
||||||
|
the thinnest and 1000 the heaviest possible font variant.
|
||||||
|
@c wxFONTWEIGHT_XXX values from wxFontWeight enum can be used here.
|
||||||
|
|
||||||
|
@since 3.1.2
|
||||||
|
*/
|
||||||
|
wxFontInfo& Weight(int weight);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Use a bold version of the font.
|
Use a bold version of the font.
|
||||||
|
|
||||||
|
This is a wrapper for Weight() calling it with ::wxFONTWEIGHT_BOLD
|
||||||
|
argument.
|
||||||
|
|
||||||
@see ::wxFontWeight, wxFont::SetWeight()
|
@see ::wxFontWeight, wxFont::SetWeight()
|
||||||
*/
|
*/
|
||||||
wxFontInfo& Bold(bool bold = true);
|
wxFontInfo& Bold(bool bold = true);
|
||||||
@@ -366,6 +388,9 @@ public:
|
|||||||
/**
|
/**
|
||||||
Use a lighter version of the font.
|
Use a lighter version of the font.
|
||||||
|
|
||||||
|
This is a wrapper for Weight() calling it with ::wxFONTWEIGHT_LIGHT
|
||||||
|
argument.
|
||||||
|
|
||||||
@see ::wxFontWeight, wxFont::SetWeight()
|
@see ::wxFontWeight, wxFont::SetWeight()
|
||||||
*/
|
*/
|
||||||
wxFontInfo& Light(bool light = true);
|
wxFontInfo& Light(bool light = true);
|
||||||
@@ -373,6 +398,9 @@ public:
|
|||||||
/**
|
/**
|
||||||
Use an italic version of the font.
|
Use an italic version of the font.
|
||||||
|
|
||||||
|
This is a wrapper for Style() calling it with ::wxFONTSTYLE_ITALIC
|
||||||
|
argument.
|
||||||
|
|
||||||
@see ::wxFontStyle, wxFont::SetStyle()
|
@see ::wxFontStyle, wxFont::SetStyle()
|
||||||
*/
|
*/
|
||||||
wxFontInfo& Italic(bool italic = true);
|
wxFontInfo& Italic(bool italic = true);
|
||||||
@@ -380,10 +408,20 @@ public:
|
|||||||
/**
|
/**
|
||||||
Use a slanted version of the font.
|
Use a slanted version of the font.
|
||||||
|
|
||||||
|
This is a wrapper for Style() calling it with ::wxFONTSTYLE_SLANT
|
||||||
|
argument.
|
||||||
|
|
||||||
@see ::wxFontStyle, wxFont::SetStyle()
|
@see ::wxFontStyle, wxFont::SetStyle()
|
||||||
*/
|
*/
|
||||||
wxFontInfo& Slant(bool slant = true);
|
wxFontInfo& Slant(bool slant = true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Specify the style of the font using one of wxFontStyle constants.
|
||||||
|
|
||||||
|
@since 3.1.2
|
||||||
|
*/
|
||||||
|
wxFontInfo& Style(wxFontStyle style);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Set anti-aliasing flag.
|
Set anti-aliasing flag.
|
||||||
|
|
||||||
@@ -419,8 +457,25 @@ public:
|
|||||||
Set all the font attributes at once.
|
Set all the font attributes at once.
|
||||||
|
|
||||||
See ::wxFontFlag for the various flags that can be used.
|
See ::wxFontFlag for the various flags that can be used.
|
||||||
|
|
||||||
|
Note that calling this method affects the font weight stored in this
|
||||||
|
object: it is set to ::wxFONTWEIGHT_LIGHT or ::wxFONTWEIGHT_BOLD if the
|
||||||
|
corresponding flag is present in @a flags, or ::wxFONTWEIGHT_NORMAL
|
||||||
|
otherwise.
|
||||||
*/
|
*/
|
||||||
wxFontInfo& AllFlags(int flags);
|
wxFontInfo& AllFlags(int flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the symbolic weight closest to the given raw weight value.
|
||||||
|
|
||||||
|
@param numWeight
|
||||||
|
A valid raw weight value, i.e. a value in the range 1 to 1000,
|
||||||
|
inclusive.
|
||||||
|
@return A valid element of wxFontWeight enum.
|
||||||
|
|
||||||
|
@since 3.1.2
|
||||||
|
*/
|
||||||
|
static wxFontWeight GetWeightClosestToNumericValue(int numWeight);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -503,7 +558,10 @@ public:
|
|||||||
historical reasons, the value 70 here is interpreted at @c
|
historical reasons, the value 70 here is interpreted at @c
|
||||||
wxDEFAULT and results in creation of the font with the default size
|
wxDEFAULT and results in creation of the font with the default size
|
||||||
and not of a font with the size of 70pt. If you really need the
|
and not of a font with the size of 70pt. If you really need the
|
||||||
latter, please use SetPointSize(70).
|
latter, please use SetPointSize(70). Note that this constructor and
|
||||||
|
the matching Create() method overload are the only places in wxFont
|
||||||
|
API handling @c wxDEFAULT specially: neither SetPointSize() nor the
|
||||||
|
constructor taking wxFontInfo handle this value in this way.
|
||||||
@param family
|
@param family
|
||||||
The font family: a generic portable way of referring to fonts without specifying a
|
The font family: a generic portable way of referring to fonts without specifying a
|
||||||
facename. This parameter must be one of the ::wxFontFamily enumeration values.
|
facename. This parameter must be one of the ::wxFontFamily enumeration values.
|
||||||
@@ -1059,19 +1117,29 @@ public:
|
|||||||
void SetNativeFontInfo(const wxNativeFontInfo& info);
|
void SetNativeFontInfo(const wxNativeFontInfo& info);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Sets the point size.
|
Sets the font size in points to an integer value.
|
||||||
|
|
||||||
|
This is a legacy version of the function only supporting integer point
|
||||||
|
sizes. It can still be used, but to avoid unnecessarily restricting the
|
||||||
|
font size in points to integer values, consider using the new (added in
|
||||||
|
wxWidgets 3.1.2) SetFractionalPointSize() function instead.
|
||||||
|
*/
|
||||||
|
virtual void SetPointSize(int pointSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Sets the font size in points.
|
||||||
|
|
||||||
The <em>point size</em> is defined as 1/72 of the Anglo-Saxon inch
|
The <em>point size</em> is defined as 1/72 of the Anglo-Saxon inch
|
||||||
(25.4 mm): it is approximately 0.0139 inch or 352.8 um.
|
(25.4 mm): it is approximately 0.0139 inch or 352.8 um.
|
||||||
|
|
||||||
@param pointSize
|
@param pointSize
|
||||||
Size in points. This can also be a fractional point size like 11.5.
|
Size in points. This can also be a fractional point size like 11.5.
|
||||||
Note that until wxWidgets 3.1.2, the size had to be an integer number
|
|
||||||
(and the type of this parameter was @c int).
|
|
||||||
|
|
||||||
@see GetPointSize()
|
@see GetFractionalPointSize(), SetPointSize()
|
||||||
|
|
||||||
|
@since 3.1.2
|
||||||
*/
|
*/
|
||||||
virtual void SetPointSize(float pointSize);
|
virtual void SetFractionalPointSize(float pointSize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Sets the pixel size.
|
Sets the pixel size.
|
||||||
@@ -1208,6 +1276,22 @@ public:
|
|||||||
*/
|
*/
|
||||||
static void SetDefaultEncoding(wxFontEncoding encoding);
|
static void SetDefaultEncoding(wxFontEncoding encoding);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the raw weight value corresponding to the given symbolic constant.
|
||||||
|
|
||||||
|
For compatibility, this function handles the values @c wxNORMAL, @c
|
||||||
|
wxLIGHT and @c wxBOLD, that have values 90, 91 and 92, specially and
|
||||||
|
converts them to the corresponding @c wxFONTWEIGHT_XXX weight value.
|
||||||
|
|
||||||
|
@param weight
|
||||||
|
A valid element of wxFontWeight enum, i.e. this argument can't have
|
||||||
|
value ::wxFONTWEIGHT_INVALID.
|
||||||
|
@return Numeric weight, between 1 and 1000.
|
||||||
|
|
||||||
|
@since 3.1.2
|
||||||
|
*/
|
||||||
|
static int GetNumericWeightOf(wxFontWeight weight);
|
||||||
|
|
||||||
//@{
|
//@{
|
||||||
/**
|
/**
|
||||||
This function takes the same parameters as the relative
|
This function takes the same parameters as the relative
|
||||||
|
@@ -41,7 +41,8 @@ public:
|
|||||||
wxFontFamily GetFamily() const;
|
wxFontFamily GetFamily() const;
|
||||||
wxFontEncoding GetEncoding() const;
|
wxFontEncoding GetEncoding() const;
|
||||||
|
|
||||||
void SetPointSize(float pointsize);
|
void SetPointSize(int pointsize);
|
||||||
|
void SetFractionalPointSize(float pointsize);
|
||||||
void SetPixelSize(const wxSize& pixelSize);
|
void SetPixelSize(const wxSize& pixelSize);
|
||||||
void SetStyle(wxFontStyle style);
|
void SetStyle(wxFontStyle style);
|
||||||
void SetNumericWeight(int weight);
|
void SetNumericWeight(int weight);
|
||||||
|
@@ -454,14 +454,15 @@ t_bitmap = t_url?,
|
|||||||
)?
|
)?
|
||||||
|
|
||||||
t_font = (
|
t_font = (
|
||||||
[xrc:p="o"] element size {_, t_integer }* &
|
[xrc:p="o"] element size {_, t_float }* &
|
||||||
[xrc:p="o"] element style {_, ("normal" | "italic" | "slant") }* &
|
[xrc:p="o"] element style {_, ("normal" | "italic" | "slant") }* &
|
||||||
[xrc:p="o"] element weight {_, ("normal" | "thin" | "extralight" | "light" |
|
[xrc:p="o"] element weight {_, ("normal" | "thin" | "extralight" | "light" |
|
||||||
"medium" | "semibold" | "bold" | "extrabold" |
|
"medium" | "semibold" | "bold" | "extrabold" |
|
||||||
"heavy" | "extraheavy") }* &
|
"heavy" | "extraheavy" | t_integer) }* &
|
||||||
[xrc:p="o"] element family {_, ("roman" | "script" | "decorative" | "swiss" |
|
[xrc:p="o"] element family {_, ("roman" | "script" | "decorative" | "swiss" |
|
||||||
"modern" | "teletype") }* &
|
"modern" | "teletype") }* &
|
||||||
[xrc:p="o"] element underlined {_, t_bool }* &
|
[xrc:p="o"] element underlined {_, t_bool }* &
|
||||||
|
[xrc:p="o"] element strikethrough{_, t_bool }* &
|
||||||
[xrc:p="o"] element face {_, t_text }* &
|
[xrc:p="o"] element face {_, t_text }* &
|
||||||
[xrc:p="o"] element encoding {_, t_text }* &
|
[xrc:p="o"] element encoding {_, t_text }* &
|
||||||
[xrc:p="o"] element sysfont {_, ("wxSYS_OEM_FIXED_FONT" | "wxSYS_ANSI_FIXED_FONT" |
|
[xrc:p="o"] element sysfont {_, ("wxSYS_OEM_FIXED_FONT" | "wxSYS_ANSI_FIXED_FONT" |
|
||||||
|
@@ -337,8 +337,7 @@ void MyCanvas::CreateCaret()
|
|||||||
|
|
||||||
void MyCanvas::SetFontSize(int fontSize)
|
void MyCanvas::SetFontSize(int fontSize)
|
||||||
{
|
{
|
||||||
m_font = wxFont(fontSize, wxFONTFAMILY_TELETYPE,
|
m_font = wxFont(wxFontInfo(fontSize).Family(wxFONTFAMILY_TELETYPE));
|
||||||
wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
|
|
||||||
|
|
||||||
wxClientDC dc(this);
|
wxClientDC dc(this);
|
||||||
dc.SetFont(m_font);
|
dc.SetFont(m_font);
|
||||||
|
@@ -28,6 +28,12 @@ of MSW, MAC and OS2
|
|||||||
#define USE_WXUNIVERSAL 0
|
#define USE_WXUNIVERSAL 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WXUSINGDLL
|
||||||
|
#define USE_DLL 1
|
||||||
|
#else
|
||||||
|
#define USE_DLL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__WXMSW__)
|
#if defined(__WXMSW__)
|
||||||
#define USE_WXMSW 1
|
#define USE_WXMSW 1
|
||||||
#else
|
#else
|
||||||
@@ -52,14 +58,16 @@ of MSW, MAC and OS2
|
|||||||
#define USE_WXGTK 0
|
#define USE_WXGTK 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define USE_GENERIC_DIALOGS (!USE_WXUNIVERSAL && !USE_DLL)
|
||||||
|
|
||||||
#define USE_COLOURDLG_GENERIC \
|
#define USE_COLOURDLG_GENERIC \
|
||||||
((USE_WXMSW || USE_WXMAC) && USE_WXUNIVERSAL && wxUSE_COLOURDLG)
|
((USE_WXMSW || USE_WXMAC) && USE_GENERIC_DIALOGS && wxUSE_COLOURDLG)
|
||||||
#define USE_DIRDLG_GENERIC \
|
#define USE_DIRDLG_GENERIC \
|
||||||
((USE_WXMSW || USE_WXMAC) && USE_WXUNIVERSAL && wxUSE_DIRDLG)
|
((USE_WXMSW || USE_WXMAC) && USE_GENERIC_DIALOGS && wxUSE_DIRDLG)
|
||||||
#define USE_FILEDLG_GENERIC \
|
#define USE_FILEDLG_GENERIC \
|
||||||
((USE_WXMSW || USE_WXMAC) && USE_WXUNIVERSAL && wxUSE_FILEDLG)
|
((USE_WXMSW || USE_WXMAC) && USE_GENERIC_DIALOGS && wxUSE_FILEDLG)
|
||||||
#define USE_FONTDLG_GENERIC \
|
#define USE_FONTDLG_GENERIC \
|
||||||
((USE_WXMSW || USE_WXMACFONTDLG) && USE_WXUNIVERSAL && wxUSE_FONTDLG)
|
((USE_WXMSW || USE_WXMACFONTDLG) && USE_GENERIC_DIALOGS && wxUSE_FONTDLG)
|
||||||
|
|
||||||
// Turn USE_MODAL_PRESENTATION to 0 if there is any reason for not presenting difference
|
// Turn USE_MODAL_PRESENTATION to 0 if there is any reason for not presenting difference
|
||||||
// between modal and modeless dialogs (ie. not implemented it in your port yet)
|
// between modal and modeless dialogs (ie. not implemented it in your port yet)
|
||||||
|
@@ -1072,7 +1072,7 @@ void MyCanvas::DrawAlpha(wxDC& dc)
|
|||||||
|
|
||||||
dc.SetTextBackground( wxColour(160, 192, 160, 160) );
|
dc.SetTextBackground( wxColour(160, 192, 160, 160) );
|
||||||
dc.SetTextForeground( wxColour(255, 128, 128, 128) );
|
dc.SetTextForeground( wxColour(255, 128, 128, 128) );
|
||||||
dc.SetFont( wxFont( 40, wxFONTFAMILY_SWISS, wxFONTSTYLE_ITALIC, wxFONTWEIGHT_NORMAL ) );
|
dc.SetFont( wxFontInfo(40).Family(wxFONTFAMILY_SWISS).Italic() );
|
||||||
dc.DrawText( wxT("Hello!"), 120, 80 );
|
dc.DrawText( wxT("Hello!"), 120, 80 );
|
||||||
}
|
}
|
||||||
#endif // wxDRAWING_DC_SUPPORTS_ALPHA || wxUSE_GRAPHICS_CONTEXT
|
#endif // wxDRAWING_DC_SUPPORTS_ALPHA || wxUSE_GRAPHICS_CONTEXT
|
||||||
|
@@ -522,8 +522,7 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
|||||||
|
|
||||||
// create the listbox in which we will show misc messages as they come
|
// create the listbox in which we will show misc messages as they come
|
||||||
m_lbox = new wxListBox(this, wxID_ANY);
|
m_lbox = new wxListBox(this, wxID_ANY);
|
||||||
wxFont font(12, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL,
|
wxFont font(wxFontInfo(12).Family(wxFONTFAMILY_TELETYPE));
|
||||||
wxFONTWEIGHT_NORMAL);
|
|
||||||
if ( font.IsOk() )
|
if ( font.IsOk() )
|
||||||
m_lbox->SetFont(font);
|
m_lbox->SetFont(font);
|
||||||
|
|
||||||
|
@@ -23,12 +23,16 @@
|
|||||||
#include "wx/log.h"
|
#include "wx/log.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "wx/checkbox.h"
|
||||||
#include "wx/choicdlg.h"
|
#include "wx/choicdlg.h"
|
||||||
#include "wx/fontdlg.h"
|
#include "wx/fontdlg.h"
|
||||||
#include "wx/fontenum.h"
|
#include "wx/fontenum.h"
|
||||||
#include "wx/fontmap.h"
|
#include "wx/fontmap.h"
|
||||||
#include "wx/encconv.h"
|
#include "wx/encconv.h"
|
||||||
|
#include "wx/sizer.h"
|
||||||
|
#include "wx/spinctrl.h"
|
||||||
#include "wx/splitter.h"
|
#include "wx/splitter.h"
|
||||||
|
#include "wx/statline.h"
|
||||||
#include "wx/stdpaths.h"
|
#include "wx/stdpaths.h"
|
||||||
#include "wx/textfile.h"
|
#include "wx/textfile.h"
|
||||||
#include "wx/settings.h"
|
#include "wx/settings.h"
|
||||||
@@ -60,14 +64,85 @@ public:
|
|||||||
virtual bool OnInit() wxOVERRIDE;
|
virtual bool OnInit() wxOVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
// MyCanvas is a canvas on which we show the font sample
|
// FontPanel contains controls allowing to specify the font properties
|
||||||
class MyCanvas: public wxWindow
|
class FontPanel : public wxPanel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyCanvas( wxWindow *parent );
|
explicit FontPanel(wxWindow* parent);
|
||||||
virtual ~MyCanvas(){};
|
|
||||||
|
|
||||||
// accessors for the frame
|
void ShowFont(const wxFont& font) { m_font = font; DoUpdate(); }
|
||||||
|
|
||||||
|
wxFontInfo GetFontInfo() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Update m_useXXX flags depending on which control was changed last.
|
||||||
|
void OnFacename(wxCommandEvent& e) { m_useFamily = false; e.Skip(); }
|
||||||
|
void OnFamily(wxCommandEvent& e) { m_useFamily = true; e.Skip(); }
|
||||||
|
|
||||||
|
void OnWeightChoice(wxCommandEvent& e) { m_useNumericWeight = false; e.Skip(); }
|
||||||
|
void OnWeightSpin(wxCommandEvent& e) { m_useNumericWeight = true; e.Skip(); }
|
||||||
|
|
||||||
|
|
||||||
|
// Unlike wxFontXXX, the elements of these enum are consecutive, which is
|
||||||
|
// more convenient here.
|
||||||
|
enum Family
|
||||||
|
{
|
||||||
|
Family_Default,
|
||||||
|
Family_Decorative,
|
||||||
|
Family_Roman,
|
||||||
|
Family_Script,
|
||||||
|
Family_Swiss,
|
||||||
|
Family_Modern,
|
||||||
|
Family_Teletype
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Style
|
||||||
|
{
|
||||||
|
Style_Normal,
|
||||||
|
Style_Italic,
|
||||||
|
Style_Slant
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Weight
|
||||||
|
{
|
||||||
|
Weight_Thin,
|
||||||
|
Weight_Extralight,
|
||||||
|
Weight_Light,
|
||||||
|
Weight_Normal,
|
||||||
|
Weight_Medium,
|
||||||
|
Weight_Semibold,
|
||||||
|
Weight_Bold,
|
||||||
|
Weight_Extrabold,
|
||||||
|
Weight_Heavy,
|
||||||
|
Weight_Extraheavy
|
||||||
|
};
|
||||||
|
|
||||||
|
void DoUpdate();
|
||||||
|
|
||||||
|
wxFont m_font;
|
||||||
|
|
||||||
|
wxTextCtrl* m_textFaceName;
|
||||||
|
wxChoice* m_choiceFamily;
|
||||||
|
wxSpinCtrlDouble* m_spinPointSize;
|
||||||
|
wxChoice* m_choiceStyle;
|
||||||
|
wxChoice* m_choiceWeight;
|
||||||
|
wxSpinCtrl* m_spinWeight;
|
||||||
|
wxCheckBox* m_checkUnderlined;
|
||||||
|
wxCheckBox* m_checkStrikethrough;
|
||||||
|
wxCheckBox* m_checkFixedWidth;
|
||||||
|
wxStaticText* m_labelInfo;
|
||||||
|
|
||||||
|
bool m_useFamily;
|
||||||
|
bool m_useNumericWeight;
|
||||||
|
};
|
||||||
|
|
||||||
|
// FontCanvas shows the font characters.
|
||||||
|
class FontCanvas : public wxWindow
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit FontCanvas( wxWindow *parent );
|
||||||
|
|
||||||
|
// accessors for FontWindow
|
||||||
const wxFont& GetTextFont() const { return m_font; }
|
const wxFont& GetTextFont() const { return m_font; }
|
||||||
const wxColour& GetColour() const { return m_colour; }
|
const wxColour& GetColour() const { return m_colour; }
|
||||||
void SetTextFont(const wxFont& font) { m_font = font; }
|
void SetTextFont(const wxFont& font) { m_font = font; }
|
||||||
@@ -76,6 +151,12 @@ public:
|
|||||||
// event handlers
|
// event handlers
|
||||||
void OnPaint( wxPaintEvent &event );
|
void OnPaint( wxPaintEvent &event );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual wxSize DoGetBestClientSize() const wxOVERRIDE
|
||||||
|
{
|
||||||
|
return wxSize(80*GetCharWidth(), 15*GetCharHeight());
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxColour m_colour;
|
wxColour m_colour;
|
||||||
wxFont m_font;
|
wxFont m_font;
|
||||||
@@ -83,22 +164,37 @@ private:
|
|||||||
wxDECLARE_EVENT_TABLE();
|
wxDECLARE_EVENT_TABLE();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// FontWindow contains both FontPanel and FontCanvas
|
||||||
|
class FontWindow : public wxWindow
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit FontWindow(wxWindow *parent);
|
||||||
|
|
||||||
|
const wxFont& GetTextFont() const { return m_canvas->GetTextFont(); }
|
||||||
|
const wxColour& GetColour() const { return m_canvas->GetColour(); }
|
||||||
|
|
||||||
|
wxFont MakeNewFont() const { return m_panel->GetFontInfo(); }
|
||||||
|
|
||||||
|
void UpdateFont(const wxFont& font, const wxColour& colour);
|
||||||
|
|
||||||
|
private:
|
||||||
|
FontPanel* const m_panel;
|
||||||
|
FontCanvas* const m_canvas;
|
||||||
|
};
|
||||||
|
|
||||||
// Define a new frame type: this is going to be our main frame
|
// Define a new frame type: this is going to be our main frame
|
||||||
class MyFrame : public wxFrame
|
class MyFrame : public wxFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// ctor(s)
|
// ctor(s)
|
||||||
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
|
MyFrame();
|
||||||
|
|
||||||
// accessors
|
|
||||||
MyCanvas *GetCanvas() const { return m_canvas; }
|
|
||||||
|
|
||||||
// event handlers (these functions should _not_ be virtual)
|
// event handlers (these functions should _not_ be virtual)
|
||||||
void OnQuit(wxCommandEvent& event);
|
void OnQuit(wxCommandEvent& event);
|
||||||
void OnAbout(wxCommandEvent& event);
|
void OnAbout(wxCommandEvent& event);
|
||||||
|
|
||||||
void OnGetBaseFont(wxCommandEvent& WXUNUSED(event))
|
void OnGetBaseFont(wxCommandEvent& WXUNUSED(event))
|
||||||
{ DoChangeFont(m_canvas->GetTextFont().GetBaseFont()); }
|
{ DoChangeFont(m_fontWindow->GetTextFont().GetBaseFont()); }
|
||||||
void OnIncFont(wxCommandEvent& WXUNUSED(event)) { DoResizeFont(+2); }
|
void OnIncFont(wxCommandEvent& WXUNUSED(event)) { DoResizeFont(+2); }
|
||||||
void OnDecFont(wxCommandEvent& WXUNUSED(event)) { DoResizeFont(-2); }
|
void OnDecFont(wxCommandEvent& WXUNUSED(event)) { DoResizeFont(-2); }
|
||||||
|
|
||||||
@@ -133,6 +229,9 @@ public:
|
|||||||
void OnSetEncoding(wxCommandEvent& event);
|
void OnSetEncoding(wxCommandEvent& event);
|
||||||
void OnPrivateFont(wxCommandEvent& event);
|
void OnPrivateFont(wxCommandEvent& event);
|
||||||
|
|
||||||
|
void OnFontPanelApply(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{ DoChangeFont(m_fontWindow->MakeNewFont()); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool DoEnumerateFamilies(bool fixedWidthOnly,
|
bool DoEnumerateFamilies(bool fixedWidthOnly,
|
||||||
wxFontEncoding encoding = wxFONTENCODING_SYSTEM,
|
wxFontEncoding encoding = wxFONTENCODING_SYSTEM,
|
||||||
@@ -149,10 +248,8 @@ protected:
|
|||||||
// wxFONTFAMILY_DEFAULT if the dialog was cancelled
|
// wxFONTFAMILY_DEFAULT if the dialog was cancelled
|
||||||
wxFontFamily GetFamilyFromUser();
|
wxFontFamily GetFamilyFromUser();
|
||||||
|
|
||||||
size_t m_fontSize; // in points
|
|
||||||
|
|
||||||
wxTextCtrl *m_textctrl;
|
wxTextCtrl *m_textctrl;
|
||||||
MyCanvas *m_canvas;
|
FontWindow *m_fontWindow;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// any class wishing to process wxWidgets events must use this macro
|
// any class wishing to process wxWidgets events must use this macro
|
||||||
@@ -292,11 +389,9 @@ bool MyApp::OnInit()
|
|||||||
{
|
{
|
||||||
if ( !wxApp::OnInit() )
|
if ( !wxApp::OnInit() )
|
||||||
return false;
|
return false;
|
||||||
wxString privfont = argv[0].BeforeLast('/');
|
|
||||||
|
|
||||||
// Create the main application window
|
// Create the main application window
|
||||||
MyFrame *frame = new MyFrame(wxT("Font wxWidgets demo"),
|
MyFrame *frame = new MyFrame();
|
||||||
wxPoint(50, 50), wxSize(600, 400));
|
|
||||||
|
|
||||||
// Show it
|
// Show it
|
||||||
frame->Show(true);
|
frame->Show(true);
|
||||||
@@ -312,11 +407,9 @@ bool MyApp::OnInit()
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
// frame constructor
|
// frame constructor
|
||||||
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
MyFrame::MyFrame()
|
||||||
: wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size), m_textctrl(NULL)
|
: wxFrame(NULL, wxID_ANY, "wxWidgets font sample")
|
||||||
{
|
{
|
||||||
m_fontSize = wxNORMAL_FONT->GetPointSize();
|
|
||||||
|
|
||||||
SetIcon(wxICON(sample));
|
SetIcon(wxICON(sample));
|
||||||
|
|
||||||
// create a menu bar
|
// create a menu bar
|
||||||
@@ -447,20 +540,26 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
|||||||
|
|
||||||
wxSplitterWindow *splitter = new wxSplitterWindow(this);
|
wxSplitterWindow *splitter = new wxSplitterWindow(this);
|
||||||
|
|
||||||
|
m_fontWindow = new FontWindow(splitter);
|
||||||
|
|
||||||
|
m_fontWindow->Bind(wxEVT_BUTTON, &MyFrame::OnFontPanelApply, this);
|
||||||
|
|
||||||
m_textctrl = new wxTextCtrl(splitter, wxID_ANY,
|
m_textctrl = new wxTextCtrl(splitter, wxID_ANY,
|
||||||
wxT("Paste text here to see how it looks\nlike in the given font"),
|
wxT("Paste text here to see how it looks\nlike in the given font"),
|
||||||
wxDefaultPosition, wxDefaultSize,
|
wxDefaultPosition,
|
||||||
|
wxSize(-1, 6*GetCharHeight()),
|
||||||
wxTE_MULTILINE);
|
wxTE_MULTILINE);
|
||||||
|
|
||||||
m_canvas = new MyCanvas(splitter);
|
splitter->SplitHorizontally(m_fontWindow, m_textctrl, 0);
|
||||||
|
|
||||||
splitter->SplitHorizontally(m_textctrl, m_canvas, 100);
|
|
||||||
|
|
||||||
#if wxUSE_STATUSBAR
|
#if wxUSE_STATUSBAR
|
||||||
// create a status bar just for fun (by default with 1 pane only)
|
// create a status bar just for fun (by default with 1 pane only)
|
||||||
CreateStatusBar();
|
CreateStatusBar();
|
||||||
SetStatusText(wxT("Welcome to wxWidgets font demo!"));
|
SetStatusText(wxT("Welcome to wxWidgets font demo!"));
|
||||||
#endif // wxUSE_STATUSBAR
|
#endif // wxUSE_STATUSBAR
|
||||||
|
|
||||||
|
SetClientSize(splitter->GetBestSize());
|
||||||
|
splitter->SetSashPosition(m_fontWindow->GetBestSize().y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------
|
// --------------------------------------------------------
|
||||||
@@ -601,7 +700,7 @@ void MyFrame::OnSetNativeDesc(wxCommandEvent& WXUNUSED(event))
|
|||||||
(
|
(
|
||||||
wxT("Enter native font string"),
|
wxT("Enter native font string"),
|
||||||
wxT("Input font description"),
|
wxT("Input font description"),
|
||||||
m_canvas->GetTextFont().GetNativeFontInfoDesc(),
|
m_fontWindow->GetTextFont().GetNativeFontInfoDesc(),
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
if ( fontInfo.empty() )
|
if ( fontInfo.empty() )
|
||||||
@@ -621,7 +720,7 @@ void MyFrame::OnSetNativeDesc(wxCommandEvent& WXUNUSED(event))
|
|||||||
|
|
||||||
void MyFrame::OnSetNativeUserDesc(wxCommandEvent& WXUNUSED(event))
|
void MyFrame::OnSetNativeUserDesc(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
wxString fontdesc = GetCanvas()->GetTextFont().GetNativeFontInfoUserDesc();
|
wxString fontdesc = m_fontWindow->GetTextFont().GetNativeFontInfoUserDesc();
|
||||||
wxString fontUserInfo = wxGetTextFromUser(
|
wxString fontUserInfo = wxGetTextFromUser(
|
||||||
wxT("Here you can edit current font description"),
|
wxT("Here you can edit current font description"),
|
||||||
wxT("Input font description"), fontdesc,
|
wxT("Input font description"), fontdesc,
|
||||||
@@ -646,14 +745,14 @@ void MyFrame::OnSetFamily(wxCommandEvent& WXUNUSED(event))
|
|||||||
{
|
{
|
||||||
wxFontFamily f = GetFamilyFromUser();
|
wxFontFamily f = GetFamilyFromUser();
|
||||||
|
|
||||||
wxFont font = m_canvas->GetTextFont();
|
wxFont font = m_fontWindow->GetTextFont();
|
||||||
font.SetFamily(f);
|
font.SetFamily(f);
|
||||||
DoChangeFont(font);
|
DoChangeFont(font);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::OnSetFaceName(wxCommandEvent& WXUNUSED(event))
|
void MyFrame::OnSetFaceName(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
wxString facename = GetCanvas()->GetTextFont().GetFaceName();
|
wxString facename = m_fontWindow->GetTextFont().GetFaceName();
|
||||||
wxString newFaceName = wxGetTextFromUser(
|
wxString newFaceName = wxGetTextFromUser(
|
||||||
wxT("Here you can edit current font face name."),
|
wxT("Here you can edit current font face name."),
|
||||||
wxT("Input font facename"), facename,
|
wxT("Input font facename"), facename,
|
||||||
@@ -661,7 +760,7 @@ void MyFrame::OnSetFaceName(wxCommandEvent& WXUNUSED(event))
|
|||||||
if (newFaceName.IsEmpty())
|
if (newFaceName.IsEmpty())
|
||||||
return; // user clicked "Cancel" - do nothing
|
return; // user clicked "Cancel" - do nothing
|
||||||
|
|
||||||
wxFont font(GetCanvas()->GetTextFont());
|
wxFont font(m_fontWindow->GetTextFont());
|
||||||
if (font.SetFaceName(newFaceName)) // change facename only
|
if (font.SetFaceName(newFaceName)) // change facename only
|
||||||
{
|
{
|
||||||
wxASSERT_MSG(font.IsOk(), wxT("The font should now be valid"));
|
wxASSERT_MSG(font.IsOk(), wxT("The font should now be valid"));
|
||||||
@@ -681,7 +780,7 @@ void MyFrame::OnSetEncoding(wxCommandEvent& WXUNUSED(event))
|
|||||||
if ( enc == wxFONTENCODING_SYSTEM )
|
if ( enc == wxFONTENCODING_SYSTEM )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wxFont font = m_canvas->GetTextFont();
|
wxFont font = m_fontWindow->GetTextFont();
|
||||||
font.SetEncoding(enc);
|
font.SetEncoding(enc);
|
||||||
DoChangeFont(font);
|
DoChangeFont(font);
|
||||||
}
|
}
|
||||||
@@ -745,7 +844,7 @@ wxFontFamily MyFrame::GetFamilyFromUser()
|
|||||||
|
|
||||||
void MyFrame::DoResizeFont(int diff)
|
void MyFrame::DoResizeFont(int diff)
|
||||||
{
|
{
|
||||||
wxFont font = m_canvas->GetTextFont();
|
wxFont font = m_fontWindow->GetTextFont();
|
||||||
|
|
||||||
font.SetPointSize(font.GetPointSize() + diff);
|
font.SetPointSize(font.GetPointSize() + diff);
|
||||||
DoChangeFont(font);
|
DoChangeFont(font);
|
||||||
@@ -753,7 +852,7 @@ void MyFrame::DoResizeFont(int diff)
|
|||||||
|
|
||||||
void MyFrame::OnBold(wxCommandEvent& event)
|
void MyFrame::OnBold(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
wxFont font = m_canvas->GetTextFont();
|
wxFont font = m_fontWindow->GetTextFont();
|
||||||
|
|
||||||
font.SetWeight(event.IsChecked() ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
|
font.SetWeight(event.IsChecked() ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
|
||||||
DoChangeFont(font);
|
DoChangeFont(font);
|
||||||
@@ -761,7 +860,7 @@ void MyFrame::OnBold(wxCommandEvent& event)
|
|||||||
|
|
||||||
void MyFrame::OnLight(wxCommandEvent& event)
|
void MyFrame::OnLight(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
wxFont font = m_canvas->GetTextFont();
|
wxFont font = m_fontWindow->GetTextFont();
|
||||||
|
|
||||||
font.SetWeight(event.IsChecked() ? wxFONTWEIGHT_LIGHT : wxFONTWEIGHT_NORMAL);
|
font.SetWeight(event.IsChecked() ? wxFONTWEIGHT_LIGHT : wxFONTWEIGHT_NORMAL);
|
||||||
DoChangeFont(font);
|
DoChangeFont(font);
|
||||||
@@ -769,7 +868,7 @@ void MyFrame::OnLight(wxCommandEvent& event)
|
|||||||
|
|
||||||
void MyFrame::OnItalic(wxCommandEvent& event)
|
void MyFrame::OnItalic(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
wxFont font = m_canvas->GetTextFont();
|
wxFont font = m_fontWindow->GetTextFont();
|
||||||
|
|
||||||
font.SetStyle(event.IsChecked() ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL);
|
font.SetStyle(event.IsChecked() ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL);
|
||||||
DoChangeFont(font);
|
DoChangeFont(font);
|
||||||
@@ -777,7 +876,7 @@ void MyFrame::OnItalic(wxCommandEvent& event)
|
|||||||
|
|
||||||
void MyFrame::OnSlant(wxCommandEvent& event)
|
void MyFrame::OnSlant(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
wxFont font = m_canvas->GetTextFont();
|
wxFont font = m_fontWindow->GetTextFont();
|
||||||
|
|
||||||
font.SetStyle(event.IsChecked() ? wxFONTSTYLE_SLANT : wxFONTSTYLE_NORMAL);
|
font.SetStyle(event.IsChecked() ? wxFONTSTYLE_SLANT : wxFONTSTYLE_NORMAL);
|
||||||
DoChangeFont(font);
|
DoChangeFont(font);
|
||||||
@@ -785,7 +884,7 @@ void MyFrame::OnSlant(wxCommandEvent& event)
|
|||||||
|
|
||||||
void MyFrame::OnUnderline(wxCommandEvent& event)
|
void MyFrame::OnUnderline(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
wxFont font = m_canvas->GetTextFont();
|
wxFont font = m_fontWindow->GetTextFont();
|
||||||
|
|
||||||
font.SetUnderlined(event.IsChecked());
|
font.SetUnderlined(event.IsChecked());
|
||||||
DoChangeFont(font);
|
DoChangeFont(font);
|
||||||
@@ -793,7 +892,7 @@ void MyFrame::OnUnderline(wxCommandEvent& event)
|
|||||||
|
|
||||||
void MyFrame::OnStrikethrough(wxCommandEvent& event)
|
void MyFrame::OnStrikethrough(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
wxFont font = m_canvas->GetTextFont();
|
wxFont font = m_fontWindow->GetTextFont();
|
||||||
font.SetStrikethrough(event.IsChecked());
|
font.SetStrikethrough(event.IsChecked());
|
||||||
DoChangeFont(font);
|
DoChangeFont(font);
|
||||||
}
|
}
|
||||||
@@ -873,10 +972,7 @@ void MyFrame::OnwxSystemSettingsFont(wxCommandEvent& event)
|
|||||||
|
|
||||||
void MyFrame::DoChangeFont(const wxFont& font, const wxColour& col)
|
void MyFrame::DoChangeFont(const wxFont& font, const wxColour& col)
|
||||||
{
|
{
|
||||||
m_canvas->SetTextFont(font);
|
m_fontWindow->UpdateFont(font, col);
|
||||||
if ( col.IsOk() )
|
|
||||||
m_canvas->SetColour(col);
|
|
||||||
m_canvas->Refresh();
|
|
||||||
|
|
||||||
m_textctrl->SetFont(font);
|
m_textctrl->SetFont(font);
|
||||||
if ( col.IsOk() )
|
if ( col.IsOk() )
|
||||||
@@ -903,8 +999,8 @@ void MyFrame::DoChangeFont(const wxFont& font, const wxColour& col)
|
|||||||
void MyFrame::OnSelectFont(wxCommandEvent& WXUNUSED(event))
|
void MyFrame::OnSelectFont(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
wxFontData data;
|
wxFontData data;
|
||||||
data.SetInitialFont(m_canvas->GetTextFont());
|
data.SetInitialFont(m_fontWindow->GetTextFont());
|
||||||
data.SetColour(m_canvas->GetColour());
|
data.SetColour(m_fontWindow->GetColour());
|
||||||
|
|
||||||
wxFontDialog dialog(this, data);
|
wxFontDialog dialog(this, data);
|
||||||
if ( dialog.ShowModal() == wxID_OK )
|
if ( dialog.ShowModal() == wxID_OK )
|
||||||
@@ -919,7 +1015,7 @@ void MyFrame::OnSelectFont(wxCommandEvent& WXUNUSED(event))
|
|||||||
|
|
||||||
void MyFrame::OnPrivateFont(wxCommandEvent& WXUNUSED(event))
|
void MyFrame::OnPrivateFont(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
wxFont font(GetCanvas()->GetTextFont());
|
wxFont font(m_fontWindow->GetTextFont());
|
||||||
if (font.SetFaceName("wxprivate"))
|
if (font.SetFaceName("wxprivate"))
|
||||||
{
|
{
|
||||||
wxASSERT_MSG( font.IsOk(), wxT("The font should now be valid")) ;
|
wxASSERT_MSG( font.IsOk(), wxT("The font should now be valid")) ;
|
||||||
@@ -1071,20 +1167,317 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// MyCanvas
|
// FontWindow
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxBEGIN_EVENT_TABLE(MyCanvas, wxWindow)
|
FontWindow::FontWindow(wxWindow *parent)
|
||||||
EVT_PAINT(MyCanvas::OnPaint)
|
: wxWindow(parent, wxID_ANY),
|
||||||
|
m_panel(new FontPanel(this)),
|
||||||
|
m_canvas(new FontCanvas(this))
|
||||||
|
{
|
||||||
|
wxSizer* const sizer = new wxBoxSizer(wxVERTICAL);
|
||||||
|
sizer->Add(m_panel, wxSizerFlags().Expand().Border());
|
||||||
|
sizer->Add(new wxStaticLine(this), wxSizerFlags().Expand());
|
||||||
|
sizer->Add(m_canvas, wxSizerFlags(1).Expand());
|
||||||
|
SetSizer(sizer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FontWindow::UpdateFont(const wxFont& font, const wxColour& colour)
|
||||||
|
{
|
||||||
|
m_panel->ShowFont(font);
|
||||||
|
|
||||||
|
m_canvas->SetTextFont(font);
|
||||||
|
if ( colour.IsOk() )
|
||||||
|
m_canvas->SetColour(colour);
|
||||||
|
m_canvas->Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// FontPanel
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
FontPanel::FontPanel(wxWindow* parent)
|
||||||
|
: wxPanel(parent)
|
||||||
|
{
|
||||||
|
m_useFamily =
|
||||||
|
m_useNumericWeight = false;
|
||||||
|
|
||||||
|
m_textFaceName = new wxTextCtrl(this, wxID_ANY, wxString(),
|
||||||
|
wxDefaultPosition, wxDefaultSize,
|
||||||
|
wxTE_PROCESS_ENTER);
|
||||||
|
m_textFaceName->Bind(wxEVT_TEXT, &FontPanel::OnFacename, this);
|
||||||
|
|
||||||
|
// Must be in sync with the Family enum.
|
||||||
|
const wxString familiesNames[] =
|
||||||
|
{
|
||||||
|
"Default",
|
||||||
|
"Decorative",
|
||||||
|
"Roman",
|
||||||
|
"Script",
|
||||||
|
"Swiss",
|
||||||
|
"Modern",
|
||||||
|
"Teletype",
|
||||||
|
};
|
||||||
|
m_choiceFamily = new wxChoice(this, wxID_ANY,
|
||||||
|
wxDefaultPosition, wxDefaultSize,
|
||||||
|
WXSIZEOF(familiesNames), familiesNames);
|
||||||
|
m_choiceFamily->Bind(wxEVT_CHOICE, &FontPanel::OnFamily, this);
|
||||||
|
|
||||||
|
m_spinPointSize = new wxSpinCtrlDouble(this, wxID_ANY, wxString(),
|
||||||
|
wxDefaultPosition, wxDefaultSize,
|
||||||
|
wxSP_ARROW_KEYS,
|
||||||
|
1.0, 100.0, 10.0, 0.1);
|
||||||
|
|
||||||
|
m_spinPointSize->SetInitialSize
|
||||||
|
(
|
||||||
|
m_spinPointSize->GetSizeFromTextSize(GetTextExtent("999.9").x)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Must be in sync with the Style enum.
|
||||||
|
const wxString stylesNames[] =
|
||||||
|
{
|
||||||
|
"Normal",
|
||||||
|
"Italic",
|
||||||
|
"Slant",
|
||||||
|
};
|
||||||
|
|
||||||
|
m_choiceStyle = new wxChoice(this, wxID_ANY,
|
||||||
|
wxDefaultPosition, wxDefaultSize,
|
||||||
|
WXSIZEOF(stylesNames), stylesNames);
|
||||||
|
|
||||||
|
// Must be in sync with the Weight enum.
|
||||||
|
const wxString weightsNames[] =
|
||||||
|
{
|
||||||
|
"Thin",
|
||||||
|
"Extra light",
|
||||||
|
"Light",
|
||||||
|
"Normal",
|
||||||
|
"Medium",
|
||||||
|
"Semi-bold",
|
||||||
|
"Bold",
|
||||||
|
"Extra bold",
|
||||||
|
"Heavy",
|
||||||
|
"Extra heavy",
|
||||||
|
};
|
||||||
|
|
||||||
|
m_choiceWeight = new wxChoice(this, wxID_ANY,
|
||||||
|
wxDefaultPosition, wxDefaultSize,
|
||||||
|
WXSIZEOF(weightsNames), weightsNames);
|
||||||
|
m_choiceWeight->Bind(wxEVT_CHOICE, &FontPanel::OnWeightChoice, this);
|
||||||
|
|
||||||
|
m_spinWeight = new wxSpinCtrl(this, wxID_ANY, wxString(),
|
||||||
|
wxDefaultPosition, wxDefaultSize,
|
||||||
|
wxSP_ARROW_KEYS,
|
||||||
|
1, wxFONTWEIGHT_MAX);
|
||||||
|
m_spinWeight->SetInitialSize
|
||||||
|
(
|
||||||
|
m_spinWeight->GetSizeFromTextSize(GetTextExtent("9999").x)
|
||||||
|
);
|
||||||
|
m_spinWeight->Bind(wxEVT_SPINCTRL, &FontPanel::OnWeightSpin, this);
|
||||||
|
|
||||||
|
m_checkUnderlined = new wxCheckBox(this, wxID_ANY, wxString());
|
||||||
|
m_checkStrikethrough = new wxCheckBox(this, wxID_ANY, wxString());
|
||||||
|
m_checkFixedWidth = new wxCheckBox(this, wxID_ANY, wxString());
|
||||||
|
m_checkFixedWidth->Disable(); // Can't be changed by the user.
|
||||||
|
|
||||||
|
m_labelInfo = new wxStaticText(this, wxID_ANY, "\n\n\n");
|
||||||
|
|
||||||
|
|
||||||
|
const int border = wxSizerFlags::GetDefaultBorder();
|
||||||
|
|
||||||
|
// Columns are: label, control, gap, label, control, label, control (there
|
||||||
|
// is no second gap column because we don't want any gap in the weight row).
|
||||||
|
wxFlexGridSizer* const sizer = new wxFlexGridSizer(7, wxSize(border, border));
|
||||||
|
|
||||||
|
const wxSizerFlags flagsLabel = wxSizerFlags().CentreVertical();
|
||||||
|
const wxSizerFlags flagsValue = wxSizerFlags().Expand().CentreVertical();
|
||||||
|
|
||||||
|
sizer->Add(new wxStaticText(this, wxID_ANY, "Face &name:"), flagsLabel);
|
||||||
|
sizer->Add(m_textFaceName, flagsValue);
|
||||||
|
|
||||||
|
sizer->AddSpacer(2*border);
|
||||||
|
|
||||||
|
sizer->Add(new wxStaticText(this, wxID_ANY, "&Family:"), flagsLabel);
|
||||||
|
sizer->Add(m_choiceFamily, flagsValue);
|
||||||
|
|
||||||
|
sizer->Add(new wxStaticText(this, wxID_ANY, "&Point size:"),
|
||||||
|
wxSizerFlags().DoubleBorder(wxLEFT).CentreVertical());
|
||||||
|
sizer->Add(m_spinPointSize, flagsValue);
|
||||||
|
|
||||||
|
|
||||||
|
sizer->Add(new wxStaticText(this, wxID_ANY, "&Style:"), flagsLabel);
|
||||||
|
sizer->Add(m_choiceStyle, flagsValue);
|
||||||
|
|
||||||
|
sizer->AddSpacer(0);
|
||||||
|
|
||||||
|
sizer->Add(new wxStaticText(this, wxID_ANY, "&Weight:"), flagsLabel);
|
||||||
|
sizer->Add(m_choiceWeight, flagsValue);
|
||||||
|
|
||||||
|
sizer->Add(new wxStaticText(this, wxID_ANY, "or &raw value:"), flagsLabel);
|
||||||
|
sizer->Add(m_spinWeight, flagsValue);
|
||||||
|
|
||||||
|
|
||||||
|
sizer->Add(new wxStaticText(this, wxID_ANY, "&Underlined:"), flagsLabel);
|
||||||
|
sizer->Add(m_checkUnderlined, flagsValue);
|
||||||
|
|
||||||
|
sizer->AddSpacer(0);
|
||||||
|
|
||||||
|
sizer->Add(new wxStaticText(this, wxID_ANY, "&Strike through:"), flagsLabel);
|
||||||
|
sizer->Add(m_checkStrikethrough, flagsValue);
|
||||||
|
|
||||||
|
sizer->Add(new wxStaticText(this, wxID_ANY, "Fixed width:"), flagsLabel);
|
||||||
|
sizer->Add(m_checkFixedWidth, flagsValue);
|
||||||
|
|
||||||
|
wxSizer* const sizerTop = new wxBoxSizer(wxVERTICAL);
|
||||||
|
sizerTop->Add(sizer, wxSizerFlags().Expand().Border(wxBOTTOM));
|
||||||
|
sizerTop->Add(new wxButton(this, wxID_APPLY, "&Apply changes"),
|
||||||
|
wxSizerFlags().Border(wxBOTTOM).Centre());
|
||||||
|
sizerTop->Add(m_labelInfo, wxSizerFlags().Expand().Border(wxTOP));
|
||||||
|
SetSizer(sizerTop);
|
||||||
|
|
||||||
|
ShowFont(*wxNORMAL_FONT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FontPanel::DoUpdate()
|
||||||
|
{
|
||||||
|
m_textFaceName->ChangeValue(m_font.GetFaceName());
|
||||||
|
|
||||||
|
Family family = Family_Default;
|
||||||
|
switch ( m_font.GetFamily() )
|
||||||
|
{
|
||||||
|
case wxFONTFAMILY_DECORATIVE: family = Family_Decorative; break;
|
||||||
|
case wxFONTFAMILY_ROMAN: family = Family_Roman; break;
|
||||||
|
case wxFONTFAMILY_SCRIPT: family = Family_Script; break;
|
||||||
|
case wxFONTFAMILY_SWISS: family = Family_Swiss; break;
|
||||||
|
case wxFONTFAMILY_MODERN: family = Family_Modern; break;
|
||||||
|
case wxFONTFAMILY_TELETYPE: family = Family_Teletype; break;
|
||||||
|
|
||||||
|
case wxFONTFAMILY_DEFAULT:
|
||||||
|
case wxFONTFAMILY_UNKNOWN:
|
||||||
|
// Leave family as Family_Default, what else can we do.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
m_choiceFamily->SetSelection(family);
|
||||||
|
|
||||||
|
m_spinPointSize->SetValue(m_font.GetFractionalPointSize());
|
||||||
|
|
||||||
|
Style style = Style_Normal;
|
||||||
|
switch ( m_font.GetStyle() )
|
||||||
|
{
|
||||||
|
case wxFONTSTYLE_ITALIC: style = Style_Italic; break;
|
||||||
|
case wxFONTSTYLE_SLANT: style = Style_Slant; break;
|
||||||
|
|
||||||
|
case wxFONTSTYLE_NORMAL:
|
||||||
|
case wxFONTSTYLE_MAX:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
m_choiceStyle->SetSelection(style);
|
||||||
|
|
||||||
|
Weight weight = Weight_Normal;
|
||||||
|
switch ( m_font.GetWeight() )
|
||||||
|
{
|
||||||
|
case wxFONTWEIGHT_THIN: weight = Weight_Thin; break;
|
||||||
|
case wxFONTWEIGHT_EXTRALIGHT: weight = Weight_Extralight; break;
|
||||||
|
case wxFONTWEIGHT_LIGHT: weight = Weight_Light; break;
|
||||||
|
case wxFONTWEIGHT_MEDIUM: weight = Weight_Medium; break;
|
||||||
|
case wxFONTWEIGHT_SEMIBOLD: weight = Weight_Semibold; break;
|
||||||
|
case wxFONTWEIGHT_BOLD: weight = Weight_Bold; break;
|
||||||
|
case wxFONTWEIGHT_EXTRABOLD: weight = Weight_Extrabold; break;
|
||||||
|
case wxFONTWEIGHT_HEAVY: weight = Weight_Heavy; break;
|
||||||
|
case wxFONTWEIGHT_EXTRAHEAVY: weight = Weight_Extraheavy; break;
|
||||||
|
|
||||||
|
case wxFONTWEIGHT_NORMAL:
|
||||||
|
case wxFONTWEIGHT_INVALID:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
m_choiceWeight->SetSelection(weight);
|
||||||
|
m_spinWeight->SetValue(m_font.GetNumericWeight());
|
||||||
|
|
||||||
|
m_checkUnderlined->SetValue(m_font.GetUnderlined());
|
||||||
|
m_checkStrikethrough->SetValue(m_font.GetStrikethrough());
|
||||||
|
m_checkFixedWidth->SetValue(m_font.IsFixedWidth());
|
||||||
|
|
||||||
|
const wxSize pixelSize = m_font.GetPixelSize();
|
||||||
|
wxClientDC dc(this);
|
||||||
|
dc.SetFont(m_font);
|
||||||
|
|
||||||
|
m_labelInfo->SetLabelText
|
||||||
|
(
|
||||||
|
wxString::Format
|
||||||
|
(
|
||||||
|
"Font info string: %s\n"
|
||||||
|
"Size in pixels: %d*%d, "
|
||||||
|
"average char size: %d*%d",
|
||||||
|
m_font.GetNativeFontInfoDesc(),
|
||||||
|
pixelSize.x, pixelSize.y,
|
||||||
|
dc.GetCharWidth(), dc.GetCharHeight()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxFontInfo FontPanel::GetFontInfo() const
|
||||||
|
{
|
||||||
|
wxFontInfo info(m_spinPointSize->GetValue());
|
||||||
|
|
||||||
|
if ( m_useFamily )
|
||||||
|
{
|
||||||
|
const wxFontFamily families[] =
|
||||||
|
{
|
||||||
|
wxFONTFAMILY_DEFAULT,
|
||||||
|
wxFONTFAMILY_DECORATIVE,
|
||||||
|
wxFONTFAMILY_ROMAN,
|
||||||
|
wxFONTFAMILY_SCRIPT,
|
||||||
|
wxFONTFAMILY_SWISS,
|
||||||
|
wxFONTFAMILY_MODERN,
|
||||||
|
wxFONTFAMILY_TELETYPE,
|
||||||
|
};
|
||||||
|
info.Family(families[m_choiceFamily->GetSelection()]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
info.FaceName(m_textFaceName->GetValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ( m_choiceStyle->GetSelection() )
|
||||||
|
{
|
||||||
|
case Style_Normal:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Style_Italic:
|
||||||
|
info.Italic();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Style_Slant:
|
||||||
|
info.Slant();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
info.Weight(m_useNumericWeight ? m_spinWeight->GetValue()
|
||||||
|
: (m_choiceWeight->GetSelection() + 1)*100);
|
||||||
|
|
||||||
|
if ( m_checkUnderlined->GetValue() )
|
||||||
|
info.Underlined();
|
||||||
|
if ( m_checkStrikethrough->GetValue() )
|
||||||
|
info.Strikethrough();
|
||||||
|
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// FontCanvas
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxBEGIN_EVENT_TABLE(FontCanvas, wxWindow)
|
||||||
|
EVT_PAINT(FontCanvas::OnPaint)
|
||||||
wxEND_EVENT_TABLE()
|
wxEND_EVENT_TABLE()
|
||||||
|
|
||||||
MyCanvas::MyCanvas( wxWindow *parent )
|
FontCanvas::FontCanvas( wxWindow *parent )
|
||||||
: wxWindow( parent, wxID_ANY ),
|
: wxWindow( parent, wxID_ANY ),
|
||||||
m_colour(*wxRED), m_font(*wxNORMAL_FONT)
|
m_colour(*wxRED), m_font(*wxNORMAL_FONT)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
void FontCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
||||||
{
|
{
|
||||||
wxPaintDC dc(this);
|
wxPaintDC dc(this);
|
||||||
PrepareDC(dc);
|
PrepareDC(dc);
|
||||||
@@ -1094,55 +1487,10 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
|||||||
dc.Clear();
|
dc.Clear();
|
||||||
dc.SetFont(m_font);
|
dc.SetFont(m_font);
|
||||||
|
|
||||||
// one text line height
|
|
||||||
wxCoord hLine = dc.GetCharHeight();
|
|
||||||
|
|
||||||
// the current text origin
|
// the current text origin
|
||||||
wxCoord x = 5,
|
wxCoord x = 5,
|
||||||
y = 5;
|
y = 5;
|
||||||
|
|
||||||
// output the font name/info
|
|
||||||
wxString fontInfo;
|
|
||||||
|
|
||||||
fontInfo.Printf(wxT("Face name: %s, family: %s"),
|
|
||||||
m_font.GetFaceName().c_str(),
|
|
||||||
m_font.GetFamilyString().c_str());
|
|
||||||
|
|
||||||
dc.DrawText(fontInfo, x, y);
|
|
||||||
y += hLine;
|
|
||||||
|
|
||||||
fontInfo.Printf(wxT("Size: %d points or %d pixels; %d*%d average char size"),
|
|
||||||
m_font.GetPointSize(),
|
|
||||||
m_font.GetPixelSize().y,
|
|
||||||
dc.GetCharWidth(), dc.GetCharHeight());
|
|
||||||
|
|
||||||
dc.DrawText(fontInfo, x, y);
|
|
||||||
y += hLine;
|
|
||||||
|
|
||||||
fontInfo.Printf(wxT("Style: %s, weight: %s, fixed width: %s, encoding: %s"),
|
|
||||||
m_font.GetStyleString().c_str(),
|
|
||||||
m_font.GetWeightString().c_str(),
|
|
||||||
m_font.IsFixedWidth() ? wxT("yes") : wxT("no"),
|
|
||||||
wxFontMapper::GetEncodingDescription(m_font.GetEncoding()));
|
|
||||||
|
|
||||||
dc.DrawText(fontInfo, x, y);
|
|
||||||
y += hLine;
|
|
||||||
|
|
||||||
if ( m_font.IsOk() )
|
|
||||||
{
|
|
||||||
const wxNativeFontInfo *info = m_font.GetNativeFontInfo();
|
|
||||||
if ( info )
|
|
||||||
{
|
|
||||||
wxString fontDesc = m_font.GetNativeFontInfoUserDesc();
|
|
||||||
fontInfo.Printf(wxT("Native font info: %s"), fontDesc.c_str());
|
|
||||||
|
|
||||||
dc.DrawText(fontInfo, x, y);
|
|
||||||
y += hLine;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
y += hLine;
|
|
||||||
|
|
||||||
// prepare to draw the font
|
// prepare to draw the font
|
||||||
dc.SetTextForeground(m_colour);
|
dc.SetTextForeground(m_colour);
|
||||||
|
|
||||||
|
@@ -244,8 +244,7 @@ MyFrame::MyFrame(const wxString& title)
|
|||||||
wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL);
|
wxTE_MULTILINE|wxTE_READONLY|wxHSCROLL);
|
||||||
|
|
||||||
// set monospace font to have output in nice columns
|
// set monospace font to have output in nice columns
|
||||||
wxFont font(9, wxFONTFAMILY_TELETYPE,
|
wxFont font(wxFontInfo(9).Family(wxFONTFAMILY_TELETYPE));
|
||||||
wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
|
|
||||||
headerText->SetFont(font);
|
headerText->SetFont(font);
|
||||||
m_evtConsole->SetFont(font);
|
m_evtConsole->SetFont(font);
|
||||||
|
|
||||||
|
@@ -206,8 +206,7 @@ MyFrame::MyFrame(const wxString& title)
|
|||||||
wxTE_MULTILINE|wxTE_READONLY|wxTE_RICH|wxHSCROLL);
|
wxTE_MULTILINE|wxTE_READONLY|wxTE_RICH|wxHSCROLL);
|
||||||
|
|
||||||
// set monospace font to have output in nice columns
|
// set monospace font to have output in nice columns
|
||||||
wxFont font(10, wxFONTFAMILY_TELETYPE,
|
wxFont font(wxFontInfo(10).Family(wxFONTFAMILY_TELETYPE));
|
||||||
wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
|
|
||||||
headerText->SetFont(font);
|
headerText->SetFont(font);
|
||||||
m_logText->SetFont(font);
|
m_logText->SetFont(font);
|
||||||
|
|
||||||
|
@@ -489,7 +489,7 @@ bool MyGLCanvas::oglInit()
|
|||||||
int swi = 0, shi = 0; //Image sizes
|
int swi = 0, shi = 0; //Image sizes
|
||||||
wxString stg("wxWidgets");
|
wxString stg("wxWidgets");
|
||||||
// Set the font. Use a big pointsize so as to smoothing edges.
|
// Set the font. Use a big pointsize so as to smoothing edges.
|
||||||
wxFont font(48, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
|
wxFont font(wxFontInfo(48).Family(wxFONTFAMILY_MODERN));
|
||||||
if ( !font.IsOk() )
|
if ( !font.IsOk() )
|
||||||
font = *wxSWISS_FONT;
|
font = *wxSWISS_FONT;
|
||||||
wxColour bgrdColo(*wxBLACK);
|
wxColour bgrdColo(*wxBLACK);
|
||||||
|
@@ -387,7 +387,7 @@ MyFrame::MyFrame()
|
|||||||
sizer_panelsizer_h->Add(sizer_panelsizer_v, 0);
|
sizer_panelsizer_h->Add(sizer_panelsizer_v, 0);
|
||||||
sizer_panel->SetSizer(sizer_panelsizer_h);
|
sizer_panel->SetSizer(sizer_panelsizer_h);
|
||||||
|
|
||||||
wxFont label_font(8, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_LIGHT);
|
wxFont label_font(wxFontInfo(8).Light());
|
||||||
m_bitmap_creation_dc.SetFont(label_font);
|
m_bitmap_creation_dc.SetFont(label_font);
|
||||||
|
|
||||||
wxRibbonPage* scheme = new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Appearance"), eye_xpm);
|
wxRibbonPage* scheme = new wxRibbonPage(m_ribbon, wxID_ANY, wxT("Appearance"), eye_xpm);
|
||||||
|
@@ -248,7 +248,7 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|||||||
text->SetBackgroundColour(*wxWHITE);
|
text->SetBackgroundColour(*wxWHITE);
|
||||||
text->SetForegroundColour(*wxBLACK);
|
text->SetForegroundColour(*wxBLACK);
|
||||||
wxFont font = text->GetFont();
|
wxFont font = text->GetFont();
|
||||||
font.SetPointSize(2*font.GetPointSize()/3);
|
font.SetFractionalPointSize(2.0*font.GetFractionalPointSize()/3.0);
|
||||||
text->SetFont(font);
|
text->SetFont(font);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@@ -402,8 +402,7 @@ MyFrame::MyFrame(const wxString& title)
|
|||||||
wxLog::SetActiveTarget(this);
|
wxLog::SetActiveTarget(this);
|
||||||
|
|
||||||
// use fixed width font to align output in nice columns
|
// use fixed width font to align output in nice columns
|
||||||
wxFont font(wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_TELETYPE,
|
wxFont font(wxFontInfo().Family(wxFONTFAMILY_TELETYPE));
|
||||||
wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
|
|
||||||
header->SetFont(font);
|
header->SetFont(font);
|
||||||
m_txtctrl->SetFont(font);
|
m_txtctrl->SetFont(font);
|
||||||
|
|
||||||
|
@@ -347,7 +347,6 @@
|
|||||||
<object class="sizeritem">
|
<object class="sizeritem">
|
||||||
<flag>wxGROW|wxALL</flag>
|
<flag>wxGROW|wxALL</flag>
|
||||||
<border>5</border>
|
<border>5</border>
|
||||||
<option>1</option>
|
|
||||||
<object class="wxCollapsiblePane" name="controls_collpane">
|
<object class="wxCollapsiblePane" name="controls_collpane">
|
||||||
<label>Details:</label>
|
<label>Details:</label>
|
||||||
<collapsed>0</collapsed>
|
<collapsed>0</collapsed>
|
||||||
@@ -1096,6 +1095,24 @@ lay them out using wxSizers, absolute positioning, everything you like!
|
|||||||
<label>It was a dark and stormy night.</label>
|
<label>It was a dark and stormy night.</label>
|
||||||
</object>
|
</object>
|
||||||
</object>
|
</object>
|
||||||
|
<object class="sizeritem">
|
||||||
|
<flag>wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL|wxALL</flag>
|
||||||
|
<border>5</border>
|
||||||
|
<object class="wxStaticText" name="wxID_STATIC">
|
||||||
|
<label>Slightly larger strikethrough font:</label>
|
||||||
|
</object>
|
||||||
|
</object>
|
||||||
|
<object class="sizeritem">
|
||||||
|
<flag>wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL</flag>
|
||||||
|
<border>5</border>
|
||||||
|
<object class="wxStaticText" name="controls_statictext">
|
||||||
|
<label>It was a dark and stormy night.</label>
|
||||||
|
<font>
|
||||||
|
<size>12.5</size>
|
||||||
|
<strikethrough>1</strikethrough>
|
||||||
|
</font>
|
||||||
|
</object>
|
||||||
|
</object>
|
||||||
<object class="sizeritem">
|
<object class="sizeritem">
|
||||||
<flag>wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL|wxALL</flag>
|
<flag>wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL|wxALL</flag>
|
||||||
<border>5</border>
|
<border>5</border>
|
||||||
@@ -1127,7 +1144,7 @@ lay them out using wxSizers, absolute positioning, everything you like!
|
|||||||
<label>It was a dark and stormy night.</label>
|
<label>It was a dark and stormy night.</label>
|
||||||
<font>
|
<font>
|
||||||
<inherit>1</inherit>
|
<inherit>1</inherit>
|
||||||
<weight>bold</weight>
|
<weight>700</weight> <!-- same as "bold" -->
|
||||||
</font>
|
</font>
|
||||||
</object>
|
</object>
|
||||||
</object>
|
</object>
|
||||||
@@ -1494,7 +1511,6 @@ lay them out using wxSizers, absolute positioning, everything you like!
|
|||||||
</object>
|
</object>
|
||||||
<object class="sizeritem">
|
<object class="sizeritem">
|
||||||
<flag>wxGROW|wxALL</flag>
|
<flag>wxGROW|wxALL</flag>
|
||||||
<option>1</option>
|
|
||||||
<border>5</border>
|
<border>5</border>
|
||||||
<object class="wxColourPickerCtrl" name="controls_colourpicker">
|
<object class="wxColourPickerCtrl" name="controls_colourpicker">
|
||||||
<value>#00ff00</value>
|
<value>#00ff00</value>
|
||||||
@@ -1510,7 +1526,6 @@ lay them out using wxSizers, absolute positioning, everything you like!
|
|||||||
</object>
|
</object>
|
||||||
<object class="sizeritem">
|
<object class="sizeritem">
|
||||||
<flag>wxGROW|wxALL</flag>
|
<flag>wxGROW|wxALL</flag>
|
||||||
<option>1</option>
|
|
||||||
<border>5</border>
|
<border>5</border>
|
||||||
<object class="wxFilePickerCtrl" name="controls_filepicker">
|
<object class="wxFilePickerCtrl" name="controls_filepicker">
|
||||||
<message>Here goes a message</message>
|
<message>Here goes a message</message>
|
||||||
@@ -1528,7 +1543,6 @@ lay them out using wxSizers, absolute positioning, everything you like!
|
|||||||
</object>
|
</object>
|
||||||
<object class="sizeritem">
|
<object class="sizeritem">
|
||||||
<flag>wxGROW|wxALL</flag>
|
<flag>wxGROW|wxALL</flag>
|
||||||
<option>1</option>
|
|
||||||
<border>5</border>
|
<border>5</border>
|
||||||
<object class="wxDirPickerCtrl" name="controls_dirpicker">
|
<object class="wxDirPickerCtrl" name="controls_dirpicker">
|
||||||
<value/>
|
<value/>
|
||||||
@@ -1545,7 +1559,6 @@ lay them out using wxSizers, absolute positioning, everything you like!
|
|||||||
</object>
|
</object>
|
||||||
<object class="sizeritem">
|
<object class="sizeritem">
|
||||||
<flag>wxGROW|wxALL</flag>
|
<flag>wxGROW|wxALL</flag>
|
||||||
<option>1</option>
|
|
||||||
<border>5</border>
|
<border>5</border>
|
||||||
<object class="wxFontPickerCtrl" name="controls_fontpicker">
|
<object class="wxFontPickerCtrl" name="controls_fontpicker">
|
||||||
<style>wxFNTP_USEFONT_FOR_LABEL</style>
|
<style>wxFNTP_USEFONT_FOR_LABEL</style>
|
||||||
|
@@ -28,7 +28,6 @@
|
|||||||
#ifndef WX_PRECOMP
|
#ifndef WX_PRECOMP
|
||||||
#include "wx/dc.h"
|
#include "wx/dc.h"
|
||||||
#include "wx/intl.h"
|
#include "wx/intl.h"
|
||||||
#include "wx/math.h"
|
|
||||||
#include "wx/dcscreen.h"
|
#include "wx/dcscreen.h"
|
||||||
#include "wx/log.h"
|
#include "wx/log.h"
|
||||||
#include "wx/gdicmn.h"
|
#include "wx/gdicmn.h"
|
||||||
@@ -51,20 +50,12 @@ extern const char *wxDumpFont(const wxFont *font)
|
|||||||
{
|
{
|
||||||
static char buf[256];
|
static char buf[256];
|
||||||
|
|
||||||
const wxFontWeight weight = font->GetWeight();
|
|
||||||
|
|
||||||
wxString s;
|
wxString s;
|
||||||
s.Printf(wxS("%s-%s-%s-%d-%d"),
|
s.Printf(wxS("%s-%d-%s-%.2f-%d"),
|
||||||
font->GetFaceName(),
|
font->GetFaceName(),
|
||||||
weight == wxFONTWEIGHT_NORMAL
|
font->GetNumericWeight(),
|
||||||
? wxT("normal")
|
font->GetStyle() == wxFONTSTYLE_NORMAL ? "regular" : "italic",
|
||||||
: weight == wxFONTWEIGHT_BOLD
|
font->GetFractionalPointSize(),
|
||||||
? wxT("bold")
|
|
||||||
: wxT("light"),
|
|
||||||
font->GetStyle() == wxFONTSTYLE_NORMAL
|
|
||||||
? wxT("regular")
|
|
||||||
: wxT("italic"),
|
|
||||||
font->GetPointSize(),
|
|
||||||
font->GetEncoding());
|
font->GetEncoding());
|
||||||
|
|
||||||
wxStrlcpy(buf, s.mb_str(), WXSIZEOF(buf));
|
wxStrlcpy(buf, s.mb_str(), WXSIZEOF(buf));
|
||||||
@@ -232,9 +223,36 @@ bool wxFontBase::IsFixedWidth() const
|
|||||||
return GetFamily() == wxFONTFAMILY_TELETYPE;
|
return GetFamily() == wxFONTFAMILY_TELETYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Convert to/from wxFontWeight enum elements and numeric weight values.
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
int wxFontBase::ConvertFromLegacyWeightIfNecessary(int weight)
|
||||||
|
{
|
||||||
|
switch ( weight )
|
||||||
|
{
|
||||||
|
case 90: return wxFONTWEIGHT_NORMAL;
|
||||||
|
case 91: return wxFONTWEIGHT_LIGHT;
|
||||||
|
case 92: return wxFONTWEIGHT_BOLD;
|
||||||
|
default: return weight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
int wxFontBase::GetNumericWeightOf(wxFontWeight weight_)
|
||||||
|
{
|
||||||
|
const int weight = ConvertFromLegacyWeightIfNecessary(weight_);
|
||||||
|
|
||||||
|
wxASSERT(weight > wxFONTWEIGHT_INVALID);
|
||||||
|
wxASSERT(weight <= wxFONTWEIGHT_MAX);
|
||||||
|
wxASSERT(weight % 100 == 0);
|
||||||
|
|
||||||
|
return weight;
|
||||||
|
}
|
||||||
|
|
||||||
int wxFontBase::GetPointSize() const
|
int wxFontBase::GetPointSize() const
|
||||||
{
|
{
|
||||||
return wxRound(GetFractionalPointSize());
|
return wxFontInfo::ToIntPointSize(GetFractionalPointSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -245,11 +263,23 @@ wxSize wxFontBase::GetPixelSize() const
|
|||||||
return wxSize(dc.GetCharWidth(), dc.GetCharHeight());
|
return wxSize(dc.GetCharWidth(), dc.GetCharHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxFontWeight wxFontBase::GetWeight() const
|
||||||
|
{
|
||||||
|
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, "invalid font" );
|
||||||
|
|
||||||
|
return wxFontInfo::GetWeightClosestToNumericValue(GetNumericWeight());
|
||||||
|
}
|
||||||
|
|
||||||
bool wxFontBase::IsUsingSizeInPixels() const
|
bool wxFontBase::IsUsingSizeInPixels() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxFontBase::SetPointSize(int pointSize)
|
||||||
|
{
|
||||||
|
SetFractionalPointSize(wxFontInfo::ToFloatPointSize(pointSize));
|
||||||
|
}
|
||||||
|
|
||||||
void wxFontBase::SetPixelSize( const wxSize& pixelSize )
|
void wxFontBase::SetPixelSize( const wxSize& pixelSize )
|
||||||
{
|
{
|
||||||
wxCHECK_RET( pixelSize.GetWidth() >= 0 && pixelSize.GetHeight() > 0,
|
wxCHECK_RET( pixelSize.GetWidth() >= 0 && pixelSize.GetHeight() > 0,
|
||||||
@@ -313,13 +343,18 @@ void wxFontBase::SetPixelSize( const wxSize& pixelSize )
|
|||||||
SetPointSize(largestGood);
|
SetPointSize(largestGood);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxFontBase::SetWeight(wxFontWeight weight)
|
||||||
|
{
|
||||||
|
SetNumericWeight(GetNumericWeightOf(weight));
|
||||||
|
}
|
||||||
|
|
||||||
void wxFontBase::DoSetNativeFontInfo(const wxNativeFontInfo& info)
|
void wxFontBase::DoSetNativeFontInfo(const wxNativeFontInfo& info)
|
||||||
{
|
{
|
||||||
#ifdef wxNO_NATIVE_FONTINFO
|
#ifdef wxNO_NATIVE_FONTINFO
|
||||||
SetPointSize(info.pointSize);
|
SetFractionalPointSize(info.pointSize);
|
||||||
SetFamily(info.family);
|
SetFamily(info.family);
|
||||||
SetStyle(info.style);
|
SetStyle(info.style);
|
||||||
SetWeight(info.weight);
|
SetNumericWeight(info.weight);
|
||||||
SetUnderlined(info.underlined);
|
SetUnderlined(info.underlined);
|
||||||
SetStrikethrough(info.strikethrough);
|
SetStrikethrough(info.strikethrough);
|
||||||
SetFaceName(info.faceName);
|
SetFaceName(info.faceName);
|
||||||
@@ -497,6 +532,74 @@ bool wxFontBase::SetFaceName(const wxString& facename)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
void InitInfoWithLegacyParams(wxFontInfo& info,
|
||||||
|
wxFontFamily family,
|
||||||
|
wxFontStyle style,
|
||||||
|
wxFontWeight weight,
|
||||||
|
bool underlined,
|
||||||
|
const wxString& face,
|
||||||
|
wxFontEncoding encoding)
|
||||||
|
{
|
||||||
|
if ( static_cast<int>(style) == wxDEFAULT )
|
||||||
|
style = wxFONTSTYLE_NORMAL;
|
||||||
|
|
||||||
|
if ( static_cast<int>(weight) == wxDEFAULT )
|
||||||
|
weight = wxFONTWEIGHT_NORMAL;
|
||||||
|
|
||||||
|
info
|
||||||
|
.Family(family)
|
||||||
|
.Style(style)
|
||||||
|
.Weight(wxFontBase::GetNumericWeightOf(weight))
|
||||||
|
.Underlined(underlined)
|
||||||
|
.FaceName(face)
|
||||||
|
.Encoding(encoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
wxFontInfo wxFontBase::InfoFromLegacyParams(int pointSize,
|
||||||
|
wxFontFamily family,
|
||||||
|
wxFontStyle style,
|
||||||
|
wxFontWeight weight,
|
||||||
|
bool underlined,
|
||||||
|
const wxString& face,
|
||||||
|
wxFontEncoding encoding)
|
||||||
|
{
|
||||||
|
// Old code specifies wxDEFAULT instead of -1 or wxNORMAL instead of the
|
||||||
|
// new type-safe wxFONTSTYLE_NORMAL or wxFONTWEIGHT_NORMAL, continue
|
||||||
|
// handling this for compatibility.
|
||||||
|
if ( pointSize == wxDEFAULT )
|
||||||
|
pointSize = -1;
|
||||||
|
|
||||||
|
wxFontInfo info(pointSize);
|
||||||
|
|
||||||
|
InitInfoWithLegacyParams(info,
|
||||||
|
family, style, weight, underlined, face, encoding);
|
||||||
|
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
wxFontInfo wxFontBase::InfoFromLegacyParams(const wxSize& pixelSize,
|
||||||
|
wxFontFamily family,
|
||||||
|
wxFontStyle style,
|
||||||
|
wxFontWeight weight,
|
||||||
|
bool underlined,
|
||||||
|
const wxString& face,
|
||||||
|
wxFontEncoding encoding)
|
||||||
|
{
|
||||||
|
wxFontInfo info(pixelSize);
|
||||||
|
|
||||||
|
InitInfoWithLegacyParams(info,
|
||||||
|
family, style, weight, underlined, face, encoding);
|
||||||
|
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
void wxFontBase::SetSymbolicSize(wxFontSymbolicSize size)
|
void wxFontBase::SetSymbolicSize(wxFontSymbolicSize size)
|
||||||
{
|
{
|
||||||
SetSymbolicSizeRelativeTo(size, wxNORMAL_FONT->GetPointSize());
|
SetSymbolicSizeRelativeTo(size, wxNORMAL_FONT->GetPointSize());
|
||||||
@@ -584,7 +687,7 @@ wxFont& wxFont::MakeStrikethrough()
|
|||||||
|
|
||||||
wxFont& wxFont::Scale(float x)
|
wxFont& wxFont::Scale(float x)
|
||||||
{
|
{
|
||||||
SetPointSize(int(x*GetPointSize() + 0.5));
|
SetFractionalPointSize(x*GetFractionalPointSize());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -621,6 +724,15 @@ void wxNativeFontInfo::SetFaceName(const wxArrayString& facenames)
|
|||||||
#endif // wxUSE_FONTENUM/!wxUSE_FONTENUM
|
#endif // wxUSE_FONTENUM/!wxUSE_FONTENUM
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int wxNativeFontInfo::GetPointSize() const
|
||||||
|
{
|
||||||
|
return wxFontInfo::ToIntPointSize(GetFractionalPointSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxNativeFontInfo::SetPointSize(int pointsize)
|
||||||
|
{
|
||||||
|
SetFractionalPointSize(wxFontInfo::ToFloatPointSize(pointsize));
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef wxNO_NATIVE_FONTINFO
|
#ifdef wxNO_NATIVE_FONTINFO
|
||||||
|
|
||||||
@@ -635,6 +747,7 @@ void wxNativeFontInfo::SetFaceName(const wxArrayString& facenames)
|
|||||||
bool wxNativeFontInfo::FromString(const wxString& s)
|
bool wxNativeFontInfo::FromString(const wxString& s)
|
||||||
{
|
{
|
||||||
long l;
|
long l;
|
||||||
|
double d;
|
||||||
unsigned long version;
|
unsigned long version;
|
||||||
|
|
||||||
wxStringTokenizer tokenizer(s, wxT(";"));
|
wxStringTokenizer tokenizer(s, wxT(";"));
|
||||||
@@ -644,9 +757,11 @@ bool wxNativeFontInfo::FromString(const wxString& s)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
token = tokenizer.GetNextToken();
|
token = tokenizer.GetNextToken();
|
||||||
if ( !token.ToLong(&l) )
|
if ( !token.ToCDouble(&d) )
|
||||||
|
return false;
|
||||||
|
pointSize = static_cast<float>(d);
|
||||||
|
if ( static_cast<double>(pointSize) != d )
|
||||||
return false;
|
return false;
|
||||||
pointSize = (int)l;
|
|
||||||
|
|
||||||
token = tokenizer.GetNextToken();
|
token = tokenizer.GetNextToken();
|
||||||
if ( !token.ToLong(&l) )
|
if ( !token.ToLong(&l) )
|
||||||
@@ -661,7 +776,9 @@ bool wxNativeFontInfo::FromString(const wxString& s)
|
|||||||
token = tokenizer.GetNextToken();
|
token = tokenizer.GetNextToken();
|
||||||
if ( !token.ToLong(&l) )
|
if ( !token.ToLong(&l) )
|
||||||
return false;
|
return false;
|
||||||
weight = (wxFontWeight)l;
|
weight = ConvertFromLegacyWeightIfNecessary(l);
|
||||||
|
if ( weight <= wxFONTWEIGHT_INVALID || weight > wxFONTWEIGHT_MAX )
|
||||||
|
return false;
|
||||||
|
|
||||||
token = tokenizer.GetNextToken();
|
token = tokenizer.GetNextToken();
|
||||||
if ( !token.ToLong(&l) )
|
if ( !token.ToLong(&l) )
|
||||||
@@ -695,12 +812,12 @@ wxString wxNativeFontInfo::ToString() const
|
|||||||
{
|
{
|
||||||
wxString s;
|
wxString s;
|
||||||
|
|
||||||
s.Printf(wxT("%d;%d;%d;%d;%d;%d;%d;%s;%d"),
|
s.Printf(wxT("%d;%f;%d;%d;%d;%d;%d;%s;%d"),
|
||||||
1, // version
|
1, // version
|
||||||
pointSize,
|
GetFractionalPointSize(),
|
||||||
family,
|
family,
|
||||||
(int)style,
|
(int)style,
|
||||||
(int)weight,
|
weight,
|
||||||
underlined,
|
underlined,
|
||||||
strikethrough,
|
strikethrough,
|
||||||
faceName.GetData(),
|
faceName.GetData(),
|
||||||
@@ -711,7 +828,7 @@ wxString wxNativeFontInfo::ToString() const
|
|||||||
|
|
||||||
void wxNativeFontInfo::Init()
|
void wxNativeFontInfo::Init()
|
||||||
{
|
{
|
||||||
pointSize = 0;
|
pointSize = 0.0f;
|
||||||
family = wxFONTFAMILY_DEFAULT;
|
family = wxFONTFAMILY_DEFAULT;
|
||||||
style = wxFONTSTYLE_NORMAL;
|
style = wxFONTSTYLE_NORMAL;
|
||||||
weight = wxFONTWEIGHT_NORMAL;
|
weight = wxFONTWEIGHT_NORMAL;
|
||||||
@@ -721,7 +838,7 @@ void wxNativeFontInfo::Init()
|
|||||||
encoding = wxFONTENCODING_DEFAULT;
|
encoding = wxFONTENCODING_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxNativeFontInfo::GetPointSize() const
|
float wxNativeFontInfo::GetFractionalPointSize() const
|
||||||
{
|
{
|
||||||
return pointSize;
|
return pointSize;
|
||||||
}
|
}
|
||||||
@@ -731,7 +848,7 @@ wxFontStyle wxNativeFontInfo::GetStyle() const
|
|||||||
return style;
|
return style;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontWeight wxNativeFontInfo::GetWeight() const
|
int wxNativeFontInfo::GetNumericWeight() const
|
||||||
{
|
{
|
||||||
return weight;
|
return weight;
|
||||||
}
|
}
|
||||||
@@ -761,7 +878,7 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
|
|||||||
return encoding;
|
return encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetPointSize(int pointsize)
|
void wxNativeFontInfo::SetFractionalPointSize(float pointsize)
|
||||||
{
|
{
|
||||||
pointSize = pointsize;
|
pointSize = pointsize;
|
||||||
}
|
}
|
||||||
@@ -771,7 +888,7 @@ void wxNativeFontInfo::SetStyle(wxFontStyle style_)
|
|||||||
style = style_;
|
style = style_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetWeight(wxFontWeight weight_)
|
void wxNativeFontInfo::SetNumericWeight(int weight_)
|
||||||
{
|
{
|
||||||
weight = weight_;
|
weight = weight_;
|
||||||
}
|
}
|
||||||
@@ -1213,7 +1330,7 @@ bool wxNativeFontInfo::FromUserString(const wxString& s)
|
|||||||
|
|
||||||
// set point size to default value if size was not given
|
// set point size to default value if size was not given
|
||||||
if ( !pointsizefound )
|
if ( !pointsizefound )
|
||||||
SetPointSize(wxNORMAL_FONT->GetPointSize());
|
SetFractionalPointSize(wxNORMAL_FONT->GetFractionalPointSize());
|
||||||
|
|
||||||
// set font weight to default value if weight was not given
|
// set font weight to default value if weight was not given
|
||||||
if ( !weightfound )
|
if ( !weightfound )
|
||||||
@@ -1234,36 +1351,14 @@ bool wxNativeFontInfo::FromUserString(const wxString& s)
|
|||||||
|
|
||||||
wxFontWeight wxNativeFontInfo::GetWeight() const
|
wxFontWeight wxNativeFontInfo::GetWeight() const
|
||||||
{
|
{
|
||||||
// round to nearest hundredth = wxFONTWEIGHT_ constant
|
return wxFontInfo::GetWeightClosestToNumericValue(GetNumericWeight());
|
||||||
int weight = ((GetNumericWeight() + 50) / 100) * 100;
|
|
||||||
|
|
||||||
if (weight < wxFONTWEIGHT_THIN)
|
|
||||||
weight = wxFONTWEIGHT_THIN;
|
|
||||||
if (weight > wxFONTWEIGHT_MAX)
|
|
||||||
weight = wxFONTWEIGHT_MAX;
|
|
||||||
|
|
||||||
return (wxFontWeight)weight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetWeight(wxFontWeight weight)
|
void wxNativeFontInfo::SetWeight(wxFontWeight weight)
|
||||||
{
|
{
|
||||||
// deal with compatibility constants
|
const int numWeight = wxFontBase::GetNumericWeightOf(weight);
|
||||||
if (weight >= 90 && weight <= 92)
|
if ( numWeight != GetNumericWeight() )
|
||||||
{
|
SetNumericWeight(numWeight);
|
||||||
if (weight == 90 /* wxNORMAL */)
|
|
||||||
weight = wxFONTWEIGHT_NORMAL;
|
|
||||||
else if (weight == 91 /* wxLIGHT */)
|
|
||||||
weight = wxFONTWEIGHT_LIGHT;
|
|
||||||
else if (weight == 92 /* wxBOLD */)
|
|
||||||
weight = wxFONTWEIGHT_BOLD;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxASSERT(weight > wxFONTWEIGHT_INVALID || weight <= wxFONTWEIGHT_MAX);
|
|
||||||
wxASSERT(weight % 100 == 0);
|
|
||||||
|
|
||||||
wxFontWeight formerWeight = GetWeight();
|
|
||||||
if (formerWeight != weight)
|
|
||||||
SetNumericWeight(weight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// wxFont <-> wxString utilities, used by wxConfig
|
// wxFont <-> wxString utilities, used by wxConfig
|
||||||
|
@@ -118,7 +118,7 @@ wxFontBundleBase::GetFaceForFont(const wxFontMgrFontRefData& font) const
|
|||||||
|
|
||||||
int type = FaceType_Regular;
|
int type = FaceType_Regular;
|
||||||
|
|
||||||
if ( font.GetWeight() == wxFONTWEIGHT_BOLD )
|
if ( font.GetNumericWeight() >= wxFONTWEIGHT_BOLD )
|
||||||
type |= FaceType_Bold;
|
type |= FaceType_Bold;
|
||||||
|
|
||||||
// FIXME -- this should read "if ( font->GetStyle() == wxFONTSTYLE_ITALIC )",
|
// FIXME -- this should read "if ( font->GetStyle() == wxFONTSTYLE_ITALIC )",
|
||||||
@@ -227,7 +227,7 @@ void wxFontsManagerBase::AddBundle(wxFontBundle *bundle)
|
|||||||
wxFontMgrFontRefData::wxFontMgrFontRefData(int size,
|
wxFontMgrFontRefData::wxFontMgrFontRefData(int size,
|
||||||
wxFontFamily family,
|
wxFontFamily family,
|
||||||
wxFontStyle style,
|
wxFontStyle style,
|
||||||
wxFontWeight weight,
|
int weight,
|
||||||
bool underlined,
|
bool underlined,
|
||||||
const wxString& faceName,
|
const wxString& faceName,
|
||||||
wxFontEncoding encoding)
|
wxFontEncoding encoding)
|
||||||
@@ -240,7 +240,7 @@ wxFontMgrFontRefData::wxFontMgrFontRefData(int size,
|
|||||||
m_info.family = (wxFontFamily)family;
|
m_info.family = (wxFontFamily)family;
|
||||||
m_info.faceName = faceName;
|
m_info.faceName = faceName;
|
||||||
m_info.style = (wxFontStyle)style;
|
m_info.style = (wxFontStyle)style;
|
||||||
m_info.weight = (wxFontWeight)weight;
|
m_info.weight = weight;
|
||||||
m_info.pointSize = size;
|
m_info.pointSize = size;
|
||||||
m_info.underlined = underlined;
|
m_info.underlined = underlined;
|
||||||
m_info.encoding = encoding;
|
m_info.encoding = encoding;
|
||||||
@@ -281,7 +281,7 @@ wxFontMgrFontRefData::GetFontInstance(float scale, bool antialiased) const
|
|||||||
antialiased);
|
antialiased);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFontMgrFontRefData::SetPointSize(int pointSize)
|
void wxFontMgrFontRefData::SetFractionalPointSize(float pointSize)
|
||||||
{
|
{
|
||||||
m_info.pointSize = pointSize;
|
m_info.pointSize = pointSize;
|
||||||
m_fontValid = false;
|
m_fontValid = false;
|
||||||
@@ -299,7 +299,7 @@ void wxFontMgrFontRefData::SetStyle(wxFontStyle style)
|
|||||||
m_fontValid = false;
|
m_fontValid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFontMgrFontRefData::SetWeight(wxFontWeight weight)
|
void wxFontMgrFontRefData::SetNumericWeight(int weight)
|
||||||
{
|
{
|
||||||
m_info.weight = weight;
|
m_info.weight = weight;
|
||||||
m_fontValid = false;
|
m_fontValid = false;
|
||||||
|
@@ -1020,22 +1020,22 @@ void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant )
|
|||||||
// adjust the font height to correspond to our new variant (notice that
|
// adjust the font height to correspond to our new variant (notice that
|
||||||
// we're only called if something really changed)
|
// we're only called if something really changed)
|
||||||
wxFont font = GetFont();
|
wxFont font = GetFont();
|
||||||
int size = font.GetPointSize();
|
float size = font.GetFractionalPointSize();
|
||||||
switch ( variant )
|
switch ( variant )
|
||||||
{
|
{
|
||||||
case wxWINDOW_VARIANT_NORMAL:
|
case wxWINDOW_VARIANT_NORMAL:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case wxWINDOW_VARIANT_SMALL:
|
case wxWINDOW_VARIANT_SMALL:
|
||||||
size = wxRound(size / 1.2);
|
size /= 1.2f;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case wxWINDOW_VARIANT_MINI:
|
case wxWINDOW_VARIANT_MINI:
|
||||||
size = wxRound(size / (1.2 * 1.2));
|
size /= 1.2f * 1.2f;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case wxWINDOW_VARIANT_LARGE:
|
case wxWINDOW_VARIANT_LARGE:
|
||||||
size = wxRound(size * 1.2);
|
size *= 1.2f;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -1043,7 +1043,7 @@ void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant )
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
font.SetPointSize(size);
|
font.SetFractionalPointSize(size);
|
||||||
SetFont(font);
|
SetFont(font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -40,8 +40,14 @@ typedef wxFontMgrFontRefData wxFontRefData;
|
|||||||
|
|
||||||
bool wxFont::Create(const wxNativeFontInfo& info)
|
bool wxFont::Create(const wxNativeFontInfo& info)
|
||||||
{
|
{
|
||||||
return Create(info.pointSize, info.family, info.style, info.weight,
|
m_refData = new wxFontRefData(info.pointSize,
|
||||||
info.underlined, info.faceName, info.encoding);
|
info.family,
|
||||||
|
info.style,
|
||||||
|
info.weight,
|
||||||
|
info.underlined,
|
||||||
|
info.faceName,
|
||||||
|
info.encoding);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxFont::Create(int pointSize,
|
bool wxFont::Create(int pointSize,
|
||||||
@@ -81,11 +87,11 @@ wxIDirectFBFontPtr wxFont::GetDirectFBFont(bool antialiased) const
|
|||||||
return i ? i->GetDirectFBFont() : wxIDirectFBFontPtr();
|
return i ? i->GetDirectFBFont() : wxIDirectFBFontPtr();
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxFont::GetPointSize() const
|
float wxFont::GetFractionalPointSize() const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
|
wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
|
||||||
|
|
||||||
return M_FONTDATA->GetPointSize();
|
return M_FONTDATA->GetFractionalPointSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxFont::GetFaceName() const
|
wxString wxFont::GetFaceName() const
|
||||||
@@ -107,11 +113,11 @@ wxFontStyle wxFont::GetStyle() const
|
|||||||
return M_FONTDATA->GetStyle();
|
return M_FONTDATA->GetStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontWeight wxFont::GetWeight() const
|
int wxFont::GetNumericWeight() const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font") );
|
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font") );
|
||||||
|
|
||||||
return M_FONTDATA->GetWeight();
|
return M_FONTDATA->GetNumericWeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxFont::GetUnderlined() const
|
bool wxFont::GetUnderlined() const
|
||||||
@@ -147,10 +153,10 @@ const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
|
|||||||
// change font attributes
|
// change font attributes
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxFont::SetPointSize(int pointSize)
|
void wxFont::SetFractionalPointSize(float pointSize)
|
||||||
{
|
{
|
||||||
AllocExclusive();
|
AllocExclusive();
|
||||||
M_FONTDATA->SetPointSize(pointSize);
|
M_FONTDATA->SetFractionalPointSize(pointSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetFamily(wxFontFamily family)
|
void wxFont::SetFamily(wxFontFamily family)
|
||||||
@@ -165,10 +171,10 @@ void wxFont::SetStyle(wxFontStyle style)
|
|||||||
M_FONTDATA->SetStyle(style);
|
M_FONTDATA->SetStyle(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetWeight(wxFontWeight weight)
|
void wxFont::SetNumericWeight(int weight)
|
||||||
{
|
{
|
||||||
AllocExclusive();
|
AllocExclusive();
|
||||||
M_FONTDATA->SetWeight(weight);
|
M_FONTDATA->SetNumericWeight(weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxFont::SetFaceName(const wxString& faceName)
|
bool wxFont::SetFaceName(const wxString& faceName)
|
||||||
|
@@ -147,7 +147,7 @@ bool wxGenericAboutDialog::Create(const wxAboutDialogInfo& info, wxWindow* paren
|
|||||||
nameAndVersion << wxT(' ') << info.GetVersion();
|
nameAndVersion << wxT(' ') << info.GetVersion();
|
||||||
wxStaticText *label = new wxStaticText(this, wxID_ANY, nameAndVersion);
|
wxStaticText *label = new wxStaticText(this, wxID_ANY, nameAndVersion);
|
||||||
wxFont fontBig(*wxNORMAL_FONT);
|
wxFont fontBig(*wxNORMAL_FONT);
|
||||||
fontBig.SetPointSize(fontBig.GetPointSize() + 2);
|
fontBig.SetFractionalPointSize(fontBig.GetFractionalPointSize() + 2.0);
|
||||||
fontBig.SetWeight(wxFONTWEIGHT_BOLD);
|
fontBig.SetWeight(wxFONTWEIGHT_BOLD);
|
||||||
label->SetFont(fontBig);
|
label->SetFont(fontBig);
|
||||||
|
|
||||||
|
@@ -213,7 +213,7 @@ wxTipDialog::wxTipDialog(wxWindow *parent,
|
|||||||
if (!isPda)
|
if (!isPda)
|
||||||
{
|
{
|
||||||
wxFont font = text->GetFont();
|
wxFont font = text->GetFont();
|
||||||
font.SetPointSize(int(1.6 * font.GetPointSize()));
|
font.SetFractionalPointSize(1.6 * font.GetFractionalPointSize());
|
||||||
font.SetWeight(wxFONTWEIGHT_BOLD);
|
font.SetWeight(wxFONTWEIGHT_BOLD);
|
||||||
text->SetFont(font);
|
text->SetFont(font);
|
||||||
}
|
}
|
||||||
|
123
src/gtk/font.cpp
123
src/gtk/font.cpp
@@ -32,13 +32,6 @@
|
|||||||
|
|
||||||
#include "wx/gtk/private.h"
|
#include "wx/gtk/private.h"
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// constants
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// the default size (in points) for the fonts
|
|
||||||
static const int wxDEFAULT_FONT_SIZE = 12;
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxFontRefData
|
// wxFontRefData
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -46,26 +39,17 @@ static const int wxDEFAULT_FONT_SIZE = 12;
|
|||||||
class wxFontRefData : public wxGDIRefData
|
class wxFontRefData : public wxGDIRefData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// from broken down font parameters, also default ctor
|
// main and also default ctor
|
||||||
wxFontRefData(int size = -1,
|
wxFontRefData(const wxFontInfo& info = wxFontInfo());
|
||||||
wxFontFamily family = wxFONTFAMILY_DEFAULT,
|
|
||||||
wxFontStyle style = wxFONTSTYLE_NORMAL,
|
|
||||||
wxFontWeight weight = wxFONTWEIGHT_NORMAL,
|
|
||||||
bool underlined = false,
|
|
||||||
bool strikethrough = false,
|
|
||||||
const wxString& faceName = wxEmptyString,
|
|
||||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
|
||||||
|
|
||||||
wxFontRefData(const wxString& nativeFontInfoString);
|
wxFontRefData(const wxString& nativeFontInfoString);
|
||||||
|
|
||||||
// copy ctor
|
// copy ctor
|
||||||
wxFontRefData( const wxFontRefData& data );
|
wxFontRefData( const wxFontRefData& data );
|
||||||
|
|
||||||
virtual ~wxFontRefData();
|
|
||||||
|
|
||||||
// setters: all of them also take care to modify m_nativeFontInfo if we
|
// setters: all of them also take care to modify m_nativeFontInfo if we
|
||||||
// have it so as to not lose the information not carried by our fields
|
// have it so as to not lose the information not carried by our fields
|
||||||
void SetPointSize(float pointSize);
|
void SetFractionalPointSize(float pointSize);
|
||||||
void SetFamily(wxFontFamily family);
|
void SetFamily(wxFontFamily family);
|
||||||
void SetStyle(wxFontStyle style);
|
void SetStyle(wxFontStyle style);
|
||||||
void SetWeight(wxFontWeight weight);
|
void SetWeight(wxFontWeight weight);
|
||||||
@@ -79,16 +63,6 @@ public:
|
|||||||
void SetNativeFontInfo(const wxNativeFontInfo& info);
|
void SetNativeFontInfo(const wxNativeFontInfo& info);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// common part of all ctors
|
|
||||||
void Init(int pointSize,
|
|
||||||
wxFontFamily family,
|
|
||||||
wxFontStyle style,
|
|
||||||
wxFontWeight weight,
|
|
||||||
bool underlined,
|
|
||||||
bool strikethrough,
|
|
||||||
const wxString& faceName,
|
|
||||||
wxFontEncoding encoding);
|
|
||||||
|
|
||||||
// set all fields from (already initialized and valid) m_nativeFontInfo
|
// set all fields from (already initialized and valid) m_nativeFontInfo
|
||||||
void InitFromNative();
|
void InitFromNative();
|
||||||
|
|
||||||
@@ -106,49 +80,30 @@ private:
|
|||||||
// wxFontRefData
|
// wxFontRefData
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxFontRefData::Init(int pointSize,
|
wxFontRefData::wxFontRefData(const wxFontInfo& info)
|
||||||
wxFontFamily family,
|
|
||||||
wxFontStyle style,
|
|
||||||
wxFontWeight weight,
|
|
||||||
bool underlined,
|
|
||||||
bool strikethrough,
|
|
||||||
const wxString& faceName,
|
|
||||||
wxFontEncoding WXUNUSED(encoding))
|
|
||||||
{
|
{
|
||||||
// Old code could wrongly specify wxDEFAULT instead of -1 or wxNORMAL or,
|
|
||||||
// preferably, wxFONTSTYLE_NORMAL or wxFONTWEIGHT_NORMAL, continue handling
|
|
||||||
// this for compatibility.
|
|
||||||
if ( pointSize == wxDEFAULT )
|
|
||||||
pointSize = -1;
|
|
||||||
|
|
||||||
if ( static_cast<int>(style) == wxDEFAULT )
|
|
||||||
style = wxFONTSTYLE_NORMAL;
|
|
||||||
|
|
||||||
if ( static_cast<int>(weight) == wxDEFAULT )
|
|
||||||
weight = wxFONTWEIGHT_NORMAL;
|
|
||||||
|
|
||||||
if (family == wxFONTFAMILY_DEFAULT)
|
|
||||||
family = wxFONTFAMILY_SWISS;
|
|
||||||
|
|
||||||
// Create native font info
|
// Create native font info
|
||||||
m_nativeFontInfo.description = pango_font_description_new();
|
m_nativeFontInfo.description = pango_font_description_new();
|
||||||
|
|
||||||
// And set its values
|
// And set its values
|
||||||
if (!faceName.empty())
|
if ( info.HasFaceName() )
|
||||||
{
|
{
|
||||||
pango_font_description_set_family( m_nativeFontInfo.description,
|
pango_font_description_set_family( m_nativeFontInfo.description,
|
||||||
wxGTK_CONV_SYS(faceName) );
|
wxGTK_CONV_SYS(info.GetFaceName()) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
wxFontFamily family = info.GetFamily();
|
||||||
|
if (family == wxFONTFAMILY_DEFAULT)
|
||||||
|
family = wxFONTFAMILY_SWISS;
|
||||||
SetFamily(family);
|
SetFamily(family);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetStyle( style );
|
SetStyle( info.GetStyle() );
|
||||||
SetPointSize( pointSize == -1 ? wxDEFAULT_FONT_SIZE : pointSize );
|
m_nativeFontInfo.SetSizeOrDefault(info.GetFractionalPointSize());
|
||||||
SetWeight( weight );
|
SetNumericWeight( info.GetNumericWeight() );
|
||||||
SetUnderlined( underlined );
|
SetUnderlined( info.IsUnderlined() );
|
||||||
SetStrikethrough( strikethrough );
|
SetStrikethrough( info.IsStrikethrough() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFontRefData::InitFromNative()
|
void wxFontRefData::InitFromNative()
|
||||||
@@ -159,7 +114,7 @@ void wxFontRefData::InitFromNative()
|
|||||||
// Pango sometimes needs to have a size
|
// Pango sometimes needs to have a size
|
||||||
int pango_size = pango_font_description_get_size( desc );
|
int pango_size = pango_font_description_get_size( desc );
|
||||||
if (pango_size == 0)
|
if (pango_size == 0)
|
||||||
m_nativeFontInfo.SetPointSize(wxDEFAULT_FONT_SIZE);
|
m_nativeFontInfo.SetSizeOrDefault(-1); // i.e. default
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontRefData::wxFontRefData( const wxFontRefData& data )
|
wxFontRefData::wxFontRefData( const wxFontRefData& data )
|
||||||
@@ -168,14 +123,6 @@ wxFontRefData::wxFontRefData( const wxFontRefData& data )
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontRefData::wxFontRefData(int size, wxFontFamily family, wxFontStyle style,
|
|
||||||
wxFontWeight weight, bool underlined, bool strikethrough,
|
|
||||||
const wxString& faceName,
|
|
||||||
wxFontEncoding encoding)
|
|
||||||
{
|
|
||||||
Init(size, family, style, weight, underlined, strikethrough, faceName, encoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
wxFontRefData::wxFontRefData(const wxString& nativeFontInfoString)
|
wxFontRefData::wxFontRefData(const wxString& nativeFontInfoString)
|
||||||
{
|
{
|
||||||
m_nativeFontInfo.FromString( nativeFontInfoString );
|
m_nativeFontInfo.FromString( nativeFontInfoString );
|
||||||
@@ -183,17 +130,13 @@ wxFontRefData::wxFontRefData(const wxString& nativeFontInfoString)
|
|||||||
InitFromNative();
|
InitFromNative();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontRefData::~wxFontRefData()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxFontRefData SetXXX()
|
// wxFontRefData SetXXX()
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxFontRefData::SetPointSize(float pointSize)
|
void wxFontRefData::SetFractionalPointSize(float pointSize)
|
||||||
{
|
{
|
||||||
m_nativeFontInfo.SetPointSize(pointSize);
|
m_nativeFontInfo.SetFractionalPointSize(pointSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -293,14 +236,7 @@ wxFont::wxFont(const wxNativeFontInfo& info)
|
|||||||
|
|
||||||
wxFont::wxFont(const wxFontInfo& info)
|
wxFont::wxFont(const wxFontInfo& info)
|
||||||
{
|
{
|
||||||
m_refData = new wxFontRefData(info.GetPointSize(),
|
m_refData = new wxFontRefData(info);
|
||||||
info.GetFamily(),
|
|
||||||
info.GetStyle(),
|
|
||||||
info.GetWeight(),
|
|
||||||
info.IsUnderlined(),
|
|
||||||
info.IsStrikethrough(),
|
|
||||||
info.GetFaceName(),
|
|
||||||
info.GetEncoding());
|
|
||||||
|
|
||||||
wxSize pixelSize = info.GetPixelSize();
|
wxSize pixelSize = info.GetPixelSize();
|
||||||
if ( pixelSize != wxDefaultSize )
|
if ( pixelSize != wxDefaultSize )
|
||||||
@@ -317,8 +253,9 @@ bool wxFont::Create( int pointSize,
|
|||||||
{
|
{
|
||||||
UnRef();
|
UnRef();
|
||||||
|
|
||||||
m_refData = new wxFontRefData(pointSize, family, style, weight,
|
m_refData = new wxFontRefData(InfoFromLegacyParams(pointSize, family,
|
||||||
underlined, false, face, encoding);
|
style, weight, underlined,
|
||||||
|
face, encoding));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -372,13 +309,6 @@ wxFontStyle wxFont::GetStyle() const
|
|||||||
return M_FONTDATA->m_nativeFontInfo.GetStyle();
|
return M_FONTDATA->m_nativeFontInfo.GetStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontWeight wxFont::GetWeight() const
|
|
||||||
{
|
|
||||||
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, "invalid font" );
|
|
||||||
|
|
||||||
return M_FONTDATA->m_nativeFontInfo.GetWeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
int wxFont::GetNumericWeight() const
|
int wxFont::GetNumericWeight() const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, "invalid font" );
|
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, "invalid font" );
|
||||||
@@ -426,11 +356,11 @@ bool wxFont::IsFixedWidth() const
|
|||||||
// change font attributes
|
// change font attributes
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxFont::SetPointSize(float pointSize)
|
void wxFont::SetFractionalPointSize(float pointSize)
|
||||||
{
|
{
|
||||||
AllocExclusive();
|
AllocExclusive();
|
||||||
|
|
||||||
M_FONTDATA->SetPointSize(pointSize);
|
M_FONTDATA->SetFractionalPointSize(pointSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetFamily(wxFontFamily family)
|
void wxFont::SetFamily(wxFontFamily family)
|
||||||
@@ -447,13 +377,6 @@ void wxFont::SetStyle(wxFontStyle style)
|
|||||||
M_FONTDATA->SetStyle(style);
|
M_FONTDATA->SetStyle(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetWeight(wxFontWeight weight)
|
|
||||||
{
|
|
||||||
AllocExclusive();
|
|
||||||
|
|
||||||
M_FONTDATA->SetWeight(weight);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxFont::SetNumericWeight(int weight)
|
void wxFont::SetNumericWeight(int weight)
|
||||||
{
|
{
|
||||||
AllocExclusive();
|
AllocExclusive();
|
||||||
|
@@ -58,13 +58,7 @@ class wxFontRefData : public wxGDIRefData
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// from broken down font parameters, also default ctor
|
// from broken down font parameters, also default ctor
|
||||||
wxFontRefData(int size = -1,
|
wxFontRefData(const wxFontInfo& info = wxFontInfo());
|
||||||
wxFontFamily family = wxFONTFAMILY_DEFAULT,
|
|
||||||
wxFontStyle style = wxFONTSTYLE_NORMAL,
|
|
||||||
wxFontWeight weight = wxFONTWEIGHT_NORMAL,
|
|
||||||
bool underlined = false,
|
|
||||||
const wxString& faceName = wxEmptyString,
|
|
||||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
|
||||||
|
|
||||||
// from XFLD
|
// from XFLD
|
||||||
wxFontRefData(const wxString& fontname);
|
wxFontRefData(const wxString& fontname);
|
||||||
@@ -83,10 +77,10 @@ public:
|
|||||||
|
|
||||||
// setters: all of them also take care to modify m_nativeFontInfo if we
|
// setters: all of them also take care to modify m_nativeFontInfo if we
|
||||||
// have it so as to not lose the information not carried by our fields
|
// have it so as to not lose the information not carried by our fields
|
||||||
void SetPointSize(int pointSize);
|
void SetFractionalPointSize(float pointSize);
|
||||||
void SetFamily(wxFontFamily family);
|
void SetFamily(wxFontFamily family);
|
||||||
void SetStyle(wxFontStyle style);
|
void SetStyle(wxFontStyle style);
|
||||||
void SetWeight(wxFontWeight weight);
|
void SetNumericWeight(int weight);
|
||||||
void SetUnderlined(bool underlined);
|
void SetUnderlined(bool underlined);
|
||||||
bool SetFaceName(const wxString& facename);
|
bool SetFaceName(const wxString& facename);
|
||||||
void SetEncoding(wxFontEncoding encoding);
|
void SetEncoding(wxFontEncoding encoding);
|
||||||
@@ -96,10 +90,10 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
// common part of all ctors
|
// common part of all ctors
|
||||||
void Init(int pointSize,
|
void Init(float pointSize,
|
||||||
wxFontFamily family,
|
wxFontFamily family,
|
||||||
wxFontStyle style,
|
wxFontStyle style,
|
||||||
wxFontWeight weight,
|
int weight,
|
||||||
bool underlined,
|
bool underlined,
|
||||||
const wxString& faceName,
|
const wxString& faceName,
|
||||||
wxFontEncoding encoding);
|
wxFontEncoding encoding);
|
||||||
@@ -114,10 +108,10 @@ private:
|
|||||||
// the map of font sizes to "GdkFont *"
|
// the map of font sizes to "GdkFont *"
|
||||||
wxScaledFontList m_scaled_xfonts;
|
wxScaledFontList m_scaled_xfonts;
|
||||||
|
|
||||||
int m_pointSize;
|
float m_pointSize;
|
||||||
wxFontFamily m_family;
|
wxFontFamily m_family;
|
||||||
wxFontStyle m_style;
|
wxFontStyle m_style;
|
||||||
wxFontWeight m_weight;
|
int m_weight;
|
||||||
bool m_underlined;
|
bool m_underlined;
|
||||||
wxString m_faceName;
|
wxString m_faceName;
|
||||||
wxFontEncoding m_encoding; // Unused under GTK 2.0
|
wxFontEncoding m_encoding; // Unused under GTK 2.0
|
||||||
@@ -135,10 +129,10 @@ private:
|
|||||||
// wxFontRefData
|
// wxFontRefData
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxFontRefData::Init(int pointSize,
|
void wxFontRefData::Init(float pointSize,
|
||||||
wxFontFamily family,
|
wxFontFamily family,
|
||||||
wxFontStyle style,
|
wxFontStyle style,
|
||||||
wxFontWeight weight,
|
int weight,
|
||||||
bool underlined,
|
bool underlined,
|
||||||
const wxString& faceName,
|
const wxString& faceName,
|
||||||
wxFontEncoding encoding)
|
wxFontEncoding encoding)
|
||||||
@@ -147,15 +141,10 @@ void wxFontRefData::Init(int pointSize,
|
|||||||
|
|
||||||
m_faceName = faceName;
|
m_faceName = faceName;
|
||||||
|
|
||||||
// we accept both wxDEFAULT and wxNORMAL here - should we?
|
m_style = style;
|
||||||
m_style = style == wxDEFAULT ? wxFONTSTYLE_NORMAL : style;
|
m_weight = weight;
|
||||||
m_weight = weight == wxDEFAULT ? wxFONTWEIGHT_NORMAL : weight;
|
|
||||||
|
|
||||||
// and here, do we really want to forbid creation of the font of the size
|
m_pointSize = pointSize < 0 ? wxDEFAULT_FONT_SIZE : pointSize;
|
||||||
// 90 (the value of wxDEFAULT)??
|
|
||||||
m_pointSize = pointSize == wxDEFAULT || pointSize == -1
|
|
||||||
? wxDEFAULT_FONT_SIZE
|
|
||||||
: pointSize;
|
|
||||||
|
|
||||||
m_underlined = underlined;
|
m_underlined = underlined;
|
||||||
m_encoding = encoding;
|
m_encoding = encoding;
|
||||||
@@ -206,7 +195,7 @@ void wxFontRefData::InitFromNative()
|
|||||||
if ( m_nativeFontInfo.GetXFontComponent(wxXLFD_POINTSIZE).ToLong(&ptSize) )
|
if ( m_nativeFontInfo.GetXFontComponent(wxXLFD_POINTSIZE).ToLong(&ptSize) )
|
||||||
{
|
{
|
||||||
// size in XLFD is in 10 point units
|
// size in XLFD is in 10 point units
|
||||||
m_pointSize = (int)(ptSize / 10);
|
m_pointSize = ptSize / 10;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -281,12 +270,15 @@ wxFontRefData::wxFontRefData( const wxFontRefData& data )
|
|||||||
m_nativeFontInfo.FromString(data.m_nativeFontInfo.ToString());
|
m_nativeFontInfo.FromString(data.m_nativeFontInfo.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontRefData::wxFontRefData(int size, wxFontFamily family, wxFontStyle style,
|
wxFontRefData::wxFontRefData(const wxFontInfo& info)
|
||||||
wxFontWeight weight, bool underlined,
|
|
||||||
const wxString& faceName,
|
|
||||||
wxFontEncoding encoding)
|
|
||||||
{
|
{
|
||||||
Init(size, family, style, weight, underlined, faceName, encoding);
|
Init(info.GetFractionalPointSize(),
|
||||||
|
info.GetFamily(),
|
||||||
|
info.GetStyle(),
|
||||||
|
info.GetNumericWeight(),
|
||||||
|
info.IsUnderlined(),
|
||||||
|
info.GetFaceName(),
|
||||||
|
info.GetEncoding());
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontRefData::wxFontRefData(const wxString& fontname)
|
wxFontRefData::wxFontRefData(const wxString& fontname)
|
||||||
@@ -319,19 +311,13 @@ wxFontRefData::~wxFontRefData()
|
|||||||
// wxFontRefData SetXXX()
|
// wxFontRefData SetXXX()
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxFontRefData::SetPointSize(int pointSize)
|
void wxFontRefData::SetFractionalPointSize(float pointSize)
|
||||||
{
|
{
|
||||||
m_pointSize = pointSize;
|
m_pointSize = pointSize;
|
||||||
|
|
||||||
if ( HasNativeFont() )
|
if ( HasNativeFont() )
|
||||||
{
|
{
|
||||||
wxString size;
|
m_nativeFontInfo.SetFractionalPointSize(pointSize);
|
||||||
if ( pointSize == -1 )
|
|
||||||
size = wxT('*');
|
|
||||||
else
|
|
||||||
size.Printf(wxT("%d"), 10*pointSize);
|
|
||||||
|
|
||||||
m_nativeFontInfo.SetXFontComponent(wxXLFD_POINTSIZE, size);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,33 +357,13 @@ void wxFontRefData::SetStyle(wxFontStyle style)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFontRefData::SetWeight(wxFontWeight weight)
|
void wxFontRefData::SetNumericWeight(int weight)
|
||||||
{
|
{
|
||||||
m_weight = weight;
|
m_weight = weight;
|
||||||
|
|
||||||
if ( HasNativeFont() )
|
if ( HasNativeFont() )
|
||||||
{
|
{
|
||||||
wxString boldness;
|
m_nativeFontInfo.SetNumericWeight(weight);
|
||||||
switch ( weight )
|
|
||||||
{
|
|
||||||
case wxFONTWEIGHT_BOLD:
|
|
||||||
boldness = wxT("bold");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case wxFONTWEIGHT_LIGHT:
|
|
||||||
boldness = wxT("light");
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
wxFAIL_MSG( wxT("unknown font weight") );
|
|
||||||
// fall through
|
|
||||||
|
|
||||||
case wxFONTWEIGHT_NORMAL:
|
|
||||||
// unspecified
|
|
||||||
boldness = wxT("medium");
|
|
||||||
}
|
|
||||||
|
|
||||||
m_nativeFontInfo.SetXFontComponent(wxXLFD_WEIGHT, boldness);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -465,8 +431,9 @@ bool wxFont::Create( int pointSize,
|
|||||||
{
|
{
|
||||||
UnRef();
|
UnRef();
|
||||||
|
|
||||||
m_refData = new wxFontRefData(pointSize, family, style, weight,
|
m_refData = new wxFontRefData(InfoFromLegacyParams(pointSize, family,
|
||||||
underlined, face, encoding);
|
style, weight, underlined,
|
||||||
|
face, encoding));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -518,7 +485,7 @@ wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const
|
|||||||
// accessors
|
// accessors
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
int wxFont::GetPointSize() const
|
float wxFont::GetFractionalPointSize() const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
|
wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
|
||||||
|
|
||||||
@@ -544,7 +511,7 @@ wxFontStyle wxFont::GetStyle() const
|
|||||||
return M_FONTDATA->m_style;
|
return M_FONTDATA->m_style;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontWeight wxFont::GetWeight() const
|
int wxFont::GetNumericWeight() const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font") );
|
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font") );
|
||||||
|
|
||||||
@@ -601,11 +568,11 @@ bool wxFont::IsFixedWidth() const
|
|||||||
// change font attributes
|
// change font attributes
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxFont::SetPointSize(int pointSize)
|
void wxFont::SetFractionalPointSize(float pointSize)
|
||||||
{
|
{
|
||||||
Unshare();
|
Unshare();
|
||||||
|
|
||||||
M_FONTDATA->SetPointSize(pointSize);
|
M_FONTDATA->SetFractionalPointSize(pointSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetFamily(wxFontFamily family)
|
void wxFont::SetFamily(wxFontFamily family)
|
||||||
@@ -622,11 +589,11 @@ void wxFont::SetStyle(wxFontStyle style)
|
|||||||
M_FONTDATA->SetStyle(style);
|
M_FONTDATA->SetStyle(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetWeight(wxFontWeight weight)
|
void wxFont::SetNumericWeight(int weight)
|
||||||
{
|
{
|
||||||
Unshare();
|
Unshare();
|
||||||
|
|
||||||
M_FONTDATA->SetWeight(weight);
|
M_FONTDATA->SetNumericWeight(weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxFont::SetFaceName(const wxString& faceName)
|
bool wxFont::SetFaceName(const wxString& faceName)
|
||||||
@@ -699,7 +666,7 @@ GdkFont *wxFont::GetInternalFont( float scale ) const
|
|||||||
wxCHECK_MSG( IsOk(), font, wxT("invalid font") );
|
wxCHECK_MSG( IsOk(), font, wxT("invalid font") );
|
||||||
|
|
||||||
long int_scale = long(scale * 100.0 + 0.5); // key for fontlist
|
long int_scale = long(scale * 100.0 + 0.5); // key for fontlist
|
||||||
int point_scale = (int)((M_FONTDATA->m_pointSize * 10 * int_scale) / 100);
|
float point_scale = (M_FONTDATA->m_pointSize * 10 * scale) / 100.0;
|
||||||
|
|
||||||
wxScaledFontList& list = M_FONTDATA->m_scaled_xfonts;
|
wxScaledFontList& list = M_FONTDATA->m_scaled_xfonts;
|
||||||
wxScaledFontList::iterator i = list.find(int_scale);
|
wxScaledFontList::iterator i = list.find(int_scale);
|
||||||
|
@@ -72,15 +72,15 @@ class wxFontRefData: public wxGDIRefData
|
|||||||
friend class wxFont;
|
friend class wxFont;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wxFontRefData(int size = wxDEFAULT,
|
wxFontRefData(const wxFontInfo& info = wxFontInfo())
|
||||||
wxFontFamily family = wxFONTFAMILY_DEFAULT,
|
|
||||||
wxFontStyle style = wxFONTSTYLE_NORMAL,
|
|
||||||
wxFontWeight weight = wxFONTWEIGHT_NORMAL,
|
|
||||||
bool underlined = false,
|
|
||||||
const wxString& faceName = wxEmptyString,
|
|
||||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
|
|
||||||
{
|
{
|
||||||
Init(size, family, style, weight, underlined, faceName, encoding);
|
Init(info.GetFractionalPointSize(),
|
||||||
|
info.GetFamily(),
|
||||||
|
info.GetStyle(),
|
||||||
|
info.GetNumericWeight(),
|
||||||
|
info.IsUnderlined(),
|
||||||
|
info.GetFaceName(),
|
||||||
|
info.GetEncoding());
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontRefData(const wxFontRefData& data)
|
wxFontRefData(const wxFontRefData& data)
|
||||||
@@ -93,19 +93,19 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
// common part of all ctors
|
// common part of all ctors
|
||||||
void Init(int size,
|
void Init(float size,
|
||||||
wxFontFamily family,
|
wxFontFamily family,
|
||||||
wxFontStyle style,
|
wxFontStyle style,
|
||||||
wxFontWeight weight,
|
int weight,
|
||||||
bool underlined,
|
bool underlined,
|
||||||
const wxString& faceName,
|
const wxString& faceName,
|
||||||
wxFontEncoding encoding);
|
wxFontEncoding encoding);
|
||||||
|
|
||||||
// font attributes
|
// font attributes
|
||||||
int m_pointSize;
|
float m_pointSize;
|
||||||
wxFontFamily m_family;
|
wxFontFamily m_family;
|
||||||
wxFontStyle m_style;
|
wxFontStyle m_style;
|
||||||
wxFontWeight m_weight;
|
int m_weight;
|
||||||
bool m_underlined;
|
bool m_underlined;
|
||||||
wxString m_faceName;
|
wxString m_faceName;
|
||||||
wxFontEncoding m_encoding;
|
wxFontEncoding m_encoding;
|
||||||
@@ -163,10 +163,10 @@ wxXFont::~wxXFont()
|
|||||||
// wxFontRefData
|
// wxFontRefData
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxFontRefData::Init(int pointSize,
|
void wxFontRefData::Init(float pointSize,
|
||||||
wxFontFamily family,
|
wxFontFamily family,
|
||||||
wxFontStyle style,
|
wxFontStyle style,
|
||||||
wxFontWeight weight,
|
int weight,
|
||||||
bool underlined,
|
bool underlined,
|
||||||
const wxString& faceName,
|
const wxString& faceName,
|
||||||
wxFontEncoding encoding)
|
wxFontEncoding encoding)
|
||||||
@@ -178,17 +178,10 @@ void wxFontRefData::Init(int pointSize,
|
|||||||
|
|
||||||
m_faceName = faceName;
|
m_faceName = faceName;
|
||||||
|
|
||||||
if (style == wxDEFAULT)
|
|
||||||
m_style = wxFONTSTYLE_NORMAL;
|
|
||||||
else
|
|
||||||
m_style = style;
|
m_style = style;
|
||||||
|
|
||||||
if (weight == wxDEFAULT)
|
|
||||||
m_weight = wxFONTWEIGHT_NORMAL;
|
|
||||||
else
|
|
||||||
m_weight = weight;
|
m_weight = weight;
|
||||||
|
|
||||||
if (pointSize == wxDEFAULT)
|
if (pointSize < 0)
|
||||||
m_pointSize = 12;
|
m_pointSize = 12;
|
||||||
else
|
else
|
||||||
m_pointSize = pointSize;
|
m_pointSize = pointSize;
|
||||||
@@ -220,6 +213,14 @@ wxFont::wxFont(const wxNativeFontInfo& info)
|
|||||||
(void)Create(info.GetXFontName());
|
(void)Create(info.GetXFontName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxFont::wxFont(const wxFontInfo& info)
|
||||||
|
{
|
||||||
|
m_refData = new wxFontRefData(info);
|
||||||
|
|
||||||
|
if ( info.IsUsingSizeInPixels() )
|
||||||
|
SetPixelSize(info.GetPixelSize());
|
||||||
|
}
|
||||||
|
|
||||||
bool wxFont::Create(int pointSize,
|
bool wxFont::Create(int pointSize,
|
||||||
wxFontFamily family,
|
wxFontFamily family,
|
||||||
wxFontStyle style,
|
wxFontStyle style,
|
||||||
@@ -229,8 +230,10 @@ bool wxFont::Create(int pointSize,
|
|||||||
wxFontEncoding encoding)
|
wxFontEncoding encoding)
|
||||||
{
|
{
|
||||||
UnRef();
|
UnRef();
|
||||||
m_refData = new wxFontRefData(pointSize, family, style, weight,
|
|
||||||
underlined, faceName, encoding);
|
m_refData = new wxFontRefData(InfoFromLegacyParams(pointSize, family,
|
||||||
|
style, weight, underlined,
|
||||||
|
faceName, encoding));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -371,7 +374,7 @@ void wxFont::Unshare()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetPointSize(int pointSize)
|
void wxFont::SetFractionalPointSize(float pointSize)
|
||||||
{
|
{
|
||||||
Unshare();
|
Unshare();
|
||||||
|
|
||||||
@@ -395,7 +398,7 @@ void wxFont::SetStyle(wxFontStyle style)
|
|||||||
M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
|
M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetWeight(wxFontWeight weight)
|
void wxFont::SetNumericWeight(int weight)
|
||||||
{
|
{
|
||||||
Unshare();
|
Unshare();
|
||||||
|
|
||||||
@@ -439,7 +442,7 @@ void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo& info)
|
|||||||
// query font attributes
|
// query font attributes
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
int wxFont::GetPointSize() const
|
float wxFont::GetFractionalPointSize() const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
|
wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
|
||||||
|
|
||||||
@@ -465,7 +468,7 @@ wxFontStyle wxFont::GetStyle() const
|
|||||||
return M_FONTDATA->m_style;
|
return M_FONTDATA->m_style;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontWeight wxFont::GetWeight() const
|
int wxFont::GetNumericWeight() const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font") );
|
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font") );
|
||||||
|
|
||||||
|
189
src/msw/font.cpp
189
src/msw/font.cpp
@@ -57,28 +57,7 @@ static const int PITCH_MASK = FIXED_PITCH | VARIABLE_PITCH;
|
|||||||
class WXDLLEXPORT wxFontRefData: public wxGDIRefData
|
class WXDLLEXPORT wxFontRefData: public wxGDIRefData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// constructors
|
wxFontRefData(const wxFontInfo& info = wxFontInfo());
|
||||||
wxFontRefData()
|
|
||||||
{
|
|
||||||
Init(-1, wxSize(0,0), false, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
|
|
||||||
wxFONTWEIGHT_NORMAL, false, false, wxEmptyString,
|
|
||||||
wxFONTENCODING_DEFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
wxFontRefData(int size,
|
|
||||||
const wxSize& pixelSize,
|
|
||||||
bool sizeUsingPixels,
|
|
||||||
wxFontFamily family,
|
|
||||||
wxFontStyle style,
|
|
||||||
wxFontWeight weight,
|
|
||||||
bool underlined,
|
|
||||||
bool strikethrough,
|
|
||||||
const wxString& faceName,
|
|
||||||
wxFontEncoding encoding)
|
|
||||||
{
|
|
||||||
Init(size, pixelSize, sizeUsingPixels, family, style, weight,
|
|
||||||
underlined, strikethrough, faceName, encoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
wxFontRefData(const wxNativeFontInfo& info, WXHFONT hFont = 0)
|
wxFontRefData(const wxNativeFontInfo& info, WXHFONT hFont = 0)
|
||||||
{
|
{
|
||||||
@@ -100,7 +79,7 @@ public:
|
|||||||
// all wxFont accessors
|
// all wxFont accessors
|
||||||
float GetFractionalPointSize() const
|
float GetFractionalPointSize() const
|
||||||
{
|
{
|
||||||
return m_nativeFontInfo.GetPointSize();
|
return m_nativeFontInfo.GetFractionalPointSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSize GetPixelSize() const
|
wxSize GetPixelSize() const
|
||||||
@@ -123,11 +102,6 @@ public:
|
|||||||
return m_nativeFontInfo.GetStyle();
|
return m_nativeFontInfo.GetStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontWeight GetWeight() const
|
|
||||||
{
|
|
||||||
return m_nativeFontInfo.GetWeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
int GetNumericWeight() const
|
int GetNumericWeight() const
|
||||||
{
|
{
|
||||||
return m_nativeFontInfo.GetNumericWeight();
|
return m_nativeFontInfo.GetNumericWeight();
|
||||||
@@ -181,11 +155,11 @@ public:
|
|||||||
// ... and setters: notice that all of them invalidate the currently
|
// ... and setters: notice that all of them invalidate the currently
|
||||||
// allocated HFONT, if any, so that the next call to GetHFONT() recreates a
|
// allocated HFONT, if any, so that the next call to GetHFONT() recreates a
|
||||||
// new one
|
// new one
|
||||||
void SetPointSize(float pointSize)
|
void SetFractionalPointSize(float pointSize)
|
||||||
{
|
{
|
||||||
Free();
|
Free();
|
||||||
|
|
||||||
m_nativeFontInfo.SetPointSize(pointSize);
|
m_nativeFontInfo.SetFractionalPointSize(pointSize);
|
||||||
m_sizeUsingPixels = false;
|
m_sizeUsingPixels = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,13 +188,6 @@ public:
|
|||||||
m_nativeFontInfo.SetStyle(style);
|
m_nativeFontInfo.SetStyle(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetWeight(wxFontWeight weight)
|
|
||||||
{
|
|
||||||
Free();
|
|
||||||
|
|
||||||
m_nativeFontInfo.SetWeight(weight);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetNumericWeight(int weight)
|
void SetNumericWeight(int weight)
|
||||||
{
|
{
|
||||||
Free();
|
Free();
|
||||||
@@ -278,18 +245,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// common part of all ctors
|
|
||||||
void Init(int size,
|
|
||||||
const wxSize& pixelSize,
|
|
||||||
bool sizeUsingPixels,
|
|
||||||
wxFontFamily family,
|
|
||||||
wxFontStyle style,
|
|
||||||
wxFontWeight weight,
|
|
||||||
bool underlined,
|
|
||||||
bool strikethrough,
|
|
||||||
const wxString& faceName,
|
|
||||||
wxFontEncoding encoding);
|
|
||||||
|
|
||||||
void Init(const wxNativeFontInfo& info, WXHFONT hFont = 0);
|
void Init(const wxNativeFontInfo& info, WXHFONT hFont = 0);
|
||||||
|
|
||||||
void AllocIfNeeded() const
|
void AllocIfNeeded() const
|
||||||
@@ -354,38 +309,33 @@ protected:
|
|||||||
// wxFontRefData
|
// wxFontRefData
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxFontRefData::Init(int pointSize,
|
wxFontRefData::wxFontRefData(const wxFontInfo& info)
|
||||||
const wxSize& pixelSize,
|
|
||||||
bool sizeUsingPixels,
|
|
||||||
wxFontFamily family,
|
|
||||||
wxFontStyle style,
|
|
||||||
wxFontWeight weight,
|
|
||||||
bool underlined,
|
|
||||||
bool strikethrough,
|
|
||||||
const wxString& faceName,
|
|
||||||
wxFontEncoding encoding)
|
|
||||||
{
|
{
|
||||||
m_hFont = NULL;
|
m_hFont = NULL;
|
||||||
|
|
||||||
m_sizeUsingPixels = sizeUsingPixels;
|
m_sizeUsingPixels = info.IsUsingSizeInPixels();
|
||||||
if ( m_sizeUsingPixels )
|
if ( m_sizeUsingPixels )
|
||||||
SetPixelSize(pixelSize);
|
{
|
||||||
|
m_nativeFontInfo.SetPixelSize(info.GetPixelSize());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
SetPointSize(pointSize == -1 ? wxNORMAL_FONT->GetPointSize() : pointSize);
|
{
|
||||||
|
m_nativeFontInfo.SetSizeOrDefault(info.GetFractionalPointSize());
|
||||||
|
}
|
||||||
|
|
||||||
SetStyle(style);
|
SetStyle(info.GetStyle());
|
||||||
SetWeight(weight);
|
SetNumericWeight(info.GetNumericWeight());
|
||||||
SetUnderlined(underlined);
|
SetUnderlined(info.IsUnderlined());
|
||||||
SetStrikethrough(strikethrough);
|
SetStrikethrough(info.IsStrikethrough());
|
||||||
|
|
||||||
// set the family/facename
|
// set the family/facename
|
||||||
SetFamily(family);
|
SetFamily(info.GetFamily());
|
||||||
if ( !faceName.empty() )
|
if ( info.HasFaceName() )
|
||||||
SetFaceName(faceName);
|
SetFaceName(info.GetFaceName());
|
||||||
|
|
||||||
// deal with encoding now (it may override the font family and facename
|
// deal with encoding now (it may override the font family and facename
|
||||||
// so do it after setting them)
|
// so do it after setting them)
|
||||||
SetEncoding(encoding);
|
SetEncoding(info.GetEncoding());
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFontRefData::Init(const wxNativeFontInfo& info, WXHFONT hFont)
|
void wxFontRefData::Init(const wxNativeFontInfo& info, WXHFONT hFont)
|
||||||
@@ -446,21 +396,20 @@ void wxNativeFontInfo::Init()
|
|||||||
lf.lfQuality = wxSystemOptions::GetOptionInt("msw.font.no-proof-quality")
|
lf.lfQuality = wxSystemOptions::GetOptionInt("msw.font.no-proof-quality")
|
||||||
? DEFAULT_QUALITY
|
? DEFAULT_QUALITY
|
||||||
: PROOF_QUALITY;
|
: PROOF_QUALITY;
|
||||||
}
|
|
||||||
|
|
||||||
int wxNativeFontInfo::GetPointSize() const
|
pointSize = 0.0f;
|
||||||
{
|
|
||||||
return wxRound(GetFractionalPointSize());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float wxNativeFontInfo::GetFractionalPointSize() const
|
float wxNativeFontInfo::GetFractionalPointSize() const
|
||||||
{
|
{
|
||||||
|
if ( pointSize != 0.0f )
|
||||||
|
return pointSize;
|
||||||
|
|
||||||
// FIXME: using the screen here results in incorrect font size calculation
|
// FIXME: using the screen here results in incorrect font size calculation
|
||||||
// for printing!
|
// for printing!
|
||||||
const int ppInch = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);
|
const int ppInch = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);
|
||||||
|
|
||||||
// BC++ 2007 doesn't provide abs(long) overload, hence the cast
|
return (72.0*abs(lf.lfHeight)) / (double) ppInch;
|
||||||
return (int) (((72.0*abs((int)lf.lfHeight)) / (double) ppInch) + 0.5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSize wxNativeFontInfo::GetPixelSize() const
|
wxSize wxNativeFontInfo::GetPixelSize() const
|
||||||
@@ -541,13 +490,17 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
|
|||||||
return wxGetFontEncFromCharSet(lf.lfCharSet);
|
return wxGetFontEncFromCharSet(lf.lfCharSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetPointSize(float pointsize)
|
void wxNativeFontInfo::SetFractionalPointSize(float pointsize)
|
||||||
{
|
{
|
||||||
|
// Store it to be able to return it from GetFractionalPointSize() later
|
||||||
|
// exactly.
|
||||||
|
pointSize = pointsize;
|
||||||
|
|
||||||
// FIXME: using the screen here results in incorrect font size calculation
|
// FIXME: using the screen here results in incorrect font size calculation
|
||||||
// for printing!
|
// for printing!
|
||||||
const int ppInch = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);
|
const int ppInch = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);
|
||||||
|
|
||||||
lf.lfHeight = -(int)((pointsize*((double)ppInch)/72.0) + 0.5);
|
lf.lfHeight = -wxRound(pointsize*((double)ppInch)/72.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetPixelSize(const wxSize& pixelSize)
|
void wxNativeFontInfo::SetPixelSize(const wxSize& pixelSize)
|
||||||
@@ -682,9 +635,32 @@ bool wxNativeFontInfo::FromString(const wxString& s)
|
|||||||
|
|
||||||
// first the version
|
// first the version
|
||||||
wxString token = tokenizer.GetNextToken();
|
wxString token = tokenizer.GetNextToken();
|
||||||
if ( token != wxS('0') )
|
if ( !token.ToLong(&l) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
switch ( l )
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
// Fractional point size is not present in this version.
|
||||||
|
pointSize = 0.0f;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
double d;
|
||||||
|
if ( !tokenizer.GetNextToken().ToCDouble(&d) )
|
||||||
|
return false;
|
||||||
|
pointSize = static_cast<float>(d);
|
||||||
|
if ( static_cast<double>(pointSize) != d )
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Unknown version.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
token = tokenizer.GetNextToken();
|
token = tokenizer.GetNextToken();
|
||||||
if ( !token.ToLong(&l) )
|
if ( !token.ToLong(&l) )
|
||||||
return false;
|
return false;
|
||||||
@@ -763,8 +739,9 @@ wxString wxNativeFontInfo::ToString() const
|
|||||||
{
|
{
|
||||||
wxString s;
|
wxString s;
|
||||||
|
|
||||||
s.Printf(wxS("%d;%ld;%ld;%ld;%ld;%ld;%d;%d;%d;%d;%d;%d;%d;%d;%s"),
|
s.Printf(wxS("%d;%f;%ld;%ld;%ld;%ld;%ld;%d;%d;%d;%d;%d;%d;%d;%d;%s"),
|
||||||
0, // version, in case we want to change the format later
|
1, // version
|
||||||
|
pointSize,
|
||||||
lf.lfHeight,
|
lf.lfHeight,
|
||||||
lf.lfWidth,
|
lf.lfWidth,
|
||||||
lf.lfEscapement,
|
lf.lfEscapement,
|
||||||
@@ -796,16 +773,7 @@ wxFont::wxFont(const wxString& fontdesc)
|
|||||||
|
|
||||||
wxFont::wxFont(const wxFontInfo& info)
|
wxFont::wxFont(const wxFontInfo& info)
|
||||||
{
|
{
|
||||||
m_refData = new wxFontRefData(info.GetPointSize(),
|
m_refData = new wxFontRefData(info);
|
||||||
info.GetPixelSize(),
|
|
||||||
info.IsUsingSizeInPixels(),
|
|
||||||
info.GetFamily(),
|
|
||||||
info.GetStyle(),
|
|
||||||
info.GetWeight(),
|
|
||||||
info.IsUnderlined(),
|
|
||||||
info.IsStrikethrough(),
|
|
||||||
info.GetFaceName(),
|
|
||||||
info.GetEncoding());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxFont::Create(const wxNativeFontInfo& info, WXHFONT hFont)
|
bool wxFont::Create(const wxNativeFontInfo& info, WXHFONT hFont)
|
||||||
@@ -817,28 +785,11 @@ bool wxFont::Create(const wxNativeFontInfo& info, WXHFONT hFont)
|
|||||||
return RealizeResource();
|
return RealizeResource();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxFont::DoCreate(int pointSize,
|
bool wxFont::DoCreate(const wxFontInfo& info)
|
||||||
const wxSize& pixelSize,
|
|
||||||
bool sizeUsingPixels,
|
|
||||||
wxFontFamily family,
|
|
||||||
wxFontStyle style,
|
|
||||||
wxFontWeight weight,
|
|
||||||
bool underlined,
|
|
||||||
const wxString& faceName,
|
|
||||||
wxFontEncoding encoding)
|
|
||||||
{
|
{
|
||||||
UnRef();
|
UnRef();
|
||||||
|
|
||||||
// wxDEFAULT is a valid value for the font size too so we must treat it
|
m_refData = new wxFontRefData(info);
|
||||||
// specially here (otherwise the size would be 70 == wxDEFAULT value)
|
|
||||||
if ( pointSize == wxDEFAULT )
|
|
||||||
{
|
|
||||||
pointSize = wxNORMAL_FONT->GetPointSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_refData = new wxFontRefData(pointSize, pixelSize, sizeUsingPixels,
|
|
||||||
family, style, weight,
|
|
||||||
underlined, false, faceName, encoding);
|
|
||||||
|
|
||||||
return RealizeResource();
|
return RealizeResource();
|
||||||
}
|
}
|
||||||
@@ -900,12 +851,12 @@ bool wxFont::IsFree() const
|
|||||||
// change font attribute: we recreate font when doing it
|
// change font attribute: we recreate font when doing it
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxFont::SetPointSize(float pointSize)
|
void wxFont::SetFractionalPointSize(float pointSize)
|
||||||
{
|
{
|
||||||
AllocExclusive();
|
AllocExclusive();
|
||||||
|
|
||||||
M_FONTDATA->Free();
|
M_FONTDATA->Free();
|
||||||
M_FONTDATA->SetPointSize(pointSize);
|
M_FONTDATA->SetFractionalPointSize(pointSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetPixelSize(const wxSize& pixelSize)
|
void wxFont::SetPixelSize(const wxSize& pixelSize)
|
||||||
@@ -929,13 +880,6 @@ void wxFont::SetStyle(wxFontStyle style)
|
|||||||
M_FONTDATA->SetStyle(style);
|
M_FONTDATA->SetStyle(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetWeight(wxFontWeight weight)
|
|
||||||
{
|
|
||||||
AllocExclusive();
|
|
||||||
|
|
||||||
M_FONTDATA->SetWeight(weight);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxFont::SetNumericWeight(int weight)
|
void wxFont::SetNumericWeight(int weight)
|
||||||
{
|
{
|
||||||
AllocExclusive();
|
AllocExclusive();
|
||||||
@@ -1025,13 +969,6 @@ wxFontStyle wxFont::GetStyle() const
|
|||||||
return M_FONTDATA->GetStyle();
|
return M_FONTDATA->GetStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontWeight wxFont::GetWeight() const
|
|
||||||
{
|
|
||||||
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, "invalid font" );
|
|
||||||
|
|
||||||
return M_FONTDATA->GetWeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
int wxFont::GetNumericWeight() const
|
int wxFont::GetNumericWeight() const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG(IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font"));
|
wxCHECK_MSG(IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font"));
|
||||||
|
@@ -335,7 +335,7 @@ public:
|
|||||||
const wxColour& col );
|
const wxColour& col );
|
||||||
wxGDIPlusFontData(wxGraphicsRenderer* renderer,
|
wxGDIPlusFontData(wxGraphicsRenderer* renderer,
|
||||||
const wxString& name,
|
const wxString& name,
|
||||||
REAL sizeInPixels,
|
REAL size,
|
||||||
int style,
|
int style,
|
||||||
const wxColour& col);
|
const wxColour& col);
|
||||||
~wxGDIPlusFontData();
|
~wxGDIPlusFontData();
|
||||||
@@ -349,8 +349,7 @@ private :
|
|||||||
void Init(const wxString& name,
|
void Init(const wxString& name,
|
||||||
REAL size,
|
REAL size,
|
||||||
int style,
|
int style,
|
||||||
const wxColour& col,
|
const wxColour& col);
|
||||||
Unit fontUnit);
|
|
||||||
|
|
||||||
Brush* m_textBrush;
|
Brush* m_textBrush;
|
||||||
Font* m_font;
|
Font* m_font;
|
||||||
@@ -986,8 +985,7 @@ void
|
|||||||
wxGDIPlusFontData::Init(const wxString& name,
|
wxGDIPlusFontData::Init(const wxString& name,
|
||||||
REAL size,
|
REAL size,
|
||||||
int style,
|
int style,
|
||||||
const wxColour& col,
|
const wxColour& col)
|
||||||
Unit fontUnit)
|
|
||||||
{
|
{
|
||||||
#if wxUSE_PRIVATE_FONTS
|
#if wxUSE_PRIVATE_FONTS
|
||||||
// If the user has registered any private fonts, they should be used in
|
// If the user has registered any private fonts, they should be used in
|
||||||
@@ -1007,7 +1005,7 @@ wxGDIPlusFontData::Init(const wxString& name,
|
|||||||
int rc = gs_pFontFamily[j].GetFamilyName(familyName);
|
int rc = gs_pFontFamily[j].GetFamilyName(familyName);
|
||||||
if ( rc == 0 && name == familyName )
|
if ( rc == 0 && name == familyName )
|
||||||
{
|
{
|
||||||
m_font = new Font(&gs_pFontFamily[j], size, style, fontUnit);
|
m_font = new Font(&gs_pFontFamily[j], size, style, UnitPoint);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1016,7 +1014,7 @@ wxGDIPlusFontData::Init(const wxString& name,
|
|||||||
if ( !m_font )
|
if ( !m_font )
|
||||||
#endif // wxUSE_PRIVATE_FONTS
|
#endif // wxUSE_PRIVATE_FONTS
|
||||||
{
|
{
|
||||||
m_font = new Font(name.wc_str(), size, style, fontUnit);
|
m_font = new Font(name.wc_str(), size, style, UnitPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_textBrush = new SolidBrush(wxColourToColor(col));
|
m_textBrush = new SolidBrush(wxColourToColor(col));
|
||||||
@@ -1037,19 +1035,17 @@ wxGDIPlusFontData::wxGDIPlusFontData( wxGraphicsRenderer* renderer,
|
|||||||
if ( font.GetWeight() == wxFONTWEIGHT_BOLD )
|
if ( font.GetWeight() == wxFONTWEIGHT_BOLD )
|
||||||
style |= FontStyleBold;
|
style |= FontStyleBold;
|
||||||
|
|
||||||
// Create font which size is measured in logical units
|
Init(font.GetFaceName(), font.GetFractionalPointSize(), style, col);
|
||||||
// and let the system rescale it according to the target resolution.
|
|
||||||
Init(font.GetFaceName(), font.GetPixelSize().GetHeight(), style, col, UnitPixel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGDIPlusFontData::wxGDIPlusFontData(wxGraphicsRenderer* renderer,
|
wxGDIPlusFontData::wxGDIPlusFontData(wxGraphicsRenderer* renderer,
|
||||||
const wxString& name,
|
const wxString& name,
|
||||||
REAL sizeInPixels,
|
REAL size,
|
||||||
int style,
|
int style,
|
||||||
const wxColour& col) :
|
const wxColour& col) :
|
||||||
wxGraphicsObjectRefData(renderer)
|
wxGraphicsObjectRefData(renderer)
|
||||||
{
|
{
|
||||||
Init(name, sizeInPixels, style, col, UnitPixel);
|
Init(name, size, style, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGDIPlusFontData::~wxGDIPlusFontData()
|
wxGDIPlusFontData::~wxGDIPlusFontData()
|
||||||
|
@@ -2637,7 +2637,7 @@ wxD2DPenData* wxGetD2DPenData(const wxGraphicsPen& pen)
|
|||||||
class wxD2DFontData : public wxGraphicsObjectRefData
|
class wxD2DFontData : public wxGraphicsObjectRefData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxD2DFontData(wxGraphicsRenderer* renderer, ID2D1Factory* d2d1Factory, const wxFont& font, const wxColor& color);
|
wxD2DFontData(wxGraphicsRenderer* renderer, const wxFont& font, const wxColor& color);
|
||||||
|
|
||||||
wxCOMPtr<IDWriteTextLayout> CreateTextLayout(const wxString& text) const;
|
wxCOMPtr<IDWriteTextLayout> CreateTextLayout(const wxString& text) const;
|
||||||
|
|
||||||
@@ -2662,7 +2662,7 @@ private:
|
|||||||
bool m_strikethrough;
|
bool m_strikethrough;
|
||||||
};
|
};
|
||||||
|
|
||||||
wxD2DFontData::wxD2DFontData(wxGraphicsRenderer* renderer, ID2D1Factory* d2dFactory, const wxFont& font, const wxColor& color) :
|
wxD2DFontData::wxD2DFontData(wxGraphicsRenderer* renderer, const wxFont& font, const wxColor& color) :
|
||||||
wxGraphicsObjectRefData(renderer), m_brushData(renderer, wxBrush(color)),
|
wxGraphicsObjectRefData(renderer), m_brushData(renderer, wxBrush(color)),
|
||||||
m_underlined(font.GetUnderlined()), m_strikethrough(font.GetStrikethrough())
|
m_underlined(font.GetUnderlined()), m_strikethrough(font.GetStrikethrough())
|
||||||
{
|
{
|
||||||
@@ -2715,16 +2715,15 @@ wxD2DFontData::wxD2DFontData(wxGraphicsRenderer* renderer, ID2D1Factory* d2dFact
|
|||||||
hr = familyNames->GetString(0, name, length+1);
|
hr = familyNames->GetString(0, name, length+1);
|
||||||
wxCHECK_HRESULT_RET(hr);
|
wxCHECK_HRESULT_RET(hr);
|
||||||
|
|
||||||
FLOAT dpiX, dpiY;
|
|
||||||
d2dFactory->GetDesktopDpi(&dpiX, &dpiY);
|
|
||||||
|
|
||||||
hr = wxDWriteFactory()->CreateTextFormat(
|
hr = wxDWriteFactory()->CreateTextFormat(
|
||||||
name,
|
name,
|
||||||
NULL,
|
NULL,
|
||||||
m_font->GetWeight(),
|
m_font->GetWeight(),
|
||||||
m_font->GetStyle(),
|
m_font->GetStyle(),
|
||||||
m_font->GetStretch(),
|
m_font->GetStretch(),
|
||||||
(FLOAT)(font.GetPixelSize().GetHeight()) / (dpiY / 96.0),
|
// We need to use DIP units for the font size, with 1dip = 1/96in,
|
||||||
|
// while wxFont uses points with 1pt = 1/72in.
|
||||||
|
font.GetFractionalPointSize()*96/72,
|
||||||
L"en-us",
|
L"en-us",
|
||||||
&m_textFormat);
|
&m_textFormat);
|
||||||
|
|
||||||
@@ -4708,7 +4707,7 @@ wxImage wxD2DRenderer::CreateImageFromBitmap(const wxGraphicsBitmap& bmp)
|
|||||||
|
|
||||||
wxGraphicsFont wxD2DRenderer::CreateFont(const wxFont& font, const wxColour& col)
|
wxGraphicsFont wxD2DRenderer::CreateFont(const wxFont& font, const wxColour& col)
|
||||||
{
|
{
|
||||||
wxD2DFontData* fontData = new wxD2DFontData(this, GetD2DFactory(), font, col);
|
wxD2DFontData* fontData = new wxD2DFontData(this, font, col);
|
||||||
if ( !fontData->GetFont() )
|
if ( !fontData->GetFont() )
|
||||||
{
|
{
|
||||||
// Apparently a non-TrueType font is given and hence
|
// Apparently a non-TrueType font is given and hence
|
||||||
|
@@ -149,8 +149,7 @@ wxFont wxCreateFontFromStockObject(int index)
|
|||||||
LOGFONT lf;
|
LOGFONT lf;
|
||||||
if ( ::GetObject(hFont, sizeof(LOGFONT), &lf) != 0 )
|
if ( ::GetObject(hFont, sizeof(LOGFONT), &lf) != 0 )
|
||||||
{
|
{
|
||||||
wxNativeFontInfo info;
|
wxNativeFontInfo info(lf);
|
||||||
info.lf = lf;
|
|
||||||
font.Create(info);
|
font.Create(info);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -182,8 +181,8 @@ wxFont wxSystemSettingsNative::GetFont(wxSystemFont index)
|
|||||||
// for most (simple) controls, e.g. buttons and such but other
|
// for most (simple) controls, e.g. buttons and such but other
|
||||||
// controls may prefer to use lfStatusFont or lfCaptionFont if it
|
// controls may prefer to use lfStatusFont or lfCaptionFont if it
|
||||||
// is more appropriate for them
|
// is more appropriate for them
|
||||||
wxNativeFontInfo info;
|
const wxNativeFontInfo
|
||||||
info.lf = wxMSWImpl::GetNonClientMetrics().lfMessageFont;
|
info(wxMSWImpl::GetNonClientMetrics().lfMessageFont);
|
||||||
gs_fontDefault = new wxFont(info);
|
gs_fontDefault = new wxFont(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -36,44 +36,23 @@
|
|||||||
class WXDLLEXPORT wxFontRefData : public wxGDIRefData
|
class WXDLLEXPORT wxFontRefData : public wxGDIRefData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxFontRefData()
|
wxFontRefData(const wxFontInfo& info = wxFontInfo());
|
||||||
{
|
|
||||||
Init(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL,
|
|
||||||
false, false, wxEmptyString, wxFONTENCODING_DEFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
wxFontRefData(float size,
|
|
||||||
wxFontFamily family,
|
|
||||||
wxFontStyle style,
|
|
||||||
wxFontWeight weight,
|
|
||||||
bool underlined,
|
|
||||||
bool strikethrough,
|
|
||||||
const wxString& faceName,
|
|
||||||
wxFontEncoding encoding)
|
|
||||||
{
|
|
||||||
Init(size, family, style, weight, underlined, strikethrough, faceName, encoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
wxFontRefData(const wxFontRefData& data);
|
wxFontRefData(const wxFontRefData& data);
|
||||||
|
|
||||||
wxFontRefData(const wxNativeFontInfo& info)
|
wxFontRefData(const wxNativeFontInfo& info)
|
||||||
|
: m_info(info)
|
||||||
{
|
{
|
||||||
Init();
|
|
||||||
m_info.Init(info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontRefData(CTFontRef font);
|
wxFontRefData(CTFontRef font);
|
||||||
|
|
||||||
virtual ~wxFontRefData();
|
|
||||||
|
|
||||||
float GetFractionalPointSize() const { return m_info.GetFractionalPointSize(); }
|
float GetFractionalPointSize() const { return m_info.GetFractionalPointSize(); }
|
||||||
|
|
||||||
wxFontFamily GetFamily() const { return m_info.GetFamily(); }
|
wxFontFamily GetFamily() const { return m_info.GetFamily(); }
|
||||||
|
|
||||||
wxFontStyle GetStyle() const { return m_info.GetStyle(); }
|
wxFontStyle GetStyle() const { return m_info.GetStyle(); }
|
||||||
|
|
||||||
wxFontWeight GetWeight() const { return m_info.GetWeight(); }
|
|
||||||
|
|
||||||
int GetNumericWeight() const { return m_info.GetNumericWeight(); }
|
int GetNumericWeight() const { return m_info.GetNumericWeight(); }
|
||||||
|
|
||||||
bool GetUnderlined() const { return m_info.GetUnderlined(); }
|
bool GetUnderlined() const { return m_info.GetUnderlined(); }
|
||||||
@@ -94,11 +73,11 @@ public:
|
|||||||
|
|
||||||
const wxNativeFontInfo& GetNativeFontInfo() const;
|
const wxNativeFontInfo& GetNativeFontInfo() const;
|
||||||
|
|
||||||
void SetPointSize(float size)
|
void SetFractionalPointSize(float size)
|
||||||
{
|
{
|
||||||
if (GetFractionalPointSize() != size)
|
if (GetFractionalPointSize() != size)
|
||||||
{
|
{
|
||||||
m_info.SetPointSize(size);
|
m_info.SetFractionalPointSize(size);
|
||||||
Free();
|
Free();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,15 +100,6 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetWeight(wxFontWeight weight)
|
|
||||||
{
|
|
||||||
if (m_info.GetWeight() != weight)
|
|
||||||
{
|
|
||||||
m_info.SetWeight(weight);
|
|
||||||
Free();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetNumericWeight(int weight)
|
void SetNumericWeight(int weight)
|
||||||
{
|
{
|
||||||
if (m_info.GetNumericWeight() != weight)
|
if (m_info.GetNumericWeight() != weight)
|
||||||
@@ -179,16 +149,6 @@ public:
|
|||||||
|
|
||||||
void Alloc();
|
void Alloc();
|
||||||
protected:
|
protected:
|
||||||
// common part of all ctors
|
|
||||||
void Init();
|
|
||||||
void Init(float size,
|
|
||||||
wxFontFamily family,
|
|
||||||
wxFontStyle style,
|
|
||||||
wxFontWeight weight,
|
|
||||||
bool underlined,
|
|
||||||
bool strikethrough,
|
|
||||||
const wxString& faceName,
|
|
||||||
wxFontEncoding encoding);
|
|
||||||
void SetFont(CTFontRef font);
|
void SetFont(CTFontRef font);
|
||||||
void AllocIfNeeded() const;
|
void AllocIfNeeded() const;
|
||||||
|
|
||||||
@@ -285,43 +245,27 @@ namespace
|
|||||||
wxFontRefData::wxFontRefData(const wxFontRefData& data)
|
wxFontRefData::wxFontRefData(const wxFontRefData& data)
|
||||||
: wxGDIRefData()
|
: wxGDIRefData()
|
||||||
{
|
{
|
||||||
Init();
|
|
||||||
m_info = data.m_info;
|
m_info = data.m_info;
|
||||||
m_ctFont = data.m_ctFont;
|
m_ctFont = data.m_ctFont;
|
||||||
m_ctFontAttributes = data.m_ctFontAttributes;
|
m_ctFontAttributes = data.m_ctFontAttributes;
|
||||||
m_cgFont = data.m_cgFont;
|
m_cgFont = data.m_cgFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFontRefData::Init()
|
wxFontRefData::wxFontRefData(const wxFontInfo& info)
|
||||||
{
|
{
|
||||||
m_info.Init();
|
m_info.Init();
|
||||||
}
|
|
||||||
|
|
||||||
void wxFontRefData::Init(float size,
|
if ( info.HasFaceName() )
|
||||||
wxFontFamily family,
|
SetFaceName(info.GetFaceName());
|
||||||
wxFontStyle style,
|
|
||||||
wxFontWeight weight,
|
|
||||||
bool underlined,
|
|
||||||
bool strikethrough,
|
|
||||||
const wxString& faceName,
|
|
||||||
wxFontEncoding encoding)
|
|
||||||
{
|
|
||||||
m_info.Init();
|
|
||||||
if ( !faceName.empty() )
|
|
||||||
SetFaceName(faceName);
|
|
||||||
else
|
else
|
||||||
SetFamily(family);
|
SetFamily(info.GetFamily());
|
||||||
SetPointSize(size < 0 ? wxNORMAL_FONT->GetFractionalPointSize() : size);
|
|
||||||
SetWeight(weight);
|
|
||||||
SetStyle(style);
|
|
||||||
SetUnderlined(underlined);
|
|
||||||
SetStrikethrough(strikethrough);
|
|
||||||
SetEncoding(encoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
wxFontRefData::~wxFontRefData()
|
m_info.SetSizeOrDefault(info.GetFractionalPointSize());
|
||||||
{
|
SetNumericWeight(info.GetNumericWeight());
|
||||||
Free();
|
SetStyle(info.GetStyle());
|
||||||
|
SetUnderlined(info.IsUnderlined());
|
||||||
|
SetStrikethrough(info.IsStrikethrough());
|
||||||
|
SetEncoding(info.GetEncoding());
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFontRefData::Free()
|
void wxFontRefData::Free()
|
||||||
@@ -333,7 +277,6 @@ void wxFontRefData::Free()
|
|||||||
|
|
||||||
wxFontRefData::wxFontRefData(CTFontRef font)
|
wxFontRefData::wxFontRefData(CTFontRef font)
|
||||||
{
|
{
|
||||||
Init();
|
|
||||||
SetFont(font);
|
SetFont(font);
|
||||||
m_info.InitFromFont(font);
|
m_info.InitFromFont(font);
|
||||||
}
|
}
|
||||||
@@ -550,6 +493,14 @@ wxFont::wxFont(const wxString& fontdesc)
|
|||||||
(void)Create(info);
|
(void)Create(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxFont::wxFont(const wxFontInfo& info)
|
||||||
|
{
|
||||||
|
m_refData = new wxFontRefData(info);
|
||||||
|
|
||||||
|
if ( info.IsUsingSizeInPixels() )
|
||||||
|
SetPixelSize(info.GetPixelSize());
|
||||||
|
}
|
||||||
|
|
||||||
wxFont::wxFont(int size,
|
wxFont::wxFont(int size,
|
||||||
int family,
|
int family,
|
||||||
int style,
|
int style,
|
||||||
@@ -562,22 +513,6 @@ wxFont::wxFont(int size,
|
|||||||
(wxFontWeight)weight, underlined, face, encoding);
|
(wxFontWeight)weight, underlined, face, encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxFont::Create(float pointSize,
|
|
||||||
wxFontFamily family,
|
|
||||||
wxFontStyle style,
|
|
||||||
wxFontWeight weight,
|
|
||||||
bool underlined,
|
|
||||||
const wxString& faceName,
|
|
||||||
wxFontEncoding encoding)
|
|
||||||
{
|
|
||||||
UnRef();
|
|
||||||
|
|
||||||
m_refData = new wxFontRefData(pointSize, family, style, weight,
|
|
||||||
underlined, false, faceName, encoding);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxFont::Create(int pointSize,
|
bool wxFont::Create(int pointSize,
|
||||||
wxFontFamily family,
|
wxFontFamily family,
|
||||||
wxFontStyle style,
|
wxFontStyle style,
|
||||||
@@ -586,12 +521,11 @@ bool wxFont::Create(int pointSize,
|
|||||||
const wxString& faceName,
|
const wxString& faceName,
|
||||||
wxFontEncoding encoding)
|
wxFontEncoding encoding)
|
||||||
{
|
{
|
||||||
// wxDEFAULT is a valid value for the font size too so we must treat it
|
m_refData = new wxFontRefData(InfoFromLegacyParams(pointSize, family,
|
||||||
// specially here (otherwise the size would be 70 == wxDEFAULT value)
|
style, weight, underlined,
|
||||||
if (pointSize == wxDEFAULT)
|
faceName, encoding));
|
||||||
pointSize = -1;
|
|
||||||
|
|
||||||
return Create((float)pointSize, family, style, weight, underlined, faceName, encoding);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFont::~wxFont()
|
wxFont::~wxFont()
|
||||||
@@ -627,14 +561,11 @@ wxGDIRefData* wxFont::CloneGDIRefData(const wxGDIRefData* data) const
|
|||||||
return new wxFontRefData(*static_cast<const wxFontRefData*>(data));
|
return new wxFontRefData(*static_cast<const wxFontRefData*>(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetPointSize(float pointSize)
|
void wxFont::SetFractionalPointSize(float pointSize)
|
||||||
{
|
{
|
||||||
if (IsOk() && M_FONTDATA->GetFractionalPointSize() == pointSize)
|
|
||||||
return;
|
|
||||||
|
|
||||||
AllocExclusive();
|
AllocExclusive();
|
||||||
|
|
||||||
M_FONTDATA->SetPointSize(pointSize);
|
M_FONTDATA->SetFractionalPointSize(pointSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetFamily(wxFontFamily family)
|
void wxFont::SetFamily(wxFontFamily family)
|
||||||
@@ -651,13 +582,6 @@ void wxFont::SetStyle(wxFontStyle style)
|
|||||||
M_FONTDATA->SetStyle(style);
|
M_FONTDATA->SetStyle(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetWeight(wxFontWeight weight)
|
|
||||||
{
|
|
||||||
AllocExclusive();
|
|
||||||
|
|
||||||
M_FONTDATA->SetWeight(weight);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxFont::SetNumericWeight(int weight)
|
void wxFont::SetNumericWeight(int weight)
|
||||||
{
|
{
|
||||||
AllocExclusive();
|
AllocExclusive();
|
||||||
@@ -738,13 +662,6 @@ wxFontStyle wxFont::GetStyle() const
|
|||||||
return M_FONTDATA->GetStyle();
|
return M_FONTDATA->GetStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontWeight wxFont::GetWeight() const
|
|
||||||
{
|
|
||||||
wxCHECK_MSG(IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font"));
|
|
||||||
|
|
||||||
return M_FONTDATA->GetWeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
int wxFont::GetNumericWeight() const
|
int wxFont::GetNumericWeight() const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG(IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font"));
|
wxCHECK_MSG(IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font"));
|
||||||
@@ -972,6 +889,7 @@ CGFloat wxNativeFontInfo::GetCTSlant(CTFontDescriptorRef descr)
|
|||||||
//
|
//
|
||||||
bool wxNativeFontInfo::FromString(const wxString& s)
|
bool wxNativeFontInfo::FromString(const wxString& s)
|
||||||
{
|
{
|
||||||
|
double d;
|
||||||
long l, version;
|
long l, version;
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
@@ -987,9 +905,16 @@ bool wxNativeFontInfo::FromString(const wxString& s)
|
|||||||
//
|
//
|
||||||
|
|
||||||
token = tokenizer.GetNextToken();
|
token = tokenizer.GetNextToken();
|
||||||
if ( !token.ToLong(&l) )
|
if ( !token.ToCDouble(&d) )
|
||||||
return false;
|
return false;
|
||||||
m_ctSize = (int)l;
|
#ifdef __LP64__
|
||||||
|
// CGFloat is just double in this case.
|
||||||
|
m_ctSize = d;
|
||||||
|
#else // !__LP64__
|
||||||
|
m_ctSize = static_cast<CGFloat>(d);
|
||||||
|
if ( static_cast<double>(m_ctSize) != d )
|
||||||
|
return false;
|
||||||
|
#endif // __LP64__/!__LP64__
|
||||||
|
|
||||||
token = tokenizer.GetNextToken();
|
token = tokenizer.GetNextToken();
|
||||||
if ( !token.ToLong(&l) )
|
if ( !token.ToLong(&l) )
|
||||||
@@ -1042,12 +967,12 @@ wxString wxNativeFontInfo::ToString() const
|
|||||||
{
|
{
|
||||||
wxString s;
|
wxString s;
|
||||||
|
|
||||||
s.Printf(wxT("%d;%d;%d;%d;%d;%d;%d;%s;%d"),
|
s.Printf(wxT("%d;%f;%d;%d;%d;%d;%d;%s;%d"),
|
||||||
1, // version
|
1, // version
|
||||||
GetPointSize(),
|
GetFractionalPointSize(),
|
||||||
GetFamily(),
|
GetFamily(),
|
||||||
(int)GetStyle(),
|
(int)GetStyle(),
|
||||||
(int)GetWeight(),
|
GetNumericWeight(),
|
||||||
GetUnderlined(),
|
GetUnderlined(),
|
||||||
GetStrikethrough(),
|
GetStrikethrough(),
|
||||||
GetFaceName().GetData(),
|
GetFaceName().GetData(),
|
||||||
@@ -1056,11 +981,6 @@ wxString wxNativeFontInfo::ToString() const
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxNativeFontInfo::GetPointSize() const
|
|
||||||
{
|
|
||||||
return wxRound(GetFractionalPointSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
float wxNativeFontInfo::GetFractionalPointSize() const
|
float wxNativeFontInfo::GetFractionalPointSize() const
|
||||||
{
|
{
|
||||||
return m_ctSize;
|
return m_ctSize;
|
||||||
@@ -1141,9 +1061,9 @@ bool wxNativeFontInfo::GetStrikethrough() const
|
|||||||
|
|
||||||
// changing the font descriptor
|
// changing the font descriptor
|
||||||
|
|
||||||
void wxNativeFontInfo::SetPointSize(float pointsize)
|
void wxNativeFontInfo::SetFractionalPointSize(float pointsize)
|
||||||
{
|
{
|
||||||
if (GetPointSize() != pointsize)
|
if (GetFractionalPointSize() != pointsize)
|
||||||
{
|
{
|
||||||
m_ctSize = pointsize;
|
m_ctSize = pointsize;
|
||||||
|
|
||||||
|
@@ -2895,17 +2895,7 @@ wxMacCoreGraphicsRenderer::CreateFont(double sizeInPixels,
|
|||||||
// Notice that under Mac we always use 72 DPI so the font size in pixels is
|
// Notice that under Mac we always use 72 DPI so the font size in pixels is
|
||||||
// the same as the font size in points and we can pass it directly to wxFont
|
// the same as the font size in points and we can pass it directly to wxFont
|
||||||
// ctor.
|
// ctor.
|
||||||
wxFont font((float)sizeInPixels,
|
wxFont font(wxFontInfo(sizeInPixels).FaceName(facename).AllFlags(flags));
|
||||||
wxFONTFAMILY_DEFAULT,
|
|
||||||
flags & wxFONTFLAG_ITALIC ? wxFONTSTYLE_ITALIC
|
|
||||||
: wxFONTSTYLE_NORMAL,
|
|
||||||
flags & wxFONTFLAG_BOLD ? wxFONTWEIGHT_BOLD
|
|
||||||
: wxFONTWEIGHT_NORMAL,
|
|
||||||
(flags & wxFONTFLAG_UNDERLINED) != 0,
|
|
||||||
facename);
|
|
||||||
|
|
||||||
if ( flags & wxFONTFLAG_STRIKETHROUGH )
|
|
||||||
font.MakeStrikethrough();
|
|
||||||
|
|
||||||
wxGraphicsFont f;
|
wxGraphicsFont f;
|
||||||
f.SetRefData(new wxMacCoreGraphicsFontData(this, font, col));
|
f.SetRefData(new wxMacCoreGraphicsFontData(this, font, col));
|
||||||
|
@@ -2056,7 +2056,7 @@ wxWindow* wxPropertyGrid::GenerateEditorButton( const wxPoint& pos, const wxSize
|
|||||||
|
|
||||||
#ifdef __WXGTK__
|
#ifdef __WXGTK__
|
||||||
wxFont font = GetFont();
|
wxFont font = GetFont();
|
||||||
font.SetPointSize(font.GetPointSize()-2);
|
font.SetFractionalPointSize(font.GetFractionalPointSize()-2);
|
||||||
but->SetFont(font);
|
but->SetFont(font);
|
||||||
#else
|
#else
|
||||||
but->SetFont(GetFont());
|
but->SetFont(GetFont());
|
||||||
|
189
src/qt/font.cpp
189
src/qt/font.cpp
@@ -53,48 +53,83 @@ static QFont::StyleHint ConvertFontFamily(wxFontFamily family)
|
|||||||
return QFont::AnyStyle;
|
return QFont::AnyStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QFont::Weight ConvertFontWeight(int weight)
|
// Helper of ConvertFontWeight() and GetNumericWeight(): if a value lies in
|
||||||
|
// ]fromMin, fromMax] interval, then map it to [toMin, toMax] interval linearly
|
||||||
|
// and return true, otherwise return false and don't modify it.
|
||||||
|
static bool TryToMap(int& x, int fromMin, int fromMax, int toMin, int toMax)
|
||||||
{
|
{
|
||||||
switch (weight)
|
if ( x > fromMin && x <= fromMax )
|
||||||
{
|
{
|
||||||
case wxFONTWEIGHT_NORMAL:
|
x = (toMin*(fromMax - x) + toMax*(x - fromMin))/(fromMax - fromMin);
|
||||||
return QFont::Normal;
|
|
||||||
|
|
||||||
case wxFONTWEIGHT_LIGHT:
|
return true;
|
||||||
return QFont::Light;
|
|
||||||
|
|
||||||
case wxFONTWEIGHT_BOLD:
|
|
||||||
return QFont::Bold;
|
|
||||||
|
|
||||||
case wxFONTWEIGHT_SEMIBOLD:
|
|
||||||
return QFont::DemiBold;
|
|
||||||
|
|
||||||
case wxFONTWEIGHT_HEAVY:
|
|
||||||
return QFont::Black;
|
|
||||||
|
|
||||||
case wxFONTWEIGHT_MAX:
|
|
||||||
wxFAIL_MSG( "Invalid font weight value" );
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ConvertFontWeight(int w)
|
||||||
|
{
|
||||||
|
// Note that QFont::Thin is 0, so we can't have anything lighter than it.
|
||||||
|
if ( TryToMap(w, wxFONTWEIGHT_INVALID, wxFONTWEIGHT_THIN,
|
||||||
|
QFont::Thin, QFont::Thin) ||
|
||||||
|
TryToMap(w, wxFONTWEIGHT_THIN, wxFONTWEIGHT_EXTRALIGHT,
|
||||||
|
QFont::Thin, QFont::ExtraLight) ||
|
||||||
|
TryToMap(w, wxFONTWEIGHT_EXTRALIGHT, wxFONTWEIGHT_LIGHT,
|
||||||
|
QFont::ExtraLight, QFont::Light) ||
|
||||||
|
TryToMap(w, wxFONTWEIGHT_LIGHT, wxFONTWEIGHT_NORMAL,
|
||||||
|
QFont::Light, QFont::Normal) ||
|
||||||
|
TryToMap(w, wxFONTWEIGHT_NORMAL, wxFONTWEIGHT_MEDIUM,
|
||||||
|
QFont::Normal, QFont::Medium) ||
|
||||||
|
TryToMap(w, wxFONTWEIGHT_MEDIUM, wxFONTWEIGHT_SEMIBOLD,
|
||||||
|
QFont::Medium, QFont::DemiBold) ||
|
||||||
|
TryToMap(w, wxFONTWEIGHT_SEMIBOLD, wxFONTWEIGHT_BOLD,
|
||||||
|
QFont::DemiBold, QFont::Bold) ||
|
||||||
|
TryToMap(w, wxFONTWEIGHT_BOLD, wxFONTWEIGHT_EXTRABOLD,
|
||||||
|
QFont::Bold, QFont::ExtraBold) ||
|
||||||
|
TryToMap(w, wxFONTWEIGHT_EXTRABOLD, wxFONTWEIGHT_HEAVY,
|
||||||
|
QFont::ExtraBold, QFont::Black) ||
|
||||||
|
TryToMap(w, wxFONTWEIGHT_HEAVY, wxFONTWEIGHT_EXTRAHEAVY,
|
||||||
|
QFont::Black, 99) )
|
||||||
|
{
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxFAIL_MSG("invalid wxFont weight");
|
||||||
|
|
||||||
return QFont::Normal;
|
return QFont::Normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
class wxFontRefData: public wxGDIRefData
|
class wxFontRefData: public wxGDIRefData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxFontRefData() {}
|
wxFontRefData() {}
|
||||||
|
|
||||||
|
wxFontRefData(const wxFontInfo& info)
|
||||||
|
{
|
||||||
|
if ( info.HasFaceName() )
|
||||||
|
m_nativeFontInfo.SetFaceName(info.GetFaceName());
|
||||||
|
else
|
||||||
|
m_nativeFontInfo.SetFamily(info.GetFamily());
|
||||||
|
|
||||||
|
if ( info.IsUsingSizeInPixels() )
|
||||||
|
m_nativeFontInfo.SetPixelSize(info.GetPixelSize());
|
||||||
|
else
|
||||||
|
m_nativeFontInfo.SetFractionalPointSize(info.GetFractionalPointSize());
|
||||||
|
|
||||||
|
m_nativeFontInfo.SetStyle(info.GetStyle());
|
||||||
|
m_nativeFontInfo.SetWeight(info.GetWeight());
|
||||||
|
m_nativeFontInfo.SetUnderlined(info.IsUnderlined());
|
||||||
|
m_nativeFontInfo.SetStrikethrough(info.IsStrikethrough());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
wxFontRefData( const wxFontRefData& data )
|
wxFontRefData( const wxFontRefData& data )
|
||||||
: wxGDIRefData()
|
: wxGDIRefData()
|
||||||
{
|
{
|
||||||
m_nativeFontInfo.m_qtFont = data.m_nativeFontInfo.m_qtFont;
|
m_nativeFontInfo.m_qtFont = data.m_nativeFontInfo.m_qtFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator == (const wxFontRefData& data) const
|
|
||||||
{
|
|
||||||
return m_nativeFontInfo.m_qtFont == data.m_nativeFontInfo.m_qtFont;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxNativeFontInfo m_nativeFontInfo;
|
wxNativeFontInfo m_nativeFontInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -107,20 +142,7 @@ wxFont::wxFont()
|
|||||||
|
|
||||||
wxFont::wxFont(const wxFontInfo& info)
|
wxFont::wxFont(const wxFontInfo& info)
|
||||||
{
|
{
|
||||||
m_refData = new wxFontRefData();
|
m_refData = new wxFontRefData(info);
|
||||||
Create(wxSize(0, info.GetPointSize()),
|
|
||||||
info.GetFamily(),
|
|
||||||
info.GetStyle(),
|
|
||||||
info.GetWeight(),
|
|
||||||
info.IsUnderlined(),
|
|
||||||
info.GetFaceName(),
|
|
||||||
info.GetEncoding());
|
|
||||||
|
|
||||||
SetStrikethrough(info.IsStrikethrough());
|
|
||||||
|
|
||||||
wxSize pixelSize = info.GetPixelSize();
|
|
||||||
if ( pixelSize != wxDefaultSize )
|
|
||||||
SetPixelSize(pixelSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFont::wxFont(const wxString& nativeFontInfoString)
|
wxFont::wxFont(const wxString& nativeFontInfoString)
|
||||||
@@ -166,7 +188,6 @@ wxFont::wxFont(const wxSize& pixelSize,
|
|||||||
const wxString& face,
|
const wxString& face,
|
||||||
wxFontEncoding encoding)
|
wxFontEncoding encoding)
|
||||||
{
|
{
|
||||||
m_refData = new wxFontRefData();
|
|
||||||
Create(pixelSize, family, style, weight, underlined, face, encoding);
|
Create(pixelSize, family, style, weight, underlined, face, encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,31 +199,26 @@ wxFont::wxFont(int size,
|
|||||||
const wxString& face,
|
const wxString& face,
|
||||||
wxFontEncoding encoding)
|
wxFontEncoding encoding)
|
||||||
{
|
{
|
||||||
m_refData = new wxFontRefData();
|
|
||||||
Create(wxSize(0, size), (wxFontFamily)family, (wxFontStyle)style, (wxFontWeight)weight, underlined, face, encoding);
|
Create(wxSize(0, size), (wxFontFamily)family, (wxFontStyle)style, (wxFontWeight)weight, underlined, face, encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool wxFont::Create(wxSize size, wxFontFamily family, wxFontStyle style,
|
bool wxFont::Create(wxSize size, wxFontFamily family, wxFontStyle style,
|
||||||
wxFontWeight weight, bool underlined, const wxString& face,
|
wxFontWeight weight, bool underlined, const wxString& face,
|
||||||
wxFontEncoding WXUNUSED(encoding) )
|
wxFontEncoding encoding )
|
||||||
{
|
{
|
||||||
if (!face.empty())
|
UnRef();
|
||||||
M_FONTDATA.SetFaceName(face);
|
|
||||||
else
|
|
||||||
M_FONTDATA.SetFamily(family);
|
|
||||||
|
|
||||||
M_FONTDATA.SetStyle(style);
|
m_refData = new wxFontRefData(InfoFromLegacyParams(size.GetHeight(), family,
|
||||||
M_FONTDATA.SetWeight(weight);
|
style, weight, underlined,
|
||||||
M_FONTDATA.SetUnderlined(underlined);
|
face, encoding));
|
||||||
M_FONTDATA.SetPointSize(size.GetHeight());
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxFont::GetPointSize() const
|
float wxFont::GetFractionalPointSize() const
|
||||||
{
|
{
|
||||||
return M_FONTDATA.GetPointSize();
|
return M_FONTDATA.GetFractionalPointSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontStyle wxFont::GetStyle() const
|
wxFontStyle wxFont::GetStyle() const
|
||||||
@@ -210,9 +226,9 @@ wxFontStyle wxFont::GetStyle() const
|
|||||||
return M_FONTDATA.GetStyle();
|
return M_FONTDATA.GetStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontWeight wxFont::GetWeight() const
|
int wxFont::GetNumericWeight() const
|
||||||
{
|
{
|
||||||
return M_FONTDATA.GetWeight();
|
return M_FONTDATA.GetNumericWeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxFont::GetUnderlined() const
|
bool wxFont::GetUnderlined() const
|
||||||
@@ -235,11 +251,11 @@ const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
|
|||||||
return &M_FONTDATA;
|
return &M_FONTDATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetPointSize( int pointSize )
|
void wxFont::SetFractionalPointSize(float pointSize)
|
||||||
{
|
{
|
||||||
AllocExclusive();
|
AllocExclusive();
|
||||||
|
|
||||||
M_FONTDATA.SetPointSize(pointSize);
|
M_FONTDATA.SetFractionalPointSize(pointSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxFont::SetFaceName(const wxString& facename)
|
bool wxFont::SetFaceName(const wxString& facename)
|
||||||
@@ -263,11 +279,11 @@ void wxFont::SetStyle( wxFontStyle style )
|
|||||||
M_FONTDATA.SetStyle(style);
|
M_FONTDATA.SetStyle(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetWeight( wxFontWeight weight )
|
void wxFont::SetNumericWeight(int weight)
|
||||||
{
|
{
|
||||||
AllocExclusive();
|
AllocExclusive();
|
||||||
|
|
||||||
M_FONTDATA.SetWeight(weight);
|
M_FONTDATA.SetNumericWeight(weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetUnderlined( bool underlined )
|
void wxFont::SetUnderlined( bool underlined )
|
||||||
@@ -312,9 +328,9 @@ void wxNativeFontInfo::Init()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxNativeFontInfo::GetPointSize() const
|
float wxNativeFontInfo::GetFractionalPointSize() const
|
||||||
{
|
{
|
||||||
return m_qtFont.pointSize();
|
return m_qtFont.pointSizeF();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontStyle wxNativeFontInfo::GetStyle() const
|
wxFontStyle wxNativeFontInfo::GetStyle() const
|
||||||
@@ -336,24 +352,36 @@ wxFontStyle wxNativeFontInfo::GetStyle() const
|
|||||||
|
|
||||||
int wxNativeFontInfo::GetNumericWeight() const
|
int wxNativeFontInfo::GetNumericWeight() const
|
||||||
{
|
{
|
||||||
switch ( m_qtFont.weight() )
|
int w = m_qtFont.weight();
|
||||||
|
|
||||||
|
// Special case of QFont::Thin == 0.
|
||||||
|
if ( w == QFont::Thin )
|
||||||
|
return wxFONTWEIGHT_THIN;
|
||||||
|
|
||||||
|
if ( TryToMap(w, QFont::Thin, QFont::ExtraLight,
|
||||||
|
wxFONTWEIGHT_THIN, wxFONTWEIGHT_EXTRALIGHT) ||
|
||||||
|
TryToMap(w, QFont::ExtraLight, QFont::Light,
|
||||||
|
wxFONTWEIGHT_EXTRALIGHT, wxFONTWEIGHT_LIGHT) ||
|
||||||
|
TryToMap(w, QFont::Light, QFont::Normal,
|
||||||
|
wxFONTWEIGHT_LIGHT, wxFONTWEIGHT_NORMAL) ||
|
||||||
|
TryToMap(w, QFont::Normal, QFont::Medium,
|
||||||
|
wxFONTWEIGHT_NORMAL, wxFONTWEIGHT_MEDIUM) ||
|
||||||
|
TryToMap(w, QFont::Medium, QFont::DemiBold,
|
||||||
|
wxFONTWEIGHT_MEDIUM, wxFONTWEIGHT_SEMIBOLD) ||
|
||||||
|
TryToMap(w, QFont::DemiBold, QFont::Bold,
|
||||||
|
wxFONTWEIGHT_SEMIBOLD, wxFONTWEIGHT_BOLD) ||
|
||||||
|
TryToMap(w, QFont::Bold, QFont::ExtraBold,
|
||||||
|
wxFONTWEIGHT_BOLD, wxFONTWEIGHT_EXTRABOLD) ||
|
||||||
|
TryToMap(w, QFont::ExtraBold, QFont::Black,
|
||||||
|
wxFONTWEIGHT_EXTRABOLD, wxFONTWEIGHT_HEAVY) ||
|
||||||
|
TryToMap(w, QFont::Black, 99,
|
||||||
|
wxFONTWEIGHT_HEAVY, wxFONTWEIGHT_EXTRAHEAVY) )
|
||||||
{
|
{
|
||||||
case QFont::Normal:
|
return w;
|
||||||
return wxFONTWEIGHT_NORMAL;
|
|
||||||
|
|
||||||
case QFont::Light:
|
|
||||||
return wxFONTWEIGHT_LIGHT;
|
|
||||||
|
|
||||||
case QFont::DemiBold:
|
|
||||||
return wxFONTWEIGHT_SEMIBOLD;
|
|
||||||
|
|
||||||
case QFont::Black:
|
|
||||||
return wxFONTWEIGHT_HEAVY;
|
|
||||||
|
|
||||||
case QFont::Bold:
|
|
||||||
return wxFONTWEIGHT_BOLD;
|
|
||||||
}
|
}
|
||||||
wxFAIL_MSG( "Invalid font weight value" );
|
|
||||||
|
wxFAIL_MSG( "Invalid QFont weight" );
|
||||||
|
|
||||||
return wxFONTWEIGHT_NORMAL;
|
return wxFONTWEIGHT_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,9 +437,14 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
|
|||||||
return wxFONTENCODING_MAX;
|
return wxFONTENCODING_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetPointSize(int pointsize)
|
void wxNativeFontInfo::SetFractionalPointSize(float pointsize)
|
||||||
{
|
{
|
||||||
m_qtFont.setPointSize(pointsize);
|
m_qtFont.setPointSizeF(pointsize);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxNativeFontInfo::SetPixelSize(const wxSize& size)
|
||||||
|
{
|
||||||
|
m_qtFont.setPixelSize(size.GetHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetStyle(wxFontStyle style)
|
void wxNativeFontInfo::SetStyle(wxFontStyle style)
|
||||||
|
@@ -6843,7 +6843,7 @@ bool wxRichTextPlainText::Draw(wxDC& dc, wxRichTextDrawingContext& context, cons
|
|||||||
{
|
{
|
||||||
if (textAttr.HasTextEffects() && (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SMALL_CAPITALS))
|
if (textAttr.HasTextEffects() && (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SMALL_CAPITALS))
|
||||||
{
|
{
|
||||||
textFont.SetPointSize((int) (textFont.GetPointSize()*0.75));
|
textFont.SetFractionalPointSize(textFont.GetFractionalPointSize()*0.75);
|
||||||
wxCheckSetFont(dc, textFont);
|
wxCheckSetFont(dc, textFont);
|
||||||
charHeight = dc.GetCharHeight();
|
charHeight = dc.GetCharHeight();
|
||||||
}
|
}
|
||||||
@@ -6859,8 +6859,7 @@ bool wxRichTextPlainText::Draw(wxDC& dc, wxRichTextDrawingContext& context, cons
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
double size = static_cast<double>(textFont.GetPointSize()) / wxSCRIPT_MUL_FACTOR;
|
textFont.SetFractionalPointSize(textFont.GetFractionalPointSize() / wxSCRIPT_MUL_FACTOR);
|
||||||
textFont.SetPointSize(static_cast<int>(size));
|
|
||||||
x = rect.x;
|
x = rect.x;
|
||||||
y = rect.y;
|
y = rect.y;
|
||||||
}
|
}
|
||||||
@@ -6878,8 +6877,7 @@ bool wxRichTextPlainText::Draw(wxDC& dc, wxRichTextDrawingContext& context, cons
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
double size = static_cast<double>(textFont.GetPointSize()) / wxSCRIPT_MUL_FACTOR;
|
textFont.SetFractionalPointSize(textFont.GetFractionalPointSize() / wxSCRIPT_MUL_FACTOR);
|
||||||
textFont.SetPointSize(static_cast<int>(size));
|
|
||||||
x = rect.x;
|
x = rect.x;
|
||||||
int sub_height = static_cast<int>(static_cast<double>(charHeight) / wxSCRIPT_MUL_FACTOR);
|
int sub_height = static_cast<int>(static_cast<double>(charHeight) / wxSCRIPT_MUL_FACTOR);
|
||||||
y = rect.y + (rect.height - sub_height + (descent - m_descent));
|
y = rect.y + (rect.height - sub_height + (descent - m_descent));
|
||||||
@@ -7197,8 +7195,7 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
double textSize = static_cast<double>(textFont.GetPointSize()) / wxSCRIPT_MUL_FACTOR;
|
textFont.SetFractionalPointSize(textFont.GetFractionalPointSize() / wxSCRIPT_MUL_FACTOR);
|
||||||
textFont.SetPointSize(static_cast<int>(textSize));
|
|
||||||
}
|
}
|
||||||
wxCheckSetFont(dc, textFont);
|
wxCheckSetFont(dc, textFont);
|
||||||
bScript = true;
|
bScript = true;
|
||||||
@@ -7206,7 +7203,7 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz
|
|||||||
else if (textAttr.HasTextEffects() && (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SMALL_CAPITALS))
|
else if (textAttr.HasTextEffects() && (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SMALL_CAPITALS))
|
||||||
{
|
{
|
||||||
wxFont textFont = font;
|
wxFont textFont = font;
|
||||||
textFont.SetPointSize((int) (textFont.GetPointSize()*0.75));
|
textFont.SetFractionalPointSize(textFont.GetFractionalPointSize()*0.75);
|
||||||
wxCheckSetFont(dc, textFont);
|
wxCheckSetFont(dc, textFont);
|
||||||
bScript = true;
|
bScript = true;
|
||||||
}
|
}
|
||||||
@@ -9264,8 +9261,7 @@ void wxRichTextStdRenderer::SetFontForBullet(wxRichTextBuffer& buffer, wxDC& dc,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
double size = static_cast<double>(textFont.GetPointSize()) / wxSCRIPT_MUL_FACTOR;
|
textFont.SetFractionalPointSize(textFont.GetFractionalPointSize() / wxSCRIPT_MUL_FACTOR);
|
||||||
textFont.SetPointSize(static_cast<int>(size));
|
|
||||||
}
|
}
|
||||||
wxCheckSetFont(dc, textFont);
|
wxCheckSetFont(dc, textFont);
|
||||||
}
|
}
|
||||||
@@ -9278,7 +9274,7 @@ void wxRichTextStdRenderer::SetFontForBullet(wxRichTextBuffer& buffer, wxDC& dc,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
textFont.SetPointSize((int) (textFont.GetPointSize()*0.75));
|
textFont.SetFractionalPointSize(textFont.GetFractionalPointSize()*0.75);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxCheckSetFont(dc, textFont);
|
wxCheckSetFont(dc, textFont);
|
||||||
|
@@ -516,8 +516,7 @@ void wxRichTextFontPreviewCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
|
|||||||
|
|
||||||
if ((GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT) || (GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT))
|
if ((GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT) || (GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT))
|
||||||
{
|
{
|
||||||
double fontSize = static_cast<double>(font.GetPointSize()) / wxSCRIPT_MUL_FACTOR;
|
font.SetFractionalPointSize(font.GetFractionalPointSize() / wxSCRIPT_MUL_FACTOR);
|
||||||
font.SetPointSize( static_cast<int>(fontSize) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( font.IsOk() )
|
if ( font.IsOk() )
|
||||||
|
@@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
#include "wx/encinfo.h"
|
#include "wx/encinfo.h"
|
||||||
#include "wx/fontmap.h"
|
#include "wx/fontmap.h"
|
||||||
|
#include "wx/math.h"
|
||||||
#include "wx/tokenzr.h"
|
#include "wx/tokenzr.h"
|
||||||
#include "wx/fontenum.h"
|
#include "wx/fontenum.h"
|
||||||
|
|
||||||
@@ -90,11 +91,6 @@ void wxNativeFontInfo::Free()
|
|||||||
pango_font_description_free(description);
|
pango_font_description_free(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxNativeFontInfo::GetPointSize() const
|
|
||||||
{
|
|
||||||
return wxRound(GetFractionalPointSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
float wxNativeFontInfo::GetFractionalPointSize() const
|
float wxNativeFontInfo::GetFractionalPointSize() const
|
||||||
{
|
{
|
||||||
return ((float) pango_font_description_get_size( description )) / PANGO_SCALE;
|
return ((float) pango_font_description_get_size( description )) / PANGO_SCALE;
|
||||||
@@ -219,9 +215,9 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
|
|||||||
return wxFONTENCODING_SYSTEM;
|
return wxFONTENCODING_SYSTEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetPointSize(float pointsize)
|
void wxNativeFontInfo::SetFractionalPointSize(float pointsize)
|
||||||
{
|
{
|
||||||
pango_font_description_set_size( description, pointsize * PANGO_SCALE );
|
pango_font_description_set_size( description, wxRound(pointsize * PANGO_SCALE) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetStyle(wxFontStyle style)
|
void wxNativeFontInfo::SetStyle(wxFontStyle style)
|
||||||
@@ -493,10 +489,10 @@ static wxHashTable *g_fontHash = NULL;
|
|||||||
|
|
||||||
static bool wxTestFontSpec(const wxString& fontspec);
|
static bool wxTestFontSpec(const wxString& fontspec);
|
||||||
|
|
||||||
static wxNativeFont wxLoadQueryFont(int pointSize,
|
static wxNativeFont wxLoadQueryFont(float pointSize,
|
||||||
wxFontFamily family,
|
wxFontFamily family,
|
||||||
wxFontStyle style,
|
wxFontStyle style,
|
||||||
wxFontWeight weight,
|
int weight,
|
||||||
bool underlined,
|
bool underlined,
|
||||||
const wxString& facename,
|
const wxString& facename,
|
||||||
const wxString& xregistry,
|
const wxString& xregistry,
|
||||||
@@ -675,18 +671,10 @@ wxNativeFontInfo::SetXFontComponent(wxXLFDField field, const wxString& value)
|
|||||||
{
|
{
|
||||||
wxCHECK_RET( field < wxXLFD_MAX, wxT("invalid XLFD field") );
|
wxCHECK_RET( field < wxXLFD_MAX, wxT("invalid XLFD field") );
|
||||||
|
|
||||||
// this class should be initialized with a valid font spec first and only
|
|
||||||
// then the fields may be modified!
|
|
||||||
wxASSERT_MSG( !IsDefault(), wxT("can't modify an uninitialized XLFD") );
|
|
||||||
|
|
||||||
if ( !HasElements() )
|
if ( !HasElements() )
|
||||||
{
|
{
|
||||||
if ( !const_cast<wxNativeFontInfo *>(this)->FromXFontName(xFontName) )
|
for ( int field = 0; field < wxXLFD_MAX; field++ )
|
||||||
{
|
fontElements[field] = '*';
|
||||||
wxFAIL_MSG( wxT("can't set font element for invalid XLFD") );
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fontElements[field] = value;
|
fontElements[field] = value;
|
||||||
@@ -705,11 +693,6 @@ void wxNativeFontInfo::SetXFontName(const wxString& xFontName_)
|
|||||||
m_isDefault = false;
|
m_isDefault = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxNativeFontInfo::GetPointSize() const
|
|
||||||
{
|
|
||||||
return wxRound(GetFractionalPointSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
float wxNativeFontInfo::GetFractionalPointSize() const
|
float wxNativeFontInfo::GetFractionalPointSize() const
|
||||||
{
|
{
|
||||||
const wxString s = GetXFontComponent(wxXLFD_POINTSIZE);
|
const wxString s = GetXFontComponent(wxXLFD_POINTSIZE);
|
||||||
@@ -802,9 +785,15 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
|
|||||||
return wxFONTENCODING_MAX;
|
return wxFONTENCODING_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetPointSize(float pointsize)
|
void wxNativeFontInfo::SetFractionalPointSize(float pointsize)
|
||||||
{
|
{
|
||||||
SetXFontComponent(wxXLFD_POINTSIZE, wxString::Format(wxT("%d"), pointsize));
|
wxString s;
|
||||||
|
if ( pointsize < 0 )
|
||||||
|
s = '*';
|
||||||
|
else
|
||||||
|
s.Printf("%d", wxRound(10*pointsize));
|
||||||
|
|
||||||
|
SetXFontComponent(wxXLFD_POINTSIZE, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetStyle(wxFontStyle style)
|
void wxNativeFontInfo::SetStyle(wxFontStyle style)
|
||||||
@@ -822,6 +811,7 @@ void wxNativeFontInfo::SetStyle(wxFontStyle style)
|
|||||||
|
|
||||||
case wxFONTSTYLE_NORMAL:
|
case wxFONTSTYLE_NORMAL:
|
||||||
s = wxT('r');
|
s = wxT('r');
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
wxFAIL_MSG( wxT("unknown wxFontStyle in wxNativeFontInfo::SetStyle") );
|
wxFAIL_MSG( wxT("unknown wxFontStyle in wxNativeFontInfo::SetStyle") );
|
||||||
@@ -831,28 +821,58 @@ void wxNativeFontInfo::SetStyle(wxFontStyle style)
|
|||||||
SetXFontComponent(wxXLFD_SLANT, s);
|
SetXFontComponent(wxXLFD_SLANT, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetWeight(wxFontWeight weight)
|
void wxNativeFontInfo::SetNumericWeight(int weight)
|
||||||
{
|
{
|
||||||
wxString s;
|
wxString s;
|
||||||
switch ( weight )
|
switch ( wxFontInfo::GetWeightClosestToNumericValue(weight) )
|
||||||
{
|
{
|
||||||
case wxFONTWEIGHT_BOLD:
|
case wxFONTWEIGHT_THIN:
|
||||||
s = wxT("bold");
|
s = "thin";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxFONTWEIGHT_EXTRALIGHT:
|
||||||
|
s = "extralight";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case wxFONTWEIGHT_LIGHT:
|
case wxFONTWEIGHT_LIGHT:
|
||||||
s = wxT("light");
|
s = "light";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case wxFONTWEIGHT_NORMAL:
|
case wxFONTWEIGHT_NORMAL:
|
||||||
s = wxT("medium");
|
s = "normal";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case wxFONTWEIGHT_MEDIUM:
|
||||||
wxFAIL_MSG( wxT("unknown wxFontWeight in wxNativeFontInfo::SetWeight") );
|
s = "medium";
|
||||||
return;
|
break;
|
||||||
|
|
||||||
|
case wxFONTWEIGHT_SEMIBOLD:
|
||||||
|
s = "semibold";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxFONTWEIGHT_BOLD:
|
||||||
|
s = "bold";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxFONTWEIGHT_EXTRABOLD:
|
||||||
|
s = "extrabold";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxFONTWEIGHT_HEAVY:
|
||||||
|
s = "heavy";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxFONTWEIGHT_EXTRAHEAVY:
|
||||||
|
s = "extraheavy";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case wxFONTWEIGHT_INVALID:
|
||||||
|
wxFAIL_MSG( "Invalid font weight" );
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxCHECK_RET( !s.empty(), "unknown weight value" );
|
||||||
|
|
||||||
SetXFontComponent(wxXLFD_WEIGHT, s);
|
SetXFontComponent(wxXLFD_WEIGHT, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -872,12 +892,24 @@ bool wxNativeFontInfo::SetFaceName(const wxString& facename)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetFamily(wxFontFamily WXUNUSED(family))
|
void wxNativeFontInfo::SetFamily(wxFontFamily family)
|
||||||
{
|
{
|
||||||
// wxFontFamily -> X foundry, anyone?
|
wxString xfamily;
|
||||||
wxFAIL_MSG( wxT("not implemented") );
|
switch (family)
|
||||||
|
{
|
||||||
|
case wxFONTFAMILY_DECORATIVE: xfamily = "lucida"; break;
|
||||||
|
case wxFONTFAMILY_ROMAN: xfamily = "times"; break;
|
||||||
|
case wxFONTFAMILY_MODERN: xfamily = "courier"; break;
|
||||||
|
case wxFONTFAMILY_DEFAULT:
|
||||||
|
case wxFONTFAMILY_SWISS: xfamily = "helvetica"; break;
|
||||||
|
case wxFONTFAMILY_TELETYPE: xfamily = "lucidatypewriter"; break;
|
||||||
|
case wxFONTFAMILY_SCRIPT: xfamily = "utopia"; break;
|
||||||
|
case wxFONTFAMILY_UNKNOWN: break;
|
||||||
|
}
|
||||||
|
|
||||||
// SetXFontComponent(wxXLFD_FOUNDRY, ...);
|
wxCHECK_RET( !xfamily.empty(), "Unknown wxFontFamily" );
|
||||||
|
|
||||||
|
SetXFontComponent(wxXLFD_FAMILY, xfamily);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding)
|
void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding)
|
||||||
@@ -997,10 +1029,10 @@ bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
|
|||||||
// X-specific functions
|
// X-specific functions
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxNativeFont wxLoadQueryNearestFont(int pointSize,
|
wxNativeFont wxLoadQueryNearestFont(float pointSize,
|
||||||
wxFontFamily family,
|
wxFontFamily family,
|
||||||
wxFontStyle style,
|
wxFontStyle style,
|
||||||
wxFontWeight weight,
|
int weight,
|
||||||
bool underlined,
|
bool underlined,
|
||||||
const wxString &facename,
|
const wxString &facename,
|
||||||
wxFontEncoding encoding,
|
wxFontEncoding encoding,
|
||||||
@@ -1077,7 +1109,7 @@ wxNativeFont wxLoadQueryNearestFont(int pointSize,
|
|||||||
|
|
||||||
// first round: search for equal, then for smaller and for larger size
|
// first round: search for equal, then for smaller and for larger size
|
||||||
// with the given weight and style
|
// with the given weight and style
|
||||||
wxFontWeight testweight = weight;
|
int testweight = weight;
|
||||||
wxFontStyle teststyle = style;
|
wxFontStyle teststyle = style;
|
||||||
|
|
||||||
for ( round = 0; round < 3; round++ )
|
for ( round = 0; round < 3; round++ )
|
||||||
@@ -1220,26 +1252,16 @@ static bool wxTestFontSpec(const wxString& fontspec)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static wxNativeFont wxLoadQueryFont(int pointSize,
|
static wxNativeFont wxLoadQueryFont(float pointSize,
|
||||||
wxFontFamily family,
|
wxFontFamily family,
|
||||||
wxFontStyle style,
|
wxFontStyle style,
|
||||||
wxFontWeight weight,
|
int weight,
|
||||||
bool WXUNUSED(underlined),
|
bool WXUNUSED(underlined),
|
||||||
const wxString& facename,
|
const wxString& facename,
|
||||||
const wxString& xregistry,
|
const wxString& xregistry,
|
||||||
const wxString& xencoding,
|
const wxString& xencoding,
|
||||||
wxString* xFontName)
|
wxString* xFontName)
|
||||||
{
|
{
|
||||||
wxString xfamily("*");
|
|
||||||
switch (family)
|
|
||||||
{
|
|
||||||
case wxFONTFAMILY_DECORATIVE: xfamily = wxT("lucida"); break;
|
|
||||||
case wxFONTFAMILY_ROMAN: xfamily = wxT("times"); break;
|
|
||||||
case wxFONTFAMILY_MODERN: xfamily = wxT("courier"); break;
|
|
||||||
case wxFONTFAMILY_SWISS: xfamily = wxT("helvetica"); break;
|
|
||||||
case wxFONTFAMILY_TELETYPE: xfamily = wxT("lucidatypewriter"); break;
|
|
||||||
case wxFONTFAMILY_SCRIPT: xfamily = wxT("utopia"); break;
|
|
||||||
}
|
|
||||||
#if wxUSE_NANOX
|
#if wxUSE_NANOX
|
||||||
int xweight;
|
int xweight;
|
||||||
switch (weight)
|
switch (weight)
|
||||||
@@ -1311,176 +1333,43 @@ static wxNativeFont wxLoadQueryFont(int pointSize,
|
|||||||
return (wxNativeFont) fontInfo;
|
return (wxNativeFont) fontInfo;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
wxString fontSpec;
|
wxNativeFontInfo info;
|
||||||
if (!facename.empty())
|
info.SetFractionalPointSize(pointSize);
|
||||||
{
|
|
||||||
fontSpec.Printf(wxT("-*-%s-*-*-normal-*-*-*-*-*-*-*-*-*"),
|
|
||||||
facename.c_str());
|
|
||||||
|
|
||||||
if ( wxTestFontSpec(fontSpec) )
|
if ( !facename.empty() )
|
||||||
{
|
{
|
||||||
xfamily = facename;
|
info.SetFaceName(facename);
|
||||||
|
if ( !wxTestFontSpec(info.GetXFontName()) )
|
||||||
|
{
|
||||||
|
// No such face name, use just the family (we assume this will
|
||||||
|
// never fail).
|
||||||
|
info.SetFamily(family);
|
||||||
}
|
}
|
||||||
//else: no such family, use default one instead
|
|
||||||
}
|
|
||||||
|
|
||||||
wxString xstyle;
|
|
||||||
switch (style)
|
|
||||||
{
|
|
||||||
case wxFONTSTYLE_SLANT:
|
|
||||||
fontSpec.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
|
|
||||||
xfamily.c_str());
|
|
||||||
if ( wxTestFontSpec(fontSpec) )
|
|
||||||
{
|
|
||||||
xstyle = wxT("o");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// fall through - try wxFONTSTYLE_ITALIC now
|
|
||||||
|
|
||||||
case wxFONTSTYLE_ITALIC:
|
|
||||||
fontSpec.Printf(wxT("-*-%s-*-i-*-*-*-*-*-*-*-*-*-*"),
|
|
||||||
xfamily.c_str());
|
|
||||||
if ( wxTestFontSpec(fontSpec) )
|
|
||||||
{
|
|
||||||
xstyle = wxT("i");
|
|
||||||
}
|
|
||||||
else if ( style == wxFONTSTYLE_ITALIC ) // and not wxFONTSTYLE_SLANT
|
|
||||||
{
|
|
||||||
// try wxFONTSTYLE_SLANT
|
|
||||||
fontSpec.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
|
|
||||||
xfamily.c_str());
|
|
||||||
if ( wxTestFontSpec(fontSpec) )
|
|
||||||
{
|
|
||||||
xstyle = wxT("o");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// no italic, no slant - leave default
|
info.SetFamily(family);
|
||||||
xstyle = wxT("*");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
wxFAIL_MSG(wxT("unknown font style"));
|
|
||||||
// fall back to normal
|
|
||||||
|
|
||||||
case wxFONTSTYLE_NORMAL:
|
|
||||||
xstyle = wxT("r");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString xweight;
|
wxNativeFontInfo infoWithStyle(info);
|
||||||
switch (weight)
|
infoWithStyle.SetStyle(style);
|
||||||
{
|
if ( wxTestFontSpec(infoWithStyle.GetXFontName()) )
|
||||||
case wxFONTWEIGHT_BOLD:
|
info = infoWithStyle;
|
||||||
{
|
|
||||||
fontSpec.Printf(wxT("-*-%s-bold-*-*-*-*-*-*-*-*-*-*-*"),
|
|
||||||
xfamily.c_str());
|
|
||||||
if ( wxTestFontSpec(fontSpec) )
|
|
||||||
{
|
|
||||||
xweight = wxT("bold");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
fontSpec.Printf(wxT("-*-%s-heavy-*-*-*-*-*-*-*-*-*-*-*"),
|
|
||||||
xfamily.c_str());
|
|
||||||
if ( wxTestFontSpec(fontSpec) )
|
|
||||||
{
|
|
||||||
xweight = wxT("heavy");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
fontSpec.Printf(wxT("-*-%s-extrabold-*-*-*-*-*-*-*-*-*-*-*"),
|
|
||||||
xfamily.c_str());
|
|
||||||
if ( wxTestFontSpec(fontSpec) )
|
|
||||||
{
|
|
||||||
xweight = wxT("extrabold");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
fontSpec.Printf(wxT("-*-%s-demibold-*-*-*-*-*-*-*-*-*-*-*"),
|
|
||||||
xfamily.c_str());
|
|
||||||
if ( wxTestFontSpec(fontSpec) )
|
|
||||||
{
|
|
||||||
xweight = wxT("demibold");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
fontSpec.Printf(wxT("-*-%s-black-*-*-*-*-*-*-*-*-*-*-*"),
|
|
||||||
xfamily.c_str());
|
|
||||||
if ( wxTestFontSpec(fontSpec) )
|
|
||||||
{
|
|
||||||
xweight = wxT("black");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
fontSpec.Printf(wxT("-*-%s-ultrablack-*-*-*-*-*-*-*-*-*-*-*"),
|
|
||||||
xfamily.c_str());
|
|
||||||
if ( wxTestFontSpec(fontSpec) )
|
|
||||||
{
|
|
||||||
xweight = wxT("ultrablack");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case wxFONTWEIGHT_LIGHT:
|
|
||||||
{
|
|
||||||
fontSpec.Printf(wxT("-*-%s-light-*-*-*-*-*-*-*-*-*-*-*"),
|
|
||||||
xfamily.c_str());
|
|
||||||
if ( wxTestFontSpec(fontSpec) )
|
|
||||||
{
|
|
||||||
xweight = wxT("light");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
fontSpec.Printf(wxT("-*-%s-thin-*-*-*-*-*-*-*-*-*-*-*"),
|
|
||||||
xfamily.c_str());
|
|
||||||
if ( wxTestFontSpec(fontSpec) )
|
|
||||||
{
|
|
||||||
xweight = wxT("thin");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case wxFONTWEIGHT_NORMAL:
|
|
||||||
{
|
|
||||||
fontSpec.Printf(wxT("-*-%s-medium-*-*-*-*-*-*-*-*-*-*-*"),
|
|
||||||
xfamily.c_str());
|
|
||||||
if ( wxTestFontSpec(fontSpec) )
|
|
||||||
{
|
|
||||||
xweight = wxT("medium");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
fontSpec.Printf(wxT("-*-%s-normal-*-*-*-*-*-*-*-*-*-*-*"),
|
|
||||||
xfamily.c_str());
|
|
||||||
if ( wxTestFontSpec(fontSpec) )
|
|
||||||
{
|
|
||||||
xweight = wxT("normal");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
fontSpec.Printf(wxT("-*-%s-regular-*-*-*-*-*-*-*-*-*-*-*"),
|
|
||||||
xfamily.c_str());
|
|
||||||
if ( wxTestFontSpec(fontSpec) )
|
|
||||||
{
|
|
||||||
xweight = wxT("regular");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
xweight = wxT("*");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default: xweight = wxT("*"); break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if pointSize is -1, don't specify any
|
wxNativeFontInfo infoWithWeight(info);
|
||||||
wxString sizeSpec;
|
infoWithWeight.SetNumericWeight(weight);
|
||||||
if ( pointSize == -1 )
|
if ( wxTestFontSpec(infoWithWeight.GetXFontName()) )
|
||||||
{
|
info = infoWithWeight;
|
||||||
sizeSpec = wxT('*');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sizeSpec.Printf(wxT("%d"), pointSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
// construct the X font spec from our data
|
// construct the X font spec from our data
|
||||||
fontSpec.Printf(wxT("-*-%s-%s-%s-normal-*-*-%s-*-*-*-*-%s-%s"),
|
wxString fontSpec;
|
||||||
xfamily.c_str(), xweight.c_str(), xstyle.c_str(),
|
fontSpec.Printf("-*-%s-%s-%s-normal-*-*-%s-*-*-*-*-%s-%s",
|
||||||
sizeSpec.c_str(), xregistry.c_str(), xencoding.c_str());
|
info.GetXFontComponent(wxXLFD_FAMILY),
|
||||||
|
info.GetXFontComponent(wxXLFD_WEIGHT),
|
||||||
|
info.GetXFontComponent(wxXLFD_SLANT),
|
||||||
|
info.GetXFontComponent(wxXLFD_POINTSIZE),
|
||||||
|
xregistry,
|
||||||
|
xencoding);
|
||||||
|
|
||||||
if( xFontName )
|
if( xFontName )
|
||||||
*xFontName = fontSpec;
|
*xFontName = fontSpec;
|
||||||
|
112
src/x11/font.cpp
112
src/x11/font.cpp
@@ -52,6 +52,28 @@
|
|||||||
static const int wxDEFAULT_FONT_SIZE = 12;
|
static const int wxDEFAULT_FONT_SIZE = 12;
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// helper functions
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static wxFontWeight ParseWeightString(wxString s)
|
||||||
|
{
|
||||||
|
s.MakeUpper();
|
||||||
|
|
||||||
|
if (s == "THIN") return wxFONTWEIGHT_THIN;
|
||||||
|
if (s == "EXTRALIGHT" || s == "ULTRALIGHT") return wxFONTWEIGHT_EXTRALIGHT;
|
||||||
|
if (s == "LIGHT") return wxFONTWEIGHT_LIGHT;
|
||||||
|
if (s == "NORMAL") return wxFONTWEIGHT_NORMAL;
|
||||||
|
if (s == "MEDIUM") return wxFONTWEIGHT_MEDIUM;
|
||||||
|
if (s == "DEMIBOLD" || s == "SEMIBOLD") return wxFONTWEIGHT_SEMIBOLD;
|
||||||
|
if (s == "BOLD") return wxFONTWEIGHT_BOLD;
|
||||||
|
if (s == "EXTRABOLD" || s == "ULTRABOLD") return wxFONTWEIGHT_EXTRABOLD;
|
||||||
|
if (s == "BLACK" || s == "HEAVY") return wxFONTWEIGHT_HEAVY;
|
||||||
|
if (s == "EXTRAHEAVY") return wxFONTWEIGHT_EXTRAHEAVY;
|
||||||
|
|
||||||
|
return wxFONTWEIGHT_NORMAL;
|
||||||
|
}
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
#else
|
#else
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -116,10 +138,10 @@ public:
|
|||||||
|
|
||||||
// setters: all of them also take care to modify m_nativeFontInfo if we
|
// setters: all of them also take care to modify m_nativeFontInfo if we
|
||||||
// have it so as to not lose the information not carried by our fields
|
// have it so as to not lose the information not carried by our fields
|
||||||
void SetPointSize(int pointSize);
|
void SetFractionalPointSize(float pointSize);
|
||||||
void SetFamily(wxFontFamily family);
|
void SetFamily(wxFontFamily family);
|
||||||
void SetStyle(wxFontStyle style);
|
void SetStyle(wxFontStyle style);
|
||||||
void SetWeight(wxFontWeight weight);
|
void SetNumericWeight(int weight);
|
||||||
void SetUnderlined(bool underlined);
|
void SetUnderlined(bool underlined);
|
||||||
void SetStrikethrough(bool strikethrough);
|
void SetStrikethrough(bool strikethrough);
|
||||||
bool SetFaceName(const wxString& facename);
|
bool SetFaceName(const wxString& facename);
|
||||||
@@ -143,10 +165,10 @@ protected:
|
|||||||
void InitFromNative();
|
void InitFromNative();
|
||||||
|
|
||||||
// font attributes
|
// font attributes
|
||||||
int m_pointSize;
|
float m_pointSize;
|
||||||
wxFontFamily m_family;
|
wxFontFamily m_family;
|
||||||
wxFontStyle m_style;
|
wxFontStyle m_style;
|
||||||
wxFontWeight m_weight;
|
int m_weight;
|
||||||
bool m_underlined;
|
bool m_underlined;
|
||||||
bool m_strikethrough;
|
bool m_strikethrough;
|
||||||
wxString m_faceName;
|
wxString m_faceName;
|
||||||
@@ -223,12 +245,12 @@ void wxFontRefData::Init(int pointSize,
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_nativeFontInfo.SetFaceName(m_faceName);
|
m_nativeFontInfo.SetFaceName(m_faceName);
|
||||||
m_nativeFontInfo.SetWeight((wxFontWeight)m_weight);
|
m_nativeFontInfo.SetNumericWeight(m_weight);
|
||||||
m_nativeFontInfo.SetStyle((wxFontStyle)m_style);
|
m_nativeFontInfo.SetStyle((wxFontStyle)m_style);
|
||||||
m_nativeFontInfo.SetUnderlined(underlined);
|
m_nativeFontInfo.SetUnderlined(underlined);
|
||||||
#endif // wxUSE_UNICODE
|
#endif // wxUSE_UNICODE
|
||||||
|
|
||||||
SetPointSize(pointSize);
|
SetFractionalPointSize(static_cast<float>(pointSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFontRefData::InitFromNative()
|
void wxFontRefData::InitFromNative()
|
||||||
@@ -240,7 +262,7 @@ void wxFontRefData::InitFromNative()
|
|||||||
// init fields
|
// init fields
|
||||||
m_faceName = wxGTK_CONV_BACK( pango_font_description_get_family( desc ) );
|
m_faceName = wxGTK_CONV_BACK( pango_font_description_get_family( desc ) );
|
||||||
|
|
||||||
m_pointSize = pango_font_description_get_size( desc ) / PANGO_SCALE;
|
m_pointSize = static_cast<float>(pango_font_description_get_size( desc )) / PANGO_SCALE;
|
||||||
|
|
||||||
switch (pango_font_description_get_style( desc ))
|
switch (pango_font_description_get_style( desc ))
|
||||||
{
|
{
|
||||||
@@ -255,56 +277,18 @@ void wxFontRefData::InitFromNative()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not defined in some Pango versions
|
m_weight = pango_font_description_get_weight( desc );
|
||||||
#define wxPANGO_WEIGHT_SEMIBOLD 600
|
|
||||||
|
|
||||||
switch (pango_font_description_get_weight( desc ))
|
|
||||||
{
|
|
||||||
case PANGO_WEIGHT_ULTRALIGHT:
|
|
||||||
case PANGO_WEIGHT_LIGHT:
|
|
||||||
m_weight = wxFONTWEIGHT_LIGHT;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
wxFAIL_MSG(wxT("unknown Pango font weight"));
|
|
||||||
// fall through
|
|
||||||
|
|
||||||
case PANGO_WEIGHT_NORMAL:
|
|
||||||
m_weight = wxFONTWEIGHT_NORMAL;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case wxPANGO_WEIGHT_SEMIBOLD:
|
|
||||||
case PANGO_WEIGHT_BOLD:
|
|
||||||
case PANGO_WEIGHT_ULTRABOLD:
|
|
||||||
case PANGO_WEIGHT_HEAVY:
|
|
||||||
m_weight = wxFONTWEIGHT_BOLD;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else // X11
|
#else // X11
|
||||||
// get the font parameters from the XLFD
|
// get the font parameters from the XLFD
|
||||||
// -------------------------------------
|
// -------------------------------------
|
||||||
|
|
||||||
m_faceName = m_nativeFontInfo.GetXFontComponent(wxXLFD_FAMILY);
|
m_faceName = m_nativeFontInfo.GetXFontComponent(wxXLFD_FAMILY);
|
||||||
|
|
||||||
m_weight = wxFONTWEIGHT_NORMAL;
|
|
||||||
|
|
||||||
wxString w = m_nativeFontInfo.GetXFontComponent(wxXLFD_WEIGHT).Upper();
|
wxString w = m_nativeFontInfo.GetXFontComponent(wxXLFD_WEIGHT).Upper();
|
||||||
if ( !w.empty() && w != wxT('*') )
|
if ( !w.empty() && w != wxT('*') )
|
||||||
{
|
m_weight = ParseWeightString(w);
|
||||||
// the test below catches all of BOLD, EXTRABOLD, DEMIBOLD, ULTRABOLD
|
else
|
||||||
// and BLACK
|
m_weight = wxFONTWEIGHT_NORMAL;
|
||||||
if ( ((w[0u] == wxT('B') && (!wxStrcmp(w.c_str() + 1, wxT("OLD")) ||
|
|
||||||
!wxStrcmp(w.c_str() + 1, wxT("LACK"))))) ||
|
|
||||||
wxStrstr(w.c_str() + 1, wxT("BOLD")) )
|
|
||||||
{
|
|
||||||
m_weight = wxFONTWEIGHT_BOLD;
|
|
||||||
}
|
|
||||||
else if ( w == wxT("LIGHT") || w == wxT("THIN") )
|
|
||||||
{
|
|
||||||
m_weight = wxFONTWEIGHT_LIGHT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ( wxToupper( m_nativeFontInfo.
|
switch ( wxToupper( m_nativeFontInfo.
|
||||||
GetXFontComponent(wxXLFD_SLANT)[0u]).GetValue() )
|
GetXFontComponent(wxXLFD_SLANT)[0u]).GetValue() )
|
||||||
@@ -442,14 +426,14 @@ wxFontRefData::~wxFontRefData()
|
|||||||
// wxFontRefData SetXXX()
|
// wxFontRefData SetXXX()
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxFontRefData::SetPointSize(int pointSize)
|
void wxFontRefData::SetFractionalPointSize(float pointSize)
|
||||||
{
|
{
|
||||||
// NB: Pango doesn't support point sizes less than 1
|
// NB: Pango doesn't support point sizes less than 1
|
||||||
m_pointSize = pointSize == wxDEFAULT || pointSize < 1 ? wxDEFAULT_FONT_SIZE
|
m_pointSize = pointSize == wxDEFAULT || pointSize < 1 ? wxDEFAULT_FONT_SIZE
|
||||||
: pointSize;
|
: pointSize;
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
m_nativeFontInfo.SetPointSize(m_pointSize);
|
m_nativeFontInfo.SetFractionalPointSize(m_pointSize);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -486,7 +470,7 @@ void wxFontRefData::SetStyle(wxFontStyle style)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFontRefData::SetWeight(wxFontWeight weight)
|
void wxFontRefData::SetNumericWeight(int weight)
|
||||||
{
|
{
|
||||||
m_weight = weight;
|
m_weight = weight;
|
||||||
}
|
}
|
||||||
@@ -594,15 +578,7 @@ bool wxFont::Create(const wxString& fontname, wxFontEncoding enc)
|
|||||||
|
|
||||||
M_FONTDATA->m_faceName = tn.GetNextToken(); // family
|
M_FONTDATA->m_faceName = tn.GetNextToken(); // family
|
||||||
|
|
||||||
tmp = tn.GetNextToken().MakeUpper(); // weight
|
M_FONTDATA->m_weight = ParseWeightString(tn.GetNextToken()); // weight
|
||||||
if (tmp == wxT("BOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
|
|
||||||
if (tmp == wxT("BLACK")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
|
|
||||||
if (tmp == wxT("EXTRABOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
|
|
||||||
if (tmp == wxT("DEMIBOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
|
|
||||||
if (tmp == wxT("ULTRABOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
|
|
||||||
|
|
||||||
if (tmp == wxT("LIGHT")) M_FONTDATA->m_weight = wxFONTWEIGHT_LIGHT;
|
|
||||||
if (tmp == wxT("THIN")) M_FONTDATA->m_weight = wxFONTWEIGHT_LIGHT;
|
|
||||||
|
|
||||||
tmp = tn.GetNextToken().MakeUpper(); // slant
|
tmp = tn.GetNextToken().MakeUpper(); // slant
|
||||||
if (tmp == wxT("I")) M_FONTDATA->m_style = wxFONTSTYLE_ITALIC;
|
if (tmp == wxT("I")) M_FONTDATA->m_style = wxFONTSTYLE_ITALIC;
|
||||||
@@ -716,11 +692,11 @@ void wxFont::Unshare()
|
|||||||
// accessors
|
// accessors
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
int wxFont::GetPointSize() const
|
float wxFont::GetFractionalPointSize() const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
|
wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
|
||||||
|
|
||||||
return M_FONTDATA->m_nativeFontInfo.GetPointSize();
|
return M_FONTDATA->m_nativeFontInfo.GetFractionalPointSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxFont::GetFaceName() const
|
wxString wxFont::GetFaceName() const
|
||||||
@@ -742,7 +718,7 @@ wxFontStyle wxFont::GetStyle() const
|
|||||||
return M_FONTDATA->m_style;
|
return M_FONTDATA->m_style;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontWeight wxFont::GetWeight() const
|
int wxFont::GetNumericWeight() const
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font") );
|
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font") );
|
||||||
|
|
||||||
@@ -823,11 +799,11 @@ bool wxFont::IsFixedWidth() const
|
|||||||
// change font attributes
|
// change font attributes
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxFont::SetPointSize(int pointSize)
|
void wxFont::SetFractionalPointSize(float pointSize)
|
||||||
{
|
{
|
||||||
Unshare();
|
Unshare();
|
||||||
|
|
||||||
M_FONTDATA->SetPointSize(pointSize);
|
M_FONTDATA->SetFractionalPointSize(pointSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetFamily(wxFontFamily family)
|
void wxFont::SetFamily(wxFontFamily family)
|
||||||
@@ -844,11 +820,11 @@ void wxFont::SetStyle(wxFontStyle style)
|
|||||||
M_FONTDATA->SetStyle(style);
|
M_FONTDATA->SetStyle(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetWeight(wxFontWeight weight)
|
void wxFont::SetNumericWeight(int weight)
|
||||||
{
|
{
|
||||||
Unshare();
|
Unshare();
|
||||||
|
|
||||||
M_FONTDATA->SetWeight(weight);
|
M_FONTDATA->SetNumericWeight(weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxFont::SetFaceName(const wxString& faceName)
|
bool wxFont::SetFaceName(const wxString& faceName)
|
||||||
|
@@ -2275,10 +2275,10 @@ wxFont wxXmlResourceHandlerImpl::GetFont(const wxString& param, wxWindow* parent
|
|||||||
// font attributes:
|
// font attributes:
|
||||||
|
|
||||||
// size
|
// size
|
||||||
int isize = -1;
|
float pointSize = -1.0f;
|
||||||
bool hasSize = HasParam(wxT("size"));
|
bool hasSize = HasParam(wxT("size"));
|
||||||
if (hasSize)
|
if (hasSize)
|
||||||
isize = GetLong(wxT("size"), -1);
|
pointSize = GetFloat(wxT("size"), -1.0f);
|
||||||
|
|
||||||
// style
|
// style
|
||||||
wxFontStyle istyle = wxFONTSTYLE_NORMAL;
|
wxFontStyle istyle = wxFONTSTYLE_NORMAL;
|
||||||
@@ -2301,12 +2301,23 @@ wxFont wxXmlResourceHandlerImpl::GetFont(const wxString& param, wxWindow* parent
|
|||||||
}
|
}
|
||||||
|
|
||||||
// weight
|
// weight
|
||||||
wxFontWeight iweight = wxFONTWEIGHT_NORMAL;
|
long iweight = wxFONTWEIGHT_NORMAL;
|
||||||
bool hasWeight = HasParam(wxT("weight"));
|
bool hasWeight = HasParam(wxT("weight"));
|
||||||
if (hasWeight)
|
if (hasWeight)
|
||||||
{
|
{
|
||||||
wxString weight = GetParamValue(wxT("weight"));
|
wxString weight = GetParamValue(wxT("weight"));
|
||||||
if (weight == wxT("thin"))
|
if (weight.ToLong(&iweight))
|
||||||
|
{
|
||||||
|
if (iweight <= wxFONTWEIGHT_INVALID || iweight > wxFONTWEIGHT_MAX)
|
||||||
|
{
|
||||||
|
ReportParamError
|
||||||
|
(
|
||||||
|
param,
|
||||||
|
wxString::Format("invalid font weight value \"%d\"", iweight)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (weight == wxT("thin"))
|
||||||
iweight = wxFONTWEIGHT_THIN;
|
iweight = wxFONTWEIGHT_THIN;
|
||||||
else if (weight == wxT("extralight"))
|
else if (weight == wxT("extralight"))
|
||||||
iweight = wxFONTWEIGHT_EXTRALIGHT;
|
iweight = wxFONTWEIGHT_EXTRALIGHT;
|
||||||
@@ -2338,6 +2349,10 @@ wxFont wxXmlResourceHandlerImpl::GetFont(const wxString& param, wxWindow* parent
|
|||||||
bool hasUnderlined = HasParam(wxT("underlined"));
|
bool hasUnderlined = HasParam(wxT("underlined"));
|
||||||
bool underlined = hasUnderlined ? GetBool(wxT("underlined"), false) : false;
|
bool underlined = hasUnderlined ? GetBool(wxT("underlined"), false) : false;
|
||||||
|
|
||||||
|
// strikethrough
|
||||||
|
bool hasStrikethrough = HasParam(wxT("strikethrough"));
|
||||||
|
bool strikethrough = hasStrikethrough ? GetBool(wxT("strikethrough"), false) : false;
|
||||||
|
|
||||||
// family and facename
|
// family and facename
|
||||||
wxFontFamily ifamily = wxFONTFAMILY_DEFAULT;
|
wxFontFamily ifamily = wxFONTFAMILY_DEFAULT;
|
||||||
bool hasFamily = HasParam(wxT("family"));
|
bool hasFamily = HasParam(wxT("family"));
|
||||||
@@ -2433,9 +2448,9 @@ wxFont wxXmlResourceHandlerImpl::GetFont(const wxString& param, wxWindow* parent
|
|||||||
|
|
||||||
if (font.IsOk())
|
if (font.IsOk())
|
||||||
{
|
{
|
||||||
if (hasSize && isize != -1)
|
if (pointSize > 0)
|
||||||
{
|
{
|
||||||
font.SetPointSize(isize);
|
font.SetFractionalPointSize(pointSize);
|
||||||
if (HasParam(wxT("relativesize")))
|
if (HasParam(wxT("relativesize")))
|
||||||
{
|
{
|
||||||
ReportParamError
|
ReportParamError
|
||||||
@@ -2452,9 +2467,11 @@ wxFont wxXmlResourceHandlerImpl::GetFont(const wxString& param, wxWindow* parent
|
|||||||
if (hasStyle)
|
if (hasStyle)
|
||||||
font.SetStyle(istyle);
|
font.SetStyle(istyle);
|
||||||
if (hasWeight)
|
if (hasWeight)
|
||||||
font.SetWeight(iweight);
|
font.SetNumericWeight(iweight);
|
||||||
if (hasUnderlined)
|
if (hasUnderlined)
|
||||||
font.SetUnderlined(underlined);
|
font.SetUnderlined(underlined);
|
||||||
|
if (hasStrikethrough)
|
||||||
|
font.SetStrikethrough(strikethrough);
|
||||||
if (hasFamily)
|
if (hasFamily)
|
||||||
font.SetFamily(ifamily);
|
font.SetFamily(ifamily);
|
||||||
if (hasFacename)
|
if (hasFacename)
|
||||||
@@ -2464,9 +2481,15 @@ wxFont wxXmlResourceHandlerImpl::GetFont(const wxString& param, wxWindow* parent
|
|||||||
}
|
}
|
||||||
else // not based on system font
|
else // not based on system font
|
||||||
{
|
{
|
||||||
font = wxFont(isize == -1 ? wxNORMAL_FONT->GetPointSize() : isize,
|
font = wxFontInfo(pointSize)
|
||||||
ifamily, istyle, iweight,
|
.FaceName(facename)
|
||||||
underlined, facename, enc);
|
.Family(ifamily)
|
||||||
|
.Style(istyle)
|
||||||
|
.Weight(iweight)
|
||||||
|
.Underlined(underlined)
|
||||||
|
.Strikethrough(strikethrough)
|
||||||
|
.Encoding(enc)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_handler->m_node = oldnode;
|
m_handler->m_node = oldnode;
|
||||||
|
@@ -21,36 +21,18 @@
|
|||||||
#include "wx/wx.h"
|
#include "wx/wx.h"
|
||||||
#endif // WX_PRECOMP
|
#endif // WX_PRECOMP
|
||||||
|
|
||||||
#if wxUSE_FONTMAP
|
|
||||||
|
|
||||||
#include "wx/font.h"
|
#include "wx/font.h"
|
||||||
|
|
||||||
#include "asserthelper.h"
|
#include "asserthelper.h"
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// test class
|
// local helpers
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class FontTestCase : public CppUnit::TestCase
|
// Returns a point to an array of fonts and fills the output parameter with the
|
||||||
|
// number of elements in this array.
|
||||||
|
static const wxFont *GetTestFonts(unsigned& numFonts)
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
FontTestCase() { }
|
|
||||||
|
|
||||||
private:
|
|
||||||
CPPUNIT_TEST_SUITE( FontTestCase );
|
|
||||||
CPPUNIT_TEST( Construct );
|
|
||||||
CPPUNIT_TEST( GetSet );
|
|
||||||
CPPUNIT_TEST( NativeFontInfo );
|
|
||||||
CPPUNIT_TEST( NativeFontInfoUserDesc );
|
|
||||||
CPPUNIT_TEST_SUITE_END();
|
|
||||||
|
|
||||||
void Construct();
|
|
||||||
void GetSet();
|
|
||||||
void NativeFontInfo();
|
|
||||||
void NativeFontInfoUserDesc();
|
|
||||||
|
|
||||||
static const wxFont *GetTestFonts(unsigned& numFonts)
|
|
||||||
{
|
|
||||||
static const wxFont testfonts[] =
|
static const wxFont testfonts[] =
|
||||||
{
|
{
|
||||||
*wxNORMAL_FONT,
|
*wxNORMAL_FONT,
|
||||||
@@ -63,16 +45,7 @@ private:
|
|||||||
numFonts = WXSIZEOF(testfonts);
|
numFonts = WXSIZEOF(testfonts);
|
||||||
|
|
||||||
return testfonts;
|
return testfonts;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDECLARE_NO_COPY_CLASS(FontTestCase);
|
|
||||||
};
|
|
||||||
|
|
||||||
// register in the unnamed registry so that these tests are run by default
|
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( FontTestCase );
|
|
||||||
|
|
||||||
// also include in its own registry so that these tests can be run alone
|
|
||||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FontTestCase, "FontTestCase" );
|
|
||||||
|
|
||||||
wxString DumpFont(const wxFont *font)
|
wxString DumpFont(const wxFont *font)
|
||||||
{
|
{
|
||||||
@@ -96,13 +69,17 @@ wxString DumpFont(const wxFont *font)
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FontTestCase::Construct()
|
// ----------------------------------------------------------------------------
|
||||||
|
// the tests
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
TEST_CASE("wxFont::Construct", "[font][ctor]")
|
||||||
{
|
{
|
||||||
// The main purpose of this test is to verify that the font ctors below
|
// The main purpose of this test is to verify that the font ctors below
|
||||||
// compile because it's easy to introduce ambiguities due to the number of
|
// compile because it's easy to introduce ambiguities due to the number of
|
||||||
// overloaded wxFont ctors.
|
// overloaded wxFont ctors.
|
||||||
|
|
||||||
CPPUNIT_ASSERT( wxFont(10, wxFONTFAMILY_DEFAULT,
|
CHECK( wxFont(10, wxFONTFAMILY_DEFAULT,
|
||||||
wxFONTSTYLE_NORMAL,
|
wxFONTSTYLE_NORMAL,
|
||||||
wxFONTWEIGHT_NORMAL).IsOk() );
|
wxFONTWEIGHT_NORMAL).IsOk() );
|
||||||
|
|
||||||
@@ -118,7 +95,7 @@ void FontTestCase::Construct()
|
|||||||
|
|
||||||
// Tests relying on the soon-to-be-deprecated ctor taking ints and not
|
// Tests relying on the soon-to-be-deprecated ctor taking ints and not
|
||||||
// wxFontXXX enum elements.
|
// wxFontXXX enum elements.
|
||||||
CPPUNIT_ASSERT( wxFont(10, wxDEFAULT, wxNORMAL, wxNORMAL).IsOk() );
|
CHECK( wxFont(10, wxDEFAULT, wxNORMAL, wxNORMAL).IsOk() );
|
||||||
|
|
||||||
wxGCC_WARNING_RESTORE(deprecated-declarations)
|
wxGCC_WARNING_RESTORE(deprecated-declarations)
|
||||||
|
|
||||||
@@ -128,7 +105,133 @@ void FontTestCase::Construct()
|
|||||||
#endif // WXWIN_COMPATIBILITY_3_0
|
#endif // WXWIN_COMPATIBILITY_3_0
|
||||||
}
|
}
|
||||||
|
|
||||||
void FontTestCase::GetSet()
|
TEST_CASE("wxFont::Size", "[font][size]")
|
||||||
|
{
|
||||||
|
const struct Sizes
|
||||||
|
{
|
||||||
|
int specified; // Size in points specified in the ctor.
|
||||||
|
int expected; // Expected GetPointSize() return value,
|
||||||
|
// -1 here means "same as wxNORMAL_FONT".
|
||||||
|
} sizes[] =
|
||||||
|
{
|
||||||
|
{ 9, 9 },
|
||||||
|
{ 10, 10 },
|
||||||
|
{ 11, 11 },
|
||||||
|
{ -1, -1 },
|
||||||
|
{ 70, -1 }, // 70 == wxDEFAULT, should be handled specially
|
||||||
|
{ 90, 90 }, // 90 == wxNORMAL, should not be handled specially
|
||||||
|
};
|
||||||
|
|
||||||
|
const int sizeDefault = wxFont(wxFontInfo()).GetPointSize();
|
||||||
|
|
||||||
|
for ( size_t n = 0; n < WXSIZEOF(sizes); n++ )
|
||||||
|
{
|
||||||
|
const Sizes& size = sizes[n];
|
||||||
|
|
||||||
|
// Note: use the old-style wxFont ctor as wxFontInfo doesn't implement
|
||||||
|
// any compatibility hacks.
|
||||||
|
const wxFont font(size.specified,
|
||||||
|
wxFONTFAMILY_DEFAULT,
|
||||||
|
wxFONTSTYLE_NORMAL,
|
||||||
|
wxFONTWEIGHT_NORMAL);
|
||||||
|
|
||||||
|
int expected = size.expected;
|
||||||
|
if ( expected == -1 )
|
||||||
|
expected = sizeDefault;
|
||||||
|
|
||||||
|
INFO("specified = " << size.specified <<
|
||||||
|
", expected = " << size.expected);
|
||||||
|
CHECK( font.GetPointSize() == expected );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note that the compatibility hacks only apply to the old ctors, the newer
|
||||||
|
// one, taking wxFontInfo, doesn't support them.
|
||||||
|
CHECK( wxFont(wxFontInfo(70)).GetPointSize() == 70 );
|
||||||
|
CHECK( wxFont(wxFontInfo(90)).GetPointSize() == 90 );
|
||||||
|
|
||||||
|
// Check fractional point sizes as well.
|
||||||
|
wxFont font(wxFontInfo(12.25));
|
||||||
|
CHECK( font.GetFractionalPointSize() == 12.25 );
|
||||||
|
CHECK( font.GetPointSize() == 12 );
|
||||||
|
|
||||||
|
font = *wxNORMAL_FONT;
|
||||||
|
font.SetFractionalPointSize(9.5);
|
||||||
|
CHECK( font.GetFractionalPointSize() == 9.5 );
|
||||||
|
CHECK( font.GetPointSize() == 10 );
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("wxFont::Style", "[font][style]")
|
||||||
|
{
|
||||||
|
#if WXWIN_COMPATIBILITY_3_0
|
||||||
|
// Disable the warning about deprecated wxNORMAL as we use it here
|
||||||
|
// intentionally.
|
||||||
|
#ifdef __VISUALC__
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable:4996)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
|
||||||
|
|
||||||
|
wxFont fontNormal(10, wxDEFAULT, wxNORMAL, wxNORMAL);
|
||||||
|
CHECK( fontNormal.GetStyle() == wxFONTSTYLE_NORMAL );
|
||||||
|
|
||||||
|
wxFont fontItalic(10, wxDEFAULT, wxITALIC, wxNORMAL);
|
||||||
|
CHECK( fontItalic.GetStyle() == wxFONTSTYLE_ITALIC );
|
||||||
|
|
||||||
|
wxFont fontSlant(10, wxDEFAULT, wxSLANT, wxNORMAL);
|
||||||
|
#ifdef __WXMSW__
|
||||||
|
CHECK( fontSlant.GetStyle() == wxFONTSTYLE_ITALIC );
|
||||||
|
#else
|
||||||
|
CHECK( fontSlant.GetStyle() == wxFONTSTYLE_SLANT );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
wxGCC_WARNING_RESTORE(deprecated-declarations)
|
||||||
|
|
||||||
|
#ifdef __VISUALC__
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
#endif // WXWIN_COMPATIBILITY_3_0
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("wxFont::Weight", "[font][weight]")
|
||||||
|
{
|
||||||
|
wxFont font;
|
||||||
|
font.SetNumericWeight(123);
|
||||||
|
CHECK( font.GetNumericWeight() == 123 );
|
||||||
|
CHECK( font.GetWeight() == wxFONTWEIGHT_THIN );
|
||||||
|
|
||||||
|
font.SetNumericWeight(wxFONTWEIGHT_SEMIBOLD);
|
||||||
|
CHECK( font.GetNumericWeight() == wxFONTWEIGHT_SEMIBOLD );
|
||||||
|
CHECK( font.GetWeight() == wxFONTWEIGHT_SEMIBOLD );
|
||||||
|
|
||||||
|
#if WXWIN_COMPATIBILITY_3_0
|
||||||
|
// Disable the warning about deprecated wxNORMAL as we use it here
|
||||||
|
// intentionally.
|
||||||
|
#ifdef __VISUALC__
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable:4996)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
|
||||||
|
|
||||||
|
wxFont fontNormal(10, wxDEFAULT, wxNORMAL, wxNORMAL);
|
||||||
|
CHECK( fontNormal.GetWeight() == wxFONTWEIGHT_NORMAL );
|
||||||
|
|
||||||
|
wxFont fontBold(10, wxDEFAULT, wxNORMAL, wxBOLD);
|
||||||
|
CHECK( fontBold.GetWeight() == wxFONTWEIGHT_BOLD );
|
||||||
|
|
||||||
|
wxFont fontLight(10, wxDEFAULT, wxNORMAL, wxLIGHT);
|
||||||
|
CHECK( fontLight.GetWeight() == wxFONTWEIGHT_LIGHT );
|
||||||
|
|
||||||
|
wxGCC_WARNING_RESTORE(deprecated-declarations)
|
||||||
|
|
||||||
|
#ifdef __VISUALC__
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
#endif // WXWIN_COMPATIBILITY_3_0
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("wxFont::GetSet", "[font][getters]")
|
||||||
{
|
{
|
||||||
unsigned numFonts;
|
unsigned numFonts;
|
||||||
const wxFont *pf = GetTestFonts(numFonts);
|
const wxFont *pf = GetTestFonts(numFonts);
|
||||||
@@ -137,12 +240,12 @@ void FontTestCase::GetSet()
|
|||||||
wxFont test(*pf++);
|
wxFont test(*pf++);
|
||||||
|
|
||||||
// remember: getters can only be called when wxFont::IsOk() == true
|
// remember: getters can only be called when wxFont::IsOk() == true
|
||||||
CPPUNIT_ASSERT( test.IsOk() );
|
CHECK( test.IsOk() );
|
||||||
|
|
||||||
|
|
||||||
// test Get/SetFaceName()
|
// test Get/SetFaceName()
|
||||||
CPPUNIT_ASSERT( !test.SetFaceName("a dummy face name") );
|
CHECK( !test.SetFaceName("a dummy face name") );
|
||||||
CPPUNIT_ASSERT( !test.IsOk() );
|
CHECK( !test.IsOk() );
|
||||||
|
|
||||||
// if the call to SetFaceName() below fails on your system/port,
|
// if the call to SetFaceName() below fails on your system/port,
|
||||||
// consider adding another branch to this #if
|
// consider adding another branch to this #if
|
||||||
@@ -159,41 +262,41 @@ void FontTestCase::GetSet()
|
|||||||
"available on this system)", knownGoodFaceName, n),
|
"available on this system)", knownGoodFaceName, n),
|
||||||
test.SetFaceName(knownGoodFaceName)
|
test.SetFaceName(knownGoodFaceName)
|
||||||
);
|
);
|
||||||
CPPUNIT_ASSERT( test.IsOk() );
|
CHECK( test.IsOk() );
|
||||||
|
|
||||||
|
|
||||||
// test Get/SetFamily()
|
// test Get/SetFamily()
|
||||||
|
|
||||||
test.SetFamily( wxFONTFAMILY_ROMAN );
|
test.SetFamily( wxFONTFAMILY_ROMAN );
|
||||||
CPPUNIT_ASSERT( test.IsOk() );
|
CHECK( test.IsOk() );
|
||||||
|
|
||||||
// note that there is always the possibility that GetFamily() returns
|
// note that there is always the possibility that GetFamily() returns
|
||||||
// wxFONTFAMILY_DEFAULT (meaning "unknown" in this case) so that we
|
// wxFONTFAMILY_DEFAULT (meaning "unknown" in this case) so that we
|
||||||
// consider it as a valid return value
|
// consider it as a valid return value
|
||||||
const wxFontFamily family = test.GetFamily();
|
const wxFontFamily family = test.GetFamily();
|
||||||
if ( family != wxFONTFAMILY_DEFAULT )
|
if ( family != wxFONTFAMILY_DEFAULT )
|
||||||
CPPUNIT_ASSERT_EQUAL( wxFONTFAMILY_ROMAN, family );
|
CHECK( wxFONTFAMILY_ROMAN == family );
|
||||||
|
|
||||||
|
|
||||||
// test Get/SetEncoding()
|
// test Get/SetEncoding()
|
||||||
|
|
||||||
//test.SetEncoding( wxFONTENCODING_KOI8 );
|
//test.SetEncoding( wxFONTENCODING_KOI8 );
|
||||||
//CPPUNIT_ASSERT( test.IsOk() );
|
//CHECK( test.IsOk() );
|
||||||
//CPPUNIT_ASSERT_EQUAL( wxFONTENCODING_KOI8 , test.GetEncoding() );
|
//CHECK( wxFONTENCODING_KOI8 == test.GetEncoding() );
|
||||||
|
|
||||||
|
|
||||||
// test Get/SetPointSize()
|
// test Get/SetPointSize()
|
||||||
|
|
||||||
test.SetPointSize(30);
|
test.SetPointSize(30);
|
||||||
CPPUNIT_ASSERT( test.IsOk() );
|
CHECK( test.IsOk() );
|
||||||
CPPUNIT_ASSERT_EQUAL( 30, test.GetPointSize() );
|
CHECK( 30 == test.GetPointSize() );
|
||||||
|
|
||||||
|
|
||||||
// test Get/SetPixelSize()
|
// test Get/SetPixelSize()
|
||||||
|
|
||||||
test.SetPixelSize(wxSize(0,30));
|
test.SetPixelSize(wxSize(0,30));
|
||||||
CPPUNIT_ASSERT( test.IsOk() );
|
CHECK( test.IsOk() );
|
||||||
CPPUNIT_ASSERT( test.GetPixelSize().GetHeight() <= 30 );
|
CHECK( test.GetPixelSize().GetHeight() <= 30 );
|
||||||
// NOTE: the match found by SetPixelSize() may be not 100% precise; it
|
// NOTE: the match found by SetPixelSize() may be not 100% precise; it
|
||||||
// only grants that a font smaller than the required height will
|
// only grants that a font smaller than the required height will
|
||||||
// be selected
|
// be selected
|
||||||
@@ -202,43 +305,43 @@ void FontTestCase::GetSet()
|
|||||||
// test Get/SetStyle()
|
// test Get/SetStyle()
|
||||||
|
|
||||||
test.SetStyle(wxFONTSTYLE_SLANT);
|
test.SetStyle(wxFONTSTYLE_SLANT);
|
||||||
CPPUNIT_ASSERT( test.IsOk() );
|
CHECK( test.IsOk() );
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
// on wxMSW wxFONTSTYLE_SLANT==wxFONTSTYLE_ITALIC, so accept the latter
|
// on wxMSW wxFONTSTYLE_SLANT==wxFONTSTYLE_ITALIC, so accept the latter
|
||||||
// as a valid value too.
|
// as a valid value too.
|
||||||
if ( test.GetStyle() != wxFONTSTYLE_ITALIC )
|
if ( test.GetStyle() != wxFONTSTYLE_ITALIC )
|
||||||
#endif
|
#endif
|
||||||
CPPUNIT_ASSERT_EQUAL( wxFONTSTYLE_SLANT, test.GetStyle() );
|
CHECK( wxFONTSTYLE_SLANT == test.GetStyle() );
|
||||||
|
|
||||||
// test Get/SetUnderlined()
|
// test Get/SetUnderlined()
|
||||||
|
|
||||||
test.SetUnderlined(true);
|
test.SetUnderlined(true);
|
||||||
CPPUNIT_ASSERT( test.IsOk() );
|
CHECK( test.IsOk() );
|
||||||
CPPUNIT_ASSERT_EQUAL( true, test.GetUnderlined() );
|
CHECK( test.GetUnderlined() );
|
||||||
|
|
||||||
const wxFont fontBase = test.GetBaseFont();
|
const wxFont fontBase = test.GetBaseFont();
|
||||||
CPPUNIT_ASSERT( fontBase.IsOk() );
|
CHECK( fontBase.IsOk() );
|
||||||
CPPUNIT_ASSERT( !fontBase.GetUnderlined() );
|
CHECK( !fontBase.GetUnderlined() );
|
||||||
CPPUNIT_ASSERT( !fontBase.GetStrikethrough() );
|
CHECK( !fontBase.GetStrikethrough() );
|
||||||
CPPUNIT_ASSERT_EQUAL( wxFONTWEIGHT_NORMAL, fontBase.GetWeight() );
|
CHECK( wxFONTWEIGHT_NORMAL == fontBase.GetWeight() );
|
||||||
CPPUNIT_ASSERT_EQUAL( wxFONTSTYLE_NORMAL, fontBase.GetStyle() );
|
CHECK( wxFONTSTYLE_NORMAL == fontBase.GetStyle() );
|
||||||
|
|
||||||
// test Get/SetStrikethrough()
|
// test Get/SetStrikethrough()
|
||||||
|
|
||||||
test.SetStrikethrough(true);
|
test.SetStrikethrough(true);
|
||||||
CPPUNIT_ASSERT( test.IsOk() );
|
CHECK( test.IsOk() );
|
||||||
CPPUNIT_ASSERT_EQUAL( true, test.GetStrikethrough() );
|
CHECK( test.GetStrikethrough() );
|
||||||
|
|
||||||
|
|
||||||
// test Get/SetWeight()
|
// test Get/SetWeight()
|
||||||
|
|
||||||
test.SetWeight(wxFONTWEIGHT_BOLD);
|
test.SetWeight(wxFONTWEIGHT_BOLD);
|
||||||
CPPUNIT_ASSERT( test.IsOk() );
|
CHECK( test.IsOk() );
|
||||||
CPPUNIT_ASSERT_EQUAL( wxFONTWEIGHT_BOLD, test.GetWeight() );
|
CHECK( wxFONTWEIGHT_BOLD == test.GetWeight() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FontTestCase::NativeFontInfo()
|
TEST_CASE("wxFont::NativeFontInfo", "[font][fontinfo]")
|
||||||
{
|
{
|
||||||
unsigned numFonts;
|
unsigned numFonts;
|
||||||
const wxFont *pf = GetTestFonts(numFonts);
|
const wxFont *pf = GetTestFonts(numFonts);
|
||||||
@@ -247,12 +350,12 @@ void FontTestCase::NativeFontInfo()
|
|||||||
wxFont test(*pf++);
|
wxFont test(*pf++);
|
||||||
|
|
||||||
const wxString& nid = test.GetNativeFontInfoDesc();
|
const wxString& nid = test.GetNativeFontInfoDesc();
|
||||||
CPPUNIT_ASSERT( !nid.empty() );
|
CHECK( !nid.empty() );
|
||||||
// documented to be never empty
|
// documented to be never empty
|
||||||
|
|
||||||
wxFont temp;
|
wxFont temp;
|
||||||
CPPUNIT_ASSERT( temp.SetNativeFontInfo(nid) );
|
CHECK( temp.SetNativeFontInfo(nid) );
|
||||||
CPPUNIT_ASSERT( temp.IsOk() );
|
CHECK( temp.IsOk() );
|
||||||
WX_ASSERT_MESSAGE(
|
WX_ASSERT_MESSAGE(
|
||||||
("Test #%u failed\ndump of test font: \"%s\"\ndump of temp font: \"%s\"", \
|
("Test #%u failed\ndump of test font: \"%s\"\ndump of temp font: \"%s\"", \
|
||||||
n, DumpFont(&test), DumpFont(&temp)),
|
n, DumpFont(&test), DumpFont(&temp)),
|
||||||
@@ -261,14 +364,14 @@ void FontTestCase::NativeFontInfo()
|
|||||||
|
|
||||||
// test that clearly invalid font info strings do not work
|
// test that clearly invalid font info strings do not work
|
||||||
wxFont font;
|
wxFont font;
|
||||||
CPPUNIT_ASSERT( !font.SetNativeFontInfo("") );
|
CHECK( !font.SetNativeFontInfo("") );
|
||||||
|
|
||||||
// pango_font_description_from_string() used by wxFont in wxGTK and wxX11
|
// pango_font_description_from_string() used by wxFont in wxGTK and wxX11
|
||||||
// never returns an error at all so this assertion fails there -- and as it
|
// never returns an error at all so this assertion fails there -- and as it
|
||||||
// doesn't seem to be possible to do anything about it maybe we should
|
// doesn't seem to be possible to do anything about it maybe we should
|
||||||
// change wxMSW and other ports to also accept any strings?
|
// change wxMSW and other ports to also accept any strings?
|
||||||
#if !defined(__WXGTK__) && !defined(__WXX11__)
|
#if !defined(__WXGTK__) && !defined(__WXX11__)
|
||||||
CPPUNIT_ASSERT( !font.SetNativeFontInfo("bloordyblop") );
|
CHECK( !font.SetNativeFontInfo("bloordyblop") );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Pango font description doesn't have 'underlined' and 'strikethrough'
|
// Pango font description doesn't have 'underlined' and 'strikethrough'
|
||||||
@@ -276,23 +379,23 @@ void FontTestCase::NativeFontInfo()
|
|||||||
// are properly preserved by wxNativeFontInfo or its string description.
|
// are properly preserved by wxNativeFontInfo or its string description.
|
||||||
font.SetUnderlined(true);
|
font.SetUnderlined(true);
|
||||||
font.SetStrikethrough(true);
|
font.SetStrikethrough(true);
|
||||||
CPPUNIT_ASSERT_EQUAL(font, wxFont(font));
|
CHECK(font == wxFont(font));
|
||||||
CPPUNIT_ASSERT_EQUAL(font, wxFont(*font.GetNativeFontInfo()));
|
CHECK(font == wxFont(*font.GetNativeFontInfo()));
|
||||||
CPPUNIT_ASSERT_EQUAL(font, wxFont(font.GetNativeFontInfoDesc()));
|
CHECK(font == wxFont(font.GetNativeFontInfoDesc()));
|
||||||
font.SetUnderlined(false);
|
font.SetUnderlined(false);
|
||||||
CPPUNIT_ASSERT_EQUAL(font, wxFont(font));
|
CHECK(font == wxFont(font));
|
||||||
CPPUNIT_ASSERT_EQUAL(font, wxFont(*font.GetNativeFontInfo()));
|
CHECK(font == wxFont(*font.GetNativeFontInfo()));
|
||||||
CPPUNIT_ASSERT_EQUAL(font, wxFont(font.GetNativeFontInfoDesc()));
|
CHECK(font == wxFont(font.GetNativeFontInfoDesc()));
|
||||||
font.SetUnderlined(true);
|
font.SetUnderlined(true);
|
||||||
font.SetStrikethrough(false);
|
font.SetStrikethrough(false);
|
||||||
CPPUNIT_ASSERT_EQUAL(font, wxFont(font));
|
CHECK(font == wxFont(font));
|
||||||
CPPUNIT_ASSERT_EQUAL(font, wxFont(*font.GetNativeFontInfo()));
|
CHECK(font == wxFont(*font.GetNativeFontInfo()));
|
||||||
CPPUNIT_ASSERT_EQUAL(font, wxFont(font.GetNativeFontInfoDesc()));
|
CHECK(font == wxFont(font.GetNativeFontInfoDesc()));
|
||||||
// note: the GetNativeFontInfoUserDesc() doesn't preserve all attributes
|
// note: the GetNativeFontInfoUserDesc() doesn't preserve all attributes
|
||||||
// according to docs, so it is not tested.
|
// according to docs, so it is not tested.
|
||||||
}
|
}
|
||||||
|
|
||||||
void FontTestCase::NativeFontInfoUserDesc()
|
TEST_CASE("wxFont::NativeFontInfoUserDesc", "[font][fontinfo]")
|
||||||
{
|
{
|
||||||
unsigned numFonts;
|
unsigned numFonts;
|
||||||
const wxFont *pf = GetTestFonts(numFonts);
|
const wxFont *pf = GetTestFonts(numFonts);
|
||||||
@@ -301,12 +404,12 @@ void FontTestCase::NativeFontInfoUserDesc()
|
|||||||
wxFont test(*pf++);
|
wxFont test(*pf++);
|
||||||
|
|
||||||
const wxString& niud = test.GetNativeFontInfoUserDesc();
|
const wxString& niud = test.GetNativeFontInfoUserDesc();
|
||||||
CPPUNIT_ASSERT( !niud.empty() );
|
CHECK( !niud.empty() );
|
||||||
// documented to be never empty
|
// documented to be never empty
|
||||||
|
|
||||||
wxFont temp2;
|
wxFont temp2;
|
||||||
CPPUNIT_ASSERT( temp2.SetNativeFontInfoUserDesc(niud) );
|
CHECK( temp2.SetNativeFontInfoUserDesc(niud) );
|
||||||
CPPUNIT_ASSERT( temp2.IsOk() );
|
CHECK( temp2.IsOk() );
|
||||||
|
|
||||||
#ifdef __WXGTK__
|
#ifdef __WXGTK__
|
||||||
// Pango saves/restores all font info in the user-friendly string:
|
// Pango saves/restores all font info in the user-friendly string:
|
||||||
@@ -319,8 +422,8 @@ void FontTestCase::NativeFontInfoUserDesc()
|
|||||||
// are not granted to save/restore all font info.
|
// are not granted to save/restore all font info.
|
||||||
// In fact e.g. the font family is not saved at all; test only those
|
// In fact e.g. the font family is not saved at all; test only those
|
||||||
// info which GetNativeFontInfoUserDesc() does indeed save:
|
// info which GetNativeFontInfoUserDesc() does indeed save:
|
||||||
CPPUNIT_ASSERT_EQUAL( test.GetWeight(), temp2.GetWeight() );
|
CHECK( test.GetWeight() == temp2.GetWeight() );
|
||||||
CPPUNIT_ASSERT_EQUAL( test.GetStyle(), temp2.GetStyle() );
|
CHECK( test.GetStyle() == temp2.GetStyle() );
|
||||||
|
|
||||||
// if the original face name was empty, it means that any face name (in
|
// if the original face name was empty, it means that any face name (in
|
||||||
// this family) can be used for the new font so we shouldn't be
|
// this family) can be used for the new font so we shouldn't be
|
||||||
@@ -328,13 +431,11 @@ void FontTestCase::NativeFontInfoUserDesc()
|
|||||||
const wxString facename = test.GetFaceName();
|
const wxString facename = test.GetFaceName();
|
||||||
if ( !facename.empty() )
|
if ( !facename.empty() )
|
||||||
{
|
{
|
||||||
CPPUNIT_ASSERT_EQUAL( facename.Upper(), temp2.GetFaceName().Upper() );
|
CHECK( facename.Upper() == temp2.GetFaceName().Upper() );
|
||||||
}
|
}
|
||||||
|
|
||||||
CPPUNIT_ASSERT_EQUAL( test.GetPointSize(), temp2.GetPointSize() );
|
CHECK( test.GetPointSize() == temp2.GetPointSize() );
|
||||||
CPPUNIT_ASSERT_EQUAL( test.GetEncoding(), temp2.GetEncoding() );
|
CHECK( test.GetEncoding() == temp2.GetEncoding() );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_FONTMAP
|
|
||||||
|
Reference in New Issue
Block a user