Skip to content

Commit

Permalink
Merge Handzo/svg
Browse files Browse the repository at this point in the history
path opacity
consume comma
  • Loading branch information
Handzo authored and rustyoz committed Apr 15, 2024
1 parent ef36291 commit 5415eb8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions drawinginstruction.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type DrawingInstruction struct {
CurvePoints *CurvePoints
Radius *float64
StrokeWidth *float64
Opacity *float64
Fill *string
Stroke *string
StrokeLineCap *string
Expand Down
10 changes: 9 additions & 1 deletion path.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Path struct {
properties map[string]string
StrokeWidth float64 `xml:"stroke-width,attr"`
Fill *string `xml:"fill,attr"`
Opacity *float64 `xml:"opacity,attr"`
Stroke *string `xml:"stroke,attr"`
StrokeLineCap *string `xml:"stroke-linecap,attr"`
StrokeLineJoin *string `xml:"stroke-linejoin,attr"`
Expand Down Expand Up @@ -151,6 +152,7 @@ func (p *Path) ParseDrawingInstructions() (chan *DrawingInstruction, chan error)
return
case i.Type == gl.ItemEOS:
scaledStrokeWidth := p.StrokeWidth * pdp.p.group.Owner.scale
opacity := p.Opacity

pdp.p.instructions <- &DrawingInstruction{
Kind: PaintInstruction,
Expand All @@ -159,6 +161,7 @@ func (p *Path) ParseDrawingInstructions() (chan *DrawingInstruction, chan error)
StrokeLineCap: p.StrokeLineCap,
StrokeLineJoin: p.StrokeLineJoin,
Fill: p.Fill,
Opacity: opacity,
}
return
case i.Type == gl.ItemLetter:
Expand Down Expand Up @@ -692,6 +695,7 @@ func (pdp *pathDescriptionParser) parseCurveToRelDI() error {
for pdp.lex.PeekItem().Type == gl.ItemNumber {
t, err := parseTuple(pdp.lex)
if err != nil {
panic(err)
return fmt.Errorf("Error Passing CurveToRel\n%s", err)
}
tuples = append(tuples, t)
Expand Down Expand Up @@ -876,7 +880,11 @@ func (p *Path) parseStyle() {
if ok == nil {
p.StrokeWidth = sw
}

case "opacity":
o, ok := strconv.ParseFloat(val, 64)
if ok == nil {
p.Opacity = &o
}
}
}
}
7 changes: 7 additions & 0 deletions svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Group struct {
Stroke string
StrokeWidth float64
Fill string
Opacity float64
FillRule string
Elements []DrawingInstructionParser
TransformString string
Expand Down Expand Up @@ -102,6 +103,12 @@ func (g *Group) UnmarshalXML(decoder *xml.Decoder, start xml.StartElement) error
g.StrokeWidth = floatValue
case "fill":
g.Fill = attr.Value
case "opacity":
floatValue, err := strconv.ParseFloat(attr.Value, 64)
if err != nil {
return err
}
g.Opacity = floatValue
case "fill-rule":
g.FillRule = attr.Value
case "transform":
Expand Down

0 comments on commit 5415eb8

Please sign in to comment.