Donner
C++20 SVG rendering library
Loading...
Searching...
No Matches
donner::svg::parser Namespace Reference

Parsers for the SVG XML format, SVGParser, as well as individual parsers for SVG components, such as PathParser and TransformParser. More...

Classes

class  AttributeParser
 Parses XML attributes and sets applies them to SVGElements. More...
 
class  CssTransformParser
 Parse a CSS "transform" property, see https://www.w3.org/TR/css-transforms-1/#transform-property. More...
 
class  Number2dParser
 Parser for floating point numbers in SVG or CSS, corresponding to the CSS3 <number-token> definition from https://www.w3.org/TR/css-syntax-3/#number-token-diagram. More...
 
struct  ParserOrigin
 Contains the start location within a string where a subparser was invoked, used for remapping errors back to their original text. More...
 
class  PathParser
 Parse an SVG path "d"-string, see Path data syntax. More...
 
class  PointsListParser
 Parse a SVG "points" attribute, used to specify line paths for "<polyline>" and "<polygon>" elements. More...
 
class  PreserveAspectRatioParser
 Parser for SVG preserveAspectRatio attribute. More...
 
class  PreserveAspectRatioParserImpl
 
struct  PropertyParseFnParams
 Parameters for a property parse function. More...
 
class  SVGParser
 Parse an SVG XML document. More...
 
class  SVGParserContext
 Stores the current state of SVGParser during parsing. More...
 
class  SVGParserImpl
 
class  TransformParser
 Parse an SVG transform attribute, such as translate(100 100), using the SVG syntax which does not support units on numbers. More...
 
struct  UnparsedProperty
 Represents an unparsed property, which is a CSS property that is element-specific and needs to be matched with the actual element before it can be parsed and applied. More...
 
class  ViewboxParser
 Parse an SVG viewBox attribute, such as "0 0 100 100". More...
 

Enumerations

enum class  AngleParseOptions {
  None ,
  AllowBareZero ,
  AllowNumbersInDegrees
}
 Options for donner::svg::parser::ParseAngle, which controls whether bare zero is allowed. More...
 
enum class  PropertyParseBehavior {
  Default ,
  AllowUserUnits
}
 Set the parse behavior for numbers. More...
 

Functions

