예제 #1
0
// completes and closes the file being written to
func (g *Graphic) Close() error {
	// destroy the context
	err := g.cairoStatus()
	if err != nil {
		return err
	}
	C.cairo_destroy(g.cr)

	// finishing the surface writes pdf, ps, and svg files
	C.cairo_surface_finish(g.surface)
	err = g.cairoSurfaceStatus()
	if err != nil {
		return err
	}

	// write other formats
	switch g.format {
	case "eps", "pdf", "ps", "svg":
		// cairo_surface_finish writes the surface to file
	case "png":
		img, err := g.Image()
		if err != nil {
			return err
		}

		file, err := os.Create(g.filename)
		if err != nil {
			return err
		}
		defer file.Close()

		err = png.Encode(file, img)
		if err != nil {
			return err
		}
	case "jpeg":
		img, err := g.Image()
		if err != nil {
			return err
		}

		file, err := os.Create(g.filename)
		if err != nil {
			return err
		}
		defer file.Close()

		err = jpeg.Encode(file, img, nil)
		if err != nil {
			return err
		}
	default:
		panic("unsupported format: " + g.format)
	}

	// destroy the surface
	C.cairo_surface_destroy(g.surface)
	err = g.cairoSurfaceStatus()
	if err != nil {
		return err
	}

	return nil
}
예제 #2
0
파일: surface.go 프로젝트: ungerik/go-cairo
func (self *Surface) Finish() {
	C.cairo_surface_finish(self.surface)
}
예제 #3
0
func (s CairoSurface) Finish() error {
	C.cairo_surface_finish(s.nativePointer())
	return s.status()
}