// Convenience functions:
bool GetParamAsColour(const wxString& par, wxColour *clr) const;
bool GetParamAsInt(const wxString& par, int *clr) const;
+ bool GetParamAsIntOrPercent(const wxString& param,
+ int* value, bool& isPercent) const;
// Scans param like scanf() functions family does.
// Example : ScanParam("COLOR", "\"#%X\"", &clr);
return true;
}
+bool
+wxHtmlTag::GetParamAsIntOrPercent(const wxString& par,
+ int* value,
+ bool& isPercent) const
+{
+ const wxString param = GetParam(par);
+ if ( param.empty() )
+ return false;
+
+ wxString num;
+ if ( param.EndsWith("%", &num) )
+ {
+ isPercent = true;
+ }
+ else
+ {
+ isPercent = false;
+ num = param;
+ }
+
+ long lValue;
+ if ( !num.ToLong(&lValue) )
+ return false;
+
+ if ( lValue > INT_MAX || lValue < INT_MIN )
+ return false;
+
+ *value = static_cast<int>(lValue);
+
+ return true;
+}
+
wxString wxHtmlTag::GetAllParams() const
{
// VS: this function is for backward compatibility only,
if (tag.HasParam(wxT("WIDTH")))
{
- wxString param = tag.GetParam(wxT("WIDTH"));
- wxSscanf(param.c_str(), wxT("%i"), &w);
- if (param.EndsWith(wxT("%"))) {
- if (w < 0)
- w = 0;
- else if (w > 100)
- w = 100;
- wpercent = true;
+ if (tag.GetParamAsIntOrPercent(wxT("WIDTH"), &w, wpercent))
+ {
+ if (wpercent)
+ {
+ if (w < 0)
+ w = 0;
+ else if (w > 100)
+ w = 100;
+ }
}
-
}
if (tag.HasParam(wxT("HEIGHT")))
{
if (tag.HasParam(wxT("WIDTH")))
{
- wxString wd = tag.GetParam(wxT("WIDTH"));
-
- if (!wd.empty() && wd[wd.length()-1] == wxT('%'))
- {
- int width = 0;
- wxSscanf(wd.c_str(), wxT("%i%%"), &width);
- m_Table->SetWidthFloat(width, wxHTML_UNITS_PERCENT);
- }
- else
+ int width = 0;
+ bool wpercent = false;
+ if (tag.GetParamAsIntOrPercent(wxT("WIDTH"), &width, wpercent))
{
- int width = 0;
- wxSscanf(wd.c_str(), wxT("%i"), &width);
- m_Table->SetWidthFloat((int)(m_WParser->GetPixelScale() * width), wxHTML_UNITS_PIXELS);
+ if (wpercent)
+ {
+ m_Table->SetWidthFloat(width, wxHTML_UNITS_PERCENT);
+ }
+ else
+ {
+ m_Table->SetWidthFloat((int)(m_WParser->GetPixelScale() * width), wxHTML_UNITS_PIXELS);
+ }
}
}
else