Extending wxFont API & OSX Core Text Implementation (#877)

* Switch to pure Core Text Implementation, Start extended Font API

* mac fixes

* First msw implementation

* Fixing paste error

* fixing typo

* Rearranging lines to former fallthrough order

* Blind fixes for covering new abstract methods

* Blind gtk implementations

* Fixing according to travis ..

* Removing method defined in base

* formatting adaptions

* Extending the schema definition for new weights

* fixing typo, using wxRound, other fixes according to comments

* changes according to suggestions

* fixing init order, before the init of m_info was overridden by Init()

* redo

* redo

* redo

* Cleanup

Removing obsolete code snippets, proper traces for font names

* Moving common code

Only the Get/SetNumericWeight calls should now be implemented in the native part, the ‚old‘ Get/SetWeight are common code and use the numeric counterparts.

* Updating docs

* commit wa missing changes.txt

* Doc fixes

* Full stops added
This commit is contained in:
Stefan Csomor 2018-09-01 19:42:18 +02:00 committed by GitHub
parent d2c77146db
commit 4580cdb9ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 1210 additions and 800 deletions

View File

@ -155,7 +155,7 @@ INCOMPATIBLE CHANGES SINCE 3.1.0:
- The enum value wxTASKBAR_JUMP_LIST_DESTIONATION, which was added in 3.1.0,
contains a typo and has been renamed to wxTASKBAR_JUMP_LIST_DESTINATION.
- wxZipOutputStream will now automatically convert filenames to UTF-8, if the
wxMBConv used when calling the constructor supports UTF-8 encoding.
@ -489,6 +489,8 @@ All (GUI):
- Allow suppressing warnings from wxImage::LoadFile().
- Allow customizing wxRibbon highlight colours (wxBen).
- Enable selecting opacity in generic wxColourPicker.
- Extend the support for font weights to a bigger range.
- Add support for fractional font sizes.
wxGTK:

View File

@ -59,10 +59,18 @@ enum wxFontStyle
// font weights
enum wxFontWeight
{
wxFONTWEIGHT_NORMAL = wxNORMAL,
wxFONTWEIGHT_LIGHT = wxLIGHT,
wxFONTWEIGHT_BOLD = wxBOLD,
wxFONTWEIGHT_MAX
wxFONTWEIGHT_INVALID = 0,
wxFONTWEIGHT_THIN = 100,
wxFONTWEIGHT_EXTRALIGHT = 200,
wxFONTWEIGHT_LIGHT = 300,
wxFONTWEIGHT_NORMAL = 400,
wxFONTWEIGHT_MEDIUM = 500,
wxFONTWEIGHT_SEMIBOLD = 600,
wxFONTWEIGHT_BOLD = 700,
wxFONTWEIGHT_EXTRABOLD = 800,
wxFONTWEIGHT_HEAVY = 900,
wxFONTWEIGHT_EXTRAHEAVY = 1000,
wxFONTWEIGHT_MAX = wxFONTWEIGHT_EXTRAHEAVY
};
// Symbolic font sizes as defined in CSS specification.
@ -338,12 +346,14 @@ public:
bool operator!=(const wxFont& font) const { return !(*this == font); }
// accessors: get the font characteristics
virtual int GetPointSize() const = 0;
virtual int GetPointSize() const;
virtual float GetFractionalPointSize() const = 0;
virtual wxSize GetPixelSize() const;
virtual bool IsUsingSizeInPixels() const;
wxFontFamily GetFamily() const;
virtual wxFontStyle GetStyle() const = 0;
virtual wxFontWeight GetWeight() const = 0;
virtual int GetNumericWeight() const = 0;
virtual bool GetUnderlined() const = 0;
virtual bool GetStrikethrough() const { return false; }
virtual wxString GetFaceName() const = 0;
@ -356,11 +366,12 @@ public:
wxString GetNativeFontInfoUserDesc() const;
// change the font characteristics
virtual void SetPointSize( int pointSize ) = 0;
virtual void SetPointSize( float pointSize ) = 0;
virtual void SetPixelSize( const wxSize& pixelSize );
virtual void SetFamily( wxFontFamily family ) = 0;
virtual void SetStyle( wxFontStyle style ) = 0;
virtual void SetWeight( wxFontWeight weight ) = 0;
virtual void SetNumericWeight( int weight ) = 0;
virtual void SetUnderlined( bool underlined ) = 0;
virtual void SetStrikethrough( bool WXUNUSED(strikethrough) ) {}

View File

@ -29,6 +29,10 @@
#include <QtGui/QFont>
#endif
#if defined(__WXOSX__)
#include "wx/osx/core/cfref.h"
#endif
class WXDLLIMPEXP_FWD_BASE wxArrayString;
struct WXDLLIMPEXP_FWD_CORE wxNativeEncodingInfo;
@ -120,20 +124,7 @@ public:
#elif defined(__WXOSX__)
public:
wxNativeFontInfo(const wxNativeFontInfo& info) { Init(info); }
wxNativeFontInfo( 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);
}
~wxNativeFontInfo() { Free(); }
wxNativeFontInfo& operator=(const wxNativeFontInfo& info)
@ -146,30 +137,44 @@ public:
return *this;
}
void Init(CTFontDescriptorRef descr);
void InitFromFont(CTFontRef font);
void InitFromFontDescriptor(CTFontDescriptorRef font);
void Init(const wxNativeFontInfo& info);
void Init(int size,
wxFontFamily family,
wxFontStyle style,
wxFontWeight weight,
bool underlined,
bool strikethrough,
const wxString& faceName ,
wxFontEncoding encoding);
void Free();
wxString GetFamilyName() const;
wxString GetStyleName() const;
static void UpdateNamesMap(const wxString& familyname, CTFontDescriptorRef descr);
static void UpdateNamesMap(const wxString& familyname, CTFontRef font);
int m_pointSize;
wxFontFamily m_family;
static CGFloat GetCTWeight( CTFontRef font );
static CGFloat GetCTWeight( CTFontDescriptorRef font );
static CGFloat GetCTSlant( CTFontDescriptorRef font );
CTFontDescriptorRef GetCTFontDescriptor() const;
private:
// attributes for regenerating a CTFontDescriptor, stay close to native values
// for better roundtrip fidelity
CGFloat m_ctWeight;
wxFontStyle m_style;
wxFontWeight m_weight;
CGFloat m_ctSize;
wxFontFamily m_family;
wxString m_styleName;
wxString m_familyName;
// native font description
wxCFRef<CTFontDescriptorRef> m_descriptor;
void CreateCTFontDescriptor();
// these attributes are not part of a CTFont
bool m_underlined;
bool m_strikethrough;
wxString m_faceName;
wxFontEncoding m_encoding;
public :
#elif defined(__WXQT__)
QFont m_qtFont;
@ -219,7 +224,7 @@ public:
// init with the parameters of the given font
void InitFromFont(const wxFont& font)
{
#if wxUSE_PANGO
#if wxUSE_PANGO || defined(__WXOSX__)
Init(*font.GetNativeFontInfo());
#else
// translate all font parameters
@ -252,18 +257,21 @@ public:
// accessors and modifiers for the font elements
int GetPointSize() const;
float GetFractionalPointSize() const;
wxSize GetPixelSize() const;
wxFontStyle GetStyle() const;
wxFontWeight GetWeight() const;
int GetNumericWeight() const;
bool GetUnderlined() const;
bool GetStrikethrough() const;
wxString GetFaceName() const;
wxFontFamily GetFamily() const;
wxFontEncoding GetEncoding() const;
void SetPointSize(int pointsize);
void SetPointSize(float pointsize);
void SetPixelSize(const wxSize& pixelSize);
void SetStyle(wxFontStyle style);
void SetNumericWeight(int weight);
void SetWeight(wxFontWeight weight);
void SetUnderlined(bool underlined);
void SetStrikethrough(bool strikethrough);

View File

@ -64,9 +64,10 @@ public:
virtual ~wxFont();
// implement base class pure virtuals
virtual int GetPointSize() const wxOVERRIDE;
virtual float GetFractionalPointSize() const wxOVERRIDE;
virtual wxFontStyle GetStyle() const wxOVERRIDE;
virtual wxFontWeight GetWeight() const wxOVERRIDE;
virtual int GetNumericWeight() const wxOVERRIDE;
virtual wxString GetFaceName() const wxOVERRIDE;
virtual bool GetUnderlined() const wxOVERRIDE;
virtual bool GetStrikethrough() const wxOVERRIDE;
@ -74,10 +75,11 @@ public:
virtual const wxNativeFontInfo *GetNativeFontInfo() const wxOVERRIDE;
virtual bool IsFixedWidth() const wxOVERRIDE;
virtual void SetPointSize( int pointSize ) wxOVERRIDE;
virtual void SetPointSize(float pointSize) wxOVERRIDE;
virtual void SetFamily(wxFontFamily family) wxOVERRIDE;
virtual void SetStyle(wxFontStyle style) wxOVERRIDE;
virtual void SetWeight(wxFontWeight weight) wxOVERRIDE;
virtual void SetNumericWeight(int weight) wxOVERRIDE;
virtual bool SetFaceName( const wxString& faceName ) wxOVERRIDE;
virtual void SetUnderlined( bool underlined ) wxOVERRIDE;
virtual void SetStrikethrough(bool strikethrough) wxOVERRIDE;

View File

@ -85,22 +85,24 @@ public:
virtual ~wxFont();
// implement base class pure virtuals
virtual int GetPointSize() const wxOVERRIDE;
virtual float GetFractionalPointSize() const wxOVERRIDE;
virtual wxSize GetPixelSize() const wxOVERRIDE;
virtual bool IsUsingSizeInPixels() const wxOVERRIDE;
virtual wxFontStyle GetStyle() const wxOVERRIDE;
virtual wxFontWeight GetWeight() const wxOVERRIDE;
virtual int GetNumericWeight() const wxOVERRIDE;
virtual bool GetUnderlined() const wxOVERRIDE;
virtual bool GetStrikethrough() const wxOVERRIDE;
virtual wxString GetFaceName() const wxOVERRIDE;
virtual wxFontEncoding GetEncoding() const wxOVERRIDE;
virtual const wxNativeFontInfo *GetNativeFontInfo() const wxOVERRIDE;
virtual void SetPointSize(int pointSize) wxOVERRIDE;
virtual void SetPointSize(float pointSize) wxOVERRIDE;
virtual void SetPixelSize(const wxSize& pixelSize) wxOVERRIDE;
virtual void SetFamily(wxFontFamily family) wxOVERRIDE;
virtual void SetStyle(wxFontStyle style) wxOVERRIDE;
virtual void SetWeight(wxFontWeight weight) wxOVERRIDE;
virtual void SetNumericWeight(int weight) wxOVERRIDE;
virtual bool SetFaceName(const wxString& faceName) wxOVERRIDE;
virtual void SetUnderlined(bool underlined) wxOVERRIDE;
virtual void SetStrikethrough(bool strikethrough) wxOVERRIDE;

View File

@ -79,12 +79,17 @@ public:
{
}
explicit wxCFDictionaryRef(CFDictionaryRef r)
wxCFDictionaryRef(CFDictionaryRef r)
: wxCFDictionaryRefCommon(r)
{
}
wxCFDictionaryRef& operator=(const wxCFMutableDictionaryRef& other);
CFDictionaryRef CreateCopy() const
{
return CFDictionaryCreateCopy(kCFAllocatorDefault, this->m_ptr);
}
};
class wxCFMutableDictionaryRef : public wxCFDictionaryRefCommon<CFMutableDictionaryRef>
@ -95,7 +100,7 @@ public:
{
}
explicit wxCFMutableDictionaryRef(CFMutableDictionaryRef r)
wxCFMutableDictionaryRef(CFMutableDictionaryRef r)
: wxCFDictionaryRefCommon(r)
{
}
@ -109,6 +114,11 @@ public:
{
SetValue(key, wxCFNumberRef(v));
}
CFMutableDictionaryRef CreateCopy() const
{
return CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, this->m_ptr);
}
friend class wxCFDictionaryRef;
};

