32 const wxCharBuffer utf8 = aSvg.ToUTF8();
33 wxMemoryInputStream input( utf8.data(), utf8.length() );
36 if( !doc.Load( input ) )
37 return tl::make_unexpected( wxString( wxS(
"Failed to load SVG XML" ) ) );
39 if( doc.GetRoot()->GetName() != wxT(
"svg" ) )
40 return tl::make_unexpected( wxString( wxS(
"Root element is not <svg>" ) ) );
48 if( aRoot.GetName() != wxT(
"svg" ) )
49 return tl::make_unexpected( wxS(
"Root element is not <svg>" ) );
53 if( !aRoot.GetAttribute( wxT(
"viewBox" ), &viewBox ) )
54 return tl::make_unexpected( wxS(
"Missing viewBox attribute" ) );
57 const std::string values = viewBox.ToStdString();
59 double*
const valuesToParse[] = { &parsed.m_X, &parsed.m_Y, &parsed.m_Width, &parsed.m_Height };
62 for(
double* value : valuesToParse )
64 while( pos < values.size() && ( values[pos] ==
' ' || values[pos] ==
'\t' ) )
67 if( pos >= values.size() )
68 return tl::make_unexpected( wxS(
"viewBox must contain four numbers" ) );
70 const auto [ptr, ec] = fast_float::from_chars( values.data() + pos, values.data() + values.size(), *value );
72 if( ec != std::errc() )
73 return tl::make_unexpected( wxS(
"Invalid viewBox number" ) );
75 pos = ptr - values.data();
78 while( pos < values.size() && ( values[pos] ==
' ' || values[pos] ==
'\t' ) )
81 if( pos != values.size() )
82 return tl::make_unexpected( wxS(
"viewBox must contain exactly four numbers" ) );
tl::expected< SVG_VIEWBOX, wxString > ParseViewBox(const wxXmlNode &aRoot)
Parse the four numbers of the SVG viewBox attribute (min-x, min-y, width, height).