Beispiel #1
0
//URL creates a Pattern similar to New, except that, instead of
//storing the uncompressed image data, a url to the image is stored.
//
//This is only useful on an SVG surface.
//
//Originally cairo_surface_set_mime_data.
func URL(URL *url.URL, r io.Reader) (cairo.Pattern, error) {
	img, _, err := image.Decode(r)
	if err != nil {
		return nil, err
	}

	is, err := cairo.FromImage(img)
	if err != nil {
		return nil, err
	}
	defer is.Close()

	bs := []byte(URL.String())
	if err = embed(is, uri, bs); err != nil {
		return nil, err
	}

	return newPattern(is)
}
Beispiel #2
0
//New creates a pattern of the image data in r of type mime.
//
//The returned pattern is essentially a SurfacePattern but the underlying
//surface is irrecoverable as any modification will lead to corruption.
//
//New will fail if there is not an image decoder for the relevant mime type
//installed with the image package.
//See the image package documentation for more information.
//It is up to you to ensure that the image data in r is of the mime type
//specified by mime.
//
//Originally cairo_surface_set_mime_data.
func New(mime mime, r io.Reader) (cairo.Pattern, error) {
	if !mime.valid() {
		return nil, errors.New("invalid or unsupported mime type: " + mime.s())
	}

	buf := bytes.NewBuffer(make([]byte, 0, 4096))
	img, _, err := image.Decode(io.TeeReader(r, buf))
	if err != nil {
		return nil, err
	}

	is, err := cairo.FromImage(img)
	if err != nil {
		return nil, err
	}
	defer is.Close()

	if err = embed(is, mime, buf.Bytes()); err != nil {
		return nil, err
	}

	return newPattern(is)
}
Beispiel #3
0
			Rectangle(cairo.Rect(0, 0, 256, 256)).
			Fill()

		c.
			SetSourceColor(cairo.Color{G: 1}).
			MoveTo(cairo.ZP).
			LineTo(pt(256, 256)).
			MoveTo(pt(256, 0)).
			LineTo(pt(0, 256)).
			SetLineWidth(10).
			Stroke()

		return nil
	}},
	{"clip-image", func(c *cairo.Context) error {
		i, err := cairo.FromImage(img) //img declared globally and set in main
		if err != nil {
			return err
		}
		defer i.Close()

		c.
			Circle(cairo.Circ(128, 128, 76.8)).
			Clip().
			NewPath()

		sz := i.Size()
		c.Scale(pt(256/sz.X, 256/sz.Y))
		if err = c.SetSourceSurface(i, cairo.ZP); err != nil {
			return err
		}