View File

@ -51,6 +51,7 @@ public:
}
wxFont( wxOSXSystemFont systemFont );
wxFont(CTFontRef font);
#if wxOSX_USE_COCOA
wxFont(WX_NSFont nsfont);
@ -67,6 +68,17 @@ public:
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,
wxFontFamily family,
wxFontStyle style,
@ -87,6 +99,14 @@ public:
const wxString& face = wxEmptyString,
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)
{
(void)Create(info);
@ -99,26 +119,28 @@ public:
virtual ~wxFont();
// implement base class pure virtuals
virtual int GetPointSize() const;
virtual wxSize GetPixelSize() const;
virtual wxFontStyle GetStyle() const;
virtual wxFontWeight GetWeight() const;
virtual bool GetUnderlined() const;
virtual bool GetStrikethrough() const;
virtual wxString GetFaceName() const;
virtual wxFontEncoding GetEncoding() const;
virtual const wxNativeFontInfo *GetNativeFontInfo() const;
virtual float GetFractionalPointSize() const wxOVERRIDE;
virtual wxSize GetPixelSize() const wxOVERRIDE;
virtual wxFontStyle GetStyle() const wxOVERRIDE;
virtual wxFontWeight GetWeight() const wxOVERRIDE;
virtual int GetNumericWeight() const wxOVERRIDE;
virtual bool GetUnderlined() const wxOVERRIDE;
virtual bool GetStrikethrough() const wxOVERRIDE;
virtual wxString GetFaceName() const wxOVERRIDE;
virtual wxFontEncoding GetEncoding() const wxOVERRIDE;
virtual const wxNativeFontInfo *GetNativeFontInfo() const wxOVERRIDE;
virtual bool IsFixedWidth() const;
virtual bool IsFixedWidth() const wxOVERRIDE;
virtual void SetPointSize(int pointSize);
virtual void SetFamily(wxFontFamily family);
virtual void SetStyle(wxFontStyle style);
virtual void SetWeight(wxFontWeight weight);
virtual bool SetFaceName(const wxString& faceName);
virtual void SetUnderlined(bool underlined);
virtual void SetStrikethrough(bool strikethrough);
virtual void SetEncoding(wxFontEncoding encoding);
virtual void SetPointSize(float pointSize) wxOVERRIDE;
virtual void SetFamily(wxFontFamily family) wxOVERRIDE;
virtual void SetStyle(wxFontStyle style) wxOVERRIDE;
virtual void SetWeight(wxFontWeight weight) wxOVERRIDE;
virtual void SetNumericWeight(int weight) wxOVERRIDE;
virtual bool SetFaceName(const wxString& faceName) wxOVERRIDE;
virtual void SetUnderlined(bool underlined) wxOVERRIDE;
virtual void SetStrikethrough(bool strikethrough) wxOVERRIDE;
virtual void SetEncoding(wxFontEncoding encoding) wxOVERRIDE;
wxDECLARE_COMMON_FONT_METHODS();
@ -148,7 +170,6 @@ public:
#if wxOSX_USE_COCOA
WX_NSFont OSXGetNSFont() const;
static void SetNativeInfoFromNSFont(WX_NSFont nsfont, wxNativeFontInfo* info);
#endif
#if wxOSX_USE_IPHONE
@ -156,11 +177,11 @@ public:
#endif
protected:
virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info);
virtual wxFontFamily DoGetFamily() const;
virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info) wxOVERRIDE;
virtual wxFontFamily DoGetFamily() const wxOVERRIDE;
virtual wxGDIRefData *CreateGDIRefData() const;
virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
virtual wxGDIRefData *CreateGDIRefData() const wxOVERRIDE;
virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const wxOVERRIDE;
private:

