Support fractional font sizes and numeric weights in XRC

Change the code to handle them, the XRC sample to test them, the schema
to accept them and the documentation to describe them.
This commit is contained in:
Vadim Zeitlin
2018-09-15 13:30:45 +02:00
parent aedf89b098
commit ca164bb4ca
4 changed files with 56 additions and 22 deletions

View File

@@ -403,14 +403,20 @@ and can be one of the following "sub-properties":
@beginTable
@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
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,
One of "normal", "italic" or "slant" (default: normal).}
@row3col{weight, enum,
One of "normal", "bold" or "light" (default: normal).}
@row3col{weight, enum or integer,
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,
One of "default", "roman", "script", "decorative", "swiss", "modern" or "teletype"
(default: default).}

View File

@@ -454,11 +454,11 @@ t_bitmap = t_url?,
)?
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 weight {_, ("normal" | "thin" | "extralight" | "light" |
"medium" | "semibold" | "bold" | "extrabold" |
"heavy" | "extraheavy") }* &
"heavy" | "extraheavy" | t_integer) }* &
[xrc:p="o"] element family {_, ("roman" | "script" | "decorative" | "swiss" |
"modern" | "teletype") }* &
[xrc:p="o"] element underlined {_, t_bool }* &

View File

@@ -347,7 +347,6 @@
<object class="sizeritem">
<flag>wxGROW|wxALL</flag>
<border>5</border>
<option>1</option>
<object class="wxCollapsiblePane" name="controls_collpane">
<label>Details:</label>
<collapsed>0</collapsed>
@@ -1096,6 +1095,23 @@ lay them out using wxSizers, absolute positioning, everything you like!
<label>It was a dark and stormy night.</label>
</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 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>
</font>
</object>
</object>
<object class="sizeritem">
<flag>wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL|wxALL</flag>
<border>5</border>
@@ -1127,7 +1143,7 @@ lay them out using wxSizers, absolute positioning, everything you like!
<label>It was a dark and stormy night.</label>
<font>
<inherit>1</inherit>
<weight>bold</weight>
<weight>700</weight> <!-- same as "bold" -->
</font>
</object>
</object>
@@ -1494,7 +1510,6 @@ lay them out using wxSizers, absolute positioning, everything you like!
</object>
<object class="sizeritem">
<flag>wxGROW|wxALL</flag>
<option>1</option>
<border>5</border>
<object class="wxColourPickerCtrl" name="controls_colourpicker">
<value>#00ff00</value>
@@ -1510,7 +1525,6 @@ lay them out using wxSizers, absolute positioning, everything you like!
</object>
<object class="sizeritem">
<flag>wxGROW|wxALL</flag>
<option>1</option>
<border>5</border>
<object class="wxFilePickerCtrl" name="controls_filepicker">
<message>Here goes a message</message>
@@ -1528,7 +1542,6 @@ lay them out using wxSizers, absolute positioning, everything you like!
</object>
<object class="sizeritem">
<flag>wxGROW|wxALL</flag>
<option>1</option>
<border>5</border>
<object class="wxDirPickerCtrl" name="controls_dirpicker">
<value/>
@@ -1545,7 +1558,6 @@ lay them out using wxSizers, absolute positioning, everything you like!
</object>
<object class="sizeritem">
<flag>wxGROW|wxALL</flag>
<option>1</option>
<border>5</border>
<object class="wxFontPickerCtrl" name="controls_fontpicker">
<style>wxFNTP_USEFONT_FOR_LABEL</style>

View File

@@ -2275,10 +2275,10 @@ wxFont wxXmlResourceHandlerImpl::GetFont(const wxString& param, wxWindow* parent
// font attributes:
// size
int isize = -1;
float pointSize = -1.0f;
bool hasSize = HasParam(wxT("size"));
if (hasSize)
isize = GetLong(wxT("size"), -1);
pointSize = GetFloat(wxT("size"), -1.0f);
// style
wxFontStyle istyle = wxFONTSTYLE_NORMAL;
@@ -2301,12 +2301,23 @@ wxFont wxXmlResourceHandlerImpl::GetFont(const wxString& param, wxWindow* parent
}
// weight
wxFontWeight iweight = wxFONTWEIGHT_NORMAL;
long iweight = wxFONTWEIGHT_NORMAL;
bool hasWeight = HasParam(wxT("weight"));
if (hasWeight)
{
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;
else if (weight == wxT("extralight"))
iweight = wxFONTWEIGHT_EXTRALIGHT;
@@ -2433,9 +2444,9 @@ wxFont wxXmlResourceHandlerImpl::GetFont(const wxString& param, wxWindow* parent
if (font.IsOk())
{
if (hasSize && isize != -1)
if (pointSize > 0)
{
font.SetPointSize(isize);
font.SetFractionalPointSize(pointSize);
if (HasParam(wxT("relativesize")))
{
ReportParamError
@@ -2452,7 +2463,7 @@ wxFont wxXmlResourceHandlerImpl::GetFont(const wxString& param, wxWindow* parent
if (hasStyle)
font.SetStyle(istyle);
if (hasWeight)
font.SetWeight(iweight);
font.SetNumericWeight(iweight);
if (hasUnderlined)
font.SetUnderlined(underlined);
if (hasFamily)
@@ -2464,9 +2475,14 @@ wxFont wxXmlResourceHandlerImpl::GetFont(const wxString& param, wxWindow* parent
}
else // not based on system font
{
font = wxFont(isize == -1 ? wxNORMAL_FONT->GetPointSize() : isize,
ifamily, istyle, iweight,
underlined, facename, enc);
font = wxFontInfo(pointSize)
.FaceName(facename)
.Family(ifamily)
.Style(istyle)
.Weight(iweight)
.Underlined(underlined)
.Encoding(enc)
;
}
m_handler->m_node = oldnode;