Donner 0.5.1
Embeddable browser-grade SVG2 engine
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. 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  SVGParserContext
 Stores the current state of SVGParser during parsing. More...
class  ListParser
 Parses a list of values conforming to the SVG comma-or-space list syntax. 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...
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  SVGParser
 Parse an SVG XML document. More...
class  TransformParser
 Parse an SVG transform attribute, such as translate(100 100), using the SVG syntax which does not support units on numbers. More...
class  ViewBoxParser
 Parse an SVG viewBox attribute, such as "0 0 100 100". 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...
struct  PropertyParseFnParams
 Parameters for a property parse function. More...

Concepts

concept  ListParserItemCallback
 Concept requiring a type to be invocable with a std::string_view and return void.

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

ParseResult< double > ParseAngle (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.
ParseResult< bool > ParsePresentationAttribute (ElementType type, EntityHandle handle, std::string_view name, const PropertyParseFnParams &params)
 Parse a presentation attribute, which can contain a CSS value, for a specific ElementType.
template<typename T, PropertyCascade kCascade, typename ParseCallbackFn>
std::optional< ParseDiagnosticParse (const PropertyParseFnParams &params, ParseCallbackFn callbackFn, Property< T, kCascade > *destination)
 Parse a property value into a Property.
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< double > 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.

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()

template<typename T, PropertyCascade kCascade, typename ParseCallbackFn>
std::optional< ParseDiagnostic > 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>

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 ParseDiagnostic 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()

ParseResult< bool > donner::svg::parser::ParsePresentationAttribute ( ElementType type,
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
Parameters
typeType of element to parse presentation attributes for.
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 ParseDiagnostic if parsing failed.

◆ 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.