View File

@ -61,13 +61,27 @@ enum wxFontStyle
/**
Font weights.
The values of this enum correspond to the CSS font weight specifications,
see https://www.w3.org/TR/css-fonts-4/#font-weight-prop, with the addition of
one font weight bolder than heavy
*/
enum wxFontWeight
{
wxFONTWEIGHT_NORMAL = wxNORMAL, //!< Normal font.
wxFONTWEIGHT_LIGHT = wxLIGHT, //!< Light font.
wxFONTWEIGHT_BOLD = wxBOLD, //!< Bold font.
wxFONTWEIGHT_MAX
wxFONTWEIGHT_INVALID = 0, //!< Invalid font weight. @since 3.1.2
wxFONTWEIGHT_THIN = 100, //!< Thin font (weight = 100). @since 3.1.2
wxFONTWEIGHT_EXTRALIGHT = 200, //!< Extra Light (Ultra Light) font (weight = 200). @since 3.1.2
wxFONTWEIGHT_LIGHT = 300, //!< Light font (weight = 300).
wxFONTWEIGHT_NORMAL = 400, //!< Normal font (weight = 400).
wxFONTWEIGHT_MEDIUM = 500, //!< Medium font (weight = 500). @since 3.1.2
wxFONTWEIGHT_SEMIBOLD = 600, //!< Semi Bold (Demi Bold) font (weight = 600). @since 3.1.2
wxFONTWEIGHT_BOLD = 700, //!< Bold font (weight = 700).
wxFONTWEIGHT_EXTRABOLD = 800, //!< Extra Bold (Ultra Bold) font (weight = 800). @since 3.1.2
wxFONTWEIGHT_HEAVY = 900, //!< Heavy (Black) font (weight = 900). @since 3.1.2
wxFONTWEIGHT_EXTRAHEAVY = 1000, //!< Extra Heavy font (weight = 1000). @since 3.1.2
wxFONTWEIGHT_MAX = wxFONTWEIGHT_EXTRAHEAVY
};
/**
@ -698,12 +712,24 @@ public:
static bool AddPrivateFont(const wxString& filename);
/**
Gets the point size.
Gets the point size as an integer number.
@see SetPointSize()
This function is kept for compatibility reasons. New code should use
GetFractionalPointSize() and support fractional point sizes.
@see SetPointSize(), @see GetFractionalPointSize()
*/
virtual int GetPointSize() const;
/**
Gets the point size as a floating number.
@see SetPointSize(float)
@since 3.1.2
*/
virtual float GetFractionalPointSize() const;
/**
Gets the pixel size.
@ -745,6 +771,18 @@ public:
*/
virtual wxFontWeight GetWeight() const;
/**
Gets the font weight as an integer value.
See ::wxFontWeight for a list of valid weight identifiers and their corresponding integer value.
@see SetWeight()
@see SetNumericWeight()
@since 3.1.2
*/
virtual int GetNumericWeight() const;
/**
Returns @true if the font is a fixed width (or monospaced) font,
@false if it is a proportional one or font is invalid.
@ -1019,7 +1057,7 @@ public:
bool SetNativeFontInfoUserDesc(const wxString& info);
void SetNativeFontInfo(const wxNativeFontInfo& info);
/**
Sets the point size.
@ -1027,11 +1065,13 @@ public:
(25.4 mm): it is approximately 0.0139 inch or 352.8 um.
@param pointSize
Size in points.
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()
*/
virtual void SetPointSize(int pointSize);
virtual void SetPointSize(float pointSize);
/**
Sets the pixel size.
@ -1114,6 +1154,19 @@ public:
*/
virtual void SetWeight(wxFontWeight weight);
/**
Sets the font weight using an integer value.
See ::wxFontWeight for a list of valid weight identifiers and their
corresponding integer value.
@param weight
An integer value int the range 1-1000.
@see GetNumericWeight()
*/
virtual void SetNumericWeight(int weight);
//@}
@ -1186,7 +1239,7 @@ public:
const wxString& faceName = wxEmptyString,
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
static wxFont *New(const wxNativeFontInfo& nativeInfo);
static wxFont *New(const wxString& nativeInfoString);
@ -1265,7 +1318,7 @@ public:
/**
Finds a font of the given specification, or creates one and adds it to the
list. See the @ref wxFont "wxFont constructor" for details of the arguments.
@since 3.1.1
*/
wxFont* FindOrCreateFont(const wxFontInfo& fontInfo);

View File

