Skip to content

Conversation

@faide
Copy link
Contributor

@faide faide commented Dec 31, 2025

Also add support for decimal alpha values in rgba()

Added tests for each feature too...

@faide
Copy link
Contributor Author

faide commented Dec 31, 2025

Pattern parsing is not complete but works for my use case, I'll look into a more complete version but will not be confident it works because I have not use case to validate against. BUT first let me know if you are interested in this ...

svg.go Outdated
return Black
}
col.A = svg.parseColorComponent(comps[3])
// Alpha can be decimal (0.0-1.0) or integer (0-255)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is true, it should only support decimal values between 0.0 (full transparent) and 1.0 (full opaque). Maybe this was wrong before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I did not realize the previous code was just wrong and wanted to maintain compatibility by falling back to it... my bad, will fix!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amended my commit to only support decimal and not fallback to old code!

}

f := height / viewbox[3]
f := 1.0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the default value for the viewbox height? Not sure about this...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When no viewBox, content uses marker coordinate space directly, which equates to scale 1.0

Would you like me to add a comment to explain the reasoning ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed an amended commit with the comment

svg.go Outdated
width = 8.0
}
if height == 0.0 {
height = 8.0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these the defaults?

Copy link
Contributor Author

@faide faide Jan 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right in svg specs pattern width/height default to 0, and a pattern with 0 dimensions simply doesn't render...

Should I update my code to return early if dimensions are 0 ? something like:

  if width == 0.0 || height == 0.0 {
      return // Pattern with zero dimensions does not render
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed an amended commit with this solution tell me we you think...

faide added 3 commits January 2, 2026 19:03
Prevent division by zero when parsing <marker> elements that don't
specify a viewBox. Default scale factor to 1.0 when viewBox height
is zero.
- Parse <pattern> elements containing line hatches
- Convert to HatchPattern with angle from patternTransform
- Add currentColor to SVG state for dynamic color resolution
- Parse CSS color property in style attributes
- Resolve currentColor at pattern application time
@tdewolff tdewolff merged commit 69e1540 into tdewolff:master Jan 9, 2026
@tdewolff
Copy link
Owner

tdewolff commented Jan 9, 2026

Thanks for the effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants