SvgDocumentService
Stateless operations on {@see SvgDocument} instances: dimension resolution, serialization and crop-scaling.
The document to operate on is always passed in as the first argument, no instance state is kept. Obtain documents via SvgDocumentFactory.
not part of TYPO3 Core API.
Attributes
- #[Autoconfigure]
- $public: true
Table of Contents
Methods
- cropScale() : SvgDocument
- Wrap the source SVG in an outer `<svg>` that carries the crop viewBox and target dimensions. The passed document is not mutated, a new {@see SvgDocument} is returned.
- getDimensions() : ImageDimension
- Resolve pixel dimensions of the SVG.
- toInlineMarkup() : string
- Serialize the document as inline HTML5-ready markup.
- toXml() : string
- Serialize the document as plain XML markup of its root element, without an `<?xml ?>` prolog.
Methods
cropScale()
Wrap the source SVG in an outer `<svg>` that carries the crop viewBox and target dimensions. The passed document is not mutated, a new {@see SvgDocument} is returned.
public
cropScale(SvgDocument $document, Area $cropArea, ImageDimension $targetDimension) : SvgDocument
Parameters
- $document : SvgDocument
- $cropArea : Area
- $targetDimension : ImageDimension
Return values
SvgDocumentgetDimensions()
Resolve pixel dimensions of the SVG.
public
getDimensions(SvgDocument $document) : ImageDimension
Preference order:
viewBoxattribute (width = index 2, height = index 3)- numeric
width/heightattributes (override viewBox values) - non-numeric
width/height(e.g. "100mm", "50%") only when no viewBox-derived value is present, stripped of their unit - 64x64 fallback when nothing usable is found
Parameters
- $document : SvgDocument
Return values
ImageDimensiontoInlineMarkup()
Serialize the document as inline HTML5-ready markup.
public
toInlineMarkup(SvgDocument $document) : string
Emits only the root <svg> element (no <?xml ?> prolog) and
applies the clean-ups needed when inlining SVG into an HTML
document:
- drops
xmlns="http://www.w3.org/2000/svg"(HTML5 auto-places<svg>in the SVG namespace), - drops the legacy
versionattribute, - synthesizes a
viewBoxfromwidth/heightwhen missing so the SVG scales with CSS instead of rendering at intrinsic pixel size.
Operates on a detached clone; the passed document is not mutated.
Parameters
- $document : SvgDocument
Return values
stringtoXml()
Serialize the document as plain XML markup of its root element, without an `<?xml ?>` prolog.
public
toXml(SvgDocument $document) : string
Parameters
- $document : SvgDocument