@ -29,19 +29,22 @@ public:
void Init();
void InitFromFont(const wxFont& font);
int GetPointSize() const;
float GetFractionalPointSize() const;
wxSize GetPixelSize() const;
wxFontStyle GetStyle() const;
int GetNumericWeight() const;
wxFontWeight GetWeight() const;
bool GetUnderlined() const;
wxString GetFaceName() const;
wxFontFamily GetFamily() const;
wxFontEncoding GetEncoding() const;
void SetPointSize(int pointsize);
void SetPointSize(float pointsize);
void SetPixelSize(const wxSize& pixelSize);
void SetStyle(wxFontStyle style);
void SetNumericWeight(int weight);
void SetWeight(wxFontWeight weight);
void SetUnderlined(bool underlined);
bool SetFaceName(const wxString& facename);

View File

@ -456,7 +456,9 @@ t_bitmap = t_url?,
t_font = (
[xrc:p="o"] element size {_, t_integer }* &
[xrc:p="o"] element style {_, ("normal" | "italic" | "slant") }* &
[xrc:p="o"] element weight {_, ("normal" | "bold" | "light") }* &
[xrc:p="o"] element weight {_, ("normal" | "thin" | "extralight" | "light" |
"medium" | "semibold" | "bold" | "extrabold" |
"heavy" | "extraheavy") }* &
[xrc:p="o"] element family {_, ("roman" | "script" | "decorative" | "swiss" |
"modern" | "teletype") }* &
[xrc:p="o"] element underlined {_, t_bool }* &

View File

@ -576,27 +576,7 @@ void wxSVGFileDCImpl::DoDrawRotatedText(const wxString& sText, wxCoord x, wxCoor
else
s += wxS("style=\" ");
wxString fontweight;
switch (m_font.GetWeight())
{
case wxFONTWEIGHT_MAX:
wxFAIL_MSG(wxS("invalid font weight value"));
wxFALLTHROUGH;
case wxFONTWEIGHT_NORMAL:
fontweight = wxS("normal");
break;
case wxFONTWEIGHT_LIGHT:
fontweight = wxS("lighter");
break;
case wxFONTWEIGHT_BOLD:
fontweight = wxS("bold");
break;
}
wxASSERT_MSG(!fontweight.empty(), wxS("unknown font weight value"));
wxString fontweight = wxString::Format(wxS("%d"),m_font.GetWeight());
s += wxS("font-weight:") + fontweight + wxS("; ");

View File

@ -92,9 +92,16 @@ wxENUM_MEMBER( wxFONTSTYLE_SLANT )
wxEND_ENUM( wxFontStyle )
wxBEGIN_ENUM( wxFontWeight )
wxENUM_MEMBER( wxFONTWEIGHT_NORMAL )
wxENUM_MEMBER( wxFONTWEIGHT_THIN )
wxENUM_MEMBER( wxFONTWEIGHT_EXTRALIGHT )
wxENUM_MEMBER( wxFONTWEIGHT_LIGHT )
wxENUM_MEMBER( wxFONTWEIGHT_NORMAL )
wxENUM_MEMBER( wxFONTWEIGHT_MEDIUM )
wxENUM_MEMBER( wxFONTWEIGHT_SEMIBOLD )
wxENUM_MEMBER( wxFONTWEIGHT_BOLD )
wxENUM_MEMBER( wxFONTWEIGHT_EXTRABOLD )
wxENUM_MEMBER( wxFONTWEIGHT_HEAVY )
wxENUM_MEMBER( wxFONTWEIGHT_EXTRAHEAVY )
wxEND_ENUM( wxFontWeight )
wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI(wxFont, wxGDIObject, "wx/font.h");
@ -225,6 +232,12 @@ bool wxFontBase::IsFixedWidth() const
return GetFamily() == wxFONTFAMILY_TELETYPE;
}
int wxFontBase::GetPointSize() const
{
return wxRound(GetFractionalPointSize());
}
wxSize wxFontBase::GetPixelSize() const
{
wxScreenDC dc;
@ -455,9 +468,16 @@ wxString wxFontBase::GetWeightString() const
switch ( GetWeight() )
{
case wxFONTWEIGHT_NORMAL: return "wxFONTWEIGHT_NORMAL";
case wxFONTWEIGHT_BOLD: return "wxFONTWEIGHT_BOLD";
case wxFONTWEIGHT_THIN: return "wxFONTWEIGHT_THIN";
case wxFONTWEIGHT_EXTRALIGHT: return "wxFONTWEIGHT_EXTRALIGHT";
case wxFONTWEIGHT_LIGHT: return "wxFONTWEIGHT_LIGHT";
case wxFONTWEIGHT_NORMAL: return "wxFONTWEIGHT_NORMAL";
case wxFONTWEIGHT_MEDIUM: return "wxFONTWEIGHT_MEDIUM";
case wxFONTWEIGHT_SEMIBOLD: return "wxFONTWEIGHT_SEMIBOLD";
case wxFONTWEIGHT_BOLD: return "wxFONTWEIGHT_BOLD";
case wxFONTWEIGHT_EXTRABOLD: return "wxFONTWEIGHT_EXTRABOLD";
case wxFONTWEIGHT_HEAVY: return "wxFONTWEIGHT_HEAVY";
case wxFONTWEIGHT_EXTRAHEAVY: return "wxFONTWEIGHT_EXTRAHEAVY";
default: return "wxFONTWEIGHT_DEFAULT";
}
}
@ -816,13 +836,41 @@ wxString wxNativeFontInfo::ToUserString() const
case wxFONTWEIGHT_NORMAL:
break;
case wxFONTWEIGHT_THIN:
desc << _(" thin");
break;
case wxFONTWEIGHT_EXTRALIGHT:
desc << _(" extra light");
break;
case wxFONTWEIGHT_LIGHT:
desc << _(" light");
break;
case wxFONTWEIGHT_MEDIUM:
desc << _(" medium");
break;
case wxFONTWEIGHT_SEMIBOLD:
desc << _(" semi bold");
break;
case wxFONTWEIGHT_BOLD:
desc << _(" bold");
break;
case wxFONTWEIGHT_EXTRABOLD:
desc << _(" extra bold");
break;
case wxFONTWEIGHT_HEAVY:
desc << _(" heavy");
break;
case wxFONTWEIGHT_EXTRAHEAVY:
desc << _(" extra heavy");
break;
}
switch ( GetStyle() )
@ -938,6 +986,8 @@ bool wxNativeFontInfo::FromUserString(const wxString& s)
bool encodingfound = false;
#endif
bool insideQuotes = false;
bool extraQualifierFound = false;
bool semiQualifierFound = false;
while ( tokenizer.HasMoreTokens() )
{
@ -988,21 +1038,85 @@ bool wxNativeFontInfo::FromUserString(const wxString& s)
SetUnderlined(true);
SetStrikethrough(true);
}
else if ( token == wxT("light") || token == _("light") )
else if ( token == wxS("thin") || token == _("thin") )
{
SetWeight(wxFONTWEIGHT_LIGHT);
SetWeight(wxFONTWEIGHT_THIN);
weightfound = true;
}
else if ( token == wxT("bold") || token == _("bold") )
else if ( token == wxS("extra") || token == wxS("ultra"))
{
SetWeight(wxFONTWEIGHT_BOLD);
extraQualifierFound = true;
}
else if ( token == wxS("semi") || token == wxS("demi") )
{
semiQualifierFound = true;
}
else if ( token == wxS("extralight") || token == _("extralight") )
{
SetWeight(wxFONTWEIGHT_EXTRALIGHT);
weightfound = true;
}
else if ( token == wxS("light") || token == _("light") )
{
if ( extraQualifierFound )
SetWeight(wxFONTWEIGHT_EXTRALIGHT);
else
SetWeight(wxFONTWEIGHT_LIGHT);
weightfound = true;
}
else if ( token == wxS("normal") || token == _("normal") )
{
SetWeight(wxFONTWEIGHT_NORMAL);
weightfound = true;
}
else if ( token == wxS("medium") || token == _("medium") )
{
SetWeight(wxFONTWEIGHT_MEDIUM);
weightfound = true;
}
else if ( token == wxS("semibold") || token == _("semibold") )
{
SetWeight(wxFONTWEIGHT_SEMIBOLD);
weightfound = true;
}
else if ( token == wxS("bold") || token == _("bold") )
{
if ( extraQualifierFound )
SetWeight(wxFONTWEIGHT_EXTRABOLD);
else if ( semiQualifierFound )
SetWeight(wxFONTWEIGHT_SEMIBOLD);
else
SetWeight(wxFONTWEIGHT_BOLD);
weightfound = true;
}
else if ( token == wxS("extrabold") || token == _("extrabold") )
{
SetWeight(wxFONTWEIGHT_EXTRABOLD);
weightfound = true;
}
else if ( token == wxS("semibold") || token == _("semibold") )
{
SetWeight(wxFONTWEIGHT_SEMIBOLD);
weightfound = true;
}
else if ( token == wxS("heavy") || token == _("heavy") )
{
if ( extraQualifierFound )
SetWeight(wxFONTWEIGHT_EXTRAHEAVY);
else
SetWeight(wxFONTWEIGHT_HEAVY);
weightfound = true;
}
else if ( token == wxS("extraheavy") || token == _("extraheavy") )
{
SetWeight(wxFONTWEIGHT_EXTRAHEAVY);
weightfound = true;
}
else if ( token == wxT("italic") || token == _("italic") )
{
SetStyle(wxFONTSTYLE_ITALIC);
}
else if ( token.ToULong(&size) )
else if ( token.ToULong(&size ) )
{
SetPointSize(size);
pointsizefound = true;
@ -1116,6 +1230,41 @@ bool wxNativeFontInfo::FromUserString(const wxString& s)
#endif // generic or wxMSW
// compatibility functions using old API implemented using numeric weight values
wxFontWeight wxNativeFontInfo::GetWeight() const
{
// round to nearest hundredth = wxFONTWEIGHT_ constant
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)
{
// deal with compatibility constants
if (weight >= 90 && weight <= 92)
{
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
wxString wxToString(const wxFontBase& font)

View File

@ -65,10 +65,11 @@ public:
// 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
void SetPointSize(int pointSize);
void SetPointSize(float pointSize);
void SetFamily(wxFontFamily family);
void SetStyle(wxFontStyle style);
void SetWeight(wxFontWeight weight);
void SetNumericWeight(int weight);
void SetUnderlined(bool underlined);
void SetStrikethrough(bool strikethrough);
bool SetFaceName(const wxString& facename);
@ -190,7 +191,7 @@ wxFontRefData::~wxFontRefData()
// wxFontRefData SetXXX()
// ----------------------------------------------------------------------------
void wxFontRefData::SetPointSize(int pointSize)
void wxFontRefData::SetPointSize(float pointSize)
{
m_nativeFontInfo.SetPointSize(pointSize);
}
@ -239,6 +240,11 @@ void wxFontRefData::SetWeight(wxFontWeight weight)
m_nativeFontInfo.SetWeight(weight);
}
void wxFontRefData::SetNumericWeight(int weight)
{
m_nativeFontInfo.SetNumericWeight(weight);
}
void wxFontRefData::SetUnderlined(bool underlined)
{
m_nativeFontInfo.SetUnderlined(underlined);
@ -340,11 +346,11 @@ wxFont::~wxFont()
// accessors
// ----------------------------------------------------------------------------
int wxFont::GetPointSize() const
float wxFont::GetFractionalPointSize() const
{
wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
return M_FONTDATA->m_nativeFontInfo.GetPointSize();
return M_FONTDATA->m_nativeFontInfo.GetFractionalPointSize();
}
wxString wxFont::GetFaceName() const
@ -368,11 +374,18 @@ wxFontStyle wxFont::GetStyle() const
wxFontWeight wxFont::GetWeight() const
{
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font") );
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, "invalid font" );
return M_FONTDATA->m_nativeFontInfo.GetWeight();
}
int wxFont::GetNumericWeight() const
{
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, "invalid font" );
return M_FONTDATA->m_nativeFontInfo.GetNumericWeight();
}
bool wxFont::GetUnderlined() const
{
wxCHECK_MSG( IsOk(), false, wxT("invalid font") );
@ -413,7 +426,7 @@ bool wxFont::IsFixedWidth() const
// change font attributes
// ----------------------------------------------------------------------------
void wxFont::SetPointSize(int pointSize)
void wxFont::SetPointSize(float pointSize)
{
AllocExclusive();
@ -441,6 +454,13 @@ void wxFont::SetWeight(wxFontWeight weight)
M_FONTDATA->SetWeight(weight);
}
void wxFont::SetNumericWeight(int weight)
{
AllocExclusive();
M_FONTDATA->SetNumericWeight(weight);
}
bool wxFont::SetFaceName(const wxString& faceName)
{
AllocExclusive();
@ -650,3 +670,4 @@ bool wxFontBase::AddPrivateFont(const wxString& filename)
}
#endif // wxUSE_PRIVATE_FONTS

View File

@ -98,7 +98,7 @@ public:
void Free();
// all wxFont accessors
int GetPointSize() const
float GetFractionalPointSize() const
{
return m_nativeFontInfo.GetPointSize();
}
@ -128,6 +128,11 @@ public:
return m_nativeFontInfo.GetWeight();
}
int GetNumericWeight() const
{
return m_nativeFontInfo.GetNumericWeight();
}
bool GetUnderlined() const
{
return m_nativeFontInfo.GetUnderlined();
@ -176,7 +181,7 @@ public:
// ... and setters: notice that all of them invalidate the currently
// allocated HFONT, if any, so that the next call to GetHFONT() recreates a
// new one
void SetPointSize(int pointSize)
void SetPointSize(float pointSize)
{
Free();
@ -216,6 +221,13 @@ public:
m_nativeFontInfo.SetWeight(weight);
}
void SetNumericWeight(int weight)
{
Free();
m_nativeFontInfo.SetNumericWeight(weight);
}
bool SetFaceName(const wxString& faceName)
{
Free();
@ -437,6 +449,11 @@ void wxNativeFontInfo::Init()
}
int wxNativeFontInfo::GetPointSize() const
{
return wxRound(GetFractionalPointSize());
}
float wxNativeFontInfo::GetFractionalPointSize() const
{
// FIXME: using the screen here results in incorrect font size calculation
// for printing!
@ -459,15 +476,9 @@ wxFontStyle wxNativeFontInfo::GetStyle() const
return lf.lfItalic ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL;
}
wxFontWeight wxNativeFontInfo::GetWeight() const
int wxNativeFontInfo::GetNumericWeight() const
{
if ( lf.lfWeight <= 300 )
return wxFONTWEIGHT_LIGHT;
if ( lf.lfWeight >= 600 )
return wxFONTWEIGHT_BOLD;
return wxFONTWEIGHT_NORMAL;
return lf.lfWeight;
}
bool wxNativeFontInfo::GetUnderlined() const
@ -530,7 +541,7 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
return wxGetFontEncFromCharSet(lf.lfCharSet);
}
void wxNativeFontInfo::SetPointSize(int pointsize)
void wxNativeFontInfo::SetPointSize(float pointsize)
{
// FIXME: using the screen here results in incorrect font size calculation
// for printing!
@ -573,26 +584,9 @@ void wxNativeFontInfo::SetStyle(wxFontStyle style)
}
}
void wxNativeFontInfo::SetWeight(wxFontWeight weight)
void wxNativeFontInfo::SetNumericWeight(int weight)
{
switch ( weight )
{
default:
wxFAIL_MSG( "unknown font weight" );
// fall through
case wxFONTWEIGHT_NORMAL:
lf.lfWeight = FW_NORMAL;
break;
case wxFONTWEIGHT_LIGHT:
lf.lfWeight = FW_LIGHT;
break;
case wxFONTWEIGHT_BOLD:
lf.lfWeight = FW_BOLD;
break;
}
lf.lfWeight = weight;
}
void wxNativeFontInfo::SetUnderlined(bool underlined)
@ -906,7 +900,7 @@ bool wxFont::IsFree() const
// change font attribute: we recreate font when doing it
// ----------------------------------------------------------------------------
void wxFont::SetPointSize(int pointSize)
void wxFont::SetPointSize(float pointSize)
{
AllocExclusive();
@ -942,6 +936,13 @@ void wxFont::SetWeight(wxFontWeight weight)
M_FONTDATA->SetWeight(weight);
}
void wxFont::SetNumericWeight(int weight)
{
AllocExclusive();
M_FONTDATA->SetNumericWeight(weight);
}
bool wxFont::SetFaceName(const wxString& faceName)
{
AllocExclusive();
@ -991,11 +992,11 @@ void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo& info)
// accessors
// ----------------------------------------------------------------------------
int wxFont::GetPointSize() const
float wxFont::GetFractionalPointSize() const
{
wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
return M_FONTDATA->GetPointSize();
return M_FONTDATA->GetFractionalPointSize();
}
wxSize wxFont::GetPixelSize() const
@ -1026,11 +1027,18 @@ wxFontStyle wxFont::GetStyle() const
wxFontWeight wxFont::GetWeight() const
{
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font") );
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, "invalid font" );
return M_FONTDATA->GetWeight();
}
int wxFont::GetNumericWeight() const
{
wxCHECK_MSG(IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font"));
return M_FONTDATA->GetNumericWeight();
}
bool wxFont::GetUnderlined() const
{
wxCHECK_MSG( IsOk(), false, wxT("invalid font") );

File diff suppressed because it is too large Load Diff

View File

@ -274,7 +274,8 @@ int RunMixedFontDialog(wxFontDialog* dialog)
if ( [accessoryView closedWithOk])
{
#if wxOSX_USE_COCOA
fontdata.m_chosenFont = wxFont( theFont );
fontdata.m_chosenFont = wxFont(theFont);
// copy the attributes not contained in a native CTFont
fontdata.m_chosenFont.SetUnderlined(theFPDelegate->m_isUnderline);
fontdata.m_chosenFont.SetStrikethrough(theFPDelegate->m_isStrikethrough);
@ -456,31 +457,11 @@ bool wxFontDialog::Create(wxWindow *parent)
//NSFontDialog to that font
if (thewxfont.IsOk())
{
NSFontTraitMask theMask = 0;
if(thewxfont.GetStyle() == wxFONTSTYLE_ITALIC)
theMask |= NSItalicFontMask;
if(thewxfont.IsFixedWidth())
theMask |= NSFixedPitchFontMask;
NSFont* theDefaultFont =
[[NSFontManager sharedFontManager] fontWithFamily:
wxNSStringWithWxString(thewxfont.GetFaceName())
traits:theMask
weight:thewxfont.GetWeight() == wxFONTWEIGHT_BOLD ? 9 :
thewxfont.GetWeight() == wxFONTWEIGHT_LIGHT ? 0 : 5
size: (float)(thewxfont.GetPointSize())
];
wxASSERT_MSG(theDefaultFont, wxT("Invalid default font for wxCocoaFontDialog!"));
//Apple docs say to call NSFontManager::setSelectedFont
//However, 10.3 doesn't seem to create the font panel
//is this is done, so create it ourselves
[[NSFontPanel sharedFontPanel] setPanelFont:theDefaultFont isMultiple:NO];
[[NSFontPanel sharedFontPanel] setPanelFont:thewxfont.OSXGetNSFont() isMultiple:NO];
[[NSFontManager sharedFontManager] setSelectedFont:theDefaultFont isMultiple:false];
}
if(m_fontData.m_fontColour.IsOk())
@ -579,22 +560,11 @@ int wxFontDialog::ShowModal()
//Get the font the user selected
NSFont* theFont = [theFontPanel panelConvertFont:[NSFont userFontOfSize:0]];
//Get more information about the user's chosen font
NSFontTraitMask theTraits = [[NSFontManager sharedFontManager] traitsOfFont:theFont];
int theFontWeight = [[NSFontManager sharedFontManager] weightOfFont:theFont];
int theFontSize = (int) [theFont pointSize];
//Set the wx font to the appropriate data
if(theTraits & NSFixedPitchFontMask)
m_fontData.m_chosenFont.SetFamily(wxTELETYPE);
m_fontData.m_chosenFont.SetFaceName(wxStringWithNSString([theFont familyName]));
m_fontData.m_chosenFont.SetPointSize(theFontSize);
m_fontData.m_chosenFont.SetStyle(theTraits & NSItalicFontMask ? wxFONTSTYLE_ITALIC : 0);
m_fontData.m_chosenFont.SetWeight(theFontWeight < 5 ? wxFONTWEIGHT_LIGHT :
theFontWeight >= 9 ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
m_fontData.m_chosenFont = wxFont(theFont);
// copy the attributes not contained in a native CTFont
m_fontData.m_chosenFont.SetUnderlined(theFPDelegate->m_isUnderline);
m_fontData.m_chosenFont.SetStrikethrough(theFPDelegate->m_isStrikethrough);
//Get the shared color panel along with the chosen color and set the chosen color
m_fontData.m_fontColour = wxColour([theColorPanel color]);

View File

@ -834,10 +834,10 @@ wxMacCoreGraphicsFontData::wxMacCoreGraphicsFontData(wxGraphicsRenderer* rendere
m_underlined = font.GetUnderlined();
m_strikethrough = font.GetStrikethrough();
m_ctFont.reset( wxCFRetain( font.OSXGetCTFont() ) );
m_ctFontAttributes.reset( wxCFRetain( font.OSXGetCTFontAttributes() ) );
m_ctFont = wxCFRetain(font.OSXGetCTFont());
m_ctFontAttributes = wxCFRetain(font.OSXGetCTFontAttributes());
#if wxOSX_USE_IPHONE
m_uiFont.reset( wxCFRetain( font.OSXGetUIFont() ) );
m_uiFont = font.OSXGetUIFont();
#endif
}
@ -2892,13 +2892,10 @@ wxMacCoreGraphicsRenderer::CreateFont(double sizeInPixels,
int flags,
const wxColour& col)
{
// This implementation is not ideal as we don't support fractional font
// sizes right now, but it's the simplest one.
//
// 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
// ctor.
wxFont font(wxRound(sizeInPixels),
wxFont font((float)sizeInPixels,
wxFONTFAMILY_DEFAULT,
flags & wxFONTFLAG_ITALIC ? wxFONTSTYLE_ITALIC
: wxFONTSTYLE_NORMAL,

View File

@ -97,48 +97,6 @@ void* wxMacCocoaRetain( void* obj )
// ----------------------------------------------------------------------------
#if wxOSX_USE_COCOA
wxFont::wxFont(WX_NSFont nsfont)
{
wxNativeFontInfo info;
SetNativeInfoFromNSFont(nsfont, &info);
Create(info);
}
void wxFont::SetNativeInfoFromNSFont(WX_NSFont theFont, wxNativeFontInfo* info)
{
if ( info->m_faceName.empty())
{
//Get more information about the user's chosen font
NSFontTraitMask theTraits = [[NSFontManager sharedFontManager] traitsOfFont:theFont];
int theFontWeight = [[NSFontManager sharedFontManager] weightOfFont:theFont];
wxFontFamily fontFamily = wxFONTFAMILY_DEFAULT;
//Set the wx font to the appropriate data
if(theTraits & NSFixedPitchFontMask)
fontFamily = wxFONTFAMILY_TELETYPE;
wxFontStyle fontstyle = wxFONTSTYLE_NORMAL;
wxFontWeight fontweight = wxFONTWEIGHT_NORMAL;
bool underlined = false;
bool strikethrough = false;
int size = (int) ([theFont pointSize]+0.5);
if ( theFontWeight >= 9 )
fontweight = wxFONTWEIGHT_BOLD ;
else if ( theFontWeight < 5 )
fontweight = wxFONTWEIGHT_LIGHT;
else
fontweight = wxFONTWEIGHT_NORMAL ;
if ( theTraits & NSItalicFontMask )
fontstyle = wxFONTSTYLE_ITALIC ;
info->Init(size,fontFamily,fontstyle,fontweight,underlined, strikethrough,
wxCFStringRef::AsString([theFont familyName]), wxFONTENCODING_DEFAULT);
}
}
NSFont* wxFont::OSXGetNSFont() const
{
@ -597,8 +555,6 @@ wxOSXEffectiveAppearanceSetter::wxOSXEffectiveAppearanceSetter()
formerAppearance = NSAppearance.currentAppearance;
NSAppearance.currentAppearance = NSApp.effectiveAppearance;
}
#else
wxUnusedVar(formerAppearance);
#endif
}

View File

@ -617,16 +617,30 @@ static const long gs_fp_es_style_values[] = {
};
static const wxChar* const gs_fp_es_weight_labels[] = {
wxT("Normal"),
wxT("Thin"),
wxT("ExtraLight"),
wxT("Light"),
wxT("Normal"),
wxT("Medium"),
wxT("SemiBold"),
wxT("Bold"),
wxT("ExtraBold"),
wxT("Heavy"),
wxT("ExtraHeavy"),
(const wxChar*) NULL
};
static const long gs_fp_es_weight_values[] = {
wxFONTWEIGHT_NORMAL,
wxFONTWEIGHT_THIN,
wxFONTWEIGHT_EXTRALIGHT,
wxFONTWEIGHT_LIGHT,
wxFONTWEIGHT_BOLD
wxFONTWEIGHT_NORMAL,
wxFONTWEIGHT_MEDIUM,
wxFONTWEIGHT_SEMIBOLD,
wxFONTWEIGHT_BOLD,
wxFONTWEIGHT_EXTRABOLD,
wxFONTWEIGHT_HEAVY,
wxFONTWEIGHT_EXTRAHEAVY
};
// Class body is in advprops.h
@ -788,9 +802,7 @@ wxVariant wxFontProperty::ChildChanged( wxVariant& thisValue,
else if ( ind == 3 )
{
int wt = childValue.GetLong();
if ( wt != wxFONTWEIGHT_NORMAL &&
wt != wxFONTWEIGHT_LIGHT &&
wt != wxFONTWEIGHT_BOLD )
if ( wt < wxFONTWEIGHT_THIN || wt > wxFONTWEIGHT_MAX )
wt = wxFONTWEIGHT_NORMAL;
font.SetWeight( static_cast<wxFontWeight>(wt) );
}

View File

@ -53,7 +53,7 @@ static QFont::StyleHint ConvertFontFamily(wxFontFamily family)
return QFont::AnyStyle;
}
static QFont::Weight ConvertFontWeight(wxFontWeight weight)
static QFont::Weight ConvertFontWeight(int weight)
{
switch (weight)
{
@ -66,6 +66,12 @@ static QFont::Weight ConvertFontWeight(wxFontWeight weight)
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;
@ -328,7 +334,7 @@ wxFontStyle wxNativeFontInfo::GetStyle() const
return wxFontStyle();
}
wxFontWeight wxNativeFontInfo::GetWeight() const
int wxNativeFontInfo::GetNumericWeight() const
{
switch ( m_qtFont.weight() )
{
@ -339,12 +345,16 @@ wxFontWeight wxNativeFontInfo::GetWeight() const
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" );
return wxFontWeight();
return wxFONTWEIGHT_NORMAL;
}
bool wxNativeFontInfo::GetUnderlined() const
@ -411,7 +421,7 @@ void wxNativeFontInfo::SetStyle(wxFontStyle style)
//case wxFONTSTYLE_NORMAL:
}
void wxNativeFontInfo::SetWeight(wxFontWeight weight)
void wxNativeFontInfo::SetNumericWeight(int weight)
{
m_qtFont.setWeight(ConvertFontWeight(weight));
}

View File

@ -92,7 +92,12 @@ void wxNativeFontInfo::Free()
int wxNativeFontInfo::GetPointSize() const
{
return pango_font_description_get_size( description ) / PANGO_SCALE;
return wxRound(GetFractionalPointSize());
}
float wxNativeFontInfo::GetFractionalPointSize() const
{
return ((float) pango_font_description_get_size( description )) / PANGO_SCALE;
}
wxFontStyle wxNativeFontInfo::GetStyle() const
@ -115,7 +120,7 @@ wxFontStyle wxNativeFontInfo::GetStyle() const
return m_style;
}
wxFontWeight wxNativeFontInfo::GetWeight() const
int wxNativeFontInfo::GetNumericWeight() const
{
// We seem to currently initialize only by string.
// In that case PANGO_FONT_MASK_WEIGHT is always set.
@ -123,19 +128,7 @@ wxFontWeight wxNativeFontInfo::GetWeight() const
// return wxFONTWEIGHT_NORMAL;
PangoWeight pango_weight = pango_font_description_get_weight( description );
// Until the API can be changed the following ranges of weight values are used:
// wxFONTWEIGHT_LIGHT: 100 .. 349 - range of 250
// wxFONTWEIGHT_NORMAL: 350 .. 599 - range of 250
// wxFONTWEIGHT_BOLD: 600 .. 900 - range of 301 (600 is "semibold" already)
if (pango_weight >= 600)
return wxFONTWEIGHT_BOLD;
if (pango_weight < 350)
return wxFONTWEIGHT_LIGHT;
return wxFONTWEIGHT_NORMAL;
return pango_weight;
}
bool wxNativeFontInfo::GetUnderlined() const
@ -226,7 +219,7 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
return wxFONTENCODING_SYSTEM;
}
void wxNativeFontInfo::SetPointSize(int pointsize)
void wxNativeFontInfo::SetPointSize(float pointsize)
{
pango_font_description_set_size( description, pointsize * PANGO_SCALE );
}
@ -250,22 +243,9 @@ void wxNativeFontInfo::SetStyle(wxFontStyle style)
}
}
void wxNativeFontInfo::SetWeight(wxFontWeight weight)
void wxNativeFontInfo::SetNumericWeight(int weight)
{
switch (weight)
{
case wxFONTWEIGHT_BOLD:
pango_font_description_set_weight(description, PANGO_WEIGHT_BOLD);
break;
case wxFONTWEIGHT_LIGHT:
pango_font_description_set_weight(description, PANGO_WEIGHT_LIGHT);
break;
default:
wxFAIL_MSG( "unknown font weight" );
// fall through
case wxFONTWEIGHT_NORMAL:
pango_font_description_set_weight(description, PANGO_WEIGHT_NORMAL);
}
pango_font_description_set_weight(description, (PangoWeight) weight);
}
void wxNativeFontInfo::SetUnderlined(bool underlined)
@ -726,6 +706,11 @@ void wxNativeFontInfo::SetXFontName(const wxString& xFontName_)
}
int wxNativeFontInfo::GetPointSize() const
{
return wxRound(GetFractionalPointSize());
}
float wxNativeFontInfo::GetFractionalPointSize() const
{
const wxString s = GetXFontComponent(wxXLFD_POINTSIZE);
@ -761,13 +746,29 @@ wxFontStyle wxNativeFontInfo::GetStyle() const
}
}
wxFontWeight wxNativeFontInfo::GetWeight() const
int wxNativeFontInfo::GetNumericWeight() const
{
const wxString s = GetXFontComponent(wxXLFD_WEIGHT).MakeLower();
if ( s.find(wxT("bold")) != wxString::npos || s == wxT("black") )
return wxFONTWEIGHT_BOLD;
else if ( s == wxT("light") )
const wxString weight = GetXFontComponent(wxXLFD_WEIGHT).MakeLower();
if (weight == wxT("thin") || weight == wxT("ultralight"))
return wxFONTWEIGHT_THIN;
else if (weight == wxT("extralight"))
return wxFONTWEIGHT_EXTRALIGHT;
else if (weight == wxT("light"))
return wxFONTWEIGHT_LIGHT;
else if (weight == wxT("book") || weight == wxT("semilight") || weight == wxT("demilight"))
return 350;
else if (weight == wxT("medium"))
return wxFONTWEIGHT_MEDIUM;
else if (weight == wxT("semibold") || weight == wxT("demibold"))
return wxFONTWEIGHT_SEMIBOLD;
else if (weight == wxT("bold"))
return wxFONTWEIGHT_BOLD;
else if (weight == wxT("extrabold"))
return wxFONTWEIGHT_EXTRABOLD;
else if (weight == wxT("heavy"))
return wxFONTWEIGHT_HEAVY;
else if (weight == wxT("extraheavy") || weight == wxT("black") || weight == wxT("ultrabold"))
return wxFONTWEIGHT_EXTRAHEAVY;
return wxFONTWEIGHT_NORMAL;
}
@ -801,7 +802,7 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
return wxFONTENCODING_MAX;
}
void wxNativeFontInfo::SetPointSize(int pointsize)
void wxNativeFontInfo::SetPointSize(float pointsize)
{
SetXFontComponent(wxXLFD_POINTSIZE, wxString::Format(wxT("%d"), pointsize));
}