template<>
ParseResult< boolParsePresentationAttribute< ElementType::Filter > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::FeGaussianBlur > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::SVG > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::Use > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::Image > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::ClipPath > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::LinearGradient > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::Marker > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::Mask > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::Pattern > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::RadialGradient > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::Stop > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::Circle > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::Ellipse > (EntityHandle handle, std::string_view name, const parser::PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::Rect > (EntityHandle handle, std::string_view name, const parser::PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::Line > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::Path > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::Polygon > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::Polyline > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::Style > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
ParseResult< doubleParseAngle (const css::ComponentValue &component, AngleParseOptions options=AngleParseOptions::None)
 Parse an angle value within a CSS property, such as '30deg' or '2rad'.
 
ParseResult< LengthdParseLengthPercentage (const css::ComponentValue &component, bool allowUserUnits)
 Parse a <length-percentage> value.
 
ParseResult< LengthdParseLengthPercentage (std::span< const css::ComponentValue > components, bool allowUserUnits)
 Parse a <length-percentage> value.
 
int LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
 Fuzzer entry point, see https://llvm.org/docs/LibFuzzer.html.
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::Defs > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::G > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
template<>
ParseResult< boolParsePresentationAttribute< ElementType::Unknown > (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 
template<ElementType Type>
ParseResult< boolParsePresentationAttribute (EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 Parse a presentation attribute,which can contain a CSS value, for a specific ElementType.
 
ParseResult< boolParseSpecialAttributes (PropertyParseFnParams &params, std::string_view name, std::optional< ElementType > type=std::nullopt, EntityHandle handle=EntityHandle())
 Parse special property attributes, currently used for transform.
 
std::optional< RcStringTryGetSingleIdent (std::span< const css::ComponentValue > components)
 If the components contain only a single ident, returns an RcString for that ident's contents.
 
ParseResult< std::optional< Lengthd > > ParseLengthPercentageOrAuto (std::span< const css::ComponentValue > components, bool allowUserUnits)
 Parse a <length-percentage>, which may optionally be set to "auto", in which case this returns std::nullopt.
 
ParseResult< doubleParseAlphaValue (std::span< const css::ComponentValue > components)
 Parse an <alpha-value>, defined by CSS Color: https://www.w3.org/TR/css-color/#typedef-alpha-value.
 
template<typename T , PropertyCascade kCascade, typename ParseCallbackFn >
std::optional< ParseErrorParse (const PropertyParseFnParams &params, ParseCallbackFn callbackFn, Property< T, kCascade > *destination)
 Parse a property value into a Property.
 

Detailed Description

Parsers for the SVG XML format, SVGParser, as well as individual parsers for SVG components, such as PathParser and TransformParser.


Class Documentation

◆ donner::svg::parser::UnparsedProperty

struct donner::svg::parser::UnparsedProperty

Represents an unparsed property, which is a CSS property that is element-specific and needs to be matched with the actual element before it can be parsed and applied.

For example, the transform property.

Collaboration diagram for donner::svg::parser::UnparsedProperty:
[legend]
Class Members
Declaration declaration CSS declaration, e.g. "transform: translate(10px, 20px);". Contains the name and list of css::ComponentValue for the value.
Specificity specificity Specificity of the declaration.

Enumeration Type Documentation

◆ AngleParseOptions

Options for donner::svg::parser::ParseAngle, which controls whether bare zero is allowed.

Enumerator
None 

Angles require a dimension suffix, such as '30deg' or '2rad'.

AllowBareZero 

Allow '0' to be parsed as an angle.

AllowNumbersInDegrees 

Allow raw numbers to be parsed as an angle in degrees.

◆ PropertyParseBehavior

Set the parse behavior for numbers.

For properties set on the XML element, units can be omitted and will be considered as "user units", which are equivalent to pixels. For properties set on the CSS style attribute, units must be specified.

When set to AllowUserUnits, the parser will accept numbers without units, such as 15.

Enumerator
Default 

Require units for numbers, such as 15px, with the exception of 0 which may be unitless.

AllowUserUnits 

Allow numbers without units, e.g. 15.

Function Documentation

◆ Parse()

std::optional< ParseError > donner::svg::parser::Parse ( const PropertyParseFnParams & params,
ParseCallbackFn callbackFn,
Property< T, kCascade > * destination )

Parse a property value into a Property.

Template Parameters
TThe type of the property value.
Parameters
paramsParameters for the property parse function.
callbackFnFunction to parse the property value.
destinationThe property to set the value on.

◆ ParseAlphaValue()

ParseResult< double > donner::svg::parser::ParseAlphaValue ( std::span< const css::ComponentValue > components)

Parse an <alpha-value>, defined by CSS Color: https://www.w3.org/TR/css-color/#typedef-alpha-value.

<alpha-value> = <number> | <percentage>
A parser result, which may contain a result of type T, or an error, or both.
Definition ParseResult.h:17

Where if a number is specified, it's represented with 1.0 being 100%.

Parameters
components
Returns
ParseResult<double> Parsed alpha value as a double, in the range of [0, 1].

◆ ParseAngle()

ParseResult< double > donner::svg::parser::ParseAngle ( const css::ComponentValue & component,
AngleParseOptions options = AngleParseOptions::None )

Parse an angle value within a CSS property, such as '30deg' or '2rad'.

Parameters
componentThe CSS component value to parse.
optionsOptions for parsing.
Returns
The angle in radians, or a donner::base::parser::ParseError if parsing failed.

◆ ParseLengthPercentage() [1/2]

ParseResult< Lengthd > donner::svg::parser::ParseLengthPercentage ( const css::ComponentValue & component,
bool allowUserUnits )

Parse a <length-percentage> value.

Parameters
componentA single component value.
allowUserUnitsWhether to allow unitless values, if this is a parse in the context of XML attributes.
Returns
Return a Length or a parse error.

◆ ParseLengthPercentage() [2/2]

ParseResult< Lengthd > donner::svg::parser::ParseLengthPercentage ( std::span< const css::ComponentValue > components,
bool allowUserUnits )

Parse a <length-percentage> value.

Parameters
componentsComponent values, which should already be trimmed.
allowUserUnitsWhether to allow unitless values, if this is a parse in the context of XML attributes.
Returns
Return a Length or a parse error.

◆ ParseLengthPercentageOrAuto()

ParseResult< std::optional< Lengthd > > donner::svg::parser::ParseLengthPercentageOrAuto ( std::span< const css::ComponentValue > components,
bool allowUserUnits )

Parse a <length-percentage>, which may optionally be set to "auto", in which case this returns std::nullopt.

Parameters
componentsComponent values, which should already be trimmed.
allowUserUnitsWhether to allow unitless values, if this is a parse in the context of XML attributes.
Returns
Return an optional, which is set to std::nullopt if the value is "auto", or a Length, or a parse error.

◆ ParsePresentationAttribute()

template<ElementType Type>
ParseResult< bool > donner::svg::parser::ParsePresentationAttribute ( EntityHandle handle,
std::string_view name,
const PropertyParseFnParams & params )

Parse a presentation attribute,which can contain a CSS value, for a specific ElementType.

See also
https://www.w3.org/TR/SVG2/styling.html#PresentationAttributes
Template Parameters
TypeType of element to parse presentation attributes for.
Parameters
handleEntity handle which determines which attributes are supported, and where to save the parsed value.
nameName of the attribute.
paramsParameters for parsing the attribute, which includes the value to parse, specificity, and parser options.
Returns
true if the element supports this attribute and it was parsed successfully, or a donner::base::parser::ParseError if parsing failed.

◆ ParseSpecialAttributes()

ParseResult< bool > donner::svg::parser::ParseSpecialAttributes ( PropertyParseFnParams & params,
std::string_view name,
std::optional< ElementType > type = std::nullopt,
EntityHandle handle = EntityHandle() )

Parse special property attributes, currently used for transform.

Parameters
paramsParameters for the property parse function.
nameName of the attribute to parse.
typeType of the element, if known.
handleEntity handle of the element, if known.

◆ TryGetSingleIdent()

std::optional< RcString > donner::svg::parser::TryGetSingleIdent ( std::span< const css::ComponentValue > components)

If the components contain only a single ident, returns an RcString for that ident's contents.

Parameters
componentsComponent values, which should already be trimmed.
Returns
A string if the components contain a single ident, otherwise std::nullopt.