Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions samples/ShieldSolid.svg.nonoptimized.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ val ShieldSolidSvgNonOptimized: ImageVector
// M256 0 c4.6 0 9.2 1 13.4 2.9 L457.7 82.8 c22 9.3 38.4 31 38.3 57.2 c-.5 99.2 -41.3 280.7 -213.6 363.2 c-16.7 8 -36.1 8 -52.8 0 C57.3 420.7 16.5 239.2 16 140 c-.1 -26.2 16.3 -47.9 38.3 -57.2 L242.7 2.9 C246.8 1 251.4 0 256 0z m0 66.8 V444.8 C394 378 431.1 230.1 432 141.4 L256 66.8 l0 0z
path(
fill = SolidColor(Color(0xFF1E3050)),
fillAlpha = 1.0f,
strokeAlpha = 1.0f,
) {
// M 256 0
moveTo(x = 256.0f, y = 0.0f)
Expand Down
231 changes: 231 additions & 0 deletions samples/svg/css/flower.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ private fun SvgCircleNode.createSimpleCircle(
return ImageVectorNode.Path(
params = override ?: ImageVectorNode.Path.Params(
fill = fillBrush(wrapper.nodes),
fillAlpha = fillOpacity,
fillAlpha = fillOpacity ?: opacity,
pathFillType = fillRule,
stroke = strokeBrush(wrapper.nodes),
strokeAlpha = strokeOpacity,
strokeAlpha = strokeOpacity ?: opacity,
strokeLineCap = strokeLineCap,
strokeLineJoin = strokeLineJoin,
strokeMiterLimit = strokeMiterLimit,
Expand Down Expand Up @@ -169,7 +169,7 @@ private fun SvgCircleNode.createDashedCircle(minified: Boolean): ImageVectorNode
minified = minified,
override = ImageVectorNode.Path.Params(
fill = fillBrush(nodes),
fillAlpha = fillOpacity,
fillAlpha = fillOpacity ?: opacity,
pathFillType = fillRule,
)
),
Expand All @@ -186,7 +186,7 @@ private fun SvgCircleNode.createDashedCircle(minified: Boolean): ImageVectorNode
// as the dash is a path now, all the stroke parameters
// are used inside the fill parameters instead.
fill = strokeBrush(dashedCircleNodes),
fillAlpha = strokeOpacity,
fillAlpha = strokeOpacity ?: opacity,
),
wrapper = ImageVectorNode.NodeWrapper(
normalizedPath = buildNormalizedPath(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package dev.tonholo.s2c.domain.svg
import dev.tonholo.s2c.domain.ImageVectorNode
import dev.tonholo.s2c.domain.xml.XmlNode
import dev.tonholo.s2c.domain.xml.XmlParentNode
import dev.tonholo.s2c.parser.ImageParser.SvgParser.ComputedRule

class SvgClipPath(
parent: XmlParentNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import dev.tonholo.s2c.domain.svg.transform.SvgTransform
import dev.tonholo.s2c.domain.xml.XmlElementNode
import dev.tonholo.s2c.domain.xml.XmlNode
import dev.tonholo.s2c.domain.xml.XmlParentNode
import dev.tonholo.s2c.parser.ImageParser.SvgParser.ComputedRule

typealias SvgElementNodeConstructorFn<T> = (
parent: XmlParentNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ fun SvgEllipseNode.asNode(
return ImageVectorNode.Path(
params = ImageVectorNode.Path.Params(
fill = fillBrush(nodes),
fillAlpha = fillOpacity,
fillAlpha = fillOpacity ?: opacity,
pathFillType = fillRule,
stroke = strokeBrush(nodes),
strokeAlpha = strokeOpacity,
strokeAlpha = strokeOpacity ?: opacity,
strokeLineCap = strokeLineCap,
strokeLineJoin = strokeLineJoin,
strokeMiterLimit = strokeMiterLimit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class SvgGraphicNode<out T>(
where T : SvgNode, T : XmlChildNode {
val fill: SvgColor? by attribute<String?, _>(inherited = true) { it?.let(SvgColor::invoke) }

val opacity: Float? by attribute()
val opacity: Float? by attribute(inherited = true)

val fillOpacity: Float? by attribute(name = "fill-opacity", inherited = true)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import dev.tonholo.s2c.domain.delegate.attribute
import dev.tonholo.s2c.domain.xml.XmlNode
import dev.tonholo.s2c.domain.xml.XmlParentNode
import dev.tonholo.s2c.extensions.firstInstanceOfOrNull
import dev.tonholo.s2c.parser.ImageParser.SvgParser.ComputedRule

class SvgGroupNode(
parent: XmlParentNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import dev.tonholo.s2c.domain.xml.XmlChildNode
import dev.tonholo.s2c.domain.xml.XmlNode
import dev.tonholo.s2c.domain.xml.XmlParentNode
import dev.tonholo.s2c.domain.xml.XmlRootNode
import dev.tonholo.s2c.parser.ImageParser.SvgParser.ComputedRule
import dev.tonholo.s2c.parser.ast.css.CssSpecificity
import dev.tonholo.s2c.parser.ast.css.syntax.node.Declaration
import dev.tonholo.s2c.parser.ast.css.syntax.node.Value

/**
Expand Down Expand Up @@ -142,6 +143,16 @@ fun SvgNode.stackedTransform(parent: XmlParentNode): SvgTransform? {
return stacked?.let(::SvgTransform)
}

data class ComputedRule(
val selector: String,
val specificity: CssSpecificity,
val declarations: List<Declaration>,
) : Comparable<ComputedRule> {
override fun compareTo(other: ComputedRule): Int {
return specificity.compareTo(other.specificity)
}
}

/**
* Converts the SVG node to a list of [ImageVectorNode].
* @param masks The list of masks defined in the SVG.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import dev.tonholo.s2c.domain.compose.ComposeBrush
import dev.tonholo.s2c.domain.compose.toBrush
import dev.tonholo.s2c.domain.delegate.attribute
import dev.tonholo.s2c.domain.xml.XmlParentNode
import dev.tonholo.s2c.parser.ImageParser.SvgParser.ComputedRule

class SvgPathNode(
parent: XmlParentNode,
Expand Down Expand Up @@ -64,10 +63,10 @@ fun SvgPathNode.asNode(
val path = ImageVectorNode.Path(
params = ImageVectorNode.Path.Params(
fill = fillBrush,
fillAlpha = fillOpacity,
fillAlpha = fillOpacity ?: opacity,
pathFillType = fillRule,
stroke = strokeBrush,
strokeAlpha = strokeOpacity,
strokeAlpha = strokeOpacity ?: opacity,
strokeLineCap = strokeLineCap,
strokeLineJoin = strokeLineJoin,
strokeMiterLimit = strokeMiterLimit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ fun SvgPolygonNode.asNode(
return ImageVectorNode.Path(
params = ImageVectorNode.Path.Params(
fill = fillBrush(nodes),
fillAlpha = fillOpacity,
fillAlpha = fillOpacity ?: opacity,
pathFillType = fillRule,
stroke = strokeBrush(nodes),
strokeAlpha = strokeOpacity,
strokeAlpha = strokeOpacity ?: opacity,
strokeLineCap = strokeLineCap,
strokeLineJoin = strokeLineJoin,
strokeMiterLimit = strokeMiterLimit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ fun SvgPolylineNode.asNode(
return ImageVectorNode.Path(
params = ImageVectorNode.Path.Params(
fill = fillBrush(nodes),
fillAlpha = fillOpacity,
fillAlpha = fillOpacity ?: opacity,
pathFillType = fillRule,
stroke = strokeBrush(nodes),
strokeAlpha = strokeOpacity,
strokeAlpha = strokeOpacity ?: opacity,
strokeLineCap = strokeLineCap,
strokeLineJoin = strokeLineJoin,
strokeMiterLimit = strokeMiterLimit,
Expand Down
Loading