View File

@ -2306,10 +2306,24 @@ wxFont wxXmlResourceHandlerImpl::GetFont(const wxString& param, wxWindow* parent
if (hasWeight)
{
wxString weight = GetParamValue(wxT("weight"));
if (weight == wxT("bold"))
iweight = wxFONTWEIGHT_BOLD;
if (weight == wxT("thin"))
iweight = wxFONTWEIGHT_THIN;
else if (weight == wxT("extralight"))
iweight = wxFONTWEIGHT_EXTRALIGHT;
else if (weight == wxT("light"))
iweight = wxFONTWEIGHT_LIGHT;
else if (weight == wxT("medium"))
iweight = wxFONTWEIGHT_MEDIUM;
else if (weight == wxT("semibold"))
iweight = wxFONTWEIGHT_SEMIBOLD;
else if (weight == wxT("bold"))
iweight = wxFONTWEIGHT_BOLD;
else if (weight == wxT("extrabold"))
iweight = wxFONTWEIGHT_EXTRABOLD;
else if (weight == wxT("heavy"))
iweight = wxFONTWEIGHT_HEAVY;
else if (weight == wxT("extraheavy"))
iweight = wxFONTWEIGHT_EXTRAHEAVY;
else if (weight != wxT("normal"))
{
ReportParamError