Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No drawing instructions #9

Open
xyproto opened this issue Oct 22, 2019 · 2 comments
Open

No drawing instructions #9

xyproto opened this issue Oct 22, 2019 · 2 comments

Comments

@xyproto
Copy link

xyproto commented Oct 22, 2019

Hi,

I have this little test program:

package main

import (
	"bytes"
	"fmt"
	"github.com/rustyoz/svg"
	"github.com/xyproto/tinysvg"
	"image"
)

func Render(svgdata []byte) (*image.RGBA, error) {
	p, err := svg.ParseSvgFromReader(bytes.NewReader(svgdata), "Untitled", 1.0)
	if err != nil {
		return nil, err
	}
	fmt.Println("title:", p.Title)
	fmt.Println("groups:")
	for _, group := range p.Groups {
		fmt.Println("group:", group)
	}
	fmt.Println("width:", p.Width)
	fmt.Println("height:", p.Height)
	fmt.Println("viewbox", p.ViewBox)
	for _, element := range p.Elements {
		fmt.Println("element:", element)
	}
	fmt.Println("name:", p.Name)
	fmt.Println("transform:", p.Transform)

	drawingInstructionChan, errorChan := p.ParseDrawingInstructions()

	for err := range errorChan {
		if err != nil {
			fmt.Println("error", err)
		} else {
			fmt.Println("no error")
		}
	}

	for drawingInstruction := range drawingInstructionChan {
		fmt.Println("drawing instruction", drawingInstruction)
	}

	img := image.NewRGBA(image.Rectangle{image.Point{0, 0}, image.Point{256, 256}})
	return img, nil
}

func main() {
	document, svgTag := tinysvg.NewTinySVG(256, 256)
	svgTag.Describe("Diagram")

	roundedRectangle := svgTag.AddRoundedRect(30, 10, 5, 5, 20, 20)
	roundedRectangle.Fill("red")

	fmt.Println(document)

	_, err := Render(document.Bytes())
	if err != nil {
		panic(err)
	}
}

However, I can't see any drawing instructions appearing. I would expect this line to kick in at least once:

fmt.Println("drawing instruction", drawingInstruction)

What am I doing wrong?

This is a feature request for adding some documentation or a small example program for simple use of this package.

@xyproto xyproto closed this as completed Oct 22, 2019
@xyproto xyproto reopened this Oct 22, 2019
@rustyoz
Copy link
Owner

rustyoz commented Oct 23, 2019

Hi @xyproto

It appears that the later developers, (I only did the first few commits) haven't implemented the drawing instruction parser for rectangles fully.

Compare the implementation for a circle

// ParseDrawingInstructions implements the DrawingInstructionParser
// interface
func (c *Circle) ParseDrawingInstructions() (chan *DrawingInstruction, chan error) {
	draw := make(chan *DrawingInstruction)
	errs := make(chan error)

	go func() {
		defer close(draw)
		defer close(errs)

		draw <- &DrawingInstruction{
			Kind:   CircleInstruction,
			M:      &Tuple{c.Cx, c.Cy},
			Radius: &c.Radius,
		}

		draw <- &DrawingInstruction{Kind: PaintInstruction, Fill: &c.Fill}
	}()

	return draw, errs
}

as compared to a rectangle:

// ParseDrawingInstructions implements the DrawingInstructionParser
// interface
func (r *Rect) ParseDrawingInstructions() (chan *DrawingInstruction, chan error) {
	draw := make(chan *DrawingInstruction)
	errs := make(chan error)

	defer close(draw)
	defer close(errs)

	return draw, errs
}

Your test code has found this oversight. Unfortunately i don't have the time to fix this.

I would search for references to the later fork https://github.com/vytis/svg to find examples of it being used. Good luck

@xyproto
Copy link
Author

xyproto commented Oct 23, 2019

Thanks for the information and the detailed reply! It's helpful to know the current state of the implementation, and I wasn't aware of the fork.

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

No branches or pull requests

2 participants