Added font family to wxTextAttr

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58112 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart 2009-01-15 09:20:55 +00:00
parent bf9ea28818
commit 9c4cb61167
6 changed files with 75 additions and 13 deletions

View File

@ -34,6 +34,7 @@ class wxRichTextCtrl;
////@begin control identifiers
#define SYMBOL_WXRICHTEXTINDENTSSPACINGPAGE_STYLE wxRESIZE_BORDER|wxTAB_TRAVERSAL
#define SYMBOL_WXRICHTEXTINDENTSSPACINGPAGE_TITLE _("wxRichTextFontPage")
#define SYMBOL_WXRICHTEXTINDENTSSPACINGPAGE_IDNAME ID_RICHTEXTINDENTSSPACINGPAGE
#define SYMBOL_WXRICHTEXTINDENTSSPACINGPAGE_SIZE wxSize(400, 300)
#define SYMBOL_WXRICHTEXTINDENTSSPACINGPAGE_POSITION wxDefaultPosition

View File

@ -171,9 +171,10 @@ enum wxTextAttrFlags
wxTEXT_ATTR_FONT_ITALIC = 0x00000020,
wxTEXT_ATTR_FONT_UNDERLINE = 0x00000040,
wxTEXT_ATTR_FONT_ENCODING = 0x02000000,
wxTEXT_ATTR_FONT_FAMILY = 0x04000000,
wxTEXT_ATTR_FONT = \
( wxTEXT_ATTR_FONT_FACE | wxTEXT_ATTR_FONT_SIZE | wxTEXT_ATTR_FONT_WEIGHT | \
wxTEXT_ATTR_FONT_ITALIC | wxTEXT_ATTR_FONT_UNDERLINE | wxTEXT_ATTR_FONT_ENCODING ),
wxTEXT_ATTR_FONT_ITALIC | wxTEXT_ATTR_FONT_UNDERLINE | wxTEXT_ATTR_FONT_ENCODING | wxTEXT_ATTR_FONT_FAMILY ),
wxTEXT_ATTR_ALIGNMENT = 0x00000080,
wxTEXT_ATTR_LEFT_INDENT = 0x00000100,
@ -200,7 +201,7 @@ enum wxTextAttrFlags
*/
wxTEXT_ATTR_CHARACTER = \
(wxTEXT_ATTR_FONT|wxTEXT_ATTR_FONT_ENCODING|wxTEXT_ATTR_EFFECTS| \
(wxTEXT_ATTR_FONT|wxTEXT_ATTR_EFFECTS| \
wxTEXT_ATTR_BACKGROUND_COLOUR|wxTEXT_ATTR_TEXT_COLOUR|wxTEXT_ATTR_CHARACTER_STYLE_NAME|wxTEXT_ATTR_URL),
wxTEXT_ATTR_PARAGRAPH = \
@ -311,6 +312,7 @@ public:
void SetFontFaceName(const wxString& faceName) { m_fontFaceName = faceName; m_flags |= wxTEXT_ATTR_FONT_FACE; }
void SetFontUnderlined(bool underlined) { m_fontUnderlined = underlined; m_flags |= wxTEXT_ATTR_FONT_UNDERLINE; }
void SetFontEncoding(wxFontEncoding encoding) { m_fontEncoding = encoding; m_flags |= wxTEXT_ATTR_FONT_ENCODING; }
void SetFontFamily(int family) { m_fontFamily = family; m_flags |= wxTEXT_ATTR_FONT_FAMILY; }
// Set font
void SetFont(const wxFont& font, int flags = wxTEXT_ATTR_FONT) { GetFontAttributes(font, flags); }
@ -349,6 +351,7 @@ public:
bool GetFontUnderlined() const { return m_fontUnderlined; }
const wxString& GetFontFaceName() const { return m_fontFaceName; }
wxFontEncoding GetFontEncoding() const { return m_fontEncoding; }
int GetFontFamily() const { return m_fontFamily; }
wxFont GetFont() const;
@ -383,6 +386,7 @@ public:
bool HasFontUnderlined() const { return HasFlag(wxTEXT_ATTR_FONT_UNDERLINE); }
bool HasFontFaceName() const { return HasFlag(wxTEXT_ATTR_FONT_FACE); }
bool HasFontEncoding() const { return HasFlag(wxTEXT_ATTR_FONT_ENCODING); }
bool HasFontFamily() const { return HasFlag(wxTEXT_ATTR_FONT_FAMILY); }
bool HasFont() const { return HasFlag(wxTEXT_ATTR_FONT); }
bool HasParagraphSpacingAfter() const { return HasFlag(wxTEXT_ATTR_PARA_SPACING_AFTER); }
@ -487,6 +491,7 @@ private:
int m_fontSize;
int m_fontStyle;
int m_fontWeight;
int m_fontFamily;
bool m_fontUnderlined;
wxString m_fontFaceName;

View File

@ -38,9 +38,10 @@ enum wxTextAttrFlags
wxTEXT_ATTR_FONT_ITALIC = 0x00000020,
wxTEXT_ATTR_FONT_UNDERLINE = 0x00000040,
wxTEXT_ATTR_FONT_ENCODING = 0x02000000,
wxTEXT_ATTR_FONT_FAMILY = 0x04000000,
wxTEXT_ATTR_FONT = \
( wxTEXT_ATTR_FONT_FACE | wxTEXT_ATTR_FONT_SIZE | wxTEXT_ATTR_FONT_WEIGHT | \
wxTEXT_ATTR_FONT_ITALIC | wxTEXT_ATTR_FONT_UNDERLINE | wxTEXT_ATTR_FONT_ENCODING ),
wxTEXT_ATTR_FONT_ITALIC | wxTEXT_ATTR_FONT_UNDERLINE | wxTEXT_ATTR_FONT_ENCODING | wxTEXT_ATTR_FONT_FAMILY ),
wxTEXT_ATTR_ALIGNMENT = 0x00000080,
wxTEXT_ATTR_LEFT_INDENT = 0x00000100,
@ -67,7 +68,7 @@ enum wxTextAttrFlags
*/
wxTEXT_ATTR_CHARACTER = \
(wxTEXT_ATTR_FONT|wxTEXT_ATTR_FONT_ENCODING|wxTEXT_ATTR_EFFECTS| \
(wxTEXT_ATTR_FONT|wxTEXT_ATTR_EFFECTS| \
wxTEXT_ATTR_BACKGROUND_COLOUR|wxTEXT_ATTR_TEXT_COLOUR|wxTEXT_ATTR_CHARACTER_STYLE_NAME|wxTEXT_ATTR_URL),
wxTEXT_ATTR_PARAGRAPH = \
@ -295,6 +296,11 @@ public:
*/
const wxString& GetFontFaceName() const;
/**
Returns the font family.
*/
int GetFontFamily() const;
/**
Returns the font size in points.
*/
@ -451,6 +457,11 @@ public:
*/
bool HasFontFaceName() const;
/**
Returns @true if the attribute object specifies a font family.
*/
bool HasFontFamily() const;
/**
Returns @true if the attribute object specifies italic style.
*/
@ -641,10 +652,15 @@ public:
void SetFontEncoding(wxFontEncoding encoding);
/**
Sets the paragraph alignment.
Sets the font face name.
*/
void SetFontFaceName(const wxString& faceName);
/**
Sets the font family.
*/
void SetFontFamily(int family);
/**
Sets the font size in points.
*/

View File

@ -89,6 +89,7 @@ void wxTextAttr::Init()
m_fontWeight = wxNORMAL;
m_fontUnderlined = false;
m_fontEncoding = wxFONTENCODING_DEFAULT;
m_fontFamily = wxFONTFAMILY_DEFAULT;
m_paragraphSpacingAfter = 0;
m_paragraphSpacingBefore = 0;
@ -118,6 +119,7 @@ void wxTextAttr::Copy(const wxTextAttr& attr)
m_fontUnderlined = attr.m_fontUnderlined;
m_fontFaceName = attr.m_fontFaceName;
m_fontEncoding = attr.m_fontEncoding;
m_fontFamily = attr.m_fontFamily;
m_textEffects = attr.m_textEffects;
m_textEffectFlags = attr.m_textEffectFlags;
@ -181,6 +183,7 @@ bool wxTextAttr::operator== (const wxTextAttr& attr) const
GetFontUnderlined() == attr.GetFontUnderlined() &&
GetFontFaceName() == attr.GetFontFaceName() &&
GetFontEncoding() == attr.GetFontEncoding() &&
GetFontFamily() == attr.GetFontFamily() &&
GetURL() == attr.GetURL();
}
@ -218,6 +221,10 @@ bool wxTextAttr::EqPartial(const wxTextAttr& attr, int flags) const
GetFontEncoding() != attr.GetFontEncoding())
return false;
if ((flags & wxTEXT_ATTR_FONT_FAMILY) &&
GetFontFamily() != attr.GetFontFamily())
return false;
if ((flags & wxTEXT_ATTR_URL) && GetURL() != attr.GetURL())
return false;
@ -326,7 +333,11 @@ wxFont wxTextAttr::GetFont() const
if (HasFontEncoding())
encoding = GetFontEncoding();
wxFont font(fontSize, wxDEFAULT, fontStyle, fontWeight, underlined, fontFaceName, encoding);
int fontFamily = wxFONTFAMILY_DEFAULT;
if (HasFontFamily())
fontFamily = GetFontFamily();
wxFont font(fontSize, fontFamily, fontStyle, fontWeight, underlined, fontFaceName, encoding);
#ifdef __WXMAC__
font.SetNoAntiAliasing(true);
#endif
@ -357,6 +368,9 @@ bool wxTextAttr::GetFontAttributes(const wxFont& font, int flags)
if (flags & wxTEXT_ATTR_FONT_ENCODING)
m_fontEncoding = font.GetEncoding();
if (flags & wxTEXT_ATTR_FONT_FAMILY)
m_fontFamily = font.GetFamily();
m_flags |= flags;
return true;
@ -414,6 +428,12 @@ bool wxTextAttr::Apply(const wxTextAttr& style, const wxTextAttr* compareWith)
destStyle.SetFontEncoding(style.GetFontEncoding());
}
if (style.HasFontFamily())
{
if (!(compareWith && compareWith->HasFontFamily() && compareWith->GetFontFamily() == style.GetFontFamily()))
destStyle.SetFontFamily(style.GetFontFamily());
}
if (style.GetTextColour().Ok() && style.HasTextColour())
{
if (!(compareWith && compareWith->HasTextColour() && compareWith->GetTextColour() == style.GetTextColour()))

View File

@ -66,6 +66,7 @@ inline void wxCheckSetFont(wxDC& dc, const wxFont& font)
font1.GetStyle() == font.GetStyle() &&
font1.GetWeight() == font.GetWeight() &&
font1.GetUnderlined() == font.GetUnderlined() &&
font1.GetFamily() == font.GetFamily() &&
font1.GetFaceName() == font.GetFaceName())
return;
}
@ -1988,6 +1989,23 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const
}
}
if (style.HasFontFamily() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_FONT_FAMILY))
{
if (currentStyle.HasFontFamily())
{
if (currentStyle.GetFontFamily() != style.GetFontFamily())
{
// Clash of style - mark as such
multipleStyleAttributes |= wxTEXT_ATTR_FONT_FAMILY;
currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_FONT_FAMILY);
}
}
else
{
currentStyle.SetFontFamily(style.GetFontFamily());
}
}
if (style.HasFontWeight() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_FONT_WEIGHT))
{
if (currentStyle.HasFontWeight())

View File

@ -971,8 +971,8 @@ wxString wxRichTextXMLHandler::CreateStyle(const wxTextAttr& attr, bool isPara)
if (attr.HasFontSize())
str << wxT(" fontsize=\"") << attr.GetFontSize() << wxT("\"");
//if (attr.HasFontFamily())
// str << wxT(" fontfamily=\"") << attr.GetFont().GetFamily() << wxT("\"");
if (attr.HasFontFamily())
str << wxT(" fontfamily=\"") << attr.GetFont().GetFamily() << wxT("\"");
if (attr.HasFontItalic())
str << wxT(" fontstyle=\"") << attr.GetFontStyle() << wxT("\"");
@ -1131,7 +1131,7 @@ bool wxRichTextXMLHandler::GetStyle(wxTextAttr& attr, wxXmlNode* node, bool isPa
{
wxString fontFacename;
int fontSize = 12;
// int fontFamily = wxDEFAULT;
int fontFamily = wxFONTFAMILY_DEFAULT;
int fontWeight = wxNORMAL;
int fontStyle = wxNORMAL;
bool fontUnderlined = false;
@ -1146,11 +1146,13 @@ bool wxRichTextXMLHandler::GetStyle(wxTextAttr& attr, wxXmlNode* node, bool isPa
wxRichTextFixFaceName(fontFacename);
}
wxString value;
//value = node->GetAttribute(wxT("fontfamily"), wxEmptyString);
//if (!value.empty())
// fontFamily = wxAtoi(value);
value = node->GetAttribute(wxT("fontfamily"), wxEmptyString);
if (!value.empty())
{
fontFamily = wxAtoi(value);
attr.SetFontFamily(fontFamily);
}
value = node->GetAttribute(wxT("fontstyle"), wxEmptyString);
if (!value.empty())